@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/esm/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var version = "2.0.3";
|
|
1
|
+
var version = "2.1.1";
|
|
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;
|
|
@@ -1657,9 +1730,6 @@ class TransactionService {
|
|
|
1657
1730
|
* @param {GetTransactionQueryParamOpts} queryParamOpts
|
|
1658
1731
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1659
1732
|
* - `noLogs`: Omit log events.
|
|
1660
|
-
* - `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.
|
|
1661
|
-
* - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
|
|
1662
|
-
* - `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.
|
|
1663
1733
|
* - `withSafe`: Include safe details.
|
|
1664
1734
|
*
|
|
1665
1735
|
*/
|
|
@@ -1673,41 +1743,31 @@ class TransactionService {
|
|
|
1673
1743
|
key: "no-logs",
|
|
1674
1744
|
value: queryParamOpts?.noLogs,
|
|
1675
1745
|
},
|
|
1676
|
-
{
|
|
1677
|
-
key: "with-dex",
|
|
1678
|
-
value: queryParamOpts?.withDex,
|
|
1679
|
-
},
|
|
1680
|
-
{
|
|
1681
|
-
key: "with-nft-sales",
|
|
1682
|
-
value: queryParamOpts?.withNftSales,
|
|
1683
|
-
},
|
|
1684
|
-
{
|
|
1685
|
-
key: "with-lending",
|
|
1686
|
-
value: queryParamOpts?.withLending,
|
|
1687
|
-
},
|
|
1688
1746
|
]);
|
|
1689
1747
|
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
|
-
|
|
1748
|
+
if (data.data) {
|
|
1749
|
+
data.data.updated_at = data.data.updated_at
|
|
1750
|
+
? new Date(data.data.updated_at)
|
|
1751
|
+
: null;
|
|
1752
|
+
data.data.items = data.data.items
|
|
1753
|
+
? data.data.items.map((txItem) => ({
|
|
1754
|
+
...txItem,
|
|
1755
|
+
value: bigIntParser(txItem.value),
|
|
1756
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1757
|
+
block_signed_at: txItem.block_signed_at
|
|
1758
|
+
? new Date(txItem.block_signed_at)
|
|
1759
|
+
: null,
|
|
1760
|
+
log_events: txItem.log_events
|
|
1761
|
+
? txItem.log_events.map((logItem) => ({
|
|
1762
|
+
...logItem,
|
|
1763
|
+
block_signed_at: logItem.block_signed_at
|
|
1764
|
+
? new Date(logItem.block_signed_at)
|
|
1765
|
+
: null,
|
|
1766
|
+
}))
|
|
1767
|
+
: null,
|
|
1768
|
+
}))
|
|
1769
|
+
: null;
|
|
1770
|
+
}
|
|
1711
1771
|
return data;
|
|
1712
1772
|
};
|
|
1713
1773
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1745,27 +1805,29 @@ class TransactionService {
|
|
|
1745
1805
|
},
|
|
1746
1806
|
]);
|
|
1747
1807
|
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
|
-
|
|
1808
|
+
if (data.data) {
|
|
1809
|
+
data.data.updated_at = data.data.updated_at
|
|
1810
|
+
? new Date(data.data.updated_at)
|
|
1811
|
+
: null;
|
|
1812
|
+
data.data.items = data.data.items
|
|
1813
|
+
? data.data.items.map((txItem) => ({
|
|
1814
|
+
...txItem,
|
|
1815
|
+
value: bigIntParser(txItem.value),
|
|
1816
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1817
|
+
block_signed_at: txItem.block_signed_at
|
|
1818
|
+
? new Date(txItem.block_signed_at)
|
|
1819
|
+
: null,
|
|
1820
|
+
log_events: txItem.log_events
|
|
1821
|
+
? txItem.log_events.map((logItem) => ({
|
|
1822
|
+
...logItem,
|
|
1823
|
+
block_signed_at: logItem.block_signed_at
|
|
1824
|
+
? new Date(logItem.block_signed_at)
|
|
1825
|
+
: null,
|
|
1826
|
+
}))
|
|
1827
|
+
: null,
|
|
1828
|
+
}))
|
|
1829
|
+
: null;
|
|
1830
|
+
}
|
|
1769
1831
|
return data;
|
|
1770
1832
|
};
|
|
1771
1833
|
for await (const data of paginateEndpoint(endpoint, this.execution, parseData, "links")) {
|
|
@@ -1806,33 +1868,35 @@ class TransactionService {
|
|
|
1806
1868
|
];
|
|
1807
1869
|
const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3`, searchParams);
|
|
1808
1870
|
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
|
-
|
|
1871
|
+
if (data.data) {
|
|
1872
|
+
data.data.prev = data.data?.links?.prev
|
|
1873
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
1874
|
+
: null;
|
|
1875
|
+
data.data.next = data.data?.links?.next
|
|
1876
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
1877
|
+
: null;
|
|
1878
|
+
data.data.updated_at = data.data.updated_at
|
|
1879
|
+
? new Date(data.data.updated_at)
|
|
1880
|
+
: null;
|
|
1881
|
+
data.data.items = data.data.items
|
|
1882
|
+
? data.data.items.map((txItem) => ({
|
|
1883
|
+
...txItem,
|
|
1884
|
+
value: bigIntParser(txItem.value),
|
|
1885
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1886
|
+
block_signed_at: txItem.block_signed_at
|
|
1887
|
+
? new Date(txItem.block_signed_at)
|
|
1888
|
+
: null,
|
|
1889
|
+
log_events: txItem.log_events
|
|
1890
|
+
? txItem.log_events.map((logItem) => ({
|
|
1891
|
+
...logItem,
|
|
1892
|
+
block_signed_at: logItem.block_signed_at
|
|
1893
|
+
? new Date(logItem.block_signed_at)
|
|
1894
|
+
: null,
|
|
1895
|
+
}))
|
|
1896
|
+
: null,
|
|
1897
|
+
}))
|
|
1898
|
+
: null;
|
|
1899
|
+
}
|
|
1836
1900
|
return data;
|
|
1837
1901
|
};
|
|
1838
1902
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1865,27 +1929,29 @@ class TransactionService {
|
|
|
1865
1929
|
},
|
|
1866
1930
|
]);
|
|
1867
1931
|
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
|
-
|
|
1932
|
+
if (data.data) {
|
|
1933
|
+
data.data.updated_at = data.data.updated_at
|
|
1934
|
+
? new Date(data.data.updated_at)
|
|
1935
|
+
: null;
|
|
1936
|
+
data.data.items = data.data.items
|
|
1937
|
+
? data.data.items.map((txItem) => ({
|
|
1938
|
+
...txItem,
|
|
1939
|
+
value: bigIntParser(txItem.value),
|
|
1940
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
1941
|
+
block_signed_at: txItem.block_signed_at
|
|
1942
|
+
? new Date(txItem.block_signed_at)
|
|
1943
|
+
: null,
|
|
1944
|
+
log_events: txItem.log_events
|
|
1945
|
+
? txItem.log_events.map((logItem) => ({
|
|
1946
|
+
...logItem,
|
|
1947
|
+
block_signed_at: logItem.block_signed_at
|
|
1948
|
+
? new Date(logItem.block_signed_at)
|
|
1949
|
+
: null,
|
|
1950
|
+
}))
|
|
1951
|
+
: null,
|
|
1952
|
+
}))
|
|
1953
|
+
: null;
|
|
1954
|
+
}
|
|
1889
1955
|
return data;
|
|
1890
1956
|
};
|
|
1891
1957
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1913,33 +1979,35 @@ class TransactionService {
|
|
|
1913
1979
|
},
|
|
1914
1980
|
]);
|
|
1915
1981
|
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
|
-
|
|
1982
|
+
if (data.data) {
|
|
1983
|
+
data.data.updated_at = data.data.updated_at
|
|
1984
|
+
? new Date(data.data.updated_at)
|
|
1985
|
+
: null;
|
|
1986
|
+
data.data.items = data.data.items
|
|
1987
|
+
? data.data.items.map((txsItem) => ({
|
|
1988
|
+
...txsItem,
|
|
1989
|
+
earliest_transaction: {
|
|
1990
|
+
...txsItem.earliest_transaction,
|
|
1991
|
+
block_signed_at: txsItem?.earliest_transaction?.block_signed_at
|
|
1992
|
+
? new Date(txsItem.earliest_transaction.block_signed_at)
|
|
1993
|
+
: null,
|
|
1994
|
+
},
|
|
1995
|
+
latest_transaction: {
|
|
1996
|
+
...txsItem.latest_transaction,
|
|
1997
|
+
block_signed_at: txsItem?.latest_transaction?.block_signed_at
|
|
1998
|
+
? new Date(txsItem?.latest_transaction?.block_signed_at)
|
|
1999
|
+
: null,
|
|
2000
|
+
},
|
|
2001
|
+
// ? API vs docs non-consistent
|
|
2002
|
+
// gas_summary: {
|
|
2003
|
+
// ...txsItem.gas_summary,
|
|
2004
|
+
// total_fees_paid: bigIntParser(
|
|
2005
|
+
// txsItem.gas_summary.total_fees_paid
|
|
2006
|
+
// ),
|
|
2007
|
+
// },
|
|
2008
|
+
}))
|
|
2009
|
+
: null;
|
|
2010
|
+
}
|
|
1943
2011
|
return data;
|
|
1944
2012
|
};
|
|
1945
2013
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -1977,33 +2045,35 @@ class TransactionService {
|
|
|
1977
2045
|
];
|
|
1978
2046
|
const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3/page/${page}`, searchParams);
|
|
1979
2047
|
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
|
-
|
|
2048
|
+
if (data.data) {
|
|
2049
|
+
data.data.prev = data.data?.links?.prev
|
|
2050
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2051
|
+
: null;
|
|
2052
|
+
data.data.next = data.data?.links?.next
|
|
2053
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2054
|
+
: null;
|
|
2055
|
+
data.data.updated_at = data.data.updated_at
|
|
2056
|
+
? new Date(data.data.updated_at)
|
|
2057
|
+
: null;
|
|
2058
|
+
data.data.items = data.data.items
|
|
2059
|
+
? data.data.items.map((txItem) => ({
|
|
2060
|
+
...txItem,
|
|
2061
|
+
value: bigIntParser(txItem.value),
|
|
2062
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2063
|
+
block_signed_at: txItem.block_signed_at
|
|
2064
|
+
? new Date(txItem.block_signed_at)
|
|
2065
|
+
: null,
|
|
2066
|
+
log_events: txItem.log_events
|
|
2067
|
+
? txItem.log_events.map((logItem) => ({
|
|
2068
|
+
...logItem,
|
|
2069
|
+
block_signed_at: logItem.block_signed_at
|
|
2070
|
+
? new Date(logItem.block_signed_at)
|
|
2071
|
+
: null,
|
|
2072
|
+
}))
|
|
2073
|
+
: null,
|
|
2074
|
+
}))
|
|
2075
|
+
: null;
|
|
2076
|
+
}
|
|
2007
2077
|
return data;
|
|
2008
2078
|
};
|
|
2009
2079
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2036,33 +2106,35 @@ class TransactionService {
|
|
|
2036
2106
|
];
|
|
2037
2107
|
const endpoint = endpointGenerator(`${chainName}/bulk/transactions/${walletAddress}/${timeBucket}`, searchParams);
|
|
2038
2108
|
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
|
-
|
|
2109
|
+
if (data.data) {
|
|
2110
|
+
data.data.prev = data.data?.links?.prev
|
|
2111
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2112
|
+
: null;
|
|
2113
|
+
data.data.next = data.data?.links?.next
|
|
2114
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2115
|
+
: null;
|
|
2116
|
+
data.data.updated_at = data.data.updated_at
|
|
2117
|
+
? new Date(data.data.updated_at)
|
|
2118
|
+
: null;
|
|
2119
|
+
data.data.items = data.data.items
|
|
2120
|
+
? data.data.items.map((txItem) => ({
|
|
2121
|
+
...txItem,
|
|
2122
|
+
value: bigIntParser(txItem.value),
|
|
2123
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2124
|
+
block_signed_at: txItem.block_signed_at
|
|
2125
|
+
? new Date(txItem.block_signed_at)
|
|
2126
|
+
: null,
|
|
2127
|
+
log_events: txItem.log_events
|
|
2128
|
+
? txItem.log_events.map((logItem) => ({
|
|
2129
|
+
...logItem,
|
|
2130
|
+
block_signed_at: logItem.block_signed_at
|
|
2131
|
+
? new Date(logItem.block_signed_at)
|
|
2132
|
+
: null,
|
|
2133
|
+
}))
|
|
2134
|
+
: null,
|
|
2135
|
+
}))
|
|
2136
|
+
: null;
|
|
2137
|
+
}
|
|
2066
2138
|
return data;
|
|
2067
2139
|
};
|
|
2068
2140
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2097,33 +2169,35 @@ class TransactionService {
|
|
|
2097
2169
|
];
|
|
2098
2170
|
const endpoint = endpointGenerator(`${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}`, searchParams);
|
|
2099
2171
|
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
|
-
|
|
2172
|
+
if (data.data) {
|
|
2173
|
+
data.data.prev = data.data?.links?.prev
|
|
2174
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
|
|
2175
|
+
: null;
|
|
2176
|
+
data.data.next = data.data?.links?.next
|
|
2177
|
+
? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
|
|
2178
|
+
: null;
|
|
2179
|
+
data.data.updated_at = data.data.updated_at
|
|
2180
|
+
? new Date(data.data.updated_at)
|
|
2181
|
+
: null;
|
|
2182
|
+
data.data.items = data.data.items
|
|
2183
|
+
? data.data.items.map((txItem) => ({
|
|
2184
|
+
...txItem,
|
|
2185
|
+
value: bigIntParser(txItem.value),
|
|
2186
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2187
|
+
block_signed_at: txItem.block_signed_at
|
|
2188
|
+
? new Date(txItem.block_signed_at)
|
|
2189
|
+
: null,
|
|
2190
|
+
log_events: txItem.log_events
|
|
2191
|
+
? txItem.log_events.map((logItem) => ({
|
|
2192
|
+
...logItem,
|
|
2193
|
+
block_signed_at: logItem.block_signed_at
|
|
2194
|
+
? new Date(logItem.block_signed_at)
|
|
2195
|
+
: null,
|
|
2196
|
+
}))
|
|
2197
|
+
: null,
|
|
2198
|
+
}))
|
|
2199
|
+
: null;
|
|
2200
|
+
}
|
|
2127
2201
|
return data;
|
|
2128
2202
|
};
|
|
2129
2203
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2156,27 +2230,29 @@ class TransactionService {
|
|
|
2156
2230
|
},
|
|
2157
2231
|
]);
|
|
2158
2232
|
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
|
-
|
|
2233
|
+
if (data.data) {
|
|
2234
|
+
data.data.updated_at = data.data.updated_at
|
|
2235
|
+
? new Date(data.data.updated_at)
|
|
2236
|
+
: null;
|
|
2237
|
+
data.data.items = data.data.items
|
|
2238
|
+
? data.data.items.map((txItem) => ({
|
|
2239
|
+
...txItem,
|
|
2240
|
+
value: bigIntParser(txItem.value),
|
|
2241
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
2242
|
+
block_signed_at: txItem.block_signed_at
|
|
2243
|
+
? new Date(txItem.block_signed_at)
|
|
2244
|
+
: null,
|
|
2245
|
+
log_events: txItem.log_events
|
|
2246
|
+
? txItem.log_events.map((logItem) => ({
|
|
2247
|
+
...logItem,
|
|
2248
|
+
block_signed_at: logItem.block_signed_at
|
|
2249
|
+
? new Date(logItem.block_signed_at)
|
|
2250
|
+
: null,
|
|
2251
|
+
}))
|
|
2252
|
+
: null,
|
|
2253
|
+
}))
|
|
2254
|
+
: null;
|
|
2255
|
+
}
|
|
2180
2256
|
return data;
|
|
2181
2257
|
};
|
|
2182
2258
|
return await this.execution.execute(endpoint, parseData);
|
|
@@ -2366,7 +2442,7 @@ class Execution {
|
|
|
2366
2442
|
const parsedData = parseData(data);
|
|
2367
2443
|
completed = true;
|
|
2368
2444
|
return {
|
|
2369
|
-
data: parsedData.data
|
|
2445
|
+
data: parsedData.data,
|
|
2370
2446
|
error: false,
|
|
2371
2447
|
error_code: null,
|
|
2372
2448
|
error_message: null,
|
|
@@ -2404,6 +2480,12 @@ class Execution {
|
|
|
2404
2480
|
}
|
|
2405
2481
|
}
|
|
2406
2482
|
}
|
|
2483
|
+
return {
|
|
2484
|
+
data: null,
|
|
2485
|
+
error: true,
|
|
2486
|
+
error_code: 500,
|
|
2487
|
+
error_message: "Internal server error",
|
|
2488
|
+
};
|
|
2407
2489
|
}
|
|
2408
2490
|
}
|
|
2409
2491
|
|
|
@@ -2443,6 +2525,1031 @@ class GoldRushClient {
|
|
|
2443
2525
|
}
|
|
2444
2526
|
}
|
|
2445
2527
|
|
|
2528
|
+
/*
|
|
2529
|
+
* big.js v6.2.1
|
|
2530
|
+
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
|
|
2531
|
+
* Copyright (c) 2022 Michael Mclaughlin
|
|
2532
|
+
* https://github.com/MikeMcl/big.js/LICENCE.md
|
|
2533
|
+
*/
|
|
2534
|
+
|
|
2535
|
+
|
|
2536
|
+
/************************************** EDITABLE DEFAULTS *****************************************/
|
|
2537
|
+
|
|
2538
|
+
|
|
2539
|
+
// The default values below must be integers within the stated ranges.
|
|
2540
|
+
|
|
2541
|
+
/*
|
|
2542
|
+
* The maximum number of decimal places (DP) of the results of operations involving division:
|
|
2543
|
+
* div and sqrt, and pow with negative exponents.
|
|
2544
|
+
*/
|
|
2545
|
+
var DP = 20, // 0 to MAX_DP
|
|
2546
|
+
|
|
2547
|
+
/*
|
|
2548
|
+
* The rounding mode (RM) used when rounding to the above decimal places.
|
|
2549
|
+
*
|
|
2550
|
+
* 0 Towards zero (i.e. truncate, no rounding). (ROUND_DOWN)
|
|
2551
|
+
* 1 To nearest neighbour. If equidistant, round up. (ROUND_HALF_UP)
|
|
2552
|
+
* 2 To nearest neighbour. If equidistant, to even. (ROUND_HALF_EVEN)
|
|
2553
|
+
* 3 Away from zero. (ROUND_UP)
|
|
2554
|
+
*/
|
|
2555
|
+
RM = 1, // 0, 1, 2 or 3
|
|
2556
|
+
|
|
2557
|
+
// The maximum value of DP and Big.DP.
|
|
2558
|
+
MAX_DP = 1E6, // 0 to 1000000
|
|
2559
|
+
|
|
2560
|
+
// The maximum magnitude of the exponent argument to the pow method.
|
|
2561
|
+
MAX_POWER = 1E6, // 1 to 1000000
|
|
2562
|
+
|
|
2563
|
+
/*
|
|
2564
|
+
* The negative exponent (NE) at and beneath which toString returns exponential notation.
|
|
2565
|
+
* (JavaScript numbers: -7)
|
|
2566
|
+
* -1000000 is the minimum recommended exponent value of a Big.
|
|
2567
|
+
*/
|
|
2568
|
+
NE = -7, // 0 to -1000000
|
|
2569
|
+
|
|
2570
|
+
/*
|
|
2571
|
+
* The positive exponent (PE) at and above which toString returns exponential notation.
|
|
2572
|
+
* (JavaScript numbers: 21)
|
|
2573
|
+
* 1000000 is the maximum recommended exponent value of a Big, but this limit is not enforced.
|
|
2574
|
+
*/
|
|
2575
|
+
PE = 21, // 0 to 1000000
|
|
2576
|
+
|
|
2577
|
+
/*
|
|
2578
|
+
* When true, an error will be thrown if a primitive number is passed to the Big constructor,
|
|
2579
|
+
* or if valueOf is called, or if toNumber is called on a Big which cannot be converted to a
|
|
2580
|
+
* primitive number without a loss of precision.
|
|
2581
|
+
*/
|
|
2582
|
+
STRICT = false, // true or false
|
|
2583
|
+
|
|
2584
|
+
|
|
2585
|
+
/**************************************************************************************************/
|
|
2586
|
+
|
|
2587
|
+
|
|
2588
|
+
// Error messages.
|
|
2589
|
+
NAME = '[big.js] ',
|
|
2590
|
+
INVALID = NAME + 'Invalid ',
|
|
2591
|
+
INVALID_DP = INVALID + 'decimal places',
|
|
2592
|
+
INVALID_RM = INVALID + 'rounding mode',
|
|
2593
|
+
DIV_BY_ZERO = NAME + 'Division by zero',
|
|
2594
|
+
|
|
2595
|
+
// The shared prototype object.
|
|
2596
|
+
P = {},
|
|
2597
|
+
UNDEFINED = void 0,
|
|
2598
|
+
NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
2599
|
+
|
|
2600
|
+
|
|
2601
|
+
/*
|
|
2602
|
+
* Create and return a Big constructor.
|
|
2603
|
+
*/
|
|
2604
|
+
function _Big_() {
|
|
2605
|
+
|
|
2606
|
+
/*
|
|
2607
|
+
* The Big constructor and exported function.
|
|
2608
|
+
* Create and return a new instance of a Big number object.
|
|
2609
|
+
*
|
|
2610
|
+
* n {number|string|Big} A numeric value.
|
|
2611
|
+
*/
|
|
2612
|
+
function Big(n) {
|
|
2613
|
+
var x = this;
|
|
2614
|
+
|
|
2615
|
+
// Enable constructor usage without new.
|
|
2616
|
+
if (!(x instanceof Big)) return n === UNDEFINED ? _Big_() : new Big(n);
|
|
2617
|
+
|
|
2618
|
+
// Duplicate.
|
|
2619
|
+
if (n instanceof Big) {
|
|
2620
|
+
x.s = n.s;
|
|
2621
|
+
x.e = n.e;
|
|
2622
|
+
x.c = n.c.slice();
|
|
2623
|
+
} else {
|
|
2624
|
+
if (typeof n !== 'string') {
|
|
2625
|
+
if (Big.strict === true && typeof n !== 'bigint') {
|
|
2626
|
+
throw TypeError(INVALID + 'value');
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// Minus zero?
|
|
2630
|
+
n = n === 0 && 1 / n < 0 ? '-0' : String(n);
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
parse(x, n);
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
// Retain a reference to this Big constructor.
|
|
2637
|
+
// Shadow Big.prototype.constructor which points to Object.
|
|
2638
|
+
x.constructor = Big;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
Big.prototype = P;
|
|
2642
|
+
Big.DP = DP;
|
|
2643
|
+
Big.RM = RM;
|
|
2644
|
+
Big.NE = NE;
|
|
2645
|
+
Big.PE = PE;
|
|
2646
|
+
Big.strict = STRICT;
|
|
2647
|
+
Big.roundDown = 0;
|
|
2648
|
+
Big.roundHalfUp = 1;
|
|
2649
|
+
Big.roundHalfEven = 2;
|
|
2650
|
+
Big.roundUp = 3;
|
|
2651
|
+
|
|
2652
|
+
return Big;
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
|
|
2656
|
+
/*
|
|
2657
|
+
* Parse the number or string value passed to a Big constructor.
|
|
2658
|
+
*
|
|
2659
|
+
* x {Big} A Big number instance.
|
|
2660
|
+
* n {number|string} A numeric value.
|
|
2661
|
+
*/
|
|
2662
|
+
function parse(x, n) {
|
|
2663
|
+
var e, i, nl;
|
|
2664
|
+
|
|
2665
|
+
if (!NUMERIC.test(n)) {
|
|
2666
|
+
throw Error(INVALID + 'number');
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
// Determine sign.
|
|
2670
|
+
x.s = n.charAt(0) == '-' ? (n = n.slice(1), -1) : 1;
|
|
2671
|
+
|
|
2672
|
+
// Decimal point?
|
|
2673
|
+
if ((e = n.indexOf('.')) > -1) n = n.replace('.', '');
|
|
2674
|
+
|
|
2675
|
+
// Exponential form?
|
|
2676
|
+
if ((i = n.search(/e/i)) > 0) {
|
|
2677
|
+
|
|
2678
|
+
// Determine exponent.
|
|
2679
|
+
if (e < 0) e = i;
|
|
2680
|
+
e += +n.slice(i + 1);
|
|
2681
|
+
n = n.substring(0, i);
|
|
2682
|
+
} else if (e < 0) {
|
|
2683
|
+
|
|
2684
|
+
// Integer.
|
|
2685
|
+
e = n.length;
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
nl = n.length;
|
|
2689
|
+
|
|
2690
|
+
// Determine leading zeros.
|
|
2691
|
+
for (i = 0; i < nl && n.charAt(i) == '0';) ++i;
|
|
2692
|
+
|
|
2693
|
+
if (i == nl) {
|
|
2694
|
+
|
|
2695
|
+
// Zero.
|
|
2696
|
+
x.c = [x.e = 0];
|
|
2697
|
+
} else {
|
|
2698
|
+
|
|
2699
|
+
// Determine trailing zeros.
|
|
2700
|
+
for (; nl > 0 && n.charAt(--nl) == '0';);
|
|
2701
|
+
x.e = e - i - 1;
|
|
2702
|
+
x.c = [];
|
|
2703
|
+
|
|
2704
|
+
// Convert string to array of digits without leading/trailing zeros.
|
|
2705
|
+
for (e = 0; i <= nl;) x.c[e++] = +n.charAt(i++);
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
return x;
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
|
|
2712
|
+
/*
|
|
2713
|
+
* Round Big x to a maximum of sd significant digits using rounding mode rm.
|
|
2714
|
+
*
|
|
2715
|
+
* x {Big} The Big to round.
|
|
2716
|
+
* sd {number} Significant digits: integer, 0 to MAX_DP inclusive.
|
|
2717
|
+
* rm {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
2718
|
+
* [more] {boolean} Whether the result of division was truncated.
|
|
2719
|
+
*/
|
|
2720
|
+
function round(x, sd, rm, more) {
|
|
2721
|
+
var xc = x.c;
|
|
2722
|
+
|
|
2723
|
+
if (rm === UNDEFINED) rm = x.constructor.RM;
|
|
2724
|
+
if (rm !== 0 && rm !== 1 && rm !== 2 && rm !== 3) {
|
|
2725
|
+
throw Error(INVALID_RM);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
if (sd < 1) {
|
|
2729
|
+
more =
|
|
2730
|
+
rm === 3 && (more || !!xc[0]) || sd === 0 && (
|
|
2731
|
+
rm === 1 && xc[0] >= 5 ||
|
|
2732
|
+
rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc[1] !== UNDEFINED))
|
|
2733
|
+
);
|
|
2734
|
+
|
|
2735
|
+
xc.length = 1;
|
|
2736
|
+
|
|
2737
|
+
if (more) {
|
|
2738
|
+
|
|
2739
|
+
// 1, 0.1, 0.01, 0.001, 0.0001 etc.
|
|
2740
|
+
x.e = x.e - sd + 1;
|
|
2741
|
+
xc[0] = 1;
|
|
2742
|
+
} else {
|
|
2743
|
+
|
|
2744
|
+
// Zero.
|
|
2745
|
+
xc[0] = x.e = 0;
|
|
2746
|
+
}
|
|
2747
|
+
} else if (sd < xc.length) {
|
|
2748
|
+
|
|
2749
|
+
// xc[sd] is the digit after the digit that may be rounded up.
|
|
2750
|
+
more =
|
|
2751
|
+
rm === 1 && xc[sd] >= 5 ||
|
|
2752
|
+
rm === 2 && (xc[sd] > 5 || xc[sd] === 5 &&
|
|
2753
|
+
(more || xc[sd + 1] !== UNDEFINED || xc[sd - 1] & 1)) ||
|
|
2754
|
+
rm === 3 && (more || !!xc[0]);
|
|
2755
|
+
|
|
2756
|
+
// Remove any digits after the required precision.
|
|
2757
|
+
xc.length = sd;
|
|
2758
|
+
|
|
2759
|
+
// Round up?
|
|
2760
|
+
if (more) {
|
|
2761
|
+
|
|
2762
|
+
// Rounding up may mean the previous digit has to be rounded up.
|
|
2763
|
+
for (; ++xc[--sd] > 9;) {
|
|
2764
|
+
xc[sd] = 0;
|
|
2765
|
+
if (sd === 0) {
|
|
2766
|
+
++x.e;
|
|
2767
|
+
xc.unshift(1);
|
|
2768
|
+
break;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
// Remove trailing zeros.
|
|
2774
|
+
for (sd = xc.length; !xc[--sd];) xc.pop();
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
return x;
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
|
|
2781
|
+
/*
|
|
2782
|
+
* Return a string representing the value of Big x in normal or exponential notation.
|
|
2783
|
+
* Handles P.toExponential, P.toFixed, P.toJSON, P.toPrecision, P.toString and P.valueOf.
|
|
2784
|
+
*/
|
|
2785
|
+
function stringify(x, doExponential, isNonzero) {
|
|
2786
|
+
var e = x.e,
|
|
2787
|
+
s = x.c.join(''),
|
|
2788
|
+
n = s.length;
|
|
2789
|
+
|
|
2790
|
+
// Exponential notation?
|
|
2791
|
+
if (doExponential) {
|
|
2792
|
+
s = s.charAt(0) + (n > 1 ? '.' + s.slice(1) : '') + (e < 0 ? 'e' : 'e+') + e;
|
|
2793
|
+
|
|
2794
|
+
// Normal notation.
|
|
2795
|
+
} else if (e < 0) {
|
|
2796
|
+
for (; ++e;) s = '0' + s;
|
|
2797
|
+
s = '0.' + s;
|
|
2798
|
+
} else if (e > 0) {
|
|
2799
|
+
if (++e > n) {
|
|
2800
|
+
for (e -= n; e--;) s += '0';
|
|
2801
|
+
} else if (e < n) {
|
|
2802
|
+
s = s.slice(0, e) + '.' + s.slice(e);
|
|
2803
|
+
}
|
|
2804
|
+
} else if (n > 1) {
|
|
2805
|
+
s = s.charAt(0) + '.' + s.slice(1);
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
return x.s < 0 && isNonzero ? '-' + s : s;
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
|
|
2812
|
+
// Prototype/instance methods
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
/*
|
|
2816
|
+
* Return a new Big whose value is the absolute value of this Big.
|
|
2817
|
+
*/
|
|
2818
|
+
P.abs = function () {
|
|
2819
|
+
var x = new this.constructor(this);
|
|
2820
|
+
x.s = 1;
|
|
2821
|
+
return x;
|
|
2822
|
+
};
|
|
2823
|
+
|
|
2824
|
+
|
|
2825
|
+
/*
|
|
2826
|
+
* Return 1 if the value of this Big is greater than the value of Big y,
|
|
2827
|
+
* -1 if the value of this Big is less than the value of Big y, or
|
|
2828
|
+
* 0 if they have the same value.
|
|
2829
|
+
*/
|
|
2830
|
+
P.cmp = function (y) {
|
|
2831
|
+
var isneg,
|
|
2832
|
+
x = this,
|
|
2833
|
+
xc = x.c,
|
|
2834
|
+
yc = (y = new x.constructor(y)).c,
|
|
2835
|
+
i = x.s,
|
|
2836
|
+
j = y.s,
|
|
2837
|
+
k = x.e,
|
|
2838
|
+
l = y.e;
|
|
2839
|
+
|
|
2840
|
+
// Either zero?
|
|
2841
|
+
if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i;
|
|
2842
|
+
|
|
2843
|
+
// Signs differ?
|
|
2844
|
+
if (i != j) return i;
|
|
2845
|
+
|
|
2846
|
+
isneg = i < 0;
|
|
2847
|
+
|
|
2848
|
+
// Compare exponents.
|
|
2849
|
+
if (k != l) return k > l ^ isneg ? 1 : -1;
|
|
2850
|
+
|
|
2851
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
2852
|
+
|
|
2853
|
+
// Compare digit by digit.
|
|
2854
|
+
for (i = -1; ++i < j;) {
|
|
2855
|
+
if (xc[i] != yc[i]) return xc[i] > yc[i] ^ isneg ? 1 : -1;
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
// Compare lengths.
|
|
2859
|
+
return k == l ? 0 : k > l ^ isneg ? 1 : -1;
|
|
2860
|
+
};
|
|
2861
|
+
|
|
2862
|
+
|
|
2863
|
+
/*
|
|
2864
|
+
* Return a new Big whose value is the value of this Big divided by the value of Big y, rounded,
|
|
2865
|
+
* if necessary, to a maximum of Big.DP decimal places using rounding mode Big.RM.
|
|
2866
|
+
*/
|
|
2867
|
+
P.div = function (y) {
|
|
2868
|
+
var x = this,
|
|
2869
|
+
Big = x.constructor,
|
|
2870
|
+
a = x.c, // dividend
|
|
2871
|
+
b = (y = new Big(y)).c, // divisor
|
|
2872
|
+
k = x.s == y.s ? 1 : -1,
|
|
2873
|
+
dp = Big.DP;
|
|
2874
|
+
|
|
2875
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
2876
|
+
throw Error(INVALID_DP);
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
// Divisor is zero?
|
|
2880
|
+
if (!b[0]) {
|
|
2881
|
+
throw Error(DIV_BY_ZERO);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
// Dividend is 0? Return +-0.
|
|
2885
|
+
if (!a[0]) {
|
|
2886
|
+
y.s = k;
|
|
2887
|
+
y.c = [y.e = 0];
|
|
2888
|
+
return y;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
var bl, bt, n, cmp, ri,
|
|
2892
|
+
bz = b.slice(),
|
|
2893
|
+
ai = bl = b.length,
|
|
2894
|
+
al = a.length,
|
|
2895
|
+
r = a.slice(0, bl), // remainder
|
|
2896
|
+
rl = r.length,
|
|
2897
|
+
q = y, // quotient
|
|
2898
|
+
qc = q.c = [],
|
|
2899
|
+
qi = 0,
|
|
2900
|
+
p = dp + (q.e = x.e - y.e) + 1; // precision of the result
|
|
2901
|
+
|
|
2902
|
+
q.s = k;
|
|
2903
|
+
k = p < 0 ? 0 : p;
|
|
2904
|
+
|
|
2905
|
+
// Create version of divisor with leading zero.
|
|
2906
|
+
bz.unshift(0);
|
|
2907
|
+
|
|
2908
|
+
// Add zeros to make remainder as long as divisor.
|
|
2909
|
+
for (; rl++ < bl;) r.push(0);
|
|
2910
|
+
|
|
2911
|
+
do {
|
|
2912
|
+
|
|
2913
|
+
// n is how many times the divisor goes into current remainder.
|
|
2914
|
+
for (n = 0; n < 10; n++) {
|
|
2915
|
+
|
|
2916
|
+
// Compare divisor and remainder.
|
|
2917
|
+
if (bl != (rl = r.length)) {
|
|
2918
|
+
cmp = bl > rl ? 1 : -1;
|
|
2919
|
+
} else {
|
|
2920
|
+
for (ri = -1, cmp = 0; ++ri < bl;) {
|
|
2921
|
+
if (b[ri] != r[ri]) {
|
|
2922
|
+
cmp = b[ri] > r[ri] ? 1 : -1;
|
|
2923
|
+
break;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
// If divisor < remainder, subtract divisor from remainder.
|
|
2929
|
+
if (cmp < 0) {
|
|
2930
|
+
|
|
2931
|
+
// Remainder can't be more than 1 digit longer than divisor.
|
|
2932
|
+
// Equalise lengths using divisor with extra leading zero?
|
|
2933
|
+
for (bt = rl == bl ? b : bz; rl;) {
|
|
2934
|
+
if (r[--rl] < bt[rl]) {
|
|
2935
|
+
ri = rl;
|
|
2936
|
+
for (; ri && !r[--ri];) r[ri] = 9;
|
|
2937
|
+
--r[ri];
|
|
2938
|
+
r[rl] += 10;
|
|
2939
|
+
}
|
|
2940
|
+
r[rl] -= bt[rl];
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
for (; !r[0];) r.shift();
|
|
2944
|
+
} else {
|
|
2945
|
+
break;
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
// Add the digit n to the result array.
|
|
2950
|
+
qc[qi++] = cmp ? n : ++n;
|
|
2951
|
+
|
|
2952
|
+
// Update the remainder.
|
|
2953
|
+
if (r[0] && cmp) r[rl] = a[ai] || 0;
|
|
2954
|
+
else r = [a[ai]];
|
|
2955
|
+
|
|
2956
|
+
} while ((ai++ < al || r[0] !== UNDEFINED) && k--);
|
|
2957
|
+
|
|
2958
|
+
// Leading zero? Do not remove if result is simply zero (qi == 1).
|
|
2959
|
+
if (!qc[0] && qi != 1) {
|
|
2960
|
+
|
|
2961
|
+
// There can't be more than one zero.
|
|
2962
|
+
qc.shift();
|
|
2963
|
+
q.e--;
|
|
2964
|
+
p--;
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
// Round?
|
|
2968
|
+
if (qi > p) round(q, p, Big.RM, r[0] !== UNDEFINED);
|
|
2969
|
+
|
|
2970
|
+
return q;
|
|
2971
|
+
};
|
|
2972
|
+
|
|
2973
|
+
|
|
2974
|
+
/*
|
|
2975
|
+
* Return true if the value of this Big is equal to the value of Big y, otherwise return false.
|
|
2976
|
+
*/
|
|
2977
|
+
P.eq = function (y) {
|
|
2978
|
+
return this.cmp(y) === 0;
|
|
2979
|
+
};
|
|
2980
|
+
|
|
2981
|
+
|
|
2982
|
+
/*
|
|
2983
|
+
* Return true if the value of this Big is greater than the value of Big y, otherwise return
|
|
2984
|
+
* false.
|
|
2985
|
+
*/
|
|
2986
|
+
P.gt = function (y) {
|
|
2987
|
+
return this.cmp(y) > 0;
|
|
2988
|
+
};
|
|
2989
|
+
|
|
2990
|
+
|
|
2991
|
+
/*
|
|
2992
|
+
* Return true if the value of this Big is greater than or equal to the value of Big y, otherwise
|
|
2993
|
+
* return false.
|
|
2994
|
+
*/
|
|
2995
|
+
P.gte = function (y) {
|
|
2996
|
+
return this.cmp(y) > -1;
|
|
2997
|
+
};
|
|
2998
|
+
|
|
2999
|
+
|
|
3000
|
+
/*
|
|
3001
|
+
* Return true if the value of this Big is less than the value of Big y, otherwise return false.
|
|
3002
|
+
*/
|
|
3003
|
+
P.lt = function (y) {
|
|
3004
|
+
return this.cmp(y) < 0;
|
|
3005
|
+
};
|
|
3006
|
+
|
|
3007
|
+
|
|
3008
|
+
/*
|
|
3009
|
+
* Return true if the value of this Big is less than or equal to the value of Big y, otherwise
|
|
3010
|
+
* return false.
|
|
3011
|
+
*/
|
|
3012
|
+
P.lte = function (y) {
|
|
3013
|
+
return this.cmp(y) < 1;
|
|
3014
|
+
};
|
|
3015
|
+
|
|
3016
|
+
|
|
3017
|
+
/*
|
|
3018
|
+
* Return a new Big whose value is the value of this Big minus the value of Big y.
|
|
3019
|
+
*/
|
|
3020
|
+
P.minus = P.sub = function (y) {
|
|
3021
|
+
var i, j, t, xlty,
|
|
3022
|
+
x = this,
|
|
3023
|
+
Big = x.constructor,
|
|
3024
|
+
a = x.s,
|
|
3025
|
+
b = (y = new Big(y)).s;
|
|
3026
|
+
|
|
3027
|
+
// Signs differ?
|
|
3028
|
+
if (a != b) {
|
|
3029
|
+
y.s = -b;
|
|
3030
|
+
return x.plus(y);
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
var xc = x.c.slice(),
|
|
3034
|
+
xe = x.e,
|
|
3035
|
+
yc = y.c,
|
|
3036
|
+
ye = y.e;
|
|
3037
|
+
|
|
3038
|
+
// Either zero?
|
|
3039
|
+
if (!xc[0] || !yc[0]) {
|
|
3040
|
+
if (yc[0]) {
|
|
3041
|
+
y.s = -b;
|
|
3042
|
+
} else if (xc[0]) {
|
|
3043
|
+
y = new Big(x);
|
|
3044
|
+
} else {
|
|
3045
|
+
y.s = 1;
|
|
3046
|
+
}
|
|
3047
|
+
return y;
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
// Determine which is the bigger number. Prepend zeros to equalise exponents.
|
|
3051
|
+
if (a = xe - ye) {
|
|
3052
|
+
|
|
3053
|
+
if (xlty = a < 0) {
|
|
3054
|
+
a = -a;
|
|
3055
|
+
t = xc;
|
|
3056
|
+
} else {
|
|
3057
|
+
ye = xe;
|
|
3058
|
+
t = yc;
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
t.reverse();
|
|
3062
|
+
for (b = a; b--;) t.push(0);
|
|
3063
|
+
t.reverse();
|
|
3064
|
+
} else {
|
|
3065
|
+
|
|
3066
|
+
// Exponents equal. Check digit by digit.
|
|
3067
|
+
j = ((xlty = xc.length < yc.length) ? xc : yc).length;
|
|
3068
|
+
|
|
3069
|
+
for (a = b = 0; b < j; b++) {
|
|
3070
|
+
if (xc[b] != yc[b]) {
|
|
3071
|
+
xlty = xc[b] < yc[b];
|
|
3072
|
+
break;
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
|
|
3077
|
+
// x < y? Point xc to the array of the bigger number.
|
|
3078
|
+
if (xlty) {
|
|
3079
|
+
t = xc;
|
|
3080
|
+
xc = yc;
|
|
3081
|
+
yc = t;
|
|
3082
|
+
y.s = -y.s;
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
/*
|
|
3086
|
+
* Append zeros to xc if shorter. No need to add zeros to yc if shorter as subtraction only
|
|
3087
|
+
* needs to start at yc.length.
|
|
3088
|
+
*/
|
|
3089
|
+
if ((b = (j = yc.length) - (i = xc.length)) > 0) for (; b--;) xc[i++] = 0;
|
|
3090
|
+
|
|
3091
|
+
// Subtract yc from xc.
|
|
3092
|
+
for (b = i; j > a;) {
|
|
3093
|
+
if (xc[--j] < yc[j]) {
|
|
3094
|
+
for (i = j; i && !xc[--i];) xc[i] = 9;
|
|
3095
|
+
--xc[i];
|
|
3096
|
+
xc[j] += 10;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
xc[j] -= yc[j];
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
// Remove trailing zeros.
|
|
3103
|
+
for (; xc[--b] === 0;) xc.pop();
|
|
3104
|
+
|
|
3105
|
+
// Remove leading zeros and adjust exponent accordingly.
|
|
3106
|
+
for (; xc[0] === 0;) {
|
|
3107
|
+
xc.shift();
|
|
3108
|
+
--ye;
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
if (!xc[0]) {
|
|
3112
|
+
|
|
3113
|
+
// n - n = +0
|
|
3114
|
+
y.s = 1;
|
|
3115
|
+
|
|
3116
|
+
// Result must be zero.
|
|
3117
|
+
xc = [ye = 0];
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
y.c = xc;
|
|
3121
|
+
y.e = ye;
|
|
3122
|
+
|
|
3123
|
+
return y;
|
|
3124
|
+
};
|
|
3125
|
+
|
|
3126
|
+
|
|
3127
|
+
/*
|
|
3128
|
+
* Return a new Big whose value is the value of this Big modulo the value of Big y.
|
|
3129
|
+
*/
|
|
3130
|
+
P.mod = function (y) {
|
|
3131
|
+
var ygtx,
|
|
3132
|
+
x = this,
|
|
3133
|
+
Big = x.constructor,
|
|
3134
|
+
a = x.s,
|
|
3135
|
+
b = (y = new Big(y)).s;
|
|
3136
|
+
|
|
3137
|
+
if (!y.c[0]) {
|
|
3138
|
+
throw Error(DIV_BY_ZERO);
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
x.s = y.s = 1;
|
|
3142
|
+
ygtx = y.cmp(x) == 1;
|
|
3143
|
+
x.s = a;
|
|
3144
|
+
y.s = b;
|
|
3145
|
+
|
|
3146
|
+
if (ygtx) return new Big(x);
|
|
3147
|
+
|
|
3148
|
+
a = Big.DP;
|
|
3149
|
+
b = Big.RM;
|
|
3150
|
+
Big.DP = Big.RM = 0;
|
|
3151
|
+
x = x.div(y);
|
|
3152
|
+
Big.DP = a;
|
|
3153
|
+
Big.RM = b;
|
|
3154
|
+
|
|
3155
|
+
return this.minus(x.times(y));
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
|
|
3159
|
+
/*
|
|
3160
|
+
* Return a new Big whose value is the value of this Big negated.
|
|
3161
|
+
*/
|
|
3162
|
+
P.neg = function () {
|
|
3163
|
+
var x = new this.constructor(this);
|
|
3164
|
+
x.s = -x.s;
|
|
3165
|
+
return x;
|
|
3166
|
+
};
|
|
3167
|
+
|
|
3168
|
+
|
|
3169
|
+
/*
|
|
3170
|
+
* Return a new Big whose value is the value of this Big plus the value of Big y.
|
|
3171
|
+
*/
|
|
3172
|
+
P.plus = P.add = function (y) {
|
|
3173
|
+
var e, k, t,
|
|
3174
|
+
x = this,
|
|
3175
|
+
Big = x.constructor;
|
|
3176
|
+
|
|
3177
|
+
y = new Big(y);
|
|
3178
|
+
|
|
3179
|
+
// Signs differ?
|
|
3180
|
+
if (x.s != y.s) {
|
|
3181
|
+
y.s = -y.s;
|
|
3182
|
+
return x.minus(y);
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
var xe = x.e,
|
|
3186
|
+
xc = x.c,
|
|
3187
|
+
ye = y.e,
|
|
3188
|
+
yc = y.c;
|
|
3189
|
+
|
|
3190
|
+
// Either zero?
|
|
3191
|
+
if (!xc[0] || !yc[0]) {
|
|
3192
|
+
if (!yc[0]) {
|
|
3193
|
+
if (xc[0]) {
|
|
3194
|
+
y = new Big(x);
|
|
3195
|
+
} else {
|
|
3196
|
+
y.s = x.s;
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
return y;
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
xc = xc.slice();
|
|
3203
|
+
|
|
3204
|
+
// Prepend zeros to equalise exponents.
|
|
3205
|
+
// Note: reverse faster than unshifts.
|
|
3206
|
+
if (e = xe - ye) {
|
|
3207
|
+
if (e > 0) {
|
|
3208
|
+
ye = xe;
|
|
3209
|
+
t = yc;
|
|
3210
|
+
} else {
|
|
3211
|
+
e = -e;
|
|
3212
|
+
t = xc;
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3215
|
+
t.reverse();
|
|
3216
|
+
for (; e--;) t.push(0);
|
|
3217
|
+
t.reverse();
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
// Point xc to the longer array.
|
|
3221
|
+
if (xc.length - yc.length < 0) {
|
|
3222
|
+
t = yc;
|
|
3223
|
+
yc = xc;
|
|
3224
|
+
xc = t;
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
e = yc.length;
|
|
3228
|
+
|
|
3229
|
+
// Only start adding at yc.length - 1 as the further digits of xc can be left as they are.
|
|
3230
|
+
for (k = 0; e; xc[e] %= 10) k = (xc[--e] = xc[e] + yc[e] + k) / 10 | 0;
|
|
3231
|
+
|
|
3232
|
+
// No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
|
3233
|
+
|
|
3234
|
+
if (k) {
|
|
3235
|
+
xc.unshift(k);
|
|
3236
|
+
++ye;
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
// Remove trailing zeros.
|
|
3240
|
+
for (e = xc.length; xc[--e] === 0;) xc.pop();
|
|
3241
|
+
|
|
3242
|
+
y.c = xc;
|
|
3243
|
+
y.e = ye;
|
|
3244
|
+
|
|
3245
|
+
return y;
|
|
3246
|
+
};
|
|
3247
|
+
|
|
3248
|
+
|
|
3249
|
+
/*
|
|
3250
|
+
* Return a Big whose value is the value of this Big raised to the power n.
|
|
3251
|
+
* If n is negative, round to a maximum of Big.DP decimal places using rounding
|
|
3252
|
+
* mode Big.RM.
|
|
3253
|
+
*
|
|
3254
|
+
* n {number} Integer, -MAX_POWER to MAX_POWER inclusive.
|
|
3255
|
+
*/
|
|
3256
|
+
P.pow = function (n) {
|
|
3257
|
+
var x = this,
|
|
3258
|
+
one = new x.constructor('1'),
|
|
3259
|
+
y = one,
|
|
3260
|
+
isneg = n < 0;
|
|
3261
|
+
|
|
3262
|
+
if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
|
|
3263
|
+
throw Error(INVALID + 'exponent');
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
if (isneg) n = -n;
|
|
3267
|
+
|
|
3268
|
+
for (;;) {
|
|
3269
|
+
if (n & 1) y = y.times(x);
|
|
3270
|
+
n >>= 1;
|
|
3271
|
+
if (!n) break;
|
|
3272
|
+
x = x.times(x);
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
return isneg ? one.div(y) : y;
|
|
3276
|
+
};
|
|
3277
|
+
|
|
3278
|
+
|
|
3279
|
+
/*
|
|
3280
|
+
* Return a new Big whose value is the value of this Big rounded to a maximum precision of sd
|
|
3281
|
+
* significant digits using rounding mode rm, or Big.RM if rm is not specified.
|
|
3282
|
+
*
|
|
3283
|
+
* sd {number} Significant digits: integer, 1 to MAX_DP inclusive.
|
|
3284
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3285
|
+
*/
|
|
3286
|
+
P.prec = function (sd, rm) {
|
|
3287
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
3288
|
+
throw Error(INVALID + 'precision');
|
|
3289
|
+
}
|
|
3290
|
+
return round(new this.constructor(this), sd, rm);
|
|
3291
|
+
};
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
/*
|
|
3295
|
+
* Return a new Big whose value is the value of this Big rounded to a maximum of dp decimal places
|
|
3296
|
+
* using rounding mode rm, or Big.RM if rm is not specified.
|
|
3297
|
+
* If dp is negative, round to an integer which is a multiple of 10**-dp.
|
|
3298
|
+
* If dp is not specified, round to 0 decimal places.
|
|
3299
|
+
*
|
|
3300
|
+
* dp? {number} Integer, -MAX_DP to MAX_DP inclusive.
|
|
3301
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3302
|
+
*/
|
|
3303
|
+
P.round = function (dp, rm) {
|
|
3304
|
+
if (dp === UNDEFINED) dp = 0;
|
|
3305
|
+
else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) {
|
|
3306
|
+
throw Error(INVALID_DP);
|
|
3307
|
+
}
|
|
3308
|
+
return round(new this.constructor(this), dp + this.e + 1, rm);
|
|
3309
|
+
};
|
|
3310
|
+
|
|
3311
|
+
|
|
3312
|
+
/*
|
|
3313
|
+
* Return a new Big whose value is the square root of the value of this Big, rounded, if
|
|
3314
|
+
* necessary, to a maximum of Big.DP decimal places using rounding mode Big.RM.
|
|
3315
|
+
*/
|
|
3316
|
+
P.sqrt = function () {
|
|
3317
|
+
var r, c, t,
|
|
3318
|
+
x = this,
|
|
3319
|
+
Big = x.constructor,
|
|
3320
|
+
s = x.s,
|
|
3321
|
+
e = x.e,
|
|
3322
|
+
half = new Big('0.5');
|
|
3323
|
+
|
|
3324
|
+
// Zero?
|
|
3325
|
+
if (!x.c[0]) return new Big(x);
|
|
3326
|
+
|
|
3327
|
+
// Negative?
|
|
3328
|
+
if (s < 0) {
|
|
3329
|
+
throw Error(NAME + 'No square root');
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
// Estimate.
|
|
3333
|
+
s = Math.sqrt(x + '');
|
|
3334
|
+
|
|
3335
|
+
// Math.sqrt underflow/overflow?
|
|
3336
|
+
// Re-estimate: pass x coefficient to Math.sqrt as integer, then adjust the result exponent.
|
|
3337
|
+
if (s === 0 || s === 1 / 0) {
|
|
3338
|
+
c = x.c.join('');
|
|
3339
|
+
if (!(c.length + e & 1)) c += '0';
|
|
3340
|
+
s = Math.sqrt(c);
|
|
3341
|
+
e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
|
|
3342
|
+
r = new Big((s == 1 / 0 ? '5e' : (s = s.toExponential()).slice(0, s.indexOf('e') + 1)) + e);
|
|
3343
|
+
} else {
|
|
3344
|
+
r = new Big(s + '');
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
e = r.e + (Big.DP += 4);
|
|
3348
|
+
|
|
3349
|
+
// Newton-Raphson iteration.
|
|
3350
|
+
do {
|
|
3351
|
+
t = r;
|
|
3352
|
+
r = half.times(t.plus(x.div(t)));
|
|
3353
|
+
} while (t.c.slice(0, e).join('') !== r.c.slice(0, e).join(''));
|
|
3354
|
+
|
|
3355
|
+
return round(r, (Big.DP -= 4) + r.e + 1, Big.RM);
|
|
3356
|
+
};
|
|
3357
|
+
|
|
3358
|
+
|
|
3359
|
+
/*
|
|
3360
|
+
* Return a new Big whose value is the value of this Big times the value of Big y.
|
|
3361
|
+
*/
|
|
3362
|
+
P.times = P.mul = function (y) {
|
|
3363
|
+
var c,
|
|
3364
|
+
x = this,
|
|
3365
|
+
Big = x.constructor,
|
|
3366
|
+
xc = x.c,
|
|
3367
|
+
yc = (y = new Big(y)).c,
|
|
3368
|
+
a = xc.length,
|
|
3369
|
+
b = yc.length,
|
|
3370
|
+
i = x.e,
|
|
3371
|
+
j = y.e;
|
|
3372
|
+
|
|
3373
|
+
// Determine sign of result.
|
|
3374
|
+
y.s = x.s == y.s ? 1 : -1;
|
|
3375
|
+
|
|
3376
|
+
// Return signed 0 if either 0.
|
|
3377
|
+
if (!xc[0] || !yc[0]) {
|
|
3378
|
+
y.c = [y.e = 0];
|
|
3379
|
+
return y;
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
// Initialise exponent of result as x.e + y.e.
|
|
3383
|
+
y.e = i + j;
|
|
3384
|
+
|
|
3385
|
+
// If array xc has fewer digits than yc, swap xc and yc, and lengths.
|
|
3386
|
+
if (a < b) {
|
|
3387
|
+
c = xc;
|
|
3388
|
+
xc = yc;
|
|
3389
|
+
yc = c;
|
|
3390
|
+
j = a;
|
|
3391
|
+
a = b;
|
|
3392
|
+
b = j;
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
// Initialise coefficient array of result with zeros.
|
|
3396
|
+
for (c = new Array(j = a + b); j--;) c[j] = 0;
|
|
3397
|
+
|
|
3398
|
+
// Multiply.
|
|
3399
|
+
|
|
3400
|
+
// i is initially xc.length.
|
|
3401
|
+
for (i = b; i--;) {
|
|
3402
|
+
b = 0;
|
|
3403
|
+
|
|
3404
|
+
// a is yc.length.
|
|
3405
|
+
for (j = a + i; j > i;) {
|
|
3406
|
+
|
|
3407
|
+
// Current sum of products at this digit position, plus carry.
|
|
3408
|
+
b = c[j] + yc[i] * xc[j - i - 1] + b;
|
|
3409
|
+
c[j--] = b % 10;
|
|
3410
|
+
|
|
3411
|
+
// carry
|
|
3412
|
+
b = b / 10 | 0;
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
c[j] = b;
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
// Increment result exponent if there is a final carry, otherwise remove leading zero.
|
|
3419
|
+
if (b) ++y.e;
|
|
3420
|
+
else c.shift();
|
|
3421
|
+
|
|
3422
|
+
// Remove trailing zeros.
|
|
3423
|
+
for (i = c.length; !c[--i];) c.pop();
|
|
3424
|
+
y.c = c;
|
|
3425
|
+
|
|
3426
|
+
return y;
|
|
3427
|
+
};
|
|
3428
|
+
|
|
3429
|
+
|
|
3430
|
+
/*
|
|
3431
|
+
* Return a string representing the value of this Big in exponential notation rounded to dp fixed
|
|
3432
|
+
* decimal places using rounding mode rm, or Big.RM if rm is not specified.
|
|
3433
|
+
*
|
|
3434
|
+
* dp? {number} Decimal places: integer, 0 to MAX_DP inclusive.
|
|
3435
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3436
|
+
*/
|
|
3437
|
+
P.toExponential = function (dp, rm) {
|
|
3438
|
+
var x = this,
|
|
3439
|
+
n = x.c[0];
|
|
3440
|
+
|
|
3441
|
+
if (dp !== UNDEFINED) {
|
|
3442
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
3443
|
+
throw Error(INVALID_DP);
|
|
3444
|
+
}
|
|
3445
|
+
x = round(new x.constructor(x), ++dp, rm);
|
|
3446
|
+
for (; x.c.length < dp;) x.c.push(0);
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
return stringify(x, true, !!n);
|
|
3450
|
+
};
|
|
3451
|
+
|
|
3452
|
+
|
|
3453
|
+
/*
|
|
3454
|
+
* Return a string representing the value of this Big in normal notation rounded to dp fixed
|
|
3455
|
+
* decimal places using rounding mode rm, or Big.RM if rm is not specified.
|
|
3456
|
+
*
|
|
3457
|
+
* dp? {number} Decimal places: integer, 0 to MAX_DP inclusive.
|
|
3458
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3459
|
+
*
|
|
3460
|
+
* (-0).toFixed(0) is '0', but (-0.1).toFixed(0) is '-0'.
|
|
3461
|
+
* (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
|
|
3462
|
+
*/
|
|
3463
|
+
P.toFixed = function (dp, rm) {
|
|
3464
|
+
var x = this,
|
|
3465
|
+
n = x.c[0];
|
|
3466
|
+
|
|
3467
|
+
if (dp !== UNDEFINED) {
|
|
3468
|
+
if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
|
|
3469
|
+
throw Error(INVALID_DP);
|
|
3470
|
+
}
|
|
3471
|
+
x = round(new x.constructor(x), dp + x.e + 1, rm);
|
|
3472
|
+
|
|
3473
|
+
// x.e may have changed if the value is rounded up.
|
|
3474
|
+
for (dp = dp + x.e + 1; x.c.length < dp;) x.c.push(0);
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
return stringify(x, false, !!n);
|
|
3478
|
+
};
|
|
3479
|
+
|
|
3480
|
+
|
|
3481
|
+
/*
|
|
3482
|
+
* Return a string representing the value of this Big.
|
|
3483
|
+
* Return exponential notation if this Big has a positive exponent equal to or greater than
|
|
3484
|
+
* Big.PE, or a negative exponent equal to or less than Big.NE.
|
|
3485
|
+
* Omit the sign for negative zero.
|
|
3486
|
+
*/
|
|
3487
|
+
P[Symbol.for('nodejs.util.inspect.custom')] = P.toJSON = P.toString = function () {
|
|
3488
|
+
var x = this,
|
|
3489
|
+
Big = x.constructor;
|
|
3490
|
+
return stringify(x, x.e <= Big.NE || x.e >= Big.PE, !!x.c[0]);
|
|
3491
|
+
};
|
|
3492
|
+
|
|
3493
|
+
|
|
3494
|
+
/*
|
|
3495
|
+
* Return the value of this Big as a primitve number.
|
|
3496
|
+
*/
|
|
3497
|
+
P.toNumber = function () {
|
|
3498
|
+
var n = Number(stringify(this, true, true));
|
|
3499
|
+
if (this.constructor.strict === true && !this.eq(n.toString())) {
|
|
3500
|
+
throw Error(NAME + 'Imprecise conversion');
|
|
3501
|
+
}
|
|
3502
|
+
return n;
|
|
3503
|
+
};
|
|
3504
|
+
|
|
3505
|
+
|
|
3506
|
+
/*
|
|
3507
|
+
* Return a string representing the value of this Big rounded to sd significant digits using
|
|
3508
|
+
* rounding mode rm, or Big.RM if rm is not specified.
|
|
3509
|
+
* Use exponential notation if sd is less than the number of digits necessary to represent
|
|
3510
|
+
* the integer part of the value in normal notation.
|
|
3511
|
+
*
|
|
3512
|
+
* sd {number} Significant digits: integer, 1 to MAX_DP inclusive.
|
|
3513
|
+
* rm? {number} Rounding mode: 0 (down), 1 (half-up), 2 (half-even) or 3 (up).
|
|
3514
|
+
*/
|
|
3515
|
+
P.toPrecision = function (sd, rm) {
|
|
3516
|
+
var x = this,
|
|
3517
|
+
Big = x.constructor,
|
|
3518
|
+
n = x.c[0];
|
|
3519
|
+
|
|
3520
|
+
if (sd !== UNDEFINED) {
|
|
3521
|
+
if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
|
|
3522
|
+
throw Error(INVALID + 'precision');
|
|
3523
|
+
}
|
|
3524
|
+
x = round(new Big(x), sd, rm);
|
|
3525
|
+
for (; x.c.length < sd;) x.c.push(0);
|
|
3526
|
+
}
|
|
3527
|
+
|
|
3528
|
+
return stringify(x, sd <= x.e || x.e <= Big.NE || x.e >= Big.PE, !!n);
|
|
3529
|
+
};
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
/*
|
|
3533
|
+
* Return a string representing the value of this Big.
|
|
3534
|
+
* Return exponential notation if this Big has a positive exponent equal to or greater than
|
|
3535
|
+
* Big.PE, or a negative exponent equal to or less than Big.NE.
|
|
3536
|
+
* Include the sign for negative zero.
|
|
3537
|
+
*/
|
|
3538
|
+
P.valueOf = function () {
|
|
3539
|
+
var x = this,
|
|
3540
|
+
Big = x.constructor;
|
|
3541
|
+
if (Big.strict === true) {
|
|
3542
|
+
throw Error(NAME + 'valueOf disallowed');
|
|
3543
|
+
}
|
|
3544
|
+
return stringify(x, x.e <= Big.NE || x.e >= Big.PE, true);
|
|
3545
|
+
};
|
|
3546
|
+
|
|
3547
|
+
|
|
3548
|
+
// Export
|
|
3549
|
+
|
|
3550
|
+
|
|
3551
|
+
var Big = _Big_();
|
|
3552
|
+
|
|
2446
3553
|
const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
|
|
2447
3554
|
const bigDecimalValue = new Big(value.toString());
|
|
2448
3555
|
const bigDecimalExpo = new Big(Math.pow(10, decimals).toString());
|
|
@@ -2847,8 +3954,6 @@ var ChainID;
|
|
|
2847
3954
|
ChainID[ChainID["SCROLL_MAINNET"] = 534352] = "SCROLL_MAINNET";
|
|
2848
3955
|
ChainID[ChainID["COVALENT_INTERNAL_NETWORK_V1"] = 1131378225] = "COVALENT_INTERNAL_NETWORK_V1";
|
|
2849
3956
|
})(ChainID || (ChainID = {}));
|
|
2850
|
-
class GoldRushResponse {
|
|
2851
|
-
}
|
|
2852
3957
|
|
|
2853
|
-
export { ChainID, ChainName, GoldRushClient
|
|
3958
|
+
export { ChainID, ChainName, GoldRushClient, bigIntParser, calculatePrettyBalance, isValidApiKey, prettifyCurrency };
|
|
2854
3959
|
//# sourceMappingURL=index.js.map
|