From d232967e055ee47aca2121e9f7bd461d6e538830 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Mon, 21 Oct 2024 16:53:48 -0400 Subject: [PATCH 1/5] initial commit --- .../ethereum/contracts/.env.template | 1 + .../contracts/deploy/zkSyncEntropyDeploy.ts | 212 ++++++++++++++++++ ...SyncDeploy.ts => zkSyncPriceFeedDeploy.ts} | 0 3 files changed, 213 insertions(+) create mode 100644 target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts rename target_chains/ethereum/contracts/deploy/{zkSyncDeploy.ts => zkSyncPriceFeedDeploy.ts} (100%) diff --git a/target_chains/ethereum/contracts/.env.template b/target_chains/ethereum/contracts/.env.template index d99d52bfd2..37eb579bba 100644 --- a/target_chains/ethereum/contracts/.env.template +++ b/target_chains/ethereum/contracts/.env.template @@ -9,6 +9,7 @@ MIGRATIONS_NETWORK= # xyz VALID_TIME_PERIOD_SECONDS= # 60 WORMHOLE_CHAIN_NAME= # ethereum, defined in /governance/xc_admin/packages/xc_admin_common/src/chains.ts +WORMHOLE_RECEIVER_ADDRESS= # 0x, Add this address if the wormhole receiver is deployed while deploying price feed contract. CLUSTER= #mainnet/testnet The configs below are read from the cluster file diff --git a/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts b/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts new file mode 100644 index 0000000000..1a58918bb2 --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts @@ -0,0 +1,212 @@ +require("dotenv").config({ path: ".env" }); +import { utils, Wallet } from "zksync-web3"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; +import { CHAINS } from "@pythnetwork/xc-admin-common"; +import { assert } from "chai"; +import { EvmWormholeContract } from "@pythnetwork/contract-manager"; +import { writeFileSync } from "fs"; +// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work +// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; + +const { getDefaultConfig } = require("../scripts/contractManagerConfig"); + +function envOrErr(name: string): string { + const res = process.env[name]; + if (res === undefined) { + throw new Error(`${name} environment variable is not set.`); + } + return res; +} + +export default async function (hre: HardhatRuntimeEnvironment) { + // Initialize the wallet. + const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); + + // Create deployer object and load the artifact of the contract we want to deploy. + const deployer = new Deployer(hre, wallet); + + // Deposit some funds to L2 in order to be able to perform L2 transactions. Uncomment + // this if the deployment account is unfunded. + // + // const depositAmount = ethers.utils.parseEther("0.005"); + // const depositHandle = await deployer.zkWallet.deposit({ + // to: deployer.zkWallet.address, + // token: utils.ETH_ADDRESS, + // amount: depositAmount, + // }); + // // Wait until the deposit is processed on zkSync + // await depositHandle.wait(); + + // Deploy WormholeReceiver contract. + const { + wormholeGovernanceChainId, + wormholeGovernanceContract, + wormholeInitialSigners, + governanceEmitter, + governanceChainId, + emitterAddresses, + emitterChainIds, + } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); + + console.log("WormholeGovernanceChainId: ", wormholeGovernanceChainId); + console.log("WormholeGovernanceContract: ", wormholeGovernanceContract); + console.log("WormholeInitialSigners: ", wormholeInitialSigners); + console.log("GovernanceEmitter: ", governanceEmitter); + console.log("GovernanceChainId: ", governanceChainId); + console.log("EmitterAddresses: ", emitterAddresses); + console.log("EmitterChainIds: ", emitterChainIds); + + const chainName = envOrErr("MIGRATIONS_NETWORK"); + const wormholeReceiverChainId = CHAINS[chainName]; + assert(wormholeReceiverChainId !== undefined); + + console.log("wormholeReceiverChainId: ", wormholeReceiverChainId); + console.log("Chain ID: ", hre.network.config); + + + + + // Check if the wormhole receiver contract is already deployed. + const wormholeReceiverAddress = process.env.WORMHOLE_RECEIVER_ADDRESS; + let wormholeReceiverContract = new EvmWormholeContract( + wormholeReceiverChainId, + wormholeReceiverAddress + ); + + console.log("wormholeReceiverContract: ", wormholeReceiverContract); + + + if (wormholeReceiverContract.address) { + console.log( + "WormholeReceiver already deployed at: ", + wormholeReceiverAddress + ); + } else { + console.log("WormholeReceiver not deployed yet, deploying..."); + const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); + const receiverImplArtifact = await deployer.loadArtifact( + "ReceiverImplementation" + ); + const wormholeReceiverArtifact = await deployer.loadArtifact( + "WormholeReceiver" + ); + + console.log("Deploying WormholeReceiver contract..."); + const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); + console.log("Deployed ReceiverSetup on", receiverSetupContract.address); + + console.log("Deploying ReceiverImplementation contract..."); + // deploy implementation + const receiverImplContract = await deployer.deploy(receiverImplArtifact); + console.log( + "Deployed ReceiverImplementation on", + receiverImplContract.address + ); + + // encode initialisation data + const whInitData = receiverSetupContract.interface.encodeFunctionData( + "setup", + [ + receiverImplContract.address, + wormholeInitialSigners, + wormholeReceiverChainId, + wormholeGovernanceChainId, + wormholeGovernanceContract, + ] + ); + + // deploy proxy + const wormholeReceiverContract = await deployer.deploy( + wormholeReceiverArtifact, + [receiverSetupContract.address, whInitData] + ); + + console.log( + `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` + ); + + console.log("Syncing mainnet guardian sets..."); + await (wormholeReceiverContract as EvmWormholeContract).syncMainnetGuardianSets(wallet.privateKey); + console.log("✅ Synced mainnet guardian sets"); + } + + // Hardcoding the initial sequence number for governance messages. + const governanceInitialSequence = Number("0"); + + // TODO: Top up accounts if necessary + + // Deploy Executor contracts + const executorImplArtifact = await deployer.loadArtifact( + "ExecutorUpgradable" + ); + // const executorImplContract = await deployer.deploy(executorImplArtifact); + // console.log( + // `Deployed ExecutorImplementation on ${executorImplContract.address}` + // ); + + // const executorInitData = executorImplContract.interface.encodeFunctionData( + // "initialize", + // [ + // wormholeReceiverContract.address, + // 0, + // wormholeReceiverChainId, + // governanceChainId, + // governanceEmitter, + // ] + // ); + + // Deploy Entropy contracts + + // const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); + // const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); + + // const pythImplArtifact = await deployer.loadArtifact("PythUpgradable"); + // const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); + + // const pythImplContract = await deployer.deploy(pythImplArtifact); + + // console.log(`Deployed Pyth implementation on ${pythImplContract.address}`); + + // const pythInitData = pythImplContract.interface.encodeFunctionData( + // "initialize", + // [ + // wormholeReceiverContract.address, + // emitterChainIds, + // emitterAddresses, + // governanceChainId, + // governanceEmitter, + // governanceInitialSequence, + // validTimePeriodSeconds, + // singleUpdateFeeInWei, + // ] + // ); + + // const pythProxyContract = await deployer.deploy(pythProxyArtifact, [ + // pythImplContract.address, + // pythInitData, + // ]); + + // console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); + + // const networkId = hre.network.config.chainId; + // const registryPath = `networks/${networkId}.json`; + // console.log(`Saving addresses in ${registryPath}`); + // writeFileSync( + // registryPath, + // JSON.stringify( + // [ + // { + // contractName: "WormholeReceiver", + // address: wormholeReceiverContract.address, + // }, + // { + // contractName: "PythUpgradable", + // address: pythProxyContract.address, + // }, + // ], + // null, + // 2 + // ) + // ); +} diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeploy.ts b/target_chains/ethereum/contracts/deploy/zkSyncPriceFeedDeploy.ts similarity index 100% rename from target_chains/ethereum/contracts/deploy/zkSyncDeploy.ts rename to target_chains/ethereum/contracts/deploy/zkSyncPriceFeedDeploy.ts From 1ef4e2e368a70417e8449955f0b8edd907472a50 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 22 Oct 2024 16:16:51 -0400 Subject: [PATCH 2/5] Deployed cronos zk testnet --- contract_manager/store/chains/EvmChains.yaml | 2 +- .../contracts/EvmPriceFeedContracts.yaml | 6 +- .../store/contracts/EvmWormholeContracts.yaml | 6 +- .../ethereum/contracts/.env.template | 1 - .../contracts/deploy/zkSyncDeployEntropy.ts | 147 ++++++++++++ ...FeedDeploy.ts => zkSyncDeployPriceFeed.ts} | 93 ++++---- .../contracts/deploy/zkSyncDeployWormhole.ts | 65 ++++++ .../contracts/deploy/zkSyncEntropyDeploy.ts | 212 ------------------ target_chains/ethereum/sdk/js/package.json | 2 +- target_chains/ethereum/sdk/js/src/index.ts | 2 +- 10 files changed, 273 insertions(+), 263 deletions(-) create mode 100644 target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts rename target_chains/ethereum/contracts/deploy/{zkSyncPriceFeedDeploy.ts => zkSyncDeployPriceFeed.ts} (67%) create mode 100644 target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts delete mode 100644 target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts diff --git a/contract_manager/store/chains/EvmChains.yaml b/contract_manager/store/chains/EvmChains.yaml index 0b0752de6b..60b6956328 100644 --- a/contract_manager/store/chains/EvmChains.yaml +++ b/contract_manager/store/chains/EvmChains.yaml @@ -662,7 +662,7 @@ - id: cronos_zkevm_testnet mainnet: false rpcUrl: https://testnet.zkevm.cronos.org - networkId: 282 + networkId: 240 type: EvmChain - id: reya_testnet mainnet: false diff --git a/contract_manager/store/contracts/EvmPriceFeedContracts.yaml b/contract_manager/store/contracts/EvmPriceFeedContracts.yaml index 7c52f0d942..4384025cef 100644 --- a/contract_manager/store/contracts/EvmPriceFeedContracts.yaml +++ b/contract_manager/store/contracts/EvmPriceFeedContracts.yaml @@ -361,15 +361,15 @@ - chain: kinto address: "0x2880aB155794e7179c9eE2e38200202908C17B43" type: EvmPriceFeedContract -- chain: cronos_zkevm_testnet - address: "0x67DFF3D12dFDCeC9f85fd86f4cBDb0a111fF721A" - type: EvmPriceFeedContract - chain: reya_testnet address: "0x2880aB155794e7179c9eE2e38200202908C17B43" type: EvmPriceFeedContract - chain: cronos_zkevm_mainnet address: "0x056f829183Ec806A78c26C98961678c24faB71af" type: EvmPriceFeedContract +- chain: cronos_zkevm_testnet + address: "0xB1DB1498902F08E16E11F1a423ec9CCB9537E1D6" + type: EvmPriceFeedContract - chain: movement_evm_devnet_imola address: "0x2880aB155794e7179c9eE2e38200202908C17B43" type: EvmPriceFeedContract diff --git a/contract_manager/store/contracts/EvmWormholeContracts.yaml b/contract_manager/store/contracts/EvmWormholeContracts.yaml index 5b004273a1..5636bf804a 100644 --- a/contract_manager/store/contracts/EvmWormholeContracts.yaml +++ b/contract_manager/store/contracts/EvmWormholeContracts.yaml @@ -349,9 +349,6 @@ - chain: kinto address: "0xb27e5ca259702f209a29225d0eDdC131039C9933" type: EvmWormholeContract -- chain: cronos_zkevm_testnet - address: "0x3f5bB93eEC6E3D6784274291A5816Bc34E851dc8" - type: EvmWormholeContract - chain: reya_testnet address: "0xb27e5ca259702f209a29225d0eDdC131039C9933" type: EvmWormholeContract @@ -361,6 +358,9 @@ - chain: cronos_zkevm_mainnet address: "0xc10F5BE78E464BB0E1f534D66E5A6ecaB150aEFa" type: EvmWormholeContract +- chain: cronos_zkevm_testnet + address: "0x470d1c91b1b1d9295815A2357FB0D20E7350ab71" + type: EvmWormholeContract - chain: movement_evm_devnet_imola address: "0xb27e5ca259702f209a29225d0eDdC131039C9933" type: EvmWormholeContract diff --git a/target_chains/ethereum/contracts/.env.template b/target_chains/ethereum/contracts/.env.template index 37eb579bba..d99d52bfd2 100644 --- a/target_chains/ethereum/contracts/.env.template +++ b/target_chains/ethereum/contracts/.env.template @@ -9,7 +9,6 @@ MIGRATIONS_NETWORK= # xyz VALID_TIME_PERIOD_SECONDS= # 60 WORMHOLE_CHAIN_NAME= # ethereum, defined in /governance/xc_admin/packages/xc_admin_common/src/chains.ts -WORMHOLE_RECEIVER_ADDRESS= # 0x, Add this address if the wormhole receiver is deployed while deploying price feed contract. CLUSTER= #mainnet/testnet The configs below are read from the cluster file diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts new file mode 100644 index 0000000000..9dc296fdcf --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts @@ -0,0 +1,147 @@ +require("dotenv").config({ path: ".env" }); +import { utils, Wallet } from "zksync-web3"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; +import { CHAINS } from "@pythnetwork/xc-admin-common"; +import { assert } from "chai"; +import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager"; +import { findWormholeContract } from "./zkSyncDeployWormhole"; + +// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work +// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; + +const { getDefaultConfig } = require("../scripts/contractManagerConfig"); + +function envOrErr(name: string): string { + const res = process.env[name]; + if (res === undefined) { + throw new Error(`${name} environment variable is not set.`); + } + return res; +} + + + +export default async function (hre: HardhatRuntimeEnvironment) { + // Initialize the wallet. + // const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); + + // Create deployer object and load the artifact of the contract we want to deploy. + // const deployer = new Deployer(hre, wallet); + + // const { + // wormholeGovernanceChainId, + // wormholeGovernanceContract, + // wormholeInitialSigners, + // governanceEmitter, + // governanceChainId, + // emitterAddresses, + // emitterChainIds, + // } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); + + // console.log("WormholeGovernanceChainId: ", wormholeGovernanceChainId); + // console.log("WormholeGovernanceContract: ", wormholeGovernanceContract); + // console.log("WormholeInitialSigners: ", wormholeInitialSigners); + // console.log("GovernanceEmitter: ", governanceEmitter); + // console.log("GovernanceChainId: ", governanceChainId); + // console.log("EmitterAddresses: ", emitterAddresses); + // console.log("EmitterChainIds: ", emitterChainIds); + + const chainName = envOrErr("MIGRATIONS_NETWORK"); + // const wormholeReceiverChainId = CHAINS[chainName]; + // assert(wormholeReceiverChainId !== undefined); + + // console.log("wormholeReceiverChainId: ", wormholeReceiverChainId); + // console.log("Chain ID: ", hre.network.config); + + const chain = DefaultStore.chains[chainName]; + if (!chain) { + throw new Error(`Chain ${chainName} not found`); + } else if (!(chain instanceof EvmChain)) { + throw new Error(`Chain ${chainName} is not an EVM chain`); + } + + const wormholeContract = findWormholeContract(chainName); + console.log("Wormhole contract: ", wormholeContract); + if (!wormholeContract) { + console.log(`Wormhole contract not found for chain ${chainName}`); + console.log("Deploying Wormhole contract..."); + } + + + // // TODO: Top up accounts if necessary + + // // Deploy Executor contracts + // const executorImplArtifact = await deployer.loadArtifact( + // "ExecutorUpgradable" + // ); + // // const executorImplContract = await deployer.deploy(executorImplArtifact); + // // console.log( + // // `Deployed ExecutorImplementation on ${executorImplContract.address}` + // // ); + + // // const executorInitData = executorImplContract.interface.encodeFunctionData( + // // "initialize", + // // [ + // // wormholeReceiverContract.address, + // // 0, + // // wormholeReceiverChainId, + // // governanceChainId, + // // governanceEmitter, + // // ] + // // ); + + // // Deploy Entropy contracts + + // // const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); + // // const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); + + // // const pythImplArtifact = await deployer.loadArtifact("PythUpgradable"); + // // const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); + + // // const pythImplContract = await deployer.deploy(pythImplArtifact); + + // // console.log(`Deployed Pyth implementation on ${pythImplContract.address}`); + + // // const pythInitData = pythImplContract.interface.encodeFunctionData( + // // "initialize", + // // [ + // // wormholeReceiverContract.address, + // // emitterChainIds, + // // emitterAddresses, + // // governanceChainId, + // // governanceEmitter, + // // governanceInitialSequence, + // // validTimePeriodSeconds, + // // singleUpdateFeeInWei, + // // ] + // // ); + + // // const pythProxyContract = await deployer.deploy(pythProxyArtifact, [ + // // pythImplContract.address, + // // pythInitData, + // // ]); + + // // console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); + + // // const networkId = hre.network.config.chainId; + // // const registryPath = `networks/${networkId}.json`; + // // console.log(`Saving addresses in ${registryPath}`); + // // writeFileSync( + // // registryPath, + // // JSON.stringify( + // // [ + // // { + // // contractName: "WormholeReceiver", + // // address: wormholeReceiverContract.address, + // // }, + // // { + // // contractName: "PythUpgradable", + // // address: pythProxyContract.address, + // // }, + // // ], + // // null, + // // 2 + // // ) + // // ); +} diff --git a/target_chains/ethereum/contracts/deploy/zkSyncPriceFeedDeploy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts similarity index 67% rename from target_chains/ethereum/contracts/deploy/zkSyncPriceFeedDeploy.ts rename to target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts index 05b8b2051d..c1bf6c4fcf 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncPriceFeedDeploy.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts @@ -5,6 +5,7 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; import { writeFileSync } from "fs"; +import { deployWormholeContract } from "./zkSyncDeployWormhole"; // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; @@ -49,50 +50,10 @@ export default async function (hre: HardhatRuntimeEnvironment) { emitterChainIds, } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); const chainName = envOrErr("MIGRATIONS_NETWORK"); - const wormholeReceiverChainId = CHAINS[chainName]; - assert(wormholeReceiverChainId !== undefined); - const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); - const receiverImplArtifact = await deployer.loadArtifact( - "ReceiverImplementation" - ); - const wormholeReceiverArtifact = await deployer.loadArtifact( - "WormholeReceiver" - ); - - console.log("Deploying WormholeReceiver contract..."); - const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); - console.log("Deployed ReceiverSetup on", receiverSetupContract.address); - - console.log("Deploying ReceiverImplementation contract..."); - // deploy implementation - const receiverImplContract = await deployer.deploy(receiverImplArtifact); - console.log( - "Deployed ReceiverImplementation on", - receiverImplContract.address - ); - - // encode initialisation data - const whInitData = receiverSetupContract.interface.encodeFunctionData( - "setup", - [ - receiverImplContract.address, - wormholeInitialSigners, - wormholeReceiverChainId, - wormholeGovernanceChainId, - wormholeGovernanceContract, - ] - ); + const wormholeReceiverContract = await deployWormholeContract(deployer, chainName, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners); - // deploy proxy - const wormholeReceiverContract = await deployer.deploy( - wormholeReceiverArtifact, - [receiverSetupContract.address, whInitData] - ); - console.log( - `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` - ); // Hardcoding the initial sequence number for governance messages. const governanceInitialSequence = Number("0"); @@ -149,3 +110,53 @@ export default async function (hre: HardhatRuntimeEnvironment) { // ) // ); } + + + + + + + // const wormholeReceiverChainId = CHAINS[chainName]; + // assert(wormholeReceiverChainId !== undefined); + + // const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); + // const receiverImplArtifact = await deployer.loadArtifact( + // "ReceiverImplementation" + // ); + // const wormholeReceiverArtifact = await deployer.loadArtifact( + // "WormholeReceiver" + // ); + + // console.log("Deploying WormholeReceiver contract..."); + // const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); + // console.log("Deployed ReceiverSetup on", receiverSetupContract.address); + + // console.log("Deploying ReceiverImplementation contract..."); + // // deploy implementation + // const receiverImplContract = await deployer.deploy(receiverImplArtifact); + // console.log( + // "Deployed ReceiverImplementation on", + // receiverImplContract.address + // ); + + // // encode initialisation data + // const whInitData = receiverSetupContract.interface.encodeFunctionData( + // "setup", + // [ + // receiverImplContract.address, + // wormholeInitialSigners, + // wormholeReceiverChainId, + // wormholeGovernanceChainId, + // wormholeGovernanceContract, + // ] + // ); + + // // deploy proxy + // const wormholeReceiverContract = await deployer.deploy( + // wormholeReceiverArtifact, + // [receiverSetupContract.address, whInitData] + // ); + + // console.log( + // `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` + // ); \ No newline at end of file diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts new file mode 100644 index 0000000000..6251c97406 --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts @@ -0,0 +1,65 @@ +import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager"; +import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; +import { CHAINS } from "@pythnetwork/xc-admin-common"; +import { assert } from "chai"; + +export function findWormholeContract(chainId: string): EvmWormholeContract | undefined { + for (const contract of Object.values(DefaultStore.wormhole_contracts)) { + if ( + contract instanceof EvmWormholeContract && + contract.getChain().getId() === chainId + ) { + return contract; + } + } + } + + +export async function deployWormholeContract(deployer: Deployer, chainName: string, wormholeGovernanceChainId: string, wormholeGovernanceContract: string, wormholeInitialSigners: string[]): Promise { + const wormholeReceiverChainId = CHAINS[chainName]; + assert(wormholeReceiverChainId !== undefined); + + const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); + const receiverImplArtifact = await deployer.loadArtifact( + "ReceiverImplementation" + ); + const wormholeReceiverArtifact = await deployer.loadArtifact( + "WormholeReceiver" + ); + console.log("Deploying WormholeReceiver contract..."); + + const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); + console.log("Deployed ReceiverSetup on", receiverSetupContract.address); + console.log("Deploying ReceiverImplementation contract..."); + + // deploy implementation + const receiverImplContract = await deployer.deploy(receiverImplArtifact); + console.log( + "Deployed ReceiverImplementation on", + receiverImplContract.address + ); + + // encode initialisation data + const whInitData = receiverSetupContract.interface.encodeFunctionData( + "setup", + [ + receiverImplContract.address, + wormholeInitialSigners, + wormholeReceiverChainId, + wormholeGovernanceChainId, + wormholeGovernanceContract, + ] + ); + + // deploy proxy + const wormholeReceiverContract = await deployer.deploy( + wormholeReceiverArtifact, + [receiverSetupContract.address, whInitData] + ); + + console.log( + `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` + ); + + return wormholeReceiverContract as unknown as EvmWormholeContract; +} diff --git a/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts b/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts deleted file mode 100644 index 1a58918bb2..0000000000 --- a/target_chains/ethereum/contracts/deploy/zkSyncEntropyDeploy.ts +++ /dev/null @@ -1,212 +0,0 @@ -require("dotenv").config({ path: ".env" }); -import { utils, Wallet } from "zksync-web3"; -import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; -import { CHAINS } from "@pythnetwork/xc-admin-common"; -import { assert } from "chai"; -import { EvmWormholeContract } from "@pythnetwork/contract-manager"; -import { writeFileSync } from "fs"; -// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work -// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; - -const { getDefaultConfig } = require("../scripts/contractManagerConfig"); - -function envOrErr(name: string): string { - const res = process.env[name]; - if (res === undefined) { - throw new Error(`${name} environment variable is not set.`); - } - return res; -} - -export default async function (hre: HardhatRuntimeEnvironment) { - // Initialize the wallet. - const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); - - // Create deployer object and load the artifact of the contract we want to deploy. - const deployer = new Deployer(hre, wallet); - - // Deposit some funds to L2 in order to be able to perform L2 transactions. Uncomment - // this if the deployment account is unfunded. - // - // const depositAmount = ethers.utils.parseEther("0.005"); - // const depositHandle = await deployer.zkWallet.deposit({ - // to: deployer.zkWallet.address, - // token: utils.ETH_ADDRESS, - // amount: depositAmount, - // }); - // // Wait until the deposit is processed on zkSync - // await depositHandle.wait(); - - // Deploy WormholeReceiver contract. - const { - wormholeGovernanceChainId, - wormholeGovernanceContract, - wormholeInitialSigners, - governanceEmitter, - governanceChainId, - emitterAddresses, - emitterChainIds, - } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); - - console.log("WormholeGovernanceChainId: ", wormholeGovernanceChainId); - console.log("WormholeGovernanceContract: ", wormholeGovernanceContract); - console.log("WormholeInitialSigners: ", wormholeInitialSigners); - console.log("GovernanceEmitter: ", governanceEmitter); - console.log("GovernanceChainId: ", governanceChainId); - console.log("EmitterAddresses: ", emitterAddresses); - console.log("EmitterChainIds: ", emitterChainIds); - - const chainName = envOrErr("MIGRATIONS_NETWORK"); - const wormholeReceiverChainId = CHAINS[chainName]; - assert(wormholeReceiverChainId !== undefined); - - console.log("wormholeReceiverChainId: ", wormholeReceiverChainId); - console.log("Chain ID: ", hre.network.config); - - - - - // Check if the wormhole receiver contract is already deployed. - const wormholeReceiverAddress = process.env.WORMHOLE_RECEIVER_ADDRESS; - let wormholeReceiverContract = new EvmWormholeContract( - wormholeReceiverChainId, - wormholeReceiverAddress - ); - - console.log("wormholeReceiverContract: ", wormholeReceiverContract); - - - if (wormholeReceiverContract.address) { - console.log( - "WormholeReceiver already deployed at: ", - wormholeReceiverAddress - ); - } else { - console.log("WormholeReceiver not deployed yet, deploying..."); - const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); - const receiverImplArtifact = await deployer.loadArtifact( - "ReceiverImplementation" - ); - const wormholeReceiverArtifact = await deployer.loadArtifact( - "WormholeReceiver" - ); - - console.log("Deploying WormholeReceiver contract..."); - const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); - console.log("Deployed ReceiverSetup on", receiverSetupContract.address); - - console.log("Deploying ReceiverImplementation contract..."); - // deploy implementation - const receiverImplContract = await deployer.deploy(receiverImplArtifact); - console.log( - "Deployed ReceiverImplementation on", - receiverImplContract.address - ); - - // encode initialisation data - const whInitData = receiverSetupContract.interface.encodeFunctionData( - "setup", - [ - receiverImplContract.address, - wormholeInitialSigners, - wormholeReceiverChainId, - wormholeGovernanceChainId, - wormholeGovernanceContract, - ] - ); - - // deploy proxy - const wormholeReceiverContract = await deployer.deploy( - wormholeReceiverArtifact, - [receiverSetupContract.address, whInitData] - ); - - console.log( - `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` - ); - - console.log("Syncing mainnet guardian sets..."); - await (wormholeReceiverContract as EvmWormholeContract).syncMainnetGuardianSets(wallet.privateKey); - console.log("✅ Synced mainnet guardian sets"); - } - - // Hardcoding the initial sequence number for governance messages. - const governanceInitialSequence = Number("0"); - - // TODO: Top up accounts if necessary - - // Deploy Executor contracts - const executorImplArtifact = await deployer.loadArtifact( - "ExecutorUpgradable" - ); - // const executorImplContract = await deployer.deploy(executorImplArtifact); - // console.log( - // `Deployed ExecutorImplementation on ${executorImplContract.address}` - // ); - - // const executorInitData = executorImplContract.interface.encodeFunctionData( - // "initialize", - // [ - // wormholeReceiverContract.address, - // 0, - // wormholeReceiverChainId, - // governanceChainId, - // governanceEmitter, - // ] - // ); - - // Deploy Entropy contracts - - // const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); - // const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); - - // const pythImplArtifact = await deployer.loadArtifact("PythUpgradable"); - // const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); - - // const pythImplContract = await deployer.deploy(pythImplArtifact); - - // console.log(`Deployed Pyth implementation on ${pythImplContract.address}`); - - // const pythInitData = pythImplContract.interface.encodeFunctionData( - // "initialize", - // [ - // wormholeReceiverContract.address, - // emitterChainIds, - // emitterAddresses, - // governanceChainId, - // governanceEmitter, - // governanceInitialSequence, - // validTimePeriodSeconds, - // singleUpdateFeeInWei, - // ] - // ); - - // const pythProxyContract = await deployer.deploy(pythProxyArtifact, [ - // pythImplContract.address, - // pythInitData, - // ]); - - // console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); - - // const networkId = hre.network.config.chainId; - // const registryPath = `networks/${networkId}.json`; - // console.log(`Saving addresses in ${registryPath}`); - // writeFileSync( - // registryPath, - // JSON.stringify( - // [ - // { - // contractName: "WormholeReceiver", - // address: wormholeReceiverContract.address, - // }, - // { - // contractName: "PythUpgradable", - // address: pythProxyContract.address, - // }, - // ], - // null, - // 2 - // ) - // ); -} diff --git a/target_chains/ethereum/sdk/js/package.json b/target_chains/ethereum/sdk/js/package.json index 0c3d2215ce..22774deb77 100644 --- a/target_chains/ethereum/sdk/js/package.json +++ b/target_chains/ethereum/sdk/js/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/pyth-evm-js", - "version": "1.73.0", + "version": "1.74.0", "description": "Pyth Network EVM Utils in JS", "homepage": "https://pyth.network", "author": { diff --git a/target_chains/ethereum/sdk/js/src/index.ts b/target_chains/ethereum/sdk/js/src/index.ts index bc525a5dda..2ad49d2452 100644 --- a/target_chains/ethereum/sdk/js/src/index.ts +++ b/target_chains/ethereum/sdk/js/src/index.ts @@ -91,7 +91,7 @@ export const CONTRACT_ADDR: Record = { conflux_espace_testnet: "0xDd24F84d36BF92C65F92307595335bdFab5Bbd21", core_dao_testnet: "0x8D254a21b3C86D32F7179855531CE99164721933", cronos_testnet: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320", - cronos_zkevm_testnet: "0x67DFF3D12dFDCeC9f85fd86f4cBDb0a111fF721A", + cronos_zkevm_testnet: "0xB1DB1498902F08E16E11F1a423ec9CCB9537E1D6", dela_deperp_testnet: "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729", dela_mithreum_deperp_testnet: "0xe9d69CdD6Fe41e7B621B4A688C5D1a68cB5c8ADc", etherlink_testnet: "0x2880aB155794e7179c9eE2e38200202908C17B43", From cf9172c4b4c39afa8ecafc4d5fe06d46322d05a1 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Tue, 22 Oct 2024 16:57:45 -0400 Subject: [PATCH 3/5] udpated scripts --- .../contracts/deploy/zkSyncDeployEntropy.ts | 160 ++++++------------ .../contracts/deploy/zkSyncDeployPriceFeed.ts | 14 +- .../contracts/deploy/zkSyncDeployWormhole.ts | 11 +- 3 files changed, 67 insertions(+), 118 deletions(-) diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts index 9dc296fdcf..2dca4b2a04 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts @@ -5,7 +5,7 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager"; -import { findWormholeContract } from "./zkSyncDeployWormhole"; +import { findWormholeContract, deployWormholeContract } from "./zkSyncDeployWormhole"; // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; @@ -24,124 +24,66 @@ function envOrErr(name: string): string { export default async function (hre: HardhatRuntimeEnvironment) { // Initialize the wallet. - // const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); + const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); // Create deployer object and load the artifact of the contract we want to deploy. - // const deployer = new Deployer(hre, wallet); - - // const { - // wormholeGovernanceChainId, - // wormholeGovernanceContract, - // wormholeInitialSigners, - // governanceEmitter, - // governanceChainId, - // emitterAddresses, - // emitterChainIds, - // } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); - - // console.log("WormholeGovernanceChainId: ", wormholeGovernanceChainId); - // console.log("WormholeGovernanceContract: ", wormholeGovernanceContract); - // console.log("WormholeInitialSigners: ", wormholeInitialSigners); - // console.log("GovernanceEmitter: ", governanceEmitter); - // console.log("GovernanceChainId: ", governanceChainId); - // console.log("EmitterAddresses: ", emitterAddresses); - // console.log("EmitterChainIds: ", emitterChainIds); + const deployer = new Deployer(hre, wallet); - const chainName = envOrErr("MIGRATIONS_NETWORK"); - // const wormholeReceiverChainId = CHAINS[chainName]; - // assert(wormholeReceiverChainId !== undefined); + - // console.log("wormholeReceiverChainId: ", wormholeReceiverChainId); - // console.log("Chain ID: ", hre.network.config); + const { + wormholeGovernanceChainId, + wormholeGovernanceContract, + wormholeInitialSigners, + governanceEmitter, + governanceChainId, + emitterAddresses, + emitterChainIds, + } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); - const chain = DefaultStore.chains[chainName]; - if (!chain) { - throw new Error(`Chain ${chainName} not found`); - } else if (!(chain instanceof EvmChain)) { - throw new Error(`Chain ${chainName} is not an EVM chain`); - } + const chainName = envOrErr("MIGRATIONS_NETWORK"); - const wormholeContract = findWormholeContract(chainName); - console.log("Wormhole contract: ", wormholeContract); - if (!wormholeContract) { + const wormholeReceiverChainId = CHAINS[chainName]; + assert(wormholeReceiverChainId !== undefined); + + let wormholeReceiverContractAddress = await findWormholeContract(chainName); + if (!wormholeReceiverContractAddress) { console.log(`Wormhole contract not found for chain ${chainName}`); console.log("Deploying Wormhole contract..."); + wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners, wormholeReceiverChainId); } - + + console.log("WormholeReceiver contract address:", wormholeReceiverContractAddress); // // TODO: Top up accounts if necessary - // // Deploy Executor contracts - // const executorImplArtifact = await deployer.loadArtifact( - // "ExecutorUpgradable" - // ); - // // const executorImplContract = await deployer.deploy(executorImplArtifact); - // // console.log( - // // `Deployed ExecutorImplementation on ${executorImplContract.address}` - // // ); - - // // const executorInitData = executorImplContract.interface.encodeFunctionData( - // // "initialize", - // // [ - // // wormholeReceiverContract.address, - // // 0, - // // wormholeReceiverChainId, - // // governanceChainId, - // // governanceEmitter, - // // ] - // // ); - - // // Deploy Entropy contracts - - // // const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); - // // const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); - - // // const pythImplArtifact = await deployer.loadArtifact("PythUpgradable"); - // // const pythProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); - - // // const pythImplContract = await deployer.deploy(pythImplArtifact); - - // // console.log(`Deployed Pyth implementation on ${pythImplContract.address}`); - - // // const pythInitData = pythImplContract.interface.encodeFunctionData( - // // "initialize", - // // [ - // // wormholeReceiverContract.address, - // // emitterChainIds, - // // emitterAddresses, - // // governanceChainId, - // // governanceEmitter, - // // governanceInitialSequence, - // // validTimePeriodSeconds, - // // singleUpdateFeeInWei, - // // ] - // // ); - - // // const pythProxyContract = await deployer.deploy(pythProxyArtifact, [ - // // pythImplContract.address, - // // pythInitData, - // // ]); - - // // console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); - - // // const networkId = hre.network.config.chainId; - // // const registryPath = `networks/${networkId}.json`; - // // console.log(`Saving addresses in ${registryPath}`); - // // writeFileSync( - // // registryPath, - // // JSON.stringify( - // // [ - // // { - // // contractName: "WormholeReceiver", - // // address: wormholeReceiverContract.address, - // // }, - // // { - // // contractName: "PythUpgradable", - // // address: pythProxyContract.address, - // // }, - // // ], - // // null, - // // 2 - // // ) - // // ); + const executorContractAddress = await deployExecutorContract(deployer, wormholeReceiverContractAddress, wormholeReceiverChainId, governanceEmitter); + +} + +async function deployExecutorContract(deployer: Deployer, wormholeReceiverContractAddress: string, wormholeReceiverChainId: number, governanceEmitter: string) { + const executorImplArtifact = await deployer.loadArtifact("ExecutorUpgradable"); + const executorImplContract = await deployer.deploy(executorImplArtifact); + + const executorInitData = executorImplContract.interface.encodeFunctionData( + "initialize", + [ + wormholeReceiverContractAddress, + 0, // lastExecutedSequence, + wormholeReceiverChainId, + governanceEmitter, + governanceEmitter + ] + ); + + const executorProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); + + const executorProxyContract = await deployer.deploy(executorProxyArtifact, [ + executorImplContract.address, + executorInitData, + ]); + + console.log(`Deployed Executor contract on ${executorProxyContract.address}`); + + return executorProxyContract.address; } diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts index c1bf6c4fcf..b664f4b346 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts @@ -5,7 +5,7 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; import { writeFileSync } from "fs"; -import { deployWormholeContract } from "./zkSyncDeployWormhole"; +import { deployWormholeContract, findWormholeContract } from "./zkSyncDeployWormhole"; // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; @@ -51,7 +51,15 @@ export default async function (hre: HardhatRuntimeEnvironment) { } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); const chainName = envOrErr("MIGRATIONS_NETWORK"); - const wormholeReceiverContract = await deployWormholeContract(deployer, chainName, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners); + const wormholeReceiverChainId = CHAINS[chainName]; + assert(wormholeReceiverChainId !== undefined); + + let wormholeReceiverContractAddress = await findWormholeContract(chainName); + if (!wormholeReceiverContractAddress) { + console.log(`Wormhole contract not found for chain ${chainName}`); + console.log("Deploying Wormhole contract..."); + wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeReceiverChainId, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners); + } @@ -71,7 +79,7 @@ export default async function (hre: HardhatRuntimeEnvironment) { const pythInitData = pythImplContract.interface.encodeFunctionData( "initialize", [ - wormholeReceiverContract.address, + wormholeReceiverContractAddress, emitterChainIds, emitterAddresses, governanceChainId, diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts index 6251c97406..bedfa2563a 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts @@ -3,21 +3,20 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; -export function findWormholeContract(chainId: string): EvmWormholeContract | undefined { +export function findWormholeContract(chainId: string): string | undefined { for (const contract of Object.values(DefaultStore.wormhole_contracts)) { if ( contract instanceof EvmWormholeContract && contract.getChain().getId() === chainId ) { - return contract; + return contract.address; } } } -export async function deployWormholeContract(deployer: Deployer, chainName: string, wormholeGovernanceChainId: string, wormholeGovernanceContract: string, wormholeInitialSigners: string[]): Promise { - const wormholeReceiverChainId = CHAINS[chainName]; - assert(wormholeReceiverChainId !== undefined); +export async function deployWormholeContract(deployer: Deployer, chainName: string, wormholeGovernanceChainId: string, wormholeGovernanceContract: string, wormholeInitialSigners: string[], wormholeReceiverChainId: number): Promise { + const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); const receiverImplArtifact = await deployer.loadArtifact( @@ -61,5 +60,5 @@ export async function deployWormholeContract(deployer: Deployer, chainName: stri `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` ); - return wormholeReceiverContract as unknown as EvmWormholeContract; + return wormholeReceiverContract.address; } From ec367ded06129d282b556c16a6cb5a19a8ffe9e8 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Wed, 23 Oct 2024 16:11:29 -0400 Subject: [PATCH 4/5] chore(entropy) Deploy on abstract --- .../store/contracts/EvmEntropyContracts.yaml | 3 + .../ethereum/contracts/.env.template | 2 +- .../contracts/deploy/zkSyncDeployEntropy.ts | 109 +++++++++++++++--- .../contracts/deploy/zkSyncDeployPriceFeed.ts | 68 +++-------- .../contracts/deploy/zkSyncDeployWormhole.ts | 34 +++--- 5 files changed, 132 insertions(+), 84 deletions(-) diff --git a/contract_manager/store/contracts/EvmEntropyContracts.yaml b/contract_manager/store/contracts/EvmEntropyContracts.yaml index eadca72856..f0a6543a88 100644 --- a/contract_manager/store/contracts/EvmEntropyContracts.yaml +++ b/contract_manager/store/contracts/EvmEntropyContracts.yaml @@ -115,3 +115,6 @@ - chain: sanko_testnet address: "0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb" type: EvmEntropyContract +- chain: abstract_testnet + address: "0x858687fD592112f7046E394A3Bf10D0C11fF9e63" + type: EvmEntropyContract diff --git a/target_chains/ethereum/contracts/.env.template b/target_chains/ethereum/contracts/.env.template index d99d52bfd2..6c716b3f97 100644 --- a/target_chains/ethereum/contracts/.env.template +++ b/target_chains/ethereum/contracts/.env.template @@ -1,7 +1,7 @@ # Network Config MIGRATIONS_DIR= # ./migrations/prod-receiver MIGRATIONS_NETWORK= # xyz - +MAINNET= # The duration that a price feed stored in the contract is considered to be # valid, after this duration, the price feed is stale and will be invalid. diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts index 2dca4b2a04..ebede64163 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts @@ -4,8 +4,15 @@ import { HardhatRuntimeEnvironment } from "hardhat/types"; import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; -import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager"; -import { findWormholeContract, deployWormholeContract } from "./zkSyncDeployWormhole"; +import { + DefaultStore, + EvmChain, + EvmWormholeContract, +} from "@pythnetwork/contract-manager"; +import { + findWormholeContract, + deployWormholeContract, +} from "./zkSyncDeployWormhole"; // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; @@ -19,26 +26,29 @@ function envOrErr(name: string): string { } return res; } - - +export const ENTROPY_DEFAULT_PROVIDER = { + mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506", + testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344", +}; +export const ENTROPY_DEFAULT_KEEPER = { + mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130", + testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df", +}; export default async function (hre: HardhatRuntimeEnvironment) { // Initialize the wallet. const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC")); + const isMainnet = envOrErr("MAINNET") === "true"; // Create deployer object and load the artifact of the contract we want to deploy. const deployer = new Deployer(hre, wallet); - - const { wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners, governanceEmitter, governanceChainId, - emitterAddresses, - emitterChainIds, } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); const chainName = envOrErr("MIGRATIONS_NETWORK"); @@ -50,20 +60,58 @@ export default async function (hre: HardhatRuntimeEnvironment) { if (!wormholeReceiverContractAddress) { console.log(`Wormhole contract not found for chain ${chainName}`); console.log("Deploying Wormhole contract..."); - wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners, wormholeReceiverChainId); + wormholeReceiverContractAddress = await deployWormholeContract( + deployer, + chainName, + wormholeGovernanceChainId, + wormholeGovernanceContract, + wormholeInitialSigners, + wormholeReceiverChainId + ); } - console.log("WormholeReceiver contract address:", wormholeReceiverContractAddress); - + console.log( + "WormholeReceiver contract address:", + wormholeReceiverContractAddress + ); + // // TODO: Top up accounts if necessary - const executorContractAddress = await deployExecutorContract(deployer, wormholeReceiverContractAddress, wormholeReceiverChainId, governanceEmitter); + const executorContractAddress = await deployExecutorContract( + deployer, + wormholeReceiverContractAddress, + wormholeReceiverChainId, + governanceChainId, + governanceEmitter + ); + + console.log("Executor contract address:", executorContractAddress); + const entropyContractAddress = await deployEntropyContract( + deployer, + executorContractAddress, + wormholeReceiverChainId, + isMainnet + ); + + console.log("Entropy contract address:", entropyContractAddress); } -async function deployExecutorContract(deployer: Deployer, wormholeReceiverContractAddress: string, wormholeReceiverChainId: number, governanceEmitter: string) { - const executorImplArtifact = await deployer.loadArtifact("ExecutorUpgradable"); +async function deployExecutorContract( + deployer: Deployer, + wormholeReceiverContractAddress: string, + wormholeReceiverChainId: number, + governanceChainId: string, + governanceEmitter: string +) { + const executorImplArtifact = await deployer.loadArtifact( + "ExecutorUpgradable" + ); const executorImplContract = await deployer.deploy(executorImplArtifact); + console.log( + "Deployed ExecutorImpl contract on", + executorImplContract.address + ); const executorInitData = executorImplContract.interface.encodeFunctionData( "initialize", @@ -71,8 +119,8 @@ async function deployExecutorContract(deployer: Deployer, wormholeReceiverContra wormholeReceiverContractAddress, 0, // lastExecutedSequence, wormholeReceiverChainId, + governanceChainId, governanceEmitter, - governanceEmitter ] ); @@ -87,3 +135,34 @@ async function deployExecutorContract(deployer: Deployer, wormholeReceiverContra return executorProxyContract.address; } + +async function deployEntropyContract( + deployer: Deployer, + executorContractAddress: string, + chainId: number, + isMainnet: boolean +) { + const entropyImplArtifact = await deployer.loadArtifact("EntropyUpgradable"); + const entropyImplContract = await deployer.deploy(entropyImplArtifact); + + const entropyInitData = entropyImplContract.interface.encodeFunctionData( + "initialize", + [ + executorContractAddress, + executorContractAddress, + 1, + isMainnet + ? ENTROPY_DEFAULT_PROVIDER.mainnet + : ENTROPY_DEFAULT_PROVIDER.testnet, + true, + ] + ); + + const entropyProxyArtifact = await deployer.loadArtifact("ERC1967Proxy"); + const entropyProxyContract = await deployer.deploy(entropyProxyArtifact, [ + entropyImplContract.address, + entropyInitData, + ]); + + return entropyProxyContract.address; +} diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts index b664f4b346..430a26b3d2 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts @@ -5,7 +5,10 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; import { writeFileSync } from "fs"; -import { deployWormholeContract, findWormholeContract } from "./zkSyncDeployWormhole"; +import { + deployWormholeContract, + findWormholeContract, +} from "./zkSyncDeployWormhole"; // import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work // import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync"; @@ -53,16 +56,21 @@ export default async function (hre: HardhatRuntimeEnvironment) { const wormholeReceiverChainId = CHAINS[chainName]; assert(wormholeReceiverChainId !== undefined); - + let wormholeReceiverContractAddress = await findWormholeContract(chainName); if (!wormholeReceiverContractAddress) { console.log(`Wormhole contract not found for chain ${chainName}`); console.log("Deploying Wormhole contract..."); - wormholeReceiverContractAddress = await deployWormholeContract(deployer, chainName, wormholeReceiverChainId, wormholeGovernanceChainId, wormholeGovernanceContract, wormholeInitialSigners); + wormholeReceiverContractAddress = await deployWormholeContract( + deployer, + chainName, + wormholeReceiverChainId, + wormholeGovernanceChainId, + wormholeGovernanceContract, + wormholeInitialSigners + ); } - - // Hardcoding the initial sequence number for governance messages. const governanceInitialSequence = Number("0"); @@ -118,53 +126,3 @@ export default async function (hre: HardhatRuntimeEnvironment) { // ) // ); } - - - - - - - // const wormholeReceiverChainId = CHAINS[chainName]; - // assert(wormholeReceiverChainId !== undefined); - - // const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); - // const receiverImplArtifact = await deployer.loadArtifact( - // "ReceiverImplementation" - // ); - // const wormholeReceiverArtifact = await deployer.loadArtifact( - // "WormholeReceiver" - // ); - - // console.log("Deploying WormholeReceiver contract..."); - // const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); - // console.log("Deployed ReceiverSetup on", receiverSetupContract.address); - - // console.log("Deploying ReceiverImplementation contract..."); - // // deploy implementation - // const receiverImplContract = await deployer.deploy(receiverImplArtifact); - // console.log( - // "Deployed ReceiverImplementation on", - // receiverImplContract.address - // ); - - // // encode initialisation data - // const whInitData = receiverSetupContract.interface.encodeFunctionData( - // "setup", - // [ - // receiverImplContract.address, - // wormholeInitialSigners, - // wormholeReceiverChainId, - // wormholeGovernanceChainId, - // wormholeGovernanceContract, - // ] - // ); - - // // deploy proxy - // const wormholeReceiverContract = await deployer.deploy( - // wormholeReceiverArtifact, - // [receiverSetupContract.address, whInitData] - // ); - - // console.log( - // `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` - // ); \ No newline at end of file diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts index bedfa2563a..bd0941ca50 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts @@ -1,23 +1,31 @@ -import { DefaultStore, EvmChain, EvmWormholeContract } from "@pythnetwork/contract-manager"; +import { + DefaultStore, + EvmChain, + EvmWormholeContract, +} from "@pythnetwork/contract-manager"; import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; import { CHAINS } from "@pythnetwork/xc-admin-common"; import { assert } from "chai"; export function findWormholeContract(chainId: string): string | undefined { - for (const contract of Object.values(DefaultStore.wormhole_contracts)) { - if ( - contract instanceof EvmWormholeContract && - contract.getChain().getId() === chainId - ) { - return contract.address; - } + for (const contract of Object.values(DefaultStore.wormhole_contracts)) { + if ( + contract instanceof EvmWormholeContract && + contract.getChain().getId() === chainId + ) { + return contract.address; } } +} - -export async function deployWormholeContract(deployer: Deployer, chainName: string, wormholeGovernanceChainId: string, wormholeGovernanceContract: string, wormholeInitialSigners: string[], wormholeReceiverChainId: number): Promise { - - +export async function deployWormholeContract( + deployer: Deployer, + chainName: string, + wormholeGovernanceChainId: string, + wormholeGovernanceContract: string, + wormholeInitialSigners: string[], + wormholeReceiverChainId: number +): Promise { const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup"); const receiverImplArtifact = await deployer.loadArtifact( "ReceiverImplementation" @@ -26,7 +34,7 @@ export async function deployWormholeContract(deployer: Deployer, chainName: stri "WormholeReceiver" ); console.log("Deploying WormholeReceiver contract..."); - + const receiverSetupContract = await deployer.deploy(receiverSetupArtifact); console.log("Deployed ReceiverSetup on", receiverSetupContract.address); console.log("Deploying ReceiverImplementation contract..."); From abedeaaef4f4df113a823f6255387c25b560ec1e Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Fri, 25 Oct 2024 10:18:51 -0400 Subject: [PATCH 5/5] requested changes --- .../contracts/deploy/zkSyncDeployEntropy.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts index ebede64163..3212669d9b 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts @@ -7,7 +7,9 @@ import { assert } from "chai"; import { DefaultStore, EvmChain, + EvmEntropyContract, EvmWormholeContract, + ENTROPY_DEFAULT_PROVIDER, } from "@pythnetwork/contract-manager"; import { findWormholeContract, @@ -26,14 +28,6 @@ function envOrErr(name: string): string { } return res; } -export const ENTROPY_DEFAULT_PROVIDER = { - mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506", - testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344", -}; -export const ENTROPY_DEFAULT_KEEPER = { - mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130", - testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df", -}; export default async function (hre: HardhatRuntimeEnvironment) { // Initialize the wallet. @@ -49,10 +43,9 @@ export default async function (hre: HardhatRuntimeEnvironment) { wormholeInitialSigners, governanceEmitter, governanceChainId, + chainName, } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); - const chainName = envOrErr("MIGRATIONS_NETWORK"); - const wormholeReceiverChainId = CHAINS[chainName]; assert(wormholeReceiverChainId !== undefined); @@ -95,6 +88,11 @@ export default async function (hre: HardhatRuntimeEnvironment) { ); console.log("Entropy contract address:", entropyContractAddress); + + console.log("Saving the contract in the store..."); + const contract = new EvmEntropyContract(chainName, entropyContractAddress); + DefaultStore.entropy_contracts[contract.getId()] = contract; + DefaultStore.saveAllContracts(); } async function deployExecutorContract( @@ -150,7 +148,7 @@ async function deployEntropyContract( [ executorContractAddress, executorContractAddress, - 1, + 1, // pythFeeInWei isMainnet ? ENTROPY_DEFAULT_PROVIDER.mainnet : ENTROPY_DEFAULT_PROVIDER.testnet,