5_deploy_pyth.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 pyth2WormholeChainId = process.env.PYTH_TO_WORMHOLE_CHAIN_ID;
  9. const pyth2WormholeEmitter = bs58.decode(process.env.PYTH_TO_WORMHOLE_EMITTER); // base58, must fit into bytes32
  10. console.log("Deploying Pyth with emitter", pyth2WormholeEmitter.toString("hex"))
  11. module.exports = async function (deployer) {
  12. // deploy implementation
  13. await deployer.deploy(PythImplementation);
  14. // deploy implementation
  15. await deployer.deploy(PythSetup);
  16. // encode initialisation data
  17. const setup = new web3.eth.Contract(PythSetup.abi, PythSetup.address);
  18. const initData = setup.methods.setup(
  19. PythImplementation.address,
  20. chainId,
  21. (await Wormhole.deployed()).address,
  22. pyth2WormholeChainId,
  23. "0x" + pyth2WormholeEmitter.toString("hex"),
  24. ).encodeABI();
  25. // deploy proxy
  26. await deployer.deploy(PythDataBridge, PythSetup.address, initData);
  27. };