From ed31243d1fb1ce39e6eecb13727faa7f37ca262b Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Fri, 25 Oct 2024 10:30:22 -0400 Subject: [PATCH] Chore(entropy) deploy on abstract (#2056) * initial commit * Deployed cronos zk testnet * udpated scripts * chore(entropy) Deploy on abstract * requested changes --- contract_manager/store/chains/EvmChains.yaml | 2 +- .../store/contracts/EvmEntropyContracts.yaml | 3 + .../contracts/EvmPriceFeedContracts.yaml | 6 +- .../store/contracts/EvmWormholeContracts.yaml | 6 +- .../ethereum/contracts/.env.template | 2 +- .../contracts/deploy/zkSyncDeployEntropy.ts | 166 ++++++++++++++++++ ...SyncDeploy.ts => zkSyncDeployPriceFeed.ts} | 55 ++---- .../contracts/deploy/zkSyncDeployWormhole.ts | 72 ++++++++ target_chains/ethereum/sdk/js/src/index.ts | 2 +- 9 files changed, 266 insertions(+), 48 deletions(-) create mode 100644 target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts rename target_chains/ethereum/contracts/deploy/{zkSyncDeploy.ts => zkSyncDeployPriceFeed.ts} (75%) create mode 100644 target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts diff --git a/contract_manager/store/chains/EvmChains.yaml b/contract_manager/store/chains/EvmChains.yaml index cd58c6323c..3f69c37041 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/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/contract_manager/store/contracts/EvmPriceFeedContracts.yaml b/contract_manager/store/contracts/EvmPriceFeedContracts.yaml index 4eb8cd750e..f36339bef4 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 d2dac95bba..1053e965eb 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 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 new file mode 100644 index 0000000000..3212669d9b --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployEntropy.ts @@ -0,0 +1,166 @@ +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, + EvmEntropyContract, + EvmWormholeContract, + ENTROPY_DEFAULT_PROVIDER, +} 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"; + +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")); + 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, + chainName, + } = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK")); + + 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 + + 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); + + 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( + 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", + [ + wormholeReceiverContractAddress, + 0, // lastExecutedSequence, + wormholeReceiverChainId, + governanceChainId, + 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; +} + +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, // pythFeeInWei + 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/zkSyncDeploy.ts b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts similarity index 75% rename from target_chains/ethereum/contracts/deploy/zkSyncDeploy.ts rename to target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts index 05b8b2051d..430a26b3d2 100644 --- a/target_chains/ethereum/contracts/deploy/zkSyncDeploy.ts +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts @@ -5,6 +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 {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 +53,23 @@ 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, + 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, - ] - ); - - // deploy proxy - const wormholeReceiverContract = await deployer.deploy( - wormholeReceiverArtifact, - [receiverSetupContract.address, whInitData] - ); - - console.log( - `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` - ); + wormholeInitialSigners + ); + } // Hardcoding the initial sequence number for governance messages. const governanceInitialSequence = Number("0"); @@ -110,7 +87,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 new file mode 100644 index 0000000000..bd0941ca50 --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/zkSyncDeployWormhole.ts @@ -0,0 +1,72 @@ +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; + } + } +} + +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" + ); + 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.address; +} diff --git a/target_chains/ethereum/sdk/js/src/index.ts b/target_chains/ethereum/sdk/js/src/index.ts index 704b1fc934..0a413f50d5 100644 --- a/target_chains/ethereum/sdk/js/src/index.ts +++ b/target_chains/ethereum/sdk/js/src/index.ts @@ -93,7 +93,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",