Skip to content

Commit 98b45a2

Browse files
committed
Push
1 parent 6cdcf4d commit 98b45a2

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MIGRATIONS_DIR=./migrations/prod-receiver
2+
MIGRATIONS_NETWORK=neon
3+
WORMHOLE_CHAIN_NAME=neon
4+
CLUSTER=mainnet
5+
VALID_TIME_PERIOD_SECONDS=60
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { ethers } from "hardhat";
3+
import loadEnv from "../scripts/loadEnv";
4+
import { CHAINS } from "@pythnetwork/xc-governance-sdk";
5+
import { assert } from "chai";
6+
import { writeFileSync } from "fs";
7+
8+
loadEnv("./");
9+
10+
function envOrErr(name: string): string {
11+
const res = process.env[name];
12+
if (res === undefined) {
13+
throw new Error(`${name} environment variable is not set.`);
14+
}
15+
return res;
16+
}
17+
18+
async function main() {
19+
// Deploy WormholeReceiver contract.
20+
const initialSigners = JSON.parse(envOrErr("INIT_SIGNERS"));
21+
const whGovernanceChainId = envOrErr("INIT_GOV_CHAIN_ID");
22+
const whGovernanceContract = envOrErr("INIT_GOV_CONTRACT"); // bytes32
23+
24+
const chainName = envOrErr("WORMHOLE_CHAIN_NAME");
25+
const wormholeReceiverChainId = CHAINS[chainName];
26+
assert(wormholeReceiverChainId !== undefined);
27+
28+
const receiverSetupArtifact = await ethers.getContractFactory(
29+
"ReceiverSetup"
30+
);
31+
const receiverImplArtifact = await ethers.getContractFactory(
32+
"ReceiverImplementation"
33+
);
34+
const wormholeReceiverArtifact = await ethers.getContractFactory(
35+
"WormholeReceiver"
36+
);
37+
38+
console.log("BLOCK: ", await ethers.provider.getBlockNumber());
39+
40+
const receiverSetupContract = await receiverSetupArtifact.deploy();
41+
42+
// deploy implementation
43+
const receiverImplContract = await receiverImplArtifact.deploy();
44+
45+
// encode initialisation data
46+
const whInitData = receiverSetupContract.interface.encodeFunctionData(
47+
"setup",
48+
[
49+
receiverImplContract.address,
50+
initialSigners,
51+
wormholeReceiverChainId,
52+
whGovernanceChainId,
53+
whGovernanceContract,
54+
]
55+
);
56+
57+
// deploy proxy
58+
const wormholeReceiverContract = await wormholeReceiverArtifact.deploy(
59+
receiverSetupContract.address,
60+
whInitData
61+
);
62+
63+
console.log(
64+
`Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
65+
);
66+
67+
// Deploy Pyth contract.
68+
const emitterChainIds = [
69+
envOrErr("SOLANA_CHAIN_ID"),
70+
envOrErr("PYTHNET_CHAIN_ID"),
71+
];
72+
const emitterAddresses = [
73+
envOrErr("SOLANA_EMITTER"),
74+
envOrErr("PYTHNET_EMITTER"),
75+
];
76+
const governanceChainId = envOrErr("GOVERNANCE_CHAIN_ID");
77+
const governanceEmitter = envOrErr("GOVERNANCE_EMITTER");
78+
// Default value for this field is 0
79+
const governanceInitialSequence = Number(
80+
process.env.GOVERNANCE_INITIAL_SEQUENCE ?? "0"
81+
);
82+
83+
const validTimePeriodSeconds = Number(envOrErr("VALID_TIME_PERIOD_SECONDS"));
84+
const singleUpdateFeeInWei = Number(envOrErr("SINGLE_UPDATE_FEE_IN_WEI"));
85+
86+
const pythImplArtifact = await ethers.getContractFactory("PythUpgradable");
87+
const pythProxyArtifact = await ethers.getContractFactory("ERC1967Proxy");
88+
89+
const pythImplContract = await pythImplArtifact.deploy();
90+
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+
105+
const pythProxyContract = await pythProxyArtifact.deploy([
106+
pythImplContract.address,
107+
pythInitData,
108+
]);
109+
110+
console.log(`Deployed Pyth contract on ${pythProxyContract.address}`);
111+
112+
const networkId = (await ethers.getDefaultProvider().getNetwork()).chainId;
113+
const registryPath = `networks/${networkId}.json`;
114+
console.log(`Saving addresses in ${registryPath}`);
115+
writeFileSync(
116+
registryPath,
117+
JSON.stringify(
118+
[
119+
{
120+
contractName: "WormholeReceiver",
121+
address: wormholeReceiverContract.address,
122+
},
123+
{
124+
contractName: "PythUpgradable",
125+
address: pythProxyContract.address,
126+
},
127+
],
128+
null,
129+
2
130+
)
131+
);
132+
}
133+
134+
main();

target_chains/ethereum/contracts/hardhat.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ module.exports = {
4343
mnemonic: process.env.MNEMONIC,
4444
},
4545
},
46+
neon: {
47+
url: "REPLACE_THIS_BY_NEON_URL",
48+
network_id: 245022934,
49+
accounts: {
50+
mnemonic: process.env.MNEMONIC,
51+
},
52+
},
4653
shimmer_testnet: {
4754
url: "https://json-rpc.evm.testnet.shimmer.network",
4855
chainId: 1071,

0 commit comments

Comments
 (0)