mainnet_deploy.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // npx pretty-quick
  2. const nearAPI = require("near-api-js");
  3. const BN = require("bn.js");
  4. const fs = require("fs");
  5. const fetch = require("node-fetch");
  6. import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
  7. const { parseSeedPhrase, generateSeedPhrase } = require("near-seed-phrase");
  8. function getConfig(env: any) {
  9. switch (env) {
  10. case "mainnet":
  11. return {
  12. networkId: "mainnet",
  13. nodeUrl: "https://rpc.mainnet.near.org",
  14. wormholeMasterAccount: "wormhole_crypto.near",
  15. wormholeAccount: "contract.wormhole_crypto.near",
  16. portalMasterAccount: "portalbridge.near",
  17. portalAccount: "contract.portalbridge.near",
  18. };
  19. }
  20. return {};
  21. }
  22. async function initNear() {
  23. let config = getConfig("mainnet");
  24. let wormholeKeys = parseSeedPhrase(process.env.WORMHOLE_KEYS);
  25. let portalKeys = parseSeedPhrase(process.env.PORTAL_KEYS);
  26. let wormholeMasterKey = nearAPI.utils.KeyPair.fromString(
  27. wormholeKeys["secretKey"]
  28. );
  29. let portalMasterKey = nearAPI.utils.KeyPair.fromString(
  30. portalKeys["secretKey"]
  31. );
  32. let keyStore = new nearAPI.keyStores.InMemoryKeyStore();
  33. keyStore.setKey(
  34. config.networkId,
  35. config.wormholeMasterAccount,
  36. wormholeMasterKey
  37. );
  38. keyStore.setKey(config.networkId, config.wormholeAccount, wormholeMasterKey);
  39. keyStore.setKey(
  40. config.networkId,
  41. config.portalMasterAccount,
  42. portalMasterKey
  43. );
  44. keyStore.setKey(config.networkId, config.portalAccount, portalMasterKey);
  45. let near = await nearAPI.connect({
  46. keyStore,
  47. networkId: config.networkId,
  48. nodeUrl: config.nodeUrl,
  49. });
  50. let wormholeMasterAccount = new nearAPI.Account(
  51. near.connection,
  52. config.wormholeMasterAccount
  53. );
  54. let portalMasterAccount = new nearAPI.Account(
  55. near.connection,
  56. config.portalMasterAccount
  57. );
  58. console.log(
  59. "wormhole account: " +
  60. JSON.stringify(await wormholeMasterAccount.getAccountBalance())
  61. );
  62. console.log(
  63. "portal account: " +
  64. JSON.stringify(await portalMasterAccount.getAccountBalance())
  65. );
  66. const wormholeContract = await fs.readFileSync(
  67. "contracts/wormhole/target/wasm32-unknown-unknown/release/near_wormhole.wasm"
  68. );
  69. const portalContract = await fs.readFileSync(
  70. "contracts/token-bridge/target/wasm32-unknown-unknown/release/near_token_bridge.wasm"
  71. );
  72. console.log("setting key for new wormhole contract");
  73. keyStore.setKey(config.networkId, config.wormholeAccount, wormholeMasterKey);
  74. keyStore.setKey(config.networkId, config.portalAccount, portalMasterKey);
  75. console.log("Deploying core/wormhole contract: " + config.wormholeAccount);
  76. let wormholeAccount = await wormholeMasterAccount.createAndDeployContract(
  77. config.wormholeAccount,
  78. wormholeMasterKey.getPublicKey(),
  79. wormholeContract,
  80. new BN("5000000000000000000000000")
  81. );
  82. console.log("Deploying core/portal contract: " + config.portalAccount);
  83. let portalAccount = await portalMasterAccount.createAndDeployContract(
  84. config.portalAccount,
  85. portalMasterKey.getPublicKey(),
  86. portalContract,
  87. new BN("12000000000000000000000000")
  88. );
  89. let result = await wormholeMasterAccount.functionCall({
  90. contractId: config.wormholeAccount,
  91. methodName: "boot_wormhole",
  92. args: {
  93. gset: 0,
  94. addresses: ["58CC3AE5C097b213cE3c81979e1B9f9570746AA5"],
  95. },
  96. gas: 100000000000000,
  97. });
  98. result = await portalMasterAccount.functionCall({
  99. contractId: config.portalAccount,
  100. methodName: "boot_portal",
  101. args: {
  102. core: config.wormholeAccount,
  103. },
  104. gas: 100000000000000,
  105. });
  106. await wormholeMasterAccount.functionCall({
  107. contractId: config.wormholeAccount,
  108. methodName: "register_emitter",
  109. args: { emitter: config.portalAccount },
  110. attachedDeposit: new BN("30000000000000000000000"),
  111. gas: new BN("100000000000000"),
  112. });
  113. console.log("deleting the master key from the token contract");
  114. await portalAccount.deleteKey(portalMasterKey.getPublicKey());
  115. console.log("deleting the master key from the wormhole contract");
  116. await wormholeAccount.deleteKey(wormholeMasterKey.getPublicKey());
  117. }
  118. initNear();