From 7806a5cb8e5bb88a80ad7414072791724d55be19 Mon Sep 17 00:00:00 2001 From: wcgcyx Date: Wed, 22 Nov 2023 15:19:55 +1000 Subject: [PATCH] Update --- scripts/bootstrap/3_child_deployment.js | 98 +---------- scripts/bootstrap/4_root_deployment.js | 82 +-------- scripts/bootstrap/5_child_initialisation.js | 97 +---------- scripts/bootstrap/8_root_initialisation.js | 178 +------------------ scripts/deploy/.env.example | 115 +++++++++++++ scripts/deploy/child_deployment.js | 102 +++++++++++ scripts/deploy/child_initialisation.js | 101 +++++++++++ scripts/deploy/deployAndInit.js | 14 ++ scripts/deploy/root_deployment.js | 86 +++++++++ scripts/deploy/root_initialisation.js | 182 ++++++++++++++++++++ 10 files changed, 608 insertions(+), 447 deletions(-) create mode 100644 scripts/deploy/.env.example create mode 100644 scripts/deploy/child_deployment.js create mode 100644 scripts/deploy/child_initialisation.js create mode 100644 scripts/deploy/deployAndInit.js create mode 100644 scripts/deploy/root_deployment.js create mode 100644 scripts/deploy/root_initialisation.js diff --git a/scripts/bootstrap/3_child_deployment.js b/scripts/bootstrap/3_child_deployment.js index 914f82fe..1eb97db4 100644 --- a/scripts/bootstrap/3_child_deployment.js +++ b/scripts/bootstrap/3_child_deployment.js @@ -1,103 +1,9 @@ // Deploy child contracts 'use strict'; require('dotenv').config(); -const { ethers } = require("ethers"); -const helper = require("../helpers/helpers.js"); -const { LedgerSigner } = require('@ethersproject/hardware-wallets') -const fs = require('fs'); +const deploy = require("../deploy/child_deployment.js"); async function run() { - // Check environment variables - let childRPCURL = helper.requireEnv("CHILD_RPC_URL"); - let childChainID = helper.requireEnv("CHILD_CHAIN_ID"); - let childDeployerSecret = helper.requireEnv("CHILD_DEPLOYER_SECRET"); - let childGatewayAddr = helper.requireEnv("CHILD_GATEWAY_ADDRESS"); - let childProxyAdmin = helper.requireEnv("CHILD_PROXY_ADMIN"); - - // Get admin address - const childProvider = new ethers.providers.JsonRpcProvider(childRPCURL, Number(childChainID)); - let adminWallet; - if (childDeployerSecret == "ledger") { - adminWallet = new LedgerSigner(childProvider); - } else { - adminWallet = new ethers.Wallet(childDeployerSecret, childProvider); - } - let adminAddr = await adminWallet.getAddress(); - console.log("Deployer address is: ", adminAddr); - - // Execute - console.log("Deploy child contracts in..."); - await helper.waitForConfirmation(); - - // Deploy child token template - let childTokenTemplateObj = JSON.parse(fs.readFileSync('../../out/ChildERC20.sol/ChildERC20.json', 'utf8')); - console.log("Deploy child token template..."); - let childTokenTemplate = await helper.deployChildContract(childTokenTemplateObj, adminWallet); - await helper.waitForReceipt(childTokenTemplate.deployTransaction.hash, childProvider); - // Initialise template - let [priorityFee, maxFee] = await helper.getFee(adminWallet); - let resp = await childTokenTemplate.connect(adminWallet).initialize("000000000000000000000000000000000000007B", "TEMPLATE", "TPT", 18, { - maxPriorityFeePerGas: priorityFee, - maxFeePerGas: maxFee, - }); - await helper.waitForReceipt(resp.hash, childProvider); - console.log("Deployed to CHILD_TOKEN_TEMPLATE: ", childTokenTemplate.address); - - // Deploy wrapped IMX - let wrappedIMXObj = JSON.parse(fs.readFileSync('../../out/WIMX.sol/WIMX.json', 'utf8')); - console.log("Deploy wrapped IMX..."); - let wrappedIMX = await helper.deployChildContract(wrappedIMXObj, adminWallet); - await helper.waitForReceipt(wrappedIMX.deployTransaction.hash, childProvider); - console.log("Deployed to WRAPPED_IMX_ADDRESS: ", wrappedIMX.address); - - // Deploy proxy admin - let proxyAdminObj = JSON.parse(fs.readFileSync('../../out/ProxyAdmin.sol/ProxyAdmin.json', 'utf8')); - console.log("Deploy proxy admin..."); - let proxyAdmin = await helper.deployChildContract(proxyAdminObj, adminWallet); - await helper.waitForReceipt(proxyAdmin.deployTransaction.hash, childProvider); - // Change owner - [priorityFee, maxFee] = await helper.getFee(adminWallet); - resp = await proxyAdmin.connect(adminWallet).transferOwnership(childProxyAdmin, { - maxPriorityFeePerGas: priorityFee, - maxFeePerGas: maxFee, - }); - await helper.waitForReceipt(resp.hash, childProvider); - console.log("Deployed to CHILD_PROXY_ADMIN: ", proxyAdmin.address); - - // Deploy child bridge impl - let childBridgeImplObj = JSON.parse(fs.readFileSync('../../out/ChildERC20Bridge.sol/ChildERC20Bridge.json', 'utf8')); - console.log("Deploy child bridge impl..."); - let childBridgeImpl = await helper.deployChildContract(childBridgeImplObj, adminWallet); - await helper.waitForReceipt(childBridgeImpl.deployTransaction.hash, childProvider); - console.log("Deployed to CHILD_BRIDGE_IMPL_ADDRESS: ", childBridgeImpl.address); - - // Deploy child bridge proxy - let childBridgeProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); - console.log("Deploy child bridge proxy..."); - let childBridgeProxy = await helper.deployChildContract(childBridgeProxyObj, adminWallet, childBridgeImpl.address, proxyAdmin.address, []); - await helper.waitForReceipt(childBridgeProxy.deployTransaction.hash, childProvider); - console.log("Deployed to CHILD_BRIDGE_PROXY_ADDRESS: ", childBridgeProxy.address); - - // Deploy child adaptor impl - let childAdaptorImplObj = JSON.parse(fs.readFileSync('../../out/ChildAxelarBridgeAdaptor.sol/ChildAxelarBridgeAdaptor.json', 'utf8')); - console.log("Deploy child adaptor impl..."); - let childAdaptorImpl = await helper.deployChildContract(childAdaptorImplObj, adminWallet, childGatewayAddr); - await helper.waitForReceipt(childAdaptorImpl.deployTransaction.hash, childProvider); - console.log("Deployed to CHILD_ADAPTOR_IMPL_ADDRESS: ", childAdaptorImpl.address); - - // Deploy child adaptor proxy - let childAdaptorProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); - console.log("Deploy child adaptor proxy..."); - let childAdaptorProxy = await helper.deployChildContract(childAdaptorProxyObj, adminWallet, childAdaptorImpl.address, proxyAdmin.address, []); - await helper.waitForReceipt(childAdaptorProxy.deployTransaction.hash, childProvider); - console.log("Deployed to CHILD_ADAPTOR_PROXY_ADDRESS: ", childAdaptorProxy.address); - - let contractData = { - CHILD_BRIDGE_ADDRESS: childBridgeProxy.address, - CHILD_ADAPTOR_ADDRESS: childAdaptorProxy.address, - WRAPPED_IMX_ADDRESS: wrappedIMX.address, - CHILD_TOKEN_TEMPLATE: childTokenTemplate.address, - }; - fs.writeFileSync(".child.bridge.contracts.json", JSON.stringify(contractData, null, 2)); + await deploy.deployChildContracts(); } run(); \ No newline at end of file diff --git a/scripts/bootstrap/4_root_deployment.js b/scripts/bootstrap/4_root_deployment.js index 40677a23..da06730b 100644 --- a/scripts/bootstrap/4_root_deployment.js +++ b/scripts/bootstrap/4_root_deployment.js @@ -1,87 +1,9 @@ // Deploy root contracts 'use strict'; require('dotenv').config(); -const { ethers } = require("ethers"); -const helper = require("../helpers/helpers.js"); -const { LedgerSigner } = require('@ethersproject/hardware-wallets') -const fs = require('fs'); +const deploy = require("../deploy/root_deployment.js"); async function run() { - // Check environment variables - let rootRPCURL = helper.requireEnv("ROOT_RPC_URL"); - let rootChainID = helper.requireEnv("ROOT_CHAIN_ID"); - let rootDeployerSecret = helper.requireEnv("ROOT_DEPLOYER_SECRET"); - let rootProxyAdmin = helper.requireEnv("ROOT_PROXY_ADMIN"); - let rootGatewayAddr = helper.requireEnv("ROOT_GATEWAY_ADDRESS"); - - // Get admin address - const rootProvider = new ethers.providers.JsonRpcProvider(rootRPCURL, Number(rootChainID)); - let adminWallet; - if (rootDeployerSecret == "ledger") { - adminWallet = new LedgerSigner(rootProvider); - } else { - adminWallet = new ethers.Wallet(rootDeployerSecret, rootProvider); - } - let adminAddr = await adminWallet.getAddress(); - console.log("Deployer address is: ", adminAddr); - - // Execute - console.log("Deploy root contracts in..."); - await helper.waitForConfirmation(); - - // Deploy root token template - let rootTokenTemplateObj = JSON.parse(fs.readFileSync('../../out/ChildERC20.sol/ChildERC20.json', 'utf8')); - console.log("Deploy root token template..."); - let rootTokenTemplate = await helper.deployRootContract(rootTokenTemplateObj, adminWallet); - await helper.waitForReceipt(rootTokenTemplate.deployTransaction.hash, rootProvider); - // Initialise template - let resp = await rootTokenTemplate.connect(adminWallet).initialize("000000000000000000000000000000000000007B", "TEMPLATE", "TPT", 18); - await helper.waitForReceipt(resp.hash, rootProvider); - console.log("Deployed to ROOT_TOKEN_TEMPLATE: ", rootTokenTemplate.address); - - // Deploy proxy admin - let proxyAdminObj = JSON.parse(fs.readFileSync('../../out/ProxyAdmin.sol/ProxyAdmin.json', 'utf8')); - console.log("Deploy proxy admin..."); - let proxyAdmin = await helper.deployRootContract(proxyAdminObj, adminWallet); - await helper.waitForReceipt(proxyAdmin.deployTransaction.hash, rootProvider); - // Change owner - resp = await proxyAdmin.connect(adminWallet).transferOwnership(rootProxyAdmin); - await helper.waitForReceipt(resp.hash, rootProvider); - console.log("Deployed to ROOT_PROXY_ADMIN: ", proxyAdmin.address); - - // Deploy root bridge impl - let rootBridgeImplObj = JSON.parse(fs.readFileSync('../../out/RootERC20BridgeFlowRate.sol/RootERC20BridgeFlowRate.json', 'utf8')); - console.log("Deploy root bridge impl..."); - let rootBridgeImpl = await helper.deployRootContract(rootBridgeImplObj, adminWallet); - await helper.waitForReceipt(rootBridgeImpl.deployTransaction.hash, rootProvider); - console.log("Deployed to ROOT_BRIDGE_IMPL_ADDRESS: ", rootBridgeImpl.address); - - // Deploy root bridge proxy - let rootBridgeProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); - console.log("Deploy root bridge proxy..."); - let rootBridgeProxy = await helper.deployRootContract(rootBridgeProxyObj, adminWallet, rootBridgeImpl.address, proxyAdmin.address, []); - await helper.waitForReceipt(rootBridgeProxy.deployTransaction.hash, rootProvider); - console.log("Deployed to ROOT_BRIDGE_PROXY_ADDRESS: ", rootBridgeProxy.address); - - // Deploy root adaptor impl - let rootAdaptorImplObj = JSON.parse(fs.readFileSync('../../out/RootAxelarBridgeAdaptor.sol/RootAxelarBridgeAdaptor.json', 'utf8')); - console.log("Deploy root adaptor impl..."); - let rootAdaptorImpl = await helper.deployRootContract(rootAdaptorImplObj, adminWallet, rootGatewayAddr); - await helper.waitForReceipt(rootAdaptorImpl.deployTransaction.hash, rootProvider); - console.log("Deployed to ROOT_ADAPTOR_IMPL_ADDRESS: ", rootAdaptorImpl.address); - - // Deploy root adaptor proxy - let rootAdaptorProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); - console.log("Deploy root adaptor proxy..."); - let rootAdaptorProxy = await helper.deployRootContract(rootAdaptorProxyObj, adminWallet, rootAdaptorImpl.address, proxyAdmin.address, []); - await helper.waitForReceipt(rootAdaptorProxy.deployTransaction.hash, rootProvider); - console.log("Deployed to ROOT_ADAPTOR_PROXY_ADDRESS: ", rootAdaptorProxy.address); - - let contractData = { - ROOT_BRIDGE_ADDRESS: rootBridgeProxy.address, - ROOT_ADAPTOR_ADDRESS: rootAdaptorProxy.address, - ROOT_TOKEN_TEMPLATE: rootTokenTemplate.address, - }; - fs.writeFileSync(".root.bridge.contracts.json", JSON.stringify(contractData, null, 2)); + await deploy.deployRootContracts(); } run(); \ No newline at end of file diff --git a/scripts/bootstrap/5_child_initialisation.js b/scripts/bootstrap/5_child_initialisation.js index 5c781f0e..75bb4db2 100644 --- a/scripts/bootstrap/5_child_initialisation.js +++ b/scripts/bootstrap/5_child_initialisation.js @@ -1,102 +1,9 @@ // Initialise child contracts 'use strict'; require('dotenv').config(); -const { ethers } = require("ethers"); -const helper = require("../helpers/helpers.js"); -const { LedgerSigner } = require('@ethersproject/hardware-wallets') -const fs = require('fs'); +const init = require("../deploy/child_initialisation.js"); async function run() { - let rootChainName = helper.requireEnv("ROOT_CHAIN_NAME"); - let childRPCURL = helper.requireEnv("CHILD_RPC_URL"); - let childChainID = helper.requireEnv("CHILD_CHAIN_ID"); - let adminEOAAddr = helper.requireEnv("CHILD_ADMIN_ADDR"); - let childBridgeDefaultAdmin = helper.requireEnv("CHILD_BRIDGE_DEFAULT_ADMIN"); - let childBridgePauser = helper.requireEnv("CHILD_BRIDGE_PAUSER"); - let childBridgeUnpauser = helper.requireEnv("CHILD_BRIDGE_UNPAUSER"); - let childBridgeAdaptorManager = helper.requireEnv("CHILD_BRIDGE_ADAPTOR_MANAGER"); - let childBridgeTreasuryManager = helper.requireEnv("CHILD_BRIDGE_TREASURY_MANAGER"); - let childAdaptorDefaultAdmin = helper.requireEnv("CHILD_ADAPTOR_DEFAULT_ADMIN"); - let childAdaptorBridgeManager = helper.requireEnv("CHILD_ADAPTOR_BRIDGE_MANAGER"); - let childAdaptorGasServiceManager = helper.requireEnv("CHILD_ADAPTOR_GAS_SERVICE_MANAGER"); - let childAdaptorTargetManager = helper.requireEnv("CHILD_ADAPTOR_TARGET_MANAGER"); - let childDeployerSecret = helper.requireEnv("CHILD_DEPLOYER_SECRET"); - let childGasServiceAddr = helper.requireEnv("CHILD_GAS_SERVICE_ADDRESS"); - let multisigAddr = helper.requireEnv("MULTISIG_CONTRACT_ADDRESS"); - let rootIMXAddr = helper.requireEnv("ROOT_IMX_ADDR"); - - // Read from contract file. - let data = fs.readFileSync(".child.bridge.contracts.json", 'utf-8'); - let childContracts = JSON.parse(data); - let childBridgeAddr = childContracts.CHILD_BRIDGE_ADDRESS; - let childAdaptorAddr = childContracts.CHILD_ADAPTOR_ADDRESS; - let childWIMXAddr = childContracts.WRAPPED_IMX_ADDRESS; - let childTemplateAddr = childContracts.CHILD_TOKEN_TEMPLATE; - data = fs.readFileSync(".root.bridge.contracts.json", 'utf-8'); - let rootContracts = JSON.parse(data); - let rootAdaptorAddr = rootContracts.ROOT_ADAPTOR_ADDRESS; - - // Get admin address - const childProvider = new ethers.providers.JsonRpcProvider(childRPCURL, Number(childChainID)); - let adminWallet; - if (childDeployerSecret == "ledger") { - adminWallet = new LedgerSigner(childProvider); - } else { - adminWallet = new ethers.Wallet(childDeployerSecret, childProvider); - } - let adminAddr = await adminWallet.getAddress(); - console.log("Deployer address is: ", adminAddr); - - // Execute - console.log("Initialise child contracts in..."); - await helper.waitForConfirmation(); - - // Initialise child bridge - let childBridgeObj = JSON.parse(fs.readFileSync('../../out/ChildERC20Bridge.sol/ChildERC20Bridge.json', 'utf8')); - console.log("Initialise child bridge..."); - let childBridge = new ethers.Contract(childBridgeAddr, childBridgeObj.abi, childProvider); - let [priorityFee, maxFee] = await helper.getFee(adminWallet); - let resp = await childBridge.connect(adminWallet).initialize( - { - defaultAdmin: childBridgeDefaultAdmin, - pauser: childBridgePauser, - unpauser: childBridgeUnpauser, - adaptorManager: childBridgeAdaptorManager, - treasuryManager: childBridgeTreasuryManager, - }, - childAdaptorAddr, - ethers.utils.getAddress(rootAdaptorAddr), - childTemplateAddr, - rootChainName, - rootIMXAddr, - childWIMXAddr, - multisigAddr, - adminEOAAddr, - { - maxPriorityFeePerGas: priorityFee, - maxFeePerGas: maxFee, - }); - await helper.waitForReceipt(resp.hash, childProvider); - - // Initialise child adaptor - let childAdaptorObj = JSON.parse(fs.readFileSync('../../out/ChildAxelarBridgeAdaptor.sol/ChildAxelarBridgeAdaptor.json', 'utf8')); - console.log("Initialise child adaptor..."); - let childAdaptor = new ethers.Contract(childAdaptorAddr, childAdaptorObj.abi, childProvider); - [priorityFee, maxFee] = await helper.getFee(adminWallet); - resp = await childAdaptor.connect(adminWallet).initialize( - { - defaultAdmin: childAdaptorDefaultAdmin, - bridgeManager: childAdaptorBridgeManager, - gasServiceManager: childAdaptorGasServiceManager, - targetManager: childAdaptorTargetManager, - }, - rootChainName, - childBridgeAddr, - childGasServiceAddr, - { - maxPriorityFeePerGas: priorityFee, - maxFeePerGas: maxFee, - }); - await helper.waitForReceipt(resp.hash, childProvider); + await init.initialiseChildContracts(); } run(); \ No newline at end of file diff --git a/scripts/bootstrap/8_root_initialisation.js b/scripts/bootstrap/8_root_initialisation.js index 639df919..74ca75ba 100644 --- a/scripts/bootstrap/8_root_initialisation.js +++ b/scripts/bootstrap/8_root_initialisation.js @@ -1,183 +1,9 @@ // Initialise root contracts 'use strict'; require('dotenv').config(); -const { ethers } = require("ethers"); -const helper = require("../helpers/helpers.js"); -const { LedgerSigner } = require('@ethersproject/hardware-wallets') -const fs = require('fs'); +const init = require("../deploy/root_initialisation.js"); async function run() { - // Check environment variables - let childChainName = helper.requireEnv("CHILD_CHAIN_NAME"); - let rootRPCURL = helper.requireEnv("ROOT_RPC_URL"); - let rootChainID = helper.requireEnv("ROOT_CHAIN_ID"); - let rootDeployerSecret = helper.requireEnv("ROOT_DEPLOYER_SECRET"); - let rootRateAdminSecret = helper.requireEnv("ROOT_BRIDGE_RATE_ADMIN_SECRET"); - let rootBridgeDefaultAdmin = helper.requireEnv("ROOT_BRIDGE_DEFAULT_ADMIN"); - let rootBridgePauser = helper.requireEnv("ROOT_BRIDGE_PAUSER"); - let rootBridgeUnpauser = helper.requireEnv("ROOT_BRIDGE_UNPAUSER"); - let rootBridgeVariableManager = helper.requireEnv("ROOT_BRIDGE_VARIABLE_MANAGER"); - let rootBridgeAdaptorManager = helper.requireEnv("ROOT_BRIDGE_ADAPTOR_MANAGER"); - let rootAdaptorDefaultAdmin = helper.requireEnv("ROOT_ADAPTOR_DEFAULT_ADMIN"); - let rootAdaptorBridgeManager = helper.requireEnv("ROOT_ADAPTOR_BRIDGE_MANAGER"); - let rootAdaptorGasServiceManager = helper.requireEnv("ROOT_ADAPTOR_GAS_SERVICE_MANAGER"); - let rootAdaptorTargetManager = helper.requireEnv("ROOT_ADAPTOR_TARGET_MANAGER"); - let rootGasServiceAddr = helper.requireEnv("ROOT_GAS_SERVICE_ADDRESS"); - let rootIMXAddr = helper.requireEnv("ROOT_IMX_ADDR"); - let rootWETHAddr = helper.requireEnv("ROOT_WETH_ADDR"); - let imxDepositLimit = helper.requireEnv("IMX_DEPOSIT_LIMIT"); - let rateLimitIMXCap = helper.requireEnv("RATE_LIMIT_IMX_CAPACITY"); - let rateLimitIMXRefill = helper.requireEnv("RATE_LIMIT_IMX_REFILL_RATE"); - let rateLimitIMXLargeThreshold = helper.requireEnv("RATE_LIMIT_IMX_LARGE_THRESHOLD"); - let rateLimitETHCap = helper.requireEnv("RATE_LIMIT_ETH_CAPACITY"); - let rateLimitETHRefill = helper.requireEnv("RATE_LIMIT_ETH_REFILL_RATE"); - let rateLimitETHLargeThreshold = helper.requireEnv("RATE_LIMIT_ETH_LARGE_THRESHOLD"); - let rateLimitUSDCAddr = helper.requireEnv("RATE_LIMIT_USDC_ADDR"); - let rateLimitUSDCCap = helper.requireEnv("RATE_LIMIT_USDC_CAPACITY"); - let rateLimitUSDCRefill = helper.requireEnv("RATE_LIMIT_USDC_REFILL_RATE"); - let rateLimitUSDCLargeThreshold = helper.requireEnv("RATE_LIMIT_USDC_LARGE_THRESHOLD"); - let rateLimitGUAddr = helper.requireEnv("RATE_LIMIT_GU_ADDR"); - let rateLimitGUCap = helper.requireEnv("RATE_LIMIT_GU_CAPACITY"); - let rateLimitGURefill = helper.requireEnv("RATE_LIMIT_GU_REFILL_RATE"); - let rateLimitGULargeThreshold = helper.requireEnv("RATE_LIMIT_GU_LARGE_THRESHOLD"); - let rateLimitCheckMateAddr = helper.requireEnv("RATE_LIMIT_CHECKMATE_ADDR"); - let rateLimitCheckMateCap = helper.requireEnv("RATE_LIMIT_CHECKMATE_CAPACITY"); - let rateLimitCheckMateRefill = helper.requireEnv("RATE_LIMIT_CHECKMATE_REFILL_RATE"); - let rateLimitCheckMateLargeThreshold = helper.requireEnv("RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD"); - let rateLimitGOGAddr = helper.requireEnv("RATE_LIMIT_GOG_ADDR"); - let rateLimitGOGCap = helper.requireEnv("RATE_LIMIT_GOG_CAPACITY"); - let rateLimitGOGRefill = helper.requireEnv("RATE_LIMIT_GOG_REFILL_RATE"); - let rateLimitGOGLargeThreshold = helper.requireEnv("RATE_LIMIT_GOG_LARGE_THRESHOLD"); - - // Read from contract file. - let data = fs.readFileSync(".child.bridge.contracts.json", 'utf-8'); - let childContracts = JSON.parse(data); - let childBridgeAddr = childContracts.CHILD_BRIDGE_ADDRESS; - let childAdaptorAddr = childContracts.CHILD_ADAPTOR_ADDRESS; - data = fs.readFileSync(".root.bridge.contracts.json", 'utf-8'); - let rootContracts = JSON.parse(data); - let rootBridgeAddr = rootContracts.ROOT_BRIDGE_ADDRESS; - let rootAdaptorAddr = rootContracts.ROOT_ADAPTOR_ADDRESS; - let rootTemplateAddr = rootContracts.ROOT_TOKEN_TEMPLATE; - - // Get admin address - const rootProvider = new ethers.providers.JsonRpcProvider(rootRPCURL, Number(rootChainID)); - let adminWallet; - if (rootDeployerSecret == "ledger") { - adminWallet = new LedgerSigner(rootProvider); - } else { - adminWallet = new ethers.Wallet(rootDeployerSecret, rootProvider); - } - let adminAddr = await adminWallet.getAddress(); - console.log("Deployer address is: ", adminAddr); - - // Get rate admin address - let rateAdminWallet; - if (rootRateAdminSecret == "ledger") { - rateAdminWallet = new LedgerSigner(rateAdminWallet); - } else { - rateAdminWallet = new ethers.Wallet(rootRateAdminSecret, rootProvider); - } - let rateAdminAddr = await rateAdminWallet.getAddress(); - console.log("Rate admin address is: ", rateAdminAddr); - - - // Execute - console.log("Initialise root contracts in..."); - await helper.waitForConfirmation(); - - // Initialise root bridge - let rootBridgeObj = JSON.parse(fs.readFileSync('../../out/RootERC20BridgeFlowRate.sol/RootERC20BridgeFlowRate.json', 'utf8')); - console.log("Initialise root bridge..."); - let rootBridge = new ethers.Contract(rootBridgeAddr, rootBridgeObj.abi, rootProvider); - let resp = await rootBridge.connect(adminWallet)["initialize((address,address,address,address,address),address,address,string,address,address,address,string,uint256,address)"]( - { - defaultAdmin: rootBridgeDefaultAdmin, - pauser: rootBridgePauser, - unpauser: rootBridgeUnpauser, - variableManager: rootBridgeVariableManager, - adaptorManager: rootBridgeAdaptorManager, - }, - rootAdaptorAddr, - childBridgeAddr, - ethers.utils.getAddress(childAdaptorAddr), - rootTemplateAddr, - rootIMXAddr, - rootWETHAddr, - childChainName, - ethers.utils.parseEther(imxDepositLimit), - rateAdminAddr); - await helper.waitForReceipt(resp.hash, rootProvider); - - // Configure rate - // IMX - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - rootIMXAddr, - ethers.utils.parseEther(rateLimitIMXCap), - ethers.utils.parseEther(rateLimitIMXRefill), - ethers.utils.parseEther(rateLimitIMXLargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // ETH - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - await rootBridge.NATIVE_ETH(), - ethers.utils.parseEther(rateLimitETHCap), - ethers.utils.parseEther(rateLimitETHRefill), - ethers.utils.parseEther(rateLimitETHLargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // USDC - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - rateLimitUSDCAddr, - ethers.utils.parseEther(rateLimitUSDCCap), - ethers.utils.parseEther(rateLimitUSDCRefill), - ethers.utils.parseEther(rateLimitUSDCLargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // GU - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - rateLimitGUAddr, - ethers.utils.parseEther(rateLimitGUCap), - ethers.utils.parseEther(rateLimitGURefill), - ethers.utils.parseEther(rateLimitGULargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // Checkmate - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - rateLimitCheckMateAddr, - ethers.utils.parseEther(rateLimitCheckMateCap), - ethers.utils.parseEther(rateLimitCheckMateRefill), - ethers.utils.parseEther(rateLimitCheckMateLargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // GOG - resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( - rateLimitGOGAddr, - ethers.utils.parseEther(rateLimitGOGCap), - ethers.utils.parseEther(rateLimitGOGRefill), - ethers.utils.parseEther(rateLimitGOGLargeThreshold) - ); - await helper.waitForReceipt(resp.hash, rootProvider); - - // Initialise root adaptor - let rootAdaptorObj = JSON.parse(fs.readFileSync('../../out/RootAxelarBridgeAdaptor.sol/RootAxelarBridgeAdaptor.json', 'utf8')); - console.log("Initialise root adaptor..."); - let rootAdaptor = new ethers.Contract(rootAdaptorAddr, rootAdaptorObj.abi, rootProvider); - resp = await rootAdaptor.connect(adminWallet).initialize( - { - defaultAdmin: rootAdaptorDefaultAdmin, - bridgeManager: rootAdaptorBridgeManager, - gasServiceManager: rootAdaptorGasServiceManager, - targetManager: rootAdaptorTargetManager, - }, - rootBridgeAddr, - childChainName, - rootGasServiceAddr); - await helper.waitForReceipt(resp.hash, rootProvider); + await init.initialiseRootContracts(); } run(); \ No newline at end of file diff --git a/scripts/deploy/.env.example b/scripts/deploy/.env.example new file mode 100644 index 00000000..db5187ee --- /dev/null +++ b/scripts/deploy/.env.example @@ -0,0 +1,115 @@ +# Access to child and root chains. +CHILD_CHAIN_NAME= +CHILD_RPC_URL= +CHILD_CHAIN_ID= +ROOT_CHAIN_NAME= +ROOT_RPC_URL= +ROOT_CHAIN_ID= +## The admin EOA address on the child chain that is allowed to top up the child bridge contract. +CHILD_ADMIN_ADDR= +## The multisig contract that is allowed to top up the child bridge contract. +MULTISIG_CONTRACT_ADDRESS= +## The private key for the deployer on child chain or "ledger" if using hardware wallet. +CHILD_DEPLOYER_SECRET= +## The private key for the deployer on root chain or "ledger" if using hardware wallet. +ROOT_DEPLOYER_SECRET= +## The private key for rate admin or "ledger" if using hardware wallet. +ROOT_BRIDGE_RATE_ADMIN_SECRET= +## The IMX token address on root chain. +ROOT_IMX_ADDR= +## The Wrapped ETH token address on the root chain. +ROOT_WETH_ADDR= +## The maximum amount of IMX that can be deposited to L2, unit is in IMX or 10^18 Wei. +IMX_DEPOSIT_LIMIT= +## The address to perform child bridge upgrade. +CHILD_PROXY_ADMIN= +## The address to be assigned with DEFAULT_ADMIN_ROLE in child bridge. +CHILD_BRIDGE_DEFAULT_ADMIN= +## The address to be assigned with PAUSER_ROLE in child bridge. +CHILD_BRIDGE_PAUSER= +## The address to be assigned with UNPAUSER_ROLE in child bridge. +CHILD_BRIDGE_UNPAUSER= +## The address to be assigned with ADAPTOR_MANAGER_ROLE in child bridge. +CHILD_BRIDGE_ADAPTOR_MANAGER= +## The address to be assigned with TREASURY_MANAGER_ROLE in child bridge. +CHILD_BRIDGE_TREASURY_MANAGER= +## The address to be assigned with DEFAULT_ADMIN_ROLE in child adaptor. +CHILD_ADAPTOR_DEFAULT_ADMIN= +## The address to be assigned with BRIDGE_MANAGER_ROLE in child adaptor. +CHILD_ADAPTOR_BRIDGE_MANAGER= +## The address to be assigned with GAS_SERVICE_MANAGER_ROLE in child adaptor. +CHILD_ADAPTOR_GAS_SERVICE_MANAGER= +## The address to be assigned with TARGET_MANAGER_ROLE in child adaptor. +CHILD_ADAPTOR_TARGET_MANAGER= +## The address to perform root adaptor upgrade. +ROOT_PROXY_ADMIN= +## The address to be assigned with DEFAULT_ADMIN_ROLE in root bridge. +ROOT_BRIDGE_DEFAULT_ADMIN= +## The address to be assigned with PAUSER_ROLE in root bridge. +ROOT_BRIDGE_PAUSER= +## The address to be assigned with UNPAUSER_ROLE in root bridge. +ROOT_BRIDGE_UNPAUSER= +## The address to be assigned with VARIABLE_MANAGER_ROLE in root bridge. +ROOT_BRIDGE_VARIABLE_MANAGER= +## The address to be assigned with ADAPTOR_MANAGER_ROLE in root bridge. +ROOT_BRIDGE_ADAPTOR_MANAGER= +## The address to be assigned with DEFAULT_ADMIN_ROLE in root adaptor. +ROOT_ADAPTOR_DEFAULT_ADMIN= +## The address to be assigned with BRIDGE_MANAGER_ROLE in root adaptor. +ROOT_ADAPTOR_BRIDGE_MANAGER= +## The address to be assigned with GAS_SERVICE_MANAGER_ROLE in root adaptor. +ROOT_ADAPTOR_GAS_SERVICE_MANAGER= +## The address to be assigned with TARGET_MANAGER_ROLE in root adaptor. +ROOT_ADAPTOR_TARGET_MANAGER= +## The capacity of the rate limit policy of IMX token, unit is in 10^18. +RATE_LIMIT_IMX_CAPACITY= +## The refill rate of the rate limit policy of IMX token, unit is in 10^18. +RATE_LIMIT_IMX_REFILL_RATE= +## The large threshold of the rate limit policy of IMX token, unit is in 10^18. +RATE_LIMIT_IMX_LARGE_THRESHOLD= +## The capacity of the rate limit policy of ETH token, unit is in 10^18. +RATE_LIMIT_ETH_CAPACITY= +## The refill rate of the rate limit policy of ETH token, unit is in 10^18. +RATE_LIMIT_ETH_REFILL_RATE= +## The large threshold of the rate limit policy of ETH token, unit is in 10^18. +RATE_LIMIT_ETH_LARGE_THRESHOLD= +## The address of USDC token to set rate limit policy. +RATE_LIMIT_USDC_ADDR= +## The capacity of the rate limit policy of USDC token, unit is in 10^18. +RATE_LIMIT_USDC_CAPACITY= +## The refill rate of the rate limit policy of USDC token, unit is in 10^18. +RATE_LIMIT_USDC_REFILL_RATE= +## The large threshold of the rate limit policy of USDC token, unit is in 10^18. +RATE_LIMIT_USDC_LARGE_THRESHOLD= +## The address of GU token to set rate limit policy. +RATE_LIMIT_GU_ADDR= +## The capacity of the rate limit policy of GU token, unit is in 10^18. +RATE_LIMIT_GU_CAPACITY= +## The refill rate of the rate limit policy of GU token, unit is in 10^18. +RATE_LIMIT_GU_REFILL_RATE= +## The large threshold of the rate limit policy of GU token, unit is in 10^18. +RATE_LIMIT_GU_LARGE_THRESHOLD= +## The address of CheckMate token to set rate limit policy. +RATE_LIMIT_CHECKMATE_ADDR= +## The capacity of the rate limit policy of CheckMate token, unit is in 10^18. +RATE_LIMIT_CHECKMATE_CAPACITY= +## The refill rate of the rate limit policy of CheckMate token, unit is in 10^18. +RATE_LIMIT_CHECKMATE_REFILL_RATE= +## The large threshold of the rate limit policy of CheckMate token, unit is in 10^18. +RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD= +## The address of GOG token to set rate limit policy. +RATE_LIMIT_GOG_ADDR= +## The capacity of the rate limit policy of GOG token, unit is in 10^18. +RATE_LIMIT_GOG_CAPACITY= +## The refill rate of the rate limit policy of GOG token, unit is in 10^18. +RATE_LIMIT_GOG_REFILL_RATE= +## The large threshold of the rate limit policy of GOG token, unit is in 10^18. +RATE_LIMIT_GOG_LARGE_THRESHOLD= +## The gateway contract on the child chain. +CHILD_GATEWAY_ADDRESS= +## The gas service contract on the child chain. +CHILD_GAS_SERVICE_ADDRESS= +## The gateway contract on the root chain. +ROOT_GATEWAY_ADDRESS= +## The gas service contract on the child chain. +ROOT_GAS_SERVICE_ADDRESS= \ No newline at end of file diff --git a/scripts/deploy/child_deployment.js b/scripts/deploy/child_deployment.js new file mode 100644 index 00000000..4de802d9 --- /dev/null +++ b/scripts/deploy/child_deployment.js @@ -0,0 +1,102 @@ +// Deploy child contracts +'use strict'; +require('dotenv').config(); +const { ethers } = require("ethers"); +const helper = require("../helpers/helpers.js"); +const { LedgerSigner } = require('@ethersproject/hardware-wallets') +const fs = require('fs'); + +exports.deployChildContracts = async () => { + // Check environment variables + let childRPCURL = helper.requireEnv("CHILD_RPC_URL"); + let childChainID = helper.requireEnv("CHILD_CHAIN_ID"); + let childDeployerSecret = helper.requireEnv("CHILD_DEPLOYER_SECRET"); + let childGatewayAddr = helper.requireEnv("CHILD_GATEWAY_ADDRESS"); + let childProxyAdmin = helper.requireEnv("CHILD_PROXY_ADMIN"); + + // Get admin address + const childProvider = new ethers.providers.JsonRpcProvider(childRPCURL, Number(childChainID)); + let adminWallet; + if (childDeployerSecret == "ledger") { + adminWallet = new LedgerSigner(childProvider); + } else { + adminWallet = new ethers.Wallet(childDeployerSecret, childProvider); + } + let adminAddr = await adminWallet.getAddress(); + console.log("Deployer address is: ", adminAddr); + + // Execute + console.log("Deploy child contracts in..."); + await helper.waitForConfirmation(); + + // Deploy child token template + let childTokenTemplateObj = JSON.parse(fs.readFileSync('../../out/ChildERC20.sol/ChildERC20.json', 'utf8')); + console.log("Deploy child token template..."); + let childTokenTemplate = await helper.deployChildContract(childTokenTemplateObj, adminWallet); + await helper.waitForReceipt(childTokenTemplate.deployTransaction.hash, childProvider); + // Initialise template + let [priorityFee, maxFee] = await helper.getFee(adminWallet); + let resp = await childTokenTemplate.connect(adminWallet).initialize("000000000000000000000000000000000000007B", "TEMPLATE", "TPT", 18, { + maxPriorityFeePerGas: priorityFee, + maxFeePerGas: maxFee, + }); + await helper.waitForReceipt(resp.hash, childProvider); + console.log("Deployed to CHILD_TOKEN_TEMPLATE: ", childTokenTemplate.address); + + // Deploy wrapped IMX + let wrappedIMXObj = JSON.parse(fs.readFileSync('../../out/WIMX.sol/WIMX.json', 'utf8')); + console.log("Deploy wrapped IMX..."); + let wrappedIMX = await helper.deployChildContract(wrappedIMXObj, adminWallet); + await helper.waitForReceipt(wrappedIMX.deployTransaction.hash, childProvider); + console.log("Deployed to WRAPPED_IMX_ADDRESS: ", wrappedIMX.address); + + // Deploy proxy admin + let proxyAdminObj = JSON.parse(fs.readFileSync('../../out/ProxyAdmin.sol/ProxyAdmin.json', 'utf8')); + console.log("Deploy proxy admin..."); + let proxyAdmin = await helper.deployChildContract(proxyAdminObj, adminWallet); + await helper.waitForReceipt(proxyAdmin.deployTransaction.hash, childProvider); + // Change owner + [priorityFee, maxFee] = await helper.getFee(adminWallet); + resp = await proxyAdmin.connect(adminWallet).transferOwnership(childProxyAdmin, { + maxPriorityFeePerGas: priorityFee, + maxFeePerGas: maxFee, + }); + await helper.waitForReceipt(resp.hash, childProvider); + console.log("Deployed to CHILD_PROXY_ADMIN: ", proxyAdmin.address); + + // Deploy child bridge impl + let childBridgeImplObj = JSON.parse(fs.readFileSync('../../out/ChildERC20Bridge.sol/ChildERC20Bridge.json', 'utf8')); + console.log("Deploy child bridge impl..."); + let childBridgeImpl = await helper.deployChildContract(childBridgeImplObj, adminWallet); + await helper.waitForReceipt(childBridgeImpl.deployTransaction.hash, childProvider); + console.log("Deployed to CHILD_BRIDGE_IMPL_ADDRESS: ", childBridgeImpl.address); + + // Deploy child bridge proxy + let childBridgeProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); + console.log("Deploy child bridge proxy..."); + let childBridgeProxy = await helper.deployChildContract(childBridgeProxyObj, adminWallet, childBridgeImpl.address, proxyAdmin.address, []); + await helper.waitForReceipt(childBridgeProxy.deployTransaction.hash, childProvider); + console.log("Deployed to CHILD_BRIDGE_PROXY_ADDRESS: ", childBridgeProxy.address); + + // Deploy child adaptor impl + let childAdaptorImplObj = JSON.parse(fs.readFileSync('../../out/ChildAxelarBridgeAdaptor.sol/ChildAxelarBridgeAdaptor.json', 'utf8')); + console.log("Deploy child adaptor impl..."); + let childAdaptorImpl = await helper.deployChildContract(childAdaptorImplObj, adminWallet, childGatewayAddr); + await helper.waitForReceipt(childAdaptorImpl.deployTransaction.hash, childProvider); + console.log("Deployed to CHILD_ADAPTOR_IMPL_ADDRESS: ", childAdaptorImpl.address); + + // Deploy child adaptor proxy + let childAdaptorProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); + console.log("Deploy child adaptor proxy..."); + let childAdaptorProxy = await helper.deployChildContract(childAdaptorProxyObj, adminWallet, childAdaptorImpl.address, proxyAdmin.address, []); + await helper.waitForReceipt(childAdaptorProxy.deployTransaction.hash, childProvider); + console.log("Deployed to CHILD_ADAPTOR_PROXY_ADDRESS: ", childAdaptorProxy.address); + + let contractData = { + CHILD_BRIDGE_ADDRESS: childBridgeProxy.address, + CHILD_ADAPTOR_ADDRESS: childAdaptorProxy.address, + WRAPPED_IMX_ADDRESS: wrappedIMX.address, + CHILD_TOKEN_TEMPLATE: childTokenTemplate.address, + }; + fs.writeFileSync(".child.bridge.contracts.json", JSON.stringify(contractData, null, 2)); +} \ No newline at end of file diff --git a/scripts/deploy/child_initialisation.js b/scripts/deploy/child_initialisation.js new file mode 100644 index 00000000..01ea2b40 --- /dev/null +++ b/scripts/deploy/child_initialisation.js @@ -0,0 +1,101 @@ +// Initialise child contracts +'use strict'; +require('dotenv').config(); +const { ethers } = require("ethers"); +const helper = require("../helpers/helpers.js"); +const { LedgerSigner } = require('@ethersproject/hardware-wallets') +const fs = require('fs'); + +exports.initialiseChildContracts = async () => { + let rootChainName = helper.requireEnv("ROOT_CHAIN_NAME"); + let childRPCURL = helper.requireEnv("CHILD_RPC_URL"); + let childChainID = helper.requireEnv("CHILD_CHAIN_ID"); + let adminEOAAddr = helper.requireEnv("CHILD_ADMIN_ADDR"); + let childBridgeDefaultAdmin = helper.requireEnv("CHILD_BRIDGE_DEFAULT_ADMIN"); + let childBridgePauser = helper.requireEnv("CHILD_BRIDGE_PAUSER"); + let childBridgeUnpauser = helper.requireEnv("CHILD_BRIDGE_UNPAUSER"); + let childBridgeAdaptorManager = helper.requireEnv("CHILD_BRIDGE_ADAPTOR_MANAGER"); + let childBridgeTreasuryManager = helper.requireEnv("CHILD_BRIDGE_TREASURY_MANAGER"); + let childAdaptorDefaultAdmin = helper.requireEnv("CHILD_ADAPTOR_DEFAULT_ADMIN"); + let childAdaptorBridgeManager = helper.requireEnv("CHILD_ADAPTOR_BRIDGE_MANAGER"); + let childAdaptorGasServiceManager = helper.requireEnv("CHILD_ADAPTOR_GAS_SERVICE_MANAGER"); + let childAdaptorTargetManager = helper.requireEnv("CHILD_ADAPTOR_TARGET_MANAGER"); + let childDeployerSecret = helper.requireEnv("CHILD_DEPLOYER_SECRET"); + let childGasServiceAddr = helper.requireEnv("CHILD_GAS_SERVICE_ADDRESS"); + let multisigAddr = helper.requireEnv("MULTISIG_CONTRACT_ADDRESS"); + let rootIMXAddr = helper.requireEnv("ROOT_IMX_ADDR"); + + // Read from contract file. + let data = fs.readFileSync(".child.bridge.contracts.json", 'utf-8'); + let childContracts = JSON.parse(data); + let childBridgeAddr = childContracts.CHILD_BRIDGE_ADDRESS; + let childAdaptorAddr = childContracts.CHILD_ADAPTOR_ADDRESS; + let childWIMXAddr = childContracts.WRAPPED_IMX_ADDRESS; + let childTemplateAddr = childContracts.CHILD_TOKEN_TEMPLATE; + data = fs.readFileSync(".root.bridge.contracts.json", 'utf-8'); + let rootContracts = JSON.parse(data); + let rootAdaptorAddr = rootContracts.ROOT_ADAPTOR_ADDRESS; + + // Get admin address + const childProvider = new ethers.providers.JsonRpcProvider(childRPCURL, Number(childChainID)); + let adminWallet; + if (childDeployerSecret == "ledger") { + adminWallet = new LedgerSigner(childProvider); + } else { + adminWallet = new ethers.Wallet(childDeployerSecret, childProvider); + } + let adminAddr = await adminWallet.getAddress(); + console.log("Deployer address is: ", adminAddr); + + // Execute + console.log("Initialise child contracts in..."); + await helper.waitForConfirmation(); + + // Initialise child bridge + let childBridgeObj = JSON.parse(fs.readFileSync('../../out/ChildERC20Bridge.sol/ChildERC20Bridge.json', 'utf8')); + console.log("Initialise child bridge..."); + let childBridge = new ethers.Contract(childBridgeAddr, childBridgeObj.abi, childProvider); + let [priorityFee, maxFee] = await helper.getFee(adminWallet); + let resp = await childBridge.connect(adminWallet).initialize( + { + defaultAdmin: childBridgeDefaultAdmin, + pauser: childBridgePauser, + unpauser: childBridgeUnpauser, + adaptorManager: childBridgeAdaptorManager, + treasuryManager: childBridgeTreasuryManager, + }, + childAdaptorAddr, + ethers.utils.getAddress(rootAdaptorAddr), + childTemplateAddr, + rootChainName, + rootIMXAddr, + childWIMXAddr, + multisigAddr, + adminEOAAddr, + { + maxPriorityFeePerGas: priorityFee, + maxFeePerGas: maxFee, + }); + await helper.waitForReceipt(resp.hash, childProvider); + + // Initialise child adaptor + let childAdaptorObj = JSON.parse(fs.readFileSync('../../out/ChildAxelarBridgeAdaptor.sol/ChildAxelarBridgeAdaptor.json', 'utf8')); + console.log("Initialise child adaptor..."); + let childAdaptor = new ethers.Contract(childAdaptorAddr, childAdaptorObj.abi, childProvider); + [priorityFee, maxFee] = await helper.getFee(adminWallet); + resp = await childAdaptor.connect(adminWallet).initialize( + { + defaultAdmin: childAdaptorDefaultAdmin, + bridgeManager: childAdaptorBridgeManager, + gasServiceManager: childAdaptorGasServiceManager, + targetManager: childAdaptorTargetManager, + }, + rootChainName, + childBridgeAddr, + childGasServiceAddr, + { + maxPriorityFeePerGas: priorityFee, + maxFeePerGas: maxFee, + }); + await helper.waitForReceipt(resp.hash, childProvider); +} \ No newline at end of file diff --git a/scripts/deploy/deployAndInit.js b/scripts/deploy/deployAndInit.js new file mode 100644 index 00000000..78243245 --- /dev/null +++ b/scripts/deploy/deployAndInit.js @@ -0,0 +1,14 @@ +'use strict'; +require('dotenv').config(); +const deployChild = require("./child_deployment.js"); +const initChild = require("./child_initialisation.js"); +const deployRoot = require("./root_deployment.js"); +const initRoot = require("./root_initialisation.js"); + +async function run() { + await deployChild.deployChildContracts(); + await deployRoot.deployRootContracts(); + await initChild.initialiseChildContracts(); + await initRoot.initialiseRootContracts(); +} +run(); \ No newline at end of file diff --git a/scripts/deploy/root_deployment.js b/scripts/deploy/root_deployment.js new file mode 100644 index 00000000..0bff1fe8 --- /dev/null +++ b/scripts/deploy/root_deployment.js @@ -0,0 +1,86 @@ +// Deploy root contracts +'use strict'; +require('dotenv').config(); +const { ethers } = require("ethers"); +const helper = require("../helpers/helpers.js"); +const { LedgerSigner } = require('@ethersproject/hardware-wallets') +const fs = require('fs'); + +exports.deployRootContracts = async () => { + // Check environment variables + let rootRPCURL = helper.requireEnv("ROOT_RPC_URL"); + let rootChainID = helper.requireEnv("ROOT_CHAIN_ID"); + let rootDeployerSecret = helper.requireEnv("ROOT_DEPLOYER_SECRET"); + let rootProxyAdmin = helper.requireEnv("ROOT_PROXY_ADMIN"); + let rootGatewayAddr = helper.requireEnv("ROOT_GATEWAY_ADDRESS"); + + // Get admin address + const rootProvider = new ethers.providers.JsonRpcProvider(rootRPCURL, Number(rootChainID)); + let adminWallet; + if (rootDeployerSecret == "ledger") { + adminWallet = new LedgerSigner(rootProvider); + } else { + adminWallet = new ethers.Wallet(rootDeployerSecret, rootProvider); + } + let adminAddr = await adminWallet.getAddress(); + console.log("Deployer address is: ", adminAddr); + + // Execute + console.log("Deploy root contracts in..."); + await helper.waitForConfirmation(); + + // Deploy root token template + let rootTokenTemplateObj = JSON.parse(fs.readFileSync('../../out/ChildERC20.sol/ChildERC20.json', 'utf8')); + console.log("Deploy root token template..."); + let rootTokenTemplate = await helper.deployRootContract(rootTokenTemplateObj, adminWallet); + await helper.waitForReceipt(rootTokenTemplate.deployTransaction.hash, rootProvider); + // Initialise template + let resp = await rootTokenTemplate.connect(adminWallet).initialize("000000000000000000000000000000000000007B", "TEMPLATE", "TPT", 18); + await helper.waitForReceipt(resp.hash, rootProvider); + console.log("Deployed to ROOT_TOKEN_TEMPLATE: ", rootTokenTemplate.address); + + // Deploy proxy admin + let proxyAdminObj = JSON.parse(fs.readFileSync('../../out/ProxyAdmin.sol/ProxyAdmin.json', 'utf8')); + console.log("Deploy proxy admin..."); + let proxyAdmin = await helper.deployRootContract(proxyAdminObj, adminWallet); + await helper.waitForReceipt(proxyAdmin.deployTransaction.hash, rootProvider); + // Change owner + resp = await proxyAdmin.connect(adminWallet).transferOwnership(rootProxyAdmin); + await helper.waitForReceipt(resp.hash, rootProvider); + console.log("Deployed to ROOT_PROXY_ADMIN: ", proxyAdmin.address); + + // Deploy root bridge impl + let rootBridgeImplObj = JSON.parse(fs.readFileSync('../../out/RootERC20BridgeFlowRate.sol/RootERC20BridgeFlowRate.json', 'utf8')); + console.log("Deploy root bridge impl..."); + let rootBridgeImpl = await helper.deployRootContract(rootBridgeImplObj, adminWallet); + await helper.waitForReceipt(rootBridgeImpl.deployTransaction.hash, rootProvider); + console.log("Deployed to ROOT_BRIDGE_IMPL_ADDRESS: ", rootBridgeImpl.address); + + // Deploy root bridge proxy + let rootBridgeProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); + console.log("Deploy root bridge proxy..."); + let rootBridgeProxy = await helper.deployRootContract(rootBridgeProxyObj, adminWallet, rootBridgeImpl.address, proxyAdmin.address, []); + await helper.waitForReceipt(rootBridgeProxy.deployTransaction.hash, rootProvider); + console.log("Deployed to ROOT_BRIDGE_PROXY_ADDRESS: ", rootBridgeProxy.address); + + // Deploy root adaptor impl + let rootAdaptorImplObj = JSON.parse(fs.readFileSync('../../out/RootAxelarBridgeAdaptor.sol/RootAxelarBridgeAdaptor.json', 'utf8')); + console.log("Deploy root adaptor impl..."); + let rootAdaptorImpl = await helper.deployRootContract(rootAdaptorImplObj, adminWallet, rootGatewayAddr); + await helper.waitForReceipt(rootAdaptorImpl.deployTransaction.hash, rootProvider); + console.log("Deployed to ROOT_ADAPTOR_IMPL_ADDRESS: ", rootAdaptorImpl.address); + + // Deploy root adaptor proxy + let rootAdaptorProxyObj = JSON.parse(fs.readFileSync('../../out/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json', 'utf8')); + console.log("Deploy root adaptor proxy..."); + let rootAdaptorProxy = await helper.deployRootContract(rootAdaptorProxyObj, adminWallet, rootAdaptorImpl.address, proxyAdmin.address, []); + await helper.waitForReceipt(rootAdaptorProxy.deployTransaction.hash, rootProvider); + console.log("Deployed to ROOT_ADAPTOR_PROXY_ADDRESS: ", rootAdaptorProxy.address); + + let contractData = { + ROOT_BRIDGE_ADDRESS: rootBridgeProxy.address, + ROOT_ADAPTOR_ADDRESS: rootAdaptorProxy.address, + ROOT_TOKEN_TEMPLATE: rootTokenTemplate.address, + }; + fs.writeFileSync(".root.bridge.contracts.json", JSON.stringify(contractData, null, 2)); +} \ No newline at end of file diff --git a/scripts/deploy/root_initialisation.js b/scripts/deploy/root_initialisation.js new file mode 100644 index 00000000..0062b70f --- /dev/null +++ b/scripts/deploy/root_initialisation.js @@ -0,0 +1,182 @@ +// Initialise root contracts +'use strict'; +require('dotenv').config(); +const { ethers } = require("ethers"); +const helper = require("../helpers/helpers.js"); +const { LedgerSigner } = require('@ethersproject/hardware-wallets') +const fs = require('fs'); + +exports.initialiseRootContracts = async() => { + // Check environment variables + let childChainName = helper.requireEnv("CHILD_CHAIN_NAME"); + let rootRPCURL = helper.requireEnv("ROOT_RPC_URL"); + let rootChainID = helper.requireEnv("ROOT_CHAIN_ID"); + let rootDeployerSecret = helper.requireEnv("ROOT_DEPLOYER_SECRET"); + let rootRateAdminSecret = helper.requireEnv("ROOT_BRIDGE_RATE_ADMIN_SECRET"); + let rootBridgeDefaultAdmin = helper.requireEnv("ROOT_BRIDGE_DEFAULT_ADMIN"); + let rootBridgePauser = helper.requireEnv("ROOT_BRIDGE_PAUSER"); + let rootBridgeUnpauser = helper.requireEnv("ROOT_BRIDGE_UNPAUSER"); + let rootBridgeVariableManager = helper.requireEnv("ROOT_BRIDGE_VARIABLE_MANAGER"); + let rootBridgeAdaptorManager = helper.requireEnv("ROOT_BRIDGE_ADAPTOR_MANAGER"); + let rootAdaptorDefaultAdmin = helper.requireEnv("ROOT_ADAPTOR_DEFAULT_ADMIN"); + let rootAdaptorBridgeManager = helper.requireEnv("ROOT_ADAPTOR_BRIDGE_MANAGER"); + let rootAdaptorGasServiceManager = helper.requireEnv("ROOT_ADAPTOR_GAS_SERVICE_MANAGER"); + let rootAdaptorTargetManager = helper.requireEnv("ROOT_ADAPTOR_TARGET_MANAGER"); + let rootGasServiceAddr = helper.requireEnv("ROOT_GAS_SERVICE_ADDRESS"); + let rootIMXAddr = helper.requireEnv("ROOT_IMX_ADDR"); + let rootWETHAddr = helper.requireEnv("ROOT_WETH_ADDR"); + let imxDepositLimit = helper.requireEnv("IMX_DEPOSIT_LIMIT"); + let rateLimitIMXCap = helper.requireEnv("RATE_LIMIT_IMX_CAPACITY"); + let rateLimitIMXRefill = helper.requireEnv("RATE_LIMIT_IMX_REFILL_RATE"); + let rateLimitIMXLargeThreshold = helper.requireEnv("RATE_LIMIT_IMX_LARGE_THRESHOLD"); + let rateLimitETHCap = helper.requireEnv("RATE_LIMIT_ETH_CAPACITY"); + let rateLimitETHRefill = helper.requireEnv("RATE_LIMIT_ETH_REFILL_RATE"); + let rateLimitETHLargeThreshold = helper.requireEnv("RATE_LIMIT_ETH_LARGE_THRESHOLD"); + let rateLimitUSDCAddr = helper.requireEnv("RATE_LIMIT_USDC_ADDR"); + let rateLimitUSDCCap = helper.requireEnv("RATE_LIMIT_USDC_CAPACITY"); + let rateLimitUSDCRefill = helper.requireEnv("RATE_LIMIT_USDC_REFILL_RATE"); + let rateLimitUSDCLargeThreshold = helper.requireEnv("RATE_LIMIT_USDC_LARGE_THRESHOLD"); + let rateLimitGUAddr = helper.requireEnv("RATE_LIMIT_GU_ADDR"); + let rateLimitGUCap = helper.requireEnv("RATE_LIMIT_GU_CAPACITY"); + let rateLimitGURefill = helper.requireEnv("RATE_LIMIT_GU_REFILL_RATE"); + let rateLimitGULargeThreshold = helper.requireEnv("RATE_LIMIT_GU_LARGE_THRESHOLD"); + let rateLimitCheckMateAddr = helper.requireEnv("RATE_LIMIT_CHECKMATE_ADDR"); + let rateLimitCheckMateCap = helper.requireEnv("RATE_LIMIT_CHECKMATE_CAPACITY"); + let rateLimitCheckMateRefill = helper.requireEnv("RATE_LIMIT_CHECKMATE_REFILL_RATE"); + let rateLimitCheckMateLargeThreshold = helper.requireEnv("RATE_LIMIT_CHECKMATE_LARGE_THRESHOLD"); + let rateLimitGOGAddr = helper.requireEnv("RATE_LIMIT_GOG_ADDR"); + let rateLimitGOGCap = helper.requireEnv("RATE_LIMIT_GOG_CAPACITY"); + let rateLimitGOGRefill = helper.requireEnv("RATE_LIMIT_GOG_REFILL_RATE"); + let rateLimitGOGLargeThreshold = helper.requireEnv("RATE_LIMIT_GOG_LARGE_THRESHOLD"); + + // Read from contract file. + let data = fs.readFileSync(".child.bridge.contracts.json", 'utf-8'); + let childContracts = JSON.parse(data); + let childBridgeAddr = childContracts.CHILD_BRIDGE_ADDRESS; + let childAdaptorAddr = childContracts.CHILD_ADAPTOR_ADDRESS; + data = fs.readFileSync(".root.bridge.contracts.json", 'utf-8'); + let rootContracts = JSON.parse(data); + let rootBridgeAddr = rootContracts.ROOT_BRIDGE_ADDRESS; + let rootAdaptorAddr = rootContracts.ROOT_ADAPTOR_ADDRESS; + let rootTemplateAddr = rootContracts.ROOT_TOKEN_TEMPLATE; + + // Get admin address + const rootProvider = new ethers.providers.JsonRpcProvider(rootRPCURL, Number(rootChainID)); + let adminWallet; + if (rootDeployerSecret == "ledger") { + adminWallet = new LedgerSigner(rootProvider); + } else { + adminWallet = new ethers.Wallet(rootDeployerSecret, rootProvider); + } + let adminAddr = await adminWallet.getAddress(); + console.log("Deployer address is: ", adminAddr); + + // Get rate admin address + let rateAdminWallet; + if (rootRateAdminSecret == "ledger") { + rateAdminWallet = new LedgerSigner(rateAdminWallet); + } else { + rateAdminWallet = new ethers.Wallet(rootRateAdminSecret, rootProvider); + } + let rateAdminAddr = await rateAdminWallet.getAddress(); + console.log("Rate admin address is: ", rateAdminAddr); + + + // Execute + console.log("Initialise root contracts in..."); + await helper.waitForConfirmation(); + + // Initialise root bridge + let rootBridgeObj = JSON.parse(fs.readFileSync('../../out/RootERC20BridgeFlowRate.sol/RootERC20BridgeFlowRate.json', 'utf8')); + console.log("Initialise root bridge..."); + let rootBridge = new ethers.Contract(rootBridgeAddr, rootBridgeObj.abi, rootProvider); + let resp = await rootBridge.connect(adminWallet)["initialize((address,address,address,address,address),address,address,string,address,address,address,string,uint256,address)"]( + { + defaultAdmin: rootBridgeDefaultAdmin, + pauser: rootBridgePauser, + unpauser: rootBridgeUnpauser, + variableManager: rootBridgeVariableManager, + adaptorManager: rootBridgeAdaptorManager, + }, + rootAdaptorAddr, + childBridgeAddr, + ethers.utils.getAddress(childAdaptorAddr), + rootTemplateAddr, + rootIMXAddr, + rootWETHAddr, + childChainName, + ethers.utils.parseEther(imxDepositLimit), + rateAdminAddr); + await helper.waitForReceipt(resp.hash, rootProvider); + + // Configure rate + // IMX + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + rootIMXAddr, + ethers.utils.parseEther(rateLimitIMXCap), + ethers.utils.parseEther(rateLimitIMXRefill), + ethers.utils.parseEther(rateLimitIMXLargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // ETH + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + await rootBridge.NATIVE_ETH(), + ethers.utils.parseEther(rateLimitETHCap), + ethers.utils.parseEther(rateLimitETHRefill), + ethers.utils.parseEther(rateLimitETHLargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // USDC + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + rateLimitUSDCAddr, + ethers.utils.parseEther(rateLimitUSDCCap), + ethers.utils.parseEther(rateLimitUSDCRefill), + ethers.utils.parseEther(rateLimitUSDCLargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // GU + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + rateLimitGUAddr, + ethers.utils.parseEther(rateLimitGUCap), + ethers.utils.parseEther(rateLimitGURefill), + ethers.utils.parseEther(rateLimitGULargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // Checkmate + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + rateLimitCheckMateAddr, + ethers.utils.parseEther(rateLimitCheckMateCap), + ethers.utils.parseEther(rateLimitCheckMateRefill), + ethers.utils.parseEther(rateLimitCheckMateLargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // GOG + resp = await rootBridge.connect(rateAdminWallet).setRateControlThreshold( + rateLimitGOGAddr, + ethers.utils.parseEther(rateLimitGOGCap), + ethers.utils.parseEther(rateLimitGOGRefill), + ethers.utils.parseEther(rateLimitGOGLargeThreshold) + ); + await helper.waitForReceipt(resp.hash, rootProvider); + + // Initialise root adaptor + let rootAdaptorObj = JSON.parse(fs.readFileSync('../../out/RootAxelarBridgeAdaptor.sol/RootAxelarBridgeAdaptor.json', 'utf8')); + console.log("Initialise root adaptor..."); + let rootAdaptor = new ethers.Contract(rootAdaptorAddr, rootAdaptorObj.abi, rootProvider); + resp = await rootAdaptor.connect(adminWallet).initialize( + { + defaultAdmin: rootAdaptorDefaultAdmin, + bridgeManager: rootAdaptorBridgeManager, + gasServiceManager: rootAdaptorGasServiceManager, + targetManager: rootAdaptorTargetManager, + }, + rootBridgeAddr, + childChainName, + rootGasServiceAddr); + await helper.waitForReceipt(resp.hash, rootProvider); +} \ No newline at end of file