From 98b45a2c88a24f4677d208858f22a51381565cb1 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 30 May 2023 21:14:12 -0500 Subject: [PATCH 1/3] Push --- .../ethereum/contracts/.env.prod.neon | 5 + .../ethereum/contracts/deploy/neonDeploy.ts | 134 ++++++++++++++++++ .../ethereum/contracts/hardhat.config.ts | 7 + 3 files changed, 146 insertions(+) create mode 100644 target_chains/ethereum/contracts/.env.prod.neon create mode 100644 target_chains/ethereum/contracts/deploy/neonDeploy.ts diff --git a/target_chains/ethereum/contracts/.env.prod.neon b/target_chains/ethereum/contracts/.env.prod.neon new file mode 100644 index 0000000000..09570eed1d --- /dev/null +++ b/target_chains/ethereum/contracts/.env.prod.neon @@ -0,0 +1,5 @@ +MIGRATIONS_DIR=./migrations/prod-receiver +MIGRATIONS_NETWORK=neon +WORMHOLE_CHAIN_NAME=neon +CLUSTER=mainnet +VALID_TIME_PERIOD_SECONDS=60 diff --git a/target_chains/ethereum/contracts/deploy/neonDeploy.ts b/target_chains/ethereum/contracts/deploy/neonDeploy.ts new file mode 100644 index 0000000000..7aa8201272 --- /dev/null +++ b/target_chains/ethereum/contracts/deploy/neonDeploy.ts @@ -0,0 +1,134 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { ethers } from "hardhat"; +import loadEnv from "../scripts/loadEnv"; +import { CHAINS } from "@pythnetwork/xc-governance-sdk"; +import { assert } from "chai"; +import { writeFileSync } from "fs"; + +loadEnv("./"); + +function envOrErr(name: string): string { + const res = process.env[name]; + if (res === undefined) { + throw new Error(`${name} environment variable is not set.`); + } + return res; +} + +async function main() { + // Deploy WormholeReceiver contract. + const initialSigners = JSON.parse(envOrErr("INIT_SIGNERS")); + const whGovernanceChainId = envOrErr("INIT_GOV_CHAIN_ID"); + const whGovernanceContract = envOrErr("INIT_GOV_CONTRACT"); // bytes32 + + const chainName = envOrErr("WORMHOLE_CHAIN_NAME"); + const wormholeReceiverChainId = CHAINS[chainName]; + assert(wormholeReceiverChainId !== undefined); + + const receiverSetupArtifact = await ethers.getContractFactory( + "ReceiverSetup" + ); + const receiverImplArtifact = await ethers.getContractFactory( + "ReceiverImplementation" + ); + const wormholeReceiverArtifact = await ethers.getContractFactory( + "WormholeReceiver" + ); + + console.log("BLOCK: ", await ethers.provider.getBlockNumber()); + + const receiverSetupContract = await receiverSetupArtifact.deploy(); + + // deploy implementation + const receiverImplContract = await receiverImplArtifact.deploy(); + + // encode initialisation data + const whInitData = receiverSetupContract.interface.encodeFunctionData( + "setup", + [ + receiverImplContract.address, + initialSigners, + wormholeReceiverChainId, + whGovernanceChainId, + whGovernanceContract, + ] + ); + + // deploy proxy + const wormholeReceiverContract = await wormholeReceiverArtifact.deploy( + receiverSetupContract.address, + whInitData + ); + + console.log( + `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` + ); + + // Deploy Pyth contract. + const emitterChainIds = [ + envOrErr("SOLANA_CHAIN_ID"), + envOrErr("PYTHNET_CHAIN_ID"), + ]; + const emitterAddresses = [ + envOrErr("SOLANA_EMITTER"), + envOrErr("PYTHNET_EMITTER"), + ]; + const governanceChainId = envOrErr("GOVERNANCE_CHAIN_ID"); + const governanceEmitter = envOrErr("GOVERNANCE_EMITTER"); + // Default value for this field is 0 + const governanceInitialSequence = Number( + process.env.GOVERNANCE_INITIAL_SEQUENCE ?? "0" + ); + + const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); + const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); + + const pythImplArtifact = await ethers.getContractFactory("PythUpgradable"); + const pythProxyArtifact = await ethers.getContractFactory("ERC1967Proxy"); + + const pythImplContract = await pythImplArtifact.deploy(); + + const pythInitData = pythImplContract.interface.encodeFunctionData( + "initialize", + [ + wormholeReceiverContract.address, + emitterChainIds, + emitterAddresses, + governanceChainId, + governanceEmitter, + governanceInitialSequence, + validTimePeriodSeconds, + singleUpdateFeeInWei, + ] + ); + + const pythProxyContract = await pythProxyArtifact.deploy([ + pythImplContract.address, + pythInitData, + ]); + + console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); + + const networkId = (await ethers.getDefaultProvider().getNetwork()).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 + ) + ); +} + +main(); diff --git a/target_chains/ethereum/contracts/hardhat.config.ts b/target_chains/ethereum/contracts/hardhat.config.ts index 424c7b653c..f2ae387900 100644 --- a/target_chains/ethereum/contracts/hardhat.config.ts +++ b/target_chains/ethereum/contracts/hardhat.config.ts @@ -43,6 +43,13 @@ module.exports = { mnemonic: process.env.MNEMONIC, }, }, + neon: { + url: "REPLACE_THIS_BY_NEON_URL", + network_id: 245022934, + accounts: { + mnemonic: process.env.MNEMONIC, + }, + }, shimmer_testnet: { url: "https://json-rpc.evm.testnet.shimmer.network", chainId: 1071, From b818343c72070562b54f653598d47fa87abe3dc1 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Thu, 1 Jun 2023 19:37:17 +0100 Subject: [PATCH 2/3] Add config --- .../ethereum/contracts/deploy/neonDeploy.ts | 134 ------------------ .../ethereum/contracts/hardhat.config.ts | 7 - .../contracts/networks/245022934.json | 16 +++ .../ethereum/contracts/truffle-config.js | 4 + 4 files changed, 20 insertions(+), 141 deletions(-) delete mode 100644 target_chains/ethereum/contracts/deploy/neonDeploy.ts create mode 100644 target_chains/ethereum/contracts/networks/245022934.json diff --git a/target_chains/ethereum/contracts/deploy/neonDeploy.ts b/target_chains/ethereum/contracts/deploy/neonDeploy.ts deleted file mode 100644 index 7aa8201272..0000000000 --- a/target_chains/ethereum/contracts/deploy/neonDeploy.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { ethers } from "hardhat"; -import loadEnv from "../scripts/loadEnv"; -import { CHAINS } from "@pythnetwork/xc-governance-sdk"; -import { assert } from "chai"; -import { writeFileSync } from "fs"; - -loadEnv("./"); - -function envOrErr(name: string): string { - const res = process.env[name]; - if (res === undefined) { - throw new Error(`${name} environment variable is not set.`); - } - return res; -} - -async function main() { - // Deploy WormholeReceiver contract. - const initialSigners = JSON.parse(envOrErr("INIT_SIGNERS")); - const whGovernanceChainId = envOrErr("INIT_GOV_CHAIN_ID"); - const whGovernanceContract = envOrErr("INIT_GOV_CONTRACT"); // bytes32 - - const chainName = envOrErr("WORMHOLE_CHAIN_NAME"); - const wormholeReceiverChainId = CHAINS[chainName]; - assert(wormholeReceiverChainId !== undefined); - - const receiverSetupArtifact = await ethers.getContractFactory( - "ReceiverSetup" - ); - const receiverImplArtifact = await ethers.getContractFactory( - "ReceiverImplementation" - ); - const wormholeReceiverArtifact = await ethers.getContractFactory( - "WormholeReceiver" - ); - - console.log("BLOCK: ", await ethers.provider.getBlockNumber()); - - const receiverSetupContract = await receiverSetupArtifact.deploy(); - - // deploy implementation - const receiverImplContract = await receiverImplArtifact.deploy(); - - // encode initialisation data - const whInitData = receiverSetupContract.interface.encodeFunctionData( - "setup", - [ - receiverImplContract.address, - initialSigners, - wormholeReceiverChainId, - whGovernanceChainId, - whGovernanceContract, - ] - ); - - // deploy proxy - const wormholeReceiverContract = await wormholeReceiverArtifact.deploy( - receiverSetupContract.address, - whInitData - ); - - console.log( - `Deployed WormholeReceiver on ${wormholeReceiverContract.address}` - ); - - // Deploy Pyth contract. - const emitterChainIds = [ - envOrErr("SOLANA_CHAIN_ID"), - envOrErr("PYTHNET_CHAIN_ID"), - ]; - const emitterAddresses = [ - envOrErr("SOLANA_EMITTER"), - envOrErr("PYTHNET_EMITTER"), - ]; - const governanceChainId = envOrErr("GOVERNANCE_CHAIN_ID"); - const governanceEmitter = envOrErr("GOVERNANCE_EMITTER"); - // Default value for this field is 0 - const governanceInitialSequence = Number( - process.env.GOVERNANCE_INITIAL_SEQUENCE ?? "0" - ); - - const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS")); - const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI")); - - const pythImplArtifact = await ethers.getContractFactory("PythUpgradable"); - const pythProxyArtifact = await ethers.getContractFactory("ERC1967Proxy"); - - const pythImplContract = await pythImplArtifact.deploy(); - - const pythInitData = pythImplContract.interface.encodeFunctionData( - "initialize", - [ - wormholeReceiverContract.address, - emitterChainIds, - emitterAddresses, - governanceChainId, - governanceEmitter, - governanceInitialSequence, - validTimePeriodSeconds, - singleUpdateFeeInWei, - ] - ); - - const pythProxyContract = await pythProxyArtifact.deploy([ - pythImplContract.address, - pythInitData, - ]); - - console.log(`Deployed Pyth contract on ${pythProxyContract.address}`); - - const networkId = (await ethers.getDefaultProvider().getNetwork()).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 - ) - ); -} - -main(); diff --git a/target_chains/ethereum/contracts/hardhat.config.ts b/target_chains/ethereum/contracts/hardhat.config.ts index f2ae387900..424c7b653c 100644 --- a/target_chains/ethereum/contracts/hardhat.config.ts +++ b/target_chains/ethereum/contracts/hardhat.config.ts @@ -43,13 +43,6 @@ module.exports = { mnemonic: process.env.MNEMONIC, }, }, - neon: { - url: "REPLACE_THIS_BY_NEON_URL", - network_id: 245022934, - accounts: { - mnemonic: process.env.MNEMONIC, - }, - }, shimmer_testnet: { url: "https://json-rpc.evm.testnet.shimmer.network", chainId: 1071, diff --git a/target_chains/ethereum/contracts/networks/245022934.json b/target_chains/ethereum/contracts/networks/245022934.json new file mode 100644 index 0000000000..90e3f9546a --- /dev/null +++ b/target_chains/ethereum/contracts/networks/245022934.json @@ -0,0 +1,16 @@ +[ + { + "contractName": "Migrations", + "address": "0x7a7F2493c578796ABfBA15Ce2e914A7A819979B7" + }, + { + "contractName": "WormholeReceiver", + "address": "0x621330D0ECd449A06b72f41C1A93626cCEC53ccA", + "transactionHash": "0x4dc725831f247e91759fb1d09a8962f9f533c57ae468630e6848b918bf92c9a6" + }, + { + "contractName": "PythUpgradable", + "address": "0x7f2dB085eFC3560AFF33865dD727225d91B4f9A5", + "transactionHash": "0x276282e22f4ea59a8eeec5223ce34b560e4e34e65b7fc503ade05878e73521ef" + } +] diff --git a/target_chains/ethereum/contracts/truffle-config.js b/target_chains/ethereum/contracts/truffle-config.js index bcf3462a62..786a5550a3 100644 --- a/target_chains/ethereum/contracts/truffle-config.js +++ b/target_chains/ethereum/contracts/truffle-config.js @@ -263,6 +263,10 @@ module.exports = { provider: payerProvider("https://evmtestnet.confluxrpc.com"), network_id: 71, }, + neon: { + provider: payerProvider("NEON_RPC_PLACEHOLDER"), // Replace this by the neon RPC node endpoint + network_id: 245022934, + }, }, compilers: { From 796b9f9a6918a15674676aff5b0fae1b81e89311 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Thu, 1 Jun 2023 19:38:31 +0100 Subject: [PATCH 3/3] Sync up optimization for hardhat and truffle --- target_chains/ethereum/contracts/hardhat.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/ethereum/contracts/hardhat.config.ts b/target_chains/ethereum/contracts/hardhat.config.ts index 424c7b653c..929339a7b8 100644 --- a/target_chains/ethereum/contracts/hardhat.config.ts +++ b/target_chains/ethereum/contracts/hardhat.config.ts @@ -80,7 +80,7 @@ module.exports = { settings: { optimizer: { enabled: true, - runs: 10000, + runs: 5000, }, }, },