Skip to content

Commit 0372d76

Browse files
committed
updat
1 parent 3ac909e commit 0372d76

File tree

3 files changed

+94
-66
lines changed

3 files changed

+94
-66
lines changed

contract_manager/scripts/common.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { Contract } from "web3-eth-contract";
66
import { InferredOptionType } from "yargs";
77
import { PrivateKey, getDefaultDeploymentConfig } from "../src/core/base";
88
import { EvmChain } from "../src/core/chains";
9-
import { EvmEntropyContract, EvmExecutorContract, EvmWormholeContract } from "../src/core/contracts";
9+
import {
10+
EvmEntropyContract,
11+
EvmExecutorContract,
12+
EvmWormholeContract,
13+
} from "../src/core/contracts";
1014

1115
export interface BaseDeployConfig {
1216
gasMultiplier: number;
@@ -237,7 +241,6 @@ export function findWormholeContract(
237241
}
238242
}
239243

240-
241244
/**
242245
* Finds the executor contract for a given EVM chain.
243246
* @param {EvmChain} chain The EVM chain to find the executor contract for.
@@ -251,7 +254,9 @@ export function findExecutorContract(
251254
contract instanceof EvmExecutorContract &&
252255
contract.chain.getId() === chain.getId()
253256
) {
254-
console.log(`Found executor contract for ${chain.getId()} at ${contract.address}`);
257+
console.log(
258+
`Found executor contract for ${chain.getId()} at ${contract.address}`,
259+
);
255260
return contract;
256261
}
257262
}

contract_manager/scripts/deploy_evm_entropy_contracts.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from "../src/core/contracts/evm";
1010
import {
1111
DeploymentType,
12-
getDefaultDeploymentConfig,
1312
toDeploymentType,
1413
toPrivateKey,
1514
} from "../src/core/base";
@@ -22,7 +21,7 @@ import {
2221
topupAccountsIfNecessary,
2322
DefaultAddresses,
2423
} from "./common";
25-
import {getOrDeployExecutorContract } from "./deploy_evm_executor";
24+
import { getOrDeployExecutorContract } from "./deploy_evm_executor";
2625

2726
interface DeploymentConfig extends BaseDeployConfig {
2827
type: DeploymentType;
Lines changed: 85 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
33
import { EvmChain } from "../src/core/chains";
4-
import { BaseDeployConfig, COMMON_DEPLOY_OPTIONS, deployIfNotCached, findExecutorContract, getOrDeployWormholeContract, getWeb3Contract } from "./common";
5-
import { DeploymentType, getDefaultDeploymentConfig, toDeploymentType, toPrivateKey } from "../src/core/base";
4+
import {
5+
BaseDeployConfig,
6+
COMMON_DEPLOY_OPTIONS,
7+
deployIfNotCached,
8+
findExecutorContract,
9+
getOrDeployWormholeContract,
10+
getWeb3Contract,
11+
} from "./common";
12+
import {
13+
DeploymentType,
14+
getDefaultDeploymentConfig,
15+
toDeploymentType,
16+
toPrivateKey,
17+
} from "../src/core/base";
618
import { DefaultStore } from "../src/node/utils/store";
719
import { EvmExecutorContract } from "../src/core/contracts/evm";
820

921
const CACHE_FILE = ".cache-deploy-evm-executor";
1022

1123
const parser = yargs(hideBin(process.argv))
1224
.scriptName("deploy_evm_executor.ts")
13-
.usage("Usage: $0 --std-output-dir <path/to/std-output-dir/> --private-key <private-key> --chain <chain>")
25+
.usage(
26+
"Usage: $0 --std-output-dir <path/to/std-output-dir/> --private-key <private-key> --chain <chain>",
27+
)
1428
.options({
1529
...COMMON_DEPLOY_OPTIONS,
1630
chain: {
@@ -20,22 +34,21 @@ const parser = yargs(hideBin(process.argv))
2034
},
2135
});
2236

23-
interface DeploymentConfig extends BaseDeployConfig {
24-
type: DeploymentType;
25-
saveContract: boolean;
26-
}
27-
37+
interface DeploymentConfig extends BaseDeployConfig {
38+
type: DeploymentType;
39+
saveContract: boolean;
40+
}
2841

29-
export async function getOrDeployExecutorContract(
30-
chain: EvmChain,
31-
config: DeploymentConfig,
32-
wormholeAddr: string,
33-
): Promise<EvmExecutorContract> {
34-
return (
35-
findExecutorContract(chain) ??
36-
(await deployExecutorContracts(chain, config, wormholeAddr))
37-
);
38-
}
42+
export async function getOrDeployExecutorContract(
43+
chain: EvmChain,
44+
config: DeploymentConfig,
45+
wormholeAddr: string,
46+
): Promise<EvmExecutorContract> {
47+
return (
48+
findExecutorContract(chain) ??
49+
(await deployExecutorContracts(chain, config, wormholeAddr))
50+
);
51+
}
3952

4053
/**
4154
* Deploys the executor contracts for a given EVM chain.
@@ -45,44 +58,47 @@ const parser = yargs(hideBin(process.argv))
4558
* @returns {Promise<string>} The address of the deployed executor contract.
4659
*/
4760
export async function deployExecutorContracts(
48-
chain: EvmChain,
49-
config: DeploymentConfig,
50-
wormholeAddr: string,
51-
): Promise<EvmExecutorContract> {
52-
const executorImplAddr = await deployIfNotCached(
53-
CACHE_FILE,
54-
chain,
55-
config,
56-
"ExecutorUpgradable",
57-
[],
58-
);
59-
60-
// Craft the init data for the proxy contract
61-
const { governanceDataSource } = getDefaultDeploymentConfig(config.type);
62-
63-
const executorImplContract = getWeb3Contract(
64-
config.jsonOutputDir,
65-
"ExecutorUpgradable",
66-
executorImplAddr,
67-
);
68-
69-
const executorInitData = executorImplContract.methods
70-
.initialize(
71-
wormholeAddr,
72-
0, // lastExecutedSequence,
73-
chain.getWormholeChainId(),
74-
governanceDataSource.emitterChain,
75-
`0x${governanceDataSource.emitterAddress}`,
76-
)
77-
.encodeABI();
78-
79-
const executorAddr = await deployIfNotCached(CACHE_FILE, chain, config, "ERC1967Proxy", [
80-
executorImplAddr,
81-
executorInitData,
82-
]);
83-
84-
return new EvmExecutorContract(chain, executorAddr);
85-
}
61+
chain: EvmChain,
62+
config: DeploymentConfig,
63+
wormholeAddr: string,
64+
): Promise<EvmExecutorContract> {
65+
const executorImplAddr = await deployIfNotCached(
66+
CACHE_FILE,
67+
chain,
68+
config,
69+
"ExecutorUpgradable",
70+
[],
71+
);
72+
73+
// Craft the init data for the proxy contract
74+
const { governanceDataSource } = getDefaultDeploymentConfig(config.type);
75+
76+
const executorImplContract = getWeb3Contract(
77+
config.jsonOutputDir,
78+
"ExecutorUpgradable",
79+
executorImplAddr,
80+
);
81+
82+
const executorInitData = executorImplContract.methods
83+
.initialize(
84+
wormholeAddr,
85+
0, // lastExecutedSequence,
86+
chain.getWormholeChainId(),
87+
governanceDataSource.emitterChain,
88+
`0x${governanceDataSource.emitterAddress}`,
89+
)
90+
.encodeABI();
91+
92+
const executorAddr = await deployIfNotCached(
93+
CACHE_FILE,
94+
chain,
95+
config,
96+
"ERC1967Proxy",
97+
[executorImplAddr, executorInitData],
98+
);
99+
100+
return new EvmExecutorContract(chain, executorAddr);
101+
}
86102

