makeChainPathsActive.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { getEndpointIdByName } = require("@layerzerolabs/lz-sdk")
  2. task("makeChainPathsActive", "activate the chainPaths for a pool")
  3. .addParam("poolId", "the pool id to create chain paths for")
  4. .addParam("targetNetworks", "csv network names to connect the local pool to remotely")
  5. .addParam("dstPoolIds", "csv of dstPoolIds to create chain paths for")
  6. .setAction(async (taskArgs) => {
  7. const Router = await ethers.getContractFactory("Router")
  8. const routerAddr = (await hre.deployments.get("Router")).address
  9. const router = await Router.attach(routerAddr)
  10. // get Factory to get pool
  11. const Factory = await ethers.getContractFactory("Factory")
  12. const factoryAddr = (await hre.deployments.get("Factory")).address
  13. const factory = await Factory.attach(factoryAddr)
  14. // get Pool
  15. let Pool = await ethers.getContractFactory("Pool")
  16. let poolData = await factory.getPool(taskArgs.poolId)
  17. let pool = await Pool.attach(poolData)
  18. let dstPoolIds = taskArgs.dstPoolIds.split(",")
  19. let targetNetworks = taskArgs.targetNetworks.split(",")
  20. for (let targetNetwork of targetNetworks) {
  21. let dstChainId = getEndpointIdByName(targetNetwork)
  22. for (let dstPoolId of dstPoolIds) {
  23. let chainPathIndex = await pool.chainPathIndexLookup(dstChainId, dstPoolId)
  24. let chainPath = await pool.chainPaths(chainPathIndex)
  25. if (chainPath.ready == true) {
  26. console.log(
  27. `✅ ${hre.network.name} > activateChainPath: poolId:${taskArgs.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} | *already active* `
  28. )
  29. continue
  30. }
  31. let tx = await (await router.activateChainPath(taskArgs.poolId, dstChainId, dstPoolId)).wait()
  32. console.log(
  33. `✅ ${hre.network.name} > activateChainPath: poolId:${taskArgs.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId}`
  34. )
  35. console.log(` -> tx: ${tx.transactionHash}`)
  36. }
  37. }
  38. })