@ohos-ports/ethcall 0.0.0-stage → 6.0.6-beta.1

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.
@@ -0,0 +1,440 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "components": [
6
+ {
7
+ "internalType": "address",
8
+ "name": "target",
9
+ "type": "address"
10
+ },
11
+ {
12
+ "internalType": "bytes",
13
+ "name": "callData",
14
+ "type": "bytes"
15
+ }
16
+ ],
17
+ "internalType": "struct Multicall3.Call[]",
18
+ "name": "calls",
19
+ "type": "tuple[]"
20
+ }
21
+ ],
22
+ "name": "aggregate",
23
+ "outputs": [
24
+ {
25
+ "internalType": "uint256",
26
+ "name": "blockNumber",
27
+ "type": "uint256"
28
+ },
29
+ {
30
+ "internalType": "bytes[]",
31
+ "name": "returnData",
32
+ "type": "bytes[]"
33
+ }
34
+ ],
35
+ "stateMutability": "view",
36
+ "type": "function"
37
+ },
38
+ {
39
+ "inputs": [
40
+ {
41
+ "components": [
42
+ {
43
+ "internalType": "address",
44
+ "name": "target",
45
+ "type": "address"
46
+ },
47
+ {
48
+ "internalType": "bool",
49
+ "name": "allowFailure",
50
+ "type": "bool"
51
+ },
52
+ {
53
+ "internalType": "bytes",
54
+ "name": "callData",
55
+ "type": "bytes"
56
+ }
57
+ ],
58
+ "internalType": "struct Multicall3.Call3[]",
59
+ "name": "calls",
60
+ "type": "tuple[]"
61
+ }
62
+ ],
63
+ "name": "aggregate3",
64
+ "outputs": [
65
+ {
66
+ "components": [
67
+ {
68
+ "internalType": "bool",
69
+ "name": "success",
70
+ "type": "bool"
71
+ },
72
+ {
73
+ "internalType": "bytes",
74
+ "name": "returnData",
75
+ "type": "bytes"
76
+ }
77
+ ],
78
+ "internalType": "struct Multicall3.Result[]",
79
+ "name": "returnData",
80
+ "type": "tuple[]"
81
+ }
82
+ ],
83
+ "stateMutability": "view",
84
+ "type": "function"
85
+ },
86
+ {
87
+ "inputs": [
88
+ {
89
+ "components": [
90
+ {
91
+ "internalType": "address",
92
+ "name": "target",
93
+ "type": "address"
94
+ },
95
+ {
96
+ "internalType": "bool",
97
+ "name": "allowFailure",
98
+ "type": "bool"
99
+ },
100
+ {
101
+ "internalType": "uint256",
102
+ "name": "value",
103
+ "type": "uint256"
104
+ },
105
+ {
106
+ "internalType": "bytes",
107
+ "name": "callData",
108
+ "type": "bytes"
109
+ }
110
+ ],
111
+ "internalType": "struct Multicall3.Call3Value[]",
112
+ "name": "calls",
113
+ "type": "tuple[]"
114
+ }
115
+ ],
116
+ "name": "aggregate3Value",
117
+ "outputs": [
118
+ {
119
+ "components": [
120
+ {
121
+ "internalType": "bool",
122
+ "name": "success",
123
+ "type": "bool"
124
+ },
125
+ {
126
+ "internalType": "bytes",
127
+ "name": "returnData",
128
+ "type": "bytes"
129
+ }
130
+ ],
131
+ "internalType": "struct Multicall3.Result[]",
132
+ "name": "returnData",
133
+ "type": "tuple[]"
134
+ }
135
+ ],
136
+ "stateMutability": "payable",
137
+ "type": "function"
138
+ },
139
+ {
140
+ "inputs": [
141
+ {
142
+ "components": [
143
+ {
144
+ "internalType": "address",
145
+ "name": "target",
146
+ "type": "address"
147
+ },
148
+ {
149
+ "internalType": "bytes",
150
+ "name": "callData",
151
+ "type": "bytes"
152
+ }
153
+ ],
154
+ "internalType": "struct Multicall3.Call[]",
155
+ "name": "calls",
156
+ "type": "tuple[]"
157
+ }
158
+ ],
159
+ "name": "blockAndAggregate",
160
+ "outputs": [
161
+ {
162
+ "internalType": "uint256",
163
+ "name": "blockNumber",
164
+ "type": "uint256"
165
+ },
166
+ {
167
+ "internalType": "bytes32",
168
+ "name": "blockHash",
169
+ "type": "bytes32"
170
+ },
171
+ {
172
+ "components": [
173
+ {
174
+ "internalType": "bool",
175
+ "name": "success",
176
+ "type": "bool"
177
+ },
178
+ {
179
+ "internalType": "bytes",
180
+ "name": "returnData",
181
+ "type": "bytes"
182
+ }
183
+ ],
184
+ "internalType": "struct Multicall3.Result[]",
185
+ "name": "returnData",
186
+ "type": "tuple[]"
187
+ }
188
+ ],
189
+ "stateMutability": "view",
190
+ "type": "function"
191
+ },
192
+ {
193
+ "inputs": [],
194
+ "name": "getBasefee",
195
+ "outputs": [
196
+ {
197
+ "internalType": "uint256",
198
+ "name": "basefee",
199
+ "type": "uint256"
200
+ }
201
+ ],
202
+ "stateMutability": "view",
203
+ "type": "function"
204
+ },
205
+ {
206
+ "inputs": [
207
+ {
208
+ "internalType": "uint256",
209
+ "name": "blockNumber",
210
+ "type": "uint256"
211
+ }
212
+ ],
213
+ "name": "getBlockHash",
214
+ "outputs": [
215
+ {
216
+ "internalType": "bytes32",
217
+ "name": "blockHash",
218
+ "type": "bytes32"
219
+ }
220
+ ],
221
+ "stateMutability": "view",
222
+ "type": "function"
223
+ },
224
+ {
225
+ "inputs": [],
226
+ "name": "getBlockNumber",
227
+ "outputs": [
228
+ {
229
+ "internalType": "uint256",
230
+ "name": "blockNumber",
231
+ "type": "uint256"
232
+ }
233
+ ],
234
+ "stateMutability": "view",
235
+ "type": "function"
236
+ },
237
+ {
238
+ "inputs": [],
239
+ "name": "getChainId",
240
+ "outputs": [
241
+ {
242
+ "internalType": "uint256",
243
+ "name": "chainid",
244
+ "type": "uint256"
245
+ }
246
+ ],
247
+ "stateMutability": "view",
248
+ "type": "function"
249
+ },
250
+ {
251
+ "inputs": [],
252
+ "name": "getCurrentBlockCoinbase",
253
+ "outputs": [
254
+ {
255
+ "internalType": "address",
256
+ "name": "coinbase",
257
+ "type": "address"
258
+ }
259
+ ],
260
+ "stateMutability": "view",
261
+ "type": "function"
262
+ },
263
+ {
264
+ "inputs": [],
265
+ "name": "getCurrentBlockDifficulty",
266
+ "outputs": [
267
+ {
268
+ "internalType": "uint256",
269
+ "name": "difficulty",
270
+ "type": "uint256"
271
+ }
272
+ ],
273
+ "stateMutability": "view",
274
+ "type": "function"
275
+ },
276
+ {
277
+ "inputs": [],
278
+ "name": "getCurrentBlockGasLimit",
279
+ "outputs": [
280
+ {
281
+ "internalType": "uint256",
282
+ "name": "gaslimit",
283
+ "type": "uint256"
284
+ }
285
+ ],
286
+ "stateMutability": "view",
287
+ "type": "function"
288
+ },
289
+ {
290
+ "inputs": [],
291
+ "name": "getCurrentBlockTimestamp",
292
+ "outputs": [
293
+ {
294
+ "internalType": "uint256",
295
+ "name": "timestamp",
296
+ "type": "uint256"
297
+ }
298
+ ],
299
+ "stateMutability": "view",
300
+ "type": "function"
301
+ },
302
+ {
303
+ "inputs": [
304
+ {
305
+ "internalType": "address",
306
+ "name": "addr",
307
+ "type": "address"
308
+ }
309
+ ],
310
+ "name": "getEthBalance",
311
+ "outputs": [
312
+ {
313
+ "internalType": "uint256",
314
+ "name": "balance",
315
+ "type": "uint256"
316
+ }
317
+ ],
318
+ "stateMutability": "view",
319
+ "type": "function"
320
+ },
321
+ {
322
+ "inputs": [],
323
+ "name": "getLastBlockHash",
324
+ "outputs": [
325
+ {
326
+ "internalType": "bytes32",
327
+ "name": "blockHash",
328
+ "type": "bytes32"
329
+ }
330
+ ],
331
+ "stateMutability": "view",
332
+ "type": "function"
333
+ },
334
+ {
335
+ "inputs": [
336
+ {
337
+ "internalType": "bool",
338
+ "name": "requireSuccess",
339
+ "type": "bool"
340
+ },
341
+ {
342
+ "components": [
343
+ {
344
+ "internalType": "address",
345
+ "name": "target",
346
+ "type": "address"
347
+ },
348
+ {
349
+ "internalType": "bytes",
350
+ "name": "callData",
351
+ "type": "bytes"
352
+ }
353
+ ],
354
+ "internalType": "struct Multicall3.Call[]",
355
+ "name": "calls",
356
+ "type": "tuple[]"
357
+ }
358
+ ],
359
+ "name": "tryAggregate",
360
+ "outputs": [
361
+ {
362
+ "components": [
363
+ {
364
+ "internalType": "bool",
365
+ "name": "success",
366
+ "type": "bool"
367
+ },
368
+ {
369
+ "internalType": "bytes",
370
+ "name": "returnData",
371
+ "type": "bytes"
372
+ }
373
+ ],
374
+ "internalType": "struct Multicall3.Result[]",
375
+ "name": "returnData",
376
+ "type": "tuple[]"
377
+ }
378
+ ],
379
+ "stateMutability": "view",
380
+ "type": "function"
381
+ },
382
+ {
383
+ "inputs": [
384
+ {
385
+ "internalType": "bool",
386
+ "name": "requireSuccess",
387
+ "type": "bool"
388
+ },
389
+ {
390
+ "components": [
391
+ {
392
+ "internalType": "address",
393
+ "name": "target",
394
+ "type": "address"
395
+ },
396
+ {
397
+ "internalType": "bytes",
398
+ "name": "callData",
399
+ "type": "bytes"
400
+ }
401
+ ],
402
+ "internalType": "struct Multicall3.Call[]",
403
+ "name": "calls",
404
+ "type": "tuple[]"
405
+ }
406
+ ],
407
+ "name": "tryBlockAndAggregate",
408
+ "outputs": [
409
+ {
410
+ "internalType": "uint256",
411
+ "name": "blockNumber",
412
+ "type": "uint256"
413
+ },
414
+ {
415
+ "internalType": "bytes32",
416
+ "name": "blockHash",
417
+ "type": "bytes32"
418
+ },
419
+ {
420
+ "components": [
421
+ {
422
+ "internalType": "bool",
423
+ "name": "success",
424
+ "type": "bool"
425
+ },
426
+ {
427
+ "internalType": "bytes",
428
+ "name": "returnData",
429
+ "type": "bytes"
430
+ }
431
+ ],
432
+ "internalType": "struct Multicall3.Result[]",
433
+ "name": "returnData",
434
+ "type": "tuple[]"
435
+ }
436
+ ],
437
+ "stateMutability": "nonpayable",
438
+ "type": "function"
439
+ }
440
+ ]
package/dist/abi.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { JsonFragmentType } from 'ethers';
2
+ import { Result } from 'ethers';
3
+ type Params = any[];
4
+ declare class Abi {
5
+ static encode(name: string, jsonInputs: readonly JsonFragmentType[], params: Params): string;
6
+ static encodeConstructor(jsonInputs: readonly JsonFragmentType[], params: Params): string;
7
+ static decode(name: string, jsonOutputs: readonly JsonFragmentType[], data: string): Result;
8
+ }
9
+ export type { Params };
10
+ export default Abi;
package/dist/abi.js ADDED
@@ -0,0 +1,89 @@
1
+ import { Coder } from 'abi-coder';
2
+ class Abi {
3
+ static encode(name, jsonInputs, params) {
4
+ const { params: inputs } = backfillParamNames(jsonInputs);
5
+ const abi = [
6
+ {
7
+ type: 'function',
8
+ name,
9
+ inputs,
10
+ },
11
+ ];
12
+ const coder = new Coder(abi);
13
+ const valueMap = Object.fromEntries(inputs.map((input, index) => [input.name, params[index]]));
14
+ return coder.encodeFunction(name, valueMap);
15
+ }
16
+ static encodeConstructor(jsonInputs, params) {
17
+ const { params: inputs } = backfillParamNames(jsonInputs);
18
+ const abi = [
19
+ {
20
+ type: 'constructor',
21
+ inputs,
22
+ },
23
+ ];
24
+ const coder = new Coder(abi);
25
+ const valueMap = Object.fromEntries(inputs.map((input, index) => [input.name, params[index]]));
26
+ return coder.encodeConstructor(valueMap);
27
+ }
28
+ static decode(name, jsonOutputs, data) {
29
+ const { params: outputs, generated } = backfillParamNames(jsonOutputs);
30
+ const abi = [
31
+ {
32
+ type: 'function',
33
+ name,
34
+ outputs,
35
+ },
36
+ ];
37
+ const coder = new Coder(abi);
38
+ const functionOutput = coder.decodeFunctionOutput(name, data);
39
+ const result = outputs.map((output) => functionOutput.values[output.name || '']);
40
+ for (const [name, value] of Object.entries(functionOutput.values)) {
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ const key = name;
43
+ // Skip generated names for clarity
44
+ if (generated.has(name)) {
45
+ continue;
46
+ }
47
+ // Don't overwrite existing keys
48
+ if (result[key]) {
49
+ continue;
50
+ }
51
+ result[key] = value;
52
+ }
53
+ return result;
54
+ }
55
+ }
56
+ // ABI doesn't enforce to specify param names
57
+ // However, abi-coder requires names to parse the params.
58
+ // Therefore, we "patch" the ABI by assigning unique param names.
59
+ function backfillParamNames(jsonParams) {
60
+ const names = new Set(...jsonParams.map((param) => param.name));
61
+ const generated = new Set();
62
+ const params = jsonParams.map((param) => {
63
+ const { name: originalName, indexed, type, components } = param;
64
+ const name = originalName ? originalName : generateUniqueName(names);
65
+ names.add(name);
66
+ if (!originalName) {
67
+ generated.add(name);
68
+ }
69
+ return {
70
+ name,
71
+ indexed,
72
+ type,
73
+ components,
74
+ };
75
+ });
76
+ return {
77
+ params,
78
+ generated,
79
+ };
80
+ }
81
+ function generateUniqueName(names) {
82
+ let i = 0;
83
+ while (names.has(i.toString())) {
84
+ i++;
85
+ }
86
+ return `param${Math.random().toString().substring(2)}`;
87
+ }
88
+ export default Abi;
89
+ //# sourceMappingURL=abi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abi.js","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAOlC,MAAM,GAAG;IACP,MAAM,CAAC,MAAM,CACX,IAAY,EACZ,UAAuC,EACvC,MAAc;QAEd,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,GAAG,GAAG;YACV;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI;gBACJ,MAAM;aACP;SACF,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAC1D,CAAC;QACF,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,iBAAiB,CACtB,UAAuC,EACvC,MAAc;QAEd,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,GAAG,GAAG;YACV;gBACE,IAAI,EAAE,aAAa;gBACnB,MAAM;aACP;SACF,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,QAAQ,GAAG,M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params } from './abi.js';
3
+ import type { Multicall } from './multicall.js';
4
+ import type { BlockTag } from './provider.js';
5
+ interface CallOverrides {
6
+ blockTag?: BlockTag;
7
+ from?: string;
8
+ }
9
+ interface Call {
10
+ contract: {
11
+ address: string;
12
+ };
13
+ name: string;
14
+ inputs: readonly JsonFragmentType[];
15
+ outputs: readonly JsonFragmentType[];
16
+ params: Params;
17
+ }
18
+ interface FailableCall extends Call {
19
+ canFail: boolean;
20
+ }
21
+ interface CallResult {
22
+ success: boolean;
23
+ returnData: string;
24
+ }
25
+ declare function all<T>(provider: Provider, multicall: Multicall | null, calls: Call[], overrides?: CallOverrides): Promise<T[]>;
26
+ declare function tryAll<T>(provider: Provider, multicall2: Multicall | null, calls: Call[], overrides?: CallOverrides): Promise<(T | null)[]>;
27
+ declare function tryEach<T>(provider: Provider, multicall3: Multicall | null, calls: FailableCall[], overrides?: CallOverrides): Promise<(T | null)[]>;
28
+ export { all, tryAll, tryEach };
29
+ export type { Call, CallOverrides, CallResult };