@1delta/providers 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evm.d.ts +43 -2
- package/dist/evm.d.ts.map +1 -1
- package/dist/evm.js +105 -54
- package/package.json +1 -1
- package/src/evm.ts +208 -158
package/dist/evm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicClient } from
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
2
|
export declare const crossfi: {
|
|
3
3
|
blockExplorers: {
|
|
4
4
|
readonly default: {
|
|
@@ -24,6 +24,7 @@ export declare const crossfi: {
|
|
|
24
24
|
readonly name: "XFI";
|
|
25
25
|
readonly symbol: "XFI";
|
|
26
26
|
};
|
|
27
|
+
experimental_preconfirmationTime?: number | undefined | undefined;
|
|
27
28
|
rpcUrls: {
|
|
28
29
|
readonly default: {
|
|
29
30
|
readonly http: readonly ["https://rpc.mainnet.ms/"];
|
|
@@ -58,6 +59,7 @@ export declare const botanix: {
|
|
|
58
59
|
readonly name: "BTC";
|
|
59
60
|
readonly symbol: "BTC";
|
|
60
61
|
};
|
|
62
|
+
experimental_preconfirmationTime?: number | undefined | undefined;
|
|
61
63
|
rpcUrls: {
|
|
62
64
|
readonly default: {
|
|
63
65
|
readonly http: readonly ["https://rpc.ankr.com/botanix_mainnet", "https://rpc.botanixlabs.com"];
|
|
@@ -70,6 +72,41 @@ export declare const botanix: {
|
|
|
70
72
|
formatters?: undefined;
|
|
71
73
|
serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable> | undefined;
|
|
72
74
|
};
|
|
75
|
+
export declare const hyperEvm: {
|
|
76
|
+
blockExplorers: {
|
|
77
|
+
readonly default: {
|
|
78
|
+
readonly name: "Explorer";
|
|
79
|
+
readonly url: "https://hypurrscan.io/";
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
blockTime?: number | undefined | undefined;
|
|
83
|
+
contracts: {
|
|
84
|
+
readonly multicall3: {
|
|
85
|
+
readonly address: "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
86
|
+
readonly blockCreated: 1;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
ensTlds?: readonly string[] | undefined;
|
|
90
|
+
id: 999;
|
|
91
|
+
name: "Hyper EVM";
|
|
92
|
+
nativeCurrency: {
|
|
93
|
+
readonly decimals: 18;
|
|
94
|
+
readonly name: "HYPE";
|
|
95
|
+
readonly symbol: "HYPE";
|
|
96
|
+
};
|
|
97
|
+
experimental_preconfirmationTime?: number | undefined | undefined;
|
|
98
|
+
rpcUrls: {
|
|
99
|
+
readonly default: {
|
|
100
|
+
readonly http: readonly ["https://rpc.hyperliquid.xyz/evm"];
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
sourceId?: number | undefined | undefined;
|
|
104
|
+
testnet?: boolean | undefined | undefined;
|
|
105
|
+
custom?: Record<string, unknown> | undefined;
|
|
106
|
+
fees?: import("viem").ChainFees<undefined> | undefined;
|
|
107
|
+
formatters?: undefined;
|
|
108
|
+
serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable> | undefined;
|
|
109
|
+
};
|
|
73
110
|
export declare const GraphLinq: {
|
|
74
111
|
blockExplorers: {
|
|
75
112
|
readonly default: {
|
|
@@ -95,6 +132,7 @@ export declare const GraphLinq: {
|
|
|
95
132
|
readonly name: "GLQ";
|
|
96
133
|
readonly symbol: "GLQ";
|
|
97
134
|
};
|
|
135
|
+
experimental_preconfirmationTime?: number | undefined | undefined;
|
|
98
136
|
rpcUrls: {
|
|
99
137
|
readonly default: {
|
|
100
138
|
readonly http: readonly ["https://glq-dataseed.graphlinq.io"];
|
|
@@ -111,5 +149,8 @@ export declare function getEvmClient(chain: string, rpcId?: number): PublicClien
|
|
|
111
149
|
export declare function createMulticallRetry(customRpcs?: {
|
|
112
150
|
[chainId: string]: string[];
|
|
113
151
|
}): (chain: string, calls: any[], abi: any, batchSize?: number, maxRetries?: number, providerId?: number, allowFailure?: boolean) => Promise<any[]>;
|
|
114
|
-
export declare function
|
|
152
|
+
export declare function getEvmClientWithCustomRpcs(chain: string, rpcId?: number, customRpcs?: {
|
|
153
|
+
[chainId: string]: string[];
|
|
154
|
+
}): PublicClient;
|
|
155
|
+
export declare function multicallRetry(chain: string, calls: any[], abi: any, batchSize?: number, maxRetries?: number, providerId?: number, allowFailure?: boolean, overrdies?: any): Promise<any[]>;
|
|
115
156
|
//# sourceMappingURL=evm.d.ts.map
|
package/dist/evm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../src/evm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyC,YAAY,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../src/evm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyC,YAAY,EAAE,MAAM,MAAM,CAAA;AAiE1E,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBlB,CAAA;AAEF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBlB,CAAA;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBnB,CAAA;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBpB,CAAA;AA2OF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,YAAY,CAiBnE;AAID,wBAAgB,oBAAoB,CAAC,UAAU,CAAC,EAAE;IAChD,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC5B,IAEG,OAAO,MAAM,EACb,OAAO,GAAG,EAAE,EACZ,KAAK,GAAG,EACR,kBAA8B,EAC9B,mBAAc,EACd,mBAAc,EACd,sBAAmB,oBAoCtB;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,KAAK,SAAI,EACT,UAAU,CAAC,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,GAC3C,YAAY,CAsCd;AAED,wBAAsB,cAAc,CAClC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,GAAG,EAAE,EACZ,GAAG,EAAE,GAAG,EACR,SAAS,SAAqB,EAC9B,UAAU,SAAI,EACd,UAAU,SAAI,EACd,YAAY,UAAQ,EACpB,SAAS,GAAE,GAAoB,kBAYhC"}
|
package/dist/evm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Chain, CHAIN_INFO } from
|
|
2
|
-
import { isArray, uniq } from
|
|
3
|
-
import { createPublicClient, defineChain, http } from
|
|
4
|
-
import { mantle, mainnet, optimism, arbitrum, bsc, avalanche, taiko, metis, polygon, zksync, scroll, gnosis, base, blast, kaia, opBNB, fantom, sonic, linea, hemi, neonMainnet, degen, gravity, lightlinkPhoenix, plume, abstract, peaq, flowMainnet, soneium, goat, berachain, rootstock, ink, vanar, fuse, superposition, story, apeChain, telos, flare, aurora, kava, iota, coreDao, unichain, mode, xLayer, zircuit, corn, bob, manta, harmonyOne, celo, bitlayer, merlin, sei, iotex, bsquared, zetachain, ronin, inEVM, } from
|
|
1
|
+
import { Chain, CHAIN_INFO } from '@1delta/asset-registry';
|
|
2
|
+
import { isArray, uniq } from 'lodash';
|
|
3
|
+
import { createPublicClient, defineChain, http } from 'viem';
|
|
4
|
+
import { mantle, mainnet, optimism, arbitrum, bsc, avalanche, taiko, metis, polygon, zksync, scroll, gnosis, base, blast, kaia, opBNB, fantom, sonic, linea, hemi, neonMainnet, degen, gravity, lightlinkPhoenix, plume, abstract, peaq, flowMainnet, soneium, goat, berachain, rootstock, ink, vanar, fuse, superposition, story, apeChain, telos, flare, aurora, kava, iota, coreDao, unichain, mode, xLayer, zircuit, corn, bob, manta, harmonyOne, celo, bitlayer, merlin, sei, iotex, bsquared, zetachain, ronin, inEVM, } from 'viem/chains';
|
|
5
5
|
export const crossfi = defineChain({
|
|
6
6
|
id: 4158,
|
|
7
7
|
name: 'CrossFi Mainet',
|
|
@@ -36,8 +36,8 @@ export const botanix = defineChain({
|
|
|
36
36
|
rpcUrls: {
|
|
37
37
|
default: {
|
|
38
38
|
http: [
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
'https://rpc.ankr.com/botanix_mainnet',
|
|
40
|
+
'https://rpc.botanixlabs.com',
|
|
41
41
|
],
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -46,10 +46,33 @@ export const botanix = defineChain({
|
|
|
46
46
|
},
|
|
47
47
|
contracts: {
|
|
48
48
|
multicall3: {
|
|
49
|
-
address:
|
|
49
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
50
50
|
blockCreated: 1,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
export const hyperEvm = defineChain({
|
|
55
|
+
id: 999,
|
|
56
|
+
name: 'Hyper EVM',
|
|
57
|
+
nativeCurrency: {
|
|
58
|
+
decimals: 18,
|
|
59
|
+
name: 'HYPE',
|
|
60
|
+
symbol: 'HYPE',
|
|
61
|
+
},
|
|
62
|
+
rpcUrls: {
|
|
63
|
+
default: {
|
|
64
|
+
http: ['https://rpc.hyperliquid.xyz/evm'],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
blockExplorers: {
|
|
68
|
+
default: { name: 'Explorer', url: 'https://hypurrscan.io/' },
|
|
69
|
+
},
|
|
70
|
+
contracts: {
|
|
71
|
+
multicall3: {
|
|
72
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
73
|
+
blockCreated: 1,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
53
76
|
});
|
|
54
77
|
export const GraphLinq = defineChain({
|
|
55
78
|
id: 614,
|
|
@@ -61,11 +84,11 @@ export const GraphLinq = defineChain({
|
|
|
61
84
|
},
|
|
62
85
|
rpcUrls: {
|
|
63
86
|
default: {
|
|
64
|
-
http: [
|
|
87
|
+
http: ['https://glq-dataseed.graphlinq.io'],
|
|
65
88
|
},
|
|
66
89
|
},
|
|
67
90
|
blockExplorers: {
|
|
68
|
-
default: { name: 'Explorer',
|
|
91
|
+
default: { name: 'Explorer', url: 'https://explorer.graphlinq.io' },
|
|
69
92
|
},
|
|
70
93
|
// contracts: {
|
|
71
94
|
// multicall3: {
|
|
@@ -119,10 +142,10 @@ function getEvmChain(chain) {
|
|
|
119
142
|
...hemi,
|
|
120
143
|
contracts: {
|
|
121
144
|
multicall3: {
|
|
122
|
-
address:
|
|
145
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
123
146
|
blockCreated: 1,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
147
|
+
},
|
|
148
|
+
},
|
|
126
149
|
};
|
|
127
150
|
case Chain.NEON_EVM_MAINNET:
|
|
128
151
|
return neonMainnet;
|
|
@@ -131,10 +154,10 @@ function getEvmChain(chain) {
|
|
|
131
154
|
...degen,
|
|
132
155
|
contracts: {
|
|
133
156
|
multicall3: {
|
|
134
|
-
address:
|
|
157
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
135
158
|
blockCreated: 1,
|
|
136
|
-
}
|
|
137
|
-
}
|
|
159
|
+
},
|
|
160
|
+
},
|
|
138
161
|
};
|
|
139
162
|
case Chain.GRAVITY_ALPHA_MAINNET:
|
|
140
163
|
return gravity;
|
|
@@ -163,10 +186,10 @@ function getEvmChain(chain) {
|
|
|
163
186
|
...ink,
|
|
164
187
|
contracts: {
|
|
165
188
|
multicall3: {
|
|
166
|
-
address:
|
|
189
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
167
190
|
blockCreated: 1,
|
|
168
|
-
}
|
|
169
|
-
}
|
|
191
|
+
},
|
|
192
|
+
},
|
|
170
193
|
};
|
|
171
194
|
case Chain.FUSE_MAINNET:
|
|
172
195
|
return fuse;
|
|
@@ -177,10 +200,10 @@ function getEvmChain(chain) {
|
|
|
177
200
|
...story,
|
|
178
201
|
contracts: {
|
|
179
202
|
multicall3: {
|
|
180
|
-
address:
|
|
203
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
181
204
|
blockCreated: 1,
|
|
182
|
-
}
|
|
183
|
-
}
|
|
205
|
+
},
|
|
206
|
+
},
|
|
184
207
|
};
|
|
185
208
|
case Chain.APECHAIN:
|
|
186
209
|
return apeChain;
|
|
@@ -229,10 +252,10 @@ function getEvmChain(chain) {
|
|
|
229
252
|
...bsquared,
|
|
230
253
|
contracts: {
|
|
231
254
|
multicall3: {
|
|
232
|
-
address:
|
|
255
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
233
256
|
blockCreated: 1,
|
|
234
|
-
}
|
|
235
|
-
}
|
|
257
|
+
},
|
|
258
|
+
},
|
|
236
259
|
};
|
|
237
260
|
case Chain.SEI_NETWORK:
|
|
238
261
|
return sei;
|
|
@@ -241,10 +264,10 @@ function getEvmChain(chain) {
|
|
|
241
264
|
...merlin,
|
|
242
265
|
contracts: {
|
|
243
266
|
multicall3: {
|
|
244
|
-
address:
|
|
267
|
+
address: '0x46063722c010AF39E465d286B84936A12aFb81F0',
|
|
245
268
|
blockCreated: 1,
|
|
246
|
-
}
|
|
247
|
-
}
|
|
269
|
+
},
|
|
270
|
+
},
|
|
248
271
|
};
|
|
249
272
|
case Chain.X_LAYER_MAINNET:
|
|
250
273
|
return xLayer;
|
|
@@ -254,20 +277,50 @@ function getEvmChain(chain) {
|
|
|
254
277
|
return botanix;
|
|
255
278
|
case Chain.HARMONY_MAINNET_SHARD_0:
|
|
256
279
|
return harmonyOne;
|
|
280
|
+
case Chain.HYPEREVM:
|
|
281
|
+
return hyperEvm;
|
|
257
282
|
// case Chain.VANA:
|
|
258
283
|
// return vana
|
|
259
284
|
// case Chain.RARI_CHAIN_MAINNET:
|
|
260
285
|
// return rariChain
|
|
261
286
|
// case Chain.GLUE_MAINNET:
|
|
262
287
|
// return glue
|
|
263
|
-
default:
|
|
288
|
+
default:
|
|
289
|
+
throw new Error('Not in VIEM: ' + chain);
|
|
264
290
|
}
|
|
265
291
|
}
|
|
266
292
|
const RPC_OVERRIDES = {
|
|
267
|
-
[Chain.FANTOM_OPERA]:
|
|
268
|
-
[Chain.BNB_SMART_CHAIN_MAINNET]:
|
|
269
|
-
[Chain.METIS_ANDROMEDA_MAINNET]:
|
|
270
|
-
[Chain.X_LAYER_MAINNET]:
|
|
293
|
+
[Chain.FANTOM_OPERA]: 'https://rpc.fantom.network',
|
|
294
|
+
[Chain.BNB_SMART_CHAIN_MAINNET]: 'https://bsc-dataseed2.ninicoin.io',
|
|
295
|
+
[Chain.METIS_ANDROMEDA_MAINNET]: 'https://andromeda.metis.io/?owner=1088',
|
|
296
|
+
[Chain.X_LAYER_MAINNET]: 'https://xlayerrpc.okx.com',
|
|
297
|
+
};
|
|
298
|
+
const LIST_OVERRIDES = {
|
|
299
|
+
[Chain.BASE]: [
|
|
300
|
+
'https://base.drpc.org',
|
|
301
|
+
'https://base.public.blockpi.network/v1/rpc/public',
|
|
302
|
+
'https://1rpc.io/base',
|
|
303
|
+
'https://base.meowrpc.com',
|
|
304
|
+
'https://base-mainnet.public.blastapi.io',
|
|
305
|
+
'https://base.gateway.tenderly.co',
|
|
306
|
+
'https://gateway.tenderly.co/public/base',
|
|
307
|
+
'https://rpc.notadegen.com/base',
|
|
308
|
+
'https://base-rpc.publicnode.com',
|
|
309
|
+
'https://developer-access-mainnet.base.org',
|
|
310
|
+
'https://base-pokt.nodies.app',
|
|
311
|
+
'https://base.api.onfinality.io/public',
|
|
312
|
+
'https://public.stackup.sh/api/v1/node/base-mainnet',
|
|
313
|
+
'https://base-mainnet.gateway.tatum.io',
|
|
314
|
+
'https://base.rpc.subquery.network/public',
|
|
315
|
+
'https://api.zan.top/base-mainnet',
|
|
316
|
+
'https://endpoints.omniatech.io/v1/base/mainnet/public',
|
|
317
|
+
'https://base.lava.build',
|
|
318
|
+
'https://rpc.numa.network/base',
|
|
319
|
+
'https://0xrpc.io/base',
|
|
320
|
+
'https://base.therpc.io',
|
|
321
|
+
'https://base.llamarpc.com',
|
|
322
|
+
'https://base-mainnet.diamondswap.org/rpc',
|
|
323
|
+
],
|
|
271
324
|
};
|
|
272
325
|
function trimTrailingSlash(url) {
|
|
273
326
|
if (!url)
|
|
@@ -280,16 +333,16 @@ export function getEvmClient(chain, rpcId = 0) {
|
|
|
280
333
|
if (rpcId === 0)
|
|
281
334
|
rpc = chainInfo.rpcUrls.default.http[0];
|
|
282
335
|
else {
|
|
283
|
-
const rpcsChain =
|
|
284
|
-
|
|
285
|
-
const
|
|
336
|
+
const rpcsChain = LIST_OVERRIDES[chain] ??
|
|
337
|
+
CHAIN_INFO[chain].rpc?.filter((a) => !a.includes('wss://'));
|
|
338
|
+
const rpcs = chainInfo.rpcUrls.default.http.map((a) => trimTrailingSlash(a));
|
|
339
|
+
const rpcsAdded = rpcsChain.map((a) => trimTrailingSlash(a));
|
|
286
340
|
const allRpcs = uniq([...rpcs, ...rpcsAdded]);
|
|
287
341
|
rpc = allRpcs[rpcId];
|
|
288
342
|
}
|
|
289
343
|
return createPublicClient({
|
|
290
344
|
chain: chainInfo,
|
|
291
|
-
transport: http(RPC_OVERRIDES[chain] ??
|
|
292
|
-
rpc)
|
|
345
|
+
transport: http(RPC_OVERRIDES[chain] ?? rpc),
|
|
293
346
|
});
|
|
294
347
|
}
|
|
295
348
|
const DEFAULT_BATCH_SIZE = 4096;
|
|
@@ -299,7 +352,7 @@ export function createMulticallRetry(customRpcs) {
|
|
|
299
352
|
const provider = getEvmClientWithCustomRpcs(chain, providerId, customRpcs);
|
|
300
353
|
const abiIsArray = isArray(abi[0]);
|
|
301
354
|
const data = await provider.multicall({
|
|
302
|
-
batchSize
|
|
355
|
+
batchSize,
|
|
303
356
|
contracts: calls.map((call, i) => ({
|
|
304
357
|
abi: abiIsArray ? abi?.[i] : abi,
|
|
305
358
|
address: call.address,
|
|
@@ -310,7 +363,7 @@ export function createMulticallRetry(customRpcs) {
|
|
|
310
363
|
allowFailure,
|
|
311
364
|
});
|
|
312
365
|
if (allowFailure) {
|
|
313
|
-
return data.map(({ result, status }) => status !==
|
|
366
|
+
return data.map(({ result, status }) => status !== 'success' ? '0x' : result);
|
|
314
367
|
}
|
|
315
368
|
return data;
|
|
316
369
|
}
|
|
@@ -323,17 +376,16 @@ export function createMulticallRetry(customRpcs) {
|
|
|
323
376
|
}
|
|
324
377
|
};
|
|
325
378
|
}
|
|
326
|
-
function getEvmClientWithCustomRpcs(chain, rpcId = 0, customRpcs) {
|
|
379
|
+
export function getEvmClientWithCustomRpcs(chain, rpcId = 0, customRpcs) {
|
|
327
380
|
const chainInfo = getEvmChain(chain);
|
|
328
381
|
let rpc;
|
|
329
382
|
if (customRpcs && customRpcs[chain]) {
|
|
330
383
|
// Use custom RPC list if any (make sure that they are unique and valid)
|
|
331
384
|
const customRpcList = uniq(customRpcs[chain]
|
|
332
385
|
.filter(Boolean) // Remove empty ones
|
|
333
|
-
.filter(a => !a.includes(
|
|
334
|
-
.map(url => trimTrailingSlash(url))
|
|
335
|
-
.filter((url) => Boolean(url))
|
|
336
|
-
);
|
|
386
|
+
.filter((a) => !a.includes('wss://')) // filter websocket ones (like the default impl)
|
|
387
|
+
.map((url) => trimTrailingSlash(url))
|
|
388
|
+
.filter((url) => Boolean(url)));
|
|
337
389
|
if (customRpcList.length === 0) {
|
|
338
390
|
throw new Error(`No valid custom RPCs provided for chain ${chain}`);
|
|
339
391
|
}
|
|
@@ -344,20 +396,19 @@ function getEvmClientWithCustomRpcs(chain, rpcId = 0, customRpcs) {
|
|
|
344
396
|
if (rpcId === 0)
|
|
345
397
|
rpc = chainInfo.rpcUrls.default.http[0];
|
|
346
398
|
else {
|
|
347
|
-
const rpcsChain = CHAIN_INFO[chain].rpc?.filter(a => !a.includes(
|
|
348
|
-
const rpcs = chainInfo.rpcUrls.default.http.map(a => trimTrailingSlash(a));
|
|
349
|
-
const rpcsAdded = rpcsChain.map(a => trimTrailingSlash(a));
|
|
399
|
+
const rpcsChain = CHAIN_INFO[chain].rpc?.filter((a) => !a.includes('wss://'));
|
|
400
|
+
const rpcs = chainInfo.rpcUrls.default.http.map((a) => trimTrailingSlash(a));
|
|
401
|
+
const rpcsAdded = rpcsChain.map((a) => trimTrailingSlash(a));
|
|
350
402
|
const allRpcs = uniq([...rpcs, ...rpcsAdded]);
|
|
351
403
|
rpc = allRpcs[rpcId];
|
|
352
404
|
}
|
|
353
405
|
}
|
|
354
406
|
return createPublicClient({
|
|
355
407
|
chain: chainInfo,
|
|
356
|
-
transport: http(RPC_OVERRIDES[chain] ??
|
|
357
|
-
rpc)
|
|
408
|
+
transport: http(RPC_OVERRIDES[chain] ?? rpc),
|
|
358
409
|
});
|
|
359
410
|
}
|
|
360
|
-
export async function multicallRetry(chain, calls, abi, batchSize = DEFAULT_BATCH_SIZE, maxRetries =
|
|
361
|
-
const defaultMulticallRetry = createMulticallRetry();
|
|
362
|
-
return defaultMulticallRetry(chain, calls, abi, batchSize, maxRetries, providerId);
|
|
411
|
+
export async function multicallRetry(chain, calls, abi, batchSize = DEFAULT_BATCH_SIZE, maxRetries = 5, providerId = 0, allowFailure = false, overrdies = LIST_OVERRIDES) {
|
|
412
|
+
const defaultMulticallRetry = createMulticallRetry(overrdies);
|
|
413
|
+
return defaultMulticallRetry(chain, calls, abi, batchSize, maxRetries, providerId, allowFailure);
|
|
363
414
|
}
|
package/package.json
CHANGED
package/src/evm.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Chain, CHAIN_INFO } from
|
|
2
|
-
import { isArray, uniq } from
|
|
3
|
-
import { createPublicClient, defineChain, http, PublicClient } from
|
|
1
|
+
import { Chain, CHAIN_INFO } from '@1delta/asset-registry'
|
|
2
|
+
import { isArray, uniq } from 'lodash'
|
|
3
|
+
import { createPublicClient, defineChain, http, PublicClient } from 'viem'
|
|
4
4
|
import {
|
|
5
5
|
mantle,
|
|
6
6
|
mainnet,
|
|
@@ -63,23 +63,23 @@ import {
|
|
|
63
63
|
zetachain,
|
|
64
64
|
ronin,
|
|
65
65
|
inEVM,
|
|
66
|
-
} from
|
|
66
|
+
} from 'viem/chains'
|
|
67
67
|
|
|
68
68
|
export const crossfi = defineChain({
|
|
69
69
|
id: 4158,
|
|
70
|
-
name:
|
|
70
|
+
name: 'CrossFi Mainet',
|
|
71
71
|
nativeCurrency: {
|
|
72
72
|
decimals: 18,
|
|
73
|
-
name:
|
|
74
|
-
symbol:
|
|
73
|
+
name: 'XFI',
|
|
74
|
+
symbol: 'XFI',
|
|
75
75
|
},
|
|
76
76
|
rpcUrls: {
|
|
77
77
|
default: {
|
|
78
|
-
http: [
|
|
78
|
+
http: ['https://rpc.mainnet.ms/'],
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
81
|
blockExplorers: {
|
|
82
|
-
default: { name:
|
|
82
|
+
default: { name: 'Explorer', url: 'https://xfiscan.com/' },
|
|
83
83
|
},
|
|
84
84
|
// contracts: {
|
|
85
85
|
// multicall3: {
|
|
@@ -87,50 +87,74 @@ export const crossfi = defineChain({
|
|
|
87
87
|
// blockCreated: 1,
|
|
88
88
|
// }
|
|
89
89
|
// }
|
|
90
|
-
})
|
|
90
|
+
})
|
|
91
91
|
|
|
92
92
|
export const botanix = defineChain({
|
|
93
93
|
id: 3637,
|
|
94
|
-
name:
|
|
94
|
+
name: 'Botanix',
|
|
95
95
|
nativeCurrency: {
|
|
96
96
|
decimals: 18,
|
|
97
|
-
name:
|
|
98
|
-
symbol:
|
|
97
|
+
name: 'BTC',
|
|
98
|
+
symbol: 'BTC',
|
|
99
99
|
},
|
|
100
100
|
rpcUrls: {
|
|
101
101
|
default: {
|
|
102
102
|
http: [
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
'https://rpc.ankr.com/botanix_mainnet',
|
|
104
|
+
'https://rpc.botanixlabs.com',
|
|
105
105
|
],
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
108
|
blockExplorers: {
|
|
109
|
-
default: { name:
|
|
109
|
+
default: { name: 'Explorer', url: 'https://botanixscan.io/' },
|
|
110
110
|
},
|
|
111
111
|
contracts: {
|
|
112
112
|
multicall3: {
|
|
113
|
-
address:
|
|
113
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
114
114
|
blockCreated: 1,
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
|
-
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
export const hyperEvm = defineChain({
|
|
120
|
+
id: 999,
|
|
121
|
+
name: 'Hyper EVM',
|
|
122
|
+
nativeCurrency: {
|
|
123
|
+
decimals: 18,
|
|
124
|
+
name: 'HYPE',
|
|
125
|
+
symbol: 'HYPE',
|
|
126
|
+
},
|
|
127
|
+
rpcUrls: {
|
|
128
|
+
default: {
|
|
129
|
+
http: ['https://rpc.hyperliquid.xyz/evm'],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
blockExplorers: {
|
|
133
|
+
default: { name: 'Explorer', url: 'https://hypurrscan.io/' },
|
|
134
|
+
},
|
|
135
|
+
contracts: {
|
|
136
|
+
multicall3: {
|
|
137
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
138
|
+
blockCreated: 1,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
})
|
|
118
142
|
|
|
119
143
|
export const GraphLinq = defineChain({
|
|
120
144
|
id: 614,
|
|
121
|
-
name:
|
|
145
|
+
name: 'GraphLinq Chain',
|
|
122
146
|
nativeCurrency: {
|
|
123
147
|
decimals: 18,
|
|
124
|
-
name:
|
|
125
|
-
symbol:
|
|
148
|
+
name: 'GLQ',
|
|
149
|
+
symbol: 'GLQ',
|
|
126
150
|
},
|
|
127
151
|
rpcUrls: {
|
|
128
152
|
default: {
|
|
129
|
-
http: [
|
|
153
|
+
http: ['https://glq-dataseed.graphlinq.io'],
|
|
130
154
|
},
|
|
131
155
|
},
|
|
132
156
|
blockExplorers: {
|
|
133
|
-
default: { name:
|
|
157
|
+
default: { name: 'Explorer', url: 'https://explorer.graphlinq.io' },
|
|
134
158
|
},
|
|
135
159
|
// contracts: {
|
|
136
160
|
// multicall3: {
|
|
@@ -138,188 +162,190 @@ export const GraphLinq = defineChain({
|
|
|
138
162
|
// blockCreated: 1,
|
|
139
163
|
// }
|
|
140
164
|
// }
|
|
141
|
-
})
|
|
165
|
+
})
|
|
142
166
|
|
|
143
167
|
function getEvmChain(chain: string) {
|
|
144
168
|
switch (chain) {
|
|
145
169
|
case Chain.ARBITRUM_ONE:
|
|
146
|
-
return arbitrum
|
|
170
|
+
return arbitrum
|
|
147
171
|
case Chain.ETHEREUM_MAINNET:
|
|
148
|
-
return mainnet
|
|
172
|
+
return mainnet
|
|
149
173
|
case Chain.MANTLE:
|
|
150
|
-
return mantle
|
|
174
|
+
return mantle
|
|
151
175
|
case Chain.BNB_SMART_CHAIN_MAINNET:
|
|
152
|
-
return bsc
|
|
176
|
+
return bsc
|
|
153
177
|
case Chain.OPBNB_MAINNET:
|
|
154
|
-
return opBNB
|
|
178
|
+
return opBNB
|
|
155
179
|
case Chain.TAIKO_ALETHIA:
|
|
156
|
-
return taiko
|
|
180
|
+
return taiko
|
|
157
181
|
case Chain.AVALANCHE_C_CHAIN:
|
|
158
|
-
return avalanche
|
|
182
|
+
return avalanche
|
|
159
183
|
case Chain.OP_MAINNET:
|
|
160
|
-
return optimism
|
|
184
|
+
return optimism
|
|
161
185
|
case Chain.METIS_ANDROMEDA_MAINNET:
|
|
162
|
-
return metis
|
|
186
|
+
return metis
|
|
163
187
|
case Chain.POLYGON_MAINNET:
|
|
164
|
-
return polygon
|
|
188
|
+
return polygon
|
|
165
189
|
case Chain.ZKSYNC_MAINNET:
|
|
166
|
-
return zksync
|
|
190
|
+
return zksync
|
|
167
191
|
case Chain.SCROLL:
|
|
168
|
-
return scroll
|
|
192
|
+
return scroll
|
|
169
193
|
case Chain.GNOSIS:
|
|
170
|
-
return gnosis
|
|
194
|
+
return gnosis
|
|
171
195
|
case Chain.BASE:
|
|
172
|
-
return base
|
|
196
|
+
return base
|
|
173
197
|
case Chain.BLAST:
|
|
174
|
-
return blast
|
|
198
|
+
return blast
|
|
175
199
|
case Chain.KAIA_MAINNET:
|
|
176
|
-
return kaia
|
|
200
|
+
return kaia
|
|
177
201
|
case Chain.FANTOM_OPERA:
|
|
178
|
-
return fantom
|
|
202
|
+
return fantom
|
|
179
203
|
case Chain.SONIC_MAINNET:
|
|
180
|
-
return sonic
|
|
204
|
+
return sonic
|
|
181
205
|
case Chain.LINEA:
|
|
182
|
-
return linea
|
|
206
|
+
return linea
|
|
183
207
|
case Chain.HEMI_NETWORK:
|
|
184
208
|
return {
|
|
185
209
|
...hemi,
|
|
186
210
|
contracts: {
|
|
187
211
|
multicall3: {
|
|
188
|
-
address:
|
|
212
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
189
213
|
blockCreated: 1,
|
|
190
214
|
},
|
|
191
215
|
},
|
|
192
|
-
}
|
|
216
|
+
}
|
|
193
217
|
case Chain.NEON_EVM_MAINNET:
|
|
194
|
-
return neonMainnet
|
|
218
|
+
return neonMainnet
|
|
195
219
|
case Chain.DEGEN_CHAIN:
|
|
196
220
|
return {
|
|
197
221
|
...degen,
|
|
198
222
|
contracts: {
|
|
199
223
|
multicall3: {
|
|
200
|
-
address:
|
|
224
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
201
225
|
blockCreated: 1,
|
|
202
226
|
},
|
|
203
227
|
},
|
|
204
|
-
}
|
|
228
|
+
}
|
|
205
229
|
case Chain.GRAVITY_ALPHA_MAINNET:
|
|
206
|
-
return gravity
|
|
230
|
+
return gravity
|
|
207
231
|
case Chain.LIGHTLINK_PHOENIX_MAINNET:
|
|
208
|
-
return lightlinkPhoenix
|
|
232
|
+
return lightlinkPhoenix
|
|
209
233
|
case Chain.PLUME_MAINNET:
|
|
210
|
-
return plume
|
|
234
|
+
return plume
|
|
211
235
|
case Chain.ABSTRACT:
|
|
212
|
-
return abstract
|
|
236
|
+
return abstract
|
|
213
237
|
case Chain.PEAQ:
|
|
214
|
-
return peaq
|
|
238
|
+
return peaq
|
|
215
239
|
case Chain.EVM_ON_FLOW:
|
|
216
|
-
return flowMainnet
|
|
240
|
+
return flowMainnet
|
|
217
241
|
case Chain.SONEIUM:
|
|
218
|
-
return soneium
|
|
242
|
+
return soneium
|
|
219
243
|
case Chain.GOAT_NETWORK:
|
|
220
|
-
return goat
|
|
244
|
+
return goat
|
|
221
245
|
case Chain.BERACHAIN:
|
|
222
|
-
return berachain
|
|
246
|
+
return berachain
|
|
223
247
|
case Chain.ROOTSTOCK_MAINNET:
|
|
224
|
-
return rootstock
|
|
248
|
+
return rootstock
|
|
225
249
|
case Chain.VANAR_MAINNET:
|
|
226
|
-
return vanar
|
|
250
|
+
return vanar
|
|
227
251
|
case Chain.INK:
|
|
228
252
|
return {
|
|
229
253
|
...ink,
|
|
230
254
|
contracts: {
|
|
231
255
|
multicall3: {
|
|
232
|
-
address:
|
|
256
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
233
257
|
blockCreated: 1,
|
|
234
258
|
},
|
|
235
259
|
},
|
|
236
|
-
}
|
|
260
|
+
}
|
|
237
261
|
case Chain.FUSE_MAINNET:
|
|
238
|
-
return fuse
|
|
262
|
+
return fuse
|
|
239
263
|
case Chain.SUPERPOSITION:
|
|
240
|
-
return superposition
|
|
264
|
+
return superposition
|
|
241
265
|
case Chain.STORY:
|
|
242
266
|
return {
|
|
243
267
|
...story,
|
|
244
268
|
contracts: {
|
|
245
269
|
multicall3: {
|
|
246
|
-
address:
|
|
270
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
247
271
|
blockCreated: 1,
|
|
248
272
|
},
|
|
249
273
|
},
|
|
250
|
-
}
|
|
274
|
+
}
|
|
251
275
|
case Chain.APECHAIN:
|
|
252
|
-
return apeChain
|
|
276
|
+
return apeChain
|
|
253
277
|
case Chain.IOTEX_NETWORK_MAINNET:
|
|
254
|
-
return iotex
|
|
278
|
+
return iotex
|
|
255
279
|
case Chain.TELOS_EVM_MAINNET:
|
|
256
|
-
return telos
|
|
280
|
+
return telos
|
|
257
281
|
case Chain.FLARE_MAINNET:
|
|
258
|
-
return flare
|
|
282
|
+
return flare
|
|
259
283
|
case Chain.AURA_MAINNET:
|
|
260
|
-
return aurora
|
|
284
|
+
return aurora
|
|
261
285
|
case Chain.KAVA:
|
|
262
|
-
return kava
|
|
286
|
+
return kava
|
|
263
287
|
case Chain.IOTA_EVM:
|
|
264
|
-
return iota
|
|
288
|
+
return iota
|
|
265
289
|
case Chain.AURORA_MAINNET:
|
|
266
|
-
return aurora
|
|
290
|
+
return aurora
|
|
267
291
|
case Chain.UNICHAIN:
|
|
268
|
-
return unichain
|
|
292
|
+
return unichain
|
|
269
293
|
case Chain.CORE_BLOCKCHAIN_MAINNET:
|
|
270
|
-
return coreDao
|
|
294
|
+
return coreDao
|
|
271
295
|
case Chain.MODE:
|
|
272
|
-
return mode
|
|
296
|
+
return mode
|
|
273
297
|
case Chain.CORN:
|
|
274
|
-
return corn
|
|
298
|
+
return corn
|
|
275
299
|
case Chain.BOB:
|
|
276
|
-
return bob
|
|
300
|
+
return bob
|
|
277
301
|
case Chain.RONIN_MAINNET:
|
|
278
|
-
return ronin
|
|
302
|
+
return ronin
|
|
279
303
|
case Chain.MANTA_PACIFIC_MAINNET:
|
|
280
|
-
return manta
|
|
304
|
+
return manta
|
|
281
305
|
case Chain.ZIRCUIT_MAINNET:
|
|
282
|
-
return zircuit
|
|
306
|
+
return zircuit
|
|
283
307
|
case Chain.GRAPHLINQ_BLOCKCHAIN_MAINNET:
|
|
284
|
-
return GraphLinq
|
|
308
|
+
return GraphLinq
|
|
285
309
|
case Chain.ZETACHAIN_MAINNET:
|
|
286
|
-
return zetachain
|
|
310
|
+
return zetachain
|
|
287
311
|
case Chain.BITLAYER_MAINNET:
|
|
288
|
-
return bitlayer
|
|
312
|
+
return bitlayer
|
|
289
313
|
case Chain.CROSSFI_MAINNET:
|
|
290
|
-
return crossfi
|
|
314
|
+
return crossfi
|
|
291
315
|
case Chain.INEVM_MAINNET:
|
|
292
|
-
return inEVM
|
|
316
|
+
return inEVM
|
|
293
317
|
case Chain.B2_MAINNET:
|
|
294
318
|
return {
|
|
295
319
|
...bsquared,
|
|
296
320
|
contracts: {
|
|
297
321
|
multicall3: {
|
|
298
|
-
address:
|
|
322
|
+
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
|
|
299
323
|
blockCreated: 1,
|
|
300
324
|
},
|
|
301
325
|
},
|
|
302
|
-
}
|
|
326
|
+
}
|
|
303
327
|
case Chain.SEI_NETWORK:
|
|
304
|
-
return sei
|
|
328
|
+
return sei
|
|
305
329
|
case Chain.MERLIN_MAINNET:
|
|
306
330
|
return {
|
|
307
331
|
...merlin,
|
|
308
332
|
contracts: {
|
|
309
333
|
multicall3: {
|
|
310
|
-
address:
|
|
334
|
+
address: '0x46063722c010AF39E465d286B84936A12aFb81F0',
|
|
311
335
|
blockCreated: 1,
|
|
312
336
|
},
|
|
313
337
|
},
|
|
314
|
-
}
|
|
338
|
+
}
|
|
315
339
|
case Chain.X_LAYER_MAINNET:
|
|
316
|
-
return xLayer
|
|
340
|
+
return xLayer
|
|
317
341
|
case Chain.CELO_MAINNET:
|
|
318
|
-
return celo
|
|
342
|
+
return celo
|
|
319
343
|
case Chain.BOTANIX_MAINNET:
|
|
320
|
-
return botanix
|
|
344
|
+
return botanix
|
|
321
345
|
case Chain.HARMONY_MAINNET_SHARD_0:
|
|
322
|
-
return harmonyOne
|
|
346
|
+
return harmonyOne
|
|
347
|
+
case Chain.HYPEREVM:
|
|
348
|
+
return hyperEvm
|
|
323
349
|
// case Chain.VANA:
|
|
324
350
|
// return vana
|
|
325
351
|
// case Chain.RARI_CHAIN_MAINNET:
|
|
@@ -327,47 +353,73 @@ function getEvmChain(chain: string) {
|
|
|
327
353
|
// case Chain.GLUE_MAINNET:
|
|
328
354
|
// return glue
|
|
329
355
|
default:
|
|
330
|
-
throw new Error(
|
|
356
|
+
throw new Error('Not in VIEM: ' + chain)
|
|
331
357
|
}
|
|
332
358
|
}
|
|
333
359
|
|
|
334
360
|
const RPC_OVERRIDES: any = {
|
|
335
|
-
[Chain.FANTOM_OPERA]:
|
|
336
|
-
[Chain.BNB_SMART_CHAIN_MAINNET]:
|
|
337
|
-
[Chain.METIS_ANDROMEDA_MAINNET]:
|
|
338
|
-
[Chain.X_LAYER_MAINNET]:
|
|
339
|
-
}
|
|
361
|
+
[Chain.FANTOM_OPERA]: 'https://rpc.fantom.network',
|
|
362
|
+
[Chain.BNB_SMART_CHAIN_MAINNET]: 'https://bsc-dataseed2.ninicoin.io',
|
|
363
|
+
[Chain.METIS_ANDROMEDA_MAINNET]: 'https://andromeda.metis.io/?owner=1088',
|
|
364
|
+
[Chain.X_LAYER_MAINNET]: 'https://xlayerrpc.okx.com',
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const LIST_OVERRIDES: { [c: string]: any[] } = {
|
|
368
|
+
[Chain.BASE]: [
|
|
369
|
+
'https://base.drpc.org',
|
|
370
|
+
'https://base.public.blockpi.network/v1/rpc/public',
|
|
371
|
+
'https://1rpc.io/base',
|
|
372
|
+
'https://base.meowrpc.com',
|
|
373
|
+
'https://base-mainnet.public.blastapi.io',
|
|
374
|
+
'https://base.gateway.tenderly.co',
|
|
375
|
+
'https://gateway.tenderly.co/public/base',
|
|
376
|
+
'https://rpc.notadegen.com/base',
|
|
377
|
+
'https://base-rpc.publicnode.com',
|
|
378
|
+
'https://developer-access-mainnet.base.org',
|
|
379
|
+
'https://base-pokt.nodies.app',
|
|
380
|
+
'https://base.api.onfinality.io/public',
|
|
381
|
+
'https://public.stackup.sh/api/v1/node/base-mainnet',
|
|
382
|
+
'https://base-mainnet.gateway.tatum.io',
|
|
383
|
+
'https://base.rpc.subquery.network/public',
|
|
384
|
+
'https://api.zan.top/base-mainnet',
|
|
385
|
+
'https://endpoints.omniatech.io/v1/base/mainnet/public',
|
|
386
|
+
'https://base.lava.build',
|
|
387
|
+
'https://rpc.numa.network/base',
|
|
388
|
+
'https://0xrpc.io/base',
|
|
389
|
+
'https://base.therpc.io',
|
|
390
|
+
'https://base.llamarpc.com',
|
|
391
|
+
'https://base-mainnet.diamondswap.org/rpc',
|
|
392
|
+
],
|
|
393
|
+
}
|
|
340
394
|
|
|
341
395
|
function trimTrailingSlash(url?: string) {
|
|
342
|
-
if (!url) return undefined
|
|
343
|
-
return url.endsWith(
|
|
396
|
+
if (!url) return undefined
|
|
397
|
+
return url.endsWith('/') ? url.slice(0, -1) : url
|
|
344
398
|
}
|
|
345
399
|
|
|
346
400
|
export function getEvmClient(chain: string, rpcId = 0): PublicClient {
|
|
347
|
-
const chainInfo = getEvmChain(chain)
|
|
348
|
-
let rpc: string
|
|
349
|
-
if (rpcId === 0) rpc = chainInfo.rpcUrls.default.http[0]
|
|
401
|
+
const chainInfo = getEvmChain(chain)
|
|
402
|
+
let rpc: string
|
|
403
|
+
if (rpcId === 0) rpc = chainInfo.rpcUrls.default.http[0]
|
|
350
404
|
else {
|
|
351
|
-
const rpcsChain =
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const rpcs = chainInfo.rpcUrls.default.http.map((a) =>
|
|
355
|
-
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
const allRpcs = uniq([...rpcs, ...rpcsAdded]);
|
|
359
|
-
rpc = allRpcs[rpcId] as any;
|
|
405
|
+
const rpcsChain =
|
|
406
|
+
LIST_OVERRIDES[chain] ??
|
|
407
|
+
CHAIN_INFO[chain].rpc?.filter((a) => !a.includes('wss://'))
|
|
408
|
+
const rpcs = chainInfo.rpcUrls.default.http.map((a) => trimTrailingSlash(a))
|
|
409
|
+
const rpcsAdded = rpcsChain.map((a) => trimTrailingSlash(a))
|
|
410
|
+
const allRpcs = uniq([...rpcs, ...rpcsAdded])
|
|
411
|
+
rpc = allRpcs[rpcId] as any
|
|
360
412
|
}
|
|
361
413
|
return createPublicClient({
|
|
362
414
|
chain: chainInfo as any,
|
|
363
415
|
transport: http(RPC_OVERRIDES[chain] ?? rpc),
|
|
364
|
-
}) as any
|
|
416
|
+
}) as any
|
|
365
417
|
}
|
|
366
418
|
|
|
367
|
-
const DEFAULT_BATCH_SIZE = 4096
|
|
419
|
+
const DEFAULT_BATCH_SIZE = 4096
|
|
368
420
|
|
|
369
421
|
export function createMulticallRetry(customRpcs?: {
|
|
370
|
-
[chainId: string]: string[]
|
|
422
|
+
[chainId: string]: string[]
|
|
371
423
|
}) {
|
|
372
424
|
return async function multicallRetry(
|
|
373
425
|
chain: string,
|
|
@@ -376,17 +428,13 @@ export function createMulticallRetry(customRpcs?: {
|
|
|
376
428
|
batchSize = DEFAULT_BATCH_SIZE,
|
|
377
429
|
maxRetries = 3,
|
|
378
430
|
providerId = 0,
|
|
379
|
-
allowFailure = true
|
|
431
|
+
allowFailure = true,
|
|
380
432
|
) {
|
|
381
433
|
try {
|
|
382
|
-
const provider = getEvmClientWithCustomRpcs(
|
|
383
|
-
|
|
384
|
-
providerId,
|
|
385
|
-
customRpcs
|
|
386
|
-
);
|
|
387
|
-
const abiIsArray = isArray(abi[0]);
|
|
434
|
+
const provider = getEvmClientWithCustomRpcs(chain, providerId, customRpcs)
|
|
435
|
+
const abiIsArray = isArray(abi[0])
|
|
388
436
|
const data = await provider.multicall({
|
|
389
|
-
batchSize
|
|
437
|
+
batchSize,
|
|
390
438
|
contracts: calls.map((call, i) => ({
|
|
391
439
|
abi: abiIsArray ? abi?.[i] : abi,
|
|
392
440
|
address: call.address as any,
|
|
@@ -395,72 +443,71 @@ export function createMulticallRetry(customRpcs?: {
|
|
|
395
443
|
args: call.args ?? call.params ?? [],
|
|
396
444
|
})),
|
|
397
445
|
allowFailure,
|
|
398
|
-
})
|
|
446
|
+
})
|
|
399
447
|
if (allowFailure) {
|
|
400
448
|
return (data as any[]).map(({ result, status }: any) =>
|
|
401
|
-
status !==
|
|
402
|
-
)
|
|
449
|
+
status !== 'success' ? '0x' : result,
|
|
450
|
+
)
|
|
403
451
|
}
|
|
404
|
-
return data
|
|
452
|
+
return data
|
|
405
453
|
} catch (e) {
|
|
406
454
|
// error if max retries achieved
|
|
407
|
-
if (maxRetries === 0) throw e
|
|
408
|
-
console.log(e)
|
|
455
|
+
if (maxRetries === 0) throw e
|
|
456
|
+
console.log(e)
|
|
409
457
|
return await multicallRetry(
|
|
410
458
|
chain,
|
|
411
459
|
calls,
|
|
412
460
|
abi,
|
|
413
461
|
batchSize,
|
|
414
462
|
maxRetries - 1,
|
|
415
|
-
providerId + 1
|
|
416
|
-
)
|
|
463
|
+
providerId + 1,
|
|
464
|
+
)
|
|
417
465
|
}
|
|
418
|
-
}
|
|
466
|
+
}
|
|
419
467
|
}
|
|
420
468
|
|
|
421
469
|
export function getEvmClientWithCustomRpcs(
|
|
422
470
|
chain: string,
|
|
423
471
|
rpcId = 0,
|
|
424
|
-
customRpcs?: { [chainId: string]: string[] }
|
|
472
|
+
customRpcs?: { [chainId: string]: string[] },
|
|
425
473
|
): PublicClient {
|
|
426
|
-
const chainInfo = getEvmChain(chain)
|
|
427
|
-
let rpc: string
|
|
474
|
+
const chainInfo = getEvmChain(chain)
|
|
475
|
+
let rpc: string
|
|
428
476
|
|
|
429
477
|
if (customRpcs && customRpcs[chain]) {
|
|
430
478
|
// Use custom RPC list if any (make sure that they are unique and valid)
|
|
431
479
|
const customRpcList = uniq(
|
|
432
480
|
customRpcs[chain]
|
|
433
481
|
.filter(Boolean) // Remove empty ones
|
|
434
|
-
.filter((a) => !a.includes(
|
|
482
|
+
.filter((a) => !a.includes('wss://')) // filter websocket ones (like the default impl)
|
|
435
483
|
.map((url) => trimTrailingSlash(url))
|
|
436
|
-
.filter((url): url is string => Boolean(url)) // Type-safe filter for defined URLs
|
|
437
|
-
)
|
|
484
|
+
.filter((url): url is string => Boolean(url)), // Type-safe filter for defined URLs
|
|
485
|
+
)
|
|
438
486
|
|
|
439
487
|
if (customRpcList.length === 0) {
|
|
440
|
-
throw new Error(`No valid custom RPCs provided for chain ${chain}`)
|
|
488
|
+
throw new Error(`No valid custom RPCs provided for chain ${chain}`)
|
|
441
489
|
}
|
|
442
490
|
|
|
443
|
-
rpc = customRpcList[rpcId % customRpcList.length]
|
|
491
|
+
rpc = customRpcList[rpcId % customRpcList.length]
|
|
444
492
|
} else {
|
|
445
493
|
// Fallback to existing logic
|
|
446
|
-
if (rpcId === 0) rpc = chainInfo.rpcUrls.default.http[0]
|
|
494
|
+
if (rpcId === 0) rpc = chainInfo.rpcUrls.default.http[0]
|
|
447
495
|
else {
|
|
448
496
|
const rpcsChain = CHAIN_INFO[chain].rpc?.filter(
|
|
449
|
-
(a) => !a.includes(
|
|
450
|
-
)
|
|
497
|
+
(a) => !a.includes('wss://'),
|
|
498
|
+
)
|
|
451
499
|
const rpcs = chainInfo.rpcUrls.default.http.map((a) =>
|
|
452
|
-
trimTrailingSlash(a)
|
|
453
|
-
)
|
|
454
|
-
const rpcsAdded = rpcsChain.map((a) => trimTrailingSlash(a))
|
|
455
|
-
const allRpcs = uniq([...rpcs, ...rpcsAdded])
|
|
456
|
-
rpc = allRpcs[rpcId] as any
|
|
500
|
+
trimTrailingSlash(a),
|
|
501
|
+
)
|
|
502
|
+
const rpcsAdded = rpcsChain.map((a) => trimTrailingSlash(a))
|
|
503
|
+
const allRpcs = uniq([...rpcs, ...rpcsAdded])
|
|
504
|
+
rpc = allRpcs[rpcId] as any
|
|
457
505
|
}
|
|
458
506
|
}
|
|
459
|
-
|
|
460
507
|
return createPublicClient({
|
|
461
508
|
chain: chainInfo as any,
|
|
462
509
|
transport: http(RPC_OVERRIDES[chain] ?? rpc),
|
|
463
|
-
}) as any
|
|
510
|
+
}) as any
|
|
464
511
|
}
|
|
465
512
|
|
|
466
513
|
export async function multicallRetry(
|
|
@@ -468,16 +515,19 @@ export async function multicallRetry(
|
|
|
468
515
|
calls: any[],
|
|
469
516
|
abi: any,
|
|
470
517
|
batchSize = DEFAULT_BATCH_SIZE,
|
|
471
|
-
maxRetries =
|
|
472
|
-
providerId = 0
|
|
518
|
+
maxRetries = 5,
|
|
519
|
+
providerId = 0,
|
|
520
|
+
allowFailure = false,
|
|
521
|
+
overrdies: any = LIST_OVERRIDES,
|
|
473
522
|
) {
|
|
474
|
-
const defaultMulticallRetry = createMulticallRetry()
|
|
523
|
+
const defaultMulticallRetry = createMulticallRetry(overrdies)
|
|
475
524
|
return defaultMulticallRetry(
|
|
476
525
|
chain,
|
|
477
526
|
calls,
|
|
478
527
|
abi,
|
|
479
528
|
batchSize,
|
|
480
529
|
maxRetries,
|
|
481
|
-
providerId
|
|
482
|
-
|
|
530
|
+
providerId,
|
|
531
|
+
allowFailure,
|
|
532
|
+
)
|
|
483
533
|
}
|