createChainPaths.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { POOLS } = require("@layerzerolabs/stargate-sdk")
  2. const { getEndpointId } = require("../utils/network")
  3. const { getEndpointIdByName } = require("@layerzerolabs/core-sdk")
  4. task("createChainPaths", "given a Stargate router, create chainPaths for a token")
  5. .addParam("targetNetwork", "the stargate router address")
  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. console.table(poolData)
  11. let tx
  12. for (let srcPoolId in poolData) {
  13. console.log(`mapping ${hre.network.name}[${getEndpointId()}] srcPoolId: ${srcPoolId}`)
  14. let chainPaths = poolData[srcPoolId].chainPaths
  15. for (let dstObj of chainPaths) {
  16. let { dstChainId, dstPoolId, weight } = dstObj
  17. if (dstChainId != getEndpointIdByName(taskArgs.targetNetwork)) {
  18. continue
  19. }
  20. try {
  21. tx = await (await router.createChainPath(srcPoolId, dstChainId, dstPoolId, weight)).wait()
  22. console.log(`✅ createChainPath: poolId:${srcPoolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} weight:${weight}`)
  23. console.log(` -> tx: ${tx.transactionHash}`)
  24. } catch (e) {
  25. if (e.error.message.includes("Stargate: cant createChainPath of existing dstChainId and _dstPoolId")) {
  26. console.log(
  27. `✅ createChainPath: poolId:${srcPoolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} weight:${weight} | *already exists*`
  28. )
  29. } else {
  30. console.log(e)
  31. console.log("^ ERROR")
  32. }
  33. }
  34. }
  35. }
  36. })