@covalenthq/client-sdk 2.0.3 → 2.1.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.
- package/README.md +3 -3
- package/dist/cjs/index.d.ts +1 -6
- package/dist/cjs/index.js +1793 -690
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/services/BaseService.d.ts +1 -1
- package/dist/cjs/src/services/NftService.d.ts +1 -1
- package/dist/cjs/src/services/PricingService.d.ts +1 -1
- package/dist/cjs/src/services/TransactionService.d.ts +4 -3
- package/dist/cjs/src/utils/functions/paginateEndpoint.d.ts +4 -4
- package/dist/cjs/src/utils/types/BalanceService.types.d.ts +52 -52
- package/dist/cjs/src/utils/types/BaseService.types.d.ts +55 -55
- package/dist/cjs/src/utils/types/Generic.types.d.ts +16 -8
- package/dist/cjs/src/utils/types/NftService.types.d.ts +53 -53
- package/dist/cjs/src/utils/types/PricingService.types.d.ts +7 -7
- package/dist/cjs/src/utils/types/SecurityService.types.d.ts +15 -15
- package/dist/cjs/src/utils/types/TransactionService.types.d.ts +47 -53
- package/dist/esm/index.d.ts +1 -6
- package/dist/esm/index.js +1794 -689
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/services/BaseService.d.ts +1 -1
- package/dist/esm/src/services/NftService.d.ts +1 -1
- package/dist/esm/src/services/PricingService.d.ts +1 -1
- package/dist/esm/src/services/TransactionService.d.ts +4 -3
- package/dist/esm/src/utils/functions/paginateEndpoint.d.ts +4 -4
- package/dist/esm/src/utils/types/BalanceService.types.d.ts +52 -52
- package/dist/esm/src/utils/types/BaseService.types.d.ts +55 -55
- package/dist/esm/src/utils/types/Generic.types.d.ts +16 -8
- package/dist/esm/src/utils/types/NftService.types.d.ts +53 -53
- package/dist/esm/src/utils/types/PricingService.types.d.ts +7 -7
- package/dist/esm/src/utils/types/SecurityService.types.d.ts +15 -15
- package/dist/esm/src/utils/types/TransactionService.types.d.ts +47 -53
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var version = "2.0.3";
|
|
3
|
+
var version = "2.1.1";
|
|
6
4
|
|
|
7
5
|
const bigIntParser = (val) => {
|
|
8
6
|
if (val === null || val === undefined) {
|
|
@@ -22,7 +20,7 @@ const endpointGenerator = (extension = "", params = []) => {
|
|
|
22
20
|
}
|
|
23
21
|
const urlParams = new URLSearchParams();
|
|
24
22
|
params.forEach((param) => {
|
|
25
|
-
if (param.value !== undefined) {
|
|
23
|
+
if (param.value !== undefined && param.value !== null) {
|
|
26
24
|
urlParams.append(param.key, param.value.toString());
|
|
27
25
|
}
|
|
28
26
|
});
|
|
@@ -32,7 +30,7 @@ const endpointGenerator = (extension = "", params = []) => {
|
|
|
32
30
|
async function* paginateEndpoint(endpoint, execution, parseData, implementation) {
|
|
33
31
|
let _endpoint = new URL(endpoint);
|
|
34
32
|
let hasMore = true;
|
|
35
|
-
let page_number = +_endpoint.searchParams.get("page-number") ?? 0;
|
|
33
|
+
let page_number = +(_endpoint.searchParams.get("page-number") ?? 0);
|
|
36
34
|
while (hasMore) {
|
|
37
35
|
try {
|
|
38
36
|
if (implementation === "pagination") {
|
|
@@ -121,27 +119,29 @@ class BalanceService {
|
|
|
121
119
|
},
|
|
122
120
|
]);
|
|
123
121
|
const parseData = (data) => {
|
|
124
|
-
data.data
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
if (data.data) {
|
|
123
|
+
data.data.updated_at = data.data.updated_at
|
|
124
|
+
? new Date(data.data.updated_at)
|
|
125
|
+
: null;
|
|
126
|
+
data.data.items = data.data.items
|
|
127
|
+
? data.data.items.map((balanceItem) => ({
|
|
128
|
+
...balanceItem,
|
|
129
|
+
balance: bigIntParser(balanceItem.balance),
|
|
130
|
+
balance_24h: bigIntParser(balanceItem.balance_24h),
|
|
131
|
+
last_transferred_at: balanceItem.last_transferred_at
|
|
132
|
+
? new Date(balanceItem.last_transferred_at)
|
|
133
|
+
: null,
|
|
134
|
+
nft_data: balanceItem.nft_data
|
|
135
|
+
? balanceItem.nft_data.map((nftItem) => ({
|
|
136
|
+
...nftItem,
|
|
137
|
+
token_id: bigIntParser(nftItem.token_id),
|
|
138
|
+
token_balance: bigIntParser(nftItem.token_balance),
|
|
139
|
+
token_price_wei: bigIntParser(nftItem.token_price_wei),
|
|
140
|
+
}))
|
|
141
|
+
: null,
|
|
142
|
+
}))
|
|
143
|
+
: null;
|
|
144
|
+
}
|
|
145
145
|
return data;
|
|
146
146
|
};
|
|
147
147
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -169,34 +169,37 @@ class BalanceService {
|
|
|
169
169
|
},
|
|
170
170
|
]);
|
|
171
171
|
const parseData = (data) => {
|
|
172
|
-
data.data
|
|
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
|
-
|
|
172
|
+
if (data.data) {
|
|
173
|
+
data.data.updated_at = data.data.updated_at
|
|
174
|
+
? new Date(data.data.updated_at)
|
|
175
|
+
: null;
|
|
176
|
+
data.data.items =
|
|
177
|
+
data.data.items?.map((portfolioItem) => ({
|
|
178
|
+
...portfolioItem,
|
|
179
|
+
holdings: portfolioItem.holdings?.map((holdingItem) => ({
|
|
180
|
+
...holdingItem,
|
|
181
|
+
timestamp: holdingItem.timestamp && data.data?.updated_at
|
|
182
|
+
? new Date(data.data.updated_at)
|
|
183
|
+
: null,
|
|
184
|
+
close: {
|
|
185
|
+
...holdingItem.close,
|
|
186
|
+
balance: bigIntParser(holdingItem.close?.balance),
|
|
187
|
+
},
|
|
188
|
+
high: {
|
|
189
|
+
...holdingItem.high,
|
|
190
|
+
balance: bigIntParser(holdingItem.high?.balance),
|
|
191
|
+
},
|
|
192
|
+
low: {
|
|
193
|
+
...holdingItem.low,
|
|
194
|
+
balance: bigIntParser(holdingItem.low?.balance),
|
|
195
|
+
},
|
|
196
|
+
open: {
|
|
197
|
+
...holdingItem.open,
|
|
198
|
+
balance: bigIntParser(holdingItem.open?.balance),
|
|
199
|
+
},
|
|
200
|
+
})) || null,
|
|
201
|
+
})) || null;
|
|
202
|
+
}
|
|
200
203
|
return data;
|
|
201
204
|
};
|
|
202
205
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -244,29 +247,31 @@ class BalanceService {
|
|
|
244
247
|
},
|
|
245
248
|
]);
|
|
246
249
|
const parseData = (data) => {
|
|
247
|
-
data.data
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
250
|
+
if (data.data) {
|
|
251
|
+
data.data.updated_at = data.data.updated_at
|
|
252
|
+
? new Date(data.data.updated_at)
|
|
253
|
+
: null;
|
|
254
|
+
data.data.items = data.data.items
|
|
255
|
+
? data.data.items.map((ercItem) => ({
|
|
256
|
+
...ercItem,
|
|
257
|
+
block_signed_at: ercItem.block_signed_at
|
|
258
|
+
? new Date(ercItem.block_signed_at)
|
|
259
|
+
: null,
|
|
260
|
+
value: bigIntParser(ercItem.value),
|
|
261
|
+
fees_paid: bigIntParser(ercItem.fees_paid),
|
|
262
|
+
transfers: ercItem.transfers
|
|
263
|
+
? ercItem.transfers.map((transferItem) => ({
|
|
264
|
+
...transferItem,
|
|
265
|
+
balance: bigIntParser(transferItem.balance),
|
|
266
|
+
block_signed_at: transferItem.block_signed_at
|
|
267
|
+
? new Date(transferItem.block_signed_at)
|
|
268
|
+
: null,
|
|
269
|
+
delta: bigIntParser(transferItem.delta),
|
|
270
|
+
}))
|
|
271
|
+
: null,
|
|
272
|
+
}))
|
|
273
|
+
: null;
|
|
274
|
+
}
|
|
270
275
|
return data;
|
|
271
276
|
};
|
|
272
277
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -316,27 +321,29 @@ class BalanceService {
|
|
|
316
321
|
},
|
|
317
322
|
]);
|
|
318
323
|
const parseData = (data) => {
|
|
319
|
-
data.data
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
fees_paid: bigIntParser(blockTxItem.fees_paid),
|
|
329
|
-
transfers: blockTxItem.transfers.map((transferItem) => ({
|
|
330
|
-
...transferItem,
|
|
331
|
-
balance: bigIntParser(transferItem.balance),
|
|
332
|
-
block_signed_at: transferItem.block_signed_at
|
|
333
|
-
? new Date(transferItem.block_signed_at)
|
|
324
|
+
if (data.data) {
|
|
325
|
+
data.data.updated_at = data.data.updated_at
|
|
326
|
+
? new Date(data.data.updated_at)
|
|
327
|
+
: null;
|
|
328
|
+
data.data.items = data.data.items
|
|
329
|
+
? data.data.items.map((blockTxItem) => ({
|
|
330
|
+
...blockTxItem,
|
|
331
|
+
block_signed_at: blockTxItem.block_signed_at
|
|
332
|
+
? new Date(blockTxItem.block_signed_at)
|
|
334
333
|
: null,
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
fees_paid: bigIntParser(blockTxItem.fees_paid),
|
|
335
|
+
transfers: blockTxItem.transfers?.map((transferItem) => ({
|
|
336
|
+
...transferItem,
|
|
337
|
+
balance: bigIntParser(transferItem.balance),
|
|
338
|
+
block_signed_at: transferItem.block_signed_at
|
|
339
|
+
? new Date(transferItem.block_signed_at)
|
|
340
|
+
: null,
|
|
341
|
+
delta: bigIntParser(transferItem.delta),
|
|
342
|
+
})) || null,
|
|
343
|
+
value: bigIntParser(blockTxItem.value),
|
|
344
|
+
}))
|
|
345
|
+
: null;
|
|
346
|
+
}
|
|
340
347
|
return data;
|
|
341
348
|
};
|
|
342
349
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -374,16 +381,18 @@ class BalanceService {
|
|
|
374
381
|
},
|
|
375
382
|
]);
|
|
376
383
|
const parseData = (data) => {
|
|
377
|
-
data.data
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
if (data.data) {
|
|
385
|
+
data.data.updated_at = data.data.updated_at
|
|
386
|
+
? new Date(data.data.updated_at)
|
|
387
|
+
: null;
|
|
388
|
+
data.data.items = data.data.items
|
|
389
|
+
? data.data.items.map((tokenItem) => ({
|
|
390
|
+
...tokenItem,
|
|
391
|
+
balance: bigIntParser(tokenItem.balance),
|
|
392
|
+
total_supply: bigIntParser(tokenItem.total_supply),
|
|
393
|
+
}))
|
|
394
|
+
: null;
|
|
395
|
+
}
|
|
387
396
|
return data;
|
|
388
397
|
};
|
|
389
398
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -423,16 +432,18 @@ class BalanceService {
|
|
|
423
432
|
},
|
|
424
433
|
]);
|
|
425
434
|
const parseData = (data) => {
|
|
426
|
-
data.data
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
435
|
+
if (data.data) {
|
|
436
|
+
data.data.updated_at = data.data.updated_at
|
|
437
|
+
? new Date(data.data.updated_at)
|
|
438
|
+
: null;
|
|
439
|
+
data.data.items = data.data.items
|
|
440
|
+
? data.data.items.map((balanceItem) => ({
|
|
441
|
+
...balanceItem,
|
|
442
|
+
balance: bigIntParser(balanceItem.balance),
|
|
443
|
+
total_supply: bigIntParser(balanceItem.total_supply),
|
|
444
|
+
}))
|
|
445
|
+
: null;
|
|
446
|
+
}
|
|
436
447
|
return data;
|
|
437
448
|
};
|
|
438
449
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -485,26 +496,28 @@ class BalanceService {
|
|
|
485
496
|
},
|
|
486
497
|
]);
|
|
487
498
|
const parseData = (data) => {
|
|
488
|
-
data.data
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
499
|
+
if (data.data) {
|
|
500
|
+
data.data.updated_at = data.data.updated_at
|
|
501
|
+
? new Date(data.data.updated_at)
|
|
502
|
+
: null;
|
|
503
|
+
data.data.items = data.data.items
|
|
504
|
+
? data.data.items.map((balanceItem) => ({
|
|
505
|
+
...balanceItem,
|
|
506
|
+
balance: bigIntParser(balanceItem.balance),
|
|
507
|
+
last_transferred_at: balanceItem.last_transferred_at
|
|
508
|
+
? new Date(balanceItem.last_transferred_at)
|
|
509
|
+
: null,
|
|
510
|
+
nft_data: balanceItem.nft_data
|
|
511
|
+
? balanceItem.nft_data.map((nftItem) => ({
|
|
512
|
+
...nftItem,
|
|
513
|
+
token_id: bigIntParser(nftItem.token_id),
|
|
514
|
+
token_balance: bigIntParser(nftItem.token_balance),
|
|
515
|
+
token_price_wei: bigIntParser(nftItem.token_price_wei),
|
|
516
|
+
}))
|
|
517
|
+
: null,
|
|
518
|
+
}))
|
|
519
|
+
: null;
|
|
520
|
+
}
|
|
508
521
|
return data;
|
|
509
522
|
};
|
|
510
523
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -530,15 +543,17 @@ class BalanceService {
|
|
|
530
543
|
},
|
|
531
544
|
]);
|
|
532
545
|
const parseData = (data) => {
|
|
533
|
-
data.data
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
546
|
+
if (data.data) {
|
|
547
|
+
data.data.updated_at = data.data.updated_at
|
|
548
|
+
? new Date(data.data.updated_at)
|
|
549
|
+
: null;
|
|
550
|
+
data.data.items = data.data.items
|
|
551
|
+
? data.data.items.map((balanceItem) => ({
|
|
552
|
+
...balanceItem,
|
|
553
|
+
balance: bigIntParser(balanceItem.balance),
|
|
554
|
+
}))
|
|
555
|
+
: null;
|
|
556
|
+
}
|
|
542
557
|
return data;
|
|
543
558
|
};
|
|
544
559
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -546,7 +561,7 @@ class BalanceService {
|
|
|
546
561
|
}
|
|
547
562
|
|
|
548
563
|
/**
|
|
549
|
-
*
|
|
564
|
+
* Base API
|
|
550
565
|
*
|
|
551
566
|
*/
|
|
552
567
|
class BaseService {
|
|
@@ -564,17 +579,19 @@ class BaseService {
|
|
|
564
579
|
async getBlock(chainName, blockHeight) {
|
|
565
580
|
const endpoint = endpointGenerator(`${chainName}/block_v2/${blockHeight}`, []);
|
|
566
581
|
const parseData = (data) => {
|
|
567
|
-
data.data
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
582
|
+
if (data.data) {
|
|
583
|
+
data.data.updated_at = data.data.updated_at
|
|
584
|
+
? new Date(data.data.updated_at)
|
|
585
|
+
: null;
|
|
586
|
+
data.data.items = data.data.items
|
|
587
|
+
? data.data.items.map((blockItem) => ({
|
|
588
|
+
...blockItem,
|
|
589
|
+
signed_at: blockItem.signed_at
|
|
590
|
+
? new Date(blockItem.signed_at)
|
|
591
|
+
: null,
|
|
592
|
+
}))
|
|
593
|
+
: null;
|
|
594
|
+
}
|
|
578
595
|
return data;
|
|
579
596
|
};
|
|
580
597
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -618,17 +635,19 @@ class BaseService {
|
|
|
618
635
|
},
|
|
619
636
|
]);
|
|
620
637
|
const parseData = (data) => {
|
|
621
|
-
data.data
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
638
|
+
if (data.data) {
|
|
639
|
+
data.data.updated_at = data.data.updated_at
|
|
640
|
+
? new Date(data.data.updated_at)
|
|
641
|
+
: null;
|
|
642
|
+
data.data.items = data.data.items
|
|
643
|
+
? data.data.items.map((blockItem) => ({
|
|
644
|
+
...blockItem,
|
|
645
|
+
signed_at: blockItem.signed_at
|
|
646
|
+
? new Date(blockItem.signed_at)
|
|
647
|
+
: null,
|
|
648
|
+
}))
|
|
649
|
+
: null;
|
|
650
|
+
}
|
|
632
651
|
return data;
|
|
633
652
|
};
|
|
634
653
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -659,17 +678,19 @@ class BaseService {
|
|
|
659
678
|
},
|
|
660
679
|
]);
|
|
661
680
|
const parseData = (data) => {
|
|
662
|
-
data.data
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
681
|
+
if (data.data) {
|
|
682
|
+
data.data.updated_at = data.data.updated_at
|
|
683
|
+
? new Date(data.data.updated_at)
|
|
684
|
+
: null;
|
|
685
|
+
data.data.items = data.data.items
|
|
686
|
+
? data.data.items.map((blockItem) => ({
|
|
687
|
+
...blockItem,
|
|
688
|
+
signed_at: blockItem.signed_at
|
|
689
|
+
? new Date(blockItem.signed_at)
|
|
690
|
+
: null,
|
|
691
|
+
}))
|
|
692
|
+
: null;
|
|
693
|
+
}
|
|
673
694
|
return data;
|
|
674
695
|
};
|
|
675
696
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -716,17 +737,19 @@ class BaseService {
|
|
|
716
737
|
},
|
|
717
738
|
]);
|
|
718
739
|
const parseData = (data) => {
|
|
719
|
-
data.data
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
740
|
+
if (data.data) {
|
|
741
|
+
data.data.updated_at = data.data.updated_at
|
|
742
|
+
? new Date(data.data.updated_at)
|
|
743
|
+
: null;
|
|
744
|
+
data.data.items = data.data.items
|
|
745
|
+
? data.data.items.map((logItem) => ({
|
|
746
|
+
...logItem,
|
|
747
|
+
block_signed_at: logItem.block_signed_at
|
|
748
|
+
? new Date(logItem.block_signed_at)
|
|
749
|
+
: null,
|
|
750
|
+
}))
|
|
751
|
+
: null;
|
|
752
|
+
}
|
|
730
753
|
return data;
|
|
731
754
|
};
|
|
732
755
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -764,17 +787,19 @@ class BaseService {
|
|
|
764
787
|
},
|
|
765
788
|
]);
|
|
766
789
|
const parseData = (data) => {
|
|
767
|
-
data.data
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
790
|
+
if (data.data) {
|
|
791
|
+
data.data.updated_at = data.data.updated_at
|
|
792
|
+
? new Date(data.data.updated_at)
|
|
793
|
+
: null;
|
|
794
|
+
data.data.items = data.data.items
|
|
795
|
+
? data.data.items.map((logItem) => ({
|
|
796
|
+
...logItem,
|
|
797
|
+
block_signed_at: logItem.block_signed_at
|
|
798
|
+
? new Date(logItem.block_signed_at)
|
|
799
|
+
: null,
|
|
800
|
+
}))
|
|
801
|
+
: null;
|
|
802
|
+
}
|
|
778
803
|
return data;
|
|
779
804
|
};
|
|
780
805
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -814,17 +839,19 @@ class BaseService {
|
|
|
814
839
|
},
|
|
815
840
|
]);
|
|
816
841
|
const parseData = (data) => {
|
|
817
|
-
data.data
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
842
|
+
if (data.data) {
|
|
843
|
+
data.data.updated_at = data.data.updated_at
|
|
844
|
+
? new Date(data.data.updated_at)
|
|
845
|
+
: null;
|
|
846
|
+
data.data.items = data.data.items
|
|
847
|
+
? data.data.items.map((logItem) => ({
|
|
848
|
+
...logItem,
|
|
849
|
+
block_signed_at: logItem.block_signed_at
|
|
850
|
+
? new Date(logItem.block_signed_at)
|
|
851
|
+
: null,
|
|
852
|
+
}))
|
|
853
|
+
: null;
|
|
854
|
+
}
|
|
828
855
|
return data;
|
|
829
856
|
};
|
|
830
857
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -867,17 +894,19 @@ class BaseService {
|
|
|
867
894
|
},
|
|
868
895
|
]);
|
|
869
896
|
const parseData = (data) => {
|
|
870
|
-
data.data
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
897
|
+
if (data.data) {
|
|
898
|
+
data.data.updated_at = data.data.updated_at
|
|
899
|
+
? new Date(data.data.updated_at)
|
|
900
|
+
: null;
|
|
901
|
+
data.data.items = data.data.items
|
|
902
|
+
? data.data.items.map((logItem) => ({
|
|
903
|
+
...logItem,
|
|
904
|
+
block_signed_at: logItem.block_signed_at
|
|
905
|
+
? new Date(logItem.block_signed_at)
|
|
906
|
+
: null,
|
|
907
|
+
}))
|
|
908
|
+
: null;
|
|
909
|
+
}
|
|
881
910
|
return data;
|
|
882
911
|
};
|
|
883
912
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -922,17 +951,19 @@ class BaseService {
|
|
|
922
951
|
},
|
|
923
952
|
]);
|
|
924
953
|
const parseData = (data) => {
|
|
925
|
-
data.data
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
954
|
+
if (data.data) {
|
|
955
|
+
data.data.updated_at = data.data.updated_at
|
|
956
|
+
? new Date(data.data.updated_at)
|
|
957
|
+
: null;
|
|
958
|
+
data.data.items = data.data.items
|
|
959
|
+
? data.data.items.map((logItem) => ({
|
|
960
|
+
...logItem,
|
|
961
|
+
block_signed_at: logItem.block_signed_at
|
|
962
|
+
? new Date(logItem.block_signed_at)
|
|
963
|
+
: null,
|
|
964
|
+
}))
|
|
965
|
+
: null;
|
|
966
|
+
}
|
|
936
967
|
return data;
|
|
937
968
|
};
|
|
938
969
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -946,15 +977,17 @@ class BaseService {
|
|
|
946
977
|
async getAllChains() {
|
|
947
978
|
const endpoint = endpointGenerator(`chains`);
|
|
948
979
|
const parseData = (data) => {
|
|
949
|
-
data.data
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
980
|
+
if (data.data) {
|
|
981
|
+
data.data.updated_at = data.data.updated_at
|
|
982
|
+
? new Date(data.data.updated_at)
|
|
983
|
+
: null;
|
|
984
|
+
data.data.items = data.data.items
|
|
985
|
+
? data.data.items.map((chainItem) => ({
|
|
986
|
+
...chainItem,
|
|
987
|
+
chain_id: chainItem.chain_id ? +chainItem.chain_id : null,
|
|
988
|
+
}))
|
|
989
|
+
: null;
|
|
990
|
+
}
|
|
958
991
|
return data;
|
|
959
992
|
};
|
|
960
993
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -968,15 +1001,17 @@ class BaseService {
|
|
|
968
1001
|
async getAllChainStatus() {
|
|
969
1002
|
const endpoint = endpointGenerator(`chains/status`);
|
|
970
1003
|
const parseData = (data) => {
|
|
971
|
-
data.data
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1004
|
+
if (data.data) {
|
|
1005
|
+
data.data.updated_at = data.data.updated_at
|
|
1006
|
+
? new Date(data.data.updated_at)
|
|
1007
|
+
: null;
|
|
1008
|
+
data.data.items = data.data.items
|
|
1009
|
+
? data.data.items.map((chainItem) => ({
|
|
1010
|
+
...chainItem,
|
|
1011
|
+
chain_id: chainItem.chain_id ? +chainItem.chain_id : null,
|
|
1012
|
+
}))
|
|
1013
|
+
: null;
|
|
1014
|
+
}
|
|
980
1015
|
return data;
|
|
981
1016
|
};
|
|
982
1017
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -998,17 +1033,19 @@ class BaseService {
|
|
|
998
1033
|
},
|
|
999
1034
|
]);
|
|
1000
1035
|
const parseData = (data) => {
|
|
1001
|
-
data.data
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1036
|
+
if (data.data) {
|
|
1037
|
+
data.data.updated_at = data.data.updated_at
|
|
1038
|
+
? new Date(data.data.updated_at)
|
|
1039
|
+
: null;
|
|
1040
|
+
data.data.items = data.data.items
|
|
1041
|
+
? data.data.items.map((activityItem) => ({
|
|
1042
|
+
...activityItem,
|
|
1043
|
+
last_seen_at: activityItem.last_seen_at
|
|
1044
|
+
? new Date(activityItem.last_seen_at)
|
|
1045
|
+
: null,
|
|
1046
|
+
}))
|
|
1047
|
+
: null;
|
|
1048
|
+
}
|
|
1012
1049
|
return data;
|
|
1013
1050
|
};
|
|
1014
1051
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1029,10 +1066,12 @@ class BaseService {
|
|
|
1029
1066
|
},
|
|
1030
1067
|
]);
|
|
1031
1068
|
const parseData = (data) => {
|
|
1032
|
-
data.data
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1069
|
+
if (data.data) {
|
|
1070
|
+
data.data.updated_at = data.data.updated_at
|
|
1071
|
+
? new Date(data.data.updated_at)
|
|
1072
|
+
: null;
|
|
1073
|
+
data.data.base_fee = bigIntParser(data.data.base_fee);
|
|
1074
|
+
}
|
|
1036
1075
|
return data;
|
|
1037
1076
|
};
|
|
1038
1077
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1040,7 +1079,7 @@ class BaseService {
|
|
|
1040
1079
|
}
|
|
1041
1080
|
|
|
1042
1081
|
/**
|
|
1043
|
-
*
|
|
1082
|
+
* NFTs API
|
|
1044
1083
|
*
|
|
1045
1084
|
*/
|
|
1046
1085
|
class NftService {
|
|
@@ -1074,17 +1113,19 @@ class NftService {
|
|
|
1074
1113
|
},
|
|
1075
1114
|
]);
|
|
1076
1115
|
const parseData = (data) => {
|
|
1077
|
-
data.data
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1116
|
+
if (data.data) {
|
|
1117
|
+
data.data.updated_at = data.data.updated_at
|
|
1118
|
+
? new Date(data.data.updated_at)
|
|
1119
|
+
: null;
|
|
1120
|
+
data.data.items = data.data.items
|
|
1121
|
+
? data.data.items.map((collectionItem) => ({
|
|
1122
|
+
...collectionItem,
|
|
1123
|
+
last_scraped_at: collectionItem.last_scraped_at
|
|
1124
|
+
? new Date(collectionItem.last_scraped_at)
|
|
1125
|
+
: null,
|
|
1126
|
+
}))
|
|
1127
|
+
: null;
|
|
1128
|
+
}
|
|
1088
1129
|
return data;
|
|
1089
1130
|
};
|
|
1090
1131
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -1118,17 +1159,19 @@ class NftService {
|
|
|
1118
1159
|
},
|
|
1119
1160
|
]);
|
|
1120
1161
|
const parseData = (data) => {
|
|
1121
|
-
data.data
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1162
|
+
if (data.data) {
|
|
1163
|
+
data.data.updated_at = data.data.updated_at
|
|
1164
|
+
? new Date(data.data.updated_at)
|
|
1165
|
+
: null;
|
|
1166
|
+
data.data.items = data.data.items
|
|
1167
|
+
? data.data.items.map((collectionItem) => ({
|
|
1168
|
+
...collectionItem,
|
|
1169
|
+
last_scraped_at: collectionItem.last_scraped_at
|
|
1170
|
+
? new Date(collectionItem.last_scraped_at)
|
|
1171
|
+
: null,
|
|
1172
|
+
}))
|
|
1173
|
+
: null;
|
|
1174
|
+
}
|
|
1132
1175
|
return data;
|
|
1133
1176
|
};
|
|
1134
1177
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1161,22 +1204,24 @@ class NftService {
|
|
|
1161
1204
|
},
|
|
1162
1205
|
]);
|
|
1163
1206
|
const parseData = (data) => {
|
|
1164
|
-
data.data
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1207
|
+
if (data.data) {
|
|
1208
|
+
data.data.updated_at = data.data.updated_at
|
|
1209
|
+
? new Date(data.data.updated_at)
|
|
1210
|
+
: null;
|
|
1211
|
+
data.data.items = data.data.items
|
|
1212
|
+
? data.data.items.map((balanceItem) => ({
|
|
1213
|
+
...balanceItem,
|
|
1214
|
+
balance: bigIntParser(balanceItem.balance),
|
|
1215
|
+
balance_24h: bigIntParser(balanceItem.balance_24h),
|
|
1216
|
+
nft_data: balanceItem.nft_data
|
|
1217
|
+
? balanceItem.nft_data.map((nftItem) => ({
|
|
1218
|
+
...nftItem,
|
|
1219
|
+
token_id: bigIntParser(nftItem.token_id),
|
|
1220
|
+
}))
|
|
1221
|
+
: null,
|
|
1222
|
+
}))
|
|
1223
|
+
: null;
|
|
1224
|
+
}
|
|
1180
1225
|
return data;
|
|
1181
1226
|
};
|
|
1182
1227
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1224,18 +1269,20 @@ class NftService {
|
|
|
1224
1269
|
},
|
|
1225
1270
|
]);
|
|
1226
1271
|
const parseData = (data) => {
|
|
1227
|
-
data.data
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1272
|
+
if (data.data) {
|
|
1273
|
+
data.data.updated_at = data.data.updated_at
|
|
1274
|
+
? new Date(data.data.updated_at)
|
|
1275
|
+
: null;
|
|
1276
|
+
data.data.items = data.data.items
|
|
1277
|
+
? data.data.items.map((tokenItem) => ({
|
|
1278
|
+
...tokenItem,
|
|
1279
|
+
nft_data: {
|
|
1280
|
+
...tokenItem.nft_data,
|
|
1281
|
+
token_id: bigIntParser(tokenItem.nft_data?.token_id),
|
|
1282
|
+
},
|
|
1283
|
+
}))
|
|
1284
|
+
: null;
|
|
1285
|
+
}
|
|
1239
1286
|
return data;
|
|
1240
1287
|
};
|
|
1241
1288
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "pagination")) {
|
|
@@ -1285,18 +1332,20 @@ class NftService {
|
|
|
1285
1332
|
},
|
|
1286
1333
|
]);
|
|
1287
1334
|
const parseData = (data) => {
|
|
1288
|
-
data.data
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1335
|
+
if (data.data) {
|
|
1336
|
+
data.data.updated_at = data.data.updated_at
|
|
1337
|
+
? new Date(data.data.updated_at)
|
|
1338
|
+
: null;
|
|
1339
|
+
data.data.items = data.data.items
|
|
1340
|
+
? data.data.items.map((tokenItem) => ({
|
|
1341
|
+
...tokenItem,
|
|
1342
|
+
nft_data: {
|
|
1343
|
+
...tokenItem.nft_data,
|
|
1344
|
+
token_id: bigIntParser(tokenItem.nft_data?.token_id),
|
|
1345
|
+
},
|
|
1346
|
+
}))
|
|
1347
|
+
: null;
|
|
1348
|
+
}
|
|
1300
1349
|
return data;
|
|
1301
1350
|
};
|
|
1302
1351
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1325,18 +1374,20 @@ class NftService {
|
|
|
1325
1374
|
},
|
|
1326
1375
|
]);
|
|
1327
1376
|
const parseData = (data) => {
|
|
1328
|
-
data.data
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1377
|
+
if (data.data) {
|
|
1378
|
+
data.data.updated_at = data.data.updated_at
|
|
1379
|
+
? new Date(data.data.updated_at)
|
|
1380
|
+
: null;
|
|
1381
|
+
data.data.items = data.data.items
|
|
1382
|
+
? data.data.items.map((tokenItem) => ({
|
|
1383
|
+
...tokenItem,
|
|
1384
|
+
nft_data: {
|
|
1385
|
+
...tokenItem.nft_data,
|
|
1386
|
+
token_id: bigIntParser(tokenItem.nft_data?.token_id),
|
|
1387
|
+
},
|
|
1388
|
+
}))
|
|
1389
|
+
: null;
|
|
1390
|
+
}
|
|
1340
1391
|
return data;
|
|
1341
1392
|
};
|
|
1342
1393
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1360,32 +1411,34 @@ class NftService {
|
|
|
1360
1411
|
},
|
|
1361
1412
|
]);
|
|
1362
1413
|
const parseData = (data) => {
|
|
1363
|
-
data.data
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1414
|
+
if (data.data) {
|
|
1415
|
+
data.data.updated_at = data.data.updated_at
|
|
1416
|
+
? new Date(data.data.updated_at)
|
|
1417
|
+
: null;
|
|
1418
|
+
data.data.items = data.data.items
|
|
1419
|
+
? data.data.items.map((nftItem) => ({
|
|
1420
|
+
...nftItem,
|
|
1421
|
+
nft_transactions: nftItem.nft_transactions
|
|
1422
|
+
? nftItem.nft_transactions.map((txItem) => ({
|
|
1423
|
+
...txItem,
|
|
1424
|
+
block_signed_at: txItem.block_signed_at
|
|
1425
|
+
? new Date(txItem.block_signed_at)
|
|
1426
|
+
: null,
|
|
1427
|
+
value: bigIntParser(txItem.value),
|
|
1428
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1429
|
+
log_events: txItem.log_events
|
|
1430
|
+
? txItem.log_events.map((logItem) => ({
|
|
1431
|
+
...logItem,
|
|
1432
|
+
block_signed_at: logItem.block_signed_at
|
|
1433
|
+
? new Date(logItem.block_signed_at)
|
|
1434
|
+
: null,
|
|
1435
|
+
}))
|
|
1436
|
+
: null,
|
|
1437
|
+
}))
|
|
1438
|
+
: null,
|
|
1439
|
+
}))
|
|
1440
|
+
: null;
|
|
1441
|
+
}
|
|
1389
1442
|
return data;
|
|
1390
1443
|
};
|
|
1391
1444
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1401,9 +1454,11 @@ class NftService {
|
|
|
1401
1454
|
async getTraitsForCollection(chainName, collectionContract) {
|
|
1402
1455
|
const endpoint = endpointGenerator(`${chainName}/nft/${collectionContract}/traits`, []);
|
|
1403
1456
|
const parseData = (data) => {
|
|
1404
|
-
data.data
|
|
1405
|
-
|
|
1406
|
-
|
|
1457
|
+
if (data.data) {
|
|
1458
|
+
data.data.updated_at = data.data.updated_at
|
|
1459
|
+
? new Date(data.data.updated_at)
|
|
1460
|
+
: null;
|
|
1461
|
+
}
|
|
1407
1462
|
return data;
|
|
1408
1463
|
};
|
|
1409
1464
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1420,9 +1475,11 @@ class NftService {
|
|
|
1420
1475
|
async getAttributesForTraitInCollection(chainName, collectionContract, trait) {
|
|
1421
1476
|
const endpoint = endpointGenerator(`${chainName}/nft/${collectionContract}/traits/${trait}/attributes`, []);
|
|
1422
1477
|
const parseData = (data) => {
|
|
1423
|
-
data.data
|
|
1424
|
-
|
|
1425
|
-
|
|
1478
|
+
if (data.data) {
|
|
1479
|
+
data.data.updated_at = data.data.updated_at
|
|
1480
|
+
? new Date(data.data.updated_at)
|
|
1481
|
+
: null;
|
|
1482
|
+
}
|
|
1426
1483
|
return data;
|
|
1427
1484
|
};
|
|
1428
1485
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1438,9 +1495,11 @@ class NftService {
|
|
|
1438
1495
|
async getCollectionTraitsSummary(chainName, collectionContract) {
|
|
1439
1496
|
const endpoint = endpointGenerator(`${chainName}/nft/${collectionContract}/traits_summary`, []);
|
|
1440
1497
|
const parseData = (data) => {
|
|
1441
|
-
data.data
|
|
1442
|
-
|
|
1443
|
-
|
|
1498
|
+
if (data.data) {
|
|
1499
|
+
data.data.updated_at = data.data.updated_at
|
|
1500
|
+
? new Date(data.data.updated_at)
|
|
1501
|
+
: null;
|
|
1502
|
+
}
|
|
1444
1503
|
return data;
|
|
1445
1504
|
};
|
|
1446
1505
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1469,21 +1528,23 @@ class NftService {
|
|
|
1469
1528
|
},
|
|
1470
1529
|
]);
|
|
1471
1530
|
const parseData = (data) => {
|
|
1472
|
-
data.data
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1531
|
+
if (data.data) {
|
|
1532
|
+
data.data.updated_at = data.data.updated_at
|
|
1533
|
+
? new Date(data.data.updated_at)
|
|
1534
|
+
: null;
|
|
1535
|
+
data.data.items = data.data.items
|
|
1536
|
+
? data.data.items.map((nftItem) => ({
|
|
1537
|
+
...nftItem,
|
|
1538
|
+
balance: bigIntParser(nftItem.balance),
|
|
1539
|
+
balance_24h: bigIntParser(nftItem.balance_24h),
|
|
1540
|
+
token_id: bigIntParser(nftItem.token_id),
|
|
1541
|
+
nft_data: {
|
|
1542
|
+
...nftItem.nft_data,
|
|
1543
|
+
token_id: bigIntParser(nftItem.nft_data?.token_id),
|
|
1544
|
+
},
|
|
1545
|
+
}))
|
|
1546
|
+
: null;
|
|
1547
|
+
}
|
|
1487
1548
|
return data;
|
|
1488
1549
|
};
|
|
1489
1550
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1501,20 +1562,22 @@ class NftService {
|
|
|
1501
1562
|
async checkOwnershipInNftForSpecificTokenId(chainName, walletAddress, collectionContract, tokenId) {
|
|
1502
1563
|
const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}`, []);
|
|
1503
1564
|
const parseData = (data) => {
|
|
1504
|
-
data.data
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1565
|
+
if (data.data) {
|
|
1566
|
+
data.data.updated_at = data.data.updated_at
|
|
1567
|
+
? new Date(data.data.updated_at)
|
|
1568
|
+
: null;
|
|
1569
|
+
data.data.items = data.data.items
|
|
1570
|
+
? data.data.items.map((balanceItem) => ({
|
|
1571
|
+
...balanceItem,
|
|
1572
|
+
balance: bigIntParser(balanceItem.balance),
|
|
1573
|
+
balance_24h: bigIntParser(balanceItem.balance_24h),
|
|
1574
|
+
token_id: bigIntParser(balanceItem.token_id),
|
|
1575
|
+
last_transfered_at: balanceItem.last_transfered_at
|
|
1576
|
+
? new Date(balanceItem.last_transfered_at)
|
|
1577
|
+
: null,
|
|
1578
|
+
}))
|
|
1579
|
+
: null;
|
|
1580
|
+
}
|
|
1518
1581
|
return data;
|
|
1519
1582
|
};
|
|
1520
1583
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1522,7 +1585,7 @@ class NftService {
|
|
|
1522
1585
|
}
|
|
1523
1586
|
|
|
1524
1587
|
/**
|
|
1525
|
-
* Pricing
|
|
1588
|
+
* Pricing API
|
|
1526
1589
|
*
|
|
1527
1590
|
*/
|
|
1528
1591
|
class PricingService {
|
|
@@ -1558,17 +1621,19 @@ class PricingService {
|
|
|
1558
1621
|
},
|
|
1559
1622
|
]);
|
|
1560
1623
|
const parseData = (data) => {
|
|
1561
|
-
data.data
|
|
1562
|
-
dataItem
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1624
|
+
if (data.data) {
|
|
1625
|
+
data.data.forEach((dataItem) => {
|
|
1626
|
+
dataItem.update_at = dataItem.update_at
|
|
1627
|
+
? new Date(dataItem.update_at)
|
|
1628
|
+
: null;
|
|
1629
|
+
dataItem.items = dataItem.items
|
|
1630
|
+
? dataItem.items.map((priceItem) => ({
|
|
1631
|
+
...priceItem,
|
|
1632
|
+
date: priceItem.date ? new Date(priceItem.date) : null,
|
|
1633
|
+
}))
|
|
1634
|
+
: null;
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1572
1637
|
return data;
|
|
1573
1638
|
};
|
|
1574
1639
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1594,23 +1659,25 @@ class SecurityService {
|
|
|
1594
1659
|
async getApprovals(chainName, walletAddress) {
|
|
1595
1660
|
const endpoint = endpointGenerator(`${chainName}/approvals/${walletAddress}`, []);
|
|
1596
1661
|
const parseData = (data) => {
|
|
1597
|
-
data.data
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1662
|
+
if (data.data) {
|
|
1663
|
+
data.data.updated_at = data.data.updated_at
|
|
1664
|
+
? new Date(data.data.updated_at)
|
|
1665
|
+
: null;
|
|
1666
|
+
data.data.items = data.data.items
|
|
1667
|
+
? data.data.items.map((approvalItem) => ({
|
|
1668
|
+
...approvalItem,
|
|
1669
|
+
balance: bigIntParser(approvalItem.balance),
|
|
1670
|
+
spenders: approvalItem.spenders
|
|
1671
|
+
? approvalItem.spenders.map((spenderItem) => ({
|
|
1672
|
+
...spenderItem,
|
|
1673
|
+
block_signed_at: spenderItem.block_signed_at
|
|
1674
|
+
? new Date(spenderItem.block_signed_at)
|
|
1675
|
+
: null,
|
|
1676
|
+
}))
|
|
1677
|
+
: null,
|
|
1678
|
+
}))
|
|
1679
|
+
: null;
|
|
1680
|
+
}
|
|
1614
1681
|
return data;
|
|
1615
1682
|
};
|
|
1616
1683
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1625,27 +1692,33 @@ class SecurityService {
|
|
|
1625
1692
|
async getNftApprovals(chainName, walletAddress) {
|
|
1626
1693
|
const endpoint = endpointGenerator(`${chainName}/nft/approvals/${walletAddress}`, []);
|
|
1627
1694
|
const parseData = (data) => {
|
|
1628
|
-
data.data
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1695
|
+
if (data.data) {
|
|
1696
|
+
data.data.updated_at = data.data.updated_at
|
|
1697
|
+
? new Date(data.data.updated_at)
|
|
1698
|
+
: null;
|
|
1699
|
+
data.data.items = data.data.items
|
|
1700
|
+
? data.data.items.map((approvalItem) => ({
|
|
1701
|
+
...approvalItem,
|
|
1702
|
+
token_balances: approvalItem.token_balances
|
|
1703
|
+
? approvalItem.token_balances.map((balanceItem) => ({
|
|
1704
|
+
...balanceItem,
|
|
1705
|
+
token_balance: bigIntParser(balanceItem.token_balance),
|
|
1706
|
+
token_id: bigIntParser(balanceItem.token_id),
|
|
1707
|
+
}))
|
|
1708
|
+
: null,
|
|
1709
|
+
}))
|
|
1710
|
+
: null;
|
|
1711
|
+
}
|
|
1643
1712
|
return data;
|
|
1644
1713
|
};
|
|
1645
1714
|
return await this.execution.execute(endpoint, parseData);
|
|
1646
1715
|
}
|
|
1647
1716
|
}
|
|
1648
1717
|
|
|
1718
|
+
/**
|
|
1719
|
+
* Transactions API
|
|
1720
|
+
*
|
|
1721
|
+
*/
|
|
1649
1722
|
class TransactionService {
|
|
1650
1723
|
constructor(execution) {
|
|
1651
1724
|
this.execution = execution;
|
|
@@ -1659,9 +1732,6 @@ class TransactionService {
|
|
|
1659
1732
|
* @param {GetTransactionQueryParamOpts} queryParamOpts
|
|
1660
1733
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1661
1734
|
* - `noLogs`: Omit log events.
|
|
1662
|
-
* - `withDex`: Decoded DEX details including protocol (e.g. Uniswap), event (e.g 'add_liquidity') and tokens involved with historical prices. Additional 0.05 credits charged if data available.
|
|
1663
|
-
* - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
|
|
1664
|
-
* - `withLending`: Decoded lending details including protocol (e.g. Aave), event (e.g. 'deposit') and tokens involved with prices. Additional 0.05 credits charged if data available.
|
|
1665
1735
|
* - `withSafe`: Include safe details.
|
|
1666
1736
|
*
|
|
1667
1737
|
*/
|
|
@@ -1675,41 +1745,31 @@ class TransactionService {
|
|
|
1675
1745
|
key: "no-logs",
|
|
1676
1746
|
value: queryParamOpts?.noLogs,
|
|
1677
1747
|
},
|
|
1678
|
-
{
|
|
1679
|
-
key: "with-dex",
|
|
1680
|
-
value: queryParamOpts?.withDex,
|
|
1681
|
-
},
|
|
1682
|
-
{
|
|
1683
|
-
key: "with-nft-sales",
|
|
1684
|
-
value: queryParamOpts?.withNftSales,
|
|
1685
|
-
},
|
|
1686
|
-
{
|
|
1687
|
-
key: "with-lending",
|
|
1688
|
-
value: queryParamOpts?.withLending,
|
|
1689
|
-
},
|
|
1690
1748
|
]);
|
|
1691
1749
|
const parseData = (data) => {
|
|
1692
|
-
data.data
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1750
|
+
if (data.data) {
|
|
1751
|
+
data.data.updated_at = data.data.updated_at
|
|
1752
|
+
? new Date(data.data.updated_at)
|
|
1753
|
+
: null;
|
|
1754
|
+
data.data.items = data.data.items
|
|
1755
|
+
? data.data.items.map((txItem) => ({
|
|
1756
|
+
...txItem,
|
|
1757
|
+
value: bigIntParser(txItem.value),
|
|
1758
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1759
|
+
block_signed_at: txItem.block_signed_at
|
|
1760
|
+
? new Date(txItem.block_signed_at)
|
|
1761
|
+
: null,
|
|
1762
|
+
log_events: txItem.log_events
|
|
1763
|
+
? txItem.log_events.map((logItem) => ({
|
|
1764
|
+
...logItem,
|
|
1765
|
+
block_signed_at: logItem.block_signed_at
|
|
1766
|
+
? new Date(logItem.block_signed_at)
|
|
1767
|
+
: null,
|
|
1768
|
+
}))
|
|
1769
|
+
: null,
|
|
1770
|
+
}))
|
|
1771
|
+
: null;
|
|
1772
|
+
}
|
|
1713
1773
|
return data;
|
|
1714
1774
|
};
|
|
1715
1775
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1747,27 +1807,29 @@ class TransactionService {
|
|
|
1747
1807
|
},
|
|
1748
1808
|
]);
|
|
1749
1809
|
const parseData = (data) => {
|
|
1750
|
-
data.data
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1810
|
+
if (data.data) {
|
|
1811
|
+
data.data.updated_at = data.data.updated_at
|
|
1812
|
+
? new Date(data.data.updated_at)
|
|
1813
|
+
: null;
|
|
1814
|
+
data.data.items = data.data.items
|
|
1815
|
+
? data.data.items.map((txItem) => ({
|
|
1816
|
+
...txItem,
|
|
1817
|
+
value: bigIntParser(txItem.value),
|
|
1818
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1819
|
+
block_signed_at: txItem.block_signed_at
|
|
1820
|
+
? new Date(txItem.block_signed_at)
|
|
1821
|
+
: null,
|
|
1822
|
+
log_events: txItem.log_events
|
|
1823
|
+
? txItem.log_events.map((logItem) => ({
|
|
1824
|
+
...logItem,
|
|
1825
|
+
block_signed_at: logItem.block_signed_at
|
|
1826
|
+
? new Date(logItem.block_signed_at)
|
|
1827
|
+
: null,
|
|
1828
|
+
}))
|
|
1829
|
+
: null,
|
|
1830
|
+
}))
|
|
1831
|
+
: null;
|
|
1832
|
+
}
|
|
1771
1833
|
return data;
|
|
1772
1834
|
};
|
|
1773
1835
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "links")) {
|
|
@@ -1808,33 +1870,35 @@ class TransactionService {
|
|
|
1808
1870
|
];
|
|
1809
1871
|
const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3`, searchParams);
|
|
1810
1872
|
const parseData = (data) => {
|
|
1811
|
-
data.data
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1873
|
+
if (data.data) {
|
|
1874
|
+
data.data.prev = data.data?.links?.prev
|
|
1875
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
1876
|
+
: null;
|
|
1877
|
+
data.data.next = data.data?.links?.next
|
|
1878
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
1879
|
+
: null;
|
|
1880
|
+
data.data.updated_at = data.data.updated_at
|
|
1881
|
+
? new Date(data.data.updated_at)
|
|
1882
|
+
: null;
|
|
1883
|
+
data.data.items = data.data.items
|
|
1884
|
+
? data.data.items.map((txItem) => ({
|
|
1885
|
+
...txItem,
|
|
1886
|
+
value: bigIntParser(txItem.value),
|
|
1887
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1888
|
+
block_signed_at: txItem.block_signed_at
|
|
1889
|
+
? new Date(txItem.block_signed_at)
|
|
1890
|
+
: null,
|
|
1891
|
+
log_events: txItem.log_events
|
|
1892
|
+
? txItem.log_events.map((logItem) => ({
|
|
1893
|
+
...logItem,
|
|
1894
|
+
block_signed_at: logItem.block_signed_at
|
|
1895
|
+
? new Date(logItem.block_signed_at)
|
|
1896
|
+
: null,
|
|
1897
|
+
}))
|
|
1898
|
+
: null,
|
|
1899
|
+
}))
|
|
1900
|
+
: null;
|
|
1901
|
+
}
|
|
1838
1902
|
return data;
|
|
1839
1903
|
};
|
|
1840
1904
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1867,27 +1931,29 @@ class TransactionService {
|
|
|
1867
1931
|
},
|
|
1868
1932
|
]);
|
|
1869
1933
|
const parseData = (data) => {
|
|
1870
|
-
data.data
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1934
|
+
if (data.data) {
|
|
1935
|
+
data.data.updated_at = data.data.updated_at
|
|
1936
|
+
? new Date(data.data.updated_at)
|
|
1937
|
+
: null;
|
|
1938
|
+
data.data.items = data.data.items
|
|
1939
|
+
? data.data.items.map((txItem) => ({
|
|
1940
|
+
...txItem,
|
|
1941
|
+
value: bigIntParser(txItem.value),
|
|
1942
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1943
|
+
block_signed_at: txItem.block_signed_at
|
|
1944
|
+
? new Date(txItem.block_signed_at)
|
|
1945
|
+
: null,
|
|
1946
|
+
log_events: txItem.log_events
|
|
1947
|
+
? txItem.log_events.map((logItem) => ({
|
|
1948
|
+
...logItem,
|
|
1949
|
+
block_signed_at: logItem.block_signed_at
|
|
1950
|
+
? new Date(logItem.block_signed_at)
|
|
1951
|
+
: null,
|
|
1952
|
+
}))
|
|
1953
|
+
: null,
|
|
1954
|
+
}))
|
|
1955
|
+
: null;
|
|
1956
|
+
}
|
|
1891
1957
|
return data;
|
|
1892
1958
|
};
|
|
1893
1959
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1915,33 +1981,35 @@ class TransactionService {
|
|
|
1915
1981
|
},
|
|
1916
1982
|
]);
|
|
1917
1983
|
const parseData = (data) => {
|
|
1918
|
-
data.data
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1984
|
+
if (data.data) {
|
|
1985
|
+
data.data.updated_at = data.data.updated_at
|
|
1986
|
+
? new Date(data.data.updated_at)
|
|
1987
|
+
: null;
|
|
1988
|
+
data.data.items = data.data.items
|
|
1989
|
+
? data.data.items.map((txsItem) => ({
|
|
1990
|
+
...txsItem,
|
|
1991
|
+
earliest_transaction: {
|
|
1992
|
+
...txsItem.earliest_transaction,
|
|
1993
|
+
block_signed_at: txsItem?.earliest_transaction?.block_signed_at
|
|
1994
|
+
? new Date(txsItem.earliest_transaction.block_signed_at)
|
|
1995
|
+
: null,
|
|
1996
|
+
},
|
|
1997
|
+
latest_transaction: {
|
|
1998
|
+
...txsItem.latest_transaction,
|
|
1999
|
+
block_signed_at: txsItem?.latest_transaction?.block_signed_at
|
|
2000
|
+
? new Date(txsItem?.latest_transaction?.block_signed_at)
|
|
2001
|
+
: null,
|
|
2002
|
+
},
|
|
2003
|
+
// ? API vs docs non-consistent
|
|
2004
|
+
// gas_summary: {
|
|
2005
|
+
// ...txsItem.gas_summary,
|
|
2006
|
+
// total_fees_paid: bigIntParser(
|
|
2007
|
+
// txsItem.gas_summary.total_fees_paid
|
|
2008
|
+
// ),
|
|
2009
|
+
// },
|
|
2010
|
+
}))
|
|
2011
|
+
: null;
|
|
2012
|
+
}
|
|
1945
2013
|
return data;
|
|
1946
2014
|
};
|
|
1947
2015
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1979,33 +2047,35 @@ class TransactionService {
|
|
|
1979
2047
|
];
|
|
1980
2048
|
const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3/page/${page}`, searchParams);
|
|
1981
2049
|
const parseData = (data) => {
|
|
1982
|
-
data.data
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2050
|
+
if (data.data) {
|
|
2051
|
+
data.data.prev = data.data?.links?.prev
|
|
2052
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2053
|
+
: null;
|
|
2054
|
+
data.data.next = data.data?.links?.next
|
|
2055
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2056
|
+
: null;
|
|
2057
|
+
data.data.updated_at = data.data.updated_at
|
|
2058
|
+
? new Date(data.data.updated_at)
|
|
2059
|
+
: null;
|
|
2060
|
+
data.data.items = data.data.items
|
|
2061
|
+
? data.data.items.map((txItem) => ({
|
|
2062
|
+
...txItem,
|
|
2063
|
+
value: bigIntParser(txItem.value),
|
|
2064
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2065
|
+
block_signed_at: txItem.block_signed_at
|
|
2066
|
+
? new Date(txItem.block_signed_at)
|
|
2067
|
+
: null,
|
|
2068
|
+
log_events: txItem.log_events
|
|
2069
|
+
? txItem.log_events.map((logItem) => ({
|
|
2070
|
+
...logItem,
|
|
2071
|
+
block_signed_at: logItem.block_signed_at
|
|
2072
|
+
? new Date(logItem.block_signed_at)
|
|
2073
|
+
: null,
|
|
2074
|
+
}))
|
|
2075
|
+
: null,
|
|
2076
|
+
}))
|
|
2077
|
+
: null;
|
|
2078
|
+
}
|
|
2009
2079
|
return data;
|
|
2010
2080
|
};
|
|
2011
2081
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2038,33 +2108,35 @@ class TransactionService {
|
|
|
2038
2108
|
];
|
|
2039
2109
|
const endpoint = endpointGenerator(`${chainName}/bulk/transactions/${walletAddress}/${timeBucket}`, searchParams);
|
|
2040
2110
|
const parseData = (data) => {
|
|
2041
|
-
data.data
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2111
|
+
if (data.data) {
|
|
2112
|
+
data.data.prev = data.data?.links?.prev
|
|
2113
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2114
|
+
: null;
|
|
2115
|
+
data.data.next = data.data?.links?.next
|
|
2116
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2117
|
+
: null;
|
|
2118
|
+
data.data.updated_at = data.data.updated_at
|
|
2119
|
+
? new Date(data.data.updated_at)
|
|
2120
|
+
: null;
|
|
2121
|
+
data.data.items = data.data.items
|
|
2122
|
+
? data.data.items.map((txItem) => ({
|
|
2123
|
+
...txItem,
|
|
2124
|
+
value: bigIntParser(txItem.value),
|
|
2125
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2126
|
+
block_signed_at: txItem.block_signed_at
|
|
2127
|
+
? new Date(txItem.block_signed_at)
|
|
2128
|
+
: null,
|
|
2129
|
+
log_events: txItem.log_events
|
|
2130
|
+
? txItem.log_events.map((logItem) => ({
|
|
2131
|
+
...logItem,
|
|
2132
|
+
block_signed_at: logItem.block_signed_at
|
|
2133
|
+
? new Date(logItem.block_signed_at)
|
|
2134
|
+
: null,
|
|
2135
|
+
}))
|
|
2136
|
+
: null,
|
|
2137
|
+
}))
|
|
2138
|
+
: null;
|
|
2139
|
+
}
|
|
2068
2140
|
return data;
|
|
2069
2141
|
};
|
|
2070
2142
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2099,33 +2171,35 @@ class TransactionService {
|
|
|
2099
2171
|
];
|
|
2100
2172
|
const endpoint = endpointGenerator(`${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}`, searchParams);
|
|
2101
2173
|
const parseData = (data) => {
|
|
2102
|
-
data.data
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2174
|
+
if (data.data) {
|
|
2175
|
+
data.data.prev = data.data?.links?.prev
|
|
2176
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2177
|
+
: null;
|
|
2178
|
+
data.data.next = data.data?.links?.next
|
|
2179
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2180
|
+
: null;
|
|
2181
|
+
data.data.updated_at = data.data.updated_at
|
|
2182
|
+
? new Date(data.data.updated_at)
|
|
2183
|
+
: null;
|
|
2184
|
+
data.data.items = data.data.items
|
|
2185
|
+
? data.data.items.map((txItem) => ({
|
|
2186
|
+
...txItem,
|
|
2187
|
+
value: bigIntParser(txItem.value),
|
|
2188
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2189
|
+
block_signed_at: txItem.block_signed_at
|
|
2190
|
+
? new Date(txItem.block_signed_at)
|
|
2191
|
+
: null,
|
|
2192
|
+
log_events: txItem.log_events
|
|
2193
|
+
? txItem.log_events.map((logItem) => ({
|
|
2194
|
+
...logItem,
|
|
2195
|
+
block_signed_at: logItem.block_signed_at
|
|
2196
|
+
? new Date(logItem.block_signed_at)
|
|
2197
|
+
: null,
|
|
2198
|
+
}))
|
|
2199
|
+
: null,
|
|
2200
|
+
}))
|
|
2201
|
+
: null;
|
|
2202
|
+
}
|
|
2129
2203
|
return data;
|
|
2130
2204
|
};
|
|
2131
2205
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2158,27 +2232,29 @@ class TransactionService {
|
|
|
2158
2232
|
},
|
|
2159
2233
|
]);
|
|
2160
2234
|
const parseData = (data) => {
|
|
2161
|
-
data.data
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2235
|
+
if (data.data) {
|
|
2236
|
+
data.data.updated_at = data.data.updated_at
|
|
2237
|
+
? new Date(data.data.updated_at)
|
|
2238
|
+
: null;
|
|
2239
|
+
data.data.items = data.data.items
|
|
2240
|
+
? data.data.items.map((txItem) => ({
|
|
2241
|
+
...txItem,
|
|
2242
|
+
value: bigIntParser(txItem.value),
|
|
2243
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2244
|
+
block_signed_at: txItem.block_signed_at
|
|
2245
|
+
? new Date(txItem.block_signed_at)
|
|
2246
|
+
: null,
|
|
2247
|
+
log_events: txItem.log_events
|
|
2248
|
+
? txItem.log_events.map((logItem) => ({
|
|
2249
|
+
...logItem,
|
|
2250
|
+
block_signed_at: logItem.block_signed_at
|
|
2251
|
+
? new Date(logItem.block_signed_at)
|
|
2252
|
+
: null,
|
|
2253
|
+
}))
|
|
2254
|
+
: null,
|
|
2255
|
+
}))
|
|
2256
|
+
: null;
|
|
2257
|
+
}
|
|
2182
2258
|
return data;
|
|
2183
2259
|
};
|
|
2184
2260
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2368,7 +2444,7 @@ class Execution {
|
|
|
2368
2444
|
const parsedData = parseData(data);
|
|
2369
2445
|
completed = true;
|
|
2370
2446
|
return {
|
|
2371
|
-
data: parsedData.data
|
|
2447
|
+
data: parsedData.data,
|
|
2372
2448
|
error: false,
|
|
2373
2449
|
error_code: null,
|
|
2374
2450
|
error_message: null,
|
|
@@ -2406,6 +2482,12 @@ class Execution {
|
|
|
2406
2482
|
}
|
|
2407
2483
|
}
|
|
2408
2484
|
}
|
|
2485
|
+
return {
|
|
2486
|
+
data: null,
|
|
2487
|
+
error: true,
|
|
2488
|
+
error_code: 500,
|
|
2489
|
+
error_message: "Internal server error",
|
|
2490
|
+
};
|
|
2409
2491
|
}
|
|
2410
2492
|
}
|
|
2411
2493
|
|
|
@@ -2445,6 +2527,1031 @@ class GoldRushClient {
|
|
|
2445
2527
|
}
|
|
2446
2528
|
}
|
|
2447
2529
|
|
|
2530
|
+
/*
|
|
2531
|
+
* big.js v6.2.1
|
|
2532
|
+
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
|
|
2533
|
+
* Copyright (c) 2022 Michael Mclaughlin
|
|
2534
|
+
* https://github.com/MikeMcl/big.js/LICENCE.md
|
|
2535
|
+
*/
|
|
2536
|
+
|
|
2537
|
+
|
|
2538
|
+
/************************************** EDITABLE DEFAULTS *****************************************/
|
|
2539
|
+
|
|
2540
|
+
|
|
2541
|
+
// The default values below must be integers within the stated ranges.
|
|
2542
|
+
|
|
2543
|
+
/*
|
|
2544
|
+
* The maximum number of decimal places (DP) of the results of operations involving division:
|
|
2545
|
+
* div and sqrt, and pow with negative exponents.
|
|
2546
|
+
*/
|
|
2547
|
+
var DP = 20, // 0 to MAX_DP
|
|
2548
|
+
|
|
2549
|
+
/*
|
|
2550
|
+
* The rounding mode (RM) used when rounding to the above decimal places.
|
|
2551
|
+
*
|
|
2552
|
+
* 0 Towards zero (i.e. truncate, no rounding). (ROUND_DOWN)
|
|
2553
|
+
* 1 To nearest neighbour. If equidistant, round up. (ROUND_HALF_UP)
|
|
2554
|
+
* 2 To nearest neighbour. If equidistant, to even. (ROUND_HALF_EVEN)
|
|
2555
|
+
* 3 Away from zero. (ROUND_UP)
|
|
2556
|
+
*/
|
|
2557
|
+
RM = 1, // 0, 1, 2 or 3
|
|
2558
|
+
|
|
2559
|
+
// The maximum value of DP and Big.DP.
|
|
2560
|
+
MAX_DP = 1E6, // 0 to 1000000
|
|
2561
|
+
|
|
2562
|
+
// The maximum magnitude of the exponent argument to the pow method.
|
|
2563
|
+
MAX_POWER = 1E6, // 1 to 1000000
|
|
2564
|
+
|
|
2565
|
+
/*
|
|
2566
|
+
* The negative exponent (NE) at and beneath which toString returns exponential notation.
|
|
2567
|
+
* (JavaScript numbers: -7)
|
|
2568
|
+
* -1000000 is the minimum recommended exponent value of a Big.
|
|
2569
|
+
*/
|
|
2570
|
+
NE = -7, // 0 to -1000000
|
|
2571
|
+
|
|
2572
|
+
/*
|
|
2573
|
+
* The positive exponent (PE) at and above which toString returns exponential notation.
|
|
2574
|
+
* (JavaScript numbers: 21)
|
|
2575
|
+
* 1000000 is the maximum recommended exponent value of a Big, but this limit is not enforced.
|
|
2576
|
+
*/
|
|
2577
|
+
PE = 21, // 0 to 1000000
|
|
2578
|
+
|
|
2579
|
+
/*
|
|
2580
|
+
* When true, an error will be thrown if a primitive number is passed to the Big constructor,
|
|
2581
|
+
* or if valueOf is called, or if toNumber is called on a Big which cannot be converted to a
|
|
2582
|
+
* primitive number without a loss of precision.
|
|
2583
|
+
*/
|
|
2584
|
+
STRICT = false, // true or false
|
|
2585
|
+
|
|
2586
|
+
|
|
2587
|
+
/**************************************************************************************************/
|
|
2588
|
+
|
|
2589
|
+
|
|
2590
|
+
// Error messages.
|
|
2591
|
+
NAME = '[big.js] ',
|
|
2592
|
+
INVALID = NAME + 'Invalid ',
|
|
2593
|
+
INVALID_DP = INVALID + 'decimal places',
|
|
2594
|
+
INVALID_RM = INVALID + 'rounding mode',
|
|
2595
|
+
DIV_BY_ZERO = NAME + 'Division by zero',
|
|
2596
|
+
|
|
2597
|
+
// The shared prototype object.
|
|
2598
|
+
P = {},
|
|
2599
|
+
UNDEFINED = void 0,
|
|
2600
|
+
NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
2601
|
+
|
|
2602
|
+
|
|
2603
|
+
/*
|
|
2604
|
+
* Create and return a Big constructor.
|
|
2605
|
+
*/
|
|
2606
|
+
function _Big_() {
|
|
2607
|
+
|
|
2608
|
+
/*
|
|
2609
|
+
* The Big constructor and exported function.
|
|
2610
|
+
* Create and return a new instance of a Big number object.
|
|
2611
|
+
*
|
|
2612
|
+
* n {number|string|Big} A numeric value.
|
|
2613
|
+
*/
|
|
2614
|
+
function Big(n) {
|
|
2615
|
+
var x = this;
|
|
2616
|
+
|
|
2617
|
+
// Enable constructor usage without new.
|
|
2618
|
+
if (!(x instanceof Big)) return n === UNDEFINED ? _Big_() : new Big(n);
|
|
2619
|
+
|
|
2620
|
+
// Duplicate.
|
|
2621
|
+
if (n instanceof Big) {
|
|
2622
|
+
x.s = n.s;
|
|
2623
|
+
x.e = n.e;
|
|
2624
|
+
x.c = n.c.slice();
|
|
2625
|
+
} else {
|
|
2626
|
+
if (typeof n !== 'string') {
|
|
2627
|
+
if (Big.strict === true && typeof n !== 'bigint') {
|
|
2628
|
+
throw TypeError(INVALID + 'value');
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
// Minus zero?
|
|
2632
|
+
n = n === 0 && 1 / n < 0 ? '-0' : String(n);
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2635
|
+
parse(x, n);
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
// Retain a reference to this Big constructor.
|
|
2639
|
+
// Shadow Big.prototype.constructor which points to Object.
|
|
2640
|
+
x.constructor = Big;
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
Big.prototype = P;
|
|
2644
|
+
Big.DP = DP;
|
|
2645
|
+
Big.RM = RM;
|
|
2646
|
+
Big.NE = NE;
|
|
2647
|
+
Big.PE = PE;
|
|
2648
|
+
Big.strict = STRICT;
|
|
2649
|
+
Big.roundDown = 0;
|
|
2650
|
+
Big.roundHalfUp = 1;
|
|
2651
|
+
Big.roundHalfEven = 2;
|
|
2652
|
+
Big.roundUp = 3;
|
|
2653
|
+
|
|
2654
|
+
return Big;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
|
|
2658
|
+
/*
|
|
2659
|
+
* Parse the number or string value passed to a Big constructor.
|
|
2660
|
+
*
|
|
2661
|
+
* x {Big} A Big number instance.
|
|
2662
|
+
* n {number|string} A numeric value.
|
|
2663
|
+
*/
|
|
2664
|
+
function parse(x, n) {
|
|
2665
|
+
var e, i, nl;
|
|
2666
|
+
|
|
2667
|
+
if (!NUMERIC.test(n)) {
|
|
2668
|
+
throw Error(INVALID + 'number');
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
// Determine sign.
|
|
2672
|
+
x.s = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1;
|
|
2673
|
+
|
|
2674
|
+
// Decimal point?
|
|
2675
|
+
if ((e = n.indexOf('.')) > -1) n = n.replace('.', '');
|
|
2676
|
+
|
|
2677
|
+
// Exponential form?
|
|
2678
|
+
if ((i = n.search(/e/i)) > 0) {
|
|
2679
|
+
|
|
2680
|
+
// Determine exponent.
|
|
2681
|
+
if (e < 0) e = i;
|
|
2682
|
+
e += +n.slice(i + 1);
|
|
2683
|
+
n = n.substring(0, i);
|
|
2684
|
+
} else if (e < 0) {
|
|
2685
|
+
|
|
2686
|
+
// Integer.
|
|
2687
|
+
e = n.length;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
nl = n.length;
|
|
2691
|
+
|
|
2692
|
+
// Determine leading zeros.
|
|
2693
|
+
for (i = 0; i < nl && n.charAt(i) == '0';) ++i;
|
|
2694
|
+
|
|
2695
|
+
if (i == nl) {
|
|
2696
|
+
|
|
2697
|
+
// Zero.
|
|
2698
|
+
x.c = [x.e = 0];
|
|
2699
|
+
} else {
|
|
2700
|
+
|
|
2701
|
+
// Determine trailing zeros.
|
|
2702
|
+
for (; nl > 0 && n.charAt(--nl) == '0';);
|
|
2703
|
+
x.e = e - i - 1;
|
|
2704
|
+
x.c = [];
|
|
2705
|
+
|
|
2706
|
+
// Convert string to array of digits without leading/trailing zeros.
|
|
2707
|
+
for (e = 0; i <= nl;) x.c[e++] = +n.charAt(i++);
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
return x;
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
|
|
2714
|
+
/*
|
|
2715
|
+
* Round Big x to a maximum of sd significant digits using rounding mode rm.
|
|
2716
|
+
*
|
|
2717
|
+
* x {Big} The Big to round.
|
|
2718
|
+
* sd {number} Significant digits: integer, 0 to MAX_DP inclusive.
|
|
2719
|
+
* rm {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
2720
|
+
* [more] {boolean} Whether the result of division was truncated.
|
|
2721
|
+
*/
|
|
2722
|
+
function round(x, sd, rm, more) {
|
|
2723
|
+
var xc = x.c;
|
|
2724
|
+
|
|
2725
|
+
if (rm === UNDEFINED) rm = x.constructor.RM;
|
|
2726
|
+
if (rm !== 0 && rm !== 1 && rm !== 2 && rm !== 3) {
|
|
2727
|
+
throw Error(INVALID_RM);
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
if (sd < 1) {
|
|
2731
|
+
more =
|
|
2732
|
+
rm === 3 && (more || !!xc[0]) || sd === 0 && (
|
|
2733
|
+
rm === 1 && xc[0] >= 5 ||
|
|
2734
|
+
rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc[1] !== UNDEFINED))
|
|
2735
|
+
);
|
|
2736
|
+
|
|
2737
|
+
xc.length = 1;
|
|
2738
|
+
|
|
2739
|
+
if (more) {
|
|
2740
|
+
|
|
2741
|
+
// 1, 0.1, 0.01, 0.001, 0.0001 etc.
|
|
2742
|
+
x.e = x.e - sd + 1;
|
|
2743
|
+
xc[0] = 1;
|
|
2744
|
+
} else {
|
|
2745
|
+
|
|
2746
|
+
// Zero.
|
|
2747
|
+
xc[0] = x.e = 0;
|
|
2748
|
+
}
|
|
2749
|
+
} else if (sd < xc.length) {
|
|
2750
|
+
|
|
2751
|
+
// xc[sd] is the digit after the digit that may be rounded up.
|
|
2752
|
+
more =
|
|
2753
|
+
rm === 1 && xc[sd] >= 5 ||
|
|
2754
|
+
rm === 2 && (xc[sd] > 5 || xc[sd] === 5 &&
|
|
2755
|
+
(more || xc[sd + 1] !== UNDEFINED || xc[sd - 1] & 1)) ||
|
|
2756
|
+
rm === 3 && (more || !!xc[0]);
|
|
2757
|
+
|
|
2758
|
+
// Remove any digits after the required precision.
|
|
2759
|
+
xc.length = sd;
|
|
2760
|
+
|
|
2761
|
+
// Round up?
|
|
2762
|
+
if (more) {
|
|
2763
|
+
|
|
2764
|
+
// Rounding up may mean the previous digit has to be rounded up.
|
|
2765
|
+
for (; ++xc[--sd] > 9;) {
|
|
2766
|
+
xc[sd] = 0;
|
|
2767
|
+
if (sd === 0) {
|
|
2768
|
+
++x.e;
|
|
2769
|
+
xc.unshift(1);
|
|
2770
|
+
break;
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
// Remove trailing zeros.
|
|
2776
|
+
for (sd = xc.length; !xc[--sd];) xc.pop();
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
return x;
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
|
|
2783
|
+
/*
|
|
2784
|
+
* Return a string representing the value of Big x in normal or exponential notation.
|
|
2785
|
+
* Handles P.toExponential, P.toFixed, P.toJSON, P.toPrecision, P.toString and P.valueOf.
|
|
2786
|
+
*/
|
|
2787
|
+
function stringify(x, doExponential, isNonzero) {
|
|
2788
|
+
var e = x.e,
|
|
2789
|
+
s = x.c.join(''),
|
|
2790
|
+
n = s.length;
|
|
2791
|
+
|
|
2792
|
+
// Exponential notation?
|
|
2793
|
+
if (doExponential) {
|
|
2794
|
+
s = s.charAt(0) + (n > 1 ? '.' + s.slice(1) : '') + (e < 0 ? 'e' : 'e+') + e;
|
|
2795
|
+
|
|
2796
|
+
// Normal notation.
|
|
2797
|
+
} else if (e < 0) {
|
|
2798
|
+
for (; ++e;) s = '0' + s;
|
|
2799
|
+
s = '0.' + s;
|
|
2800
|
+
} else if (e > 0) {
|
|
2801
|
+
if (++e > n) {
|
|
2802
|
+
for (e -= n; e--;) s += '0';
|
|
2803
|
+
} else if (e < n) {
|
|
2804
|
+
s = s.slice(0, e) + '.' + s.slice(e);
|
|
2805
|
+
}
|
|
2806
|
+
} else if (n > 1) {
|
|
2807
|
+
s = s.charAt(0) + '.' + s.slice(1);
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
return x.s < 0 && isNonzero ? '-' + s : s;
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
|
|
2814
|
+
// Prototype/instance methods
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
/*
|
|
2818
|
+
* Return a new Big whose value is the absolute value of this Big.
|
|
2819
|
+
*/
|
|
2820
|
+
P.abs = function () {
|
|
2821
|
+
var x = new this.constructor(this);
|
|
2822
|
+
x.s = 1;
|
|
2823
|
+
return x;
|
|
2824
|
+
};
|
|
2825
|
+
|
|
2826
|
+
|
|
2827
|
+
/*
|
|
2828
|
+
* Return 1 if the value of this Big is greater than the value of Big y,
|
|
2829
|
+
* -1 if the value of this Big is less than the value of Big y, or
|
|
2830
|
+
* 0 if they have the same value.
|
|
2831
|
+
*/
|
|
2832
|
+
P.cmp = function (y) {
|
|
2833
|
+
var isneg,
|
|
2834
|
+
x = this,
|
|
2835
|
+
xc = x.c,
|
|
2836
|
+
yc = (y = new x.constructor(y)).c,
|
|
2837
|
+
i = x.s,
|
|
2838
|
+
j = y.s,
|
|
2839
|
+
k = x.e,
|
|
2840
|
+
l = y.e;
|
|
2841
|
+
|
|
2842
|
+
// Either zero?
|
|
2843
|
+
if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i;
|
|
2844
|
+
|
|
2845
|
+
// Signs differ?
|
|
2846
|
+
if (i != j) return i;
|
|
2847
|
+
|
|
2848
|
+
isneg = i < 0;
|
|
2849
|
+
|
|
2850
|
+
// Compare exponents.
|
|
2851
|
+
if (k != l) return k > l ^ isneg ? 1 : -1;
|
|
2852
|
+
|
|
2853
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
2854
|
+
|
|
2855
|
+
// Compare digit by digit.
|
|
2856
|
+
for (i = -1; ++i < j;) {
|
|
2857
|
+
if (xc[i] != yc[i]) return xc[i] > yc[i] ^ isneg ? 1 : -1;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
// Compare lengths.
|
|
2861
|
+
return k == l ? 0 : k > l ^ isneg ? 1 : -1;
|
|
2862
|
+
};
|
|
2863
|
+
|
|
2864
|
+
|
|
2865
|
+
/*
|
|
2866
|
+
* Return a new Big whose value is the value of this Big divided by the value of Big y, rounded,
|
|
2867
|
+
* if necessary, to a maximum of Big.DP decimal places using rounding mode Big.RM.
|
|
2868
|
+
*/
|
|
2869
|
+
P.div = function (y) {
|
|
2870
|
+
var x = this,
|
|
2871
|
+
Big = x.constructor,
|
|
2872
|
+
a = x.c, // dividend
|
|
2873
|
+
b = (y = new Big(y)).c, // divisor
|
|
2874
|
+
k = x.s == y.s ? 1 : -1,
|
|
2875
|
+
dp = Big.DP;
|
|
2876
|
+
|
|
2877
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
2878
|
+
throw Error(INVALID_DP);
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
// Divisor is zero?
|
|
2882
|
+
if (!b[0]) {
|
|
2883
|
+
throw Error(DIV_BY_ZERO);
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
// Dividend is 0? Return +-0.
|
|
2887
|
+
if (!a[0]) {
|
|
2888
|
+
y.s = k;
|
|
2889
|
+
y.c = [y.e = 0];
|
|
2890
|
+
return y;
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
var bl, bt, n, cmp, ri,
|
|
2894
|
+
bz = b.slice(),
|
|
2895
|
+
ai = bl = b.length,
|
|
2896
|
+
al = a.length,
|
|
2897
|
+
r = a.slice(0, bl), // remainder
|
|
2898
|
+
rl = r.length,
|
|
2899
|
+
q = y, // quotient
|
|
2900
|
+
qc = q.c = [],
|
|
2901
|
+
qi = 0,
|
|
2902
|
+
p = dp + (q.e = x.e - y.e) + 1; // precision of the result
|
|
2903
|
+
|
|
2904
|
+
q.s = k;
|
|
2905
|
+
k = p < 0 ? 0 : p;
|
|
2906
|
+
|
|
2907
|
+
// Create version of divisor with leading zero.
|
|
2908
|
+
bz.unshift(0);
|
|
2909
|
+
|
|
2910
|
+
// Add zeros to make remainder as long as divisor.
|
|
2911
|
+
for (; rl++ < bl;) r.push(0);
|
|
2912
|
+
|
|
2913
|
+
do {
|
|
2914
|
+
|
|
2915
|
+
// n is how many times the divisor goes into current remainder.
|
|
2916
|
+
for (n = 0; n < 10; n++) {
|
|
2917
|
+
|
|
2918
|
+
// Compare divisor and remainder.
|
|
2919
|
+
if (bl != (rl = r.length)) {
|
|
2920
|
+
cmp = bl > rl ? 1 : -1;
|
|
2921
|
+
} else {
|
|
2922
|
+
for (ri = -1, cmp = 0; ++ri < bl;) {
|
|
2923
|
+
if (b[ri] != r[ri]) {
|
|
2924
|
+
cmp = b[ri] > r[ri] ? 1 : -1;
|
|
2925
|
+
break;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
// If divisor < remainder, subtract divisor from remainder.
|
|
2931
|
+
if (cmp < 0) {
|
|
2932
|
+
|
|
2933
|
+
// Remainder can't be more than 1 digit longer than divisor.
|
|
2934
|
+
// Equalise lengths using divisor with extra leading zero?
|
|
2935
|
+
for (bt = rl == bl ? b : bz; rl;) {
|
|
2936
|
+
if (r[--rl] < bt[rl]) {
|
|
2937
|
+
ri = rl;
|
|
2938
|
+
for (; ri && !r[--ri];) r[ri] = 9;
|
|
2939
|
+
--r[ri];
|
|
2940
|
+
r[rl] += 10;
|
|
2941
|
+
}
|
|
2942
|
+
r[rl] -= bt[rl];
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
for (; !r[0];) r.shift();
|
|
2946
|
+
} else {
|
|
2947
|
+
break;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
// Add the digit n to the result array.
|
|
2952
|
+
qc[qi++] = cmp ? n : ++n;
|
|
2953
|
+
|
|
2954
|
+
// Update the remainder.
|
|
2955
|
+
if (r[0] && cmp) r[rl] = a[ai] || 0;
|
|
2956
|
+
else r = [a[ai]];
|
|
2957
|
+
|
|
2958
|
+
} while ((ai++ < al || r[0] !== UNDEFINED) && k--);
|
|
2959
|
+
|
|
2960
|
+
// Leading zero? Do not remove if result is simply zero (qi == 1).
|
|
2961
|
+
if (!qc[0] && qi != 1) {
|
|
2962
|
+
|
|
2963
|
+
// There can't be more than one zero.
|
|
2964
|
+
qc.shift();
|
|
2965
|
+
q.e--;
|
|
2966
|
+
p--;
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
// Round?
|
|
2970
|
+
if (qi > p) round(q, p, Big.RM, r[0] !== UNDEFINED);
|
|
2971
|
+
|
|
2972
|
+
return q;
|
|
2973
|
+
};
|
|
2974
|
+
|
|
2975
|
+
|
|
2976
|
+
/*
|
|
2977
|
+
* Return true if the value of this Big is equal to the value of Big y, otherwise return false.
|
|
2978
|
+
*/
|
|
2979
|
+
P.eq = function (y) {
|
|
2980
|
+
return this.cmp(y) === 0;
|
|
2981
|
+
};
|
|
2982
|
+
|
|
2983
|
+
|
|
2984
|
+
/*
|
|
2985
|
+
* Return true if the value of this Big is greater than the value of Big y, otherwise return
|
|
2986
|
+
* false.
|
|
2987
|
+
*/
|
|
2988
|
+
P.gt = function (y) {
|
|
2989
|
+
return this.cmp(y) > 0;
|
|
2990
|
+
};
|
|
2991
|
+
|
|
2992
|
+
|
|
2993
|
+
/*
|
|
2994
|
+
* Return true if the value of this Big is greater than or equal to the value of Big y, otherwise
|
|
2995
|
+
* return false.
|
|
2996
|
+
*/
|
|
2997
|
+
P.gte = function (y) {
|
|
2998
|
+
return this.cmp(y) > -1;
|
|
2999
|
+
};
|
|
3000
|
+
|
|
3001
|
+
|
|
3002
|
+
/*
|
|
3003
|
+
* Return true if the value of this Big is less than the value of Big y, otherwise return false.
|
|
3004
|
+
*/
|
|
3005
|
+
P.lt = function (y) {
|
|
3006
|
+
return this.cmp(y) < 0;
|
|
3007
|
+
};
|
|
3008
|
+
|
|
3009
|
+
|
|
3010
|
+
/*
|
|
3011
|
+
* Return true if the value of this Big is less than or equal to the value of Big y, otherwise
|
|
3012
|
+
* return false.
|
|
3013
|
+
*/
|
|
3014
|
+
P.lte = function (y) {
|
|
3015
|
+
return this.cmp(y) < 1;
|
|
3016
|
+
};
|
|
3017
|
+
|
|
3018
|
+
|
|
3019
|
+
/*
|
|
3020
|
+
* Return a new Big whose value is the value of this Big minus the value of Big y.
|
|
3021
|
+
*/
|
|
3022
|
+
P.minus = P.sub = function (y) {
|
|
3023
|
+
var i, j, t, xlty,
|
|
3024
|
+
x = this,
|
|
3025
|
+
Big = x.constructor,
|
|
3026
|
+
a = x.s,
|
|
3027
|
+
b = (y = new Big(y)).s;
|
|
3028
|
+
|
|
3029
|
+
// Signs differ?
|
|
3030
|
+
if (a != b) {
|
|
3031
|
+
y.s = -b;
|
|
3032
|
+
return x.plus(y);
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
var xc = x.c.slice(),
|
|
3036
|
+
xe = x.e,
|
|
3037
|
+
yc = y.c,
|
|
3038
|
+
ye = y.e;
|
|
3039
|
+
|
|
3040
|
+
// Either zero?
|
|
3041
|
+
if (!xc[0] || !yc[0]) {
|
|
3042
|
+
if (yc[0]) {
|
|
3043
|
+
y.s = -b;
|
|
3044
|
+
} else if (xc[0]) {
|
|
3045
|
+
y = new Big(x);
|
|
3046
|
+
} else {
|
|
3047
|
+
y.s = 1;
|
|
3048
|
+
}
|
|
3049
|
+
return y;
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
// Determine which is the bigger number. Prepend zeros to equalise exponents.
|
|
3053
|
+
if (a = xe - ye) {
|
|
3054
|
+
|
|
3055
|
+
if (xlty = a < 0) {
|
|
3056
|
+
a = -a;
|
|
3057
|
+
t = xc;
|
|
3058
|
+
} else {
|
|
3059
|
+
ye = xe;
|
|
3060
|
+
t = yc;
|
|
3061
|
+
}
|
|
3062
|
+
|
|
3063
|
+
t.reverse();
|
|
3064
|
+
for (b = a; b--;) t.push(0);
|
|
3065
|
+
t.reverse();
|
|
3066
|
+
} else {
|
|
3067
|
+
|
|
3068
|
+
// Exponents equal. Check digit by digit.
|
|
3069
|
+
j = ((xlty = xc.length < yc.length) ? xc : yc).length;
|
|
3070
|
+
|
|
3071
|
+
for (a = b = 0; b < j; b++) {
|
|
3072
|
+
if (xc[b] != yc[b]) {
|
|
3073
|
+
xlty = xc[b] < yc[b];
|
|
3074
|
+
break;
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
// x < y? Point xc to the array of the bigger number.
|
|
3080
|
+
if (xlty) {
|
|
3081
|
+
t = xc;
|
|
3082
|
+
xc = yc;
|
|
3083
|
+
yc = t;
|
|
3084
|
+
y.s = -y.s;
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
/*
|
|
3088
|
+
* Append zeros to xc if shorter. No need to add zeros to yc if shorter as subtraction only
|
|
3089
|
+
* needs to start at yc.length.
|
|
3090
|
+
*/
|
|
3091
|
+
if ((b = (j = yc.length) - (i = xc.length)) > 0) for (; b--;) xc[i++] = 0;
|
|
3092
|
+
|
|
3093
|
+
// Subtract yc from xc.
|
|
3094
|
+
for (b = i; j > a;) {
|
|
3095
|
+
if (xc[--j] < yc[j]) {
|
|
3096
|
+
for (i = j; i && !xc[--i];) xc[i] = 9;
|
|
3097
|
+
--xc[i];
|
|
3098
|
+
xc[j] += 10;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
xc[j] -= yc[j];
|
|
3102
|
+
}
|
|
3103
|
+
|
|
3104
|
+
// Remove trailing zeros.
|
|
3105
|
+
for (; xc[--b] === 0;) xc.pop();
|
|
3106
|
+
|
|
3107
|
+
// Remove leading zeros and adjust exponent accordingly.
|
|
3108
|
+
for (; xc[0] === 0;) {
|
|
3109
|
+
xc.shift();
|
|
3110
|
+
--ye;
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
if (!xc[0]) {
|
|
3114
|
+
|
|
3115
|
+
// n - n = +0
|
|
3116
|
+
y.s = 1;
|
|
3117
|
+
|
|
3118
|
+
// Result must be zero.
|
|
3119
|
+
xc = [ye = 0];
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
y.c = xc;
|
|
3123
|
+
y.e = ye;
|
|
3124
|
+
|
|
3125
|
+
return y;
|
|
3126
|
+
};
|
|
3127
|
+
|
|
3128
|
+
|
|
3129
|
+
/*
|
|
3130
|
+
* Return a new Big whose value is the value of this Big modulo the value of Big y.
|
|
3131
|
+
*/
|
|
3132
|
+
P.mod = function (y) {
|
|
3133
|
+
var ygtx,
|
|
3134
|
+
x = this,
|
|
3135
|
+
Big = x.constructor,
|
|
3136
|
+
a = x.s,
|
|
3137
|
+
b = (y = new Big(y)).s;
|
|
3138
|
+
|
|
3139
|
+
if (!y.c[0]) {
|
|
3140
|
+
throw Error(DIV_BY_ZERO);
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
x.s = y.s = 1;
|
|
3144
|
+
ygtx = y.cmp(x) == 1;
|
|
3145
|
+
x.s = a;
|
|
3146
|
+
y.s = b;
|
|
3147
|
+
|
|
3148
|
+
if (ygtx) return new Big(x);
|
|
3149
|
+
|
|
3150
|
+
a = Big.DP;
|
|
3151
|
+
b = Big.RM;
|
|
3152
|
+
Big.DP = Big.RM = 0;
|
|
3153
|
+
x = x.div(y);
|
|
3154
|
+
Big.DP = a;
|
|
3155
|
+
Big.RM = b;
|
|
3156
|
+
|
|
3157
|
+
return this.minus(x.times(y));
|
|
3158
|
+
};
|
|
3159
|
+
|
|
3160
|
+
|
|
3161
|
+
/*
|
|
3162
|
+
* Return a new Big whose value is the value of this Big negated.
|
|
3163
|
+
*/
|
|
3164
|
+
P.neg = function () {
|
|
3165
|
+
var x = new this.constructor(this);
|
|
3166
|
+
x.s = -x.s;
|
|
3167
|
+
return x;
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3170
|
+
|
|
3171
|
+
/*
|
|
3172
|
+
* Return a new Big whose value is the value of this Big plus the value of Big y.
|
|
3173
|
+
*/
|
|
3174
|
+
P.plus = P.add = function (y) {
|
|
3175
|
+
var e, k, t,
|
|
3176
|
+
x = this,
|
|
3177
|
+
Big = x.constructor;
|
|
3178
|
+
|
|
3179
|
+
y = new Big(y);
|
|
3180
|
+
|
|
3181
|
+
// Signs differ?
|
|
3182
|
+
if (x.s != y.s) {
|
|
3183
|
+
y.s = -y.s;
|
|
3184
|
+
return x.minus(y);
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
var xe = x.e,
|
|
3188
|
+
xc = x.c,
|
|
3189
|
+
ye = y.e,
|
|
3190
|
+
yc = y.c;
|
|
3191
|
+
|
|
3192
|
+
// Either zero?
|
|
3193
|
+
if (!xc[0] || !yc[0]) {
|
|
3194
|
+
if (!yc[0]) {
|
|
3195
|
+
if (xc[0]) {
|
|
3196
|
+
y = new Big(x);
|
|
3197
|
+
} else {
|
|
3198
|
+
y.s = x.s;
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
return y;
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
xc = xc.slice();
|
|
3205
|
+
|
|
3206
|
+
// Prepend zeros to equalise exponents.
|
|
3207
|
+
// Note: reverse faster than unshifts.
|
|
3208
|
+
if (e = xe - ye) {
|
|
3209
|
+
if (e > 0) {
|
|
3210
|
+
ye = xe;
|
|
3211
|
+
t = yc;
|
|
3212
|
+
} else {
|
|
3213
|
+
e = -e;
|
|
3214
|
+
t = xc;
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
t.reverse();
|
|
3218
|
+
for (; e--;) t.push(0);
|
|
3219
|
+
t.reverse();
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
// Point xc to the longer array.
|
|
3223
|
+
if (xc.length - yc.length < 0) {
|
|
3224
|
+
t = yc;
|
|
3225
|
+
yc = xc;
|
|
3226
|
+
xc = t;
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
e = yc.length;
|
|
3230
|
+
|
|
3231
|
+
// Only start adding at yc.length - 1 as the further digits of xc can be left as they are.
|
|
3232
|
+
for (k = 0; e; xc[e] %= 10) k = (xc[--e] = xc[e] + yc[e] + k) / 10 | 0;
|
|
3233
|
+
|
|
3234
|
+
// No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
|
3235
|
+
|
|
3236
|
+
if (k) {
|
|
3237
|
+
xc.unshift(k);
|
|
3238
|
+
++ye;
|
|
3239
|
+
}
|
|
3240
|
+
|
|
3241
|
+
// Remove trailing zeros.
|
|
3242
|
+
for (e = xc.length; xc[--e] === 0;) xc.pop();
|
|
3243
|
+
|
|
3244
|
+
y.c = xc;
|
|
3245
|
+
y.e = ye;
|
|
3246
|
+
|
|
3247
|
+
return y;
|
|
3248
|
+
};
|
|
3249
|
+
|
|
3250
|
+
|
|
3251
|
+
/*
|
|
3252
|
+
* Return a Big whose value is the value of this Big raised to the power n.
|
|
3253
|
+
* If n is negative, round to a maximum of Big.DP decimal places using rounding
|
|
3254
|
+
* mode Big.RM.
|
|
3255
|
+
*
|
|
3256
|
+
* n {number} Integer, -MAX_POWER to MAX_POWER inclusive.
|
|
3257
|
+
*/
|
|
3258
|
+
P.pow = function (n) {
|
|
3259
|
+
var x = this,
|
|
3260
|
+
one = new x.constructor('1'),
|
|
3261
|
+
y = one,
|
|
3262
|
+
isneg = n < 0;
|
|
3263
|
+
|
|
3264
|
+
if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
|
|
3265
|
+
throw Error(INVALID + 'exponent');
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
if (isneg) n = -n;
|
|
3269
|
+
|
|
3270
|
+
for (;;) {
|
|
3271
|
+
if (n & 1) y = y.times(x);
|
|
3272
|
+
n >>= 1;
|
|
3273
|
+
if (!n) break;
|
|
3274
|
+
x = x.times(x);
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
return isneg ? one.div(y) : y;
|
|
3278
|
+
};
|
|
3279
|
+
|
|
3280
|
+
|
|
3281
|
+
/*
|
|
3282
|
+
* Return a new Big whose value is the value of this Big rounded to a maximum precision of sd
|
|
3283
|
+
* significant digits using rounding mode rm, or Big.RM if rm is not specified.
|
|
3284
|
+
*
|
|
3285
|
+
* sd {number} Significant digits: integer, 1 to MAX_DP inclusive.
|
|
3286
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3287
|
+
*/
|
|
3288
|
+
P.prec = function (sd, rm) {
|
|
3289
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
3290
|
+
throw Error(INVALID + 'precision');
|
|
3291
|
+
}
|
|
3292
|
+
return round(new this.constructor(this), sd, rm);
|
|
3293
|
+
};
|
|
3294
|
+
|
|
3295
|
+
|
|
3296
|
+
/*
|
|
3297
|
+
* Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal places
|
|
3298
|
+
* using rounding mode rm, or Big.RM if rm is not specified.
|
|
3299
|
+
* If dp is negative, round to an integer which is a multiple of 10**-dp.
|
|
3300
|
+
* If dp is not specified, round to 0 decimal places.
|
|
3301
|
+
*
|
|
3302
|
+
* dp? {number} Integer, -MAX_DP to MAX_DP inclusive.
|
|
3303
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3304
|
+
*/
|
|
3305
|
+
P.round = function (dp, rm) {
|
|
3306
|
+
if (dp === UNDEFINED) dp = 0;
|
|
3307
|
+
else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) {
|
|
3308
|
+
throw Error(INVALID_DP);
|
|
3309
|
+
}
|
|
3310
|
+
return round(new this.constructor(this), dp + this.e + 1, rm);
|
|
3311
|
+
};
|
|
3312
|
+
|
|
3313
|
+
|
|
3314
|
+
/*
|
|
3315
|
+
* Return a new Big whose value is the square root of the value of this Big, rounded, if
|
|
3316
|
+
* necessary, to a maximum of Big.DP decimal places using rounding mode Big.RM.
|
|
3317
|
+
*/
|
|
3318
|
+
P.sqrt = function () {
|
|
3319
|
+
var r, c, t,
|
|
3320
|
+
x = this,
|
|
3321
|
+
Big = x.constructor,
|
|
3322
|
+
s = x.s,
|
|
3323
|
+
e = x.e,
|
|
3324
|
+
half = new Big('0.5');
|
|
3325
|
+
|
|
3326
|
+
// Zero?
|
|
3327
|
+
if (!x.c[0]) return new Big(x);
|
|
3328
|
+
|
|
3329
|
+
// Negative?
|
|
3330
|
+
if (s < 0) {
|
|
3331
|
+
throw Error(NAME + 'No square root');
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
// Estimate.
|
|
3335
|
+
s = Math.sqrt(x + '');
|
|
3336
|
+
|
|
3337
|
+
// Math.sqrt underflow/overflow?
|
|
3338
|
+
// Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent.
|
|
3339
|
+
if (s === 0 || s === 1 / 0) {
|
|
3340
|
+
c = x.c.join('');
|
|
3341
|
+
if (!(c.length + e & 1)) c += '0';
|
|
3342
|
+
s = Math.sqrt(c);
|
|
3343
|
+
e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
|
|
3344
|
+
r = new Big((s == 1 / 0 ? '5e' : (s = s.toExponential()).slice(0, s.indexOf('e') + 1)) + e);
|
|
3345
|
+
} else {
|
|
3346
|
+
r = new Big(s + '');
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
e = r.e + (Big.DP += 4);
|
|
3350
|
+
|
|
3351
|
+
// Newton-Raphson iteration.
|
|
3352
|
+
do {
|
|
3353
|
+
t = r;
|
|
3354
|
+
r = half.times(t.plus(x.div(t)));
|
|
3355
|
+
} while (t.c.slice(0, e).join('') !== r.c.slice(0, e).join(''));
|
|
3356
|
+
|
|
3357
|
+
return round(r, (Big.DP -= 4) + r.e + 1, Big.RM);
|
|
3358
|
+
};
|
|
3359
|
+
|
|
3360
|
+
|
|
3361
|
+
/*
|
|
3362
|
+
* Return a new Big whose value is the value of this Big times the value of Big y.
|
|
3363
|
+
*/
|
|
3364
|
+
P.times = P.mul = function (y) {
|
|
3365
|
+
var c,
|
|
3366
|
+
x = this,
|
|
3367
|
+
Big = x.constructor,
|
|
3368
|
+
xc = x.c,
|
|
3369
|
+
yc = (y = new Big(y)).c,
|
|
3370
|
+
a = xc.length,
|
|
3371
|
+
b = yc.length,
|
|
3372
|
+
i = x.e,
|
|
3373
|
+
j = y.e;
|
|
3374
|
+
|
|
3375
|
+
// Determine sign of result.
|
|
3376
|
+
y.s = x.s == y.s ? 1 : -1;
|
|
3377
|
+
|
|
3378
|
+
// Return signed 0 if either 0.
|
|
3379
|
+
if (!xc[0] || !yc[0]) {
|
|
3380
|
+
y.c = [y.e = 0];
|
|
3381
|
+
return y;
|
|
3382
|
+
}
|
|
3383
|
+
|
|
3384
|
+
// Initialise exponent of result as x.e + y.e.
|
|
3385
|
+
y.e = i + j;
|
|
3386
|
+
|
|
3387
|
+
// If array xc has fewer digits than yc, swap xc and yc, and lengths.
|
|
3388
|
+
if (a < b) {
|
|
3389
|
+
c = xc;
|
|
3390
|
+
xc = yc;
|
|
3391
|
+
yc = c;
|
|
3392
|
+
j = a;
|
|
3393
|
+
a = b;
|
|
3394
|
+
b = j;
|
|
3395
|
+
}
|
|
3396
|
+
|
|
3397
|
+
// Initialise coefficient array of result with zeros.
|
|
3398
|
+
for (c = new Array(j = a + b); j--;) c[j] = 0;
|
|
3399
|
+
|
|
3400
|
+
// Multiply.
|
|
3401
|
+
|
|
3402
|
+
// i is initially xc.length.
|
|
3403
|
+
for (i = b; i--;) {
|
|
3404
|
+
b = 0;
|
|
3405
|
+
|
|
3406
|
+
// a is yc.length.
|
|
3407
|
+
for (j = a + i; j > i;) {
|
|
3408
|
+
|
|
3409
|
+
// Current sum of products at this digit position, plus carry.
|
|
3410
|
+
b = c[j] + yc[i] * xc[j - i - 1] + b;
|
|
3411
|
+
c[j--] = b % 10;
|
|
3412
|
+
|
|
3413
|
+
// carry
|
|
3414
|
+
b = b / 10 | 0;
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
c[j] = b;
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3420
|
+
// Increment result exponent if there is a final carry, otherwise remove leading zero.
|
|
3421
|
+
if (b) ++y.e;
|
|
3422
|
+
else c.shift();
|
|
3423
|
+
|
|
3424
|
+
// Remove trailing zeros.
|
|
3425
|
+
for (i = c.length; !c[--i];) c.pop();
|
|
3426
|
+
y.c = c;
|
|
3427
|
+
|
|
3428
|
+
return y;
|
|
3429
|
+
};
|
|
3430
|
+
|
|
3431
|
+
|
|
3432
|
+
/*
|
|
3433
|
+
* Return a string representing the value of this Big in exponential notation rounded to dp fixed
|
|
3434
|
+
* decimal places using rounding mode rm, or Big.RM if rm is not specified.
|
|
3435
|
+
*
|
|
3436
|
+
* dp? {number} Decimal places: integer, 0 to MAX_DP inclusive.
|
|
3437
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3438
|
+
*/
|
|
3439
|
+
P.toExponential = function (dp, rm) {
|
|
3440
|
+
var x = this,
|
|
3441
|
+
n = x.c[0];
|
|
3442
|
+
|
|
3443
|
+
if (dp !== UNDEFINED) {
|
|
3444
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
3445
|
+
throw Error(INVALID_DP);
|
|
3446
|
+
}
|
|
3447
|
+
x = round(new x.constructor(x), ++dp, rm);
|
|
3448
|
+
for (; x.c.length < dp;) x.c.push(0);
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
return stringify(x, true, !!n);
|
|
3452
|
+
};
|
|
3453
|
+
|
|
3454
|
+
|
|
3455
|
+
/*
|
|
3456
|
+
* Return a string representing the value of this Big in normal notation rounded to dp fixed
|
|
3457
|
+
* decimal places using rounding mode rm, or Big.RM if rm is not specified.
|
|
3458
|
+
*
|
|
3459
|
+
* dp? {number} Decimal places: integer, 0 to MAX_DP inclusive.
|
|
3460
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3461
|
+
*
|
|
3462
|
+
* (-0).toFixed(0) is '0', but (-0.1).toFixed(0) is '-0'.
|
|
3463
|
+
* (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
|
|
3464
|
+
*/
|
|
3465
|
+
P.toFixed = function (dp, rm) {
|
|
3466
|
+
var x = this,
|
|
3467
|
+
n = x.c[0];
|
|
3468
|
+
|
|
3469
|
+
if (dp !== UNDEFINED) {
|
|
3470
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
3471
|
+
throw Error(INVALID_DP);
|
|
3472
|
+
}
|
|
3473
|
+
x = round(new x.constructor(x), dp + x.e + 1, rm);
|
|
3474
|
+
|
|
3475
|
+
// x.e may have changed if the value is rounded up.
|
|
3476
|
+
for (dp = dp + x.e + 1; x.c.length < dp;) x.c.push(0);
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
return stringify(x, false, !!n);
|
|
3480
|
+
};
|
|
3481
|
+
|
|
3482
|
+
|
|
3483
|
+
/*
|
|
3484
|
+
* Return a string representing the value of this Big.
|
|
3485
|
+
* Return exponential notation if this Big has a positive exponent equal to or greater than
|
|
3486
|
+
* Big.PE, or a negative exponent equal to or less than Big.NE.
|
|
3487
|
+
* Omit the sign for negative zero.
|
|
3488
|
+
*/
|
|
3489
|
+
P[Symbol.for('nodejs.util.inspect.custom')] = P.toJSON = P.toString = function () {
|
|
3490
|
+
var x = this,
|
|
3491
|
+
Big = x.constructor;
|
|
3492
|
+
return stringify(x, x.e <= Big.NE || x.e >= Big.PE, !!x.c[0]);
|
|
3493
|
+
};
|
|
3494
|
+
|
|
3495
|
+
|
|
3496
|
+
/*
|
|
3497
|
+
* Return the value of this Big as a primitve number.
|
|
3498
|
+
*/
|
|
3499
|
+
P.toNumber = function () {
|
|
3500
|
+
var n = Number(stringify(this, true, true));
|
|
3501
|
+
if (this.constructor.strict === true && !this.eq(n.toString())) {
|
|
3502
|
+
throw Error(NAME + 'Imprecise conversion');
|
|
3503
|
+
}
|
|
3504
|
+
return n;
|
|
3505
|
+
};
|
|
3506
|
+
|
|
3507
|
+
|
|
3508
|
+
/*
|
|
3509
|
+
* Return a string representing the value of this Big rounded to sd significant digits using
|
|
3510
|
+
* rounding mode rm, or Big.RM if rm is not specified.
|
|
3511
|
+
* Use exponential notation if sd is less than the number of digits necessary to represent
|
|
3512
|
+
* the integer part of the value in normal notation.
|
|
3513
|
+
*
|
|
3514
|
+
* sd {number} Significant digits: integer, 1 to MAX_DP inclusive.
|
|
3515
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3516
|
+
*/
|
|
3517
|
+
P.toPrecision = function (sd, rm) {
|
|
3518
|
+
var x = this,
|
|
3519
|
+
Big = x.constructor,
|
|
3520
|
+
n = x.c[0];
|
|
3521
|
+
|
|
3522
|
+
if (sd !== UNDEFINED) {
|
|
3523
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
3524
|
+
throw Error(INVALID + 'precision');
|
|
3525
|
+
}
|
|
3526
|
+
x = round(new Big(x), sd, rm);
|
|
3527
|
+
for (; x.c.length < sd;) x.c.push(0);
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
return stringify(x, sd <= x.e || x.e <= Big.NE || x.e >= Big.PE, !!n);
|
|
3531
|
+
};
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
/*
|
|
3535
|
+
* Return a string representing the value of this Big.
|
|
3536
|
+
* Return exponential notation if this Big has a positive exponent equal to or greater than
|
|
3537
|
+
* Big.PE, or a negative exponent equal to or less than Big.NE.
|
|
3538
|
+
* Include the sign for negative zero.
|
|
3539
|
+
*/
|
|
3540
|
+
P.valueOf = function () {
|
|
3541
|
+
var x = this,
|
|
3542
|
+
Big = x.constructor;
|
|
3543
|
+
if (Big.strict === true) {
|
|
3544
|
+
throw Error(NAME + 'valueOf disallowed');
|
|
3545
|
+
}
|
|
3546
|
+
return stringify(x, x.e <= Big.NE || x.e >= Big.PE, true);
|
|
3547
|
+
};
|
|
3548
|
+
|
|
3549
|
+
|
|
3550
|
+
// Export
|
|
3551
|
+
|
|
3552
|
+
|
|
3553
|
+
var Big = _Big_();
|
|
3554
|
+
|
|
2448
3555
|
const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
|
|
2449
3556
|
const bigDecimalValue = new Big(value.toString());
|
|
2450
3557
|
const bigDecimalExpo = new Big(Math.pow(10, decimals).toString());
|
|
@@ -2849,12 +3956,8 @@ exports.ChainID = void 0;
|
|
|
2849
3956
|
ChainID[ChainID["SCROLL_MAINNET"] = 534352] = "SCROLL_MAINNET";
|
|
2850
3957
|
ChainID[ChainID["COVALENT_INTERNAL_NETWORK_V1"] = 1131378225] = "COVALENT_INTERNAL_NETWORK_V1";
|
|
2851
3958
|
})(exports.ChainID || (exports.ChainID = {}));
|
|
2852
|
-
class GoldRushResponse {
|
|
2853
|
-
}
|
|
2854
3959
|
|
|
2855
|
-
exports.CovalentClient = GoldRushClient;
|
|
2856
3960
|
exports.GoldRushClient = GoldRushClient;
|
|
2857
|
-
exports.GoldRushResponse = GoldRushResponse;
|
|
2858
3961
|
exports.bigIntParser = bigIntParser;
|
|
2859
3962
|
exports.calculatePrettyBalance = calculatePrettyBalance;
|
|
2860
3963
|
exports.isValidApiKey = isValidApiKey;
|