wireBridges.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const CONFIG = require("../constants/config.json")
  2. const {getDeploymentAddresses} = require("../utils/readDeployments")
  3. const {getEndpointIdByName} = require("../utils/layerzero")
  4. task("wireBridges", "connect the local mirrorgate to a remote mirrorgate by configuring the remote bridge")
  5. .addParam("targetNetworks", "the remote mirrorgate instance named by network")
  6. .setAction(async (taskArgs, hre) => {
  7. let accounts = await ethers.getSigners()
  8. let owner = accounts[0] // me
  9. // console.log(`owner: ${owner.address}`);
  10. const Bridge = await ethers.getContractFactory("Bridge")
  11. const bridgeAddr = (await hre.deployments.get("Bridge")).address
  12. const bridge = await Bridge.attach(bridgeAddr)
  13. let targetNetworks = taskArgs.targetNetworks.split(",")
  14. console.log(`${hre.network.name}: setting local functionType gas and remote bridge...`)
  15. for (let targetNetwork of targetNetworks) {
  16. let targetNetworkAddrs = getDeploymentAddresses(targetNetwork)
  17. // console.log(targetNetworkAddrs);
  18. let chainId = getEndpointIdByName(targetNetwork)
  19. let numFunctionTypes = Object.keys(CONFIG.gasAmounts).length
  20. for (let functionType = 1; functionType <= numFunctionTypes; ++functionType) {
  21. let gasAmount = CONFIG.gasAmounts[functionType]
  22. let currentAmount = await bridge.gasLookup(chainId, functionType)
  23. if (currentAmount.eq(gasAmount)) {
  24. console.log(
  25. ` ✅ ${hre.network.name} > bridge.setGasAmount(chainId:${chainId}, functionType:${functionType}, gasAmount:${gasAmount}) | *already set*`
  26. )
  27. } else {
  28. await (await bridge.setGasAmount(chainId, functionType, gasAmount)).wait()
  29. console.log(
  30. ` ✅ ${hre.network.name} > bridge.setGasAmount(chainId:${chainId}, functionType:${functionType}, gasAmount:${gasAmount})`
  31. )
  32. }
  33. }
  34. let currBridge = await bridge.bridgeLookup(chainId)
  35. let targetBridgeAddr = "0x" + ethers.utils.getAddress(targetNetworkAddrs["Bridge"]).substring(2) + bridgeAddr.substring(2); // cast to standardized address
  36. if (currBridge !== "0x" && ethers.utils.getAddress(currBridge) == targetBridgeAddr) {
  37. // its nto a bridge
  38. console.log(`✅ ${hre.network.name} > setBridge(${chainId}, ${targetBridgeAddr}) | *already set*`)
  39. } else {
  40. // setBridge , 1-time only call. better do it right!
  41. let tx = await (await bridge.setBridge(chainId, targetBridgeAddr)).wait()
  42. console.log(` ✅ ${hre.network.name} > setBridge(${chainId}, ${targetBridgeAddr}) | tx: ${tx.transactionHash}`)
  43. }
  44. }
  45. })