zkSyncDeploy.ts 4.8 KB

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