Skip to content

Commit

Permalink
fix AcceptAdmin deploy script for resumes
Browse files Browse the repository at this point in the history
  • Loading branch information
Archethect committed Oct 31, 2024
1 parent dcb0eca commit 4576d08
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 21 deletions.
79 changes: 58 additions & 21 deletions l1-contracts/deploy-scripts/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,76 @@ contract AcceptAdmin is Script {
// This function should be called by the owner to accept the admin role
function governanceAcceptOwner(address governor, address target) public {
Ownable2Step adminContract = Ownable2Step(target);
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: abi.encodeCall(adminContract.acceptOwnership, ()),
_value: 0,
_delay: 0
});
bytes memory data = abi.encodeCall(adminContract.acceptOwnership, ());
//Only execute if the operation does not exist yet
if (!Utils.governanceOperationExists(governor, target, 0, data, bytes32(0), bytes32(0))) {

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 36 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: data,
_value: 0,
_delay: 0
});
}
}

// This function should be called by the owner to accept the admin role
function governanceAcceptAdmin(address governor, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: abi.encodeCall(adminContract.acceptAdmin, ()),
_value: 0,
_delay: 0
});
bytes memory data = abi.encodeCall(adminContract.acceptAdmin, ());
//Only execute if the operation does not exist yet
if (!Utils.governanceOperationExists(governor, target, 0, data, bytes32(0), bytes32(0))) {

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 53 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: target,
_data: data,
_value: 0,
_delay: 0
});
}
}

// This function should be called by the owner to accept the admin role
function chainAdminAcceptAdmin(ChainAdmin chainAdmin, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
bool adminIsDifferent = false;
address currentAdmin;

IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({target: target, value: 0, data: abi.encodeCall(adminContract.acceptAdmin, ())});
// Attempt to call admin() using a low-level call
(bool success, bytes memory result) = target.call(abi.encodeWithSignature("admin()"));

vm.startBroadcast();
chainAdmin.multicall(calls, true);
vm.stopBroadcast();
if (success) {
// Decode the result to get the current admin address
currentAdmin = abi.decode(result, (address));
} else {
// If admin() fails, try calling getAdmin() instead
(success, result) = target.call(abi.encodeWithSignature("getAdmin()"));
require(success, "Both admin() and getAdmin() calls failed");

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Error message for require is too long: 40 counted / 32 allowed

Check failure on line 80 in l1-contracts/deploy-scripts/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

// Decode the result to get the current admin address
currentAdmin = abi.decode(result, (address));
}

// Check if the current admin is different from the expected chainAdmin
if (currentAdmin != address(chainAdmin)) {
adminIsDifferent = true;
}

// Proceed with multicall if the admin is different
if (adminIsDifferent) {
IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({
target: target,
value: 0,
data: abi.encodeCall(adminContract.acceptAdmin, ())
});

vm.startBroadcast();
chainAdmin.multicall(calls, true);
vm.stopBroadcast();
}
}

// This function should be called by the owner to update token multiplier setter role
Expand Down
23 changes: 23 additions & 0 deletions l1-contracts/deploy-scripts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,27 @@ library Utils {
vm.stopBroadcast();
}
}

function governanceOperationExists(
address _governance,
address _target,
uint256 _value,
bytes memory _data,
bytes32 _predecessor,
bytes32 _salt
) internal view returns (bool) {
IGovernance governance = IGovernance(_governance);

IGovernance.Call[] memory calls = new IGovernance.Call[](1);
calls[0] = IGovernance.Call({target: _target, value: _value, data: _data});

IGovernance.Operation memory operation = IGovernance.Operation({
calls: calls,
predecessor: _predecessor,
salt: _salt
});

bytes32 operationHash = governance.hashOperation(operation);
return governance.isOperation(operationHash);
}
}

0 comments on commit 4576d08

Please sign in to comment.