Skip to content

Commit

Permalink
Update commitee Role to security council role
Browse files Browse the repository at this point in the history
  • Loading branch information
zkJoaquin committed Apr 1, 2024
1 parent 5e2a6af commit db77b03
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion contracts/interfaces/IMergeTokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface IMergeTokenPortal {

event DepositLimitUpdated(address indexed sourceToken, uint256 depositLimit);

event CommiteeUpdated(address indexed oldCommitee, address indexed newCommitee);
event SecurityCouncilUpdated(address indexed oldCommitee, address indexed newCommitee);

/// @notice Source token info
/// @param isSupported Is the source token supported
Expand Down
38 changes: 23 additions & 15 deletions contracts/merge/MergeTokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ import {IERC20MergeToken} from "../interfaces/IERC20MergeToken.sol";
contract MergeTokenPortal is IMergeTokenPortal, UUPSUpgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
using SafeERC20Upgradeable for IERC20Upgradeable;

address public commiteeRoleAddress;

/// @dev A mapping source token address => source token status.
mapping(address sourceToken => SourceTokenInfo) public sourceTokenInfoMap;

modifier onlyOwnerOrCommitee() {
// @dev Security Council address
address public securityCouncil;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;

modifier onlyOwnerOrSecurityCouncil() {
require(
_msgSender() == owner() || _msgSender() == commiteeRoleAddress,
_msgSender() == owner() || _msgSender() == securityCouncil,
"Only owner or commitee can call this function"
);
_;
Expand All @@ -32,12 +40,12 @@ contract MergeTokenPortal is IMergeTokenPortal, UUPSUpgradeable, OwnableUpgradea
}

/// @notice Initializes the portal contract.
function initialize(address _commiteeRoleAddress) external initializer {
function initialize(address _securityCouncil) external initializer {
__UUPSUpgradeable_init_unchained();
__Ownable_init_unchained();
__ReentrancyGuard_init_unchained();

commiteeRoleAddress = _commiteeRoleAddress;
securityCouncil = _securityCouncil;
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
Expand Down Expand Up @@ -104,7 +112,7 @@ contract MergeTokenPortal is IMergeTokenPortal, UUPSUpgradeable, OwnableUpgradea
}

/// @notice Remove source token
function removeSourceToken(address _sourceToken) external onlyOwnerOrCommitee {
function removeSourceToken(address _sourceToken) external onlyOwnerOrSecurityCouncil {
SourceTokenInfo storage tokenInfo = sourceTokenInfoMap[_sourceToken];
require(tokenInfo.balance == 0, "Source Token balance is not zero");
delete sourceTokenInfoMap[_sourceToken];
Expand All @@ -113,7 +121,7 @@ contract MergeTokenPortal is IMergeTokenPortal, UUPSUpgradeable, OwnableUpgradea
}

/// @notice Lock source token
function updateDepositStatus(address _sourceToken, bool _isLocked) external onlyOwnerOrCommitee {
function updateDepositStatus(address _sourceToken, bool _isLocked) external onlyOwnerOrSecurityCouncil {
SourceTokenInfo storage tokenInfo = sourceTokenInfoMap[_sourceToken];
require(tokenInfo.isSupported, "Source token is not supported");

Expand All @@ -132,13 +140,13 @@ contract MergeTokenPortal is IMergeTokenPortal, UUPSUpgradeable, OwnableUpgradea
emit DepositLimitUpdated(_sourceToken, _limit);
}

/// @notice Grant commitee role
function grantCommiteeRole(address _commiteeRoleAddress) external onlyOwner {
require(_commiteeRoleAddress != address(0), "Invalid commitee role address");
address oldCommiteeRoleAddress = commiteeRoleAddress;
require(oldCommiteeRoleAddress != _commiteeRoleAddress, "Commitee role address is the same");
commiteeRoleAddress = _commiteeRoleAddress;
/// @notice Grant security council role
function grantSecurityCouncilRole(address _securityCouncil) external onlyOwner {
require(_securityCouncil != address(0), "Invalid the security council role address");
address oldSecurityCouncil = securityCouncil;
require(oldSecurityCouncil != _securityCouncil, "The Security Council role address is the same as old one");
securityCouncil = _securityCouncil;

emit CommiteeUpdated(oldCommiteeRoleAddress, _commiteeRoleAddress);
emit SecurityCouncilUpdated(oldSecurityCouncil, _securityCouncil);
}
}
2 changes: 1 addition & 1 deletion script/deploy_log_name.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// consumed in deploy_portal.ts
export const DEPLOY_PORTAL_LOG_PREFIX = 'deploy_portal';
export const DEPLOY_LOG_PORTAL_COMMITEE = 'commiteeAddress';
export const DEPLOY_LOG_PORTAL_COUNCIL = 'securityCouncilAddress';
export const DEPLOY_LOG_PORTAL_TARGET = 'portalTarget';
export const DEPLOY_LOG_PORTAL_TARGET_VERIFIED = 'portalTargetVerified';
export const DEPLOY_LOG_PORTAL_PROXY = 'portalProxy';
Expand Down
22 changes: 11 additions & 11 deletions script/deploy_portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import {
DEPLOY_PORTAL_LOG_PREFIX,
DEPLOY_LOG_DEPLOYER,
DEPLOY_LOG_PORTAL_COMMITEE,
DEPLOY_LOG_PORTAL_COUNCIL,
DEPLOY_LOG_PORTAL_TARGET,
DEPLOY_LOG_PORTAL_TARGET_VERIFIED,
DEPLOY_LOG_PORTAL_PROXY,
Expand All @@ -29,12 +29,12 @@ function getMergeTokenContractName() {
}

task('deployPortal', 'Deploy portal')
.addParam('commitee', 'Commitee address', undefined, types.string, false)
.addParam('securityCouncil', 'The Security Council address', undefined, types.string, false)
.addParam('skipVerify', 'Skip verify', false, types.boolean, true)
.setAction(async (taskArgs, hardhat) => {
let commiteeAddress = taskArgs.commitee;
let securityCouncilAddress = taskArgs.securityCouncil;
let skipVerify = taskArgs.skipVerify;
console.log('commitee address', commiteeAddress);
console.log('security council address', securityCouncilAddress);
console.log('skip verify contracts?', skipVerify);

const contractDeployer = new ChainContractDeployer(hardhat);
Expand All @@ -44,15 +44,15 @@ task('deployPortal', 'Deploy portal')
const { deployLogPath, deployLog } = createOrGetDeployLog(DEPLOY_PORTAL_LOG_PREFIX, hardhat.network.name);
const dLog = deployLog as any;
dLog[DEPLOY_LOG_DEPLOYER] = await deployerWallet?.getAddress();
dLog[DEPLOY_LOG_PORTAL_COMMITEE] = commiteeAddress;
dLog[DEPLOY_LOG_PORTAL_COUNCIL] = securityCouncilAddress;
fs.writeFileSync(deployLogPath, JSON.stringify(dLog, null, 2));

// deploy portal
let portalAddr;
if (!(DEPLOY_LOG_PORTAL_PROXY in dLog)) {
console.log('deploy portal...');
const contractName = getPortalContractName();
const contract = await contractDeployer.deployProxy(contractName, [commiteeAddress], {
const contract = await contractDeployer.deployProxy(contractName, [securityCouncilAddress], {
unsafeAllow: ['constructor'],
});
const transaction = await getDeployTx(contract);
Expand Down Expand Up @@ -276,20 +276,20 @@ task('encodeUpdateDepositLimit', 'Get the calldata of update deposit limit for p
return calldata;
});

task('encodeGrantCommiteeRole', 'Get the calldata of grant commitee role for portal')
.addParam('commitee', 'Commitee address', undefined, types.string, false)
task('encodeGrantSecurityCouncilRole', 'Get the calldata of grant the security council role for portal')
.addParam('securityCouncil', 'The Security Council address', undefined, types.string, false)
.addParam('portal', 'The portal address (default get from portal deploy log)', undefined, types.string, true)
.setAction(async (taskArgs, hre) => {
let commitee = taskArgs.commitee;
console.log('commitee', commitee);
let securityCouncilAddr = taskArgs.securityCouncil;
console.log('The Security Council Address', securityCouncilAddr);
let portal = taskArgs.portal;
if (portal === undefined) {
portal = readDeployContract(DEPLOY_PORTAL_LOG_PREFIX, DEPLOY_LOG_PORTAL_PROXY, hre.network.name);
}
console.log('portal address', portal);

const portalContract = await hre.ethers.getContractAt(getPortalContractName(), portal);
const calldata = portalContract.interface.encodeFunctionData('grantCommiteeRole', [commitee]);
const calldata = portalContract.interface.encodeFunctionData('grantSecurityCouncilRole', [securityCouncilAddr]);
console.log('calldata', calldata);

return calldata;
Expand Down
24 changes: 12 additions & 12 deletions test/MergeTokenPortal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,28 @@ describe('MergeToeknPortal', function () {
);
});

it('Should allow owner grant commitee role', async function () {
const oldCommitee = await mergeTokenPortal.commiteeRoleAddress();
it('Should allow owner grant the security council role', async function () {
const oldCommitee = await mergeTokenPortal.securityCouncil();
expect(oldCommitee).to.equal(commiteeAddr);
await mergeTokenPortal.connect(owner).grantCommiteeRole(user1Addr);
expect(await mergeTokenPortal.commiteeRoleAddress()).to.equal(user1Addr);
await mergeTokenPortal.connect(owner).grantSecurityCouncilRole(user1Addr);
expect(await mergeTokenPortal.securityCouncil()).to.equal(user1Addr);
});

it('Should not allow non-owner to grant commitee role', async function () {
await expect(mergeTokenPortal.connect(user1).grantCommiteeRole(user2Addr)).to.be.revertedWith(
it('Should not allow non-owner to grant the security council role', async function () {
await expect(mergeTokenPortal.connect(user1).grantSecurityCouncilRole(user2Addr)).to.be.revertedWith(
'Ownable: caller is not the owner',
);
});

it('Should not allow grant commitee role to zero address', async function () {
await expect(mergeTokenPortal.connect(owner).grantCommiteeRole(ZERO_ADDRESS)).to.be.revertedWith(
'Invalid commitee role address',
it('Should not allow grant the security council role to zero address', async function () {
await expect(mergeTokenPortal.connect(owner).grantSecurityCouncilRole(ZERO_ADDRESS)).to.be.revertedWith(
'Invalid the security council role address',
);
});

it('Should not allow grant commitee role to old commitee address', async function () {
await expect(mergeTokenPortal.connect(owner).grantCommiteeRole(commiteeAddr)).to.be.revertedWith(
'Commitee role address is the same',
it('Should not allow grant the security council role to old one', async function () {
await expect(mergeTokenPortal.connect(owner).grantSecurityCouncilRole(commiteeAddr)).to.be.revertedWith(
'The Security Council role address is the same as old one',
);
});
});
Expand Down

0 comments on commit db77b03

Please sign in to comment.