-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNodes.ts
342 lines (317 loc) · 10.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
import {
arbitrumSepolia as arbitrumSepoliaViemChain,
arbitrumNova as arbitrumNovaViemChain,
celo as celoViemChain,
zksync as zksyncViemChain,
zksyncSepoliaTestnet as zksyncSepoliaTestnetViemChain,
berachainTestnetbArtio as berachainTestnetbArtioViemChain,
} from 'viem/chains'
import {
createCommon,
base as baseCommon,
mainnet as mainnetCommon,
optimism as optimismCommon,
arbitrum as arbitrumCommon,
zora as zoraCommon,
polygon as polygonCommon,
redstone as redstoneCommon,
sepolia as sepoliaCommon,
baseSepolia as baseSepoliaCommon,
scroll as scrollCommon,
blast as blastCommon,
avalanche as avalanceCommon,
manta as manaCommon,
zoraSepolia as zoraSepoliaCommon,
mantle as mantleCommon,
optimismSepolia as optimismSeplia,
tevmDefault as tevmDefault,
} from "tevm/common";
import { Storage } from "./Storage";
import { createTevmNode, http } from 'tevm'
import type { Common } from 'tevm/common'
export type SupportedNetwork =
| "arbitrum"
| "arbitrumNova"
| "arbitrumSepolia"
| "avalanche"
| "base"
| "baseSepolia"
| "berachain"
| "blast"
| "celo"
| "mainnet"
| "manta"
| "mantle"
| "optimism"
| "optimismSepolia"
| "polygon"
| "redstone"
| "scroll"
| "sepolia"
| "zksync"
| "zksyncSepolia"
| "zora"
| "zoraSepolia";
/**
* Tevm node eagerly instantiates tevm nodes for all supported networks
* It lazy loads the tevm library for optimal code splitting
*/
export class Nodes {
// We choose to lazy load tevm to optimize first load
public static lazyLoadedTevmNode = async (rpcUrl: string, common: Common) => {
return createTevmNode({
common,
fork: {
transport: http(rpcUrl)({})
}
})
}
private storage: Storage;
public network: SupportedNetwork;
private _mainnet: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
private _base: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
private _optimism: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
private _arbitrum: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
private _polygon: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
private _zora: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _redstone: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _sepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _baseSepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _scroll: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _blast: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _avalanche: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _manta: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _zoraSepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _mantle: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _optimismSepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _arbitrumSepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _arbitrumNova: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _celo: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _zksync: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _zksyncSepolia: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
private _berachain: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> } | undefined;
public newChain: { common: Common; lazyLoadedNode: Promise<ReturnType<typeof createTevmNode>> };
constructor(storage: Storage, network: SupportedNetwork = 'mainnet') {
this.storage = storage;
this.network = network;
// Optimistically create mainnet through polygon
this._mainnet = {
common: mainnetCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('mainnet'), mainnetCommon),
};
this._base = {
common: baseCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('base'), baseCommon),
};
this._optimism = {
common: optimismCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('optimism'), optimismCommon),
};
this._arbitrum = {
common: arbitrumCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('arbitrum'), arbitrumCommon),
};
this._polygon = {
common: polygonCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('polygon'), polygonCommon),
};
this.newChain = {
common: tevmDefault,
lazyLoadedNode: Promise.resolve(createTevmNode({ common: tevmDefault })),
};
}
public get mainnet() { return this._mainnet; }
public get base() { return this._base; }
public get optimism() { return this._optimism; }
public get arbitrum() { return this._arbitrum; }
public get polygon() { return this._polygon; }
public get zora() {
if (!this._zora) {
this._zora = {
common: zoraCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('zora'), zoraCommon),
};
}
return this._zora;
}
public get redstone() {
if (!this._redstone) {
this._redstone = {
common: redstoneCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('redstone'), redstoneCommon),
};
}
return this._redstone;
}
public get sepolia() {
if (!this._sepolia) {
this._sepolia = {
common: sepoliaCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('sepolia'), sepoliaCommon),
};
}
return this._sepolia;
}
public get baseSepolia() {
if (!this._baseSepolia) {
this._baseSepolia = {
common: baseSepoliaCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('baseSepolia'), baseSepoliaCommon),
};
}
return this._baseSepolia;
}
public get scroll() {
if (!this._scroll) {
this._scroll = {
common: scrollCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('scroll'), scrollCommon),
};
}
return this._scroll;
}
public get blast() {
if (!this._blast) {
this._blast = {
common: blastCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('blast'), blastCommon),
};
}
return this._blast;
}
public get avalanche() {
if (!this._avalanche) {
this._avalanche = {
common: avalanceCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('avalanche'), avalanceCommon),
};
}
return this._avalanche;
}
public get manta() {
if (!this._manta) {
this._manta = {
common: manaCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('manta'), manaCommon),
};
}
return this._manta;
}
public get zoraSepolia() {
if (!this._zoraSepolia) {
this._zoraSepolia = {
common: zoraSepoliaCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('zoraSepolia'), zoraSepoliaCommon),
};
}
return this._zoraSepolia;
}
public get mantle() {
if (!this._mantle) {
this._mantle = {
common: mantleCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('mantle'), mantleCommon),
};
}
return this._mantle;
}
public get optimismSepolia() {
if (!this._optimismSepolia) {
this._optimismSepolia = {
common: optimismSeplia,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('optimismSepolia'), optimismSeplia),
};
}
return this._optimismSepolia;
}
public get arbitrumSepolia() {
if (!this._arbitrumSepolia) {
const common = createCommon({
...arbitrumSepoliaViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._arbitrumSepolia = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('arbitrumSepolia'), common),
};
}
return this._arbitrumSepolia;
}
public get arbitrumNova() {
if (!this._arbitrumNova) {
const common = createCommon({
...arbitrumNovaViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._arbitrumNova = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('arbitrumNova'), common),
};
}
return this._arbitrumNova;
}
public get celo() {
if (!this._celo) {
const common = createCommon({
...celoViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._celo = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('celo'), common),
};
}
return this._celo;
}
public get zksync() {
if (!this._zksync) {
const common = createCommon({
...zksyncViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._zksync = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('zksync'), common),
};
}
return this._zksync;
}
public get zksyncSepolia() {
if (!this._zksyncSepolia) {
const common = createCommon({
...zksyncSepoliaTestnetViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._zksyncSepolia = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('zksyncSepolia'), common),
};
}
return this._zksyncSepolia;
}
public get berachain() {
if (!this._berachain) {
const common = createCommon({
...berachainTestnetbArtioViemChain,
loggingLevel: 'warn',
hardfork: 'cancun',
eips: [],
});
this._berachain = {
common,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(this.storage.getStoredUrl('berachain'), common),
};
}
return this._berachain;
}
}