Skip to content

Commit ed31243

Browse files
authored
Chore(entropy) deploy on abstract (#2056)
* initial commit * Deployed cronos zk testnet * udpated scripts * chore(entropy) Deploy on abstract * requested changes
1 parent 9487848 commit ed31243

File tree

9 files changed

+266
-48
lines changed

9 files changed

+266
-48
lines changed

contract_manager/store/chains/EvmChains.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@
662662
- id: cronos_zkevm_testnet
663663
mainnet: false
664664
rpcUrl: https://testnet.zkevm.cronos.org
665-
networkId: 282
665+
networkId: 240
666666
type: EvmChain
667667
- id: reya_testnet
668668
mainnet: false

contract_manager/store/contracts/EvmEntropyContracts.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@
115115
- chain: sanko_testnet
116116
address: "0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb"
117117
type: EvmEntropyContract
118+
- chain: abstract_testnet
119+
address: "0x858687fD592112f7046E394A3Bf10D0C11fF9e63"
120+
type: EvmEntropyContract

contract_manager/store/contracts/EvmPriceFeedContracts.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,15 @@
361361
- chain: kinto
362362
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
363363
type: EvmPriceFeedContract
364-
- chain: cronos_zkevm_testnet
365-
address: "0x67DFF3D12dFDCeC9f85fd86f4cBDb0a111fF721A"
366-
type: EvmPriceFeedContract
367364
- chain: reya_testnet
368365
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
369366
type: EvmPriceFeedContract
370367
- chain: cronos_zkevm_mainnet
371368
address: "0x056f829183Ec806A78c26C98961678c24faB71af"
372369
type: EvmPriceFeedContract
370+
- chain: cronos_zkevm_testnet
371+
address: "0xB1DB1498902F08E16E11F1a423ec9CCB9537E1D6"
372+
type: EvmPriceFeedContract
373373
- chain: movement_evm_devnet_imola
374374
address: "0x2880aB155794e7179c9eE2e38200202908C17B43"
375375
type: EvmPriceFeedContract

contract_manager/store/contracts/EvmWormholeContracts.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@
349349
- chain: kinto
350350
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
351351
type: EvmWormholeContract
352-
- chain: cronos_zkevm_testnet
353-
address: "0x3f5bB93eEC6E3D6784274291A5816Bc34E851dc8"
354-
type: EvmWormholeContract
355352
- chain: reya_testnet
356353
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
357354
type: EvmWormholeContract
@@ -361,6 +358,9 @@
361358
- chain: cronos_zkevm_mainnet
362359
address: "0xc10F5BE78E464BB0E1f534D66E5A6ecaB150aEFa"
363360
type: EvmWormholeContract
361+
- chain: cronos_zkevm_testnet
362+
address: "0x470d1c91b1b1d9295815A2357FB0D20E7350ab71"
363+
type: EvmWormholeContract
364364
- chain: movement_evm_devnet_imola
365365
address: "0xb27e5ca259702f209a29225d0eDdC131039C9933"
366366
type: EvmWormholeContract

target_chains/ethereum/contracts/.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Network Config
22
MIGRATIONS_DIR= # ./migrations/prod-receiver
33
MIGRATIONS_NETWORK= # xyz
4-
4+
MAINNET=
55

66
# The duration that a price feed stored in the contract is considered to be
77
# valid, after this duration, the price feed is stale and will be invalid.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
require("dotenv").config({ path: ".env" });
2+
import { utils, Wallet } from "zksync-web3";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
4+
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
5+
import { CHAINS } from "@pythnetwork/xc-admin-common";
6+
import { assert } from "chai";
7+
import {
8+
DefaultStore,
9+
EvmChain,
10+
EvmEntropyContract,
11+
EvmWormholeContract,
12+
ENTROPY_DEFAULT_PROVIDER,
13+
} from "@pythnetwork/contract-manager";
14+
import {
15+
findWormholeContract,
16+
deployWormholeContract,
17+
} from "./zkSyncDeployWormhole";
18+
19+
// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work
20+
// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync";
21+
22+
const { getDefaultConfig } = require("../scripts/contractManagerConfig");
23+
24+
function envOrErr(name: string): string {
25+
const res = process.env[name];
26+
if (res === undefined) {
27+
throw new Error(`${name} environment variable is not set.`);
28+
}
29+
return res;
30+
}
31+
32+
export default async function (hre: HardhatRuntimeEnvironment) {
33+
// Initialize the wallet.
34+
const wallet = Wallet.fromMnemonic(envOrErr("MNEMONIC"));
35+
const isMainnet = envOrErr("MAINNET") === "true";
36+
37+
// Create deployer object and load the artifact of the contract we want to deploy.
38+
const deployer = new Deployer(hre, wallet);
39+
40+
const {
41+
wormholeGovernanceChainId,
42+
wormholeGovernanceContract,
43+
wormholeInitialSigners,
44+
governanceEmitter,
45+
governanceChainId,
46+
chainName,
47+
} = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK"));
48+
49+
const wormholeReceiverChainId = CHAINS[chainName];
50+
assert(wormholeReceiverChainId !== undefined);
51+
52+
let wormholeReceiverContractAddress = await findWormholeContract(chainName);
53+
if (!wormholeReceiverContractAddress) {
54+
console.log(`Wormhole contract not found for chain ${chainName}`);
55+
console.log("Deploying Wormhole contract...");
56+
wormholeReceiverContractAddress = await deployWormholeContract(
57+
deployer,
58+
chainName,
59+
wormholeGovernanceChainId,
60+
wormholeGovernanceContract,
61+
wormholeInitialSigners,
62+
wormholeReceiverChainId
63+
);
64+
}
65+
66+
console.log(
67+
"WormholeReceiver contract address:",
68+
wormholeReceiverContractAddress
69+
);
70+
71+
// // TODO: Top up accounts if necessary
72+
73+
const executorContractAddress = await deployExecutorContract(
74+
deployer,
75+
wormholeReceiverContractAddress,
76+
wormholeReceiverChainId,
77+
governanceChainId,
78+
governanceEmitter
79+
);
80+
81+
console.log("Executor contract address:", executorContractAddress);
82+
83+
const entropyContractAddress = await deployEntropyContract(
84+
deployer,
85+
executorContractAddress,
86+
wormholeReceiverChainId,
87+
isMainnet
88+
);
89+
90+
console.log("Entropy contract address:", entropyContractAddress);
91+
92+
console.log("Saving the contract in the store...");
93+
const contract = new EvmEntropyContract(chainName, entropyContractAddress);
94+
DefaultStore.entropy_contracts[contract.getId()] = contract;
95+
DefaultStore.saveAllContracts();
96+
}
97+
98+
async function deployExecutorContract(
99+
deployer: Deployer,
100+
wormholeReceiverContractAddress: string,
101+
wormholeReceiverChainId: number,
102+
governanceChainId: string,
103+
governanceEmitter: string
104+
) {
105+
const executorImplArtifact = await deployer.loadArtifact(
106+
"ExecutorUpgradable"
107+
);
108+
const executorImplContract = await deployer.deploy(executorImplArtifact);
109+
console.log(
110+
"Deployed ExecutorImpl contract on",
111+
executorImplContract.address
112+
);
113+
114+
const executorInitData = executorImplContract.interface.encodeFunctionData(
115+
"initialize",
116+
[
117+
wormholeReceiverContractAddress,
118+
0, // lastExecutedSequence,
119+
wormholeReceiverChainId,
120+
governanceChainId,
121+
governanceEmitter,
122+
]
123+
);
124+
125+
const executorProxyArtifact = await deployer.loadArtifact("ERC1967Proxy");
126+
127+
const executorProxyContract = await deployer.deploy(executorProxyArtifact, [
128+
executorImplContract.address,
129+
executorInitData,
130+
]);
131+
132+
console.log(`Deployed Executor contract on ${executorProxyContract.address}`);
133+
134+
return executorProxyContract.address;
135+
}
136+
137+
async function deployEntropyContract(
138+
deployer: Deployer,
139+
executorContractAddress: string,
140+
chainId: number,
141+
isMainnet: boolean
142+
) {
143+
const entropyImplArtifact = await deployer.loadArtifact("EntropyUpgradable");
144+
const entropyImplContract = await deployer.deploy(entropyImplArtifact);
145+
146+
const entropyInitData = entropyImplContract.interface.encodeFunctionData(
147+
"initialize",
148+
[
149+
executorContractAddress,
150+
executorContractAddress,
151+
1, // pythFeeInWei
152+
isMainnet
153+
? ENTROPY_DEFAULT_PROVIDER.mainnet
154+
: ENTROPY_DEFAULT_PROVIDER.testnet,
155+
true,
156+
]
157+
);
158+
159+
const entropyProxyArtifact = await deployer.loadArtifact("ERC1967Proxy");
160+
const entropyProxyContract = await deployer.deploy(entropyProxyArtifact, [
161+
entropyImplContract.address,
162+
entropyInitData,
163+
]);
164+
165+
return entropyProxyContract.address;
166+
}

target_chains/ethereum/contracts/deploy/zkSyncDeploy.ts renamed to target_chains/ethereum/contracts/deploy/zkSyncDeployPriceFeed.ts

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
55
import { CHAINS } from "@pythnetwork/xc-admin-common";
66
import { assert } from "chai";
77
import { writeFileSync } from "fs";
8+
import {
9+
deployWormholeContract,
10+
findWormholeContract,
11+
} from "./zkSyncDeployWormhole";
812
// import {Wallet as ZkWallet} from "zksync-ethers"; // Use These packages if "zksync-web3" doesn't work
913
// import { Deployer as ZkDeployer } from "@matterlabs/hardhat-zksync";
1014

@@ -49,50 +53,23 @@ export default async function (hre: HardhatRuntimeEnvironment) {
4953
emitterChainIds,
5054
} = getDefaultConfig(envOrErr("MIGRATIONS_NETWORK"));
5155
const chainName = envOrErr("MIGRATIONS_NETWORK");
56+
5257
const wormholeReceiverChainId = CHAINS[chainName];
5358
assert(wormholeReceiverChainId !== undefined);
5459

55-
const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
56-
const receiverImplArtifact = await deployer.loadArtifact(
57-
"ReceiverImplementation"
58-
);
59-
const wormholeReceiverArtifact = await deployer.loadArtifact(
60-
"WormholeReceiver"
61-
);
62-
63-
console.log("Deploying WormholeReceiver contract...");
64-
const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
65-
console.log("Deployed ReceiverSetup on", receiverSetupContract.address);
66-
67-
console.log("Deploying ReceiverImplementation contract...");
68-
// deploy implementation
69-
const receiverImplContract = await deployer.deploy(receiverImplArtifact);
70-
console.log(
71-
"Deployed ReceiverImplementation on",
72-
receiverImplContract.address
73-
);
74-
75-
// encode initialisation data
76-
const whInitData = receiverSetupContract.interface.encodeFunctionData(
77-
"setup",
78-
[
79-
receiverImplContract.address,
80-
wormholeInitialSigners,
60+
let wormholeReceiverContractAddress = await findWormholeContract(chainName);
61+
if (!wormholeReceiverContractAddress) {
62+
console.log(`Wormhole contract not found for chain ${chainName}`);
63+
console.log("Deploying Wormhole contract...");
64+
wormholeReceiverContractAddress = await deployWormholeContract(
65+
deployer,
66+
chainName,
8167
wormholeReceiverChainId,
8268
wormholeGovernanceChainId,
8369
wormholeGovernanceContract,
84-
]
85-
);
86-
87-
// deploy proxy
88-
const wormholeReceiverContract = await deployer.deploy(
89-
wormholeReceiverArtifact,
90-
[receiverSetupContract.address, whInitData]
91-
);
92-
93-
console.log(
94-
`Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
95-
);
70+
wormholeInitialSigners
71+
);
72+
}
9673

9774
// Hardcoding the initial sequence number for governance messages.
9875
const governanceInitialSequence = Number("0");
@@ -110,7 +87,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {
11087
const pythInitData = pythImplContract.interface.encodeFunctionData(
11188
"initialize",
11289
[
113-
wormholeReceiverContract.address,
90+
wormholeReceiverContractAddress,
11491
emitterChainIds,
11592
emitterAddresses,
11693
governanceChainId,
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
DefaultStore,
3+
EvmChain,
4+
EvmWormholeContract,
5+
} from "@pythnetwork/contract-manager";
6+
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
7+
import { CHAINS } from "@pythnetwork/xc-admin-common";
8+
import { assert } from "chai";
9+
10+
export function findWormholeContract(chainId: string): string | undefined {
11+
for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
12+
if (
13+
contract instanceof EvmWormholeContract &&
14+
contract.getChain().getId() === chainId
15+
) {
16+
return contract.address;
17+
}
18+
}
19+
}
20+
21+
export async function deployWormholeContract(
22+
deployer: Deployer,
23+
chainName: string,
24+
wormholeGovernanceChainId: string,
25+
wormholeGovernanceContract: string,
26+
wormholeInitialSigners: string[],
27+
wormholeReceiverChainId: number
28+
): Promise<string> {
29+
const receiverSetupArtifact = await deployer.loadArtifact("ReceiverSetup");
30+
const receiverImplArtifact = await deployer.loadArtifact(
31+
"ReceiverImplementation"
32+
);
33+
const wormholeReceiverArtifact = await deployer.loadArtifact(
34+
"WormholeReceiver"
35+
);
36+
console.log("Deploying WormholeReceiver contract...");
37+
38+
const receiverSetupContract = await deployer.deploy(receiverSetupArtifact);
39+
console.log("Deployed ReceiverSetup on", receiverSetupContract.address);
40+
console.log("Deploying ReceiverImplementation contract...");
41+
42+
// deploy implementation
43+
const receiverImplContract = await deployer.deploy(receiverImplArtifact);
44+
console.log(
45+
"Deployed ReceiverImplementation on",
46+
receiverImplContract.address
47+
);
48+
49+
// encode initialisation data
50+
const whInitData = receiverSetupContract.interface.encodeFunctionData(
51+
"setup",
52+
[
53+
receiverImplContract.address,
54+
wormholeInitialSigners,
55+
wormholeReceiverChainId,
56+
wormholeGovernanceChainId,
57+
wormholeGovernanceContract,
58+
]
59+
);
60+
61+
// deploy proxy
62+
const wormholeReceiverContract = await deployer.deploy(
63+
wormholeReceiverArtifact,
64+
[receiverSetupContract.address, whInitData]
65+
);
66+
67+
console.log(
68+
`Deployed WormholeReceiver on ${wormholeReceiverContract.address}`
69+
);
70+
71+
return wormholeReceiverContract.address;
72+
}

target_chains/ethereum/sdk/js/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const CONTRACT_ADDR: Record<string, string> = {
9393
conflux_espace_testnet: "0xDd24F84d36BF92C65F92307595335bdFab5Bbd21",
9494
core_dao_testnet: "0x8D254a21b3C86D32F7179855531CE99164721933",
9595
cronos_testnet: "0x36825bf3Fbdf5a29E2d5148bfe7Dcf7B5639e320",
96-
cronos_zkevm_testnet: "0x67DFF3D12dFDCeC9f85fd86f4cBDb0a111fF721A",
96+
cronos_zkevm_testnet: "0xB1DB1498902F08E16E11F1a423ec9CCB9537E1D6",
9797
dela_deperp_testnet: "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",
9898
dela_mithreum_deperp_testnet: "0xe9d69CdD6Fe41e7B621B4A688C5D1a68cB5c8ADc",
9999
etherlink_testnet: "0x2880aB155794e7179c9eE2e38200202908C17B43",

0 commit comments

Comments
 (0)