zkSyncDeploy.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. const { getDefaultConfig } = require("../scripts/contractManagerConfig");
  9. function envOrErr(name: string): string {
  10. const res = process.env[name];
  11. if (res === undefined) {
  12. throw new Error(`${name} environment variable is not set.`);
  13. }
  14. return res;
  15. }
  16. export default async function (hre: HardhatRuntimeEnvironment) {
  17. // Initialize the wallet.
  18. const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC"));
  19. // Create deployer object and load the artifact of the contract we want to deploy.
  20. const deployer = new Deployer(hre, wallet);
  21. // Deposit some funds to L2 in order to be able to perform L2 transactions. Uncomment
  22. // this if the deployment account is unfunded.
  23. //
  24. // const depositAmount = ethers.utils.parseEther("0.005");
  25. // const depositHandle = await deployer.zkWallet.deposit({
  26. // to: deployer.zkWallet.address,
  27. // token: utils.ETH_ADDRESS,
  28. // amount: depositAmount,
  29. // });
  30. // // Wait until the deposit is processed on zkSync
  31. // await depositHandle.wait();
  32. // Deploy WormholeReceiver contract.
  33. const {
  34. wormholeGovernanceChainId,
  35. wormholeGovernanceContract,
  36. wormholeInitialSigners,
  37. governanceEmitter,
  38. governanceChainId,
  39. emitterAddresses,
  40. emitterChainIds,
  41. } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK"));
  42. const chainName = envOrErr("MIGRATIONS_NETWORK");
  43. const wormholeReceiverChainId = CHAINS[chainName];
  44. assert(wormholeReceiverChainId !== undefined);
  45. const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
  46. const receiverImplArtifact = await deployer.loadArtifact(
  47. "ReceiverImplementation"
  48. );
  49. const wormholeReceiverArtifact = await deployer.loadArtifact(
  50. "WormholeReceiver"
  51. );
  52. const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
  53. // deploy implementation
  54. const receiverImplContract = await deployer.deploy(receiverImplArtifact);
  55. // encode initialisation data
  56. const whInitData = receiverSetupContract.interface.encodeFunctionData(
  57. "setup",
  58. [
  59. receiverImplContract.address,
  60. wormholeInitialSigners,
  61. wormholeReceiverChainId,
  62. wormholeGovernanceChainId,
  63. wormholeGovernanceContract,
  64. ]
  65. );
  66. // deploy proxy
  67. const wormholeReceiverContract = await deployer.deploy(
  68. wormholeReceiverArtifact,
  69. [receiverSetupContract.address, whInitData]
  70. );
  71. console.log(
  72. `Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
  73. );
  74. const governanceInitialSequence = Number(
  75. process.env.GOVERNANCE_INITIAL_SEQUENCE ?? "0"
  76. );
  77. const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS"));
  78. const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI"));
  79. const pythImplArtifact = await deployer.loadArtifact("PythUpgradable");
  80. const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy");
  81. const pythImplContract = await deployer.deploy(pythImplArtifact);
  82. const pythInitData = pythImplContract.interface.encodeFunctionData(
  83. "initialize",
  84. [
  85. wormholeReceiverContract.address,
  86. emitterChainIds,
  87. emitterAddresses,
  88. governanceChainId,
  89. governanceEmitter,
  90. governanceInitialSequence,
  91. validTimePeriodSeconds,
  92. singleUpdateFeeInWei,
  93. ]
  94. );
  95. const pythProxyContract = await deployer.deploy(pythProxyArtifact, [
  96. pythImplContract.address,
  97. pythInitData,
  98. ]);
  99. console.log(`Deployed Pyth contract on ${pythProxyContract.address}`);
  100. const networkId = hre.network.config.chainId;
  101. const registryPath = `networks/${networkId}.json`;
  102. console.log(`Saving addresses in ${registryPath}`);
  103. writeFileSync(
  104. registryPath,
  105. JSON.stringify(
  106. [
  107. {
  108. contractName: "WormholeReceiver",
  109. address: wormholeReceiverContract.address,
  110. },
  111. {
  112. contractName: "PythUpgradable",
  113. address: pythProxyContract.address,
  114. },
  115. ],
  116. null,
  117. 2
  118. )
  119. );
  120. }