const {getDeploymentAddresses} = require("../utils/readDeployments") const {getEndpointIdByName} = require("../utils/layerzero") task("wireMirrorgateTokens", "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) => { const Mirrorgate = await ethers.getContractFactory("MirrorgateToken") const mirrorgateTokenAddr = (await hre.deployments.get("MirrorgateToken")).address const mirrorgateToken = await Mirrorgate.attach(mirrorgateTokenAddr) let targetNetworks = taskArgs.targetNetworks.split(",") for (let targetNetwork of targetNetworks) { let targetNetworkAddrs = getDeploymentAddresses(targetNetwork) let dstChainId = getEndpointIdByName(targetNetwork) let currenDstMirrorgateAddr = await mirrorgateToken.dstContractLookup(dstChainId) let targetMirrorgateTokenAddr = ethers.utils.getAddress(targetNetworkAddrs["MirrorgateToken"]) // cast to standardized address if (currenDstMirrorgateAddr !== "0x" && ethers.utils.getAddress(currenDstMirrorgateAddr) == targetMirrorgateTokenAddr) { console.log(` ✅ ${hre.network.name} > setDestination(${dstChainId}, ${targetMirrorgateTokenAddr}) | *already set*`) } else { let tx = await (await mirrorgateToken.setDestination(dstChainId, targetMirrorgateTokenAddr)).wait(1) console.log(` ✅ ${hre.network.name} > setDestination(${dstChainId}, ${targetMirrorgateTokenAddr}) | tx: ${tx.transactionHash}`) } } })