5_deploy_pyth.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require('dotenv').config({ path: "../.env" });
  2. const bs58 = require("bs58");
  3. const PythDataBridge = artifacts.require("PythDataBridge");
  4. const PythImplementation = artifacts.require("PythImplementation");
  5. const PythSetup = artifacts.require("PythSetup");
  6. const Wormhole = artifacts.require("Wormhole");
  7. const chainId = process.env.PYTH_INIT_CHAIN_ID;
  8. const governanceChainId = process.env.PYTH_INIT_GOV_CHAIN_ID;
  9. const governanceContract = process.env.PYTH_INIT_GOV_CONTRACT; // bytes32
  10. const pyth2WormholeChainId = process.env.PYTH_TO_WORMHOLE_CHAIN_ID;
  11. const pyth2WormholeEmitter = bs58.decode(process.env.PYTH_TO_WORMHOLE_EMITTER); // base58, must fit into bytes32
  12. console.log("Deploying Pyth with emitter", pyth2WormholeEmitter.toString("hex"))
  13. module.exports = async function (deployer) {
  14. // deploy implementation
  15. await deployer.deploy(PythImplementation);
  16. // deploy implementation
  17. await deployer.deploy(PythSetup);
  18. // encode initialisation data
  19. const setup = new web3.eth.Contract(PythSetup.abi, PythSetup.address);
  20. const initData = setup.methods.setup(
  21. PythImplementation.address,
  22. chainId,
  23. (await Wormhole.deployed()).address,
  24. governanceChainId,
  25. governanceContract,
  26. pyth2WormholeChainId,
  27. "0x" + pyth2WormholeEmitter.toString("hex"),
  28. ).encodeABI();
  29. // deploy proxy
  30. await deployer.deploy(PythDataBridge, PythSetup.address, initData);
  31. };