zkSyncDeployPriceFeed.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. require("dotenv").config({ path: ".env" });
  2. import { utils, Wallet } from "zksync-web3";
  3. import { HardhatRuntimeEnvironment } from "hardhat/types";
  4. import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
  5. import { CHAINS } from "@pythnetwork/xc-admin-common";
  6. import { assert } from "chai";
  7. import { writeFileSync } from "fs";
  8. import {
  9. deployWormholeContract,
  10. findWormholeContract,
  11. } from "./zkSyncDeployWormhole";
  12. // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work
  13. // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync";
  14. const { getDefaultConfig } = require("../scripts/contractManagerConfig");
  15. function envOrErr(name: string): string {
  16. const res = process.env[name];
  17. if (res === undefined) {
  18. throw new Error(`${name} environment variable is not set.`);
  19. }
  20. return res;
  21. }
  22. export default async function (hre: HardhatRuntimeEnvironment) {
  23. // Initialize the wallet.
  24. const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC"));
  25. // Create deployer object and load the artifact of the contract we want to deploy.
  26. const deployer = new Deployer(hre, wallet);
  27. // Deposit some funds to L2 in order to be able to perform L2 transactions. Uncomment
  28. // this if the deployment account is unfunded.
  29. //
  30. // const depositAmount = ethers.utils.parseEther("0.005");
  31. // const depositHandle = await deployer.zkWallet.deposit({
  32. // to: deployer.zkWallet.address,
  33. // token: utils.ETH_ADDRESS,
  34. // amount: depositAmount,
  35. // });
  36. // // Wait until the deposit is processed on zkSync
  37. // await depositHandle.wait();
  38. // Deploy WormholeReceiver contract.
  39. const {
  40. wormholeGovernanceChainId,
  41. wormholeGovernanceContract,
  42. wormholeInitialSigners,
  43. governanceEmitter,
  44. governanceChainId,
  45. emitterAddresses,
  46. emitterChainIds,
  47. } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK"));
  48. const chainName = envOrErr("MIGRATIONS_NETWORK");
  49. const wormholeReceiverChainId = CHAINS[chainName];
  50. assert(wormholeReceiverChainId !== undefined);
  51. let wormholeReceiverContractAddress = await findWormholeContract(chainName);
  52. if (!wormholeReceiverContractAddress) {
  53. console.log(`Wormhole contract not found for chain ${chainName}`);
  54. console.log("Deploying Wormhole contract...");
  55. wormholeReceiverContractAddress = await deployWormholeContract(
  56. deployer,
  57. chainName,
  58. wormholeGovernanceChainId,
  59. wormholeGovernanceContract,
  60. wormholeInitialSigners,
  61. wormholeReceiverChainId
  62. );
  63. }
  64. // Hardcoding the initial sequence number for governance messages.
  65. const governanceInitialSequence = Number("0");
  66. const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS"));
  67. const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI"));
  68. const pythImplArtifact = await deployer.loadArtifact("PythUpgradable");
  69. const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy");
  70. const pythImplContract = await deployer.deploy(pythImplArtifact);
  71. console.log(`Deployed Pyth implementation on ${pythImplContract.address}`);
  72. const pythInitData = pythImplContract.interface.encodeFunctionData(
  73. "initialize",
  74. [
  75. wormholeReceiverContractAddress,
  76. emitterChainIds,
  77. emitterAddresses,
  78. governanceChainId,
  79. governanceEmitter,
  80. governanceInitialSequence,
  81. validTimePeriodSeconds,
  82. singleUpdateFeeInWei,
  83. ]
  84. );
  85. const pythProxyContract = await deployer.deploy(pythProxyArtifact, [
  86. pythImplContract.address,
  87. pythInitData,
  88. ]);
  89. console.log(`Deployed Pyth contract on ${pythProxyContract.address}`);
  90. // const networkId = hre.network.config.chainId;
  91. // const registryPath = `networks/${networkId}.json`;
  92. // console.log(`Saving addresses in ${registryPath}`);
  93. // writeFileSync(
  94. // registryPath,
  95. // JSON.stringify(
  96. // [
  97. // {
  98. // contractName: "WormholeReceiver",
  99. // address: wormholeReceiverContract.address,
  100. // },
  101. // {
  102. // contractName: "PythUpgradable",
  103. // address: pythProxyContract.address,
  104. // },
  105. // ],
  106. // null,
  107. // 2
  108. // )
  109. // );
  110. }