forked from ubiquity/rpc-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.ts
86 lines (73 loc) · 1.97 KB
/
handler.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
import { JsonRpcProvider } from "@ethersproject/providers";
import { networkCurrencies, networkExplorers, networkRpcs } from "./constants";
import { CHAINS_IDS, EXTRA_RPCS } from "./dynamic";
export type BlockExplorer = {
name: string;
url: string;
standard?: string;
icon?: string;
};
export type ValidBlockData = {
jsonrpc: string;
id: number;
result: {
number: string;
timestamp: string;
hash: string;
};
};
export type Token = {
decimals: number;
address: string;
symbol: string;
};
export type NativeToken = {
name: string;
symbol: string;
decimals: number;
};
export type HandlerInterface = {
getProvider(): JsonRpcProvider | null;
clearInstance(): void;
getFastestRpcProvider(): Promise<JsonRpcProvider | null>;
testRpcPerformance(): Promise<JsonRpcProvider | null>;
};
export type HandlerConstructorConfig = {
networkId: NetworkId;
networkName: NetworkName | null;
networkRpcs: Rpc[] | null;
autoStorage: boolean | null;
cacheRefreshCycles: number | null;
runtimeRpcs: string[] | null;
rpcTimeout: number | null;
tracking?: Tracking;
};
export type NetworkRPCs = typeof networkRpcs;
export type NetworkCurrencies = typeof networkCurrencies;
export type NetworkExplorers = typeof networkExplorers;
// filtered NetworkId union
export type NetworkId = keyof typeof EXTRA_RPCS | "31337" | "1337";
// unfiltered Record<NetworkId, NetworkName>
type ChainsUnfiltered = {
-readonly [K in keyof typeof CHAINS_IDS]: (typeof CHAINS_IDS)[K];
};
// filtered NetworkName union
export type NetworkName = ChainsUnfiltered[NetworkId] | "anvil" | "hardhat";
export type Tracking = "yes" | "limited" | "none";
export type Rpc = {
url: string;
tracking?: Tracking;
trackingDetails?: string;
isOpenSource?: boolean;
};
export function getRpcUrls(rpcs: Rpc[]) {
const urls: string[] = [];
rpcs.forEach((rpc) => {
if (typeof rpc == "string") {
urls.push(rpc);
} else {
urls.push(rpc.url);
}
});
return urls;
}