@covalenthq/client-sdk 0.7.6 → 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 +5 -0
- package/dist/cjs/index.js +815 -181
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +14 -13
- package/dist/cjs/services/BaseService.d.ts +12 -11
- package/dist/cjs/services/CovalentClient.d.ts +5 -3
- package/dist/cjs/services/NftService.d.ts +18 -17
- package/dist/cjs/services/PricingService.d.ts +4 -3
- package/dist/cjs/services/SecurityService.d.ts +5 -4
- package/dist/cjs/services/TransactionService.d.ts +79 -12
- package/dist/cjs/services/XykService.d.ts +226 -15
- 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 +114 -0
- package/dist/es/index.js +815 -181
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +14 -13
- package/dist/es/services/BaseService.d.ts +12 -11
- package/dist/es/services/CovalentClient.d.ts +5 -3
- package/dist/es/services/NftService.d.ts +18 -17
- package/dist/es/services/PricingService.d.ts +4 -3
- package/dist/es/services/SecurityService.d.ts +5 -4
- package/dist/es/services/TransactionService.d.ts +79 -12
- package/dist/es/services/XykService.d.ts +226 -15
- 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 +114 -0
- package/dist/esm/index.js +815 -181
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +14 -13
- package/dist/esm/services/BaseService.d.ts +12 -11
- package/dist/esm/services/CovalentClient.d.ts +5 -3
- package/dist/esm/services/NftService.d.ts +18 -17
- package/dist/esm/services/PricingService.d.ts +4 -3
- package/dist/esm/services/SecurityService.d.ts +5 -4
- package/dist/esm/services/TransactionService.d.ts +79 -12
- package/dist/esm/services/XykService.d.ts +226 -15
- 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 +114 -0
- package/dist/services/BalanceService.d.ts +14 -13
- package/dist/services/BalanceService.js +16 -15
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +12 -11
- package/dist/services/BaseService.js +25 -24
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +5 -3
- package/dist/services/CovalentClient.js +17 -17
- package/dist/services/CovalentClient.js.map +1 -1
- package/dist/services/NftService.d.ts +18 -17
- package/dist/services/NftService.js +30 -29
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +4 -3
- package/dist/services/PricingService.js +4 -3
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +5 -4
- package/dist/services/SecurityService.js +6 -5
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +79 -12
- package/dist/services/TransactionService.js +369 -41
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +226 -15
- package/dist/services/XykService.js +335 -34
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +3 -3
- 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 +114 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -13,7 +13,7 @@ class ExponentialBackoff {
|
|
|
13
13
|
this._apiKey = apiKey;
|
|
14
14
|
this._debug = debug;
|
|
15
15
|
}
|
|
16
|
-
async backOff(url) {
|
|
16
|
+
async backOff(url, source) {
|
|
17
17
|
try {
|
|
18
18
|
let startTime;
|
|
19
19
|
if (this._debug) {
|
|
@@ -22,7 +22,7 @@ class ExponentialBackoff {
|
|
|
22
22
|
const response = await fetch(url, {
|
|
23
23
|
headers: {
|
|
24
24
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
25
|
-
"X-Requested-With": userAgent
|
|
25
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
debugOutput(response.url, response.status ?? 429, startTime);
|
|
@@ -38,7 +38,7 @@ class ExponentialBackoff {
|
|
|
38
38
|
this.retryCount++;
|
|
39
39
|
const delayMs = Math.pow(2, this.retryCount) * BASE_DELAY_MS;
|
|
40
40
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
41
|
-
return this.backOff(url);
|
|
41
|
+
return this.backOff(url, source);
|
|
42
42
|
}
|
|
43
43
|
return Promise.reject(new Error(`Max retries exceeded: ${this.maxRetries}`));
|
|
44
44
|
}
|
|
@@ -221,7 +221,7 @@ async function debugOutput(url, responseStatus, startTime) {
|
|
|
221
221
|
}
|
|
222
222
|
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")}`);
|
|
223
223
|
}
|
|
224
|
-
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry) {
|
|
224
|
+
async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor, debug, threadCount, enableRetry, source) {
|
|
225
225
|
let hasNext = true;
|
|
226
226
|
let response;
|
|
227
227
|
let data;
|
|
@@ -238,13 +238,13 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
|
|
|
238
238
|
response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
|
|
239
239
|
headers: {
|
|
240
240
|
"Authorization": `Bearer ${apiKey}`,
|
|
241
|
-
"X-Requested-With": userAgent
|
|
241
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
242
242
|
}
|
|
243
243
|
}));
|
|
244
244
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
245
245
|
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
246
246
|
try {
|
|
247
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : link));
|
|
247
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : link, source));
|
|
248
248
|
}
|
|
249
249
|
catch (error) {
|
|
250
250
|
hasNext = false;
|
|
@@ -386,12 +386,13 @@ class NftApprovalSpender {
|
|
|
386
386
|
*
|
|
387
387
|
*/
|
|
388
388
|
class SecurityService {
|
|
389
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
389
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
390
390
|
this.apiKey = apiKey;
|
|
391
391
|
this.debug = debug;
|
|
392
392
|
this.threadCount = threadCount;
|
|
393
393
|
this.is_key_valid = is_key_valid;
|
|
394
394
|
this.enableRetry = enableRetry;
|
|
395
|
+
this.source = source;
|
|
395
396
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
396
397
|
}
|
|
397
398
|
/**
|
|
@@ -426,13 +427,13 @@ class SecurityService {
|
|
|
426
427
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`, {
|
|
427
428
|
headers: {
|
|
428
429
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
429
|
-
"X-Requested-With": userAgent
|
|
430
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
430
431
|
}
|
|
431
432
|
}));
|
|
432
433
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
433
434
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
434
435
|
try {
|
|
435
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
436
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
436
437
|
}
|
|
437
438
|
catch (error) {
|
|
438
439
|
success = true;
|
|
@@ -499,13 +500,13 @@ class SecurityService {
|
|
|
499
500
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`, {
|
|
500
501
|
headers: {
|
|
501
502
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
502
|
-
"X-Requested-With": userAgent
|
|
503
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
503
504
|
}
|
|
504
505
|
}));
|
|
505
506
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
506
507
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
507
508
|
try {
|
|
508
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
509
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
509
510
|
}
|
|
510
511
|
catch (error) {
|
|
511
512
|
success = true;
|
|
@@ -824,12 +825,13 @@ class NativeBalanceItem {
|
|
|
824
825
|
*
|
|
825
826
|
*/
|
|
826
827
|
class BalanceService {
|
|
827
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
828
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
828
829
|
this.apiKey = apiKey;
|
|
829
830
|
this.debug = debug;
|
|
830
831
|
this.threadCount = threadCount;
|
|
831
832
|
this.is_key_valid = is_key_valid;
|
|
832
833
|
this.enableRetry = enableRetry;
|
|
834
|
+
this.source = source;
|
|
833
835
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
834
836
|
}
|
|
835
837
|
/**
|
|
@@ -885,13 +887,13 @@ class BalanceService {
|
|
|
885
887
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
|
|
886
888
|
headers: {
|
|
887
889
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
888
|
-
"X-Requested-With": userAgent
|
|
890
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
889
891
|
}
|
|
890
892
|
}));
|
|
891
893
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
892
894
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
893
895
|
try {
|
|
894
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
896
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
895
897
|
}
|
|
896
898
|
catch (error) {
|
|
897
899
|
success = true;
|
|
@@ -968,13 +970,13 @@ class BalanceService {
|
|
|
968
970
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
|
|
969
971
|
headers: {
|
|
970
972
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
971
|
-
"X-Requested-With": userAgent
|
|
973
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
972
974
|
}
|
|
973
975
|
}));
|
|
974
976
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
975
977
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
976
978
|
try {
|
|
977
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
979
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
978
980
|
}
|
|
979
981
|
catch (error) {
|
|
980
982
|
success = true;
|
|
@@ -1052,7 +1054,7 @@ class BalanceService {
|
|
|
1052
1054
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1053
1055
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1054
1056
|
}
|
|
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)) {
|
|
1057
|
+
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)) {
|
|
1056
1058
|
yield res;
|
|
1057
1059
|
}
|
|
1058
1060
|
success = true;
|
|
@@ -1120,13 +1122,13 @@ class BalanceService {
|
|
|
1120
1122
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
|
|
1121
1123
|
headers: {
|
|
1122
1124
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1123
|
-
"X-Requested-With": userAgent
|
|
1125
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1124
1126
|
}
|
|
1125
1127
|
}));
|
|
1126
1128
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1127
1129
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1128
1130
|
try {
|
|
1129
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1131
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1130
1132
|
}
|
|
1131
1133
|
catch (error) {
|
|
1132
1134
|
success = true;
|
|
@@ -1196,7 +1198,7 @@ class BalanceService {
|
|
|
1196
1198
|
if (queryParamOpts?.date !== undefined) {
|
|
1197
1199
|
urlParams.append("date", queryParamOpts?.date.toString());
|
|
1198
1200
|
}
|
|
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)) {
|
|
1201
|
+
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)) {
|
|
1200
1202
|
yield res;
|
|
1201
1203
|
}
|
|
1202
1204
|
success = true;
|
|
@@ -1256,13 +1258,13 @@ class BalanceService {
|
|
|
1256
1258
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
|
|
1257
1259
|
headers: {
|
|
1258
1260
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1259
|
-
"X-Requested-With": userAgent
|
|
1261
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1260
1262
|
}
|
|
1261
1263
|
}));
|
|
1262
1264
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1263
1265
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1264
1266
|
try {
|
|
1265
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1267
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1266
1268
|
}
|
|
1267
1269
|
catch (error) {
|
|
1268
1270
|
success = true;
|
|
@@ -1359,13 +1361,13 @@ class BalanceService {
|
|
|
1359
1361
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
|
|
1360
1362
|
headers: {
|
|
1361
1363
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1362
|
-
"X-Requested-With": userAgent
|
|
1364
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1363
1365
|
}
|
|
1364
1366
|
}));
|
|
1365
1367
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1366
1368
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1367
1369
|
try {
|
|
1368
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1370
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1369
1371
|
}
|
|
1370
1372
|
catch (error) {
|
|
1371
1373
|
success = true;
|
|
@@ -1440,13 +1442,13 @@ class BalanceService {
|
|
|
1440
1442
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
|
|
1441
1443
|
headers: {
|
|
1442
1444
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1443
|
-
"X-Requested-With": userAgent
|
|
1445
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1444
1446
|
}
|
|
1445
1447
|
}));
|
|
1446
1448
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1447
1449
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1448
1450
|
try {
|
|
1449
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1451
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1450
1452
|
}
|
|
1451
1453
|
catch (error) {
|
|
1452
1454
|
success = true;
|
|
@@ -1705,12 +1707,13 @@ class OtherFees {
|
|
|
1705
1707
|
*
|
|
1706
1708
|
*/
|
|
1707
1709
|
class BaseService {
|
|
1708
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
1710
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
1709
1711
|
this.apiKey = apiKey;
|
|
1710
1712
|
this.debug = debug;
|
|
1711
1713
|
this.threadCount = threadCount;
|
|
1712
1714
|
this.is_key_valid = is_key_valid;
|
|
1713
1715
|
this.enableRetry = enableRetry;
|
|
1716
|
+
this.source = source;
|
|
1714
1717
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
1715
1718
|
}
|
|
1716
1719
|
/**
|
|
@@ -1745,13 +1748,13 @@ class BaseService {
|
|
|
1745
1748
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
|
|
1746
1749
|
headers: {
|
|
1747
1750
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1748
|
-
"X-Requested-With": userAgent
|
|
1751
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1749
1752
|
}
|
|
1750
1753
|
}));
|
|
1751
1754
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1752
1755
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1753
1756
|
try {
|
|
1754
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1757
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1755
1758
|
}
|
|
1756
1759
|
catch (error) {
|
|
1757
1760
|
success = true;
|
|
@@ -1819,13 +1822,13 @@ class BaseService {
|
|
|
1819
1822
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
|
|
1820
1823
|
headers: {
|
|
1821
1824
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1822
|
-
"X-Requested-With": userAgent
|
|
1825
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1823
1826
|
}
|
|
1824
1827
|
}));
|
|
1825
1828
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1826
1829
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1827
1830
|
try {
|
|
1828
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1831
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1829
1832
|
}
|
|
1830
1833
|
catch (error) {
|
|
1831
1834
|
success = true;
|
|
@@ -1888,7 +1891,7 @@ class BaseService {
|
|
|
1888
1891
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
1889
1892
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
1890
1893
|
}
|
|
1891
|
-
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)) {
|
|
1894
|
+
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)) {
|
|
1892
1895
|
yield res;
|
|
1893
1896
|
}
|
|
1894
1897
|
success = true;
|
|
@@ -1941,13 +1944,13 @@ class BaseService {
|
|
|
1941
1944
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
|
|
1942
1945
|
headers: {
|
|
1943
1946
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1944
|
-
"X-Requested-With": userAgent
|
|
1947
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1945
1948
|
}
|
|
1946
1949
|
}));
|
|
1947
1950
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1948
1951
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1949
1952
|
try {
|
|
1950
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
1953
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1951
1954
|
}
|
|
1952
1955
|
catch (error) {
|
|
1953
1956
|
success = true;
|
|
@@ -2039,13 +2042,13 @@ class BaseService {
|
|
|
2039
2042
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
|
|
2040
2043
|
headers: {
|
|
2041
2044
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2042
|
-
"X-Requested-With": userAgent
|
|
2045
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2043
2046
|
}
|
|
2044
2047
|
}));
|
|
2045
2048
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2046
2049
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2047
2050
|
try {
|
|
2048
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2051
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2049
2052
|
}
|
|
2050
2053
|
catch (error) {
|
|
2051
2054
|
success = true;
|
|
@@ -2115,7 +2118,7 @@ class BaseService {
|
|
|
2115
2118
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2116
2119
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2117
2120
|
}
|
|
2118
|
-
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)) {
|
|
2121
|
+
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)) {
|
|
2119
2122
|
yield res;
|
|
2120
2123
|
}
|
|
2121
2124
|
success = true;
|
|
@@ -2175,13 +2178,13 @@ class BaseService {
|
|
|
2175
2178
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
|
|
2176
2179
|
headers: {
|
|
2177
2180
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2178
|
-
"X-Requested-With": userAgent
|
|
2181
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2179
2182
|
}
|
|
2180
2183
|
}));
|
|
2181
2184
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2182
2185
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2183
2186
|
try {
|
|
2184
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2187
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2185
2188
|
}
|
|
2186
2189
|
catch (error) {
|
|
2187
2190
|
success = true;
|
|
@@ -2255,7 +2258,7 @@ class BaseService {
|
|
|
2255
2258
|
if (queryParamOpts?.pageNumber !== undefined) {
|
|
2256
2259
|
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
2257
2260
|
}
|
|
2258
|
-
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)) {
|
|
2261
|
+
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)) {
|
|
2259
2262
|
yield res;
|
|
2260
2263
|
}
|
|
2261
2264
|
success = true;
|
|
@@ -2319,13 +2322,13 @@ class BaseService {
|
|
|
2319
2322
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
|
|
2320
2323
|
headers: {
|
|
2321
2324
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2322
|
-
"X-Requested-With": userAgent
|
|
2325
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2323
2326
|
}
|
|
2324
2327
|
}));
|
|
2325
2328
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2326
2329
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2327
2330
|
try {
|
|
2328
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2331
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2329
2332
|
}
|
|
2330
2333
|
catch (error) {
|
|
2331
2334
|
success = true;
|
|
@@ -2391,13 +2394,13 @@ class BaseService {
|
|
|
2391
2394
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
|
|
2392
2395
|
headers: {
|
|
2393
2396
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2394
|
-
"X-Requested-With": userAgent
|
|
2397
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2395
2398
|
}
|
|
2396
2399
|
}));
|
|
2397
2400
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2398
2401
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2399
2402
|
try {
|
|
2400
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2403
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2401
2404
|
}
|
|
2402
2405
|
catch (error) {
|
|
2403
2406
|
success = true;
|
|
@@ -2463,13 +2466,13 @@ class BaseService {
|
|
|
2463
2466
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
|
|
2464
2467
|
headers: {
|
|
2465
2468
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2466
|
-
"X-Requested-With": userAgent
|
|
2469
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2467
2470
|
}
|
|
2468
2471
|
}));
|
|
2469
2472
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2470
2473
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2471
2474
|
try {
|
|
2472
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2475
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2473
2476
|
}
|
|
2474
2477
|
catch (error) {
|
|
2475
2478
|
success = true;
|
|
@@ -2541,13 +2544,13 @@ class BaseService {
|
|
|
2541
2544
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
|
|
2542
2545
|
headers: {
|
|
2543
2546
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2544
|
-
"X-Requested-With": userAgent
|
|
2547
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2545
2548
|
}
|
|
2546
2549
|
}));
|
|
2547
2550
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2548
2551
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2549
2552
|
try {
|
|
2550
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2553
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2551
2554
|
}
|
|
2552
2555
|
catch (error) {
|
|
2553
2556
|
success = true;
|
|
@@ -2618,13 +2621,13 @@ class BaseService {
|
|
|
2618
2621
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
|
|
2619
2622
|
headers: {
|
|
2620
2623
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
2621
|
-
"X-Requested-With": userAgent
|
|
2624
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
2622
2625
|
}
|
|
2623
2626
|
}));
|
|
2624
2627
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
2625
2628
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
2626
2629
|
try {
|
|
2627
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
2630
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
2628
2631
|
}
|
|
2629
2632
|
catch (error) {
|
|
2630
2633
|
success = true;
|
|
@@ -2984,12 +2987,13 @@ class MarketFloorPriceItem {
|
|
|
2984
2987
|
*
|
|
2985
2988
|
*/
|
|
2986
2989
|
class NftService {
|
|
2987
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
2990
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
2988
2991
|
this.apiKey = apiKey;
|
|
2989
2992
|
this.debug = debug;
|
|
2990
2993
|
this.threadCount = threadCount;
|
|
2991
2994
|
this.is_key_valid = is_key_valid;
|
|
2992
2995
|
this.enableRetry = enableRetry;
|
|
2996
|
+
this.source = source;
|
|
2993
2997
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
2994
2998
|
}
|
|
2995
2999
|
/**
|
|
@@ -3021,7 +3025,7 @@ class NftService {
|
|
|
3021
3025
|
if (queryParamOpts?.noSpam !== undefined) {
|
|
3022
3026
|
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
3023
3027
|
}
|
|
3024
|
-
for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry)) {
|
|
3028
|
+
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)) {
|
|
3025
3029
|
yield res;
|
|
3026
3030
|
}
|
|
3027
3031
|
success = true;
|
|
@@ -3076,13 +3080,13 @@ class NftService {
|
|
|
3076
3080
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
|
|
3077
3081
|
headers: {
|
|
3078
3082
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3079
|
-
"X-Requested-With": userAgent
|
|
3083
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3080
3084
|
}
|
|
3081
3085
|
}));
|
|
3082
3086
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3083
3087
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3084
3088
|
try {
|
|
3085
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3089
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3086
3090
|
}
|
|
3087
3091
|
catch (error) {
|
|
3088
3092
|
success = true;
|
|
@@ -3163,13 +3167,13 @@ class NftService {
|
|
|
3163
3167
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
|
|
3164
3168
|
headers: {
|
|
3165
3169
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3166
|
-
"X-Requested-With": userAgent
|
|
3170
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3167
3171
|
}
|
|
3168
3172
|
}));
|
|
3169
3173
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3170
3174
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3171
3175
|
try {
|
|
3172
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3176
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3173
3177
|
}
|
|
3174
3178
|
catch (error) {
|
|
3175
3179
|
success = true;
|
|
@@ -3247,7 +3251,7 @@ class NftService {
|
|
|
3247
3251
|
if (queryParamOpts?.withUncached !== undefined) {
|
|
3248
3252
|
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
3249
3253
|
}
|
|
3250
|
-
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)) {
|
|
3254
|
+
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)) {
|
|
3251
3255
|
yield res;
|
|
3252
3256
|
}
|
|
3253
3257
|
success = true;
|
|
@@ -3315,13 +3319,13 @@ class NftService {
|
|
|
3315
3319
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
|
|
3316
3320
|
headers: {
|
|
3317
3321
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3318
|
-
"X-Requested-With": userAgent
|
|
3322
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3319
3323
|
}
|
|
3320
3324
|
}));
|
|
3321
3325
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3322
3326
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3323
3327
|
try {
|
|
3324
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3328
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3325
3329
|
}
|
|
3326
3330
|
catch (error) {
|
|
3327
3331
|
success = true;
|
|
@@ -3399,13 +3403,13 @@ class NftService {
|
|
|
3399
3403
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
|
|
3400
3404
|
headers: {
|
|
3401
3405
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3402
|
-
"X-Requested-With": userAgent
|
|
3406
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3403
3407
|
}
|
|
3404
3408
|
}));
|
|
3405
3409
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3406
3410
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3407
3411
|
try {
|
|
3408
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3412
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3409
3413
|
}
|
|
3410
3414
|
catch (error) {
|
|
3411
3415
|
success = true;
|
|
@@ -3479,13 +3483,13 @@ class NftService {
|
|
|
3479
3483
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
|
|
3480
3484
|
headers: {
|
|
3481
3485
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3482
|
-
"X-Requested-With": userAgent
|
|
3486
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3483
3487
|
}
|
|
3484
3488
|
}));
|
|
3485
3489
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3486
3490
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3487
3491
|
try {
|
|
3488
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3492
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3489
3493
|
}
|
|
3490
3494
|
catch (error) {
|
|
3491
3495
|
success = true;
|
|
@@ -3553,13 +3557,13 @@ class NftService {
|
|
|
3553
3557
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
|
|
3554
3558
|
headers: {
|
|
3555
3559
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3556
|
-
"X-Requested-With": userAgent
|
|
3560
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3557
3561
|
}
|
|
3558
3562
|
}));
|
|
3559
3563
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3560
3564
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3561
3565
|
try {
|
|
3562
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3566
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3563
3567
|
}
|
|
3564
3568
|
catch (error) {
|
|
3565
3569
|
success = true;
|
|
@@ -3628,13 +3632,13 @@ class NftService {
|
|
|
3628
3632
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
|
|
3629
3633
|
headers: {
|
|
3630
3634
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3631
|
-
"X-Requested-With": userAgent
|
|
3635
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3632
3636
|
}
|
|
3633
3637
|
}));
|
|
3634
3638
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3635
3639
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3636
3640
|
try {
|
|
3637
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3641
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3638
3642
|
}
|
|
3639
3643
|
catch (error) {
|
|
3640
3644
|
success = true;
|
|
@@ -3702,13 +3706,13 @@ class NftService {
|
|
|
3702
3706
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
|
|
3703
3707
|
headers: {
|
|
3704
3708
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3705
|
-
"X-Requested-With": userAgent
|
|
3709
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3706
3710
|
}
|
|
3707
3711
|
}));
|
|
3708
3712
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3709
3713
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3710
3714
|
try {
|
|
3711
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3715
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3712
3716
|
}
|
|
3713
3717
|
catch (error) {
|
|
3714
3718
|
success = true;
|
|
@@ -3777,13 +3781,13 @@ class NftService {
|
|
|
3777
3781
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
|
|
3778
3782
|
headers: {
|
|
3779
3783
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3780
|
-
"X-Requested-With": userAgent
|
|
3784
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3781
3785
|
}
|
|
3782
3786
|
}));
|
|
3783
3787
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3784
3788
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3785
3789
|
try {
|
|
3786
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3790
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3787
3791
|
}
|
|
3788
3792
|
catch (error) {
|
|
3789
3793
|
success = true;
|
|
@@ -3853,13 +3857,13 @@ class NftService {
|
|
|
3853
3857
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
|
|
3854
3858
|
headers: {
|
|
3855
3859
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3856
|
-
"X-Requested-With": userAgent
|
|
3860
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3857
3861
|
}
|
|
3858
3862
|
}));
|
|
3859
3863
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3860
3864
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3861
3865
|
try {
|
|
3862
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3866
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3863
3867
|
}
|
|
3864
3868
|
catch (error) {
|
|
3865
3869
|
success = true;
|
|
@@ -3936,13 +3940,13 @@ class NftService {
|
|
|
3936
3940
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
|
|
3937
3941
|
headers: {
|
|
3938
3942
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
3939
|
-
"X-Requested-With": userAgent
|
|
3943
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
3940
3944
|
}
|
|
3941
3945
|
}));
|
|
3942
3946
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
3943
3947
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
3944
3948
|
try {
|
|
3945
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
3949
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
3946
3950
|
}
|
|
3947
3951
|
catch (error) {
|
|
3948
3952
|
success = true;
|
|
@@ -4019,13 +4023,13 @@ class NftService {
|
|
|
4019
4023
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
|
|
4020
4024
|
headers: {
|
|
4021
4025
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
4022
|
-
"X-Requested-With": userAgent
|
|
4026
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
4023
4027
|
}
|
|
4024
4028
|
}));
|
|
4025
4029
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4026
4030
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4027
4031
|
try {
|
|
4028
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4032
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
4029
4033
|
}
|
|
4030
4034
|
catch (error) {
|
|
4031
4035
|
success = true;
|
|
@@ -4102,13 +4106,13 @@ class NftService {
|
|
|
4102
4106
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
|
|
4103
4107
|
headers: {
|
|
4104
4108
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
4105
|
-
"X-Requested-With": userAgent
|
|
4109
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
4106
4110
|
}
|
|
4107
4111
|
}));
|
|
4108
4112
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4109
4113
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4110
4114
|
try {
|
|
4111
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4115
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
4112
4116
|
}
|
|
4113
4117
|
catch (error) {
|
|
4114
4118
|
success = true;
|
|
@@ -4179,12 +4183,13 @@ let ContractMetadata$2 = class ContractMetadata {
|
|
|
4179
4183
|
}
|
|
4180
4184
|
};
|
|
4181
4185
|
class PricingService {
|
|
4182
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
4186
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
4183
4187
|
this.apiKey = apiKey;
|
|
4184
4188
|
this.debug = debug;
|
|
4185
4189
|
this.threadCount = threadCount;
|
|
4186
4190
|
this.is_key_valid = is_key_valid;
|
|
4187
4191
|
this.enableRetry = enableRetry;
|
|
4192
|
+
this.source = source;
|
|
4188
4193
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
4189
4194
|
}
|
|
4190
4195
|
/**
|
|
@@ -4233,13 +4238,13 @@ class PricingService {
|
|
|
4233
4238
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`, {
|
|
4234
4239
|
headers: {
|
|
4235
4240
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
4236
|
-
"X-Requested-With": userAgent
|
|
4241
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
4237
4242
|
}
|
|
4238
4243
|
}));
|
|
4239
4244
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4240
4245
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4241
4246
|
try {
|
|
4242
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4247
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
4243
4248
|
}
|
|
4244
4249
|
catch (error) {
|
|
4245
4250
|
success = true;
|
|
@@ -4495,12 +4500,13 @@ class Param {
|
|
|
4495
4500
|
}
|
|
4496
4501
|
}
|
|
4497
4502
|
class RecentTransactionsResponse {
|
|
4498
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4503
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4499
4504
|
this._debug = _debug;
|
|
4500
4505
|
this._apiKey = _apiKey;
|
|
4501
4506
|
this._threadCount = _threadCount;
|
|
4502
4507
|
this._urlParams = _urlParams;
|
|
4503
4508
|
this._enableRetry = _enableRetry;
|
|
4509
|
+
this._source = _source;
|
|
4504
4510
|
this.address = data.address;
|
|
4505
4511
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4506
4512
|
this.quote_currency = data.quote_currency;
|
|
@@ -4535,13 +4541,13 @@ class RecentTransactionsResponse {
|
|
|
4535
4541
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4536
4542
|
headers: {
|
|
4537
4543
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4538
|
-
"X-Requested-With": userAgent
|
|
4544
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4539
4545
|
}
|
|
4540
4546
|
}));
|
|
4541
4547
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4542
4548
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4543
4549
|
try {
|
|
4544
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4550
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4545
4551
|
}
|
|
4546
4552
|
catch (error) {
|
|
4547
4553
|
success = true;
|
|
@@ -4556,7 +4562,7 @@ class RecentTransactionsResponse {
|
|
|
4556
4562
|
else {
|
|
4557
4563
|
data = await response.json();
|
|
4558
4564
|
}
|
|
4559
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4565
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4560
4566
|
checkAndModifyResponse(dataClass);
|
|
4561
4567
|
success = true;
|
|
4562
4568
|
return {
|
|
@@ -4602,13 +4608,13 @@ class RecentTransactionsResponse {
|
|
|
4602
4608
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4603
4609
|
headers: {
|
|
4604
4610
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4605
|
-
"X-Requested-With": userAgent
|
|
4611
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4606
4612
|
}
|
|
4607
4613
|
}));
|
|
4608
4614
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4609
4615
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4610
4616
|
try {
|
|
4611
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4617
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4612
4618
|
}
|
|
4613
4619
|
catch (error) {
|
|
4614
4620
|
success = true;
|
|
@@ -4623,7 +4629,7 @@ class RecentTransactionsResponse {
|
|
|
4623
4629
|
else {
|
|
4624
4630
|
data = await response.json();
|
|
4625
4631
|
}
|
|
4626
|
-
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4632
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4627
4633
|
checkAndModifyResponse(dataClass);
|
|
4628
4634
|
success = true;
|
|
4629
4635
|
return {
|
|
@@ -4651,6 +4657,155 @@ class PaginationLinks {
|
|
|
4651
4657
|
this.next = data.next;
|
|
4652
4658
|
}
|
|
4653
4659
|
}
|
|
4660
|
+
class TransactionsBlockPageResponse {
|
|
4661
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4662
|
+
this._debug = _debug;
|
|
4663
|
+
this._apiKey = _apiKey;
|
|
4664
|
+
this._threadCount = _threadCount;
|
|
4665
|
+
this._urlParams = _urlParams;
|
|
4666
|
+
this._enableRetry = _enableRetry;
|
|
4667
|
+
this._source = _source;
|
|
4668
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4669
|
+
this.chain_id = data.chain_id;
|
|
4670
|
+
this.chain_name = data.chain_name;
|
|
4671
|
+
this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
|
|
4672
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
|
|
4673
|
+
}
|
|
4674
|
+
async prev() {
|
|
4675
|
+
let success = false;
|
|
4676
|
+
let data;
|
|
4677
|
+
let response;
|
|
4678
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4679
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4680
|
+
while (!success) {
|
|
4681
|
+
try {
|
|
4682
|
+
let startTime;
|
|
4683
|
+
if (this._debug) {
|
|
4684
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4685
|
+
}
|
|
4686
|
+
if (this.links.prev === null) {
|
|
4687
|
+
success = true;
|
|
4688
|
+
return {
|
|
4689
|
+
data: null,
|
|
4690
|
+
error: true,
|
|
4691
|
+
error_code: 400,
|
|
4692
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4693
|
+
};
|
|
4694
|
+
}
|
|
4695
|
+
const url = `${this.links.prev}?${this._urlParams}`;
|
|
4696
|
+
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4697
|
+
headers: {
|
|
4698
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4699
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4700
|
+
}
|
|
4701
|
+
}));
|
|
4702
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4703
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4704
|
+
try {
|
|
4705
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4706
|
+
}
|
|
4707
|
+
catch (error) {
|
|
4708
|
+
success = true;
|
|
4709
|
+
return {
|
|
4710
|
+
data: null,
|
|
4711
|
+
error: true,
|
|
4712
|
+
error_code: response.status ?? 429,
|
|
4713
|
+
error_message: error.message
|
|
4714
|
+
};
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
else {
|
|
4718
|
+
data = await response.json();
|
|
4719
|
+
}
|
|
4720
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4721
|
+
checkAndModifyResponse(dataClass);
|
|
4722
|
+
success = true;
|
|
4723
|
+
return {
|
|
4724
|
+
data: dataClass,
|
|
4725
|
+
error: data.error,
|
|
4726
|
+
error_code: data ? data.error_code : response.status,
|
|
4727
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4728
|
+
};
|
|
4729
|
+
}
|
|
4730
|
+
catch (error) {
|
|
4731
|
+
success = true;
|
|
4732
|
+
return {
|
|
4733
|
+
data: null,
|
|
4734
|
+
error: true,
|
|
4735
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4736
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4737
|
+
};
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
async next() {
|
|
4742
|
+
let success = false;
|
|
4743
|
+
let data;
|
|
4744
|
+
let response;
|
|
4745
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4746
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4747
|
+
while (!success) {
|
|
4748
|
+
try {
|
|
4749
|
+
let startTime;
|
|
4750
|
+
if (this._debug) {
|
|
4751
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4752
|
+
}
|
|
4753
|
+
if (this.links.next === null) {
|
|
4754
|
+
success = true;
|
|
4755
|
+
return {
|
|
4756
|
+
data: null,
|
|
4757
|
+
error: true,
|
|
4758
|
+
error_code: 400,
|
|
4759
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4760
|
+
};
|
|
4761
|
+
}
|
|
4762
|
+
const url = `${this.links.next}?${this._urlParams}`;
|
|
4763
|
+
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4764
|
+
headers: {
|
|
4765
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4766
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4767
|
+
}
|
|
4768
|
+
}));
|
|
4769
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4770
|
+
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4771
|
+
try {
|
|
4772
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4773
|
+
}
|
|
4774
|
+
catch (error) {
|
|
4775
|
+
success = true;
|
|
4776
|
+
return {
|
|
4777
|
+
data: null,
|
|
4778
|
+
error: true,
|
|
4779
|
+
error_code: response.status ?? 429,
|
|
4780
|
+
error_message: error.message
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
else {
|
|
4785
|
+
data = await response.json();
|
|
4786
|
+
}
|
|
4787
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4788
|
+
checkAndModifyResponse(dataClass);
|
|
4789
|
+
success = true;
|
|
4790
|
+
return {
|
|
4791
|
+
data: dataClass,
|
|
4792
|
+
error: data.error,
|
|
4793
|
+
error_code: data ? data.error_code : response.status,
|
|
4794
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4795
|
+
};
|
|
4796
|
+
}
|
|
4797
|
+
catch (error) {
|
|
4798
|
+
success = true;
|
|
4799
|
+
return {
|
|
4800
|
+
data: null,
|
|
4801
|
+
error: true,
|
|
4802
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
4803
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
4804
|
+
};
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4654
4809
|
class TransactionsBlockResponse {
|
|
4655
4810
|
constructor(data) {
|
|
4656
4811
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
@@ -4683,12 +4838,13 @@ class TransactionSummary {
|
|
|
4683
4838
|
}
|
|
4684
4839
|
}
|
|
4685
4840
|
class TransactionsResponse {
|
|
4686
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4841
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4687
4842
|
this._debug = _debug;
|
|
4688
4843
|
this._apiKey = _apiKey;
|
|
4689
4844
|
this._threadCount = _threadCount;
|
|
4690
4845
|
this._urlParams = _urlParams;
|
|
4691
4846
|
this._enableRetry = _enableRetry;
|
|
4847
|
+
this._source = _source;
|
|
4692
4848
|
this.address = data.address;
|
|
4693
4849
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4694
4850
|
this.quote_currency = data.quote_currency;
|
|
@@ -4723,13 +4879,13 @@ class TransactionsResponse {
|
|
|
4723
4879
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4724
4880
|
headers: {
|
|
4725
4881
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4726
|
-
"X-Requested-With": userAgent
|
|
4882
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4727
4883
|
}
|
|
4728
4884
|
}));
|
|
4729
4885
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4730
4886
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4731
4887
|
try {
|
|
4732
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4888
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4733
4889
|
}
|
|
4734
4890
|
catch (error) {
|
|
4735
4891
|
success = true;
|
|
@@ -4744,7 +4900,7 @@ class TransactionsResponse {
|
|
|
4744
4900
|
else {
|
|
4745
4901
|
data = await response.json();
|
|
4746
4902
|
}
|
|
4747
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4903
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4748
4904
|
checkAndModifyResponse(dataClass);
|
|
4749
4905
|
success = true;
|
|
4750
4906
|
return {
|
|
@@ -4790,13 +4946,13 @@ class TransactionsResponse {
|
|
|
4790
4946
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4791
4947
|
headers: {
|
|
4792
4948
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4793
|
-
"X-Requested-With": userAgent
|
|
4949
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4794
4950
|
}
|
|
4795
4951
|
}));
|
|
4796
4952
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4797
4953
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4798
4954
|
try {
|
|
4799
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
4955
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4800
4956
|
}
|
|
4801
4957
|
catch (error) {
|
|
4802
4958
|
success = true;
|
|
@@ -4811,7 +4967,7 @@ class TransactionsResponse {
|
|
|
4811
4967
|
else {
|
|
4812
4968
|
data = await response.json();
|
|
4813
4969
|
}
|
|
4814
|
-
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
4970
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4815
4971
|
checkAndModifyResponse(dataClass);
|
|
4816
4972
|
success = true;
|
|
4817
4973
|
return {
|
|
@@ -4834,12 +4990,13 @@ class TransactionsResponse {
|
|
|
4834
4990
|
}
|
|
4835
4991
|
}
|
|
4836
4992
|
class TransactionsTimeBucketResponse {
|
|
4837
|
-
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
|
|
4993
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
|
|
4838
4994
|
this._debug = _debug;
|
|
4839
4995
|
this._apiKey = _apiKey;
|
|
4840
4996
|
this._threadCount = _threadCount;
|
|
4841
4997
|
this._urlParams = _urlParams;
|
|
4842
4998
|
this._enableRetry = _enableRetry;
|
|
4999
|
+
this._source = _source;
|
|
4843
5000
|
this.address = data.address;
|
|
4844
5001
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4845
5002
|
this.quote_currency = data.quote_currency;
|
|
@@ -4875,13 +5032,13 @@ class TransactionsTimeBucketResponse {
|
|
|
4875
5032
|
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4876
5033
|
headers: {
|
|
4877
5034
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4878
|
-
"X-Requested-With": userAgent
|
|
5035
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4879
5036
|
}
|
|
4880
5037
|
}));
|
|
4881
5038
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4882
5039
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4883
5040
|
try {
|
|
4884
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5041
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4885
5042
|
}
|
|
4886
5043
|
catch (error) {
|
|
4887
5044
|
success = true;
|
|
@@ -4896,7 +5053,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4896
5053
|
else {
|
|
4897
5054
|
data = await response.json();
|
|
4898
5055
|
}
|
|
4899
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
5056
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4900
5057
|
checkAndModifyResponse(dataClass);
|
|
4901
5058
|
success = true;
|
|
4902
5059
|
return {
|
|
@@ -4942,13 +5099,13 @@ class TransactionsTimeBucketResponse {
|
|
|
4942
5099
|
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4943
5100
|
headers: {
|
|
4944
5101
|
"Authorization": `Bearer ${this._apiKey}`,
|
|
4945
|
-
"X-Requested-With": userAgent
|
|
5102
|
+
"X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
|
|
4946
5103
|
}
|
|
4947
5104
|
}));
|
|
4948
5105
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
4949
5106
|
if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
4950
5107
|
try {
|
|
4951
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5108
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
|
|
4952
5109
|
}
|
|
4953
5110
|
catch (error) {
|
|
4954
5111
|
success = true;
|
|
@@ -4963,7 +5120,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4963
5120
|
else {
|
|
4964
5121
|
data = await response.json();
|
|
4965
5122
|
}
|
|
4966
|
-
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
|
|
5123
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
|
|
4967
5124
|
checkAndModifyResponse(dataClass);
|
|
4968
5125
|
success = true;
|
|
4969
5126
|
return {
|
|
@@ -4989,7 +5146,7 @@ class TransactionsTimeBucketResponse {
|
|
|
4989
5146
|
* Transactions APIs
|
|
4990
5147
|
*
|
|
4991
5148
|
*/
|
|
4992
|
-
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
|
|
5149
|
+
async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
|
|
4993
5150
|
let hasNext = true;
|
|
4994
5151
|
let response;
|
|
4995
5152
|
let data;
|
|
@@ -5004,13 +5161,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
|
|
|
5004
5161
|
response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
|
|
5005
5162
|
headers: {
|
|
5006
5163
|
"Authorization": `Bearer ${apiKey}`,
|
|
5007
|
-
"X-Requested-With": userAgent
|
|
5164
|
+
"X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
|
|
5008
5165
|
}
|
|
5009
5166
|
}));
|
|
5010
5167
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5011
5168
|
if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5012
5169
|
try {
|
|
5013
|
-
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}
|
|
5170
|
+
data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
|
|
5014
5171
|
}
|
|
5015
5172
|
catch (error) {
|
|
5016
5173
|
hasNext = false;
|
|
@@ -5046,12 +5203,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, en
|
|
|
5046
5203
|
}
|
|
5047
5204
|
}
|
|
5048
5205
|
class TransactionService {
|
|
5049
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
5206
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
5050
5207
|
this.apiKey = apiKey;
|
|
5051
5208
|
this.debug = debug;
|
|
5052
5209
|
this.threadCount = threadCount;
|
|
5053
5210
|
this.is_key_valid = is_key_valid;
|
|
5054
5211
|
this.enableRetry = enableRetry;
|
|
5212
|
+
this.source = source;
|
|
5055
5213
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
5056
5214
|
}
|
|
5057
5215
|
/**
|
|
@@ -5111,13 +5269,13 @@ class TransactionService {
|
|
|
5111
5269
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
|
|
5112
5270
|
headers: {
|
|
5113
5271
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5114
|
-
"X-Requested-With": userAgent
|
|
5272
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5115
5273
|
}
|
|
5116
5274
|
}));
|
|
5117
5275
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5118
5276
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5119
5277
|
try {
|
|
5120
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5278
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5121
5279
|
}
|
|
5122
5280
|
catch (error) {
|
|
5123
5281
|
success = true;
|
|
@@ -5187,7 +5345,7 @@ class TransactionService {
|
|
|
5187
5345
|
if (queryParamOpts?.withSafe !== undefined) {
|
|
5188
5346
|
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5189
5347
|
}
|
|
5190
|
-
for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
|
|
5348
|
+
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)) {
|
|
5191
5349
|
yield tx;
|
|
5192
5350
|
}
|
|
5193
5351
|
success = true;
|
|
@@ -5247,13 +5405,13 @@ class TransactionService {
|
|
|
5247
5405
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
5248
5406
|
headers: {
|
|
5249
5407
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5250
|
-
"X-Requested-With": userAgent
|
|
5408
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5251
5409
|
}
|
|
5252
5410
|
}));
|
|
5253
5411
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5254
5412
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5255
5413
|
try {
|
|
5256
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5414
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5257
5415
|
}
|
|
5258
5416
|
catch (error) {
|
|
5259
5417
|
success = true;
|
|
@@ -5268,7 +5426,7 @@ class TransactionService {
|
|
|
5268
5426
|
else {
|
|
5269
5427
|
data = await response.json();
|
|
5270
5428
|
}
|
|
5271
|
-
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5429
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5272
5430
|
checkAndModifyResponse(dataClass);
|
|
5273
5431
|
success = true;
|
|
5274
5432
|
return {
|
|
@@ -5334,13 +5492,13 @@ class TransactionService {
|
|
|
5334
5492
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
|
|
5335
5493
|
headers: {
|
|
5336
5494
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5337
|
-
"X-Requested-With": userAgent
|
|
5495
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5338
5496
|
}
|
|
5339
5497
|
}));
|
|
5340
5498
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5341
5499
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5342
5500
|
try {
|
|
5343
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5501
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5344
5502
|
}
|
|
5345
5503
|
catch (error) {
|
|
5346
5504
|
success = true;
|
|
@@ -5408,13 +5566,13 @@ class TransactionService {
|
|
|
5408
5566
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
|
|
5409
5567
|
headers: {
|
|
5410
5568
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5411
|
-
"X-Requested-With": userAgent
|
|
5569
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5412
5570
|
}
|
|
5413
5571
|
}));
|
|
5414
5572
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5415
5573
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5416
5574
|
try {
|
|
5417
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5575
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5418
5576
|
}
|
|
5419
5577
|
catch (error) {
|
|
5420
5578
|
success = true;
|
|
@@ -5498,13 +5656,13 @@ class TransactionService {
|
|
|
5498
5656
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5499
5657
|
headers: {
|
|
5500
5658
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5501
|
-
"X-Requested-With": userAgent
|
|
5659
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5502
5660
|
}
|
|
5503
5661
|
}));
|
|
5504
5662
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5505
5663
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5506
5664
|
try {
|
|
5507
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5665
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5508
5666
|
}
|
|
5509
5667
|
catch (error) {
|
|
5510
5668
|
success = true;
|
|
@@ -5519,7 +5677,7 @@ class TransactionService {
|
|
|
5519
5677
|
else {
|
|
5520
5678
|
data = await response.json();
|
|
5521
5679
|
}
|
|
5522
|
-
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
|
|
5680
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5523
5681
|
checkAndModifyResponse(dataClass);
|
|
5524
5682
|
success = true;
|
|
5525
5683
|
return {
|
|
@@ -5584,13 +5742,188 @@ class TransactionService {
|
|
|
5584
5742
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
|
|
5585
5743
|
headers: {
|
|
5586
5744
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
5587
|
-
"X-Requested-With": userAgent
|
|
5745
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5746
|
+
}
|
|
5747
|
+
}));
|
|
5748
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5749
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5750
|
+
try {
|
|
5751
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5752
|
+
}
|
|
5753
|
+
catch (error) {
|
|
5754
|
+
success = true;
|
|
5755
|
+
return {
|
|
5756
|
+
data: null,
|
|
5757
|
+
error: true,
|
|
5758
|
+
error_code: response.status ?? 429,
|
|
5759
|
+
error_message: error.message
|
|
5760
|
+
};
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5763
|
+
else {
|
|
5764
|
+
data = await response.json();
|
|
5765
|
+
}
|
|
5766
|
+
const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5767
|
+
checkAndModifyResponse(dataClass);
|
|
5768
|
+
success = true;
|
|
5769
|
+
return {
|
|
5770
|
+
data: dataClass,
|
|
5771
|
+
error: data.error,
|
|
5772
|
+
error_code: data ? data.error_code : response.status,
|
|
5773
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5774
|
+
};
|
|
5775
|
+
}
|
|
5776
|
+
catch (error) {
|
|
5777
|
+
success = true;
|
|
5778
|
+
return {
|
|
5779
|
+
data: null,
|
|
5780
|
+
error: true,
|
|
5781
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5782
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5783
|
+
};
|
|
5784
|
+
}
|
|
5785
|
+
}
|
|
5786
|
+
}
|
|
5787
|
+
/**
|
|
5788
|
+
*
|
|
5789
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
5790
|
+
*
|
|
5791
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
5792
|
+
* @param {string} blockHash - The requested block hash.
|
|
5793
|
+
* @param {number} page - The requested 0-indexed page number.
|
|
5794
|
+
* @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
|
|
5795
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
5796
|
+
* - `noLogs`: Omit log events.
|
|
5797
|
+
* - `withSafe`: Include safe details.
|
|
5798
|
+
*
|
|
5799
|
+
*/
|
|
5800
|
+
async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
|
|
5801
|
+
let success = false;
|
|
5802
|
+
let data;
|
|
5803
|
+
let response;
|
|
5804
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
5805
|
+
while (!success) {
|
|
5806
|
+
try {
|
|
5807
|
+
const urlParams = new URLSearchParams();
|
|
5808
|
+
if (!this.is_key_valid) {
|
|
5809
|
+
return {
|
|
5810
|
+
data: null,
|
|
5811
|
+
error: true,
|
|
5812
|
+
error_code: 401,
|
|
5813
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
5814
|
+
};
|
|
5815
|
+
}
|
|
5816
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
5817
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
5818
|
+
}
|
|
5819
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
5820
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
5821
|
+
}
|
|
5822
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
5823
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5824
|
+
}
|
|
5825
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
|
|
5826
|
+
let startTime;
|
|
5827
|
+
if (this.debug) {
|
|
5828
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5829
|
+
}
|
|
5830
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
|
|
5831
|
+
headers: {
|
|
5832
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
5833
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5834
|
+
}
|
|
5835
|
+
}));
|
|
5836
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5837
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5838
|
+
try {
|
|
5839
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5840
|
+
}
|
|
5841
|
+
catch (error) {
|
|
5842
|
+
success = true;
|
|
5843
|
+
return {
|
|
5844
|
+
data: null,
|
|
5845
|
+
error: true,
|
|
5846
|
+
error_code: response.status ?? 429,
|
|
5847
|
+
error_message: error.message
|
|
5848
|
+
};
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
else {
|
|
5852
|
+
data = await response.json();
|
|
5853
|
+
}
|
|
5854
|
+
const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
|
|
5855
|
+
checkAndModifyResponse(dataClass);
|
|
5856
|
+
success = true;
|
|
5857
|
+
return {
|
|
5858
|
+
data: dataClass,
|
|
5859
|
+
error: data.error,
|
|
5860
|
+
error_code: data ? data.error_code : response.status,
|
|
5861
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
5862
|
+
};
|
|
5863
|
+
}
|
|
5864
|
+
catch (error) {
|
|
5865
|
+
success = true;
|
|
5866
|
+
return {
|
|
5867
|
+
data: null,
|
|
5868
|
+
error: true,
|
|
5869
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
5870
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
5871
|
+
};
|
|
5872
|
+
}
|
|
5873
|
+
}
|
|
5874
|
+
}
|
|
5875
|
+
/**
|
|
5876
|
+
*
|
|
5877
|
+
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
5878
|
+
*
|
|
5879
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
5880
|
+
* @param {string} blockHash - The requested block hash.
|
|
5881
|
+
* @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
|
|
5882
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
5883
|
+
* - `noLogs`: Omit log events.
|
|
5884
|
+
* - `withSafe`: Include safe details.
|
|
5885
|
+
*
|
|
5886
|
+
*/
|
|
5887
|
+
async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
|
|
5888
|
+
let success = false;
|
|
5889
|
+
let data;
|
|
5890
|
+
let response;
|
|
5891
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
5892
|
+
while (!success) {
|
|
5893
|
+
try {
|
|
5894
|
+
const urlParams = new URLSearchParams();
|
|
5895
|
+
if (!this.is_key_valid) {
|
|
5896
|
+
return {
|
|
5897
|
+
data: null,
|
|
5898
|
+
error: true,
|
|
5899
|
+
error_code: 401,
|
|
5900
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
5901
|
+
};
|
|
5902
|
+
}
|
|
5903
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
5904
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
5905
|
+
}
|
|
5906
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
5907
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
5908
|
+
}
|
|
5909
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
5910
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
5911
|
+
}
|
|
5912
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
|
|
5913
|
+
let startTime;
|
|
5914
|
+
if (this.debug) {
|
|
5915
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
5916
|
+
}
|
|
5917
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
|
|
5918
|
+
headers: {
|
|
5919
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
5920
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
5588
5921
|
}
|
|
5589
5922
|
}));
|
|
5590
5923
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
5591
5924
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
5592
5925
|
try {
|
|
5593
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
5926
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
5594
5927
|
}
|
|
5595
5928
|
catch (error) {
|
|
5596
5929
|
success = true;
|
|
@@ -5605,7 +5938,7 @@ class TransactionService {
|
|
|
5605
5938
|
else {
|
|
5606
5939
|
data = await response.json();
|
|
5607
5940
|
}
|
|
5608
|
-
const dataClass = new
|
|
5941
|
+
const dataClass = new TransactionsBlockResponse(data.data);
|
|
5609
5942
|
checkAndModifyResponse(dataClass);
|
|
5610
5943
|
success = true;
|
|
5611
5944
|
return {
|
|
@@ -5870,23 +6203,55 @@ class UniswapLikeTokenWithSupply {
|
|
|
5870
6203
|
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
5871
6204
|
this.contract_address = data.contract_address;
|
|
5872
6205
|
this.logo_url = data.logo_url;
|
|
5873
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
5874
|
-
this.quote = data.quote;
|
|
5875
|
-
this.pretty_quote = data.pretty_quote;
|
|
6206
|
+
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
6207
|
+
this.quote = data.quote;
|
|
6208
|
+
this.pretty_quote = data.pretty_quote;
|
|
6209
|
+
this.quote_rate = data.quote_rate;
|
|
6210
|
+
this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
class NetworkExchangeTokensResponse {
|
|
6214
|
+
constructor(data) {
|
|
6215
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
6216
|
+
this.chain_id = data.chain_id;
|
|
6217
|
+
this.chain_name = data.chain_name;
|
|
6218
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2Volume(itemData)) : null;
|
|
6219
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
6222
|
+
class TokenV2Volume {
|
|
6223
|
+
constructor(data) {
|
|
6224
|
+
this.chain_name = data.chain_name;
|
|
6225
|
+
this.chain_id = data.chain_id;
|
|
6226
|
+
this.dex_name = data.dex_name;
|
|
6227
|
+
this.contract_address = data.contract_address;
|
|
6228
|
+
this.contract_name = data.contract_name;
|
|
6229
|
+
this.total_liquidity = data.total_liquidity;
|
|
6230
|
+
this.total_volume_24h = data.total_volume_24h;
|
|
6231
|
+
this.logo_url = data.logo_url;
|
|
6232
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
6233
|
+
this.contract_decimals = data.contract_decimals;
|
|
6234
|
+
this.swap_count_24h = data.swap_count_24h;
|
|
5876
6235
|
this.quote_rate = data.quote_rate;
|
|
5877
|
-
this.
|
|
6236
|
+
this.quote_rate_24h = data.quote_rate_24h;
|
|
6237
|
+
this.pretty_quote_rate = data.pretty_quote_rate;
|
|
6238
|
+
this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
|
|
6239
|
+
this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
|
|
6240
|
+
this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
|
|
6241
|
+
this.total_liquidity_quote = data.total_liquidity_quote;
|
|
6242
|
+
this.total_volume_24h_quote = data.total_volume_24h_quote;
|
|
5878
6243
|
}
|
|
5879
6244
|
}
|
|
5880
|
-
class
|
|
6245
|
+
class NetworkExchangeTokenViewResponse {
|
|
5881
6246
|
constructor(data) {
|
|
5882
6247
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
5883
6248
|
this.chain_id = data.chain_id;
|
|
5884
6249
|
this.chain_name = data.chain_name;
|
|
5885
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new
|
|
6250
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
|
|
5886
6251
|
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
5887
6252
|
}
|
|
5888
6253
|
}
|
|
5889
|
-
class
|
|
6254
|
+
class TokenV2VolumeWithChartData {
|
|
5890
6255
|
constructor(data) {
|
|
5891
6256
|
this.chain_name = data.chain_name;
|
|
5892
6257
|
this.chain_id = data.chain_id;
|
|
@@ -5907,6 +6272,43 @@ class TokenV2Volume {
|
|
|
5907
6272
|
this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
|
|
5908
6273
|
this.total_liquidity_quote = data.total_liquidity_quote;
|
|
5909
6274
|
this.total_volume_24h_quote = data.total_volume_24h_quote;
|
|
6275
|
+
this.transactions_24h = data.transactions_24h;
|
|
6276
|
+
this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
|
|
6277
|
+
this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
|
|
6278
|
+
this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
|
|
6279
|
+
this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
|
|
6280
|
+
this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
|
|
6281
|
+
this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
class VolumeTokenTimeseries {
|
|
6285
|
+
constructor(data) {
|
|
6286
|
+
this.dex_name = data.dex_name;
|
|
6287
|
+
this.chain_id = data.chain_id;
|
|
6288
|
+
this.dt = data.dt;
|
|
6289
|
+
this.total_volume = data.total_volume;
|
|
6290
|
+
this.volume_quote = data.volume_quote;
|
|
6291
|
+
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
6292
|
+
}
|
|
6293
|
+
}
|
|
6294
|
+
class LiquidityTokenTimeseries {
|
|
6295
|
+
constructor(data) {
|
|
6296
|
+
this.dex_name = data.dex_name;
|
|
6297
|
+
this.chain_id = data.chain_id;
|
|
6298
|
+
this.dt = data.dt;
|
|
6299
|
+
this.total_liquidity = data.total_liquidity;
|
|
6300
|
+
this.liquidity_quote = data.liquidity_quote;
|
|
6301
|
+
this.pretty_liquidity_quote = data.pretty_liquidity_quote;
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6304
|
+
class PriceTokenTimeseries {
|
|
6305
|
+
constructor(data) {
|
|
6306
|
+
this.dex_name = data.dex_name;
|
|
6307
|
+
this.chain_id = data.chain_id;
|
|
6308
|
+
this.dt = data.dt;
|
|
6309
|
+
this.quote_currency = data.quote_currency;
|
|
6310
|
+
this.quote_rate = data.quote_rate;
|
|
6311
|
+
this.pretty_quote_rate = data.pretty_quote_rate;
|
|
5910
6312
|
}
|
|
5911
6313
|
}
|
|
5912
6314
|
class SupportedDexesResponse {
|
|
@@ -6007,6 +6409,15 @@ class TransactionsForExchangeResponse {
|
|
|
6007
6409
|
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
6008
6410
|
}
|
|
6009
6411
|
}
|
|
6412
|
+
class NetworkTransactionsResponse {
|
|
6413
|
+
constructor(data) {
|
|
6414
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
6415
|
+
this.chain_id = data.chain_id;
|
|
6416
|
+
this.chain_name = data.chain_name;
|
|
6417
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
|
|
6418
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
6419
|
+
}
|
|
6420
|
+
}
|
|
6010
6421
|
class EcosystemChartDataResponse {
|
|
6011
6422
|
constructor(data) {
|
|
6012
6423
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
@@ -6076,12 +6487,13 @@ class HealthData {
|
|
|
6076
6487
|
*
|
|
6077
6488
|
*/
|
|
6078
6489
|
class XykService {
|
|
6079
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
|
|
6490
|
+
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
6080
6491
|
this.apiKey = apiKey;
|
|
6081
6492
|
this.debug = debug;
|
|
6082
6493
|
this.threadCount = threadCount;
|
|
6083
6494
|
this.is_key_valid = is_key_valid;
|
|
6084
6495
|
this.enableRetry = enableRetry;
|
|
6496
|
+
this.source = source;
|
|
6085
6497
|
this.LIMIT = pLimit$1(this.threadCount);
|
|
6086
6498
|
}
|
|
6087
6499
|
/**
|
|
@@ -6090,9 +6502,12 @@ class XykService {
|
|
|
6090
6502
|
*
|
|
6091
6503
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6092
6504
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6505
|
+
* @param {GetPoolsQueryParamOpts} queryParamOpts
|
|
6506
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6507
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6093
6508
|
*
|
|
6094
6509
|
*/
|
|
6095
|
-
async getPools(chainName, dexName) {
|
|
6510
|
+
async getPools(chainName, dexName, queryParamOpts) {
|
|
6096
6511
|
let success = false;
|
|
6097
6512
|
let data;
|
|
6098
6513
|
let response;
|
|
@@ -6100,6 +6515,12 @@ class XykService {
|
|
|
6100
6515
|
while (!success) {
|
|
6101
6516
|
try {
|
|
6102
6517
|
const urlParams = new URLSearchParams();
|
|
6518
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6519
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6520
|
+
}
|
|
6521
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
6522
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
6523
|
+
}
|
|
6103
6524
|
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
|
|
6104
6525
|
if (!this.is_key_valid) {
|
|
6105
6526
|
return {
|
|
@@ -6116,13 +6537,13 @@ class XykService {
|
|
|
6116
6537
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
|
|
6117
6538
|
headers: {
|
|
6118
6539
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6119
|
-
"X-Requested-With": userAgent
|
|
6540
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6120
6541
|
}
|
|
6121
6542
|
}));
|
|
6122
6543
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6123
6544
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6124
6545
|
try {
|
|
6125
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6546
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6126
6547
|
}
|
|
6127
6548
|
catch (error) {
|
|
6128
6549
|
success = true;
|
|
@@ -6190,13 +6611,13 @@ class XykService {
|
|
|
6190
6611
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
|
|
6191
6612
|
headers: {
|
|
6192
6613
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6193
|
-
"X-Requested-With": userAgent
|
|
6614
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6194
6615
|
}
|
|
6195
6616
|
}));
|
|
6196
6617
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6197
6618
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6198
6619
|
try {
|
|
6199
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6620
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6200
6621
|
}
|
|
6201
6622
|
catch (error) {
|
|
6202
6623
|
success = true;
|
|
@@ -6265,13 +6686,13 @@ class XykService {
|
|
|
6265
6686
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
|
|
6266
6687
|
headers: {
|
|
6267
6688
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6268
|
-
"X-Requested-With": userAgent
|
|
6689
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6269
6690
|
}
|
|
6270
6691
|
}));
|
|
6271
6692
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6272
6693
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6273
6694
|
try {
|
|
6274
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6695
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6275
6696
|
}
|
|
6276
6697
|
catch (error) {
|
|
6277
6698
|
success = true;
|
|
@@ -6316,6 +6737,8 @@ class XykService {
|
|
|
6316
6737
|
* @param {number} page - The requested 0-indexed page number.
|
|
6317
6738
|
* @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
|
|
6318
6739
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
6740
|
+
* - `dexName`: The DEX name eg: `uniswap_v2`.
|
|
6741
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6319
6742
|
*
|
|
6320
6743
|
*/
|
|
6321
6744
|
async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
|
|
@@ -6340,6 +6763,9 @@ class XykService {
|
|
|
6340
6763
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6341
6764
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6342
6765
|
}
|
|
6766
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6767
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6768
|
+
}
|
|
6343
6769
|
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
|
|
6344
6770
|
let startTime;
|
|
6345
6771
|
if (this.debug) {
|
|
@@ -6348,13 +6774,13 @@ class XykService {
|
|
|
6348
6774
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
|
|
6349
6775
|
headers: {
|
|
6350
6776
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6351
|
-
"X-Requested-With": userAgent
|
|
6777
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6352
6778
|
}
|
|
6353
6779
|
}));
|
|
6354
6780
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6355
6781
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6356
6782
|
try {
|
|
6357
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6783
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6358
6784
|
}
|
|
6359
6785
|
catch (error) {
|
|
6360
6786
|
success = true;
|
|
@@ -6423,13 +6849,13 @@ class XykService {
|
|
|
6423
6849
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
|
|
6424
6850
|
headers: {
|
|
6425
6851
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6426
|
-
"X-Requested-With": userAgent
|
|
6852
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6427
6853
|
}
|
|
6428
6854
|
}));
|
|
6429
6855
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6430
6856
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6431
6857
|
try {
|
|
6432
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6858
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6433
6859
|
}
|
|
6434
6860
|
catch (error) {
|
|
6435
6861
|
success = true;
|
|
@@ -6475,6 +6901,8 @@ class XykService {
|
|
|
6475
6901
|
* @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
|
|
6476
6902
|
* - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
6477
6903
|
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
6904
|
+
* - `dexName`: The DEX name eg: `uniswap_v2`.
|
|
6905
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6478
6906
|
*
|
|
6479
6907
|
*/
|
|
6480
6908
|
async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
|
|
@@ -6502,6 +6930,9 @@ class XykService {
|
|
|
6502
6930
|
if (queryParamOpts?.dexName !== undefined) {
|
|
6503
6931
|
urlParams.append("dex-name", queryParamOpts?.dexName.toString());
|
|
6504
6932
|
}
|
|
6933
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
6934
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
6935
|
+
}
|
|
6505
6936
|
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
|
|
6506
6937
|
let startTime;
|
|
6507
6938
|
if (this.debug) {
|
|
@@ -6510,13 +6941,13 @@ class XykService {
|
|
|
6510
6941
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
|
|
6511
6942
|
headers: {
|
|
6512
6943
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6513
|
-
"X-Requested-With": userAgent
|
|
6944
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6514
6945
|
}
|
|
6515
6946
|
}));
|
|
6516
6947
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6517
6948
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6518
6949
|
try {
|
|
6519
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
6950
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6520
6951
|
}
|
|
6521
6952
|
catch (error) {
|
|
6522
6953
|
success = true;
|
|
@@ -6558,9 +6989,12 @@ class XykService {
|
|
|
6558
6989
|
*
|
|
6559
6990
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6560
6991
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6992
|
+
* @param {GetNetworkExchangeTokensQueryParamOpts} queryParamOpts
|
|
6993
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
6994
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6561
6995
|
*
|
|
6562
6996
|
*/
|
|
6563
|
-
async getNetworkExchangeTokens(chainName, dexName) {
|
|
6997
|
+
async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
|
|
6564
6998
|
let success = false;
|
|
6565
6999
|
let data;
|
|
6566
7000
|
let response;
|
|
@@ -6568,6 +7002,12 @@ class XykService {
|
|
|
6568
7002
|
while (!success) {
|
|
6569
7003
|
try {
|
|
6570
7004
|
const urlParams = new URLSearchParams();
|
|
7005
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7006
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7007
|
+
}
|
|
7008
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7009
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7010
|
+
}
|
|
6571
7011
|
if (!this.is_key_valid) {
|
|
6572
7012
|
return {
|
|
6573
7013
|
data: null,
|
|
@@ -6584,13 +7024,13 @@ class XykService {
|
|
|
6584
7024
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
|
|
6585
7025
|
headers: {
|
|
6586
7026
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6587
|
-
"X-Requested-With": userAgent
|
|
7027
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6588
7028
|
}
|
|
6589
7029
|
}));
|
|
6590
7030
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6591
7031
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6592
7032
|
try {
|
|
6593
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7033
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6594
7034
|
}
|
|
6595
7035
|
catch (error) {
|
|
6596
7036
|
success = true;
|
|
@@ -6626,6 +7066,86 @@ class XykService {
|
|
|
6626
7066
|
}
|
|
6627
7067
|
}
|
|
6628
7068
|
}
|
|
7069
|
+
/**
|
|
7070
|
+
*
|
|
7071
|
+
* Commonly used to get a detailed view for a single liquidity pool token. Includes time series data.
|
|
7072
|
+
*
|
|
7073
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
7074
|
+
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
7075
|
+
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7076
|
+
* @param {GetLpTokenViewQueryParamOpts} queryParamOpts
|
|
7077
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
7078
|
+
*
|
|
7079
|
+
*/
|
|
7080
|
+
async getLpTokenView(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
7081
|
+
let success = false;
|
|
7082
|
+
let data;
|
|
7083
|
+
let response;
|
|
7084
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
7085
|
+
while (!success) {
|
|
7086
|
+
try {
|
|
7087
|
+
const urlParams = new URLSearchParams();
|
|
7088
|
+
if (!this.is_key_valid) {
|
|
7089
|
+
return {
|
|
7090
|
+
data: null,
|
|
7091
|
+
error: true,
|
|
7092
|
+
error_code: 401,
|
|
7093
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
7094
|
+
};
|
|
7095
|
+
}
|
|
7096
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
7097
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
7098
|
+
}
|
|
7099
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`;
|
|
7100
|
+
let startTime;
|
|
7101
|
+
if (this.debug) {
|
|
7102
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
7103
|
+
}
|
|
7104
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`, {
|
|
7105
|
+
headers: {
|
|
7106
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
7107
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7108
|
+
}
|
|
7109
|
+
}));
|
|
7110
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7111
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7112
|
+
try {
|
|
7113
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7114
|
+
}
|
|
7115
|
+
catch (error) {
|
|
7116
|
+
success = true;
|
|
7117
|
+
return {
|
|
7118
|
+
data: null,
|
|
7119
|
+
error: true,
|
|
7120
|
+
error_code: response.status ?? 429,
|
|
7121
|
+
error_message: error.message
|
|
7122
|
+
};
|
|
7123
|
+
}
|
|
7124
|
+
}
|
|
7125
|
+
else {
|
|
7126
|
+
data = await response.json();
|
|
7127
|
+
}
|
|
7128
|
+
const dataClass = new NetworkExchangeTokenViewResponse(data.data);
|
|
7129
|
+
checkAndModifyResponse(dataClass);
|
|
7130
|
+
success = true;
|
|
7131
|
+
return {
|
|
7132
|
+
data: dataClass,
|
|
7133
|
+
error: data.error,
|
|
7134
|
+
error_code: data ? data.error_code : response.status,
|
|
7135
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7136
|
+
};
|
|
7137
|
+
}
|
|
7138
|
+
catch (error) {
|
|
7139
|
+
success = true;
|
|
7140
|
+
return {
|
|
7141
|
+
data: null,
|
|
7142
|
+
error: true,
|
|
7143
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7144
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7145
|
+
};
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
6629
7149
|
/**
|
|
6630
7150
|
*
|
|
6631
7151
|
* Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
|
|
@@ -6656,13 +7176,13 @@ class XykService {
|
|
|
6656
7176
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
|
|
6657
7177
|
headers: {
|
|
6658
7178
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6659
|
-
"X-Requested-With": userAgent
|
|
7179
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6660
7180
|
}
|
|
6661
7181
|
}));
|
|
6662
7182
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6663
7183
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6664
7184
|
try {
|
|
6665
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7185
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6666
7186
|
}
|
|
6667
7187
|
catch (error) {
|
|
6668
7188
|
success = true;
|
|
@@ -6705,9 +7225,12 @@ class XykService {
|
|
|
6705
7225
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6706
7226
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6707
7227
|
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7228
|
+
* @param {GetSingleNetworkExchangeTokenQueryParamOpts} queryParamOpts
|
|
7229
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7230
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6708
7231
|
*
|
|
6709
7232
|
*/
|
|
6710
|
-
async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
|
|
7233
|
+
async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
6711
7234
|
let success = false;
|
|
6712
7235
|
let data;
|
|
6713
7236
|
let response;
|
|
@@ -6715,6 +7238,12 @@ class XykService {
|
|
|
6715
7238
|
while (!success) {
|
|
6716
7239
|
try {
|
|
6717
7240
|
const urlParams = new URLSearchParams();
|
|
7241
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7242
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7243
|
+
}
|
|
7244
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7245
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7246
|
+
}
|
|
6718
7247
|
if (!this.is_key_valid) {
|
|
6719
7248
|
return {
|
|
6720
7249
|
data: null,
|
|
@@ -6731,13 +7260,13 @@ class XykService {
|
|
|
6731
7260
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
|
|
6732
7261
|
headers: {
|
|
6733
7262
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6734
|
-
"X-Requested-With": userAgent
|
|
7263
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6735
7264
|
}
|
|
6736
7265
|
}));
|
|
6737
7266
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6738
7267
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6739
7268
|
try {
|
|
6740
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7269
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6741
7270
|
}
|
|
6742
7271
|
catch (error) {
|
|
6743
7272
|
success = true;
|
|
@@ -6806,13 +7335,13 @@ class XykService {
|
|
|
6806
7335
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
|
|
6807
7336
|
headers: {
|
|
6808
7337
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6809
|
-
"X-Requested-With": userAgent
|
|
7338
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6810
7339
|
}
|
|
6811
7340
|
}));
|
|
6812
7341
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6813
7342
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6814
7343
|
try {
|
|
6815
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7344
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6816
7345
|
}
|
|
6817
7346
|
catch (error) {
|
|
6818
7347
|
success = true;
|
|
@@ -6855,9 +7384,12 @@ class XykService {
|
|
|
6855
7384
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6856
7385
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6857
7386
|
* @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7387
|
+
* @param {GetTransactionsForTokenAddressQueryParamOpts} queryParamOpts
|
|
7388
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7389
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6858
7390
|
*
|
|
6859
7391
|
*/
|
|
6860
|
-
async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
|
|
7392
|
+
async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
|
|
6861
7393
|
let success = false;
|
|
6862
7394
|
let data;
|
|
6863
7395
|
let response;
|
|
@@ -6873,6 +7405,12 @@ class XykService {
|
|
|
6873
7405
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6874
7406
|
};
|
|
6875
7407
|
}
|
|
7408
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7409
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7410
|
+
}
|
|
7411
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7412
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7413
|
+
}
|
|
6876
7414
|
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
|
|
6877
7415
|
let startTime;
|
|
6878
7416
|
if (this.debug) {
|
|
@@ -6881,13 +7419,13 @@ class XykService {
|
|
|
6881
7419
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
|
|
6882
7420
|
headers: {
|
|
6883
7421
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6884
|
-
"X-Requested-With": userAgent
|
|
7422
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6885
7423
|
}
|
|
6886
7424
|
}));
|
|
6887
7425
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6888
7426
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6889
7427
|
try {
|
|
6890
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7428
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6891
7429
|
}
|
|
6892
7430
|
catch (error) {
|
|
6893
7431
|
success = true;
|
|
@@ -6930,9 +7468,12 @@ class XykService {
|
|
|
6930
7468
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
6931
7469
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
6932
7470
|
* @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
7471
|
+
* @param {GetTransactionsForExchangeQueryParamOpts} queryParamOpts
|
|
7472
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7473
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
6933
7474
|
*
|
|
6934
7475
|
*/
|
|
6935
|
-
async getTransactionsForExchange(chainName, dexName, poolAddress) {
|
|
7476
|
+
async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
|
|
6936
7477
|
let success = false;
|
|
6937
7478
|
let data;
|
|
6938
7479
|
let response;
|
|
@@ -6948,6 +7489,12 @@ class XykService {
|
|
|
6948
7489
|
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
6949
7490
|
};
|
|
6950
7491
|
}
|
|
7492
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7493
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7494
|
+
}
|
|
7495
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7496
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7497
|
+
}
|
|
6951
7498
|
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
|
|
6952
7499
|
let startTime;
|
|
6953
7500
|
if (this.debug) {
|
|
@@ -6956,13 +7503,13 @@ class XykService {
|
|
|
6956
7503
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
|
|
6957
7504
|
headers: {
|
|
6958
7505
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
6959
|
-
"X-Requested-With": userAgent
|
|
7506
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
6960
7507
|
}
|
|
6961
7508
|
}));
|
|
6962
7509
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
6963
7510
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
6964
7511
|
try {
|
|
6965
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7512
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
6966
7513
|
}
|
|
6967
7514
|
catch (error) {
|
|
6968
7515
|
success = true;
|
|
@@ -6998,6 +7545,93 @@ class XykService {
|
|
|
6998
7545
|
}
|
|
6999
7546
|
}
|
|
7000
7547
|
}
|
|
7548
|
+
/**
|
|
7549
|
+
*
|
|
7550
|
+
* Commonly used to get all the the transactions for a given DEX. Useful for building DEX activity views.
|
|
7551
|
+
*
|
|
7552
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
7553
|
+
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
7554
|
+
* @param {GetTransactionsForDexQueryParamOpts} queryParamOpts
|
|
7555
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
7556
|
+
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
7557
|
+
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
7558
|
+
*
|
|
7559
|
+
*/
|
|
7560
|
+
async getTransactionsForDex(chainName, dexName, queryParamOpts) {
|
|
7561
|
+
let success = false;
|
|
7562
|
+
let data;
|
|
7563
|
+
let response;
|
|
7564
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
7565
|
+
while (!success) {
|
|
7566
|
+
try {
|
|
7567
|
+
const urlParams = new URLSearchParams();
|
|
7568
|
+
if (!this.is_key_valid) {
|
|
7569
|
+
return {
|
|
7570
|
+
data: null,
|
|
7571
|
+
error: true,
|
|
7572
|
+
error_code: 401,
|
|
7573
|
+
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
7574
|
+
};
|
|
7575
|
+
}
|
|
7576
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
7577
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
7578
|
+
}
|
|
7579
|
+
if (queryParamOpts?.pageSize !== undefined) {
|
|
7580
|
+
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
7581
|
+
}
|
|
7582
|
+
if (queryParamOpts?.pageNumber !== undefined) {
|
|
7583
|
+
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
7584
|
+
}
|
|
7585
|
+
const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`;
|
|
7586
|
+
let startTime;
|
|
7587
|
+
if (this.debug) {
|
|
7588
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
7589
|
+
}
|
|
7590
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`, {
|
|
7591
|
+
headers: {
|
|
7592
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
7593
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7594
|
+
}
|
|
7595
|
+
}));
|
|
7596
|
+
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7597
|
+
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7598
|
+
try {
|
|
7599
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7600
|
+
}
|
|
7601
|
+
catch (error) {
|
|
7602
|
+
success = true;
|
|
7603
|
+
return {
|
|
7604
|
+
data: null,
|
|
7605
|
+
error: true,
|
|
7606
|
+
error_code: response.status ?? 429,
|
|
7607
|
+
error_message: error.message
|
|
7608
|
+
};
|
|
7609
|
+
}
|
|
7610
|
+
}
|
|
7611
|
+
else {
|
|
7612
|
+
data = await response.json();
|
|
7613
|
+
}
|
|
7614
|
+
const dataClass = new NetworkTransactionsResponse(data.data);
|
|
7615
|
+
checkAndModifyResponse(dataClass);
|
|
7616
|
+
success = true;
|
|
7617
|
+
return {
|
|
7618
|
+
data: dataClass,
|
|
7619
|
+
error: data.error,
|
|
7620
|
+
error_code: data ? data.error_code : response.status,
|
|
7621
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
7622
|
+
};
|
|
7623
|
+
}
|
|
7624
|
+
catch (error) {
|
|
7625
|
+
success = true;
|
|
7626
|
+
return {
|
|
7627
|
+
data: null,
|
|
7628
|
+
error: true,
|
|
7629
|
+
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
7630
|
+
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
7631
|
+
};
|
|
7632
|
+
}
|
|
7633
|
+
}
|
|
7634
|
+
}
|
|
7001
7635
|
/**
|
|
7002
7636
|
*
|
|
7003
7637
|
* Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
|
|
@@ -7030,13 +7664,13 @@ class XykService {
|
|
|
7030
7664
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
|
|
7031
7665
|
headers: {
|
|
7032
7666
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
7033
|
-
"X-Requested-With": userAgent
|
|
7667
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7034
7668
|
}
|
|
7035
7669
|
}));
|
|
7036
7670
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7037
7671
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7038
7672
|
try {
|
|
7039
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7673
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7040
7674
|
}
|
|
7041
7675
|
catch (error) {
|
|
7042
7676
|
success = true;
|
|
@@ -7104,13 +7738,13 @@ class XykService {
|
|
|
7104
7738
|
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
|
|
7105
7739
|
headers: {
|
|
7106
7740
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
7107
|
-
"X-Requested-With": userAgent
|
|
7741
|
+
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
7108
7742
|
}
|
|
7109
7743
|
}));
|
|
7110
7744
|
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
7111
7745
|
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
7112
7746
|
try {
|
|
7113
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
|
|
7747
|
+
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
7114
7748
|
}
|
|
7115
7749
|
catch (error) {
|
|
7116
7750
|
success = true;
|
|
@@ -7148,22 +7782,22 @@ class XykService {
|
|
|
7148
7782
|
}
|
|
7149
7783
|
}
|
|
7150
7784
|
|
|
7151
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.
|
|
7785
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.8.0";
|
|
7152
7786
|
/**
|
|
7153
7787
|
* CovalentClient Class
|
|
7154
7788
|
*/
|
|
7155
7789
|
class CovalentClient {
|
|
7156
|
-
constructor(apiKey, settings) {
|
|
7790
|
+
constructor(apiKey, settings, source) {
|
|
7157
7791
|
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7158
7792
|
const validator = new ApiKeyValidator(apiKey);
|
|
7159
7793
|
this._is_key_valid = validator.isValidApiKey();
|
|
7160
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7161
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7162
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7163
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7164
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7165
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7166
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7794
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7795
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7796
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7797
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7798
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7799
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7800
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7167
7801
|
}
|
|
7168
7802
|
}
|
|
7169
7803
|
/**
|
|
@@ -7173,17 +7807,17 @@ class CovalentClient {
|
|
|
7173
7807
|
* CovalentClient Class
|
|
7174
7808
|
*/
|
|
7175
7809
|
class Client {
|
|
7176
|
-
constructor(apiKey, settings) {
|
|
7810
|
+
constructor(apiKey, settings, source) {
|
|
7177
7811
|
const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
|
|
7178
7812
|
const validator = new ApiKeyValidator(apiKey);
|
|
7179
7813
|
this._is_key_valid = validator.isValidApiKey();
|
|
7180
|
-
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7181
|
-
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7182
|
-
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7183
|
-
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7184
|
-
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7185
|
-
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7186
|
-
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry);
|
|
7814
|
+
this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7815
|
+
this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7816
|
+
this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7817
|
+
this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7818
|
+
this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7819
|
+
this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7820
|
+
this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid, enableRetry, source);
|
|
7187
7821
|
}
|
|
7188
7822
|
}
|
|
7189
7823
|
|