-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNodes.ts
620 lines (610 loc) · 18.7 KB
/
Nodes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
import {
arbitrum as arbitrumCommon,
arbitrumNova as arbitrumNovaCommon,
arbitrumSepolia as arbitrumSepoliaCommon,
aurora as auroraCommon,
auroraTestnet as auroraTestnetCommon,
avalanche as avalanceCommon,
base as baseCommon,
baseSepolia as baseSepoliaCommon,
bearNetworkChainMainnet as bearNetworkChainMainnetCommon,
berachainTestnet as berachainTestnetCommon,
blast as blastCommon,
blastSepolia as blastSepoliaCommon,
boba as bobaCommon,
bsc as bscCommon,
celo as celoCommon,
cronos as cronosCommon,
cronosTestnet as cronosTestnetCommon,
fantom as fantomCommon,
filecoin as filecoinCommon,
gnosis as gnosisCommon,
harmonyOne as harmonyOneCommon,
holesky as holeskyCommon,
kava as kavaCommon,
kavaTestnet as kavaTestnetCommon,
linea as lineaCommon,
lineaTestnet as lineaTestnetCommon,
lyra as lyraCommon,
mainnet as mainnetCommon,
manta as manaCommon,
mantle as mantleCommon,
metis as metisCommon,
mode as modeCommon,
moonbeam as moonbeamCommon,
moonriver as moonriverCommon,
opBNB as opBNBCommon,
optimism as optimismCommon,
optimismSepolia as optimismSeplia,
polygon as polygonCommon,
polygonMumbai as polygonMumbaiCommon,
polygonZkEvm as polygonZkEvmCommon,
polygonZkEvmTestnet as polygonZkEvmTestnetCommon,
redstone as redstoneCommon,
scroll as scrollCommon,
sepolia as sepoliaCommon,
tevmDefault as tevmDefault,
zksync as zksyncCommon,
zksyncSepoliaTestnet as zksyncSepoliaTestnetCommon,
zora as zoraCommon,
zoraSepolia as zoraSepoliaCommon,
zoraTestnet as zoraTestnetCommon,
} from "tevm/common";
import { Storage } from "./Storage";
import { createTevmNode, http, TevmNode } from 'tevm'
import type { Common } from 'tevm/common'
export type SupportedNetwork =
| "arbitrum"
| "arbitrumNova"
| "arbitrumSepolia"
| "aurora"
| "auroraTestnet"
| "avalanche"
| "base"
| "baseSepolia"
| "bearNetworkChainMainnet"
| "berachain"
| "berachainTestnet"
| "blast"
| "blastSepolia"
| "boba"
| "bsc"
| "celo"
| "cronos"
| "cronosTestnet"
| "fantom"
| "filecoin"
| "gnosis"
| "harmonyOne"
| "kava"
| "kavaTestnet"
| "linea"
| "lineaTestnet"
| "lyra"
| "mainnet"
| "manta"
| "mantle"
| "metis"
| "mode"
| "moonbeam"
| "moonriver"
| "opBNB"
| "optimism"
| "optimismSepolia"
| "polygon"
| "polygonMumbai"
| "polygonZkEvm"
| "polygonZkEvmTestnet"
| "redstone"
| "scroll"
| "sepolia"
| "tevmDefault"
| "zksync"
| "zksyncSepolia"
| "zora"
| "zoraSepolia"
| "zoraTestnet";
/**
* Tevm node eagerly instantiates tevm nodes for all supported networks
* It lazy loads the tevm library for optimal code splitting
*/
export class Nodes implements Record<SupportedNetwork, { common: Common; node: TevmNode }>{
// We choose to lazy load tevm to optimize first load
public static createTevmNode = (rpcUrl: string, common: Common) => {
return createTevmNode({
common,
fork: {
transport: http(rpcUrl)({})
}
})
}
private storage: Storage;
public network: SupportedNetwork;
private _tevmDefault: { common: Common; node: TevmNode } | undefined;
public get tevmDefault() {
if (!this._tevmDefault) {
this._tevmDefault = { common: tevmDefault, node: createTevmNode({ common: tevmDefault })}
}
return this._tevmDefault;
}
private _arbitrum: { common: Common; node: TevmNode };
private _arbitrumNova: { common: Common; node: TevmNode } | undefined;
private _arbitrumSepolia: { common: Common; node: TevmNode } | undefined;
private _aurora: { common: Common; node: TevmNode } | undefined;
private _auroraTestnet: { common: Common; node: TevmNode } | undefined;
private _avalanche: { common: Common; node: TevmNode } | undefined;
private _base: { common: Common; node: TevmNode };
private _baseSepolia: { common: Common; node: TevmNode } | undefined;
private _bearNetworkChainMainnet: { common: Common; node: TevmNode } | undefined;
private _berachain: { common: Common; node: TevmNode } | undefined;
private _berachainTestnet: { common: Common; node: TevmNode } | undefined;
private _blast: { common: Common; node: TevmNode } | undefined;
private _blastSepolia: { common: Common; node: TevmNode } | undefined;
private _boba: { common: Common; node: TevmNode } | undefined;
private _bsc: { common: Common; node: TevmNode } | undefined;
private _celo: { common: Common; node: TevmNode } | undefined;
private _cronos: { common: Common; node: TevmNode } | undefined;
private _cronosTestnet: { common: Common; node: TevmNode } | undefined;
private _fantom: { common: Common; node: TevmNode } | undefined;
private _filecoin: { common: Common; node: TevmNode } | undefined;
private _gnosis: { common: Common; node: TevmNode } | undefined;
private _harmonyOne: { common: Common; node: TevmNode } | undefined;
private _kava: { common: Common; node: TevmNode } | undefined;
private _kavaTestnet: { common: Common; node: TevmNode } | undefined;
private _linea: { common: Common; node: TevmNode } | undefined;
private _lineaTestnet: { common: Common; node: TevmNode } | undefined;
private _lyra: { common: Common; node: TevmNode } | undefined;
private _mainnet: { common: Common; node: TevmNode };
private _manta: { common: Common; node: TevmNode } | undefined;
private _mantle: { common: Common; node: TevmNode } | undefined;
private _metis: { common: Common; node: TevmNode } | undefined;
private _mode: { common: Common; node: TevmNode } | undefined;
private _moonbeam: { common: Common; node: TevmNode } | undefined;
private _moonriver: { common: Common; node: TevmNode } | undefined;
private _opBNB: { common: Common; node: TevmNode } | undefined;
private _optimism: { common: Common; node: TevmNode };
private _optimismSepolia: { common: Common; node: TevmNode } | undefined;
private _polygon: { common: Common; node: TevmNode };
private _polygonMumbai: { common: Common; node: TevmNode } | undefined;
private _polygonZkEvm: { common: Common; node: TevmNode } | undefined;
private _polygonZkEvmTestnet: { common: Common; node: TevmNode } | undefined;
private _redstone: { common: Common; node: TevmNode } | undefined;
private _scroll: { common: Common; node: TevmNode } | undefined;
private _sepolia: { common: Common; node: TevmNode } | undefined;
private _zksync: { common: Common; node: TevmNode } | undefined;
private _zksyncSepolia: { common: Common; node: TevmNode } | undefined;
private _zora: { common: Common; node: TevmNode } | undefined;
private _zoraSepolia: { common: Common; node: TevmNode } | undefined;
private _zoraTestnet: { common: Common; node: TevmNode } | undefined;
public newChain: { common: Common; node: TevmNode };
constructor(storage: Storage, network: SupportedNetwork = 'mainnet') {
this.storage = storage;
this.network = network;
// Optimistically create mainnet through polygon
this._mainnet = {
common: mainnetCommon,
node: Nodes.createTevmNode(storage.getStoredUrl('mainnet'), mainnetCommon),
};
this._base = {
common: baseCommon,
node: Nodes.createTevmNode(storage.getStoredUrl('base'), baseCommon),
};
this._optimism = {
common: optimismCommon,
node: Nodes.createTevmNode(storage.getStoredUrl('optimism'), optimismCommon),
};
this._arbitrum = {
common: arbitrumCommon,
node: Nodes.createTevmNode(storage.getStoredUrl('arbitrum'), arbitrumCommon),
};
this._polygon = {
common: polygonCommon,
node: Nodes.createTevmNode(storage.getStoredUrl('polygon'), polygonCommon),
};
this.newChain = {
common: tevmDefault,
node: createTevmNode({ common: tevmDefault }),
};
}
public get arbitrum() { return this._arbitrum; }
public get arbitrumNova() {
if (!this._arbitrumNova) {
this._arbitrumNova = {
common: arbitrumNovaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('arbitrumNova'), arbitrumNovaCommon),
};
}
return this._arbitrumNova;
}
public get arbitrumSepolia() {
if (!this._arbitrumSepolia) {
this._arbitrumSepolia = {
common: arbitrumSepoliaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('arbitrumSepolia'), arbitrumSepoliaCommon),
};
}
return this._arbitrumSepolia;
}
public get aurora() {
if (!this._aurora) {
this._aurora = {
common: auroraCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('aurora'), auroraCommon),
};
}
return this._aurora;
}
public get auroraTestnet() {
if (!this._auroraTestnet) {
this._auroraTestnet = {
common: auroraTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('auroraTestnet'), auroraTestnetCommon),
};
}
return this._auroraTestnet;
}
public get avalanche() {
if (!this._avalanche) {
this._avalanche = {
common: avalanceCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('avalanche'), avalanceCommon),
};
}
return this._avalanche;
}
public get base() { return this._base; }
public get baseSepolia() {
if (!this._baseSepolia) {
this._baseSepolia = {
common: baseSepoliaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('baseSepolia'), baseSepoliaCommon),
};
}
return this._baseSepolia;
}
public get bearNetworkChainMainnet() {
if (!this._bearNetworkChainMainnet) {
this._bearNetworkChainMainnet = {
common: bearNetworkChainMainnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('bearNetworkChainMainnet'), bearNetworkChainMainnetCommon),
};
}
return this._bearNetworkChainMainnet;
}
public get berachain() {
if (!this._berachain) {
this._berachain = {
common: berachainTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('berachain'), berachainTestnetCommon),
};
}
return this._berachain;
}
public get berachainTestnet() {
if (!this._berachainTestnet) {
this._berachainTestnet = {
common: berachainTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('berachainTestnet'), berachainTestnetCommon),
};
}
return this._berachainTestnet;
}
public get blast() {
if (!this._blast) {
this._blast = {
common: blastCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('blast'), blastCommon),
};
}
return this._blast;
}
public get blastSepolia() {
if (!this._blastSepolia) {
this._blastSepolia = {
common: blastSepoliaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('blastSepolia'), blastSepoliaCommon),
};
}
return this._blastSepolia;
}
public get boba() {
if (!this._boba) {
this._boba = {
common: bobaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('boba'), bobaCommon),
};
}
return this._boba;
}
public get bsc() {
if (!this._bsc) {
this._bsc = {
common: bscCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('bsc'), bscCommon),
};
}
return this._bsc;
}
public get celo() {
if (!this._celo) {
this._celo = {
common: celoCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('celo'), celoCommon),
};
}
return this._celo;
}
public get cronos() {
if (!this._cronos) {
this._cronos = {
common: cronosCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('cronos'), cronosCommon),
};
}
return this._cronos;
}
public get cronosTestnet() {
if (!this._cronosTestnet) {
this._cronosTestnet = {
common: cronosTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('cronosTestnet'), cronosTestnetCommon),
};
}
return this._cronosTestnet;
}
public get fantom() {
if (!this._fantom) {
this._fantom = {
common: fantomCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('fantom'), fantomCommon),
};
}
return this._fantom;
}
public get filecoin() {
if (!this._filecoin) {
this._filecoin = {
common: filecoinCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('filecoin'), filecoinCommon),
};
}
return this._filecoin;
}
public get gnosis() {
if (!this._gnosis) {
this._gnosis = {
common: gnosisCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('gnosis'), gnosisCommon),
};
}
return this._gnosis;
}
public get harmonyOne() {
if (!this._harmonyOne) {
this._harmonyOne = {
common: harmonyOneCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('harmonyOne'), harmonyOneCommon),
};
}
return this._harmonyOne;
}
public get kava() {
if (!this._kava) {
this._kava = {
common: kavaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('kava'), kavaCommon),
};
}
return this._kava;
}
public get kavaTestnet() {
if (!this._kavaTestnet) {
this._kavaTestnet = {
common: kavaTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('kavaTestnet'), kavaTestnetCommon),
};
}
return this._kavaTestnet;
}
public get linea() {
if (!this._linea) {
this._linea = {
common: lineaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('linea'), lineaCommon),
};
}
return this._linea;
}
public get lineaTestnet() {
if (!this._lineaTestnet) {
this._lineaTestnet = {
common: lineaTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('lineaTestnet'), lineaTestnetCommon),
};
}
return this._lineaTestnet;
}
public get lyra() {
if (!this._lyra) {
this._lyra = {
common: lyraCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('lyra'), lyraCommon),
};
}
return this._lyra;
}
public get mainnet() { return this._mainnet; }
public get manta() {
if (!this._manta) {
this._manta = {
common: manaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('manta'), manaCommon),
};
}
return this._manta;
}
public get mantle() {
if (!this._mantle) {
this._mantle = {
common: mantleCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('mantle'), mantleCommon),
};
}
return this._mantle;
}
public get metis() {
if (!this._metis) {
this._metis = {
common: metisCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('metis'), metisCommon),
};
}
return this._metis;
}
public get mode() {
if (!this._mode) {
this._mode = {
common: modeCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('mode'), modeCommon),
};
}
return this._mode;
}
public get moonbeam() {
if (!this._moonbeam) {
this._moonbeam = {
common: moonbeamCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('moonbeam'), moonbeamCommon),
};
}
return this._moonbeam;
}
public get moonriver() {
if (!this._moonriver) {
this._moonriver = {
common: moonriverCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('moonriver'), moonriverCommon),
};
}
return this._moonriver;
}
public get opBNB() {
if (!this._opBNB) {
this._opBNB = {
common: opBNBCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('opBNB'), opBNBCommon),
};
}
return this._opBNB;
}
public get optimism() { return this._optimism; }
public get optimismSepolia() {
if (!this._optimismSepolia) {
this._optimismSepolia = {
common: optimismSeplia,
node: Nodes.createTevmNode(this.storage.getStoredUrl('optimismSepolia'), optimismSeplia),
};
}
return this._optimismSepolia;
}
public get polygon() { return this._polygon; }
public get polygonMumbai() {
if (!this._polygonMumbai) {
this._polygonMumbai = {
common: polygonMumbaiCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('polygonMumbai'), polygonMumbaiCommon),
};
}
return this._polygonMumbai;
}
public get polygonZkEvm() {
if (!this._polygonZkEvm) {
this._polygonZkEvm = {
common: polygonZkEvmCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('polygonZkEvm'), polygonZkEvmCommon),
};
}
return this._polygonZkEvm;
}
public get polygonZkEvmTestnet() {
if (!this._polygonZkEvmTestnet) {
this._polygonZkEvmTestnet = {
common: polygonZkEvmTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('polygonZkEvmTestnet'), polygonZkEvmTestnetCommon),
};
}
return this._polygonZkEvmTestnet;
}
public get redstone() {
if (!this._redstone) {
this._redstone = {
common: redstoneCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('redstone'), redstoneCommon),
};
}
return this._redstone;
}
public get scroll() {
if (!this._scroll) {
this._scroll = {
common: scrollCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('scroll'), scrollCommon),
};
}
return this._scroll;
}
public get sepolia() {
if (!this._sepolia) {
this._sepolia = {
common: sepoliaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('sepolia'), sepoliaCommon),
};
}
return this._sepolia;
}
public get zksync() {
if (!this._zksync) {
this._zksync = {
common: zksyncCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('zksync'), zksyncCommon),
};
}
return this._zksync;
}
public get zksyncSepolia() {
if (!this._zksyncSepolia) {
this._zksyncSepolia = {
common: zksyncSepoliaTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('zksyncSepolia'), zksyncSepoliaTestnetCommon),
};
}
return this._zksyncSepolia;
}
public get zora() {
if (!this._zora) {
this._zora = {
common: zoraCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('zora'), zoraCommon),
};
}
return this._zora;
}
public get zoraSepolia() {
if (!this._zoraSepolia) {
this._zoraSepolia = {
common: zoraSepoliaCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('zoraSepolia'), zoraSepoliaCommon),
};
}
return this._zoraSepolia;
}
public get zoraTestnet() {
if (!this._zoraTestnet) {
this._zoraTestnet = {
common: zoraTestnetCommon,
node: Nodes.createTevmNode(this.storage.getStoredUrl('zoraTestnet'), zoraTestnetCommon),
};
}
return this._zoraTestnet;
}
}