Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Nov 22, 2023
1 parent 09177bb commit 7806a5c
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 447 deletions.
98 changes: 2 additions & 96 deletions scripts/bootstrap/3_child_deployment.js
Original file line number Diff line number Diff line change
@@ -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();
82 changes: 2 additions & 80 deletions scripts/bootstrap/4_root_deployment.js
Original file line number Diff line number Diff line change
@@ -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();
97 changes: 2 additions & 95 deletions scripts/bootstrap/5_child_initialisation.js
Original file line number Diff line number Diff line change
@@ -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();
Loading

0 comments on commit 7806a5c

Please sign in to comment.