createPools.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // const {POOLS} = require("@layerzerolabs/sg-sdk")
  2. const {getEndpointId} = require("../utils/network")
  3. const {getPoolsByNetwork} = require("../utils/layerzero");
  4. task("createPools", "create the pools for the network").setAction(async (taskArgs) => {
  5. let router = await ethers.getContract("Router")
  6. let pools = getPoolsByNetwork(hre.network.name);
  7. // console.log(pools)
  8. // for (let poolId in pools) {
  9. // console.log(pools[poolId].info)
  10. // console.log(`poolId: ${poolId}`)
  11. // console.table(pools[poolId].chainPaths)
  12. // }
  13. // return;
  14. // make sure the token exists
  15. const factory = await ethers.getContract("Factory")
  16. const mirrorgateEthVault = await ethers.getContract("MirrorgateEthVault");
  17. pools.push({
  18. info: {
  19. poolId: 0,
  20. address: mirrorgateEthVault.address,
  21. sharedDecimals: await mirrorgateEthVault.decimals(),
  22. }
  23. })
  24. let tx
  25. for (let pool of pools) {
  26. let sharedDecimals = pool.info.sharedDecimals
  27. let address = pool.info.address
  28. let Token = await ethers.getContractFactory("MockToken")
  29. let token = await Token.attach(address)
  30. let name = await token.name()
  31. let symbol = await token.symbol()
  32. let decimals = await token.decimals()
  33. let poolName = `${name}-LP`
  34. let poolSymbol = `S*${symbol}`
  35. try {
  36. tx = await (
  37. await router.createPool(
  38. pool.info.poolId,
  39. token.address,
  40. sharedDecimals, // Mirrorgate pairs shared decimals across chains
  41. decimals, // the tokens real decimals
  42. poolName,
  43. poolSymbol
  44. )
  45. ).wait()
  46. let poolAddr = await factory.getPool(pool.info.poolId)
  47. console.log(`[${getEndpointId()}] createPool | name:${name} symbol:${symbol} decimals:${decimals} address:${token.address}`)
  48. console.log(`- tx: ${tx.transactionHash} | pool.address: ${poolAddr} name: ${poolName} symbol: ${poolSymbol}`)
  49. } catch (e) {
  50. console.error(e);
  51. if (e.error.message.includes("Mirrorgate: Pool already created")) {
  52. let poolAddr = await factory.getPool(pool.info.poolId)
  53. console.log(
  54. `[${getEndpointId()}] createPool | name:${name} symbol:${symbol} decimals:${decimals} address:${
  55. token.address
  56. } | *already created*`
  57. )
  58. console.log(`- pool.address: ${poolAddr} name: ${poolName} symbol: ${poolSymbol}`)
  59. }
  60. }
  61. }
  62. })