@@ -5,6 +5,7 @@ import { ChainConfig, ChainInfo, ContractsJson, Dependencies, Ecosystem } from "
5
5
import { getSigner } from "./evm" ;
6
6
// TODO: support different env files
7
7
import 'dotenv/config' ;
8
+ import { ChainId } from "@wormhole-foundation/sdk-base" ;
8
9
9
10
export const env = getEnv ( "ENV" ) ;
10
11
export const contracts = loadContracts ( ) ;
@@ -39,46 +40,46 @@ export function getEnv(env: string): string {
39
40
return v ;
40
41
}
41
42
42
- export async function getChainConfig < T extends ChainConfig > ( filename : string , evmChainId : number ) : Promise < T > {
43
+ export async function getChainConfig < T extends ChainConfig > ( filename : string , whChainId : ChainId ) : Promise < T > {
43
44
const scriptConfig : T [ ] = await loadJson ( filename ) ;
44
45
45
- const chainConfig = scriptConfig . find ( ( x ) => x . chainId == evmChainId ) ;
46
+ const chainConfig = scriptConfig . find ( ( x ) => x . chainId == whChainId ) ;
46
47
47
48
if ( ! chainConfig ) {
48
- throw Error ( `Failed to find chain config for chain ${ evmChainId } ` ) ;
49
+ throw Error ( `Failed to find chain config for chain ${ whChainId } ` ) ;
49
50
}
50
51
51
52
return chainConfig ;
52
53
}
53
54
54
- export function getContractAddress ( contractName : string , evmChainId : number ) : string {
55
- const contract = contracts [ contractName ] ?. find ( ( c ) => c . chainId === evmChainId ) ?. address ;
55
+ export function getContractAddress ( contractName : string , whChainId : ChainId ) : string {
56
+ const contract = contracts [ contractName ] ?. find ( ( c ) => c . chainId === whChainId ) ?. address ;
56
57
57
58
if ( ! contract ) {
58
- throw new Error ( `No ${ contractName } contract found for chain ${ evmChainId } ` ) ;
59
+ throw new Error ( `No ${ contractName } contract found for chain ${ whChainId } ` ) ;
59
60
}
60
61
61
62
if ( ! utils . isAddress ( contract ) && ! validateSolAddress ( contract ) ) {
62
- throw new Error ( `Invalid address for ${ contractName } contract found for chain ${ evmChainId } ` ) ;
63
+ throw new Error ( `Invalid address for ${ contractName } contract found for chain ${ whChainId } ` ) ;
63
64
}
64
65
65
66
return contract ;
66
67
}
67
68
68
- export function getDependencyAddress ( dependencyName : string , evmChainId : number ) : string {
69
- const chainDependencies = dependencies . find ( ( d ) => d . chainId === evmChainId ) ;
69
+ export function getDependencyAddress ( dependencyName : string , whChainId : ChainId ) : string {
70
+ const chainDependencies = dependencies . find ( ( d ) => d . chainId === whChainId ) ;
70
71
71
72
if ( chainDependencies === undefined ) {
72
- throw new Error ( `No dependencies found for chain ${ evmChainId } ` ) ;
73
+ throw new Error ( `No dependencies found for chain ${ whChainId } ` ) ;
73
74
}
74
75
75
76
const dependency = chainDependencies [ dependencyName as keyof Dependencies ] as string ;
76
77
if ( dependency === undefined ) {
77
- throw new Error ( `No dependency found for ${ dependencyName } for chain ${ evmChainId } ` ) ;
78
+ throw new Error ( `No dependency found for ${ dependencyName } for chain ${ whChainId } ` ) ;
78
79
}
79
80
80
81
if ( ! utils . isAddress ( dependency ) && ! validateSolAddress ( dependency ) ) {
81
- throw new Error ( `Invalid address for ${ dependencyName } dependency found for chain ${ evmChainId } ` ) ;
82
+ throw new Error ( `Invalid address for ${ dependencyName } dependency found for chain ${ whChainId } ` ) ;
82
83
}
83
84
84
85
return dependency ;
@@ -94,30 +95,30 @@ export async function getContractInstance(
94
95
return factory . connect ( contractAddress , signer ) ;
95
96
}
96
97
97
- export function getDeploymentArgs ( contractName : string , evmChainId : number ) : any [ ] {
98
- const constructorArgs = contracts [ contractName ] ?. find ( ( c ) => c . chainId === evmChainId ) ?. constructorArgs ;
98
+ export function getDeploymentArgs ( contractName : string , whChainId : ChainId ) : any [ ] {
99
+ const constructorArgs = contracts [ contractName ] ?. find ( ( c ) => c . chainId === whChainId ) ?. constructorArgs ;
99
100
100
101
if ( ! constructorArgs ) {
101
- throw new Error ( `No constructorArgs found for ${ contractName } contract for chain ${ evmChainId } ` ) ;
102
+ throw new Error ( `No constructorArgs found for ${ contractName } contract for chain ${ whChainId } ` ) ;
102
103
}
103
104
104
105
return constructorArgs ;
105
106
}
106
107
107
- export function writeDeployedContract ( evmChainId : number , contractName : string , address : string , constructorArgs : any [ ] ) {
108
+ export function writeDeployedContract ( whChainId : ChainId , contractName : string , address : string , constructorArgs : any [ ] ) {
108
109
const contracts = loadContracts ( ) ;
109
110
if ( ! contracts [ contractName ] ) {
110
- contracts [ contractName ] = [ { chainId : evmChainId , address, constructorArgs } ] ;
111
+ contracts [ contractName ] = [ { chainId : whChainId , address, constructorArgs } ] ;
111
112
}
112
113
113
- else if ( ! contracts [ contractName ] . find ( ( c ) => c . chainId === evmChainId ) ) {
114
- contracts [ contractName ] . push ( { chainId : evmChainId , address, constructorArgs } ) ;
114
+ else if ( ! contracts [ contractName ] . find ( ( c ) => c . chainId === whChainId ) ) {
115
+ contracts [ contractName ] . push ( { chainId : whChainId , address, constructorArgs } ) ;
115
116
}
116
117
117
118
else {
118
119
contracts [ contractName ] = contracts [ contractName ] . map ( ( c ) => {
119
- if ( c . chainId === evmChainId ) {
120
- return { chainId : evmChainId , address, constructorArgs } ;
120
+ if ( c . chainId === whChainId ) {
121
+ return { chainId : whChainId , address, constructorArgs } ;
121
122
}
122
123
123
124
return c ;
0 commit comments