@covalenthq/client-sdk 0.7.5 → 0.8.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 +25 -0
- package/dist/cjs/index.js +1183 -451
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +15 -13
- package/dist/cjs/services/BaseService.d.ts +13 -11
- package/dist/cjs/services/CovalentClient.d.ts +8 -4
- package/dist/cjs/services/NftService.d.ts +19 -17
- package/dist/cjs/services/PricingService.d.ts +5 -3
- package/dist/cjs/services/SecurityService.d.ts +6 -4
- package/dist/cjs/services/TransactionService.d.ts +83 -12
- package/dist/cjs/services/XykService.d.ts +287 -22
- package/dist/cjs/util/ApiHelpers.d.ts +2 -1
- package/dist/cjs/util/backoff.d.ts +2 -1
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +160 -8
- package/dist/es/index.js +1183 -451
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +15 -13
- package/dist/es/services/BaseService.d.ts +13 -11
- package/dist/es/services/CovalentClient.d.ts +8 -4
- package/dist/es/services/NftService.d.ts +19 -17
- package/dist/es/services/PricingService.d.ts +5 -3
- package/dist/es/services/SecurityService.d.ts +6 -4
- package/dist/es/services/TransactionService.d.ts +83 -12
- package/dist/es/services/XykService.d.ts +287 -22
- package/dist/es/util/ApiHelpers.d.ts +2 -1
- package/dist/es/util/backoff.d.ts +2 -1
- package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +160 -8
- package/dist/esm/index.js +1183 -451
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +15 -13
- package/dist/esm/services/BaseService.d.ts +13 -11
- package/dist/esm/services/CovalentClient.d.ts +8 -4
- package/dist/esm/services/NftService.d.ts +19 -17
- package/dist/esm/services/PricingService.d.ts +5 -3
- package/dist/esm/services/SecurityService.d.ts +6 -4
- package/dist/esm/services/TransactionService.d.ts +83 -12
- package/dist/esm/services/XykService.d.ts +287 -22
- package/dist/esm/util/ApiHelpers.d.ts +2 -1
- package/dist/esm/util/backoff.d.ts +2 -1
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/esm/util/types/XykServiceTypes.d.ts +160 -8
- package/dist/services/BalanceService.d.ts +15 -13
- package/dist/services/BalanceService.js +47 -39
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +13 -11
- package/dist/services/BaseService.js +77 -65
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +8 -4
- package/dist/services/CovalentClient.js +19 -19
- package/dist/services/CovalentClient.js.map +1 -1
- package/dist/services/NftService.d.ts +19 -17
- package/dist/services/NftService.js +96 -81
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +5 -3
- package/dist/services/PricingService.js +10 -7
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +6 -4
- package/dist/services/SecurityService.js +17 -13
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +83 -12
- package/dist/services/TransactionService.js +434 -90
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +287 -22
- package/dist/services/XykService.js +438 -93
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +7 -6
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/backoff.d.ts +2 -1
- package/dist/util/backoff.js +3 -3
- package/dist/util/backoff.js.map +1 -1
- package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
- package/dist/util/types/XykServiceTypes.d.ts +160 -8
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -11,7 +11,7 @@ class ExponentialBackoff {
|
|
|
11
11
|
this._apiKey = apiKey;
|
|
12
12
|
this._debug = debug;
|
|
13
13
|
}
|
|
14
|
-
async backOff(url) {
|
|
14
|
+
async backOff(url, source) {
|
|
15
15
|
try {
|
|
16
16
|
let startTime;
|
|
17
17
|
if (this._debug) {
|
|
@@ -20,7 +20,7 @@ class ExponentialBackoff {
|
|
|
20
20
|
const response = await fetch(url, {
|
|
21
21
|
headers: {
|
|
22
22
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
23
|
-
"X-Requested-With": userAgent
|
|
23
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
debugOutput(response.url, response.status ?? 429, startTime);
|
|
@@ -36,7 +36,7 @@ class ExponentialBackoff {
|
|
|
36
36
|
this.retryCount++;
|
|
37
37
|
const delayMs = Math.pow(2, this.retryCount) * BASE_DELAY_MS;
|
|
38
38
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
39
|
-
return this.backOff(url);
|
|
39
|
+
return this.backOff(url, source);
|
|
40
40
|
}
|
|
41
41
|
return Promise.reject(new Error(`Max retries exceeded: ${this.maxRetries}`));
|
|
42
42
|
}
|
|
@@ -219,7 +219,7 @@ async function debugOutput(url, responseStatus, startTime) {
|
|
|
219
219
|
}
|
|
220
220
|
console.log(`${chalk.red("[DEBUG]")}` + " |" + ` Request URL: ${chalk.yellow(url)}` + " |" + ` Response code: ${responseStatus !== 200 ? chalk.red(responseStatus) : chalk.green(responseStatus)}` + " |" + ` Response time: ${chalk.cyan(elapsedTime.toFixed(2) + "ms")}`);
|
|
221
221
|
}
|
|
222
|
-
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount) {
|
|
222
|
+
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry, source) {
|
|
223
223
|
let hasNext = true;
|
|
224
224
|
let response;
|
|
225
225
|
let data;
|
|
@@ -232,20 +232,21 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
|
|
|
232
232
|
if (debug) {
|
|
233
233
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
234
234
|
}
|
|
235
|
+
const link = urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`;
|
|
235
236
|
response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
|
|
236
237
|
headers: {
|
|
237
238
|
"Authorization": `Bearer ${apiKey}`,
|
|
238
|
-
"X-Requested-With": userAgent
|
|
239
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
239
240
|
}
|
|
240
241
|
}));
|
|
241
|
-
debugOutput(response.url, response.status
|
|
242
|
-
if (response.status === null || response.status === 429) {
|
|
242
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
243
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
243
244
|
try {
|
|
244
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
245
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : link, source));
|
|
245
246
|
}
|
|
246
247
|
catch (error) {
|
|
247
248
|
hasNext = false;
|
|
248
|
-
throw new Error(`An error occurred ${response.status
|
|
249
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
@@ -383,11 +384,13 @@ class NftApprovalSpender {
|
|
|
383
384
|
*
|
|
384
385
|
*/
|
|
385
386
|
class SecurityService {
|
|
386
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
387
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
387
388
|
this.apiKey = apiKey;
|
|
388
389
|
this.debug = debug;
|
|
389
390
|
this.threadCount = threadCount;
|
|
390
391
|
this.is_key_valid = is_key_valid;
|
|
392
|
+
this.enableRetry = enableRetry;
|
|
393
|
+
this.source = source;
|
|
391
394
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
392
395
|
}
|
|
393
396
|
/**
|
|
@@ -406,6 +409,7 @@ class SecurityService {
|
|
|
406
409
|
while (!success) {
|
|
407
410
|
try {
|
|
408
411
|
const urlParams = new URLSearchParams();
|
|
412
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`;
|
|
409
413
|
if (!this.is_key_valid) {
|
|
410
414
|
return {
|
|
411
415
|
data: null,
|
|
@@ -421,13 +425,13 @@ class SecurityService {
|
|
|
421
425
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`, {
|
|
422
426
|
headers: {
|
|
423
427
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
424
|
-
"X-Requested-With": userAgent
|
|
428
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
425
429
|
}
|
|
426
430
|
}));
|
|
427
|
-
debugOutput(response.url, response.status
|
|
428
|
-
if (response.status === null || response.status === 429) {
|
|
431
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
432
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
429
433
|
try {
|
|
430
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
434
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
431
435
|
}
|
|
432
436
|
catch (error) {
|
|
433
437
|
success = true;
|
|
@@ -457,8 +461,8 @@ class SecurityService {
|
|
|
457
461
|
return {
|
|
458
462
|
data: null,
|
|
459
463
|
error: true,
|
|
460
|
-
error_code: data ? data.error_code : response.status,
|
|
461
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
464
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
465
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
462
466
|
};
|
|
463
467
|
}
|
|
464
468
|
}
|
|
@@ -478,6 +482,7 @@ class SecurityService {
|
|
|
478
482
|
while (!success) {
|
|
479
483
|
try {
|
|
480
484
|
const urlParams = new URLSearchParams();
|
|
485
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`;
|
|
481
486
|
if (!this.is_key_valid) {
|
|
482
487
|
return {
|
|
483
488
|
data: null,
|
|
@@ -493,13 +498,13 @@ class SecurityService {
|
|
|
493
498
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`, {
|
|
494
499
|
headers: {
|
|
495
500
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
496
|
-
"X-Requested-With": userAgent
|
|
501
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
497
502
|
}
|
|
498
503
|
}));
|
|
499
|
-
debugOutput(response.url, response.status
|
|
500
|
-
if (response.status === null || response.status === 429) {
|
|
504
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
505
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
501
506
|
try {
|
|
502
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
507
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
503
508
|
}
|
|
504
509
|
catch (error) {
|
|
505
510
|
success = true;
|
|
@@ -529,8 +534,8 @@ class SecurityService {
|
|
|
529
534
|
return {
|
|
530
535
|
data: null,
|
|
531
536
|
error: true,
|
|
532
|
-
error_code: data ? data.error_code : response.status,
|
|
533
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
537
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
538
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
534
539
|
};
|
|
535
540
|
}
|
|
536
541
|
}
|
|
@@ -818,11 +823,13 @@ class NativeBalanceItem {
|
|
|
818
823
|
*
|
|
819
824
|
*/
|
|
820
825
|
class BalanceService {
|
|
821
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
826
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
822
827
|
this.apiKey = apiKey;
|
|
823
828
|
this.debug = debug;
|
|
824
829
|
this.threadCount = threadCount;
|
|
825
830
|
this.is_key_valid = is_key_valid;
|
|
831
|
+
this.enableRetry = enableRetry;
|
|
832
|
+
this.source = source;
|
|
826
833
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
827
834
|
}
|
|
828
835
|
/**
|
|
@@ -870,6 +877,7 @@ class BalanceService {
|
|
|
870
877
|
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
871
878
|
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
872
879
|
}
|
|
880
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`;
|
|
873
881
|
let startTime;
|
|
874
882
|
if (this.debug) {
|
|
875
883
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -877,13 +885,13 @@ class BalanceService {
|
|
|
877
885
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
|
|
878
886
|
headers: {
|
|
879
887
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
880
|
-
"X-Requested-With": userAgent
|
|
888
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
881
889
|
}
|
|
882
890
|
}));
|
|
883
|
-
debugOutput(response.url, response.status
|
|
884
|
-
if (response.status === null || response.status === 429) {
|
|
891
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
892
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
885
893
|
try {
|
|
886
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
894
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
887
895
|
}
|
|
888
896
|
catch (error) {
|
|
889
897
|
success = true;
|
|
@@ -913,8 +921,8 @@ class BalanceService {
|
|
|
913
921
|
return {
|
|
914
922
|
data: null,
|
|
915
923
|
error: true,
|
|
916
|
-
error_code: data ? data.error_code : response.status,
|
|
917
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
924
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
925
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
918
926
|
};
|
|
919
927
|
}
|
|
920
928
|
}
|
|
@@ -952,6 +960,7 @@ class BalanceService {
|
|
|
952
960
|
if (queryParamOpts?.days !== undefined) {
|
|
953
961
|
urlParams.append("days", queryParamOpts?.days.toString());
|
|
954
962
|
}
|
|
963
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`;
|
|
955
964
|
let startTime;
|
|
956
965
|
if (this.debug) {
|
|
957
966
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -959,13 +968,13 @@ class BalanceService {
|
|
|
959
968
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
|
|
960
969
|
headers: {
|
|
961
970
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
962
|
-
"X-Requested-With": userAgent
|
|
971
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
963
972
|
}
|
|
964
973
|
}));
|
|
965
|
-
debugOutput(response.url, response.status
|
|
966
|
-
if (response.status === null || response.status === 429) {
|
|
974
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
975
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
967
976
|
try {
|
|
968
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
977
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
969
978
|
}
|
|
970
979
|
catch (error) {
|
|
971
980
|
success = true;
|
|
@@ -995,8 +1004,8 @@ class BalanceService {
|
|
|
995
1004
|
return {
|
|
996
1005
|
data: null,
|
|
997
1006
|
error: true,
|
|
998
|
-
error_code: data ? data.error_code : response.status,
|
|
999
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1007
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1008
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1000
1009
|
};
|
|
1001
1010
|
}
|
|
1002
1011
|
}
|
|
@@ -1043,7 +1052,7 @@ class BalanceService {
|
|
|
1043
1052
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1044
1053
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1045
1054
|
}
|
|
1046
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount)) {
|
|
1055
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
1047
1056
|
yield res;
|
|
1048
1057
|
}
|
|
1049
1058
|
success = true;
|
|
@@ -1103,6 +1112,7 @@ class BalanceService {
|
|
|
1103
1112
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1104
1113
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1105
1114
|
}
|
|
1115
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`;
|
|
1106
1116
|
let startTime;
|
|
1107
1117
|
if (this.debug) {
|
|
1108
1118
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1110,13 +1120,13 @@ class BalanceService {
|
|
|
1110
1120
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
|
|
1111
1121
|
headers: {
|
|
1112
1122
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1113
|
-
"X-Requested-With": userAgent
|
|
1123
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1114
1124
|
}
|
|
1115
1125
|
}));
|
|
1116
|
-
debugOutput(response.url, response.status
|
|
1117
|
-
if (response.status === null || response.status === 429) {
|
|
1126
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1127
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1118
1128
|
try {
|
|
1119
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1129
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1120
1130
|
}
|
|
1121
1131
|
catch (error) {
|
|
1122
1132
|
success = true;
|
|
@@ -1146,8 +1156,8 @@ class BalanceService {
|
|
|
1146
1156
|
return {
|
|
1147
1157
|
data: null,
|
|
1148
1158
|
error: true,
|
|
1149
|
-
error_code: data ? data.error_code : response.status,
|
|
1150
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1159
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1160
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1151
1161
|
};
|
|
1152
1162
|
}
|
|
1153
1163
|
}
|
|
@@ -1186,7 +1196,7 @@ class BalanceService {
|
|
|
1186
1196
|
if (queryParamOpts?.date !== undefined) {
|
|
1187
1197
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1188
1198
|
}
|
|
1189
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount)) {
|
|
1199
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
1190
1200
|
yield res;
|
|
1191
1201
|
}
|
|
1192
1202
|
success = true;
|
|
@@ -1238,6 +1248,7 @@ class BalanceService {
|
|
|
1238
1248
|
if (queryParamOpts?.date !== undefined) {
|
|
1239
1249
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1240
1250
|
}
|
|
1251
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`;
|
|
1241
1252
|
let startTime;
|
|
1242
1253
|
if (this.debug) {
|
|
1243
1254
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1245,13 +1256,13 @@ class BalanceService {
|
|
|
1245
1256
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
|
|
1246
1257
|
headers: {
|
|
1247
1258
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1248
|
-
"X-Requested-With": userAgent
|
|
1259
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1249
1260
|
}
|
|
1250
1261
|
}));
|
|
1251
|
-
debugOutput(response.url, response.status
|
|
1252
|
-
if (response.status === null || response.status === 429) {
|
|
1262
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1263
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1253
1264
|
try {
|
|
1254
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1265
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1255
1266
|
}
|
|
1256
1267
|
catch (error) {
|
|
1257
1268
|
success = true;
|
|
@@ -1281,8 +1292,8 @@ class BalanceService {
|
|
|
1281
1292
|
return {
|
|
1282
1293
|
data: null,
|
|
1283
1294
|
error: true,
|
|
1284
|
-
error_code: data ? data.error_code : response.status,
|
|
1285
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1295
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1296
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1286
1297
|
};
|
|
1287
1298
|
}
|
|
1288
1299
|
}
|
|
@@ -1340,6 +1351,7 @@ class BalanceService {
|
|
|
1340
1351
|
if (queryParamOpts?.date !== undefined) {
|
|
1341
1352
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1342
1353
|
}
|
|
1354
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`;
|
|
1343
1355
|
let startTime;
|
|
1344
1356
|
if (this.debug) {
|
|
1345
1357
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1347,13 +1359,13 @@ class BalanceService {
|
|
|
1347
1359
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
|
|
1348
1360
|
headers: {
|
|
1349
1361
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1350
|
-
"X-Requested-With": userAgent
|
|
1362
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1351
1363
|
}
|
|
1352
1364
|
}));
|
|
1353
|
-
debugOutput(response.url, response.status
|
|
1354
|
-
if (response.status === null || response.status === 429) {
|
|
1365
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1366
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1355
1367
|
try {
|
|
1356
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1368
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1357
1369
|
}
|
|
1358
1370
|
catch (error) {
|
|
1359
1371
|
success = true;
|
|
@@ -1383,8 +1395,8 @@ class BalanceService {
|
|
|
1383
1395
|
return {
|
|
1384
1396
|
data: null,
|
|
1385
1397
|
error: true,
|
|
1386
|
-
error_code: data ? data.error_code : response.status,
|
|
1387
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1398
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1399
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1388
1400
|
};
|
|
1389
1401
|
}
|
|
1390
1402
|
}
|
|
@@ -1420,6 +1432,7 @@ class BalanceService {
|
|
|
1420
1432
|
if (queryParamOpts?.blockHeight !== undefined) {
|
|
1421
1433
|
urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
|
|
1422
1434
|
}
|
|
1435
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`;
|
|
1423
1436
|
let startTime;
|
|
1424
1437
|
if (this.debug) {
|
|
1425
1438
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1427,13 +1440,13 @@ class BalanceService {
|
|
|
1427
1440
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
|
|
1428
1441
|
headers: {
|
|
1429
1442
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1430
|
-
"X-Requested-With": userAgent
|
|
1443
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1431
1444
|
}
|
|
1432
1445
|
}));
|
|
1433
|
-
debugOutput(response.url, response.status
|
|
1434
|
-
if (response.status === null || response.status === 429) {
|
|
1446
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1447
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1435
1448
|
try {
|
|
1436
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1449
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1437
1450
|
}
|
|
1438
1451
|
catch (error) {
|
|
1439
1452
|
success = true;
|
|
@@ -1463,8 +1476,8 @@ class BalanceService {
|
|
|
1463
1476
|
return {
|
|
1464
1477
|
data: null,
|
|
1465
1478
|
error: true,
|
|
1466
|
-
error_code: data ? data.error_code : response.status,
|
|
1467
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1479
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1480
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1468
1481
|
};
|
|
1469
1482
|
}
|
|
1470
1483
|
}
|
|
@@ -1692,11 +1705,13 @@ class OtherFees {
|
|
|
1692
1705
|
*
|
|
1693
1706
|
*/
|
|
1694
1707
|
class BaseService {
|
|
1695
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
1708
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
1696
1709
|
this.apiKey = apiKey;
|
|
1697
1710
|
this.debug = debug;
|
|
1698
1711
|
this.threadCount = threadCount;
|
|
1699
1712
|
this.is_key_valid = is_key_valid;
|
|
1713
|
+
this.enableRetry = enableRetry;
|
|
1714
|
+
this.source = source;
|
|
1700
1715
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
1701
1716
|
}
|
|
1702
1717
|
/**
|
|
@@ -1723,6 +1738,7 @@ class BaseService {
|
|
|
1723
1738
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1724
1739
|
};
|
|
1725
1740
|
}
|
|
1741
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`;
|
|
1726
1742
|
let startTime;
|
|
1727
1743
|
if (this.debug) {
|
|
1728
1744
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1730,13 +1746,13 @@ class BaseService {
|
|
|
1730
1746
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
|
|
1731
1747
|
headers: {
|
|
1732
1748
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1733
|
-
"X-Requested-With": userAgent
|
|
1749
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1734
1750
|
}
|
|
1735
1751
|
}));
|
|
1736
|
-
debugOutput(response.url, response.status
|
|
1737
|
-
if (response.status === null || response.status === 429) {
|
|
1752
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1753
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1738
1754
|
try {
|
|
1739
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1755
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1740
1756
|
}
|
|
1741
1757
|
catch (error) {
|
|
1742
1758
|
success = true;
|
|
@@ -1766,8 +1782,8 @@ class BaseService {
|
|
|
1766
1782
|
return {
|
|
1767
1783
|
data: null,
|
|
1768
1784
|
error: true,
|
|
1769
|
-
error_code: data ? data.error_code : response.status,
|
|
1770
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1785
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1786
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1771
1787
|
};
|
|
1772
1788
|
}
|
|
1773
1789
|
}
|
|
@@ -1796,6 +1812,7 @@ class BaseService {
|
|
|
1796
1812
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1797
1813
|
};
|
|
1798
1814
|
}
|
|
1815
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`;
|
|
1799
1816
|
let startTime;
|
|
1800
1817
|
if (this.debug) {
|
|
1801
1818
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1803,13 +1820,13 @@ class BaseService {
|
|
|
1803
1820
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
|
|
1804
1821
|
headers: {
|
|
1805
1822
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1806
|
-
"X-Requested-With": userAgent
|
|
1823
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1807
1824
|
}
|
|
1808
1825
|
}));
|
|
1809
|
-
debugOutput(response.url, response.status
|
|
1810
|
-
if (response.status === null || response.status === 429) {
|
|
1826
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1827
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1811
1828
|
try {
|
|
1812
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1829
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1813
1830
|
}
|
|
1814
1831
|
catch (error) {
|
|
1815
1832
|
success = true;
|
|
@@ -1839,8 +1856,8 @@ class BaseService {
|
|
|
1839
1856
|
return {
|
|
1840
1857
|
data: null,
|
|
1841
1858
|
error: true,
|
|
1842
|
-
error_code: data ? data.error_code : response.status,
|
|
1843
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1859
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1860
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1844
1861
|
};
|
|
1845
1862
|
}
|
|
1846
1863
|
}
|
|
@@ -1872,7 +1889,7 @@ class BaseService {
|
|
|
1872
1889
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1873
1890
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1874
1891
|
}
|
|
1875
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount)) {
|
|
1892
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
1876
1893
|
yield res;
|
|
1877
1894
|
}
|
|
1878
1895
|
success = true;
|
|
@@ -1917,6 +1934,7 @@ class BaseService {
|
|
|
1917
1934
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1918
1935
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1919
1936
|
}
|
|
1937
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`;
|
|
1920
1938
|
let startTime;
|
|
1921
1939
|
if (this.debug) {
|
|
1922
1940
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -1924,13 +1942,13 @@ class BaseService {
|
|
|
1924
1942
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
|
|
1925
1943
|
headers: {
|
|
1926
1944
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1927
|
-
"X-Requested-With": userAgent
|
|
1945
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1928
1946
|
}
|
|
1929
1947
|
}));
|
|
1930
|
-
debugOutput(response.url, response.status
|
|
1931
|
-
if (response.status === null || response.status === 429) {
|
|
1948
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1949
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1932
1950
|
try {
|
|
1933
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1951
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1934
1952
|
}
|
|
1935
1953
|
catch (error) {
|
|
1936
1954
|
success = true;
|
|
@@ -1960,8 +1978,8 @@ class BaseService {
|
|
|
1960
1978
|
return {
|
|
1961
1979
|
data: null,
|
|
1962
1980
|
error: true,
|
|
1963
|
-
error_code: data ? data.error_code : response.status,
|
|
1964
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
1981
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1982
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1965
1983
|
};
|
|
1966
1984
|
}
|
|
1967
1985
|
}
|
|
@@ -2014,6 +2032,7 @@ class BaseService {
|
|
|
2014
2032
|
if (queryParamOpts?.skipDecode !== undefined) {
|
|
2015
2033
|
urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
|
|
2016
2034
|
}
|
|
2035
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`;
|
|
2017
2036
|
let startTime;
|
|
2018
2037
|
if (this.debug) {
|
|
2019
2038
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2021,13 +2040,13 @@ class BaseService {
|
|
|
2021
2040
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
|
|
2022
2041
|
headers: {
|
|
2023
2042
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2024
|
-
"X-Requested-With": userAgent
|
|
2043
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2025
2044
|
}
|
|
2026
2045
|
}));
|
|
2027
|
-
debugOutput(response.url, response.status
|
|
2028
|
-
if (response.status === null || response.status === 429) {
|
|
2046
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2047
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2029
2048
|
try {
|
|
2030
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2049
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2031
2050
|
}
|
|
2032
2051
|
catch (error) {
|
|
2033
2052
|
success = true;
|
|
@@ -2057,8 +2076,8 @@ class BaseService {
|
|
|
2057
2076
|
return {
|
|
2058
2077
|
data: null,
|
|
2059
2078
|
error: true,
|
|
2060
|
-
error_code: data ? data.error_code : response.status,
|
|
2061
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2079
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2080
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2062
2081
|
};
|
|
2063
2082
|
}
|
|
2064
2083
|
}
|
|
@@ -2097,7 +2116,7 @@ class BaseService {
|
|
|
2097
2116
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2098
2117
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2099
2118
|
}
|
|
2100
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2119
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
2101
2120
|
yield res;
|
|
2102
2121
|
}
|
|
2103
2122
|
success = true;
|
|
@@ -2149,6 +2168,7 @@ class BaseService {
|
|
|
2149
2168
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2150
2169
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2151
2170
|
}
|
|
2171
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`;
|
|
2152
2172
|
let startTime;
|
|
2153
2173
|
if (this.debug) {
|
|
2154
2174
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2156,13 +2176,13 @@ class BaseService {
|
|
|
2156
2176
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
|
|
2157
2177
|
headers: {
|
|
2158
2178
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2159
|
-
"X-Requested-With": userAgent
|
|
2179
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2160
2180
|
}
|
|
2161
2181
|
}));
|
|
2162
|
-
debugOutput(response.url, response.status
|
|
2163
|
-
if (response.status === null || response.status === 429) {
|
|
2182
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2183
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2164
2184
|
try {
|
|
2165
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2185
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2166
2186
|
}
|
|
2167
2187
|
catch (error) {
|
|
2168
2188
|
success = true;
|
|
@@ -2192,8 +2212,8 @@ class BaseService {
|
|
|
2192
2212
|
return {
|
|
2193
2213
|
data: null,
|
|
2194
2214
|
error: true,
|
|
2195
|
-
error_code: data ? data.error_code : response.status,
|
|
2196
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2215
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2216
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2197
2217
|
};
|
|
2198
2218
|
}
|
|
2199
2219
|
}
|
|
@@ -2236,7 +2256,7 @@ class BaseService {
|
|
|
2236
2256
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2237
2257
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2238
2258
|
}
|
|
2239
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
|
|
2259
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
2240
2260
|
yield res;
|
|
2241
2261
|
}
|
|
2242
2262
|
success = true;
|
|
@@ -2292,6 +2312,7 @@ class BaseService {
|
|
|
2292
2312
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2293
2313
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2294
2314
|
}
|
|
2315
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`;
|
|
2295
2316
|
let startTime;
|
|
2296
2317
|
if (this.debug) {
|
|
2297
2318
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2299,13 +2320,13 @@ class BaseService {
|
|
|
2299
2320
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
|
|
2300
2321
|
headers: {
|
|
2301
2322
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2302
|
-
"X-Requested-With": userAgent
|
|
2323
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2303
2324
|
}
|
|
2304
2325
|
}));
|
|
2305
|
-
debugOutput(response.url, response.status
|
|
2306
|
-
if (response.status === null || response.status === 429) {
|
|
2326
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2327
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2307
2328
|
try {
|
|
2308
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2329
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2309
2330
|
}
|
|
2310
2331
|
catch (error) {
|
|
2311
2332
|
success = true;
|
|
@@ -2335,8 +2356,8 @@ class BaseService {
|
|
|
2335
2356
|
return {
|
|
2336
2357
|
data: null,
|
|
2337
2358
|
error: true,
|
|
2338
|
-
error_code: data ? data.error_code : response.status,
|
|
2339
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2359
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2360
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2340
2361
|
};
|
|
2341
2362
|
}
|
|
2342
2363
|
}
|
|
@@ -2367,16 +2388,17 @@ class BaseService {
|
|
|
2367
2388
|
if (this.debug) {
|
|
2368
2389
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
2369
2390
|
}
|
|
2391
|
+
const url = `https://api.covalenthq.com/v1/chains/?${urlParams}`;
|
|
2370
2392
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
|
|
2371
2393
|
headers: {
|
|
2372
2394
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2373
|
-
"X-Requested-With": userAgent
|
|
2395
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2374
2396
|
}
|
|
2375
2397
|
}));
|
|
2376
|
-
debugOutput(response.url, response.status
|
|
2377
|
-
if (response.status === null || response.status === 429) {
|
|
2398
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2399
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2378
2400
|
try {
|
|
2379
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2401
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2380
2402
|
}
|
|
2381
2403
|
catch (error) {
|
|
2382
2404
|
success = true;
|
|
@@ -2406,8 +2428,8 @@ class BaseService {
|
|
|
2406
2428
|
return {
|
|
2407
2429
|
data: null,
|
|
2408
2430
|
error: true,
|
|
2409
|
-
error_code: data ? data.error_code : response.status,
|
|
2410
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2431
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2432
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2411
2433
|
};
|
|
2412
2434
|
}
|
|
2413
2435
|
}
|
|
@@ -2434,6 +2456,7 @@ class BaseService {
|
|
|
2434
2456
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
2435
2457
|
};
|
|
2436
2458
|
}
|
|
2459
|
+
const url = `https://api.covalenthq.com/v1/chains/status/?${urlParams}`;
|
|
2437
2460
|
let startTime;
|
|
2438
2461
|
if (this.debug) {
|
|
2439
2462
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2441,13 +2464,13 @@ class BaseService {
|
|
|
2441
2464
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
|
|
2442
2465
|
headers: {
|
|
2443
2466
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2444
|
-
"X-Requested-With": userAgent
|
|
2467
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2445
2468
|
}
|
|
2446
2469
|
}));
|
|
2447
|
-
debugOutput(response.url, response.status
|
|
2448
|
-
if (response.status === null || response.status === 429) {
|
|
2470
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2471
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2449
2472
|
try {
|
|
2450
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2473
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2451
2474
|
}
|
|
2452
2475
|
catch (error) {
|
|
2453
2476
|
success = true;
|
|
@@ -2477,8 +2500,8 @@ class BaseService {
|
|
|
2477
2500
|
return {
|
|
2478
2501
|
data: null,
|
|
2479
2502
|
error: true,
|
|
2480
|
-
error_code: data ? data.error_code : response.status,
|
|
2481
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2503
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2504
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2482
2505
|
};
|
|
2483
2506
|
}
|
|
2484
2507
|
}
|
|
@@ -2511,6 +2534,7 @@ class BaseService {
|
|
|
2511
2534
|
if (queryParamOpts?.testnets !== undefined) {
|
|
2512
2535
|
urlParams.append("testnets", queryParamOpts?.testnets.toString());
|
|
2513
2536
|
}
|
|
2537
|
+
const url = `https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`;
|
|
2514
2538
|
let startTime;
|
|
2515
2539
|
if (this.debug) {
|
|
2516
2540
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2518,13 +2542,13 @@ class BaseService {
|
|
|
2518
2542
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
|
|
2519
2543
|
headers: {
|
|
2520
2544
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2521
|
-
"X-Requested-With": userAgent
|
|
2545
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2522
2546
|
}
|
|
2523
2547
|
}));
|
|
2524
|
-
debugOutput(response.url, response.status
|
|
2525
|
-
if (response.status === null || response.status === 429) {
|
|
2548
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2549
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2526
2550
|
try {
|
|
2527
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2551
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2528
2552
|
}
|
|
2529
2553
|
catch (error) {
|
|
2530
2554
|
success = true;
|
|
@@ -2554,8 +2578,8 @@ class BaseService {
|
|
|
2554
2578
|
return {
|
|
2555
2579
|
data: null,
|
|
2556
2580
|
error: true,
|
|
2557
|
-
error_code: data ? data.error_code : response.status,
|
|
2558
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2581
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2582
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2559
2583
|
};
|
|
2560
2584
|
}
|
|
2561
2585
|
}
|
|
@@ -2587,6 +2611,7 @@ class BaseService {
|
|
|
2587
2611
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
2588
2612
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
2589
2613
|
}
|
|
2614
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`;
|
|
2590
2615
|
let startTime;
|
|
2591
2616
|
if (this.debug) {
|
|
2592
2617
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -2594,20 +2619,20 @@ class BaseService {
|
|
|
2594
2619
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
|
|
2595
2620
|
headers: {
|
|
2596
2621
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2597
|
-
"X-Requested-With": userAgent
|
|
2622
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2598
2623
|
}
|
|
2599
2624
|
}));
|
|
2600
|
-
debugOutput(response.url, response.status, startTime);
|
|
2601
|
-
if (response.status === 429) {
|
|
2625
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2626
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2602
2627
|
try {
|
|
2603
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
2628
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2604
2629
|
}
|
|
2605
2630
|
catch (error) {
|
|
2606
2631
|
success = true;
|
|
2607
2632
|
return {
|
|
2608
2633
|
data: null,
|
|
2609
2634
|
error: true,
|
|
2610
|
-
error_code: response.status,
|
|
2635
|
+
error_code: response.status ?? 429,
|
|
2611
2636
|
error_message: error.message
|
|
2612
2637
|
};
|
|
2613
2638
|
}
|
|
@@ -2630,8 +2655,8 @@ class BaseService {
|
|
|
2630
2655
|
return {
|
|
2631
2656
|
data: null,
|
|
2632
2657
|
error: true,
|
|
2633
|
-
error_code: data ? data.error_code : response.status,
|
|
2634
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
2658
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
2659
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
2635
2660
|
};
|
|
2636
2661
|
}
|
|
2637
2662
|
}
|
|
@@ -2960,11 +2985,13 @@ class MarketFloorPriceItem {
|
|
|
2960
2985
|
*
|
|
2961
2986
|
*/
|
|
2962
2987
|
class NftService {
|
|
2963
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
2988
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
2964
2989
|
this.apiKey = apiKey;
|
|
2965
2990
|
this.debug = debug;
|
|
2966
2991
|
this.threadCount = threadCount;
|
|
2967
2992
|
this.is_key_valid = is_key_valid;
|
|
2993
|
+
this.enableRetry = enableRetry;
|
|
2994
|
+
this.source = source;
|
|
2968
2995
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
2969
2996
|
}
|
|
2970
2997
|
/**
|
|
@@ -2996,7 +3023,7 @@ class NftService {
|
|
|
2996
3023
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
2997
3024
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
2998
3025
|
}
|
|
2999
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
|
|
3026
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
3000
3027
|
yield res;
|
|
3001
3028
|
}
|
|
3002
3029
|
success = true;
|
|
@@ -3043,6 +3070,7 @@ class NftService {
|
|
|
3043
3070
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3044
3071
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3045
3072
|
}
|
|
3073
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
|
|
3046
3074
|
let startTime;
|
|
3047
3075
|
if (this.debug) {
|
|
3048
3076
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3050,13 +3078,13 @@ class NftService {
|
|
|
3050
3078
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
|
|
3051
3079
|
headers: {
|
|
3052
3080
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3053
|
-
"X-Requested-With": userAgent
|
|
3081
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3054
3082
|
}
|
|
3055
3083
|
}));
|
|
3056
|
-
debugOutput(response.url, response.status
|
|
3057
|
-
if (response.status === null || response.status === 429) {
|
|
3084
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3085
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3058
3086
|
try {
|
|
3059
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3087
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3060
3088
|
}
|
|
3061
3089
|
catch (error) {
|
|
3062
3090
|
success = true;
|
|
@@ -3086,8 +3114,8 @@ class NftService {
|
|
|
3086
3114
|
return {
|
|
3087
3115
|
data: null,
|
|
3088
3116
|
error: true,
|
|
3089
|
-
error_code: data ? data.error_code : response.status,
|
|
3090
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3117
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3118
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3091
3119
|
};
|
|
3092
3120
|
}
|
|
3093
3121
|
}
|
|
@@ -3129,6 +3157,7 @@ class NftService {
|
|
|
3129
3157
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3130
3158
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3131
3159
|
}
|
|
3160
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
|
|
3132
3161
|
let startTime;
|
|
3133
3162
|
if (this.debug) {
|
|
3134
3163
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3136,13 +3165,13 @@ class NftService {
|
|
|
3136
3165
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
|
|
3137
3166
|
headers: {
|
|
3138
3167
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3139
|
-
"X-Requested-With": userAgent
|
|
3168
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3140
3169
|
}
|
|
3141
3170
|
}));
|
|
3142
|
-
debugOutput(response.url, response.status
|
|
3143
|
-
if (response.status === null || response.status === 429) {
|
|
3171
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3172
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3144
3173
|
try {
|
|
3145
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3174
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3146
3175
|
}
|
|
3147
3176
|
catch (error) {
|
|
3148
3177
|
success = true;
|
|
@@ -3172,8 +3201,8 @@ class NftService {
|
|
|
3172
3201
|
return {
|
|
3173
3202
|
data: null,
|
|
3174
3203
|
error: true,
|
|
3175
|
-
error_code: data ? data.error_code : response.status,
|
|
3176
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3204
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3205
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3177
3206
|
};
|
|
3178
3207
|
}
|
|
3179
3208
|
}
|
|
@@ -3220,7 +3249,7 @@ class NftService {
|
|
|
3220
3249
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3221
3250
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3222
3251
|
}
|
|
3223
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
|
|
3252
|
+
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
3224
3253
|
yield res;
|
|
3225
3254
|
}
|
|
3226
3255
|
success = true;
|
|
@@ -3280,6 +3309,7 @@ class NftService {
|
|
|
3280
3309
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3281
3310
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3282
3311
|
}
|
|
3312
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
|
|
3283
3313
|
let startTime;
|
|
3284
3314
|
if (this.debug) {
|
|
3285
3315
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3287,13 +3317,13 @@ class NftService {
|
|
|
3287
3317
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
|
|
3288
3318
|
headers: {
|
|
3289
3319
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3290
|
-
"X-Requested-With": userAgent
|
|
3320
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3291
3321
|
}
|
|
3292
3322
|
}));
|
|
3293
|
-
debugOutput(response.url, response.status
|
|
3294
|
-
if (response.status === null || response.status === 429) {
|
|
3323
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3324
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3295
3325
|
try {
|
|
3296
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3326
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3297
3327
|
}
|
|
3298
3328
|
catch (error) {
|
|
3299
3329
|
success = true;
|
|
@@ -3323,8 +3353,8 @@ class NftService {
|
|
|
3323
3353
|
return {
|
|
3324
3354
|
data: null,
|
|
3325
3355
|
error: true,
|
|
3326
|
-
error_code: data ? data.error_code : response.status,
|
|
3327
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3356
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3357
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3328
3358
|
};
|
|
3329
3359
|
}
|
|
3330
3360
|
}
|
|
@@ -3363,6 +3393,7 @@ class NftService {
|
|
|
3363
3393
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3364
3394
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3365
3395
|
}
|
|
3396
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
|
|
3366
3397
|
let startTime;
|
|
3367
3398
|
if (this.debug) {
|
|
3368
3399
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3370,13 +3401,13 @@ class NftService {
|
|
|
3370
3401
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
|
|
3371
3402
|
headers: {
|
|
3372
3403
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3373
|
-
"X-Requested-With": userAgent
|
|
3404
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3374
3405
|
}
|
|
3375
3406
|
}));
|
|
3376
|
-
debugOutput(response.url, response.status
|
|
3377
|
-
if (response.status === null || response.status === 429) {
|
|
3407
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3408
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3378
3409
|
try {
|
|
3379
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3410
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3380
3411
|
}
|
|
3381
3412
|
catch (error) {
|
|
3382
3413
|
success = true;
|
|
@@ -3406,8 +3437,8 @@ class NftService {
|
|
|
3406
3437
|
return {
|
|
3407
3438
|
data: null,
|
|
3408
3439
|
error: true,
|
|
3409
|
-
error_code: data ? data.error_code : response.status,
|
|
3410
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3440
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3441
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3411
3442
|
};
|
|
3412
3443
|
}
|
|
3413
3444
|
}
|
|
@@ -3442,6 +3473,7 @@ class NftService {
|
|
|
3442
3473
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3443
3474
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3444
3475
|
}
|
|
3476
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
|
|
3445
3477
|
let startTime;
|
|
3446
3478
|
if (this.debug) {
|
|
3447
3479
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3449,13 +3481,13 @@ class NftService {
|
|
|
3449
3481
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
|
|
3450
3482
|
headers: {
|
|
3451
3483
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3452
|
-
"X-Requested-With": userAgent
|
|
3484
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3453
3485
|
}
|
|
3454
3486
|
}));
|
|
3455
|
-
debugOutput(response.url, response.status
|
|
3456
|
-
if (response.status === null || response.status === 429) {
|
|
3487
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3488
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3457
3489
|
try {
|
|
3458
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3490
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3459
3491
|
}
|
|
3460
3492
|
catch (error) {
|
|
3461
3493
|
success = true;
|
|
@@ -3485,8 +3517,8 @@ class NftService {
|
|
|
3485
3517
|
return {
|
|
3486
3518
|
data: null,
|
|
3487
3519
|
error: true,
|
|
3488
|
-
error_code: data ? data.error_code : response.status,
|
|
3489
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3520
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3521
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3490
3522
|
};
|
|
3491
3523
|
}
|
|
3492
3524
|
}
|
|
@@ -3515,6 +3547,7 @@ class NftService {
|
|
|
3515
3547
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3516
3548
|
};
|
|
3517
3549
|
}
|
|
3550
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
|
|
3518
3551
|
let startTime;
|
|
3519
3552
|
if (this.debug) {
|
|
3520
3553
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3522,13 +3555,13 @@ class NftService {
|
|
|
3522
3555
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
|
|
3523
3556
|
headers: {
|
|
3524
3557
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3525
|
-
"X-Requested-With": userAgent
|
|
3558
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3526
3559
|
}
|
|
3527
3560
|
}));
|
|
3528
|
-
debugOutput(response.url, response.status
|
|
3529
|
-
if (response.status === null || response.status === 429) {
|
|
3561
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3562
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3530
3563
|
try {
|
|
3531
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3564
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3532
3565
|
}
|
|
3533
3566
|
catch (error) {
|
|
3534
3567
|
success = true;
|
|
@@ -3558,8 +3591,8 @@ class NftService {
|
|
|
3558
3591
|
return {
|
|
3559
3592
|
data: null,
|
|
3560
3593
|
error: true,
|
|
3561
|
-
error_code: data ? data.error_code : response.status,
|
|
3562
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3594
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3595
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3563
3596
|
};
|
|
3564
3597
|
}
|
|
3565
3598
|
}
|
|
@@ -3589,6 +3622,7 @@ class NftService {
|
|
|
3589
3622
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3590
3623
|
};
|
|
3591
3624
|
}
|
|
3625
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
|
|
3592
3626
|
let startTime;
|
|
3593
3627
|
if (this.debug) {
|
|
3594
3628
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3596,13 +3630,13 @@ class NftService {
|
|
|
3596
3630
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
|
|
3597
3631
|
headers: {
|
|
3598
3632
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3599
|
-
"X-Requested-With": userAgent
|
|
3633
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3600
3634
|
}
|
|
3601
3635
|
}));
|
|
3602
|
-
debugOutput(response.url, response.status
|
|
3603
|
-
if (response.status === null || response.status === 429) {
|
|
3636
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3637
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3604
3638
|
try {
|
|
3605
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3639
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3606
3640
|
}
|
|
3607
3641
|
catch (error) {
|
|
3608
3642
|
success = true;
|
|
@@ -3632,8 +3666,8 @@ class NftService {
|
|
|
3632
3666
|
return {
|
|
3633
3667
|
data: null,
|
|
3634
3668
|
error: true,
|
|
3635
|
-
error_code: data ? data.error_code : response.status,
|
|
3636
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3669
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3670
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3637
3671
|
};
|
|
3638
3672
|
}
|
|
3639
3673
|
}
|
|
@@ -3662,6 +3696,7 @@ class NftService {
|
|
|
3662
3696
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3663
3697
|
};
|
|
3664
3698
|
}
|
|
3699
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
|
|
3665
3700
|
let startTime;
|
|
3666
3701
|
if (this.debug) {
|
|
3667
3702
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3669,13 +3704,13 @@ class NftService {
|
|
|
3669
3704
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
|
|
3670
3705
|
headers: {
|
|
3671
3706
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3672
|
-
"X-Requested-With": userAgent
|
|
3707
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3673
3708
|
}
|
|
3674
3709
|
}));
|
|
3675
|
-
debugOutput(response.url, response.status
|
|
3676
|
-
if (response.status === null || response.status === 429) {
|
|
3710
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3711
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3677
3712
|
try {
|
|
3678
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3713
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3679
3714
|
}
|
|
3680
3715
|
catch (error) {
|
|
3681
3716
|
success = true;
|
|
@@ -3705,8 +3740,8 @@ class NftService {
|
|
|
3705
3740
|
return {
|
|
3706
3741
|
data: null,
|
|
3707
3742
|
error: true,
|
|
3708
|
-
error_code: data ? data.error_code : response.status,
|
|
3709
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3743
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3744
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3710
3745
|
};
|
|
3711
3746
|
}
|
|
3712
3747
|
}
|
|
@@ -3736,6 +3771,7 @@ class NftService {
|
|
|
3736
3771
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3737
3772
|
};
|
|
3738
3773
|
}
|
|
3774
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
|
|
3739
3775
|
let startTime;
|
|
3740
3776
|
if (this.debug) {
|
|
3741
3777
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3743,13 +3779,13 @@ class NftService {
|
|
|
3743
3779
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
|
|
3744
3780
|
headers: {
|
|
3745
3781
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3746
|
-
"X-Requested-With": userAgent
|
|
3782
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3747
3783
|
}
|
|
3748
3784
|
}));
|
|
3749
|
-
debugOutput(response.url, response.status
|
|
3750
|
-
if (response.status === null || response.status === 429) {
|
|
3785
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3786
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3751
3787
|
try {
|
|
3752
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3788
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3753
3789
|
}
|
|
3754
3790
|
catch (error) {
|
|
3755
3791
|
success = true;
|
|
@@ -3779,8 +3815,8 @@ class NftService {
|
|
|
3779
3815
|
return {
|
|
3780
3816
|
data: null,
|
|
3781
3817
|
error: true,
|
|
3782
|
-
error_code: data ? data.error_code : response.status,
|
|
3783
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3818
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3819
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3784
3820
|
};
|
|
3785
3821
|
}
|
|
3786
3822
|
}
|
|
@@ -3811,6 +3847,7 @@ class NftService {
|
|
|
3811
3847
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
3812
3848
|
};
|
|
3813
3849
|
}
|
|
3850
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
|
|
3814
3851
|
let startTime;
|
|
3815
3852
|
if (this.debug) {
|
|
3816
3853
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3818,13 +3855,13 @@ class NftService {
|
|
|
3818
3855
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
|
|
3819
3856
|
headers: {
|
|
3820
3857
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3821
|
-
"X-Requested-With": userAgent
|
|
3858
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3822
3859
|
}
|
|
3823
3860
|
}));
|
|
3824
|
-
debugOutput(response.url, response.status
|
|
3825
|
-
if (response.status === null || response.status === 429) {
|
|
3861
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3862
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3826
3863
|
try {
|
|
3827
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3864
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3828
3865
|
}
|
|
3829
3866
|
catch (error) {
|
|
3830
3867
|
success = true;
|
|
@@ -3854,8 +3891,8 @@ class NftService {
|
|
|
3854
3891
|
return {
|
|
3855
3892
|
data: null,
|
|
3856
3893
|
error: true,
|
|
3857
|
-
error_code: data ? data.error_code : response.status,
|
|
3858
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3894
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3895
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3859
3896
|
};
|
|
3860
3897
|
}
|
|
3861
3898
|
}
|
|
@@ -3893,6 +3930,7 @@ class NftService {
|
|
|
3893
3930
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3894
3931
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3895
3932
|
}
|
|
3933
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
|
|
3896
3934
|
let startTime;
|
|
3897
3935
|
if (this.debug) {
|
|
3898
3936
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3900,13 +3938,13 @@ class NftService {
|
|
|
3900
3938
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
|
|
3901
3939
|
headers: {
|
|
3902
3940
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3903
|
-
"X-Requested-With": userAgent
|
|
3941
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3904
3942
|
}
|
|
3905
3943
|
}));
|
|
3906
|
-
debugOutput(response.url, response.status
|
|
3907
|
-
if (response.status === null || response.status === 429) {
|
|
3944
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3945
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3908
3946
|
try {
|
|
3909
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
3947
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3910
3948
|
}
|
|
3911
3949
|
catch (error) {
|
|
3912
3950
|
success = true;
|
|
@@ -3936,8 +3974,8 @@ class NftService {
|
|
|
3936
3974
|
return {
|
|
3937
3975
|
data: null,
|
|
3938
3976
|
error: true,
|
|
3939
|
-
error_code: data ? data.error_code : response.status,
|
|
3940
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
3977
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
3978
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
3941
3979
|
};
|
|
3942
3980
|
}
|
|
3943
3981
|
}
|
|
@@ -3975,6 +4013,7 @@ class NftService {
|
|
|
3975
4013
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
3976
4014
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
3977
4015
|
}
|
|
4016
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
|
|
3978
4017
|
let startTime;
|
|
3979
4018
|
if (this.debug) {
|
|
3980
4019
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -3982,13 +4021,13 @@ class NftService {
|
|
|
3982
4021
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
|
|
3983
4022
|
headers: {
|
|
3984
4023
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3985
|
-
"X-Requested-With": userAgent
|
|
4024
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3986
4025
|
}
|
|
3987
4026
|
}));
|
|
3988
|
-
debugOutput(response.url, response.status
|
|
3989
|
-
if (response.status === null || response.status === 429) {
|
|
4027
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4028
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3990
4029
|
try {
|
|
3991
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4030
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3992
4031
|
}
|
|
3993
4032
|
catch (error) {
|
|
3994
4033
|
success = true;
|
|
@@ -4018,8 +4057,8 @@ class NftService {
|
|
|
4018
4057
|
return {
|
|
4019
4058
|
data: null,
|
|
4020
4059
|
error: true,
|
|
4021
|
-
error_code: data ? data.error_code : response.status,
|
|
4022
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4060
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4061
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4023
4062
|
};
|
|
4024
4063
|
}
|
|
4025
4064
|
}
|
|
@@ -4057,6 +4096,7 @@ class NftService {
|
|
|
4057
4096
|
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
4058
4097
|
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
4059
4098
|
}
|
|
4099
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
|
|
4060
4100
|
let startTime;
|
|
4061
4101
|
if (this.debug) {
|
|
4062
4102
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4064,13 +4104,13 @@ class NftService {
|
|
|
4064
4104
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
|
|
4065
4105
|
headers: {
|
|
4066
4106
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
4067
|
-
"X-Requested-With": userAgent
|
|
4107
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
4068
4108
|
}
|
|
4069
4109
|
}));
|
|
4070
|
-
debugOutput(response.url, response.status
|
|
4071
|
-
if (response.status === null || response.status === 429) {
|
|
4110
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4111
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4072
4112
|
try {
|
|
4073
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4113
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
4074
4114
|
}
|
|
4075
4115
|
catch (error) {
|
|
4076
4116
|
success = true;
|
|
@@ -4100,8 +4140,8 @@ class NftService {
|
|
|
4100
4140
|
return {
|
|
4101
4141
|
data: null,
|
|
4102
4142
|
error: true,
|
|
4103
|
-
error_code: data ? data.error_code : response.status,
|
|
4104
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4143
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4144
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4105
4145
|
};
|
|
4106
4146
|
}
|
|
4107
4147
|
}
|
|
@@ -4127,10 +4167,10 @@ class Price {
|
|
|
4127
4167
|
this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
|
|
4128
4168
|
this.price = data.price;
|
|
4129
4169
|
this.pretty_price = data.pretty_price;
|
|
4130
|
-
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$
|
|
4170
|
+
this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$2(data.contract_metadata) : null;
|
|
4131
4171
|
}
|
|
4132
4172
|
}
|
|
4133
|
-
let ContractMetadata$
|
|
4173
|
+
let ContractMetadata$2 = class ContractMetadata {
|
|
4134
4174
|
constructor(data) {
|
|
4135
4175
|
this.contract_decimals = data.contract_decimals;
|
|
4136
4176
|
this.contract_name = data.contract_name;
|
|
@@ -4141,11 +4181,13 @@ let ContractMetadata$1 = class ContractMetadata {
|
|
|
4141
4181
|
}
|
|
4142
4182
|
};
|
|
4143
4183
|
class PricingService {
|
|
4144
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
4184
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
4145
4185
|
this.apiKey = apiKey;
|
|
4146
4186
|
this.debug = debug;
|
|
4147
4187
|
this.threadCount = threadCount;
|
|
4148
4188
|
this.is_key_valid = is_key_valid;
|
|
4189
|
+
this.enableRetry = enableRetry;
|
|
4190
|
+
this.source = source;
|
|
4149
4191
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
4150
4192
|
}
|
|
4151
4193
|
/**
|
|
@@ -4186,6 +4228,7 @@ class PricingService {
|
|
|
4186
4228
|
if (queryParamOpts?.pricesAtAsc !== undefined) {
|
|
4187
4229
|
urlParams.append("prices-at-asc", queryParamOpts?.pricesAtAsc.toString());
|
|
4188
4230
|
}
|
|
4231
|
+
const url = `https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`;
|
|
4189
4232
|
let startTime;
|
|
4190
4233
|
if (this.debug) {
|
|
4191
4234
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -4193,13 +4236,13 @@ class PricingService {
|
|
|
4193
4236
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`, {
|
|
4194
4237
|
headers: {
|
|
4195
4238
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
4196
|
-
"X-Requested-With": userAgent
|
|
4239
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
4197
4240
|
}
|
|
4198
4241
|
}));
|
|
4199
|
-
debugOutput(response.url, response.status
|
|
4200
|
-
if (response.status === null || response.status === 429) {
|
|
4242
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4243
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4201
4244
|
try {
|
|
4202
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4245
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
4203
4246
|
}
|
|
4204
4247
|
catch (error) {
|
|
4205
4248
|
success = true;
|
|
@@ -4233,8 +4276,8 @@ class PricingService {
|
|
|
4233
4276
|
return {
|
|
4234
4277
|
data: null,
|
|
4235
4278
|
error: true,
|
|
4236
|
-
error_code: data ? data.error_code : response.status,
|
|
4237
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4279
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4280
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4238
4281
|
};
|
|
4239
4282
|
}
|
|
4240
4283
|
}
|
|
@@ -4272,7 +4315,7 @@ class Transaction {
|
|
|
4272
4315
|
this.gas_quote = data.gas_quote;
|
|
4273
4316
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
4274
4317
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
4275
|
-
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
4318
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata$1(data.gas_metadata) : null;
|
|
4276
4319
|
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
|
|
4277
4320
|
this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
|
|
4278
4321
|
this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
|
|
@@ -4281,7 +4324,7 @@ class Transaction {
|
|
|
4281
4324
|
this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
|
|
4282
4325
|
}
|
|
4283
4326
|
}
|
|
4284
|
-
class ContractMetadata {
|
|
4327
|
+
let ContractMetadata$1 = class ContractMetadata {
|
|
4285
4328
|
constructor(data) {
|
|
4286
4329
|
this.contract_decimals = data.contract_decimals;
|
|
4287
4330
|
this.contract_name = data.contract_name;
|
|
@@ -4290,7 +4333,7 @@ class ContractMetadata {
|
|
|
4290
4333
|
this.supports_erc = data.supports_erc;
|
|
4291
4334
|
this.logo_url = data.logo_url;
|
|
4292
4335
|
}
|
|
4293
|
-
}
|
|
4336
|
+
};
|
|
4294
4337
|
class Explorer {
|
|
4295
4338
|
constructor(data) {
|
|
4296
4339
|
this.label = data.label;
|
|
@@ -4455,11 +4498,13 @@ class Param {
|
|
|
4455
4498
|
}
|
|
4456
4499
|
}
|
|
4457
4500
|
class RecentTransactionsResponse {
|
|
4458
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4501
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4459
4502
|
this._debug = _debug;
|
|
4460
4503
|
this._apiKey = _apiKey;
|
|
4461
4504
|
this._threadCount = _threadCount;
|
|
4462
4505
|
this._urlParams = _urlParams;
|
|
4506
|
+
this._enableRetry = _enableRetry;
|
|
4507
|
+
this._source = _source;
|
|
4463
4508
|
this.address = data.address;
|
|
4464
4509
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4465
4510
|
this.quote_currency = data.quote_currency;
|
|
@@ -4490,16 +4535,17 @@ class RecentTransactionsResponse {
|
|
|
4490
4535
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4491
4536
|
};
|
|
4492
4537
|
}
|
|
4538
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4493
4539
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4494
4540
|
headers: {
|
|
4495
4541
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4496
|
-
"X-Requested-With": userAgent
|
|
4542
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4497
4543
|
}
|
|
4498
4544
|
}));
|
|
4499
|
-
debugOutput(response.url, response.status
|
|
4500
|
-
if (response.status === null || response.status === 429) {
|
|
4545
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4546
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4501
4547
|
try {
|
|
4502
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4548
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4503
4549
|
}
|
|
4504
4550
|
catch (error) {
|
|
4505
4551
|
success = true;
|
|
@@ -4514,7 +4560,7 @@ class RecentTransactionsResponse {
|
|
|
4514
4560
|
else {
|
|
4515
4561
|
data = await response.json();
|
|
4516
4562
|
}
|
|
4517
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4563
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4518
4564
|
checkAndModifyResponse(dataClass);
|
|
4519
4565
|
success = true;
|
|
4520
4566
|
return {
|
|
@@ -4529,8 +4575,8 @@ class RecentTransactionsResponse {
|
|
|
4529
4575
|
return {
|
|
4530
4576
|
data: null,
|
|
4531
4577
|
error: true,
|
|
4532
|
-
error_code: data ? data.error_code : response.status,
|
|
4533
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4578
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4579
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4534
4580
|
};
|
|
4535
4581
|
}
|
|
4536
4582
|
}
|
|
@@ -4556,16 +4602,17 @@ class RecentTransactionsResponse {
|
|
|
4556
4602
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4557
4603
|
};
|
|
4558
4604
|
}
|
|
4605
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4559
4606
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4560
4607
|
headers: {
|
|
4561
4608
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4562
|
-
"X-Requested-With": userAgent
|
|
4609
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4563
4610
|
}
|
|
4564
4611
|
}));
|
|
4565
|
-
debugOutput(response.url, response.status
|
|
4566
|
-
if (response.status === null || response.status === 429) {
|
|
4612
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4613
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4567
4614
|
try {
|
|
4568
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4615
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4569
4616
|
}
|
|
4570
4617
|
catch (error) {
|
|
4571
4618
|
success = true;
|
|
@@ -4580,7 +4627,7 @@ class RecentTransactionsResponse {
|
|
|
4580
4627
|
else {
|
|
4581
4628
|
data = await response.json();
|
|
4582
4629
|
}
|
|
4583
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4630
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4584
4631
|
checkAndModifyResponse(dataClass);
|
|
4585
4632
|
success = true;
|
|
4586
4633
|
return {
|
|
@@ -4595,8 +4642,8 @@ class RecentTransactionsResponse {
|
|
|
4595
4642
|
return {
|
|
4596
4643
|
data: null,
|
|
4597
4644
|
error: true,
|
|
4598
|
-
error_code: data ? data.error_code : response.status,
|
|
4599
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4645
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4646
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4600
4647
|
};
|
|
4601
4648
|
}
|
|
4602
4649
|
}
|
|
@@ -4608,6 +4655,155 @@ class PaginationLinks {
|
|
|
4608
4655
|
this.next = data.next;
|
|
4609
4656
|
}
|
|
4610
4657
|
}
|
|
4658
|
+
class TransactionsBlockPageResponse {
|
|
4659
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4660
|
+
this._debug = _debug;
|
|
4661
|
+
this._apiKey = _apiKey;
|
|
4662
|
+
this._threadCount = _threadCount;
|
|
4663
|
+
this._urlParams = _urlParams;
|
|
4664
|
+
this._enableRetry = _enableRetry;
|
|
4665
|
+
this._source = _source;
|
|
4666
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4667
|
+
this.chain_id = data.chain_id;
|
|
4668
|
+
this.chain_name = data.chain_name;
|
|
4669
|
+
this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
|
|
4670
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
|
|
4671
|
+
}
|
|
4672
|
+
async prev() {
|
|
4673
|
+
let success = false;
|
|
4674
|
+
let data;
|
|
4675
|
+
let response;
|
|
4676
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4677
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4678
|
+
while (!success) {
|
|
4679
|
+
try {
|
|
4680
|
+
let startTime;
|
|
4681
|
+
if (this._debug) {
|
|
4682
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4683
|
+
}
|
|
4684
|
+
if (this.links.prev === null) {
|
|
4685
|
+
success = true;
|
|
4686
|
+
return {
|
|
4687
|
+
data: null,
|
|
4688
|
+
error: true,
|
|
4689
|
+
error_code: 400,
|
|
4690
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4691
|
+
};
|
|
4692
|
+
}
|
|
4693
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4694
|
+
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4695
|
+
headers: {
|
|
4696
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4697
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4698
|
+
}
|
|
4699
|
+
}));
|
|
4700
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4701
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4702
|
+
try {
|
|
4703
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4704
|
+
}
|
|
4705
|
+
catch (error) {
|
|
4706
|
+
success = true;
|
|
4707
|
+
return {
|
|
4708
|
+
data: null,
|
|
4709
|
+
error: true,
|
|
4710
|
+
error_code: response.status ?? 429,
|
|
4711
|
+
error_message: error.message
|
|
4712
|
+
};
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
else {
|
|
4716
|
+
data = await response.json();
|
|
4717
|
+
}
|
|
4718
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4719
|
+
checkAndModifyResponse(dataClass);
|
|
4720
|
+
success = true;
|
|
4721
|
+
return {
|
|
4722
|
+
data: dataClass,
|
|
4723
|
+
error: data.error,
|
|
4724
|
+
error_code: data ? data.error_code : response.status,
|
|
4725
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4726
|
+
};
|
|
4727
|
+
}
|
|
4728
|
+
catch (error) {
|
|
4729
|
+
success = true;
|
|
4730
|
+
return {
|
|
4731
|
+
data: null,
|
|
4732
|
+
error: true,
|
|
4733
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4734
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4735
|
+
};
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
async next() {
|
|
4740
|
+
let success = false;
|
|
4741
|
+
let data;
|
|
4742
|
+
let response;
|
|
4743
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4744
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4745
|
+
while (!success) {
|
|
4746
|
+
try {
|
|
4747
|
+
let startTime;
|
|
4748
|
+
if (this._debug) {
|
|
4749
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4750
|
+
}
|
|
4751
|
+
if (this.links.next === null) {
|
|
4752
|
+
success = true;
|
|
4753
|
+
return {
|
|
4754
|
+
data: null,
|
|
4755
|
+
error: true,
|
|
4756
|
+
error_code: 400,
|
|
4757
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4758
|
+
};
|
|
4759
|
+
}
|
|
4760
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4761
|
+
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4762
|
+
headers: {
|
|
4763
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4764
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4765
|
+
}
|
|
4766
|
+
}));
|
|
4767
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4768
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4769
|
+
try {
|
|
4770
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4771
|
+
}
|
|
4772
|
+
catch (error) {
|
|
4773
|
+
success = true;
|
|
4774
|
+
return {
|
|
4775
|
+
data: null,
|
|
4776
|
+
error: true,
|
|
4777
|
+
error_code: response.status ?? 429,
|
|
4778
|
+
error_message: error.message
|
|
4779
|
+
};
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
else {
|
|
4783
|
+
data = await response.json();
|
|
4784
|
+
}
|
|
4785
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4786
|
+
checkAndModifyResponse(dataClass);
|
|
4787
|
+
success = true;
|
|
4788
|
+
return {
|
|
4789
|
+
data: dataClass,
|
|
4790
|
+
error: data.error,
|
|
4791
|
+
error_code: data ? data.error_code : response.status,
|
|
4792
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4793
|
+
};
|
|
4794
|
+
}
|
|
4795
|
+
catch (error) {
|
|
4796
|
+
success = true;
|
|
4797
|
+
return {
|
|
4798
|
+
data: null,
|
|
4799
|
+
error: true,
|
|
4800
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4801
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4802
|
+
};
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4611
4807
|
class TransactionsBlockResponse {
|
|
4612
4808
|
constructor(data) {
|
|
4613
4809
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
@@ -4640,11 +4836,13 @@ class TransactionSummary {
|
|
|
4640
4836
|
}
|
|
4641
4837
|
}
|
|
4642
4838
|
class TransactionsResponse {
|
|
4643
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4839
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4644
4840
|
this._debug = _debug;
|
|
4645
4841
|
this._apiKey = _apiKey;
|
|
4646
4842
|
this._threadCount = _threadCount;
|
|
4647
4843
|
this._urlParams = _urlParams;
|
|
4844
|
+
this._enableRetry = _enableRetry;
|
|
4845
|
+
this._source = _source;
|
|
4648
4846
|
this.address = data.address;
|
|
4649
4847
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4650
4848
|
this.quote_currency = data.quote_currency;
|
|
@@ -4675,16 +4873,17 @@ class TransactionsResponse {
|
|
|
4675
4873
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4676
4874
|
};
|
|
4677
4875
|
}
|
|
4876
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4678
4877
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4679
4878
|
headers: {
|
|
4680
4879
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4681
|
-
"X-Requested-With": userAgent
|
|
4880
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4682
4881
|
}
|
|
4683
4882
|
}));
|
|
4684
|
-
debugOutput(response.url, response.status
|
|
4685
|
-
if (response.status === null || response.status === 429) {
|
|
4883
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4884
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4686
4885
|
try {
|
|
4687
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4886
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4688
4887
|
}
|
|
4689
4888
|
catch (error) {
|
|
4690
4889
|
success = true;
|
|
@@ -4699,7 +4898,7 @@ class TransactionsResponse {
|
|
|
4699
4898
|
else {
|
|
4700
4899
|
data = await response.json();
|
|
4701
4900
|
}
|
|
4702
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4901
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4703
4902
|
checkAndModifyResponse(dataClass);
|
|
4704
4903
|
success = true;
|
|
4705
4904
|
return {
|
|
@@ -4714,8 +4913,8 @@ class TransactionsResponse {
|
|
|
4714
4913
|
return {
|
|
4715
4914
|
data: null,
|
|
4716
4915
|
error: true,
|
|
4717
|
-
error_code: data ? data.error_code : response.status,
|
|
4718
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4916
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4917
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4719
4918
|
};
|
|
4720
4919
|
}
|
|
4721
4920
|
}
|
|
@@ -4741,16 +4940,17 @@ class TransactionsResponse {
|
|
|
4741
4940
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4742
4941
|
};
|
|
4743
4942
|
}
|
|
4943
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4744
4944
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4745
4945
|
headers: {
|
|
4746
4946
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4747
|
-
"X-Requested-With": userAgent
|
|
4947
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4748
4948
|
}
|
|
4749
4949
|
}));
|
|
4750
|
-
debugOutput(response.url, response.status
|
|
4751
|
-
if (response.status === null || response.status === 429) {
|
|
4950
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4951
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4752
4952
|
try {
|
|
4753
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4953
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4754
4954
|
}
|
|
4755
4955
|
catch (error) {
|
|
4756
4956
|
success = true;
|
|
@@ -4765,7 +4965,7 @@ class TransactionsResponse {
|
|
|
4765
4965
|
else {
|
|
4766
4966
|
data = await response.json();
|
|
4767
4967
|
}
|
|
4768
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4968
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4769
4969
|
checkAndModifyResponse(dataClass);
|
|
4770
4970
|
success = true;
|
|
4771
4971
|
return {
|
|
@@ -4780,19 +4980,21 @@ class TransactionsResponse {
|
|
|
4780
4980
|
return {
|
|
4781
4981
|
data: null,
|
|
4782
4982
|
error: true,
|
|
4783
|
-
error_code: data ? data.error_code : response.status,
|
|
4784
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4983
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4984
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4785
4985
|
};
|
|
4786
4986
|
}
|
|
4787
4987
|
}
|
|
4788
4988
|
}
|
|
4789
4989
|
}
|
|
4790
4990
|
class TransactionsTimeBucketResponse {
|
|
4791
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4991
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4792
4992
|
this._debug = _debug;
|
|
4793
4993
|
this._apiKey = _apiKey;
|
|
4794
4994
|
this._threadCount = _threadCount;
|
|
4795
4995
|
this._urlParams = _urlParams;
|
|
4996
|
+
this._enableRetry = _enableRetry;
|
|
4997
|
+
this._source = _source;
|
|
4796
4998
|
this.address = data.address;
|
|
4797
4999
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
4798
5000
|
this.quote_currency = data.quote_currency;
|
|
@@ -4824,16 +5026,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4824
5026
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4825
5027
|
};
|
|
4826
5028
|
}
|
|
5029
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4827
5030
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4828
5031
|
headers: {
|
|
4829
5032
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4830
|
-
"X-Requested-With": userAgent
|
|
5033
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4831
5034
|
}
|
|
4832
5035
|
}));
|
|
4833
|
-
debugOutput(response.url, response.status
|
|
4834
|
-
if (response.status === null || response.status === 429) {
|
|
5036
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5037
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4835
5038
|
try {
|
|
4836
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
5039
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4837
5040
|
}
|
|
4838
5041
|
catch (error) {
|
|
4839
5042
|
success = true;
|
|
@@ -4848,7 +5051,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4848
5051
|
else {
|
|
4849
5052
|
data = await response.json();
|
|
4850
5053
|
}
|
|
4851
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
5054
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4852
5055
|
checkAndModifyResponse(dataClass);
|
|
4853
5056
|
success = true;
|
|
4854
5057
|
return {
|
|
@@ -4863,8 +5066,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4863
5066
|
return {
|
|
4864
5067
|
data: null,
|
|
4865
5068
|
error: true,
|
|
4866
|
-
error_code: data ? data.error_code : response.status,
|
|
4867
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5069
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5070
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4868
5071
|
};
|
|
4869
5072
|
}
|
|
4870
5073
|
}
|
|
@@ -4890,16 +5093,17 @@ class TransactionsTimeBucketResponse {
|
|
|
4890
5093
|
error_message: "Invalid URL: URL link cannot be null"
|
|
4891
5094
|
};
|
|
4892
5095
|
}
|
|
5096
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4893
5097
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4894
5098
|
headers: {
|
|
4895
5099
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4896
|
-
"X-Requested-With": userAgent
|
|
5100
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4897
5101
|
}
|
|
4898
5102
|
}));
|
|
4899
|
-
debugOutput(response.url, response.status
|
|
4900
|
-
if (response.status === null || response.status === 429) {
|
|
5103
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5104
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4901
5105
|
try {
|
|
4902
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
5106
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4903
5107
|
}
|
|
4904
5108
|
catch (error) {
|
|
4905
5109
|
success = true;
|
|
@@ -4914,7 +5118,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4914
5118
|
else {
|
|
4915
5119
|
data = await response.json();
|
|
4916
5120
|
}
|
|
4917
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
5121
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4918
5122
|
checkAndModifyResponse(dataClass);
|
|
4919
5123
|
success = true;
|
|
4920
5124
|
return {
|
|
@@ -4929,8 +5133,8 @@ class TransactionsTimeBucketResponse {
|
|
|
4929
5133
|
return {
|
|
4930
5134
|
data: null,
|
|
4931
5135
|
error: true,
|
|
4932
|
-
error_code: data ? data.error_code : response.status,
|
|
4933
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5136
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5137
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4934
5138
|
};
|
|
4935
5139
|
}
|
|
4936
5140
|
}
|
|
@@ -4940,7 +5144,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4940
5144
|
* Transactions APIs
|
|
4941
5145
|
*
|
|
4942
5146
|
*/
|
|
4943
|
-
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
5147
|
+
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
|
|
4944
5148
|
let hasNext = true;
|
|
4945
5149
|
let response;
|
|
4946
5150
|
let data;
|
|
@@ -4955,17 +5159,17 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4955
5159
|
response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
|
|
4956
5160
|
headers: {
|
|
4957
5161
|
"Authorization": `Bearer ${apiKey}`,
|
|
4958
|
-
"X-Requested-With": userAgent
|
|
5162
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
4959
5163
|
}
|
|
4960
5164
|
}));
|
|
4961
|
-
debugOutput(response.url, response.status
|
|
4962
|
-
if (response.status === null || response.status === 429) {
|
|
5165
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5166
|
+
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4963
5167
|
try {
|
|
4964
|
-
data = await LIMIT(() => backoff.backOff(response.url));
|
|
5168
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
|
|
4965
5169
|
}
|
|
4966
5170
|
catch (error) {
|
|
4967
5171
|
hasNext = false;
|
|
4968
|
-
throw new Error(`An error occurred ${response.status}: ${error.message}`);
|
|
5172
|
+
throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
|
|
4969
5173
|
}
|
|
4970
5174
|
}
|
|
4971
5175
|
else {
|
|
@@ -4997,11 +5201,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
|
|
|
4997
5201
|
}
|
|
4998
5202
|
}
|
|
4999
5203
|
class TransactionService {
|
|
5000
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
5204
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
5001
5205
|
this.apiKey = apiKey;
|
|
5002
5206
|
this.debug = debug;
|
|
5003
5207
|
this.threadCount = threadCount;
|
|
5004
5208
|
this.is_key_valid = is_key_valid;
|
|
5209
|
+
this.enableRetry = enableRetry;
|
|
5210
|
+
this.source = source;
|
|
5005
5211
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
5006
5212
|
}
|
|
5007
5213
|
/**
|
|
@@ -5057,16 +5263,17 @@ class TransactionService {
|
|
|
5057
5263
|
if (this.debug) {
|
|
5058
5264
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5059
5265
|
}
|
|
5266
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
|
|
5060
5267
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
5061
5268
|
headers: {
|
|
5062
5269
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5063
|
-
"X-Requested-With": userAgent
|
|
5270
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5064
5271
|
}
|
|
5065
5272
|
}));
|
|
5066
|
-
debugOutput(response.url, response.status
|
|
5067
|
-
if (response.status === null || response.status === 429) {
|
|
5273
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5274
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5068
5275
|
try {
|
|
5069
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5276
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5070
5277
|
}
|
|
5071
5278
|
catch (error) {
|
|
5072
5279
|
success = true;
|
|
@@ -5096,8 +5303,8 @@ class TransactionService {
|
|
|
5096
5303
|
return {
|
|
5097
5304
|
data: null,
|
|
5098
5305
|
error: true,
|
|
5099
|
-
error_code: data ? data.error_code : response.status,
|
|
5100
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5306
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5307
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5101
5308
|
};
|
|
5102
5309
|
}
|
|
5103
5310
|
}
|
|
@@ -5136,7 +5343,7 @@ class TransactionService {
|
|
|
5136
5343
|
if (queryParamOpts?.withSafe !== undefined) {
|
|
5137
5344
|
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5138
5345
|
}
|
|
5139
|
-
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
|
|
5346
|
+
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
5140
5347
|
yield tx;
|
|
5141
5348
|
}
|
|
5142
5349
|
success = true;
|
|
@@ -5192,16 +5399,17 @@ class TransactionService {
|
|
|
5192
5399
|
if (this.debug) {
|
|
5193
5400
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5194
5401
|
}
|
|
5402
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
|
|
5195
5403
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
5196
5404
|
headers: {
|
|
5197
5405
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5198
|
-
"X-Requested-With": userAgent
|
|
5406
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5199
5407
|
}
|
|
5200
5408
|
}));
|
|
5201
|
-
debugOutput(response.url, response.status
|
|
5202
|
-
if (response.status === null || response.status === 429) {
|
|
5409
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5410
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5203
5411
|
try {
|
|
5204
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5412
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5205
5413
|
}
|
|
5206
5414
|
catch (error) {
|
|
5207
5415
|
success = true;
|
|
@@ -5216,7 +5424,7 @@ class TransactionService {
|
|
|
5216
5424
|
else {
|
|
5217
5425
|
data = await response.json();
|
|
5218
5426
|
}
|
|
5219
|
-
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5427
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5220
5428
|
checkAndModifyResponse(dataClass);
|
|
5221
5429
|
success = true;
|
|
5222
5430
|
return {
|
|
@@ -5231,8 +5439,8 @@ class TransactionService {
|
|
|
5231
5439
|
return {
|
|
5232
5440
|
data: null,
|
|
5233
5441
|
error: true,
|
|
5234
|
-
error_code: data ? data.error_code : response.status,
|
|
5235
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5442
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5443
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5236
5444
|
};
|
|
5237
5445
|
}
|
|
5238
5446
|
}
|
|
@@ -5278,16 +5486,17 @@ class TransactionService {
|
|
|
5278
5486
|
if (this.debug) {
|
|
5279
5487
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5280
5488
|
}
|
|
5489
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
|
|
5281
5490
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
5282
5491
|
headers: {
|
|
5283
5492
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5284
|
-
"X-Requested-With": userAgent
|
|
5493
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5285
5494
|
}
|
|
5286
5495
|
}));
|
|
5287
|
-
debugOutput(response.url, response.status
|
|
5288
|
-
if (response.status === null || response.status === 429) {
|
|
5496
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5497
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5289
5498
|
try {
|
|
5290
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5499
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5291
5500
|
}
|
|
5292
5501
|
catch (error) {
|
|
5293
5502
|
success = true;
|
|
@@ -5317,8 +5526,8 @@ class TransactionService {
|
|
|
5317
5526
|
return {
|
|
5318
5527
|
data: null,
|
|
5319
5528
|
error: true,
|
|
5320
|
-
error_code: data ? data.error_code : response.status,
|
|
5321
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5529
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5530
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5322
5531
|
};
|
|
5323
5532
|
}
|
|
5324
5533
|
}
|
|
@@ -5351,16 +5560,17 @@ class TransactionService {
|
|
|
5351
5560
|
if (this.debug) {
|
|
5352
5561
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5353
5562
|
}
|
|
5563
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
|
|
5354
5564
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
5355
5565
|
headers: {
|
|
5356
5566
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5357
|
-
"X-Requested-With": userAgent
|
|
5567
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5358
5568
|
}
|
|
5359
5569
|
}));
|
|
5360
|
-
debugOutput(response.url, response.status
|
|
5361
|
-
if (response.status === null || response.status === 429) {
|
|
5570
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5571
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5362
5572
|
try {
|
|
5363
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5573
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5364
5574
|
}
|
|
5365
5575
|
catch (error) {
|
|
5366
5576
|
success = true;
|
|
@@ -5390,8 +5600,8 @@ class TransactionService {
|
|
|
5390
5600
|
return {
|
|
5391
5601
|
data: null,
|
|
5392
5602
|
error: true,
|
|
5393
|
-
error_code: data ? data.error_code : response.status,
|
|
5394
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5603
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5604
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5395
5605
|
};
|
|
5396
5606
|
}
|
|
5397
5607
|
}
|
|
@@ -5440,16 +5650,17 @@ class TransactionService {
|
|
|
5440
5650
|
if (this.debug) {
|
|
5441
5651
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5442
5652
|
}
|
|
5653
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
|
|
5443
5654
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5444
5655
|
headers: {
|
|
5445
5656
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5446
|
-
"X-Requested-With": userAgent
|
|
5657
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5447
5658
|
}
|
|
5448
5659
|
}));
|
|
5449
|
-
debugOutput(response.url, response.status
|
|
5450
|
-
if (response.status === null || response.status === 429) {
|
|
5660
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5661
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5451
5662
|
try {
|
|
5452
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5663
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5453
5664
|
}
|
|
5454
5665
|
catch (error) {
|
|
5455
5666
|
success = true;
|
|
@@ -5464,7 +5675,7 @@ class TransactionService {
|
|
|
5464
5675
|
else {
|
|
5465
5676
|
data = await response.json();
|
|
5466
5677
|
}
|
|
5467
|
-
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5678
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5468
5679
|
checkAndModifyResponse(dataClass);
|
|
5469
5680
|
success = true;
|
|
5470
5681
|
return {
|
|
@@ -5479,8 +5690,8 @@ class TransactionService {
|
|
|
5479
5690
|
return {
|
|
5480
5691
|
data: null,
|
|
5481
5692
|
error: true,
|
|
5482
|
-
error_code: data ? data.error_code : response.status,
|
|
5483
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5693
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5694
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5484
5695
|
};
|
|
5485
5696
|
}
|
|
5486
5697
|
}
|
|
@@ -5525,16 +5736,17 @@ class TransactionService {
|
|
|
5525
5736
|
if (this.debug) {
|
|
5526
5737
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5527
5738
|
}
|
|
5739
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
|
|
5528
5740
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
5529
5741
|
headers: {
|
|
5530
5742
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5531
|
-
"X-Requested-With": userAgent
|
|
5743
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5532
5744
|
}
|
|
5533
5745
|
}));
|
|
5534
|
-
debugOutput(response.url, response.status
|
|
5535
|
-
if (response.status === null || response.status === 429) {
|
|
5746
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5747
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5536
5748
|
try {
|
|
5537
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
5749
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5538
5750
|
}
|
|
5539
5751
|
catch (error) {
|
|
5540
5752
|
success = true;
|
|
@@ -5549,7 +5761,7 @@ class TransactionService {
|
|
|
5549
5761
|
else {
|
|
5550
5762
|
data = await response.json();
|
|
5551
5763
|
}
|
|
5552
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
5764
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5553
5765
|
checkAndModifyResponse(dataClass);
|
|
5554
5766
|
success = true;
|
|
5555
5767
|
return {
|
|
@@ -5564,40 +5776,215 @@ class TransactionService {
|
|
|
5564
5776
|
return {
|
|
5565
5777
|
data: null,
|
|
5566
5778
|
error: true,
|
|
5567
|
-
error_code: data ? data.error_code : response.status,
|
|
5568
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5779
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5780
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5569
5781
|
};
|
|
5570
5782
|
}
|
|
5571
5783
|
}
|
|
5572
5784
|
}
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5785
|
+
/**
|
|
5786
|
+
*
|
|
5787
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
5788
|
+
*
|
|
5789
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
5790
|
+
* @param {string} blockHash - The requested block hash.
|
|
5791
|
+
* @param {number} page - The requested 0-indexed page number.
|
|
5792
|
+
* @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
|
|
5793
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
5794
|
+
* - `noLogs`: Omit log events.
|
|
5795
|
+
* - `withSafe`: Include safe details.
|
|
5796
|
+
*
|
|
5797
|
+
*/
|
|
5798
|
+
async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
|
|
5799
|
+
let success = false;
|
|
5800
|
+
let data;
|
|
5801
|
+
let response;
|
|
5802
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
5803
|
+
while (!success) {
|
|
5804
|
+
try {
|
|
5805
|
+
const urlParams = new URLSearchParams();
|
|
5806
|
+
if (!this.is_key_valid) {
|
|
5807
|
+
return {
|
|
5808
|
+
data: null,
|
|
5809
|
+
error: true,
|
|
5810
|
+
error_code: 401,
|
|
5811
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
5812
|
+
};
|
|
5813
|
+
}
|
|
5814
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
5815
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
5816
|
+
}
|
|
5817
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
5818
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
5819
|
+
}
|
|
5820
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
5821
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5822
|
+
}
|
|
5823
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
|
|
5824
|
+
let startTime;
|
|
5825
|
+
if (this.debug) {
|
|
5826
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5827
|
+
}
|
|
5828
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5829
|
+
headers: {
|
|
5830
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
5831
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5832
|
+
}
|
|
5833
|
+
}));
|
|
5834
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5835
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5836
|
+
try {
|
|
5837
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5838
|
+
}
|
|
5839
|
+
catch (error) {
|
|
5840
|
+
success = true;
|
|
5841
|
+
return {
|
|
5842
|
+
data: null,
|
|
5843
|
+
error: true,
|
|
5844
|
+
error_code: response.status ?? 429,
|
|
5845
|
+
error_message: error.message
|
|
5846
|
+
};
|
|
5847
|
+
}
|
|
5848
|
+
}
|
|
5849
|
+
else {
|
|
5850
|
+
data = await response.json();
|
|
5851
|
+
}
|
|
5852
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5853
|
+
checkAndModifyResponse(dataClass);
|
|
5854
|
+
success = true;
|
|
5855
|
+
return {
|
|
5856
|
+
data: dataClass,
|
|
5857
|
+
error: data.error,
|
|
5858
|
+
error_code: data ? data.error_code : response.status,
|
|
5859
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5860
|
+
};
|
|
5861
|
+
}
|
|
5862
|
+
catch (error) {
|
|
5863
|
+
success = true;
|
|
5864
|
+
return {
|
|
5865
|
+
data: null,
|
|
5866
|
+
error: true,
|
|
5867
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5868
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5869
|
+
};
|
|
5870
|
+
}
|
|
5871
|
+
}
|
|
5872
|
+
}
|
|
5873
|
+
/**
|
|
5874
|
+
*
|
|
5875
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
5876
|
+
*
|
|
5877
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
5878
|
+
* @param {string} blockHash - The requested block hash.
|
|
5879
|
+
* @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
|
|
5880
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
5881
|
+
* - `noLogs`: Omit log events.
|
|
5882
|
+
* - `withSafe`: Include safe details.
|
|
5883
|
+
*
|
|
5884
|
+
*/
|
|
5885
|
+
async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
|
|
5886
|
+
let success = false;
|
|
5887
|
+
let data;
|
|
5888
|
+
let response;
|
|
5889
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
5890
|
+
while (!success) {
|
|
5891
|
+
try {
|
|
5892
|
+
const urlParams = new URLSearchParams();
|
|
5893
|
+
if (!this.is_key_valid) {
|
|
5894
|
+
return {
|
|
5895
|
+
data: null,
|
|
5896
|
+
error: true,
|
|
5897
|
+
error_code: 401,
|
|
5898
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
5899
|
+
};
|
|
5900
|
+
}
|
|
5901
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
5902
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
5903
|
+
}
|
|
5904
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
5905
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
5906
|
+
}
|
|
5907
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
5908
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5909
|
+
}
|
|
5910
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
|
|
5911
|
+
let startTime;
|
|
5912
|
+
if (this.debug) {
|
|
5913
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5914
|
+
}
|
|
5915
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
|
|
5916
|
+
headers: {
|
|
5917
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
5918
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5919
|
+
}
|
|
5920
|
+
}));
|
|
5921
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5922
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5923
|
+
try {
|
|
5924
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5925
|
+
}
|
|
5926
|
+
catch (error) {
|
|
5927
|
+
success = true;
|
|
5928
|
+
return {
|
|
5929
|
+
data: null,
|
|
5930
|
+
error: true,
|
|
5931
|
+
error_code: response.status ?? 429,
|
|
5932
|
+
error_message: error.message
|
|
5933
|
+
};
|
|
5934
|
+
}
|
|
5935
|
+
}
|
|
5936
|
+
else {
|
|
5937
|
+
data = await response.json();
|
|
5938
|
+
}
|
|
5939
|
+
const dataClass = new TransactionsBlockResponse(data.data);
|
|
5940
|
+
checkAndModifyResponse(dataClass);
|
|
5941
|
+
success = true;
|
|
5942
|
+
return {
|
|
5943
|
+
data: dataClass,
|
|
5944
|
+
error: data.error,
|
|
5945
|
+
error_code: data ? data.error_code : response.status,
|
|
5946
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5947
|
+
};
|
|
5948
|
+
}
|
|
5949
|
+
catch (error) {
|
|
5950
|
+
success = true;
|
|
5951
|
+
return {
|
|
5952
|
+
data: null,
|
|
5953
|
+
error: true,
|
|
5954
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5955
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5956
|
+
};
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5959
|
+
}
|
|
5960
|
+
}
|
|
5961
|
+
|
|
5962
|
+
class PoolResponse {
|
|
5963
|
+
constructor(data) {
|
|
5964
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
5965
|
+
this.chain_id = data.chain_id;
|
|
5966
|
+
this.chain_name = data.chain_name;
|
|
5967
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Pool(itemData)) : null;
|
|
5968
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
5969
|
+
}
|
|
5970
|
+
}
|
|
5971
|
+
class Pool {
|
|
5972
|
+
constructor(data) {
|
|
5973
|
+
this.exchange = data.exchange;
|
|
5974
|
+
this.swap_count_24h = data.swap_count_24h;
|
|
5975
|
+
this.total_liquidity_quote = data.total_liquidity_quote;
|
|
5976
|
+
this.volume_24h_quote = data.volume_24h_quote;
|
|
5977
|
+
this.fee_24h_quote = data.fee_24h_quote;
|
|
5978
|
+
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
5979
|
+
this.quote_rate = data.quote_rate;
|
|
5980
|
+
this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
|
|
5981
|
+
this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
|
|
5982
|
+
this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
|
|
5983
|
+
this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
|
|
5984
|
+
this.chain_name = data.chain_name;
|
|
5985
|
+
this.chain_id = data.chain_id;
|
|
5986
|
+
this.dex_name = data.dex_name;
|
|
5987
|
+
this.volume_7d_quote = data.volume_7d_quote;
|
|
5601
5988
|
this.annualized_fee = data.annualized_fee;
|
|
5602
5989
|
this.token_0 = data.token_0 && data.token_0 !== null ? new Token(data.token_0) : null;
|
|
5603
5990
|
this.token_1 = data.token_1 && data.token_1 !== null ? new Token(data.token_1) : null;
|
|
@@ -5761,6 +6148,7 @@ class PoolsDexDataItem {
|
|
|
5761
6148
|
this.volume_24h_quote = data.volume_24h_quote;
|
|
5762
6149
|
this.volume_7d_quote = data.volume_7d_quote;
|
|
5763
6150
|
this.fee_24h_quote = data.fee_24h_quote;
|
|
6151
|
+
this.annualized_fee = data.annualized_fee;
|
|
5764
6152
|
this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
|
|
5765
6153
|
this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
|
|
5766
6154
|
this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
|
|
@@ -5803,6 +6191,7 @@ class UniswapLikeToken {
|
|
|
5803
6191
|
this.logo_url = data.logo_url;
|
|
5804
6192
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5805
6193
|
this.quote = data.quote;
|
|
6194
|
+
this.pretty_quote = data.pretty_quote;
|
|
5806
6195
|
this.quote_rate = data.quote_rate;
|
|
5807
6196
|
}
|
|
5808
6197
|
}
|
|
@@ -5814,6 +6203,7 @@ class UniswapLikeTokenWithSupply {
|
|
|
5814
6203
|
this.logo_url = data.logo_url;
|
|
5815
6204
|
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5816
6205
|
this.quote = data.quote;
|
|
6206
|
+
this.pretty_quote = data.pretty_quote;
|
|
5817
6207
|
this.quote_rate = data.quote_rate;
|
|
5818
6208
|
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
5819
6209
|
}
|
|
@@ -5850,6 +6240,75 @@ class TokenV2Volume {
|
|
|
5850
6240
|
this.total_volume_24h_quote = data.total_volume_24h_quote;
|
|
5851
6241
|
}
|
|
5852
6242
|
}
|
|
6243
|
+
class NetworkExchangeTokenViewResponse {
|
|
6244
|
+
constructor(data) {
|
|
6245
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
6246
|
+
this.chain_id = data.chain_id;
|
|
6247
|
+
this.chain_name = data.chain_name;
|
|
6248
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
|
|
6249
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
class TokenV2VolumeWithChartData {
|
|
6253
|
+
constructor(data) {
|
|
6254
|
+
this.chain_name = data.chain_name;
|
|
6255
|
+
this.chain_id = data.chain_id;
|
|
6256
|
+
this.dex_name = data.dex_name;
|
|
6257
|
+
this.contract_address = data.contract_address;
|
|
6258
|
+
this.contract_name = data.contract_name;
|
|
6259
|
+
this.total_liquidity = data.total_liquidity;
|
|
6260
|
+
this.total_volume_24h = data.total_volume_24h;
|
|
6261
|
+
this.logo_url = data.logo_url;
|
|
6262
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
6263
|
+
this.contract_decimals = data.contract_decimals;
|
|
6264
|
+
this.swap_count_24h = data.swap_count_24h;
|
|
6265
|
+
this.quote_rate = data.quote_rate;
|
|
6266
|
+
this.quote_rate_24h = data.quote_rate_24h;
|
|
6267
|
+
this.pretty_quote_rate = data.pretty_quote_rate;
|
|
6268
|
+
this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
|
|
6269
|
+
this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
|
|
6270
|
+
this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
|
|
6271
|
+
this.total_liquidity_quote = data.total_liquidity_quote;
|
|
6272
|
+
this.total_volume_24h_quote = data.total_volume_24h_quote;
|
|
6273
|
+
this.transactions_24h = data.transactions_24h;
|
|
6274
|
+
this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
|
|
6275
|
+
this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
|
|
6276
|
+
this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
|
|
6277
|
+
this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
|
|
6278
|
+
this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
|
|
6279
|
+
this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
class VolumeTokenTimeseries {
|
|
6283
|
+
constructor(data) {
|
|
6284
|
+
this.dex_name = data.dex_name;
|
|
6285
|
+
this.chain_id = data.chain_id;
|
|
6286
|
+
this.dt = data.dt;
|
|
6287
|
+
this.total_volume = data.total_volume;
|
|
6288
|
+
this.volume_quote = data.volume_quote;
|
|
6289
|
+
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
class LiquidityTokenTimeseries {
|
|
6293
|
+
constructor(data) {
|
|
6294
|
+
this.dex_name = data.dex_name;
|
|
6295
|
+
this.chain_id = data.chain_id;
|
|
6296
|
+
this.dt = data.dt;
|
|
6297
|
+
this.total_liquidity = data.total_liquidity;
|
|
6298
|
+
this.liquidity_quote = data.liquidity_quote;
|
|
6299
|
+
this.pretty_liquidity_quote = data.pretty_liquidity_quote;
|
|
6300
|
+
}
|
|
6301
|
+
}
|
|
6302
|
+
class PriceTokenTimeseries {
|
|
6303
|
+
constructor(data) {
|
|
6304
|
+
this.dex_name = data.dex_name;
|
|
6305
|
+
this.chain_id = data.chain_id;
|
|
6306
|
+
this.dt = data.dt;
|
|
6307
|
+
this.quote_currency = data.quote_currency;
|
|
6308
|
+
this.quote_rate = data.quote_rate;
|
|
6309
|
+
this.pretty_quote_rate = data.pretty_quote_rate;
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
5853
6312
|
class SupportedDexesResponse {
|
|
5854
6313
|
constructor(data) {
|
|
5855
6314
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
@@ -5892,12 +6351,34 @@ class ExchangeTransaction {
|
|
|
5892
6351
|
this.sender_address = data.sender_address;
|
|
5893
6352
|
this.total_quote = data.total_quote;
|
|
5894
6353
|
this.pretty_total_quote = data.pretty_total_quote;
|
|
6354
|
+
this.value = data.value && data.value !== null ? BigInt(data.value) : null;
|
|
6355
|
+
this.value_quote = data.value_quote;
|
|
6356
|
+
this.pretty_value_quote = data.pretty_value_quote;
|
|
6357
|
+
this.gas_offered = data.gas_offered;
|
|
6358
|
+
this.gas_spent = data.gas_spent;
|
|
6359
|
+
this.gas_price = data.gas_price;
|
|
6360
|
+
this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
6361
|
+
this.gas_quote = data.gas_quote;
|
|
6362
|
+
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
6363
|
+
this.gas_quote_rate = data.gas_quote_rate;
|
|
6364
|
+
this.quote_currency = data.quote_currency;
|
|
5895
6365
|
this.token_0_quote_rate = data.token_0_quote_rate;
|
|
5896
6366
|
this.token_1_quote_rate = data.token_1_quote_rate;
|
|
6367
|
+
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
5897
6368
|
this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
|
|
5898
6369
|
this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
|
|
5899
6370
|
}
|
|
5900
6371
|
}
|
|
6372
|
+
class ContractMetadata {
|
|
6373
|
+
constructor(data) {
|
|
6374
|
+
this.contract_decimals = data.contract_decimals;
|
|
6375
|
+
this.contract_name = data.contract_name;
|
|
6376
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
6377
|
+
this.contract_address = data.contract_address;
|
|
6378
|
+
this.supports_erc = data.supports_erc;
|
|
6379
|
+
this.logo_url = data.logo_url;
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
5901
6382
|
class PoolToken {
|
|
5902
6383
|
constructor(data) {
|
|
5903
6384
|
this.contract_decimals = data.contract_decimals;
|
|
@@ -5926,6 +6407,15 @@ class TransactionsForExchangeResponse {
|
|
|
5926
6407
|
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
5927
6408
|
}
|
|
5928
6409
|
}
|
|
6410
|
+
class NetworkTransactionsResponse {
|
|
6411
|
+
constructor(data) {
|
|
6412
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
6413
|
+
this.chain_id = data.chain_id;
|
|
6414
|
+
this.chain_name = data.chain_name;
|
|
6415
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
|
|
6416
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
6417
|
+
}
|
|
6418
|
+
}
|
|
5929
6419
|
class EcosystemChartDataResponse {
|
|
5930
6420
|
constructor(data) {
|
|
5931
6421
|
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
@@ -5941,13 +6431,15 @@ class UniswapLikeEcosystemCharts {
|
|
|
5941
6431
|
this.chain_id = data.chain_id;
|
|
5942
6432
|
this.quote_currency = data.quote_currency;
|
|
5943
6433
|
this.gas_token_price_quote = data.gas_token_price_quote;
|
|
5944
|
-
this.
|
|
5945
|
-
this.
|
|
5946
|
-
this.
|
|
5947
|
-
this.
|
|
5948
|
-
this.
|
|
5949
|
-
this.
|
|
5950
|
-
this.
|
|
6434
|
+
this.total_swaps_24h = data.total_swaps_24h;
|
|
6435
|
+
this.total_active_pairs_7d = data.total_active_pairs_7d;
|
|
6436
|
+
this.total_fees_24h = data.total_fees_24h;
|
|
6437
|
+
this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
|
|
6438
|
+
this.pretty_total_fees_24h = data.pretty_total_fees_24h;
|
|
6439
|
+
this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6440
|
+
this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
|
|
6441
|
+
this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
6442
|
+
this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
|
|
5951
6443
|
}
|
|
5952
6444
|
}
|
|
5953
6445
|
class VolumeEcosystemChart {
|
|
@@ -5957,6 +6449,7 @@ class VolumeEcosystemChart {
|
|
|
5957
6449
|
this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
|
|
5958
6450
|
this.quote_currency = data.quote_currency;
|
|
5959
6451
|
this.volume_quote = data.volume_quote;
|
|
6452
|
+
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
5960
6453
|
this.swap_count_24 = data.swap_count_24;
|
|
5961
6454
|
}
|
|
5962
6455
|
}
|
|
@@ -5967,6 +6460,7 @@ class LiquidityEcosystemChart {
|
|
|
5967
6460
|
this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
|
|
5968
6461
|
this.quote_currency = data.quote_currency;
|
|
5969
6462
|
this.liquidity_quote = data.liquidity_quote;
|
|
6463
|
+
this.pretty_liquidity_quote = data.pretty_liquidity_quote;
|
|
5970
6464
|
}
|
|
5971
6465
|
}
|
|
5972
6466
|
class HealthDataResponse {
|
|
@@ -5991,11 +6485,13 @@ class HealthData {
|
|
|
5991
6485
|
*
|
|
5992
6486
|
*/
|
|
5993
6487
|
class XykService {
|
|
5994
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
|
|
6488
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
5995
6489
|
this.apiKey = apiKey;
|
|
5996
6490
|
this.debug = debug;
|
|
5997
6491
|
this.threadCount = threadCount;
|
|
5998
6492
|
this.is_key_valid = is_key_valid;
|
|
6493
|
+
this.enableRetry = enableRetry;
|
|
6494
|
+
this.source = source;
|
|
5999
6495
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
6000
6496
|
}
|
|
6001
6497
|
/**
|
|
@@ -6004,9 +6500,12 @@ class XykService {
|
|
|
6004
6500
|
*
|
|
6005
6501
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6006
6502
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6503
|
+
* @param {GetPoolsQueryParamOpts} queryParamOpts
|
|
6504
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6505
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6007
6506
|
*
|
|
6008
6507
|
*/
|
|
6009
|
-
async getPools(chainName, dexName) {
|
|
6508
|
+
async getPools(chainName, dexName, queryParamOpts) {
|
|
6010
6509
|
let success = false;
|
|
6011
6510
|
let data;
|
|
6012
6511
|
let response;
|
|
@@ -6014,6 +6513,13 @@ class XykService {
|
|
|
6014
6513
|
while (!success) {
|
|
6015
6514
|
try {
|
|
6016
6515
|
const urlParams = new URLSearchParams();
|
|
6516
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6517
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6518
|
+
}
|
|
6519
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
6520
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
6521
|
+
}
|
|
6522
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
|
|
6017
6523
|
if (!this.is_key_valid) {
|
|
6018
6524
|
return {
|
|
6019
6525
|
data: null,
|
|
@@ -6029,13 +6535,13 @@ class XykService {
|
|
|
6029
6535
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
|
|
6030
6536
|
headers: {
|
|
6031
6537
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6032
|
-
"X-Requested-With": userAgent
|
|
6538
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6033
6539
|
}
|
|
6034
6540
|
}));
|
|
6035
|
-
debugOutput(response.url, response.status
|
|
6036
|
-
if (response.status === null || response.status === 429) {
|
|
6541
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6542
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6037
6543
|
try {
|
|
6038
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6544
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6039
6545
|
}
|
|
6040
6546
|
catch (error) {
|
|
6041
6547
|
success = true;
|
|
@@ -6065,8 +6571,8 @@ class XykService {
|
|
|
6065
6571
|
return {
|
|
6066
6572
|
data: null,
|
|
6067
6573
|
error: true,
|
|
6068
|
-
error_code: data ? data.error_code : response.status,
|
|
6069
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6574
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6575
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6070
6576
|
};
|
|
6071
6577
|
}
|
|
6072
6578
|
}
|
|
@@ -6087,6 +6593,7 @@ class XykService {
|
|
|
6087
6593
|
while (!success) {
|
|
6088
6594
|
try {
|
|
6089
6595
|
const urlParams = new URLSearchParams();
|
|
6596
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
|
|
6090
6597
|
if (!this.is_key_valid) {
|
|
6091
6598
|
return {
|
|
6092
6599
|
data: null,
|
|
@@ -6102,13 +6609,13 @@ class XykService {
|
|
|
6102
6609
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
|
|
6103
6610
|
headers: {
|
|
6104
6611
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6105
|
-
"X-Requested-With": userAgent
|
|
6612
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6106
6613
|
}
|
|
6107
6614
|
}));
|
|
6108
|
-
debugOutput(response.url, response.status
|
|
6109
|
-
if (response.status === null || response.status === 429) {
|
|
6615
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6616
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6110
6617
|
try {
|
|
6111
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6618
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6112
6619
|
}
|
|
6113
6620
|
catch (error) {
|
|
6114
6621
|
success = true;
|
|
@@ -6138,8 +6645,8 @@ class XykService {
|
|
|
6138
6645
|
return {
|
|
6139
6646
|
data: null,
|
|
6140
6647
|
error: true,
|
|
6141
|
-
error_code: data ? data.error_code : response.status,
|
|
6142
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6648
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6649
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6143
6650
|
};
|
|
6144
6651
|
}
|
|
6145
6652
|
}
|
|
@@ -6161,6 +6668,7 @@ class XykService {
|
|
|
6161
6668
|
while (!success) {
|
|
6162
6669
|
try {
|
|
6163
6670
|
const urlParams = new URLSearchParams();
|
|
6671
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
|
|
6164
6672
|
if (!this.is_key_valid) {
|
|
6165
6673
|
return {
|
|
6166
6674
|
data: null,
|
|
@@ -6176,13 +6684,13 @@ class XykService {
|
|
|
6176
6684
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
|
|
6177
6685
|
headers: {
|
|
6178
6686
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6179
|
-
"X-Requested-With": userAgent
|
|
6687
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6180
6688
|
}
|
|
6181
6689
|
}));
|
|
6182
|
-
debugOutput(response.url, response.status
|
|
6183
|
-
if (response.status === null || response.status === 429) {
|
|
6690
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6691
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6184
6692
|
try {
|
|
6185
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6693
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6186
6694
|
}
|
|
6187
6695
|
catch (error) {
|
|
6188
6696
|
success = true;
|
|
@@ -6212,8 +6720,8 @@ class XykService {
|
|
|
6212
6720
|
return {
|
|
6213
6721
|
data: null,
|
|
6214
6722
|
error: true,
|
|
6215
|
-
error_code: data ? data.error_code : response.status,
|
|
6216
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6723
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6724
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6217
6725
|
};
|
|
6218
6726
|
}
|
|
6219
6727
|
}
|
|
@@ -6227,6 +6735,8 @@ class XykService {
|
|
|
6227
6735
|
* @param {number} page - The requested 0-indexed page number.
|
|
6228
6736
|
* @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
|
|
6229
6737
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
6738
|
+
* - `dexName`: The DEX name eg: `uniswap_v2`.
|
|
6739
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6230
6740
|
*
|
|
6231
6741
|
*/
|
|
6232
6742
|
async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
|
|
@@ -6251,6 +6761,10 @@ class XykService {
|
|
|
6251
6761
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6252
6762
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6253
6763
|
}
|
|
6764
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6765
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6766
|
+
}
|
|
6767
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
|
|
6254
6768
|
let startTime;
|
|
6255
6769
|
if (this.debug) {
|
|
6256
6770
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6258,13 +6772,13 @@ class XykService {
|
|
|
6258
6772
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
|
|
6259
6773
|
headers: {
|
|
6260
6774
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6261
|
-
"X-Requested-With": userAgent
|
|
6775
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6262
6776
|
}
|
|
6263
6777
|
}));
|
|
6264
|
-
debugOutput(response.url, response.status
|
|
6265
|
-
if (response.status === null || response.status === 429) {
|
|
6778
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6779
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6266
6780
|
try {
|
|
6267
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6781
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6268
6782
|
}
|
|
6269
6783
|
catch (error) {
|
|
6270
6784
|
success = true;
|
|
@@ -6294,8 +6808,8 @@ class XykService {
|
|
|
6294
6808
|
return {
|
|
6295
6809
|
data: null,
|
|
6296
6810
|
error: true,
|
|
6297
|
-
error_code: data ? data.error_code : response.status,
|
|
6298
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6811
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6812
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6299
6813
|
};
|
|
6300
6814
|
}
|
|
6301
6815
|
}
|
|
@@ -6325,6 +6839,7 @@ class XykService {
|
|
|
6325
6839
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6326
6840
|
};
|
|
6327
6841
|
}
|
|
6842
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
|
|
6328
6843
|
let startTime;
|
|
6329
6844
|
if (this.debug) {
|
|
6330
6845
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6332,13 +6847,13 @@ class XykService {
|
|
|
6332
6847
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
|
|
6333
6848
|
headers: {
|
|
6334
6849
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6335
|
-
"X-Requested-With": userAgent
|
|
6850
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6336
6851
|
}
|
|
6337
6852
|
}));
|
|
6338
|
-
debugOutput(response.url, response.status
|
|
6339
|
-
if (response.status === null || response.status === 429) {
|
|
6853
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6854
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6340
6855
|
try {
|
|
6341
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6856
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6342
6857
|
}
|
|
6343
6858
|
catch (error) {
|
|
6344
6859
|
success = true;
|
|
@@ -6368,8 +6883,8 @@ class XykService {
|
|
|
6368
6883
|
return {
|
|
6369
6884
|
data: null,
|
|
6370
6885
|
error: true,
|
|
6371
|
-
error_code: data ? data.error_code : response.status,
|
|
6372
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6886
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6887
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6373
6888
|
};
|
|
6374
6889
|
}
|
|
6375
6890
|
}
|
|
@@ -6384,6 +6899,8 @@ class XykService {
|
|
|
6384
6899
|
* @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
|
|
6385
6900
|
* - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
6386
6901
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
6902
|
+
* - `dexName`: The DEX name eg: `uniswap_v2`.
|
|
6903
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6387
6904
|
*
|
|
6388
6905
|
*/
|
|
6389
6906
|
async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
|
|
@@ -6411,6 +6928,10 @@ class XykService {
|
|
|
6411
6928
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6412
6929
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6413
6930
|
}
|
|
6931
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6932
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6933
|
+
}
|
|
6934
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
|
|
6414
6935
|
let startTime;
|
|
6415
6936
|
if (this.debug) {
|
|
6416
6937
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6418,13 +6939,13 @@ class XykService {
|
|
|
6418
6939
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
|
|
6419
6940
|
headers: {
|
|
6420
6941
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6421
|
-
"X-Requested-With": userAgent
|
|
6942
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6422
6943
|
}
|
|
6423
6944
|
}));
|
|
6424
|
-
debugOutput(response.url, response.status
|
|
6425
|
-
if (response.status === null || response.status === 429) {
|
|
6945
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6946
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6426
6947
|
try {
|
|
6427
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
6948
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6428
6949
|
}
|
|
6429
6950
|
catch (error) {
|
|
6430
6951
|
success = true;
|
|
@@ -6454,8 +6975,8 @@ class XykService {
|
|
|
6454
6975
|
return {
|
|
6455
6976
|
data: null,
|
|
6456
6977
|
error: true,
|
|
6457
|
-
error_code: data ? data.error_code : response.status,
|
|
6458
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6978
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
6979
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6459
6980
|
};
|
|
6460
6981
|
}
|
|
6461
6982
|
}
|
|
@@ -6466,9 +6987,12 @@ class XykService {
|
|
|
6466
6987
|
*
|
|
6467
6988
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6468
6989
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6990
|
+
* @param {GetNetworkExchangeTokensQueryParamOpts} queryParamOpts
|
|
6991
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6992
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6469
6993
|
*
|
|
6470
6994
|
*/
|
|
6471
|
-
async getNetworkExchangeTokens(chainName, dexName) {
|
|
6995
|
+
async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
|
|
6472
6996
|
let success = false;
|
|
6473
6997
|
let data;
|
|
6474
6998
|
let response;
|
|
@@ -6476,6 +7000,12 @@ class XykService {
|
|
|
6476
7000
|
while (!success) {
|
|
6477
7001
|
try {
|
|
6478
7002
|
const urlParams = new URLSearchParams();
|
|
7003
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7004
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7005
|
+
}
|
|
7006
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7007
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7008
|
+
}
|
|
6479
7009
|
if (!this.is_key_valid) {
|
|
6480
7010
|
return {
|
|
6481
7011
|
data: null,
|
|
@@ -6484,6 +7014,7 @@ class XykService {
|
|
|
6484
7014
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6485
7015
|
};
|
|
6486
7016
|
}
|
|
7017
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
|
|
6487
7018
|
let startTime;
|
|
6488
7019
|
if (this.debug) {
|
|
6489
7020
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6491,13 +7022,13 @@ class XykService {
|
|
|
6491
7022
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
|
|
6492
7023
|
headers: {
|
|
6493
7024
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6494
|
-
"X-Requested-With": userAgent
|
|
7025
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6495
7026
|
}
|
|
6496
7027
|
}));
|
|
6497
|
-
debugOutput(response.url, response.status
|
|
6498
|
-
if (response.status === null || response.status === 429) {
|
|
7028
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7029
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6499
7030
|
try {
|
|
6500
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7031
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6501
7032
|
}
|
|
6502
7033
|
catch (error) {
|
|
6503
7034
|
success = true;
|
|
@@ -6527,10 +7058,90 @@ class XykService {
|
|
|
6527
7058
|
return {
|
|
6528
7059
|
data: null,
|
|
6529
7060
|
error: true,
|
|
7061
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7062
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7063
|
+
};
|
|
7064
|
+
}
|
|
7065
|
+
}
|
|
7066
|
+
}
|
|
7067
|
+
/**
|
|
7068
|
+
*
|
|
7069
|
+
* Commonly used to get a detailed view for a single liquidity pool token. Includes time series data.
|
|
7070
|
+
*
|
|
7071
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
7072
|
+
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
7073
|
+
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7074
|
+
* @param {GetLpTokenViewQueryParamOpts} queryParamOpts
|
|
7075
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
7076
|
+
*
|
|
7077
|
+
*/
|
|
7078
|
+
async getLpTokenView(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
7079
|
+
let success = false;
|
|
7080
|
+
let data;
|
|
7081
|
+
let response;
|
|
7082
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
7083
|
+
while (!success) {
|
|
7084
|
+
try {
|
|
7085
|
+
const urlParams = new URLSearchParams();
|
|
7086
|
+
if (!this.is_key_valid) {
|
|
7087
|
+
return {
|
|
7088
|
+
data: null,
|
|
7089
|
+
error: true,
|
|
7090
|
+
error_code: 401,
|
|
7091
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
7092
|
+
};
|
|
7093
|
+
}
|
|
7094
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
7095
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
7096
|
+
}
|
|
7097
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`;
|
|
7098
|
+
let startTime;
|
|
7099
|
+
if (this.debug) {
|
|
7100
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
7101
|
+
}
|
|
7102
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`, {
|
|
7103
|
+
headers: {
|
|
7104
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
7105
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7106
|
+
}
|
|
7107
|
+
}));
|
|
7108
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7109
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7110
|
+
try {
|
|
7111
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7112
|
+
}
|
|
7113
|
+
catch (error) {
|
|
7114
|
+
success = true;
|
|
7115
|
+
return {
|
|
7116
|
+
data: null,
|
|
7117
|
+
error: true,
|
|
7118
|
+
error_code: response.status ?? 429,
|
|
7119
|
+
error_message: error.message
|
|
7120
|
+
};
|
|
7121
|
+
}
|
|
7122
|
+
}
|
|
7123
|
+
else {
|
|
7124
|
+
data = await response.json();
|
|
7125
|
+
}
|
|
7126
|
+
const dataClass = new NetworkExchangeTokenViewResponse(data.data);
|
|
7127
|
+
checkAndModifyResponse(dataClass);
|
|
7128
|
+
success = true;
|
|
7129
|
+
return {
|
|
7130
|
+
data: dataClass,
|
|
7131
|
+
error: data.error,
|
|
6530
7132
|
error_code: data ? data.error_code : response.status,
|
|
6531
7133
|
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6532
7134
|
};
|
|
6533
7135
|
}
|
|
7136
|
+
catch (error) {
|
|
7137
|
+
success = true;
|
|
7138
|
+
return {
|
|
7139
|
+
data: null,
|
|
7140
|
+
error: true,
|
|
7141
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7142
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7143
|
+
};
|
|
7144
|
+
}
|
|
6534
7145
|
}
|
|
6535
7146
|
}
|
|
6536
7147
|
/**
|
|
@@ -6555,6 +7166,7 @@ class XykService {
|
|
|
6555
7166
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6556
7167
|
};
|
|
6557
7168
|
}
|
|
7169
|
+
const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
|
|
6558
7170
|
let startTime;
|
|
6559
7171
|
if (this.debug) {
|
|
6560
7172
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6562,13 +7174,13 @@ class XykService {
|
|
|
6562
7174
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
|
|
6563
7175
|
headers: {
|
|
6564
7176
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6565
|
-
"X-Requested-With": userAgent
|
|
7177
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6566
7178
|
}
|
|
6567
7179
|
}));
|
|
6568
|
-
debugOutput(response.url, response.status
|
|
6569
|
-
if (response.status === null || response.status === 429) {
|
|
7180
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7181
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6570
7182
|
try {
|
|
6571
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7183
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6572
7184
|
}
|
|
6573
7185
|
catch (error) {
|
|
6574
7186
|
success = true;
|
|
@@ -6598,8 +7210,8 @@ class XykService {
|
|
|
6598
7210
|
return {
|
|
6599
7211
|
data: null,
|
|
6600
7212
|
error: true,
|
|
6601
|
-
error_code: data ? data.error_code : response.status,
|
|
6602
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7213
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7214
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6603
7215
|
};
|
|
6604
7216
|
}
|
|
6605
7217
|
}
|
|
@@ -6611,9 +7223,12 @@ class XykService {
|
|
|
6611
7223
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6612
7224
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6613
7225
|
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7226
|
+
* @param {GetSingleNetworkExchangeTokenQueryParamOpts} queryParamOpts
|
|
7227
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7228
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6614
7229
|
*
|
|
6615
7230
|
*/
|
|
6616
|
-
async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
|
|
7231
|
+
async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
6617
7232
|
let success = false;
|
|
6618
7233
|
let data;
|
|
6619
7234
|
let response;
|
|
@@ -6621,6 +7236,12 @@ class XykService {
|
|
|
6621
7236
|
while (!success) {
|
|
6622
7237
|
try {
|
|
6623
7238
|
const urlParams = new URLSearchParams();
|
|
7239
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7240
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7241
|
+
}
|
|
7242
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7243
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7244
|
+
}
|
|
6624
7245
|
if (!this.is_key_valid) {
|
|
6625
7246
|
return {
|
|
6626
7247
|
data: null,
|
|
@@ -6629,6 +7250,7 @@ class XykService {
|
|
|
6629
7250
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6630
7251
|
};
|
|
6631
7252
|
}
|
|
7253
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
|
|
6632
7254
|
let startTime;
|
|
6633
7255
|
if (this.debug) {
|
|
6634
7256
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6636,13 +7258,13 @@ class XykService {
|
|
|
6636
7258
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
|
|
6637
7259
|
headers: {
|
|
6638
7260
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6639
|
-
"X-Requested-With": userAgent
|
|
7261
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6640
7262
|
}
|
|
6641
7263
|
}));
|
|
6642
|
-
debugOutput(response.url, response.status
|
|
6643
|
-
if (response.status === null || response.status === 429) {
|
|
7264
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7265
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6644
7266
|
try {
|
|
6645
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7267
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6646
7268
|
}
|
|
6647
7269
|
catch (error) {
|
|
6648
7270
|
success = true;
|
|
@@ -6672,8 +7294,8 @@ class XykService {
|
|
|
6672
7294
|
return {
|
|
6673
7295
|
data: null,
|
|
6674
7296
|
error: true,
|
|
6675
|
-
error_code: data ? data.error_code : response.status,
|
|
6676
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7297
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7298
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6677
7299
|
};
|
|
6678
7300
|
}
|
|
6679
7301
|
}
|
|
@@ -6703,6 +7325,7 @@ class XykService {
|
|
|
6703
7325
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6704
7326
|
};
|
|
6705
7327
|
}
|
|
7328
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
|
|
6706
7329
|
let startTime;
|
|
6707
7330
|
if (this.debug) {
|
|
6708
7331
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6710,13 +7333,13 @@ class XykService {
|
|
|
6710
7333
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
|
|
6711
7334
|
headers: {
|
|
6712
7335
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6713
|
-
"X-Requested-With": userAgent
|
|
7336
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6714
7337
|
}
|
|
6715
7338
|
}));
|
|
6716
|
-
debugOutput(response.url, response.status
|
|
6717
|
-
if (response.status === null || response.status === 429) {
|
|
7339
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7340
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6718
7341
|
try {
|
|
6719
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7342
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6720
7343
|
}
|
|
6721
7344
|
catch (error) {
|
|
6722
7345
|
success = true;
|
|
@@ -6746,8 +7369,8 @@ class XykService {
|
|
|
6746
7369
|
return {
|
|
6747
7370
|
data: null,
|
|
6748
7371
|
error: true,
|
|
6749
|
-
error_code: data ? data.error_code : response.status,
|
|
6750
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7372
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7373
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6751
7374
|
};
|
|
6752
7375
|
}
|
|
6753
7376
|
}
|
|
@@ -6759,9 +7382,12 @@ class XykService {
|
|
|
6759
7382
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6760
7383
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6761
7384
|
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7385
|
+
* @param {GetTransactionsForTokenAddressQueryParamOpts} queryParamOpts
|
|
7386
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7387
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6762
7388
|
*
|
|
6763
7389
|
*/
|
|
6764
|
-
async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
|
|
7390
|
+
async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
6765
7391
|
let success = false;
|
|
6766
7392
|
let data;
|
|
6767
7393
|
let response;
|
|
@@ -6777,6 +7403,13 @@ class XykService {
|
|
|
6777
7403
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6778
7404
|
};
|
|
6779
7405
|
}
|
|
7406
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7407
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7408
|
+
}
|
|
7409
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7410
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7411
|
+
}
|
|
7412
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
|
|
6780
7413
|
let startTime;
|
|
6781
7414
|
if (this.debug) {
|
|
6782
7415
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6784,13 +7417,13 @@ class XykService {
|
|
|
6784
7417
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
|
|
6785
7418
|
headers: {
|
|
6786
7419
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6787
|
-
"X-Requested-With": userAgent
|
|
7420
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6788
7421
|
}
|
|
6789
7422
|
}));
|
|
6790
|
-
debugOutput(response.url, response.status
|
|
6791
|
-
if (response.status === null || response.status === 429) {
|
|
7423
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7424
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6792
7425
|
try {
|
|
6793
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7426
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6794
7427
|
}
|
|
6795
7428
|
catch (error) {
|
|
6796
7429
|
success = true;
|
|
@@ -6820,8 +7453,8 @@ class XykService {
|
|
|
6820
7453
|
return {
|
|
6821
7454
|
data: null,
|
|
6822
7455
|
error: true,
|
|
6823
|
-
error_code: data ? data.error_code : response.status,
|
|
6824
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7456
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7457
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6825
7458
|
};
|
|
6826
7459
|
}
|
|
6827
7460
|
}
|
|
@@ -6833,9 +7466,12 @@ class XykService {
|
|
|
6833
7466
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6834
7467
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6835
7468
|
* @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7469
|
+
* @param {GetTransactionsForExchangeQueryParamOpts} queryParamOpts
|
|
7470
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7471
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6836
7472
|
*
|
|
6837
7473
|
*/
|
|
6838
|
-
async getTransactionsForExchange(chainName, dexName, poolAddress) {
|
|
7474
|
+
async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
|
|
6839
7475
|
let success = false;
|
|
6840
7476
|
let data;
|
|
6841
7477
|
let response;
|
|
@@ -6851,6 +7487,13 @@ class XykService {
|
|
|
6851
7487
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6852
7488
|
};
|
|
6853
7489
|
}
|
|
7490
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7491
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7492
|
+
}
|
|
7493
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7494
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7495
|
+
}
|
|
7496
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
|
|
6854
7497
|
let startTime;
|
|
6855
7498
|
if (this.debug) {
|
|
6856
7499
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6858,13 +7501,13 @@ class XykService {
|
|
|
6858
7501
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
|
|
6859
7502
|
headers: {
|
|
6860
7503
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6861
|
-
"X-Requested-With": userAgent
|
|
7504
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6862
7505
|
}
|
|
6863
7506
|
}));
|
|
6864
|
-
debugOutput(response.url, response.status
|
|
6865
|
-
if (response.status === null || response.status === 429) {
|
|
7507
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7508
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6866
7509
|
try {
|
|
6867
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7510
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6868
7511
|
}
|
|
6869
7512
|
catch (error) {
|
|
6870
7513
|
success = true;
|
|
@@ -6894,10 +7537,97 @@ class XykService {
|
|
|
6894
7537
|
return {
|
|
6895
7538
|
data: null,
|
|
6896
7539
|
error: true,
|
|
7540
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7541
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7542
|
+
};
|
|
7543
|
+
}
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
/**
|
|
7547
|
+
*
|
|
7548
|
+
* Commonly used to get all the the transactions for a given DEX. Useful for building DEX activity views.
|
|
7549
|
+
*
|
|
7550
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
7551
|
+
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
7552
|
+
* @param {GetTransactionsForDexQueryParamOpts} queryParamOpts
|
|
7553
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
7554
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7555
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
7556
|
+
*
|
|
7557
|
+
*/
|
|
7558
|
+
async getTransactionsForDex(chainName, dexName, queryParamOpts) {
|
|
7559
|
+
let success = false;
|
|
7560
|
+
let data;
|
|
7561
|
+
let response;
|
|
7562
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
7563
|
+
while (!success) {
|
|
7564
|
+
try {
|
|
7565
|
+
const urlParams = new URLSearchParams();
|
|
7566
|
+
if (!this.is_key_valid) {
|
|
7567
|
+
return {
|
|
7568
|
+
data: null,
|
|
7569
|
+
error: true,
|
|
7570
|
+
error_code: 401,
|
|
7571
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
7572
|
+
};
|
|
7573
|
+
}
|
|
7574
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
7575
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
7576
|
+
}
|
|
7577
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7578
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7579
|
+
}
|
|
7580
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7581
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7582
|
+
}
|
|
7583
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`;
|
|
7584
|
+
let startTime;
|
|
7585
|
+
if (this.debug) {
|
|
7586
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
7587
|
+
}
|
|
7588
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`, {
|
|
7589
|
+
headers: {
|
|
7590
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
7591
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7592
|
+
}
|
|
7593
|
+
}));
|
|
7594
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7595
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7596
|
+
try {
|
|
7597
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7598
|
+
}
|
|
7599
|
+
catch (error) {
|
|
7600
|
+
success = true;
|
|
7601
|
+
return {
|
|
7602
|
+
data: null,
|
|
7603
|
+
error: true,
|
|
7604
|
+
error_code: response.status ?? 429,
|
|
7605
|
+
error_message: error.message
|
|
7606
|
+
};
|
|
7607
|
+
}
|
|
7608
|
+
}
|
|
7609
|
+
else {
|
|
7610
|
+
data = await response.json();
|
|
7611
|
+
}
|
|
7612
|
+
const dataClass = new NetworkTransactionsResponse(data.data);
|
|
7613
|
+
checkAndModifyResponse(dataClass);
|
|
7614
|
+
success = true;
|
|
7615
|
+
return {
|
|
7616
|
+
data: dataClass,
|
|
7617
|
+
error: data.error,
|
|
6897
7618
|
error_code: data ? data.error_code : response.status,
|
|
6898
7619
|
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
6899
7620
|
};
|
|
6900
7621
|
}
|
|
7622
|
+
catch (error) {
|
|
7623
|
+
success = true;
|
|
7624
|
+
return {
|
|
7625
|
+
data: null,
|
|
7626
|
+
error: true,
|
|
7627
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7628
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7629
|
+
};
|
|
7630
|
+
}
|
|
6901
7631
|
}
|
|
6902
7632
|
}
|
|
6903
7633
|
/**
|
|
@@ -6924,6 +7654,7 @@ class XykService {
|
|
|
6924
7654
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6925
7655
|
};
|
|
6926
7656
|
}
|
|
7657
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
|
|
6927
7658
|
let startTime;
|
|
6928
7659
|
if (this.debug) {
|
|
6929
7660
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -6931,13 +7662,13 @@ class XykService {
|
|
|
6931
7662
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
|
|
6932
7663
|
headers: {
|
|
6933
7664
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6934
|
-
"X-Requested-With": userAgent
|
|
7665
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6935
7666
|
}
|
|
6936
7667
|
}));
|
|
6937
|
-
debugOutput(response.url, response.status
|
|
6938
|
-
if (response.status === null || response.status === 429) {
|
|
7668
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7669
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6939
7670
|
try {
|
|
6940
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7671
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6941
7672
|
}
|
|
6942
7673
|
catch (error) {
|
|
6943
7674
|
success = true;
|
|
@@ -6967,8 +7698,8 @@ class XykService {
|
|
|
6967
7698
|
return {
|
|
6968
7699
|
data: null,
|
|
6969
7700
|
error: true,
|
|
6970
|
-
error_code: data ? data.error_code : response.status,
|
|
6971
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7701
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7702
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
6972
7703
|
};
|
|
6973
7704
|
}
|
|
6974
7705
|
}
|
|
@@ -6997,6 +7728,7 @@ class XykService {
|
|
|
6997
7728
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6998
7729
|
};
|
|
6999
7730
|
}
|
|
7731
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
|
|
7000
7732
|
let startTime;
|
|
7001
7733
|
if (this.debug) {
|
|
7002
7734
|
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
@@ -7004,13 +7736,13 @@ class XykService {
|
|
|
7004
7736
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
|
|
7005
7737
|
headers: {
|
|
7006
7738
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
7007
|
-
"X-Requested-With": userAgent
|
|
7739
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7008
7740
|
}
|
|
7009
7741
|
}));
|
|
7010
|
-
debugOutput(response.url, response.status
|
|
7011
|
-
if (response.status === null || response.status === 429) {
|
|
7742
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7743
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7012
7744
|
try {
|
|
7013
|
-
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
7745
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7014
7746
|
}
|
|
7015
7747
|
catch (error) {
|
|
7016
7748
|
success = true;
|
|
@@ -7040,30 +7772,30 @@ class XykService {
|
|
|
7040
7772
|
return {
|
|
7041
7773
|
data: null,
|
|
7042
7774
|
error: true,
|
|
7043
|
-
error_code: data ? data.error_code : response.status,
|
|
7044
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7775
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7776
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7045
7777
|
};
|
|
7046
7778
|
}
|
|
7047
7779
|
}
|
|
7048
7780
|
}
|
|
7049
7781
|
}
|
|
7050
7782
|
|
|
7051
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.
|
|
7783
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.8.0";
|
|
7052
7784
|
/**
|
|
7053
7785
|
* CovalentClient Class
|
|
7054
7786
|
*/
|
|
7055
7787
|
class CovalentClient {
|
|
7056
|
-
constructor(apiKey, settings) {
|
|
7057
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7788
|
+
constructor(apiKey, settings, source) {
|
|
7789
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7058
7790
|
const validator = new ApiKeyValidator(apiKey);
|
|
7059
7791
|
this._is_key_valid = validator.isValidApiKey();
|
|
7060
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7061
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7062
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7063
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7064
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7065
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7066
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7792
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7793
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7794
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7795
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7796
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7797
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7798
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7067
7799
|
}
|
|
7068
7800
|
}
|
|
7069
7801
|
/**
|
|
@@ -7073,17 +7805,17 @@ class CovalentClient {
|
|
|
7073
7805
|
* CovalentClient Class
|
|
7074
7806
|
*/
|
|
7075
7807
|
class Client {
|
|
7076
|
-
constructor(apiKey, settings) {
|
|
7077
|
-
const { debug = false, threadCount = 3 } = settings || {};
|
|
7808
|
+
constructor(apiKey, settings, source) {
|
|
7809
|
+
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7078
7810
|
const validator = new ApiKeyValidator(apiKey);
|
|
7079
7811
|
this._is_key_valid = validator.isValidApiKey();
|
|
7080
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7081
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7082
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7083
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7084
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7085
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7086
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
|
|
7812
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7813
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7814
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7815
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7816
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7817
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7818
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7087
7819
|
}
|
|
7088
7820
|
}
|
|
7089
7821
|
|