12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const CONFIG = require("../constants/config.json")
- const {getDeploymentAddresses} = require("../utils/readDeployments")
- const {getEndpointIdByName} = require("../utils/layerzero")
- task("wireBridges", "connect the local mirrorgate to a remote mirrorgate by configuring the remote bridge")
- .addParam("targetNetworks", "the remote mirrorgate instance named by network")
- .setAction(async (taskArgs, hre) => {
- let accounts = await ethers.getSigners()
- let owner = accounts[0] // me
- // console.log(`owner: ${owner.address}`);
- const Bridge = await ethers.getContractFactory("Bridge")
- const bridgeAddr = (await hre.deployments.get("Bridge")).address
- const bridge = await Bridge.attach(bridgeAddr)
- let targetNetworks = taskArgs.targetNetworks.split(",")
- console.log(`${hre.network.name}: setting local functionType gas and remote bridge...`)
- for (let targetNetwork of targetNetworks) {
- let targetNetworkAddrs = getDeploymentAddresses(targetNetwork)
- // console.log(targetNetworkAddrs);
- let chainId = getEndpointIdByName(targetNetwork)
- let numFunctionTypes = Object.keys(CONFIG.gasAmounts).length
- for (let functionType = 1; functionType <= numFunctionTypes; ++functionType) {
- let gasAmount = CONFIG.gasAmounts[functionType]
- let currentAmount = await bridge.gasLookup(chainId, functionType)
- if (currentAmount.eq(gasAmount)) {
- console.log(
- ` ✅ ${hre.network.name} > bridge.setGasAmount(chainId:${chainId}, functionType:${functionType}, gasAmount:${gasAmount}) | *already set*`
- )
- } else {
- await (await bridge.setGasAmount(chainId, functionType, gasAmount)).wait()
- console.log(
- ` ✅ ${hre.network.name} > bridge.setGasAmount(chainId:${chainId}, functionType:${functionType}, gasAmount:${gasAmount})`
- )
- }
- }
- let currBridge = await bridge.bridgeLookup(chainId)
- let targetBridgeAddr = "0x" + ethers.utils.getAddress(targetNetworkAddrs["Bridge"]).substring(2) + bridgeAddr.substring(2); // cast to standardized address
- if (currBridge !== "0x" && ethers.utils.getAddress(currBridge) == targetBridgeAddr) {
- // its nto a bridge
- console.log(`✅ ${hre.network.name} > setBridge(${chainId}, ${targetBridgeAddr}) | *already set*`)
- } else {
- // setBridge , 1-time only call. better do it right!
- let tx = await (await bridge.setBridge(chainId, targetBridgeAddr)).wait()
- console.log(` ✅ ${hre.network.name} > setBridge(${chainId}, ${targetBridgeAddr}) | tx: ${tx.transactionHash}`)
- }
- }
- })
|