1
1
import type {
2
- ConfigurationResolver ,
2
+ ConfigurationVariableResolver ,
3
3
EdrNetworkAccountsConfig ,
4
4
EdrNetworkAccountsUserConfig ,
5
5
EdrNetworkChainConfig ,
@@ -22,21 +22,21 @@ import {
22
22
normalizeHexString ,
23
23
} from "@ignored/hardhat-vnext-utils/hex" ;
24
24
25
- import { DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS } from "./accounts/derive-private-keys .js" ;
25
+ import { DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS } from "./accounts/constants .js" ;
26
26
import {
27
27
DEFAULT_EDR_NETWORK_HD_ACCOUNTS_CONFIG_PARAMS ,
28
28
EDR_NETWORK_DEFAULT_COINBASE ,
29
29
} from "./edr/edr-provider.js" ;
30
- import { HardforkName } from "./edr/types/hardfork.js" ;
31
- import { isHdAccountsConfig } from "./type-validation.js" ;
30
+ import { HardforkName , LATEST_HARDFORK } from "./edr/types/hardfork.js" ;
31
+ import { isHdAccountsUserConfig } from "./type-validation.js" ;
32
32
33
33
export function resolveGasConfig ( value : GasUserConfig = "auto" ) : GasConfig {
34
34
return value === "auto" ? value : BigInt ( value ) ;
35
35
}
36
36
37
37
export function resolveHttpNetworkAccounts (
38
38
accounts : HttpNetworkAccountsUserConfig | undefined = "remote" ,
39
- resolveConfigurationVariable : ConfigurationResolver ,
39
+ resolveConfigurationVariable : ConfigurationVariableResolver ,
40
40
) : HttpNetworkAccountsConfig {
41
41
if ( Array . isArray ( accounts ) ) {
42
42
return accounts . map ( ( acc ) => {
@@ -48,10 +48,16 @@ export function resolveHttpNetworkAccounts(
48
48
} ) ;
49
49
}
50
50
51
- if ( isHdAccountsConfig ( accounts ) ) {
51
+ if ( isHdAccountsUserConfig ( accounts ) ) {
52
+ const { passphrase : defaultPassphrase , ...defaultHdAccountRest } =
53
+ DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS ;
54
+ const { mnemonic, passphrase, ...hdAccountRest } = accounts ;
55
+
52
56
return {
53
- ...DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS ,
54
- ...accounts ,
57
+ ...defaultHdAccountRest ,
58
+ ...hdAccountRest ,
59
+ mnemonic : resolveConfigurationVariable ( mnemonic ) ,
60
+ passphrase : resolveConfigurationVariable ( passphrase ?? defaultPassphrase ) ,
55
61
} ;
56
62
}
57
63
@@ -62,49 +68,55 @@ export function resolveEdrNetworkAccounts(
62
68
accounts :
63
69
| EdrNetworkAccountsUserConfig
64
70
| undefined = DEFAULT_EDR_NETWORK_HD_ACCOUNTS_CONFIG_PARAMS ,
71
+ resolveConfigurationVariable : ConfigurationVariableResolver ,
65
72
) : EdrNetworkAccountsConfig {
66
73
if ( Array . isArray ( accounts ) ) {
67
- return accounts . map ( ( { privateKey, balance } ) => ( {
68
- privateKey : normalizeHexString ( privateKey ) ,
69
- balance : BigInt ( balance ) ,
70
- } ) ) ;
74
+ return accounts . map ( ( { privateKey, balance } ) => {
75
+ if ( typeof privateKey === "string" ) {
76
+ privateKey = normalizeHexString ( privateKey ) ;
77
+ }
78
+
79
+ return {
80
+ privateKey : resolveConfigurationVariable ( privateKey ) ,
81
+ balance : BigInt ( balance ) ,
82
+ } ;
83
+ } ) ;
71
84
}
72
85
86
+ const {
87
+ mnemonic : defaultMnemonic ,
88
+ accountsBalance : defaultAccountsBalance ,
89
+ passphrase : defaultPassphrase ,
90
+ ...defaultHdAccountRest
91
+ } = DEFAULT_EDR_NETWORK_HD_ACCOUNTS_CONFIG_PARAMS ;
92
+ const { mnemonic, passphrase, accountsBalance, ...hdAccountRest } = accounts ;
73
93
return {
74
- ...DEFAULT_EDR_NETWORK_HD_ACCOUNTS_CONFIG_PARAMS ,
75
- ...accounts ,
76
- accountsBalance : BigInt (
77
- accounts . accountsBalance ??
78
- DEFAULT_EDR_NETWORK_HD_ACCOUNTS_CONFIG_PARAMS . accountsBalance ,
79
- ) ,
94
+ ...defaultHdAccountRest ,
95
+ ...hdAccountRest ,
96
+ mnemonic : resolveConfigurationVariable ( mnemonic ?? defaultMnemonic ) ,
97
+ accountsBalance : BigInt ( accountsBalance ?? defaultAccountsBalance ) ,
98
+ passphrase : resolveConfigurationVariable ( passphrase ?? defaultPassphrase ) ,
80
99
} ;
81
100
}
82
101
83
102
export function resolveForkingConfig (
84
103
forkingUserConfig : EdrNetworkForkingUserConfig | undefined ,
85
104
cacheDir : string ,
105
+ resolveConfigurationVariable : ConfigurationVariableResolver ,
86
106
) : EdrNetworkForkingConfig | undefined {
87
107
if ( forkingUserConfig === undefined ) {
88
108
return undefined ;
89
109
}
90
110
91
- const httpHeaders =
92
- forkingUserConfig . httpHeaders !== undefined
93
- ? Object . entries ( forkingUserConfig . httpHeaders ) . map ( ( [ name , value ] ) => ( {
94
- name,
95
- value,
96
- } ) )
97
- : undefined ;
98
-
99
111
return {
100
112
enabled : forkingUserConfig . enabled ?? true ,
101
- url : forkingUserConfig . url ,
113
+ url : resolveConfigurationVariable ( forkingUserConfig . url ) ,
102
114
cacheDir : path . join ( cacheDir , "edr-fork-cache" ) ,
103
115
blockNumber :
104
116
forkingUserConfig . blockNumber !== undefined
105
117
? BigInt ( forkingUserConfig . blockNumber )
106
118
: undefined ,
107
- httpHeaders,
119
+ httpHeaders : forkingUserConfig . httpHeaders ,
108
120
} ;
109
121
}
110
122
@@ -274,7 +286,7 @@ export function resolveHardfork(
274
286
}
275
287
276
288
if ( enableTransientStorage === true ) {
277
- return HardforkName . CANCUN ;
289
+ return LATEST_HARDFORK ;
278
290
} else {
279
291
return HardforkName . SHANGHAI ;
280
292
}
0 commit comments