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