-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNodes.ts
41 lines (36 loc) · 1.24 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
import { base as baseCommon, mainnet as mainnetCommon, optimism as optimismCommon } from "tevm/common";
import { Storage } from "./Storage";
import { Common } from 'tevm/common'
export type SupportedNetwork = 'mainnet' | 'optimism' | 'base'
/**
* Tevm node eagerly instanciates tevm nodes for the three networks
* It lazy loads the tevm library for optimial code splitting
*/
export class Nodes {
// We choose to lazy load tevm to optimize first load
public static lazyLoadedTevmNode = async (rpcUrl: string, common: Common) => {
const { createTevmNode, http } = await import('tevm')
return createTevmNode({
common,
fork: {
transport: http(rpcUrl)({})
}
})
}
constructor(
storage: Storage,
public network: SupportedNetwork = 'mainnet',
public mainnet = {
common: mainnetCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('mainnet'), mainnetCommon),
},
public optimism = {
common: optimismCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('optimism'), optimismCommon),
},
public base = {
common: baseCommon,
lazyLoadedNode: Nodes.lazyLoadedTevmNode(storage.getStoredUrl('base'), baseCommon),
},
) { }
};