11import yargs from "yargs" ;
22import { hideBin } from "yargs/helpers" ;
33import { 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" ;
618import { DefaultStore } from "../src/node/utils/store" ;
719import { EvmExecutorContract } from "../src/core/contracts/evm" ;
820
921const CACHE_FILE = ".cache-deploy-evm-executor" ;
1022
1123const 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 */
4760export 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
87103export 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