zkSyncDeployWormhole.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {
  2. DefaultStore,
  3. EvmChain,
  4. EvmWormholeContract,
  5. } from "@pythnetwork/contract-manager";
  6. import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
  7. import { CHAINS } from "@pythnetwork/xc-admin-common";
  8. import { assert } from "chai";
  9. export function findWormholeContract(chainId: string): string | undefined {
  10. for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
  11. if (
  12. contract instanceof EvmWormholeContract &&
  13. contract.getChain().getId() === chainId
  14. ) {
  15. return contract.address;
  16. }
  17. }
  18. }
  19. export async function deployWormholeContract(
  20. deployer: Deployer,
  21. chainName: string,
  22. wormholeGovernanceChainId: string,
  23. wormholeGovernanceContract: string,
  24. wormholeInitialSigners: string[],
  25. wormholeReceiverChainId: number
  26. ): Promise<string> {
  27. const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
  28. const receiverImplArtifact = await deployer.loadArtifact(
  29. "ReceiverImplementation"
  30. );
  31. const wormholeReceiverArtifact = await deployer.loadArtifact(
  32. "WormholeReceiver"
  33. );
  34. console.log("Deploying WormholeReceiver contract...");
  35. const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
  36. console.log("Deployed ReceiverSetup on", receiverSetupContract.address);
  37. console.log("Deploying ReceiverImplementation contract...");
  38. // deploy implementation
  39. const receiverImplContract = await deployer.deploy(receiverImplArtifact);
  40. console.log(
  41. "Deployed ReceiverImplementation on",
  42. receiverImplContract.address
  43. );
  44. // encode initialisation data
  45. const whInitData = receiverSetupContract.interface.encodeFunctionData(
  46. "setup",
  47. [
  48. receiverImplContract.address,
  49. wormholeInitialSigners,
  50. wormholeReceiverChainId,
  51. wormholeGovernanceChainId,
  52. wormholeGovernanceContract,
  53. ]
  54. );
  55. // deploy proxy
  56. const wormholeReceiverContract = await deployer.deploy(
  57. wormholeReceiverArtifact,
  58. [receiverSetupContract.address, whInitData]
  59. );
  60. console.log(
  61. `Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
  62. );
  63. return wormholeReceiverContract.address;
  64. }