@@ -16,6 +16,7 @@ import type {
16
16
CompilerInput ,
17
17
CompilerOutput ,
18
18
} from "../../../../types/solidity/compiler-io.js" ;
19
+ import type { JsonRpcRequestWrapperFunction } from "../network-manager.js" ;
19
20
import type {
20
21
RawTrace ,
21
22
SubscriptionEvent ,
@@ -92,10 +93,12 @@ export async function getGlobalEdrContext(): Promise<EdrContext> {
92
93
return _globalEdrContext ;
93
94
}
94
95
95
- export type JsonRpcRequestWrapperFunction = (
96
- request : JsonRpcRequest ,
97
- defaultBehavior : ( r : JsonRpcRequest ) => Promise < JsonRpcResponse > ,
98
- ) => Promise < JsonRpcResponse > ;
96
+ interface EdrProviderConfig {
97
+ networkConfig : EdrNetworkConfig ;
98
+ loggerConfig ?: LoggerConfig ;
99
+ tracingConfig ?: TracingConfig ;
100
+ jsonRpcRequestWrapper ?: JsonRpcRequestWrapperFunction ;
101
+ }
99
102
100
103
export class EdrProvider extends EventEmitter implements EthereumProvider {
101
104
readonly #provider: Provider ;
@@ -107,23 +110,25 @@ export class EdrProvider extends EventEmitter implements EthereumProvider {
107
110
#vmTracer?: VMTracerT ;
108
111
#nextRequestId = 1 ;
109
112
110
- // TODO: should take an object with all the config like the HTTP provider
111
- public static async create (
112
- config : EdrNetworkConfig ,
113
- loggerConfig : LoggerConfig ,
114
- tracingConfig ?: TracingConfig ,
115
- jsonRpcRequestWrapper ?: JsonRpcRequestWrapperFunction ,
116
- ) : Promise < EdrProvider > {
117
- const coinbase = config . coinbase ?? DEFAULT_COINBASE ;
113
+ /**
114
+ * Creates a new instance of `EdrProvider`.
115
+ */
116
+ public static async create ( {
117
+ networkConfig,
118
+ loggerConfig = { enabled : false } ,
119
+ tracingConfig = { } ,
120
+ jsonRpcRequestWrapper,
121
+ } : EdrProviderConfig ) : Promise < EdrProvider > {
122
+ const coinbase = networkConfig . coinbase ?? DEFAULT_COINBASE ;
118
123
119
124
let fork ;
120
- if ( config . forkConfig !== undefined ) {
125
+ if ( networkConfig . forkConfig !== undefined ) {
121
126
let httpHeaders : HttpHeader [ ] | undefined ;
122
- if ( config . forkConfig . httpHeaders !== undefined ) {
127
+ if ( networkConfig . forkConfig . httpHeaders !== undefined ) {
123
128
httpHeaders = [ ] ;
124
129
125
130
for ( const [ name , value ] of Object . entries (
126
- config . forkConfig . httpHeaders ,
131
+ networkConfig . forkConfig . httpHeaders ,
127
132
) ) {
128
133
httpHeaders . push ( {
129
134
name,
@@ -133,66 +138,70 @@ export class EdrProvider extends EventEmitter implements EthereumProvider {
133
138
}
134
139
135
140
fork = {
136
- jsonRpcUrl : config . forkConfig . jsonRpcUrl ,
141
+ jsonRpcUrl : networkConfig . forkConfig . jsonRpcUrl ,
137
142
blockNumber :
138
- config . forkConfig . blockNumber !== undefined
139
- ? BigInt ( config . forkConfig . blockNumber )
143
+ networkConfig . forkConfig . blockNumber !== undefined
144
+ ? BigInt ( networkConfig . forkConfig . blockNumber )
140
145
: undefined ,
141
146
httpHeaders,
142
147
} ;
143
148
}
144
149
145
150
const initialDate =
146
- config . initialDate !== undefined
147
- ? BigInt ( Math . floor ( config . initialDate . getTime ( ) / 1000 ) )
151
+ networkConfig . initialDate !== undefined
152
+ ? BigInt ( Math . floor ( networkConfig . initialDate . getTime ( ) / 1000 ) )
148
153
: undefined ;
149
154
150
155
const printLineFn = loggerConfig . printLineFn ?? printLine ;
151
156
const replaceLastLineFn = loggerConfig . replaceLastLineFn ?? replaceLastLine ;
152
157
153
158
const vmTraceDecoder = await createVmTraceDecoder ( ) ;
154
159
155
- const hardforkName = getHardforkName ( config . hardfork ) ;
160
+ const hardforkName = getHardforkName ( networkConfig . hardfork ) ;
156
161
157
162
const context = await getGlobalEdrContext ( ) ;
158
163
const provider = await context . createProvider (
159
- config . chainType === "optimism"
164
+ networkConfig . chainType === "optimism"
160
165
? OPTIMISM_CHAIN_TYPE
161
166
: GENERIC_CHAIN_TYPE , // TODO: l1 is missing here
162
167
{
163
168
allowBlocksWithSameTimestamp :
164
- config . allowBlocksWithSameTimestamp ?? false ,
165
- allowUnlimitedContractSize : config . allowUnlimitedContractSize ,
166
- bailOnCallFailure : config . throwOnCallFailures ,
167
- bailOnTransactionFailure : config . throwOnTransactionFailures ,
168
- blockGasLimit : BigInt ( config . blockGasLimit ) ,
169
- chainId : BigInt ( config . chainId ) ,
170
- chains : this . #convertToEdrChains( config . chains ) ,
171
- cacheDir : config . forkCachePath ,
169
+ networkConfig . allowBlocksWithSameTimestamp ?? false ,
170
+ allowUnlimitedContractSize : networkConfig . allowUnlimitedContractSize ,
171
+ bailOnCallFailure : networkConfig . throwOnCallFailures ,
172
+ bailOnTransactionFailure : networkConfig . throwOnTransactionFailures ,
173
+ blockGasLimit : BigInt ( networkConfig . blockGasLimit ) ,
174
+ chainId : BigInt ( networkConfig . chainId ) ,
175
+ chains : this . #convertToEdrChains( networkConfig . chains ) ,
176
+ cacheDir : networkConfig . forkCachePath ,
172
177
coinbase : Buffer . from ( coinbase . slice ( 2 ) , "hex" ) ,
173
- enableRip7212 : config . enableRip7212 ,
178
+ enableRip7212 : networkConfig . enableRip7212 ,
174
179
fork,
175
180
hardfork : ethereumsjsHardforkToEdrSpecId ( hardforkName ) ,
176
- genesisAccounts : config . genesisAccounts . map ( ( account ) => {
181
+ genesisAccounts : networkConfig . genesisAccounts . map ( ( account ) => {
177
182
return {
178
183
secretKey : account . privateKey ,
179
184
balance : BigInt ( account . balance ) ,
180
185
} ;
181
186
} ) ,
182
187
initialDate,
183
188
initialBaseFeePerGas :
184
- config . initialBaseFeePerGas !== undefined
185
- ? BigInt ( config . initialBaseFeePerGas )
189
+ networkConfig . initialBaseFeePerGas !== undefined
190
+ ? BigInt ( networkConfig . initialBaseFeePerGas )
186
191
: undefined ,
187
- minGasPrice : config . minGasPrice ,
192
+ minGasPrice : networkConfig . minGasPrice ,
188
193
mining : {
189
- autoMine : config . automine ,
190
- interval : ethereumjsIntervalMiningConfigToEdr ( config . intervalMining ) ,
194
+ autoMine : networkConfig . automine ,
195
+ interval : ethereumjsIntervalMiningConfigToEdr (
196
+ networkConfig . intervalMining ,
197
+ ) ,
191
198
memPool : {
192
- order : ethereumjsMempoolOrderToEdrMineOrdering ( config . mempoolOrder ) ,
199
+ order : ethereumjsMempoolOrderToEdrMineOrdering (
200
+ networkConfig . mempoolOrder ,
201
+ ) ,
193
202
} ,
194
203
} ,
195
- networkId : BigInt ( config . networkId ) ,
204
+ networkId : BigInt ( networkConfig . networkId ) ,
196
205
} ,
197
206
{
198
207
enable : loggerConfig . enabled ,
@@ -231,6 +240,13 @@ export class EdrProvider extends EventEmitter implements EthereumProvider {
231
240
return edrProvider ;
232
241
}
233
242
243
+ /**
244
+ * @private
245
+ *
246
+ * This constructor is intended for internal use only.
247
+ * Use the static method {@link EdrProvider.create} to create an instance of
248
+ * `EdrProvider`.
249
+ */
234
250
private constructor (
235
251
provider : Provider ,
236
252
vmTraceDecoder : VmTraceDecoder ,
0 commit comments