diff --git a/contracts/contracts/libraries/usdc/MigrationUSDC.sol b/contracts/contracts/libraries/usdc/MigrationUSDC.sol index 462aacb70..ffef27aa9 100644 --- a/contracts/contracts/libraries/usdc/MigrationUSDC.sol +++ b/contracts/contracts/libraries/usdc/MigrationUSDC.sol @@ -11,11 +11,14 @@ import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ER contract MigrationUSDC is OwnableUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable { using SafeERC20Upgradeable for IERC20Upgradeable; + error ErrZeroAddress(); + /// @dev Thrown the token balance is zero. error ErrorTokenBalanceZero(); event Migrate(address indexed user, uint256 amount); event Transfer(address indexed token, address indexed to, uint256 amount); + event UpdateRecipient(address indexed oldRecipient, address indexed newRecipient); /// @notice The address of old USDC address. address public immutable OLD_USDC; @@ -23,6 +26,9 @@ contract MigrationUSDC is OwnableUpgradeable, PausableUpgradeable, ReentrancyGua /// @notice The address of new USDC address. address public immutable NEW_USDC; + /// @notice Wallet that will receive the tokens on L2. + address public recipient; + /*************** * Constructor * ***************/ @@ -38,10 +44,17 @@ contract MigrationUSDC is OwnableUpgradeable, PausableUpgradeable, ReentrancyGua } // initialize contract status - function initialize() external initializer { + function initialize(address _recipient) external initializer { + if (_recipient == address(0)) { + revert ErrZeroAddress(); + } + recipient = _recipient; + __Ownable_init(); __Pausable_init(); __ReentrancyGuard_init(); + + emit UpdateRecipient(address(0), recipient); } // Transfer all old USDC to this contract and then transfer new USDC token to msg sender. @@ -59,7 +72,10 @@ contract MigrationUSDC is OwnableUpgradeable, PausableUpgradeable, ReentrancyGua } // Transfer token to other address. - function transferToken(address _token, address _to, uint256 _amount) external onlyOwner { + function transferToken(address _token, uint256 _amount) external onlyOwner { + if (recipient == address(0)) { + revert ErrZeroAddress(); + } uint256 balance = IERC20Upgradeable(_token).balanceOf(address(this)); if (balance == 0) { revert ErrorTokenBalanceZero(); @@ -69,12 +85,20 @@ contract MigrationUSDC is OwnableUpgradeable, PausableUpgradeable, ReentrancyGua _amount = balance; } // Transfer token. - IERC20Upgradeable(_token).transfer(_to, _amount); - emit Transfer(_token, _to, _amount); + IERC20Upgradeable(_token).transfer(recipient, _amount); + emit Transfer(_token, recipient, _amount); + } + + // Update the address of recipient. + function updateRecipient(address _newRecipient) external onlyOwner { + address _oldRecipient = recipient; + recipient = _newRecipient; + + emit UpdateRecipient(_oldRecipient, _newRecipient); } // Change pause status - function setPause(bool status) external { + function setPause(bool status) external onlyOwner { if (status) { _requireNotPaused(); _pause(); diff --git a/contracts/tasks/token_deploy.ts b/contracts/tasks/token_deploy.ts index 81821d0dc..b942b243b 100644 --- a/contracts/tasks/token_deploy.ts +++ b/contracts/tasks/token_deploy.ts @@ -253,11 +253,11 @@ task("init-l1-lidogateway") const gateway = await GatewayFactory.attach(taskArgs.l1lidogateway) console.log(`gateway at ${gateway.address}`) - let res = await gateway.initialize(taskArgs.counterpart,taskArgs.router,taskArgs.messenger) + let res = await gateway.initialize(taskArgs.counterpart, taskArgs.router, taskArgs.messenger) let rec = await res.wait() console.log(`initialize ${rec.status == 1}, txHash: ${rec.transactionHash}`) - res = await gateway.initializeV2(taskArgs.opter,taskArgs.opter,taskArgs.opter,taskArgs.opter) + res = await gateway.initializeV2(taskArgs.opter, taskArgs.opter, taskArgs.opter, taskArgs.opter) rec = await res.wait() console.log(`initializeV2 ${rec.status == 1}, txHash: ${rec.transactionHash}`) @@ -268,14 +268,14 @@ task("init-l1-lidogateway") let withdrawalEnabled = await gateway.isWithdrawalsEnabled() console.log(`counterpart ${counterpart}, router ${router}, messenger ${messenger}, depositEnabled ${depositEnabled}, withdrawalEnabled ${withdrawalEnabled}`) - const DEPOSITS_ENABLER_ROLE =await gateway.DEPOSITS_ENABLER_ROLE() - const DEPOSITS_DISABLER_ROLE =await gateway.DEPOSITS_DISABLER_ROLE() - const WITHDRAWALS_ENABLER_ROLE =await gateway.WITHDRAWALS_ENABLER_ROLE() - const WITHDRAWALS_DISABLER_ROLE =await gateway.WITHDRAWALS_DISABLER_ROLE() - const depositE = await gateway.hasRole(DEPOSITS_ENABLER_ROLE,taskArgs.opter) - const depositD = await gateway.hasRole(DEPOSITS_DISABLER_ROLE,taskArgs.opter) - const withdrawE = await gateway.hasRole(WITHDRAWALS_ENABLER_ROLE,taskArgs.opter) - const withdrawD = await gateway.hasRole(WITHDRAWALS_DISABLER_ROLE,taskArgs.opter) + const DEPOSITS_ENABLER_ROLE = await gateway.DEPOSITS_ENABLER_ROLE() + const DEPOSITS_DISABLER_ROLE = await gateway.DEPOSITS_DISABLER_ROLE() + const WITHDRAWALS_ENABLER_ROLE = await gateway.WITHDRAWALS_ENABLER_ROLE() + const WITHDRAWALS_DISABLER_ROLE = await gateway.WITHDRAWALS_DISABLER_ROLE() + const depositE = await gateway.hasRole(DEPOSITS_ENABLER_ROLE, taskArgs.opter) + const depositD = await gateway.hasRole(DEPOSITS_DISABLER_ROLE, taskArgs.opter) + const withdrawE = await gateway.hasRole(WITHDRAWALS_ENABLER_ROLE, taskArgs.opter) + const withdrawD = await gateway.hasRole(WITHDRAWALS_DISABLER_ROLE, taskArgs.opter) console.log(`Role: depositE ${depositE}, depositD ${depositD}, withdrawE ${withdrawE}, withdrawD ${withdrawD}`) }) @@ -301,11 +301,11 @@ task("init-l2-lidogateway") const gateway = await GatewayFactory.attach(taskArgs.l2lidogateway) console.log(`gateway at ${gateway.address}`) - let res = await gateway.initialize(taskArgs.counterpart,taskArgs.router,taskArgs.messenger) + let res = await gateway.initialize(taskArgs.counterpart, taskArgs.router, taskArgs.messenger) let rec = await res.wait() console.log(`initialize ${rec.status == 1}, txHash: ${rec.transactionHash}`) - res = await gateway.initializeV2(taskArgs.opter,taskArgs.opter,taskArgs.opter,taskArgs.opter) + res = await gateway.initializeV2(taskArgs.opter, taskArgs.opter, taskArgs.opter, taskArgs.opter) rec = await res.wait() console.log(`initializeV2 ${rec.status == 1}, txHash: ${rec.transactionHash}`) @@ -316,14 +316,14 @@ task("init-l2-lidogateway") let withdrawalEnabled = await gateway.isWithdrawalsEnabled() console.log(`counterpart ${counterpart}, router ${router}, messenger ${messenger}, depositEnabled ${depositEnabled}, withdrawalEnabled ${withdrawalEnabled}`) - const DEPOSITS_ENABLER_ROLE =await gateway.DEPOSITS_ENABLER_ROLE() - const DEPOSITS_DISABLER_ROLE =await gateway.DEPOSITS_DISABLER_ROLE() - const WITHDRAWALS_ENABLER_ROLE =await gateway.WITHDRAWALS_ENABLER_ROLE() - const WITHDRAWALS_DISABLER_ROLE =await gateway.WITHDRAWALS_DISABLER_ROLE() - const depositE = await gateway.hasRole(DEPOSITS_ENABLER_ROLE,taskArgs.opter) - const depositD = await gateway.hasRole(DEPOSITS_DISABLER_ROLE,taskArgs.opter) - const withdrawE = await gateway.hasRole(WITHDRAWALS_ENABLER_ROLE,taskArgs.opter) - const withdrawD = await gateway.hasRole(WITHDRAWALS_DISABLER_ROLE,taskArgs.opter) + const DEPOSITS_ENABLER_ROLE = await gateway.DEPOSITS_ENABLER_ROLE() + const DEPOSITS_DISABLER_ROLE = await gateway.DEPOSITS_DISABLER_ROLE() + const WITHDRAWALS_ENABLER_ROLE = await gateway.WITHDRAWALS_ENABLER_ROLE() + const WITHDRAWALS_DISABLER_ROLE = await gateway.WITHDRAWALS_DISABLER_ROLE() + const depositE = await gateway.hasRole(DEPOSITS_ENABLER_ROLE, taskArgs.opter) + const depositD = await gateway.hasRole(DEPOSITS_DISABLER_ROLE, taskArgs.opter) + const withdrawE = await gateway.hasRole(WITHDRAWALS_ENABLER_ROLE, taskArgs.opter) + const withdrawD = await gateway.hasRole(WITHDRAWALS_DISABLER_ROLE, taskArgs.opter) console.log(`Role: depositE ${depositE}, depositD ${depositD}, withdrawE ${withdrawE}, withdrawD ${withdrawD}`) }) @@ -336,49 +336,49 @@ task("upgrade-l1-usdcgateway") .addParam("router") .addParam("messenger") .setAction(async (taskArgs, hre) => { - // params check - if (!ethers.utils.isAddress(taskArgs.proxyadmin) || - !ethers.utils.isAddress(taskArgs.l1usdcgatewayproxy) || - !ethers.utils.isAddress(taskArgs.l1token) || - !ethers.utils.isAddress(taskArgs.l2token) || - !ethers.utils.isAddress(taskArgs.counterpart) || - !ethers.utils.isAddress(taskArgs.router) || - !ethers.utils.isAddress(taskArgs.messenger) - ) { - console.error(`address params check failed`) - return - } - // deploy gateway impl - const GatewayFactory = await hre.ethers.getContractFactory("L1USDCGateway") - const gateway = await GatewayFactory.deploy(taskArgs.l1token, taskArgs.l2token) - await gateway.deployed() - console.log(`gateway impl deployed at ${gateway.address}`) - - // upgrade proxy with initialize - const ProxyAdminFactory = await hre.ethers.getContractFactory("ProxyAdmin") - const proxyAdmin = await ProxyAdminFactory.attach(taskArgs.proxyadmin) - console.log(`proxy admin at ${proxyAdmin.address}`) - - let res = await proxyAdmin.upgrade( - taskArgs.l1usdcgatewayproxy, - gateway.address - ) - let rec =await res.wait() - console.log(`upgrade gateway ${rec.status == 1}`) - - - const gatewayProxy = GatewayFactory.attach(taskArgs.l1usdcgatewayproxy) - res = await gatewayProxy.initialize(taskArgs.counterpart,taskArgs.router,taskArgs.messenger) - rec =await res.wait() - console.log(`init gateway ${rec.status == 1}`) - - const owner = await gatewayProxy.owner() - const counterpart = await gatewayProxy.counterpart() - const router = await gatewayProxy.router() - const messenger = await gatewayProxy.messenger() - const l1USDC = await gatewayProxy.l1USDC() - const l2USDC = await gatewayProxy.l2USDC() - console.log(`owner ${owner}, gatewayProxy ${gatewayProxy.address}, counterpart ${counterpart}, router ${router}, messenger ${messenger}, l1USDC ${l1USDC}, l2USDC ${l2USDC}`) + // params check + if (!ethers.utils.isAddress(taskArgs.proxyadmin) || + !ethers.utils.isAddress(taskArgs.l1usdcgatewayproxy) || + !ethers.utils.isAddress(taskArgs.l1token) || + !ethers.utils.isAddress(taskArgs.l2token) || + !ethers.utils.isAddress(taskArgs.counterpart) || + !ethers.utils.isAddress(taskArgs.router) || + !ethers.utils.isAddress(taskArgs.messenger) + ) { + console.error(`address params check failed`) + return + } + // deploy gateway impl + const GatewayFactory = await hre.ethers.getContractFactory("L1USDCGateway") + const gateway = await GatewayFactory.deploy(taskArgs.l1token, taskArgs.l2token) + await gateway.deployed() + console.log(`gateway impl deployed at ${gateway.address}`) + + // upgrade proxy with initialize + const ProxyAdminFactory = await hre.ethers.getContractFactory("ProxyAdmin") + const proxyAdmin = await ProxyAdminFactory.attach(taskArgs.proxyadmin) + console.log(`proxy admin at ${proxyAdmin.address}`) + + let res = await proxyAdmin.upgrade( + taskArgs.l1usdcgatewayproxy, + gateway.address + ) + let rec = await res.wait() + console.log(`upgrade gateway ${rec.status == 1}`) + + + const gatewayProxy = GatewayFactory.attach(taskArgs.l1usdcgatewayproxy) + res = await gatewayProxy.initialize(taskArgs.counterpart, taskArgs.router, taskArgs.messenger) + rec = await res.wait() + console.log(`init gateway ${rec.status == 1}`) + + const owner = await gatewayProxy.owner() + const counterpart = await gatewayProxy.counterpart() + const router = await gatewayProxy.router() + const messenger = await gatewayProxy.messenger() + const l1USDC = await gatewayProxy.l1USDC() + const l2USDC = await gatewayProxy.l2USDC() + console.log(`owner ${owner}, gatewayProxy ${gatewayProxy.address}, counterpart ${counterpart}, router ${router}, messenger ${messenger}, l1USDC ${l1USDC}, l2USDC ${l2USDC}`) }) task("upgrade-l2-usdcgateway") @@ -390,45 +390,45 @@ task("upgrade-l2-usdcgateway") .addParam("router") .addParam("messenger") .setAction(async (taskArgs, hre) => { - // params check - if (!ethers.utils.isAddress(taskArgs.proxyadmin) || - !ethers.utils.isAddress(taskArgs.l2usdcgatewayproxy) || - !ethers.utils.isAddress(taskArgs.l1token) || - !ethers.utils.isAddress(taskArgs.l2token) || - !ethers.utils.isAddress(taskArgs.counterpart) || - !ethers.utils.isAddress(taskArgs.router) || - !ethers.utils.isAddress(taskArgs.messenger) - ) { - console.error(`address params check failed`) - return - } - // deploy gateway impl - const GatewayFactory = await hre.ethers.getContractFactory("L2USDCGateway") - const gateway = await GatewayFactory.deploy(taskArgs.l1token, taskArgs.l2token) - await gateway.deployed() - console.log(`gateway impl deployed at ${gateway.address}`) - - // upgrade proxy with initialize - const ProxyAdminFactory = await hre.ethers.getContractFactory("ProxyAdmin") - const proxyAdmin = await ProxyAdminFactory.attach(taskArgs.proxyadmin) - console.log(`proxy admin at ${proxyAdmin.address}`) - - let res = await proxyAdmin.upgrade( - taskArgs.l2usdcgatewayproxy, - gateway.address - ) - let rec =await res.wait() - console.log(`upgrade gateway ${rec.status == 1}`) - - const gatewayProxy = GatewayFactory.attach(taskArgs.l2usdcgatewayproxy) - res = await gatewayProxy.initialize( taskArgs.counterpart,taskArgs.router,taskArgs.messenger) - rec =await res.wait() - console.log(`init gateway ${rec.status == 1}`) - const counterpart = await gatewayProxy.counterpart() - const router = await gatewayProxy.router() - const l1USDC = await gatewayProxy.l1USDC() - const l2USDC = await gatewayProxy.l2USDC() - console.log(`gatewayProxy ${gatewayProxy.address}, counterpart ${counterpart}, router ${router}, l1USDC ${l1USDC}, l2USDC ${l2USDC}`) + // params check + if (!ethers.utils.isAddress(taskArgs.proxyadmin) || + !ethers.utils.isAddress(taskArgs.l2usdcgatewayproxy) || + !ethers.utils.isAddress(taskArgs.l1token) || + !ethers.utils.isAddress(taskArgs.l2token) || + !ethers.utils.isAddress(taskArgs.counterpart) || + !ethers.utils.isAddress(taskArgs.router) || + !ethers.utils.isAddress(taskArgs.messenger) + ) { + console.error(`address params check failed`) + return + } + // deploy gateway impl + const GatewayFactory = await hre.ethers.getContractFactory("L2USDCGateway") + const gateway = await GatewayFactory.deploy(taskArgs.l1token, taskArgs.l2token) + await gateway.deployed() + console.log(`gateway impl deployed at ${gateway.address}`) + + // upgrade proxy with initialize + const ProxyAdminFactory = await hre.ethers.getContractFactory("ProxyAdmin") + const proxyAdmin = await ProxyAdminFactory.attach(taskArgs.proxyadmin) + console.log(`proxy admin at ${proxyAdmin.address}`) + + let res = await proxyAdmin.upgrade( + taskArgs.l2usdcgatewayproxy, + gateway.address + ) + let rec = await res.wait() + console.log(`upgrade gateway ${rec.status == 1}`) + + const gatewayProxy = GatewayFactory.attach(taskArgs.l2usdcgatewayproxy) + res = await gatewayProxy.initialize(taskArgs.counterpart, taskArgs.router, taskArgs.messenger) + rec = await res.wait() + console.log(`init gateway ${rec.status == 1}`) + const counterpart = await gatewayProxy.counterpart() + const router = await gatewayProxy.router() + const l1USDC = await gatewayProxy.l1USDC() + const l2USDC = await gatewayProxy.l2USDC() + console.log(`gatewayProxy ${gatewayProxy.address}, counterpart ${counterpart}, router ${router}, l1USDC ${l1USDC}, l2USDC ${l2USDC}`) }) task("upgrade-l2-usdc-v2") @@ -452,7 +452,7 @@ task("upgrade-l2-usdc-v2") let res = await proxyAdmin.upgradeAndCall( taskArgs.l2usdcproxy, taskArgs.newimpl, - new ethers.utils.Interface(V2_1ABI).encodeFunctionData("initializeV2",[ + new ethers.utils.Interface(V2_1ABI).encodeFunctionData("initializeV2", [ "USD Coin" ]) ) @@ -489,7 +489,7 @@ task("upgrade-l2-usdc-v2-1") let rec = await res.wait() console.log(`upgrade usdc v2 ${rec.status == 1}`) - const l2usdc = new ethers.Contract(taskArgs.l2usdcproxy,new ethers.utils.Interface(V2_1ABI)) + const l2usdc = new ethers.Contract(taskArgs.l2usdcproxy, new ethers.utils.Interface(V2_1ABI)) res = await l2usdc.connect(deployer).initializeV2("USD Coin") rec = await res.wait() @@ -552,11 +552,11 @@ task("deploy-l2-usdcgateway") const proxy = await TransparentProxyFactory.deploy( gateway.address, //logic taskArgs.proxyadmin, //admin - GatewayFactory.interface.encodeFunctionData("initialize",[ + GatewayFactory.interface.encodeFunctionData("initialize", [ taskArgs.counterpart, taskArgs.router, taskArgs.messenger - ] + ] ) ) await proxy.deployed() @@ -576,10 +576,12 @@ task("deploy-l2-MigrationUSDC") .addParam("proxyadmin") .addParam("oldtoken") .addParam("newtoken") + .addParam("recipient") .setAction(async (taskArgs, hre) => { // params check if (!ethers.utils.isAddress(taskArgs.proxyadmin) || !ethers.utils.isAddress(taskArgs.oldtoken) || + !ethers.utils.isAddress(taskArgs.recipient) || !ethers.utils.isAddress(taskArgs.newtoken) ) { console.error(`address params check failed`) @@ -595,7 +597,9 @@ task("deploy-l2-MigrationUSDC") const proxy = await TransparentProxyFactory.deploy( contract.address, //logic taskArgs.proxyadmin, //admin - ContractFactory.interface.encodeFunctionData("initialize",[] + ContractFactory.interface.encodeFunctionData("initialize", [ + taskArgs.recipient + ] ) ) await proxy.deployed()