2_deploy_pyth.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const loadEnv = require("../../scripts/loadEnv");
  2. loadEnv("../../");
  3. const PythUpgradable = artifacts.require("PythUpgradable");
  4. const pyth2WormholeChainId = process.env.SOLANA_CHAIN_ID;
  5. const pyth2WormholeEmitter = process.env.SOLANA_EMITTER;
  6. const { deployProxy } = require("@openzeppelin/truffle-upgrades");
  7. const tdr = require('truffle-deploy-registry');
  8. const { CONTRACTS } = require('@certusone/wormhole-sdk');
  9. const { assert } = require("chai");
  10. console.log("pyth2WormholeEmitter: " + pyth2WormholeEmitter)
  11. console.log("pyth2WormholeChainId: " + pyth2WormholeChainId)
  12. module.exports = async function (deployer, network) {
  13. const cluster = process.env.CLUSTER;
  14. const chainName = process.env.WORMHOLE_CHAIN_NAME;
  15. assert(cluster !== undefined && chainName !== undefined);
  16. const wormholeBridgeAddress = CONTRACTS[cluster.toUpperCase()][chainName].core;
  17. assert(wormholeBridgeAddress !== undefined);
  18. console.log("Wormhole bridge address: " + wormholeBridgeAddress)
  19. // Deploy the proxy. This will return an instance of PythUpgradable,
  20. // with the address field corresponding to the fronting ERC1967Proxy.
  21. let proxyInstance = await deployProxy(PythUpgradable,
  22. [
  23. wormholeBridgeAddress,
  24. pyth2WormholeChainId,
  25. pyth2WormholeEmitter
  26. ],
  27. { deployer });
  28. // Add the ERC1967Proxy address to the PythUpgradable contract's
  29. // entry in the registry. This allows us to call upgradeProxy
  30. // functions with the value of PythUpgradable.deployed().address:
  31. // e.g. upgradeProxy(PythUpgradable.deployed().address, NewImplementation)
  32. if (!tdr.isDryRunNetworkName(network)) {
  33. await tdr.appendInstance(proxyInstance);
  34. }
  35. };