Skip to content

Commit

Permalink
Merge pull request #1 from mantle-lsp/will-m-admin-script
Browse files Browse the repository at this point in the history
Add function to grant all admin roles
  • Loading branch information
shidaxi authored Oct 19, 2023
2 parents 92295b9 + b464dfa commit f9c0d66
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion script/deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pragma solidity ^0.8.20;
import {Base} from "./base.s.sol";
import {console2 as console} from "forge-std/console2.sol";

import {deployAll, grantAndRenounceAllRoles, Deployments, DeploymentParams} from "./helpers/Proxy.sol";
import {
deployAll, grantAndRenounceAllRoles, grantAllAdminRoles, Deployments, DeploymentParams
} from "./helpers/Proxy.sol";

contract Deploy is Base {
function _readDeploymentParamsFromEnv() internal view returns (DeploymentParams memory) {
Expand Down Expand Up @@ -60,4 +62,11 @@ contract Deploy is Base {
grantAndRenounceAllRoles(params, ds, msg.sender);
vm.stopBroadcast();
}

function addNewAdminToAllContracts(address newAdmin) public {
Deployments memory ds = readDeployments();
vm.startBroadcast();
grantAllAdminRoles(ds, newAdmin);
vm.stopBroadcast();
}
}
21 changes: 21 additions & 0 deletions script/helpers/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ function grantAndRenounce(AccessControl controllable, bytes32 role, address send
}
}

function grantRole(AccessControlUpgradeable controllable, bytes32 role, address newAccount) {
grantRole(AccessControl(address(controllable)), role, newAccount);
}

function grantRole(AccessControl controllable, bytes32 role, address newAccount) {
controllable.grantRole(role, newAccount);
}

/// @notice Grants roles to addresses as specified in `params` and renounces the roles from `sender`.
/// @dev Assumes that all contracts were deployed using `sender` as admin/manager/etc.
function grantAndRenounceAllRoles(DeploymentParams memory params, Deployments memory ds, address sender) {
Expand Down Expand Up @@ -401,3 +409,16 @@ function grantAndRenounceAllRoles(DeploymentParams memory params, Deployments me
grantAndRenounce(ds.proxyAdmin, ds.proxyAdmin.CANCELLER_ROLE(), sender, params.upgrader);
grantAndRenounce(ds.proxyAdmin, ds.proxyAdmin.TIMELOCK_ADMIN_ROLE(), sender, params.admin);
}

function grantAllAdminRoles(Deployments memory ds, address newAdmin) {
grantRole(ds.staking, ds.staking.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.mETH, ds.mETH.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.oracle, ds.oracle.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.quorumManager, ds.quorumManager.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.unstakeRequestsManager, ds.unstakeRequestsManager.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.aggregator, ds.aggregator.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.pauser, ds.pauser.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.consensusLayerReceiver, ds.consensusLayerReceiver.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.executionLayerReceiver, ds.executionLayerReceiver.DEFAULT_ADMIN_ROLE(), newAdmin);
grantRole(ds.proxyAdmin, ds.proxyAdmin.TIMELOCK_ADMIN_ROLE(), newAdmin);
}

0 comments on commit f9c0d66

Please sign in to comment.