activateChainPaths.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { POOLS } = require("@layerzerolabs/sg-sdk")
  2. const { getEndpointId } = require("../utils/network")
  3. const { getEndpointIdByName } = require("@layerzerolabs/lz-sdk")
  4. task("activateChainPaths", "activate chain paths")
  5. .addParam("targetNetwork", "activate chain paths for this destination targetNetwork")
  6. .setAction(async (taskArgs) => {
  7. let router = await ethers.getContract("Router")
  8. console.log(`router.address: ${router.address}`)
  9. const poolData = POOLS[hre.network.name]
  10. let tx
  11. for (let srcPoolId in poolData) {
  12. console.log(`mapping ${hre.network.name}[${getEndpointId()}] srcPoolId: ${srcPoolId}:`)
  13. let chainPaths = poolData[srcPoolId].chainPaths
  14. for (let dstObj of chainPaths) {
  15. let { dstChainId, dstPoolId, weight } = dstObj
  16. if (dstChainId != getEndpointIdByName(taskArgs.targetNetwork)) {
  17. continue
  18. }
  19. try {
  20. tx = await (await router.activateChainPath(srcPoolId, dstChainId, dstPoolId)).wait()
  21. console.log(
  22. ` ✅ activateChainPath: poolId:${srcPoolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} | tx: ${tx.transactionHash}`
  23. )
  24. } catch (e) {
  25. if (e.error.message.includes("Stargate: chainPath is already active")) {
  26. console.log(
  27. ` ✅ activateChainPath: poolId:${srcPoolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} | *already exists*`
  28. )
  29. } else {
  30. console.log(e)
  31. console.log("^ ERROR")
  32. }
  33. }
  34. }
  35. }
  36. })