createChainPaths.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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("createChainPaths", "given a mirrorgate router, create chainPaths for a token")
  6. .addParam("targetNetwork", "the mirrorgate router address")
  7. .setAction(async (taskArgs) => {
  8. let router = await ethers.getContract("Router")
  9. console.log(`router.address: ${router.address}`)
  10. const 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. console.table(pools)
  28. let tx
  29. for (let pool of pools) {
  30. console.log(`mapping ${hre.network.name}[${getEndpointId()}] srcPoolId: ${pool.info.poolId}`)
  31. let chainPaths = pool.chainPaths
  32. for (let dstObj of chainPaths) {
  33. let {dstChainId, dstPoolId, weight} = dstObj
  34. if (dstChainId != getEndpointIdByName(taskArgs.targetNetwork)) {
  35. continue
  36. }
  37. try {
  38. tx = await (await router.createChainPath(pool.info.poolId, dstChainId, dstPoolId, weight)).wait()
  39. console.log(`✅ createChainPath: poolId:${pool.info.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} weight:${weight}`)
  40. console.log(` -> tx: ${tx.transactionHash}`)
  41. } catch (e) {
  42. if (e.error.message.includes("Mirrorgate: cant createChainPath of existing dstChainId and _dstPoolId")) {
  43. console.log(
  44. `✅ createChainPath: poolId:${pool.info.poolId} dstChainId:${dstChainId} dstPoolId:${dstPoolId} weight:${weight} | *already exists*`
  45. )
  46. } else {
  47. console.log(e)
  48. console.log("^ ERROR")
  49. }
  50. }
  51. }
  52. }
  53. })