87103
export async function main() {
88104
const argv = await parser.argv;
@@ -98,20 +114,28 @@ export async function main() {
98114
saveContract: argv.saveContract,
99115
};
100116

101-
const wormholeContract = await getOrDeployWormholeContract(chain, deploymentConfig, CACHE_FILE);
117+
const wormholeContract = await getOrDeployWormholeContract(
118+
chain,
119+
deploymentConfig,
120+
CACHE_FILE,
121+
);
102122

103123
console.log(
104124
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n`,
105125
);
106126

107127
console.log(`Deploying executor contracts on ${chain.getId()}...`);
108128

109-
const executorContract = await getOrDeployExecutorContract(chain, deploymentConfig, wormholeContract.address);
110-
129+
const executorContract = await getOrDeployExecutorContract(
130+
chain,
131+
deploymentConfig,
132+
wormholeContract.address,
133+
);
111134

112135
if (deploymentConfig.saveContract) {
113136
console.log("Saving the contract in the store...");
114-
DefaultStore.executor_contracts[executorContract.getId()] = executorContract;
137+
DefaultStore.executor_contracts[executorContract.getId()] =
138+
executorContract;
115139
DefaultStore.saveAllContracts();
116140
}
117141

@@ -120,4 +144,4 @@ export async function main() {
120144
);
121145
}
122146

123-
main();
147+
main();

0 commit comments

Comments
 (0)