From c4b61a21ce2427aec15a793e86a1f1671d265654 Mon Sep 17 00:00:00 2001 From: Benjamin Patch Date: Tue, 7 Nov 2023 14:19:40 +1100 Subject: [PATCH] Add env vars --- .env.sample | 7 ++- README.md | 4 +- script/InitializeChildContracts.s.sol | 67 +++++++++++++++++---------- script/InitializeRootContracts.s.sol | 18 ++++--- 4 files changed, 62 insertions(+), 34 deletions(-) diff --git a/.env.sample b/.env.sample index beed0739..d5f783c6 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,6 @@ ROOT_ADMIN_ADDRESS= +ROOT_PAUSER_ADDRESS= +ROOT_UNPAUSER_ADDRESS= ROOT_RPC_URL= ROOT_CHAIN_ID= ROOT_PRIVATE_KEY= @@ -7,8 +9,11 @@ ROOT_GAS_SERVICE_ADDRESS= ROOT_CHAIN_NAME= ROOT_IMX_ADDRESS= ROOT_WETH_ADDRESS= +INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT= # 0 for unlimited -ROOT_ADMIN_ADDRESS= +CHILD_ADMIN_ADDRESS= +CHILD_PAUSER_ADDRESS= +CHILD_UNPAUSER_ADDRESS= CHILD_RPC_URL= CHILD_CHAIN_ID= CHILD_PRIVATE_KEY= diff --git a/README.md b/README.md index e7054c68..5cb20ba1 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ yarn run execute evm/call-contract local Ethereum Polygon map 5. (OPTIONAL) Check the token mapping has been populated using `cast` ```shell source .env -cast call --rpc-url $CHILD_RPC_URL "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" "rootTokenToChildToken(address)(address)" "0x38Aa1Cb12E5263eC0c6e9febC25B01116D346CD4" +cast call --rpc-url $CHILD_RPC_URL "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" "rootTokenToChildToken(address)(address)" "0x38Aa1Cb12E5263eC0c6e9febC25B01116D346CD4" ``` 6. Run the script that will send a `DEPOSIT` message @@ -172,6 +172,6 @@ yarn run execute evm/call-contract local Ethereum Polygon deposit 7. (OPTIONAL) Check the tokens have been deposited using `cast` ```shell source .env -cast call --rpc-url $CHILD_RPC_URL "0x3b39f73D7De57Ed2Fe85C0F30374D839dc625b93" "balanceOf(address)(uint256)" "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" +cast call --rpc-url $CHILD_RPC_URL "0xa03647137120b00cae83751A82280A67df027F04" "balanceOf(address)(uint256)" "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ``` (Note: This assumes your address is the one associated with the above-specified private key) diff --git a/script/InitializeChildContracts.s.sol b/script/InitializeChildContracts.s.sol index 2c4742cd..81ca6e9e 100644 --- a/script/InitializeChildContracts.s.sol +++ b/script/InitializeChildContracts.s.sol @@ -9,47 +9,66 @@ import {Utils} from "./Utils.sol"; // TODO update private key usage to be more secure: https://book.getfoundry.sh/reference/forge/forge-script#wallet-options---raw +struct InitializeChildContractsParams { + address childAdminAddress; + address childPauserAddress; + address childUnpauserAddress; + ChildERC20Bridge childERC20Bridge; + ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor; + address childTokenTemplate; + address rootERC20BridgeAdaptor; + string rootChainName; + address rootIMXToken; + string childRpcUrl; + uint256 deployerPrivateKey; + address childGasService; +} + contract InitializeChildContracts is Script { function run() public { - uint256 deployerPrivateKey = vm.envUint("CHILD_PRIVATE_KEY"); - ChildERC20Bridge childERC20Bridge = ChildERC20Bridge(vm.envAddress("CHILD_ERC20_BRIDGE")); - ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor = - ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")); - address childTokenTemplate = vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE"); - address rootERC20BridgeAdaptor = vm.envAddress("ROOT_BRIDGE_ADAPTOR"); - string memory childRpcUrl = vm.envString("CHILD_RPC_URL"); - string memory rootChainName = vm.envString("ROOT_CHAIN_NAME"); - address rootIMXToken = vm.envAddress("ROOT_IMX_ADDRESS"); - address childGasService = vm.envAddress("CHILD_GAS_SERVICE_ADDRESS"); // Not yet used. + InitializeChildContractsParams memory params = InitializeChildContractsParams({ + childAdminAddress: vm.envAddress("CHILD_ADMIN_ADDRESS"), + childPauserAddress: vm.envAddress("CHILD_PAUSER_ADDRESS"), + childUnpauserAddress: vm.envAddress("CHILD_UNPAUSER_ADDRESS"), + childERC20Bridge: ChildERC20Bridge(vm.envAddress("CHILD_ERC20_BRIDGE")), + childAxelarBridgeAdaptor: ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")), + childTokenTemplate: vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE"), + rootERC20BridgeAdaptor: vm.envAddress("ROOT_BRIDGE_ADAPTOR"), + rootChainName: vm.envString("ROOT_CHAIN_NAME"), + rootIMXToken: vm.envAddress("ROOT_IMX_ADDRESS"), + childRpcUrl: vm.envString("CHILD_RPC_URL"), + deployerPrivateKey: vm.envUint("CHILD_PRIVATE_KEY"), + childGasService: vm.envAddress("CHILD_GAS_SERVICE_ADDRESS") + }); /** * INITIALIZE CHILD CONTRACTS */ - string[] memory checksumInputs = Utils.getChecksumInputs(rootERC20BridgeAdaptor); + string[] memory checksumInputs = Utils.getChecksumInputs(params.rootERC20BridgeAdaptor); bytes memory checksumOutput = vm.ffi(checksumInputs); string memory rootBridgeAdaptorString = string(Utils.removeZeroByteValues(checksumOutput)); - vm.createSelectFork(childRpcUrl); - vm.startBroadcast(deployerPrivateKey); + vm.createSelectFork(params.childRpcUrl); + vm.startBroadcast(params.deployerPrivateKey); // TODO update IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({ - defaultAdmin: address(1), - pauser: address(2), - unpauser: address(3), - variableManager: address(4), - adaptorManager: address(5) + defaultAdmin: params.childAdminAddress, + pauser: params.childPauserAddress, + unpauser: params.childUnpauserAddress, + variableManager: params.childAdminAddress, + adaptorManager: params.childAdminAddress }); - childERC20Bridge.initialize( + params.childERC20Bridge.initialize( roles, - address(childAxelarBridgeAdaptor), + address(params.childAxelarBridgeAdaptor), rootBridgeAdaptorString, - childTokenTemplate, - rootChainName, - rootIMXToken + params.childTokenTemplate, + params.rootChainName, + params.rootIMXToken ); - childAxelarBridgeAdaptor.initialize(rootChainName, address(childERC20Bridge), childGasService); + params.childAxelarBridgeAdaptor.initialize(params.rootChainName, address(params.childERC20Bridge), params.childGasService); vm.stopBroadcast(); } diff --git a/script/InitializeRootContracts.s.sol b/script/InitializeRootContracts.s.sol index cebdb540..ea09b8ae 100644 --- a/script/InitializeRootContracts.s.sol +++ b/script/InitializeRootContracts.s.sol @@ -15,6 +15,8 @@ import {Utils} from "./Utils.sol"; struct InitializeRootContractsParams { address rootAdminAddress; + address rootPauserAddress; + address rootUnpauserAddress; RootERC20Bridge rootERC20Bridge; RootAxelarBridgeAdaptor rootBridgeAdaptor; address rootChainChildTokenTemplate; @@ -33,6 +35,8 @@ contract InitializeRootContracts is Script { function run() public { InitializeRootContractsParams memory params = InitializeRootContractsParams({ rootAdminAddress: vm.envAddress("ROOT_ADMIN_ADDRESS"), + rootPauserAddress: vm.envAddress("ROOT_PAUSER_ADDRESS"), + rootUnpauserAddress: vm.envAddress("ROOT_UNPAUSER_ADDRESS"), rootERC20Bridge: RootERC20Bridge(payable(vm.envAddress("ROOT_ERC20_BRIDGE"))), rootBridgeAdaptor: RootAxelarBridgeAdaptor(vm.envAddress("ROOT_BRIDGE_ADAPTOR")), rootChainChildTokenTemplate: vm.envAddress("ROOTCHAIN_CHILD_TOKEN_TEMPLATE"), @@ -58,13 +62,13 @@ contract InitializeRootContracts is Script { // TODO add pauser, unpauser roles. variable manager and Adaptor manager will be privileged transaction multisg - IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles( - address(params.rootAdminAddress), - address(params.rootAdminAddress), - address(params.rootAdminAddress), - address(params.rootAdminAddress), - address(params.rootAdminAddress) - ); + IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles({ + defaultAdmin: params.rootAdminAddress, + pauser: params.rootPauserAddress, + unpauser: params.rootUnpauserAddress, + variableManager: params.rootAdminAddress, + adaptorManager: params.rootAdminAddress + }); params.rootERC20Bridge.initialize( roles,