activateChainPaths.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // const { POOLS } = require("@layerzerolabs/sg-sdk")
  2. const {getEndpointId} = require("../utils/network")
  3. const {getEndpointIdByName} = require("../utils/layerzero")
  4. const {getPoolsByNetwork} = require("../utils/layerzero")
  5. task("activateChainPaths", "activate chain paths")
  6. .addParam("targetNetwork", "activate chain paths for this destination targetNetwork")
  7. .setAction(async (taskArgs) => {
  8. let router = await ethers.getContract("Router")
  9. console.log(`router.address: ${router.address}`)
  10. let pools = getPoolsByNetwork(hre.network.name);
  11. // const poolData = POOLS[hre.network.name]
  12. const mirrorgateEthVault = await ethers.getContract("MirrorgateEthVault");
  13. pools.push({
  14. info: {
  15. poolId: 0,
  16. address: mirrorgateEthVault.address,
  17. sharedDecimals: await mirrorgateEthVault.decimals(),
  18. },
  19. chainPaths: [
  20. {
  21. dstChainId: getEndpointIdByName(taskArgs.targetNetwork),
  22. dstPoolId: 0,
  23. weight: 1000,
  24. }
  25. ]
  26. })
  27. let tx
  28. for (let pool of pools) {
  29. console.log(`mapping ${hre.network.name}[${getEndpointId()}] srcPoolId: ${pool.info.poolId}:`)
  30. let chainPaths = pool.chainPaths
  31. for (let dstObj of chainPaths) {
  32. let {dstChainId, dstPoolId, weight} = dstObj
  33. if (dstChainId != getEndpointIdByName(taskArgs.targetNetwork)) {
  34. continue
  35. }
  36. try {
  37. tx = await (await router.activateChainPath(pool.info.poolId, dstChainId, dstPoolId)).wait()
  38. console.log(
  39. ` ✅ activateChainPath: poolId:${pool.info.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} | tx: ${tx.transactionHash}`
  40. )
  41. } catch (e) {
  42. if (e.error.message.includes("Stargate: chainPath is already active")) {
  43. console.log(
  44. ` ✅ activateChainPath: poolId:${pool.info.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} | *already exists*`
  45. )
  46. } else {
  47. console.log(e)
  48. console.log("^ ERROR")
  49. }
  50. }
  51. }
  52. }
  53. })