@covalenthq/client-sdk 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +25 -0
  2. package/dist/cjs/index.js +1183 -451
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +15 -13
  5. package/dist/cjs/services/BaseService.d.ts +13 -11
  6. package/dist/cjs/services/CovalentClient.d.ts +8 -4
  7. package/dist/cjs/services/NftService.d.ts +19 -17
  8. package/dist/cjs/services/PricingService.d.ts +5 -3
  9. package/dist/cjs/services/SecurityService.d.ts +6 -4
  10. package/dist/cjs/services/TransactionService.d.ts +83 -12
  11. package/dist/cjs/services/XykService.d.ts +287 -22
  12. package/dist/cjs/util/ApiHelpers.d.ts +2 -1
  13. package/dist/cjs/util/backoff.d.ts +2 -1
  14. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
  15. package/dist/cjs/util/types/XykServiceTypes.d.ts +160 -8
  16. package/dist/es/index.js +1183 -451
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +15 -13
  19. package/dist/es/services/BaseService.d.ts +13 -11
  20. package/dist/es/services/CovalentClient.d.ts +8 -4
  21. package/dist/es/services/NftService.d.ts +19 -17
  22. package/dist/es/services/PricingService.d.ts +5 -3
  23. package/dist/es/services/SecurityService.d.ts +6 -4
  24. package/dist/es/services/TransactionService.d.ts +83 -12
  25. package/dist/es/services/XykService.d.ts +287 -22
  26. package/dist/es/util/ApiHelpers.d.ts +2 -1
  27. package/dist/es/util/backoff.d.ts +2 -1
  28. package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
  29. package/dist/es/util/types/XykServiceTypes.d.ts +160 -8
  30. package/dist/esm/index.js +1183 -451
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +15 -13
  33. package/dist/esm/services/BaseService.d.ts +13 -11
  34. package/dist/esm/services/CovalentClient.d.ts +8 -4
  35. package/dist/esm/services/NftService.d.ts +19 -17
  36. package/dist/esm/services/PricingService.d.ts +5 -3
  37. package/dist/esm/services/SecurityService.d.ts +6 -4
  38. package/dist/esm/services/TransactionService.d.ts +83 -12
  39. package/dist/esm/services/XykService.d.ts +287 -22
  40. package/dist/esm/util/ApiHelpers.d.ts +2 -1
  41. package/dist/esm/util/backoff.d.ts +2 -1
  42. package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
  43. package/dist/esm/util/types/XykServiceTypes.d.ts +160 -8
  44. package/dist/services/BalanceService.d.ts +15 -13
  45. package/dist/services/BalanceService.js +47 -39
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +13 -11
  48. package/dist/services/BaseService.js +77 -65
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +8 -4
  51. package/dist/services/CovalentClient.js +19 -19
  52. package/dist/services/CovalentClient.js.map +1 -1
  53. package/dist/services/NftService.d.ts +19 -17
  54. package/dist/services/NftService.js +96 -81
  55. package/dist/services/NftService.js.map +1 -1
  56. package/dist/services/PricingService.d.ts +5 -3
  57. package/dist/services/PricingService.js +10 -7
  58. package/dist/services/PricingService.js.map +1 -1
  59. package/dist/services/SecurityService.d.ts +6 -4
  60. package/dist/services/SecurityService.js +17 -13
  61. package/dist/services/SecurityService.js.map +1 -1
  62. package/dist/services/TransactionService.d.ts +83 -12
  63. package/dist/services/TransactionService.js +434 -90
  64. package/dist/services/TransactionService.js.map +1 -1
  65. package/dist/services/XykService.d.ts +287 -22
  66. package/dist/services/XykService.js +438 -93
  67. package/dist/services/XykService.js.map +1 -1
  68. package/dist/util/ApiHelpers.d.ts +2 -1
  69. package/dist/util/ApiHelpers.js +7 -6
  70. package/dist/util/ApiHelpers.js.map +1 -1
  71. package/dist/util/backoff.d.ts +2 -1
  72. package/dist/util/backoff.js +3 -3
  73. package/dist/util/backoff.js.map +1 -1
  74. package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
  75. package/dist/util/types/XykServiceTypes.d.ts +160 -8
  76. 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) {
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;
@@ -234,20 +234,21 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
234
234
  if (debug) {
235
235
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
236
236
  }
237
+ const link = urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`;
237
238
  response = await LIMIT(() => fetch(urlsParams.get("page-number") ? `${url}?${urlsParams}` : `${url}?${urlsParams}&page-number=${page_number}`, {
238
239
  headers: {
239
240
  "Authorization": `Bearer ${apiKey}`,
240
- "X-Requested-With": userAgent
241
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
241
242
  }
242
243
  }));
243
- debugOutput(response.url, response.status ?? 429, startTime);
244
- if (response.status === null || response.status === 429) {
244
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
245
+ if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
245
246
  try {
246
- data = await LIMIT(() => backoff.backOff(response.url));
247
+ data = await LIMIT(() => backoff.backOff(response ? response.url : link, source));
247
248
  }
248
249
  catch (error) {
249
250
  hasNext = false;
250
- throw new Error(`An error occurred ${response.status ?? 429}: ${error.message}`);
251
+ throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
251
252
  }
252
253
  }
253
254
  else {
@@ -385,11 +386,13 @@ class NftApprovalSpender {
385
386
  *
386
387
  */
387
388
  class SecurityService {
388
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
389
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
389
390
  this.apiKey = apiKey;
390
391
  this.debug = debug;
391
392
  this.threadCount = threadCount;
392
393
  this.is_key_valid = is_key_valid;
394
+ this.enableRetry = enableRetry;
395
+ this.source = source;
393
396
  this.LIMIT = pLimit$1(this.threadCount);
394
397
  }
395
398
  /**
@@ -408,6 +411,7 @@ class SecurityService {
408
411
  while (!success) {
409
412
  try {
410
413
  const urlParams = new URLSearchParams();
414
+ const url = `https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`;
411
415
  if (!this.is_key_valid) {
412
416
  return {
413
417
  data: null,
@@ -423,13 +427,13 @@ class SecurityService {
423
427
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/approvals/${walletAddress}/?${urlParams}`, {
424
428
  headers: {
425
429
  "Authorization": `Bearer ${this.apiKey}`,
426
- "X-Requested-With": userAgent
430
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
427
431
  }
428
432
  }));
429
- debugOutput(response.url, response.status ?? 429, startTime);
430
- if (response.status === null || response.status === 429) {
433
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
434
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
431
435
  try {
432
- data = await this.LIMIT(() => backoff.backOff(response.url));
436
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
433
437
  }
434
438
  catch (error) {
435
439
  success = true;
@@ -459,8 +463,8 @@ class SecurityService {
459
463
  return {
460
464
  data: null,
461
465
  error: true,
462
- error_code: data ? data.error_code : response.status,
463
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
466
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
467
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
464
468
  };
465
469
  }
466
470
  }
@@ -480,6 +484,7 @@ class SecurityService {
480
484
  while (!success) {
481
485
  try {
482
486
  const urlParams = new URLSearchParams();
487
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`;
483
488
  if (!this.is_key_valid) {
484
489
  return {
485
490
  data: null,
@@ -495,13 +500,13 @@ class SecurityService {
495
500
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/approvals/${walletAddress}/?${urlParams}`, {
496
501
  headers: {
497
502
  "Authorization": `Bearer ${this.apiKey}`,
498
- "X-Requested-With": userAgent
503
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
499
504
  }
500
505
  }));
501
- debugOutput(response.url, response.status ?? 429, startTime);
502
- if (response.status === null || response.status === 429) {
506
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
507
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
503
508
  try {
504
- data = await this.LIMIT(() => backoff.backOff(response.url));
509
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
505
510
  }
506
511
  catch (error) {
507
512
  success = true;
@@ -531,8 +536,8 @@ class SecurityService {
531
536
  return {
532
537
  data: null,
533
538
  error: true,
534
- error_code: data ? data.error_code : response.status,
535
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
539
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
540
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
536
541
  };
537
542
  }
538
543
  }
@@ -820,11 +825,13 @@ class NativeBalanceItem {
820
825
  *
821
826
  */
822
827
  class BalanceService {
823
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
828
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
824
829
  this.apiKey = apiKey;
825
830
  this.debug = debug;
826
831
  this.threadCount = threadCount;
827
832
  this.is_key_valid = is_key_valid;
833
+ this.enableRetry = enableRetry;
834
+ this.source = source;
828
835
  this.LIMIT = pLimit$1(this.threadCount);
829
836
  }
830
837
  /**
@@ -872,6 +879,7 @@ class BalanceService {
872
879
  if (queryParamOpts?.noNftAssetMetadata !== undefined) {
873
880
  urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
874
881
  }
882
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`;
875
883
  let startTime;
876
884
  if (this.debug) {
877
885
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -879,13 +887,13 @@ class BalanceService {
879
887
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
880
888
  headers: {
881
889
  "Authorization": `Bearer ${this.apiKey}`,
882
- "X-Requested-With": userAgent
890
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
883
891
  }
884
892
  }));
885
- debugOutput(response.url, response.status ?? 429, startTime);
886
- if (response.status === null || response.status === 429) {
893
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
894
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
887
895
  try {
888
- data = await this.LIMIT(() => backoff.backOff(response.url));
896
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
889
897
  }
890
898
  catch (error) {
891
899
  success = true;
@@ -915,8 +923,8 @@ class BalanceService {
915
923
  return {
916
924
  data: null,
917
925
  error: true,
918
- error_code: data ? data.error_code : response.status,
919
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
926
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
927
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
920
928
  };
921
929
  }
922
930
  }
@@ -954,6 +962,7 @@ class BalanceService {
954
962
  if (queryParamOpts?.days !== undefined) {
955
963
  urlParams.append("days", queryParamOpts?.days.toString());
956
964
  }
965
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`;
957
966
  let startTime;
958
967
  if (this.debug) {
959
968
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -961,13 +970,13 @@ class BalanceService {
961
970
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
962
971
  headers: {
963
972
  "Authorization": `Bearer ${this.apiKey}`,
964
- "X-Requested-With": userAgent
973
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
965
974
  }
966
975
  }));
967
- debugOutput(response.url, response.status ?? 429, startTime);
968
- if (response.status === null || response.status === 429) {
976
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
977
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
969
978
  try {
970
- data = await this.LIMIT(() => backoff.backOff(response.url));
979
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
971
980
  }
972
981
  catch (error) {
973
982
  success = true;
@@ -997,8 +1006,8 @@ class BalanceService {
997
1006
  return {
998
1007
  data: null,
999
1008
  error: true,
1000
- error_code: data ? data.error_code : response.status,
1001
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1009
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1010
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1002
1011
  };
1003
1012
  }
1004
1013
  }
@@ -1045,7 +1054,7 @@ class BalanceService {
1045
1054
  if (queryParamOpts?.pageNumber !== undefined) {
1046
1055
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1047
1056
  }
1048
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount)) {
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)) {
1049
1058
  yield res;
1050
1059
  }
1051
1060
  success = true;
@@ -1105,6 +1114,7 @@ class BalanceService {
1105
1114
  if (queryParamOpts?.pageNumber !== undefined) {
1106
1115
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1107
1116
  }
1117
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`;
1108
1118
  let startTime;
1109
1119
  if (this.debug) {
1110
1120
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1112,13 +1122,13 @@ class BalanceService {
1112
1122
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/?${urlParams}`, {
1113
1123
  headers: {
1114
1124
  "Authorization": `Bearer ${this.apiKey}`,
1115
- "X-Requested-With": userAgent
1125
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1116
1126
  }
1117
1127
  }));
1118
- debugOutput(response.url, response.status ?? 429, startTime);
1119
- if (response.status === null || response.status === 429) {
1128
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1129
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1120
1130
  try {
1121
- data = await this.LIMIT(() => backoff.backOff(response.url));
1131
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1122
1132
  }
1123
1133
  catch (error) {
1124
1134
  success = true;
@@ -1148,8 +1158,8 @@ class BalanceService {
1148
1158
  return {
1149
1159
  data: null,
1150
1160
  error: true,
1151
- error_code: data ? data.error_code : response.status,
1152
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1161
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1162
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1153
1163
  };
1154
1164
  }
1155
1165
  }
@@ -1188,7 +1198,7 @@ class BalanceService {
1188
1198
  if (queryParamOpts?.date !== undefined) {
1189
1199
  urlParams.append("date", queryParamOpts?.date.toString());
1190
1200
  }
1191
- 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)) {
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)) {
1192
1202
  yield res;
1193
1203
  }
1194
1204
  success = true;
@@ -1240,6 +1250,7 @@ class BalanceService {
1240
1250
  if (queryParamOpts?.date !== undefined) {
1241
1251
  urlParams.append("date", queryParamOpts?.date.toString());
1242
1252
  }
1253
+ const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`;
1243
1254
  let startTime;
1244
1255
  if (this.debug) {
1245
1256
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1247,13 +1258,13 @@ class BalanceService {
1247
1258
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/?${urlParams}`, {
1248
1259
  headers: {
1249
1260
  "Authorization": `Bearer ${this.apiKey}`,
1250
- "X-Requested-With": userAgent
1261
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1251
1262
  }
1252
1263
  }));
1253
- debugOutput(response.url, response.status ?? 429, startTime);
1254
- if (response.status === null || response.status === 429) {
1264
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1265
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1255
1266
  try {
1256
- data = await this.LIMIT(() => backoff.backOff(response.url));
1267
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1257
1268
  }
1258
1269
  catch (error) {
1259
1270
  success = true;
@@ -1283,8 +1294,8 @@ class BalanceService {
1283
1294
  return {
1284
1295
  data: null,
1285
1296
  error: true,
1286
- error_code: data ? data.error_code : response.status,
1287
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1297
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1298
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1288
1299
  };
1289
1300
  }
1290
1301
  }
@@ -1342,6 +1353,7 @@ class BalanceService {
1342
1353
  if (queryParamOpts?.date !== undefined) {
1343
1354
  urlParams.append("date", queryParamOpts?.date.toString());
1344
1355
  }
1356
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`;
1345
1357
  let startTime;
1346
1358
  if (this.debug) {
1347
1359
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1349,13 +1361,13 @@ class BalanceService {
1349
1361
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
1350
1362
  headers: {
1351
1363
  "Authorization": `Bearer ${this.apiKey}`,
1352
- "X-Requested-With": userAgent
1364
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1353
1365
  }
1354
1366
  }));
1355
- debugOutput(response.url, response.status ?? 429, startTime);
1356
- if (response.status === null || response.status === 429) {
1367
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1368
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1357
1369
  try {
1358
- data = await this.LIMIT(() => backoff.backOff(response.url));
1370
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1359
1371
  }
1360
1372
  catch (error) {
1361
1373
  success = true;
@@ -1385,8 +1397,8 @@ class BalanceService {
1385
1397
  return {
1386
1398
  data: null,
1387
1399
  error: true,
1388
- error_code: data ? data.error_code : response.status,
1389
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1400
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1401
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1390
1402
  };
1391
1403
  }
1392
1404
  }
@@ -1422,6 +1434,7 @@ class BalanceService {
1422
1434
  if (queryParamOpts?.blockHeight !== undefined) {
1423
1435
  urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
1424
1436
  }
1437
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`;
1425
1438
  let startTime;
1426
1439
  if (this.debug) {
1427
1440
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1429,13 +1442,13 @@ class BalanceService {
1429
1442
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_native/?${urlParams}`, {
1430
1443
  headers: {
1431
1444
  "Authorization": `Bearer ${this.apiKey}`,
1432
- "X-Requested-With": userAgent
1445
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1433
1446
  }
1434
1447
  }));
1435
- debugOutput(response.url, response.status ?? 429, startTime);
1436
- if (response.status === null || response.status === 429) {
1448
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1449
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1437
1450
  try {
1438
- data = await this.LIMIT(() => backoff.backOff(response.url));
1451
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1439
1452
  }
1440
1453
  catch (error) {
1441
1454
  success = true;
@@ -1465,8 +1478,8 @@ class BalanceService {
1465
1478
  return {
1466
1479
  data: null,
1467
1480
  error: true,
1468
- error_code: data ? data.error_code : response.status,
1469
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1481
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1482
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1470
1483
  };
1471
1484
  }
1472
1485
  }
@@ -1694,11 +1707,13 @@ class OtherFees {
1694
1707
  *
1695
1708
  */
1696
1709
  class BaseService {
1697
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
1710
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
1698
1711
  this.apiKey = apiKey;
1699
1712
  this.debug = debug;
1700
1713
  this.threadCount = threadCount;
1701
1714
  this.is_key_valid = is_key_valid;
1715
+ this.enableRetry = enableRetry;
1716
+ this.source = source;
1702
1717
  this.LIMIT = pLimit$1(this.threadCount);
1703
1718
  }
1704
1719
  /**
@@ -1725,6 +1740,7 @@ class BaseService {
1725
1740
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1726
1741
  };
1727
1742
  }
1743
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`;
1728
1744
  let startTime;
1729
1745
  if (this.debug) {
1730
1746
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1732,13 +1748,13 @@ class BaseService {
1732
1748
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
1733
1749
  headers: {
1734
1750
  "Authorization": `Bearer ${this.apiKey}`,
1735
- "X-Requested-With": userAgent
1751
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1736
1752
  }
1737
1753
  }));
1738
- debugOutput(response.url, response.status ?? 429, startTime);
1739
- if (response.status === null || response.status === 429) {
1754
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1755
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1740
1756
  try {
1741
- data = await this.LIMIT(() => backoff.backOff(response.url));
1757
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1742
1758
  }
1743
1759
  catch (error) {
1744
1760
  success = true;
@@ -1768,8 +1784,8 @@ class BaseService {
1768
1784
  return {
1769
1785
  data: null,
1770
1786
  error: true,
1771
- error_code: data ? data.error_code : response.status,
1772
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1787
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1788
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1773
1789
  };
1774
1790
  }
1775
1791
  }
@@ -1798,6 +1814,7 @@ class BaseService {
1798
1814
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1799
1815
  };
1800
1816
  }
1817
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`;
1801
1818
  let startTime;
1802
1819
  if (this.debug) {
1803
1820
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1805,13 +1822,13 @@ class BaseService {
1805
1822
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
1806
1823
  headers: {
1807
1824
  "Authorization": `Bearer ${this.apiKey}`,
1808
- "X-Requested-With": userAgent
1825
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1809
1826
  }
1810
1827
  }));
1811
- debugOutput(response.url, response.status ?? 429, startTime);
1812
- if (response.status === null || response.status === 429) {
1828
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1829
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1813
1830
  try {
1814
- data = await this.LIMIT(() => backoff.backOff(response.url));
1831
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1815
1832
  }
1816
1833
  catch (error) {
1817
1834
  success = true;
@@ -1841,8 +1858,8 @@ class BaseService {
1841
1858
  return {
1842
1859
  data: null,
1843
1860
  error: true,
1844
- error_code: data ? data.error_code : response.status,
1845
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1861
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1862
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1846
1863
  };
1847
1864
  }
1848
1865
  }
@@ -1874,7 +1891,7 @@ class BaseService {
1874
1891
  if (queryParamOpts?.pageNumber !== undefined) {
1875
1892
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1876
1893
  }
1877
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount)) {
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)) {
1878
1895
  yield res;
1879
1896
  }
1880
1897
  success = true;
@@ -1919,6 +1936,7 @@ class BaseService {
1919
1936
  if (queryParamOpts?.pageNumber !== undefined) {
1920
1937
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1921
1938
  }
1939
+ const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`;
1922
1940
  let startTime;
1923
1941
  if (this.debug) {
1924
1942
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1926,13 +1944,13 @@ class BaseService {
1926
1944
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
1927
1945
  headers: {
1928
1946
  "Authorization": `Bearer ${this.apiKey}`,
1929
- "X-Requested-With": userAgent
1947
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1930
1948
  }
1931
1949
  }));
1932
- debugOutput(response.url, response.status ?? 429, startTime);
1933
- if (response.status === null || response.status === 429) {
1950
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1951
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1934
1952
  try {
1935
- data = await this.LIMIT(() => backoff.backOff(response.url));
1953
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1936
1954
  }
1937
1955
  catch (error) {
1938
1956
  success = true;
@@ -1962,8 +1980,8 @@ class BaseService {
1962
1980
  return {
1963
1981
  data: null,
1964
1982
  error: true,
1965
- error_code: data ? data.error_code : response.status,
1966
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1983
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1984
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1967
1985
  };
1968
1986
  }
1969
1987
  }
@@ -2016,6 +2034,7 @@ class BaseService {
2016
2034
  if (queryParamOpts?.skipDecode !== undefined) {
2017
2035
  urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
2018
2036
  }
2037
+ const url = `https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`;
2019
2038
  let startTime;
2020
2039
  if (this.debug) {
2021
2040
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2023,13 +2042,13 @@ class BaseService {
2023
2042
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
2024
2043
  headers: {
2025
2044
  "Authorization": `Bearer ${this.apiKey}`,
2026
- "X-Requested-With": userAgent
2045
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2027
2046
  }
2028
2047
  }));
2029
- debugOutput(response.url, response.status ?? 429, startTime);
2030
- if (response.status === null || response.status === 429) {
2048
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2049
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2031
2050
  try {
2032
- data = await this.LIMIT(() => backoff.backOff(response.url));
2051
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2033
2052
  }
2034
2053
  catch (error) {
2035
2054
  success = true;
@@ -2059,8 +2078,8 @@ class BaseService {
2059
2078
  return {
2060
2079
  data: null,
2061
2080
  error: true,
2062
- error_code: data ? data.error_code : response.status,
2063
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2081
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2082
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2064
2083
  };
2065
2084
  }
2066
2085
  }
@@ -2099,7 +2118,7 @@ class BaseService {
2099
2118
  if (queryParamOpts?.pageNumber !== undefined) {
2100
2119
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2101
2120
  }
2102
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
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)) {
2103
2122
  yield res;
2104
2123
  }
2105
2124
  success = true;
@@ -2151,6 +2170,7 @@ class BaseService {
2151
2170
  if (queryParamOpts?.pageNumber !== undefined) {
2152
2171
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2153
2172
  }
2173
+ const url = `https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`;
2154
2174
  let startTime;
2155
2175
  if (this.debug) {
2156
2176
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2158,13 +2178,13 @@ class BaseService {
2158
2178
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
2159
2179
  headers: {
2160
2180
  "Authorization": `Bearer ${this.apiKey}`,
2161
- "X-Requested-With": userAgent
2181
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2162
2182
  }
2163
2183
  }));
2164
- debugOutput(response.url, response.status ?? 429, startTime);
2165
- if (response.status === null || response.status === 429) {
2184
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2185
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2166
2186
  try {
2167
- data = await this.LIMIT(() => backoff.backOff(response.url));
2187
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2168
2188
  }
2169
2189
  catch (error) {
2170
2190
  success = true;
@@ -2194,8 +2214,8 @@ class BaseService {
2194
2214
  return {
2195
2215
  data: null,
2196
2216
  error: true,
2197
- error_code: data ? data.error_code : response.status,
2198
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2217
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2218
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2199
2219
  };
2200
2220
  }
2201
2221
  }
@@ -2238,7 +2258,7 @@ class BaseService {
2238
2258
  if (queryParamOpts?.pageNumber !== undefined) {
2239
2259
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2240
2260
  }
2241
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent$2, this.debug, this.threadCount)) {
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)) {
2242
2262
  yield res;
2243
2263
  }
2244
2264
  success = true;
@@ -2294,6 +2314,7 @@ class BaseService {
2294
2314
  if (queryParamOpts?.pageNumber !== undefined) {
2295
2315
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
2296
2316
  }
2317
+ const url = `https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`;
2297
2318
  let startTime;
2298
2319
  if (this.debug) {
2299
2320
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2301,13 +2322,13 @@ class BaseService {
2301
2322
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
2302
2323
  headers: {
2303
2324
  "Authorization": `Bearer ${this.apiKey}`,
2304
- "X-Requested-With": userAgent
2325
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2305
2326
  }
2306
2327
  }));
2307
- debugOutput(response.url, response.status ?? 429, startTime);
2308
- if (response.status === null || response.status === 429) {
2328
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2329
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2309
2330
  try {
2310
- data = await this.LIMIT(() => backoff.backOff(response.url));
2331
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2311
2332
  }
2312
2333
  catch (error) {
2313
2334
  success = true;
@@ -2337,8 +2358,8 @@ class BaseService {
2337
2358
  return {
2338
2359
  data: null,
2339
2360
  error: true,
2340
- error_code: data ? data.error_code : response.status,
2341
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2361
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2362
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2342
2363
  };
2343
2364
  }
2344
2365
  }
@@ -2369,16 +2390,17 @@ class BaseService {
2369
2390
  if (this.debug) {
2370
2391
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
2371
2392
  }
2393
+ const url = `https://api.covalenthq.com/v1/chains/?${urlParams}`;
2372
2394
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
2373
2395
  headers: {
2374
2396
  "Authorization": `Bearer ${this.apiKey}`,
2375
- "X-Requested-With": userAgent
2397
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2376
2398
  }
2377
2399
  }));
2378
- debugOutput(response.url, response.status ?? 429, startTime);
2379
- if (response.status === null || response.status === 429) {
2400
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2401
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2380
2402
  try {
2381
- data = await this.LIMIT(() => backoff.backOff(response.url));
2403
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2382
2404
  }
2383
2405
  catch (error) {
2384
2406
  success = true;
@@ -2408,8 +2430,8 @@ class BaseService {
2408
2430
  return {
2409
2431
  data: null,
2410
2432
  error: true,
2411
- error_code: data ? data.error_code : response.status,
2412
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2433
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2434
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2413
2435
  };
2414
2436
  }
2415
2437
  }
@@ -2436,6 +2458,7 @@ class BaseService {
2436
2458
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2437
2459
  };
2438
2460
  }
2461
+ const url = `https://api.covalenthq.com/v1/chains/status/?${urlParams}`;
2439
2462
  let startTime;
2440
2463
  if (this.debug) {
2441
2464
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2443,13 +2466,13 @@ class BaseService {
2443
2466
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
2444
2467
  headers: {
2445
2468
  "Authorization": `Bearer ${this.apiKey}`,
2446
- "X-Requested-With": userAgent
2469
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2447
2470
  }
2448
2471
  }));
2449
- debugOutput(response.url, response.status ?? 429, startTime);
2450
- if (response.status === null || response.status === 429) {
2472
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2473
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2451
2474
  try {
2452
- data = await this.LIMIT(() => backoff.backOff(response.url));
2475
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2453
2476
  }
2454
2477
  catch (error) {
2455
2478
  success = true;
@@ -2479,8 +2502,8 @@ class BaseService {
2479
2502
  return {
2480
2503
  data: null,
2481
2504
  error: true,
2482
- error_code: data ? data.error_code : response.status,
2483
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2505
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2506
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2484
2507
  };
2485
2508
  }
2486
2509
  }
@@ -2513,6 +2536,7 @@ class BaseService {
2513
2536
  if (queryParamOpts?.testnets !== undefined) {
2514
2537
  urlParams.append("testnets", queryParamOpts?.testnets.toString());
2515
2538
  }
2539
+ const url = `https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`;
2516
2540
  let startTime;
2517
2541
  if (this.debug) {
2518
2542
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2520,13 +2544,13 @@ class BaseService {
2520
2544
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
2521
2545
  headers: {
2522
2546
  "Authorization": `Bearer ${this.apiKey}`,
2523
- "X-Requested-With": userAgent
2547
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2524
2548
  }
2525
2549
  }));
2526
- debugOutput(response.url, response.status ?? 429, startTime);
2527
- if (response.status === null || response.status === 429) {
2550
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2551
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2528
2552
  try {
2529
- data = await this.LIMIT(() => backoff.backOff(response.url));
2553
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2530
2554
  }
2531
2555
  catch (error) {
2532
2556
  success = true;
@@ -2556,8 +2580,8 @@ class BaseService {
2556
2580
  return {
2557
2581
  data: null,
2558
2582
  error: true,
2559
- error_code: data ? data.error_code : response.status,
2560
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2583
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2584
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2561
2585
  };
2562
2586
  }
2563
2587
  }
@@ -2589,6 +2613,7 @@ class BaseService {
2589
2613
  if (queryParamOpts?.quoteCurrency !== undefined) {
2590
2614
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
2591
2615
  }
2616
+ const url = `https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`;
2592
2617
  let startTime;
2593
2618
  if (this.debug) {
2594
2619
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2596,20 +2621,20 @@ class BaseService {
2596
2621
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
2597
2622
  headers: {
2598
2623
  "Authorization": `Bearer ${this.apiKey}`,
2599
- "X-Requested-With": userAgent
2624
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
2600
2625
  }
2601
2626
  }));
2602
- debugOutput(response.url, response.status, startTime);
2603
- if (response.status === 429) {
2627
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
2628
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
2604
2629
  try {
2605
- data = await this.LIMIT(() => backoff.backOff(response.url));
2630
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
2606
2631
  }
2607
2632
  catch (error) {
2608
2633
  success = true;
2609
2634
  return {
2610
2635
  data: null,
2611
2636
  error: true,
2612
- error_code: response.status,
2637
+ error_code: response.status ?? 429,
2613
2638
  error_message: error.message
2614
2639
  };
2615
2640
  }
@@ -2632,8 +2657,8 @@ class BaseService {
2632
2657
  return {
2633
2658
  data: null,
2634
2659
  error: true,
2635
- error_code: data ? data.error_code : response.status,
2636
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2660
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
2661
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
2637
2662
  };
2638
2663
  }
2639
2664
  }
@@ -2962,11 +2987,13 @@ class MarketFloorPriceItem {
2962
2987
  *
2963
2988
  */
2964
2989
  class NftService {
2965
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
2990
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
2966
2991
  this.apiKey = apiKey;
2967
2992
  this.debug = debug;
2968
2993
  this.threadCount = threadCount;
2969
2994
  this.is_key_valid = is_key_valid;
2995
+ this.enableRetry = enableRetry;
2996
+ this.source = source;
2970
2997
  this.LIMIT = pLimit$1(this.threadCount);
2971
2998
  }
2972
2999
  /**
@@ -2998,7 +3025,7 @@ class NftService {
2998
3025
  if (queryParamOpts?.noSpam !== undefined) {
2999
3026
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
3000
3027
  }
3001
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
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)) {
3002
3029
  yield res;
3003
3030
  }
3004
3031
  success = true;
@@ -3045,6 +3072,7 @@ class NftService {
3045
3072
  if (queryParamOpts?.noSpam !== undefined) {
3046
3073
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
3047
3074
  }
3075
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
3048
3076
  let startTime;
3049
3077
  if (this.debug) {
3050
3078
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3052,13 +3080,13 @@ class NftService {
3052
3080
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
3053
3081
  headers: {
3054
3082
  "Authorization": `Bearer ${this.apiKey}`,
3055
- "X-Requested-With": userAgent
3083
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3056
3084
  }
3057
3085
  }));
3058
- debugOutput(response.url, response.status ?? 429, startTime);
3059
- if (response.status === null || response.status === 429) {
3086
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3087
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3060
3088
  try {
3061
- data = await this.LIMIT(() => backoff.backOff(response.url));
3089
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3062
3090
  }
3063
3091
  catch (error) {
3064
3092
  success = true;
@@ -3088,8 +3116,8 @@ class NftService {
3088
3116
  return {
3089
3117
  data: null,
3090
3118
  error: true,
3091
- error_code: data ? data.error_code : response.status,
3092
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3119
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3120
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3093
3121
  };
3094
3122
  }
3095
3123
  }
@@ -3131,6 +3159,7 @@ class NftService {
3131
3159
  if (queryParamOpts?.withUncached !== undefined) {
3132
3160
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
3133
3161
  }
3162
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
3134
3163
  let startTime;
3135
3164
  if (this.debug) {
3136
3165
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3138,13 +3167,13 @@ class NftService {
3138
3167
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
3139
3168
  headers: {
3140
3169
  "Authorization": `Bearer ${this.apiKey}`,
3141
- "X-Requested-With": userAgent
3170
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3142
3171
  }
3143
3172
  }));
3144
- debugOutput(response.url, response.status ?? 429, startTime);
3145
- if (response.status === null || response.status === 429) {
3173
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3174
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3146
3175
  try {
3147
- data = await this.LIMIT(() => backoff.backOff(response.url));
3176
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3148
3177
  }
3149
3178
  catch (error) {
3150
3179
  success = true;
@@ -3174,8 +3203,8 @@ class NftService {
3174
3203
  return {
3175
3204
  data: null,
3176
3205
  error: true,
3177
- error_code: data ? data.error_code : response.status,
3178
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3206
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3207
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3179
3208
  };
3180
3209
  }
3181
3210
  }
@@ -3222,7 +3251,7 @@ class NftService {
3222
3251
  if (queryParamOpts?.withUncached !== undefined) {
3223
3252
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
3224
3253
  }
3225
- for await (res of paginateEndpoint$1(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
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)) {
3226
3255
  yield res;
3227
3256
  }
3228
3257
  success = true;
@@ -3282,6 +3311,7 @@ class NftService {
3282
3311
  if (queryParamOpts?.withUncached !== undefined) {
3283
3312
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
3284
3313
  }
3314
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
3285
3315
  let startTime;
3286
3316
  if (this.debug) {
3287
3317
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3289,13 +3319,13 @@ class NftService {
3289
3319
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
3290
3320
  headers: {
3291
3321
  "Authorization": `Bearer ${this.apiKey}`,
3292
- "X-Requested-With": userAgent
3322
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3293
3323
  }
3294
3324
  }));
3295
- debugOutput(response.url, response.status ?? 429, startTime);
3296
- if (response.status === null || response.status === 429) {
3325
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3326
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3297
3327
  try {
3298
- data = await this.LIMIT(() => backoff.backOff(response.url));
3328
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3299
3329
  }
3300
3330
  catch (error) {
3301
3331
  success = true;
@@ -3325,8 +3355,8 @@ class NftService {
3325
3355
  return {
3326
3356
  data: null,
3327
3357
  error: true,
3328
- error_code: data ? data.error_code : response.status,
3329
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3358
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3359
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3330
3360
  };
3331
3361
  }
3332
3362
  }
@@ -3365,6 +3395,7 @@ class NftService {
3365
3395
  if (queryParamOpts?.withUncached !== undefined) {
3366
3396
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
3367
3397
  }
3398
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
3368
3399
  let startTime;
3369
3400
  if (this.debug) {
3370
3401
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3372,13 +3403,13 @@ class NftService {
3372
3403
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
3373
3404
  headers: {
3374
3405
  "Authorization": `Bearer ${this.apiKey}`,
3375
- "X-Requested-With": userAgent
3406
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3376
3407
  }
3377
3408
  }));
3378
- debugOutput(response.url, response.status ?? 429, startTime);
3379
- if (response.status === null || response.status === 429) {
3409
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3410
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3380
3411
  try {
3381
- data = await this.LIMIT(() => backoff.backOff(response.url));
3412
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3382
3413
  }
3383
3414
  catch (error) {
3384
3415
  success = true;
@@ -3408,8 +3439,8 @@ class NftService {
3408
3439
  return {
3409
3440
  data: null,
3410
3441
  error: true,
3411
- error_code: data ? data.error_code : response.status,
3412
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3442
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3443
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3413
3444
  };
3414
3445
  }
3415
3446
  }
@@ -3444,6 +3475,7 @@ class NftService {
3444
3475
  if (queryParamOpts?.noSpam !== undefined) {
3445
3476
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
3446
3477
  }
3478
+ const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
3447
3479
  let startTime;
3448
3480
  if (this.debug) {
3449
3481
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3451,13 +3483,13 @@ class NftService {
3451
3483
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
3452
3484
  headers: {
3453
3485
  "Authorization": `Bearer ${this.apiKey}`,
3454
- "X-Requested-With": userAgent
3486
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3455
3487
  }
3456
3488
  }));
3457
- debugOutput(response.url, response.status ?? 429, startTime);
3458
- if (response.status === null || response.status === 429) {
3489
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3490
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3459
3491
  try {
3460
- data = await this.LIMIT(() => backoff.backOff(response.url));
3492
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3461
3493
  }
3462
3494
  catch (error) {
3463
3495
  success = true;
@@ -3487,8 +3519,8 @@ class NftService {
3487
3519
  return {
3488
3520
  data: null,
3489
3521
  error: true,
3490
- error_code: data ? data.error_code : response.status,
3491
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3522
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3523
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3492
3524
  };
3493
3525
  }
3494
3526
  }
@@ -3517,6 +3549,7 @@ class NftService {
3517
3549
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3518
3550
  };
3519
3551
  }
3552
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
3520
3553
  let startTime;
3521
3554
  if (this.debug) {
3522
3555
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3524,13 +3557,13 @@ class NftService {
3524
3557
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
3525
3558
  headers: {
3526
3559
  "Authorization": `Bearer ${this.apiKey}`,
3527
- "X-Requested-With": userAgent
3560
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3528
3561
  }
3529
3562
  }));
3530
- debugOutput(response.url, response.status ?? 429, startTime);
3531
- if (response.status === null || response.status === 429) {
3563
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3564
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3532
3565
  try {
3533
- data = await this.LIMIT(() => backoff.backOff(response.url));
3566
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3534
3567
  }
3535
3568
  catch (error) {
3536
3569
  success = true;
@@ -3560,8 +3593,8 @@ class NftService {
3560
3593
  return {
3561
3594
  data: null,
3562
3595
  error: true,
3563
- error_code: data ? data.error_code : response.status,
3564
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3596
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3597
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3565
3598
  };
3566
3599
  }
3567
3600
  }
@@ -3591,6 +3624,7 @@ class NftService {
3591
3624
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3592
3625
  };
3593
3626
  }
3627
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
3594
3628
  let startTime;
3595
3629
  if (this.debug) {
3596
3630
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3598,13 +3632,13 @@ class NftService {
3598
3632
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
3599
3633
  headers: {
3600
3634
  "Authorization": `Bearer ${this.apiKey}`,
3601
- "X-Requested-With": userAgent
3635
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3602
3636
  }
3603
3637
  }));
3604
- debugOutput(response.url, response.status ?? 429, startTime);
3605
- if (response.status === null || response.status === 429) {
3638
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3639
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3606
3640
  try {
3607
- data = await this.LIMIT(() => backoff.backOff(response.url));
3641
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3608
3642
  }
3609
3643
  catch (error) {
3610
3644
  success = true;
@@ -3634,8 +3668,8 @@ class NftService {
3634
3668
  return {
3635
3669
  data: null,
3636
3670
  error: true,
3637
- error_code: data ? data.error_code : response.status,
3638
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3671
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3672
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3639
3673
  };
3640
3674
  }
3641
3675
  }
@@ -3664,6 +3698,7 @@ class NftService {
3664
3698
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3665
3699
  };
3666
3700
  }
3701
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
3667
3702
  let startTime;
3668
3703
  if (this.debug) {
3669
3704
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3671,13 +3706,13 @@ class NftService {
3671
3706
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
3672
3707
  headers: {
3673
3708
  "Authorization": `Bearer ${this.apiKey}`,
3674
- "X-Requested-With": userAgent
3709
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3675
3710
  }
3676
3711
  }));
3677
- debugOutput(response.url, response.status ?? 429, startTime);
3678
- if (response.status === null || response.status === 429) {
3712
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3713
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3679
3714
  try {
3680
- data = await this.LIMIT(() => backoff.backOff(response.url));
3715
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3681
3716
  }
3682
3717
  catch (error) {
3683
3718
  success = true;
@@ -3707,8 +3742,8 @@ class NftService {
3707
3742
  return {
3708
3743
  data: null,
3709
3744
  error: true,
3710
- error_code: data ? data.error_code : response.status,
3711
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3745
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3746
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3712
3747
  };
3713
3748
  }
3714
3749
  }
@@ -3738,6 +3773,7 @@ class NftService {
3738
3773
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3739
3774
  };
3740
3775
  }
3776
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
3741
3777
  let startTime;
3742
3778
  if (this.debug) {
3743
3779
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3745,13 +3781,13 @@ class NftService {
3745
3781
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
3746
3782
  headers: {
3747
3783
  "Authorization": `Bearer ${this.apiKey}`,
3748
- "X-Requested-With": userAgent
3784
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3749
3785
  }
3750
3786
  }));
3751
- debugOutput(response.url, response.status ?? 429, startTime);
3752
- if (response.status === null || response.status === 429) {
3787
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3788
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3753
3789
  try {
3754
- data = await this.LIMIT(() => backoff.backOff(response.url));
3790
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3755
3791
  }
3756
3792
  catch (error) {
3757
3793
  success = true;
@@ -3781,8 +3817,8 @@ class NftService {
3781
3817
  return {
3782
3818
  data: null,
3783
3819
  error: true,
3784
- error_code: data ? data.error_code : response.status,
3785
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3820
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3821
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3786
3822
  };
3787
3823
  }
3788
3824
  }
@@ -3813,6 +3849,7 @@ class NftService {
3813
3849
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3814
3850
  };
3815
3851
  }
3852
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
3816
3853
  let startTime;
3817
3854
  if (this.debug) {
3818
3855
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3820,13 +3857,13 @@ class NftService {
3820
3857
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
3821
3858
  headers: {
3822
3859
  "Authorization": `Bearer ${this.apiKey}`,
3823
- "X-Requested-With": userAgent
3860
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3824
3861
  }
3825
3862
  }));
3826
- debugOutput(response.url, response.status ?? 429, startTime);
3827
- if (response.status === null || response.status === 429) {
3863
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3864
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3828
3865
  try {
3829
- data = await this.LIMIT(() => backoff.backOff(response.url));
3866
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3830
3867
  }
3831
3868
  catch (error) {
3832
3869
  success = true;
@@ -3856,8 +3893,8 @@ class NftService {
3856
3893
  return {
3857
3894
  data: null,
3858
3895
  error: true,
3859
- error_code: data ? data.error_code : response.status,
3860
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3896
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3897
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3861
3898
  };
3862
3899
  }
3863
3900
  }
@@ -3895,6 +3932,7 @@ class NftService {
3895
3932
  if (queryParamOpts?.quoteCurrency !== undefined) {
3896
3933
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
3897
3934
  }
3935
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
3898
3936
  let startTime;
3899
3937
  if (this.debug) {
3900
3938
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3902,13 +3940,13 @@ class NftService {
3902
3940
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
3903
3941
  headers: {
3904
3942
  "Authorization": `Bearer ${this.apiKey}`,
3905
- "X-Requested-With": userAgent
3943
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3906
3944
  }
3907
3945
  }));
3908
- debugOutput(response.url, response.status ?? 429, startTime);
3909
- if (response.status === null || response.status === 429) {
3946
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
3947
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3910
3948
  try {
3911
- data = await this.LIMIT(() => backoff.backOff(response.url));
3949
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3912
3950
  }
3913
3951
  catch (error) {
3914
3952
  success = true;
@@ -3938,8 +3976,8 @@ class NftService {
3938
3976
  return {
3939
3977
  data: null,
3940
3978
  error: true,
3941
- error_code: data ? data.error_code : response.status,
3942
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
3979
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
3980
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
3943
3981
  };
3944
3982
  }
3945
3983
  }
@@ -3977,6 +4015,7 @@ class NftService {
3977
4015
  if (queryParamOpts?.quoteCurrency !== undefined) {
3978
4016
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
3979
4017
  }
4018
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
3980
4019
  let startTime;
3981
4020
  if (this.debug) {
3982
4021
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3984,13 +4023,13 @@ class NftService {
3984
4023
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
3985
4024
  headers: {
3986
4025
  "Authorization": `Bearer ${this.apiKey}`,
3987
- "X-Requested-With": userAgent
4026
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
3988
4027
  }
3989
4028
  }));
3990
- debugOutput(response.url, response.status ?? 429, startTime);
3991
- if (response.status === null || response.status === 429) {
4029
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4030
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
3992
4031
  try {
3993
- data = await this.LIMIT(() => backoff.backOff(response.url));
4032
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
3994
4033
  }
3995
4034
  catch (error) {
3996
4035
  success = true;
@@ -4020,8 +4059,8 @@ class NftService {
4020
4059
  return {
4021
4060
  data: null,
4022
4061
  error: true,
4023
- error_code: data ? data.error_code : response.status,
4024
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4062
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4063
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4025
4064
  };
4026
4065
  }
4027
4066
  }
@@ -4059,6 +4098,7 @@ class NftService {
4059
4098
  if (queryParamOpts?.quoteCurrency !== undefined) {
4060
4099
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4061
4100
  }
4101
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
4062
4102
  let startTime;
4063
4103
  if (this.debug) {
4064
4104
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -4066,13 +4106,13 @@ class NftService {
4066
4106
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
4067
4107
  headers: {
4068
4108
  "Authorization": `Bearer ${this.apiKey}`,
4069
- "X-Requested-With": userAgent
4109
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
4070
4110
  }
4071
4111
  }));
4072
- debugOutput(response.url, response.status ?? 429, startTime);
4073
- if (response.status === null || response.status === 429) {
4112
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4113
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4074
4114
  try {
4075
- data = await this.LIMIT(() => backoff.backOff(response.url));
4115
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
4076
4116
  }
4077
4117
  catch (error) {
4078
4118
  success = true;
@@ -4102,8 +4142,8 @@ class NftService {
4102
4142
  return {
4103
4143
  data: null,
4104
4144
  error: true,
4105
- error_code: data ? data.error_code : response.status,
4106
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4145
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4146
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4107
4147
  };
4108
4148
  }
4109
4149
  }
@@ -4129,10 +4169,10 @@ class Price {
4129
4169
  this.date = data.date && data.date !== null ? dateFns.parseISO(data.date.toString()) : null;
4130
4170
  this.price = data.price;
4131
4171
  this.pretty_price = data.pretty_price;
4132
- this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$1(data.contract_metadata) : null;
4172
+ this.contract_metadata = data.contract_metadata && data.contract_metadata !== null ? new ContractMetadata$2(data.contract_metadata) : null;
4133
4173
  }
4134
4174
  }
4135
- let ContractMetadata$1 = class ContractMetadata {
4175
+ let ContractMetadata$2 = class ContractMetadata {
4136
4176
  constructor(data) {
4137
4177
  this.contract_decimals = data.contract_decimals;
4138
4178
  this.contract_name = data.contract_name;
@@ -4143,11 +4183,13 @@ let ContractMetadata$1 = class ContractMetadata {
4143
4183
  }
4144
4184
  };
4145
4185
  class PricingService {
4146
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
4186
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
4147
4187
  this.apiKey = apiKey;
4148
4188
  this.debug = debug;
4149
4189
  this.threadCount = threadCount;
4150
4190
  this.is_key_valid = is_key_valid;
4191
+ this.enableRetry = enableRetry;
4192
+ this.source = source;
4151
4193
  this.LIMIT = pLimit$1(this.threadCount);
4152
4194
  }
4153
4195
  /**
@@ -4188,6 +4230,7 @@ class PricingService {
4188
4230
  if (queryParamOpts?.pricesAtAsc !== undefined) {
4189
4231
  urlParams.append("prices-at-asc", queryParamOpts?.pricesAtAsc.toString());
4190
4232
  }
4233
+ const url = `https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`;
4191
4234
  let startTime;
4192
4235
  if (this.debug) {
4193
4236
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -4195,13 +4238,13 @@ class PricingService {
4195
4238
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/?${urlParams}`, {
4196
4239
  headers: {
4197
4240
  "Authorization": `Bearer ${this.apiKey}`,
4198
- "X-Requested-With": userAgent
4241
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
4199
4242
  }
4200
4243
  }));
4201
- debugOutput(response.url, response.status ?? 429, startTime);
4202
- if (response.status === null || response.status === 429) {
4244
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4245
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4203
4246
  try {
4204
- data = await this.LIMIT(() => backoff.backOff(response.url));
4247
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
4205
4248
  }
4206
4249
  catch (error) {
4207
4250
  success = true;
@@ -4235,8 +4278,8 @@ class PricingService {
4235
4278
  return {
4236
4279
  data: null,
4237
4280
  error: true,
4238
- error_code: data ? data.error_code : response.status,
4239
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4281
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4282
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4240
4283
  };
4241
4284
  }
4242
4285
  }
@@ -4274,7 +4317,7 @@ class Transaction {
4274
4317
  this.gas_quote = data.gas_quote;
4275
4318
  this.pretty_gas_quote = data.pretty_gas_quote;
4276
4319
  this.gas_quote_rate = data.gas_quote_rate;
4277
- this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
4320
+ this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata$1(data.gas_metadata) : null;
4278
4321
  this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
4279
4322
  this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
4280
4323
  this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
@@ -4283,7 +4326,7 @@ class Transaction {
4283
4326
  this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
4284
4327
  }
4285
4328
  }
4286
- class ContractMetadata {
4329
+ let ContractMetadata$1 = class ContractMetadata {
4287
4330
  constructor(data) {
4288
4331
  this.contract_decimals = data.contract_decimals;
4289
4332
  this.contract_name = data.contract_name;
@@ -4292,7 +4335,7 @@ class ContractMetadata {
4292
4335
  this.supports_erc = data.supports_erc;
4293
4336
  this.logo_url = data.logo_url;
4294
4337
  }
4295
- }
4338
+ };
4296
4339
  class Explorer {
4297
4340
  constructor(data) {
4298
4341
  this.label = data.label;
@@ -4457,11 +4500,13 @@ class Param {
4457
4500
  }
4458
4501
  }
4459
4502
  class RecentTransactionsResponse {
4460
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4503
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4461
4504
  this._debug = _debug;
4462
4505
  this._apiKey = _apiKey;
4463
4506
  this._threadCount = _threadCount;
4464
4507
  this._urlParams = _urlParams;
4508
+ this._enableRetry = _enableRetry;
4509
+ this._source = _source;
4465
4510
  this.address = data.address;
4466
4511
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
4467
4512
  this.quote_currency = data.quote_currency;
@@ -4492,16 +4537,17 @@ class RecentTransactionsResponse {
4492
4537
  error_message: "Invalid URL: URL link cannot be null"
4493
4538
  };
4494
4539
  }
4540
+ const url = `${this.links.prev}?${this._urlParams}`;
4495
4541
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4496
4542
  headers: {
4497
4543
  "Authorization": `Bearer ${this._apiKey}`,
4498
- "X-Requested-With": userAgent
4544
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4499
4545
  }
4500
4546
  }));
4501
- debugOutput(response.url, response.status ?? 429, startTime);
4502
- if (response.status === null || response.status === 429) {
4547
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4548
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4503
4549
  try {
4504
- data = await LIMIT(() => backoff.backOff(response.url));
4550
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4505
4551
  }
4506
4552
  catch (error) {
4507
4553
  success = true;
@@ -4516,7 +4562,7 @@ class RecentTransactionsResponse {
4516
4562
  else {
4517
4563
  data = await response.json();
4518
4564
  }
4519
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4565
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4520
4566
  checkAndModifyResponse(dataClass);
4521
4567
  success = true;
4522
4568
  return {
@@ -4531,8 +4577,8 @@ class RecentTransactionsResponse {
4531
4577
  return {
4532
4578
  data: null,
4533
4579
  error: true,
4534
- error_code: data ? data.error_code : response.status,
4535
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4580
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4581
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4536
4582
  };
4537
4583
  }
4538
4584
  }
@@ -4558,16 +4604,17 @@ class RecentTransactionsResponse {
4558
4604
  error_message: "Invalid URL: URL link cannot be null"
4559
4605
  };
4560
4606
  }
4607
+ const url = `${this.links.next}?${this._urlParams}`;
4561
4608
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4562
4609
  headers: {
4563
4610
  "Authorization": `Bearer ${this._apiKey}`,
4564
- "X-Requested-With": userAgent
4611
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4565
4612
  }
4566
4613
  }));
4567
- debugOutput(response.url, response.status ?? 429, startTime);
4568
- if (response.status === null || response.status === 429) {
4614
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4615
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4569
4616
  try {
4570
- data = await LIMIT(() => backoff.backOff(response.url));
4617
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4571
4618
  }
4572
4619
  catch (error) {
4573
4620
  success = true;
@@ -4582,7 +4629,7 @@ class RecentTransactionsResponse {
4582
4629
  else {
4583
4630
  data = await response.json();
4584
4631
  }
4585
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4632
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4586
4633
  checkAndModifyResponse(dataClass);
4587
4634
  success = true;
4588
4635
  return {
@@ -4597,8 +4644,8 @@ class RecentTransactionsResponse {
4597
4644
  return {
4598
4645
  data: null,
4599
4646
  error: true,
4600
- error_code: data ? data.error_code : response.status,
4601
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4647
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4648
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4602
4649
  };
4603
4650
  }
4604
4651
  }
@@ -4610,6 +4657,155 @@ class PaginationLinks {
4610
4657
  this.next = data.next;
4611
4658
  }
4612
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
+ }
4613
4809
  class TransactionsBlockResponse {
4614
4810
  constructor(data) {
4615
4811
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
@@ -4642,11 +4838,13 @@ class TransactionSummary {
4642
4838
  }
4643
4839
  }
4644
4840
  class TransactionsResponse {
4645
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4841
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4646
4842
  this._debug = _debug;
4647
4843
  this._apiKey = _apiKey;
4648
4844
  this._threadCount = _threadCount;
4649
4845
  this._urlParams = _urlParams;
4846
+ this._enableRetry = _enableRetry;
4847
+ this._source = _source;
4650
4848
  this.address = data.address;
4651
4849
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
4652
4850
  this.quote_currency = data.quote_currency;
@@ -4677,16 +4875,17 @@ class TransactionsResponse {
4677
4875
  error_message: "Invalid URL: URL link cannot be null"
4678
4876
  };
4679
4877
  }
4878
+ const url = `${this.links.prev}?${this._urlParams}`;
4680
4879
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4681
4880
  headers: {
4682
4881
  "Authorization": `Bearer ${this._apiKey}`,
4683
- "X-Requested-With": userAgent
4882
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4684
4883
  }
4685
4884
  }));
4686
- debugOutput(response.url, response.status ?? 429, startTime);
4687
- if (response.status === null || response.status === 429) {
4885
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4886
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4688
4887
  try {
4689
- data = await LIMIT(() => backoff.backOff(response.url));
4888
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4690
4889
  }
4691
4890
  catch (error) {
4692
4891
  success = true;
@@ -4701,7 +4900,7 @@ class TransactionsResponse {
4701
4900
  else {
4702
4901
  data = await response.json();
4703
4902
  }
4704
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4903
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4705
4904
  checkAndModifyResponse(dataClass);
4706
4905
  success = true;
4707
4906
  return {
@@ -4716,8 +4915,8 @@ class TransactionsResponse {
4716
4915
  return {
4717
4916
  data: null,
4718
4917
  error: true,
4719
- error_code: data ? data.error_code : response.status,
4720
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4918
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4919
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4721
4920
  };
4722
4921
  }
4723
4922
  }
@@ -4743,16 +4942,17 @@ class TransactionsResponse {
4743
4942
  error_message: "Invalid URL: URL link cannot be null"
4744
4943
  };
4745
4944
  }
4945
+ const url = `${this.links.next}?${this._urlParams}`;
4746
4946
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4747
4947
  headers: {
4748
4948
  "Authorization": `Bearer ${this._apiKey}`,
4749
- "X-Requested-With": userAgent
4949
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4750
4950
  }
4751
4951
  }));
4752
- debugOutput(response.url, response.status ?? 429, startTime);
4753
- if (response.status === null || response.status === 429) {
4952
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
4953
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4754
4954
  try {
4755
- data = await LIMIT(() => backoff.backOff(response.url));
4955
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4756
4956
  }
4757
4957
  catch (error) {
4758
4958
  success = true;
@@ -4767,7 +4967,7 @@ class TransactionsResponse {
4767
4967
  else {
4768
4968
  data = await response.json();
4769
4969
  }
4770
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4970
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4771
4971
  checkAndModifyResponse(dataClass);
4772
4972
  success = true;
4773
4973
  return {
@@ -4782,19 +4982,21 @@ class TransactionsResponse {
4782
4982
  return {
4783
4983
  data: null,
4784
4984
  error: true,
4785
- error_code: data ? data.error_code : response.status,
4786
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4985
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
4986
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4787
4987
  };
4788
4988
  }
4789
4989
  }
4790
4990
  }
4791
4991
  }
4792
4992
  class TransactionsTimeBucketResponse {
4793
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4993
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
4794
4994
  this._debug = _debug;
4795
4995
  this._apiKey = _apiKey;
4796
4996
  this._threadCount = _threadCount;
4797
4997
  this._urlParams = _urlParams;
4998
+ this._enableRetry = _enableRetry;
4999
+ this._source = _source;
4798
5000
  this.address = data.address;
4799
5001
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
4800
5002
  this.quote_currency = data.quote_currency;
@@ -4826,16 +5028,17 @@ class TransactionsTimeBucketResponse {
4826
5028
  error_message: "Invalid URL: URL link cannot be null"
4827
5029
  };
4828
5030
  }
5031
+ const url = `${this.links.prev}?${this._urlParams}`;
4829
5032
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4830
5033
  headers: {
4831
5034
  "Authorization": `Bearer ${this._apiKey}`,
4832
- "X-Requested-With": userAgent
5035
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4833
5036
  }
4834
5037
  }));
4835
- debugOutput(response.url, response.status ?? 429, startTime);
4836
- if (response.status === null || response.status === 429) {
5038
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5039
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4837
5040
  try {
4838
- data = await LIMIT(() => backoff.backOff(response.url));
5041
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4839
5042
  }
4840
5043
  catch (error) {
4841
5044
  success = true;
@@ -4850,7 +5053,7 @@ class TransactionsTimeBucketResponse {
4850
5053
  else {
4851
5054
  data = await response.json();
4852
5055
  }
4853
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
5056
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4854
5057
  checkAndModifyResponse(dataClass);
4855
5058
  success = true;
4856
5059
  return {
@@ -4865,8 +5068,8 @@ class TransactionsTimeBucketResponse {
4865
5068
  return {
4866
5069
  data: null,
4867
5070
  error: true,
4868
- error_code: data ? data.error_code : response.status,
4869
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5071
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5072
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4870
5073
  };
4871
5074
  }
4872
5075
  }
@@ -4892,16 +5095,17 @@ class TransactionsTimeBucketResponse {
4892
5095
  error_message: "Invalid URL: URL link cannot be null"
4893
5096
  };
4894
5097
  }
5098
+ const url = `${this.links.next}?${this._urlParams}`;
4895
5099
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4896
5100
  headers: {
4897
5101
  "Authorization": `Bearer ${this._apiKey}`,
4898
- "X-Requested-With": userAgent
5102
+ "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
4899
5103
  }
4900
5104
  }));
4901
- debugOutput(response.url, response.status ?? 429, startTime);
4902
- if (response.status === null || response.status === 429) {
5105
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5106
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4903
5107
  try {
4904
- data = await LIMIT(() => backoff.backOff(response.url));
5108
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
4905
5109
  }
4906
5110
  catch (error) {
4907
5111
  success = true;
@@ -4916,7 +5120,7 @@ class TransactionsTimeBucketResponse {
4916
5120
  else {
4917
5121
  data = await response.json();
4918
5122
  }
4919
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
5123
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
4920
5124
  checkAndModifyResponse(dataClass);
4921
5125
  success = true;
4922
5126
  return {
@@ -4931,8 +5135,8 @@ class TransactionsTimeBucketResponse {
4931
5135
  return {
4932
5136
  data: null,
4933
5137
  error: true,
4934
- error_code: data ? data.error_code : response.status,
4935
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5138
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5139
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
4936
5140
  };
4937
5141
  }
4938
5142
  }
@@ -4942,7 +5146,7 @@ class TransactionsTimeBucketResponse {
4942
5146
  * Transactions APIs
4943
5147
  *
4944
5148
  */
4945
- async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
5149
+ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
4946
5150
  let hasNext = true;
4947
5151
  let response;
4948
5152
  let data;
@@ -4957,17 +5161,17 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
4957
5161
  response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
4958
5162
  headers: {
4959
5163
  "Authorization": `Bearer ${apiKey}`,
4960
- "X-Requested-With": userAgent
5164
+ "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
4961
5165
  }
4962
5166
  }));
4963
- debugOutput(response.url, response.status ?? 429, startTime);
4964
- if (response.status === null || response.status === 429) {
5167
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5168
+ if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
4965
5169
  try {
4966
- data = await LIMIT(() => backoff.backOff(response.url));
5170
+ data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
4967
5171
  }
4968
5172
  catch (error) {
4969
5173
  hasNext = false;
4970
- throw new Error(`An error occurred ${response.status}: ${error.message}`);
5174
+ throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
4971
5175
  }
4972
5176
  }
4973
5177
  else {
@@ -4999,11 +5203,13 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
4999
5203
  }
5000
5204
  }
5001
5205
  class TransactionService {
5002
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
5206
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
5003
5207
  this.apiKey = apiKey;
5004
5208
  this.debug = debug;
5005
5209
  this.threadCount = threadCount;
5006
5210
  this.is_key_valid = is_key_valid;
5211
+ this.enableRetry = enableRetry;
5212
+ this.source = source;
5007
5213
  this.LIMIT = pLimit$1(this.threadCount);
5008
5214
  }
5009
5215
  /**
@@ -5059,16 +5265,17 @@ class TransactionService {
5059
5265
  if (this.debug) {
5060
5266
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5061
5267
  }
5268
+ const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
5062
5269
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
5063
5270
  headers: {
5064
5271
  "Authorization": `Bearer ${this.apiKey}`,
5065
- "X-Requested-With": userAgent
5272
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5066
5273
  }
5067
5274
  }));
5068
- debugOutput(response.url, response.status ?? 429, startTime);
5069
- if (response.status === null || response.status === 429) {
5275
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5276
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5070
5277
  try {
5071
- data = await this.LIMIT(() => backoff.backOff(response.url));
5278
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5072
5279
  }
5073
5280
  catch (error) {
5074
5281
  success = true;
@@ -5098,8 +5305,8 @@ class TransactionService {
5098
5305
  return {
5099
5306
  data: null,
5100
5307
  error: true,
5101
- error_code: data ? data.error_code : response.status,
5102
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5308
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5309
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5103
5310
  };
5104
5311
  }
5105
5312
  }
@@ -5138,7 +5345,7 @@ class TransactionService {
5138
5345
  if (queryParamOpts?.withSafe !== undefined) {
5139
5346
  urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
5140
5347
  }
5141
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
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)) {
5142
5349
  yield tx;
5143
5350
  }
5144
5351
  success = true;
@@ -5194,16 +5401,17 @@ class TransactionService {
5194
5401
  if (this.debug) {
5195
5402
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5196
5403
  }
5404
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
5197
5405
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
5198
5406
  headers: {
5199
5407
  "Authorization": `Bearer ${this.apiKey}`,
5200
- "X-Requested-With": userAgent
5408
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5201
5409
  }
5202
5410
  }));
5203
- debugOutput(response.url, response.status ?? 429, startTime);
5204
- if (response.status === null || response.status === 429) {
5411
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5412
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5205
5413
  try {
5206
- data = await this.LIMIT(() => backoff.backOff(response.url));
5414
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5207
5415
  }
5208
5416
  catch (error) {
5209
5417
  success = true;
@@ -5218,7 +5426,7 @@ class TransactionService {
5218
5426
  else {
5219
5427
  data = await response.json();
5220
5428
  }
5221
- const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
5429
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
5222
5430
  checkAndModifyResponse(dataClass);
5223
5431
  success = true;
5224
5432
  return {
@@ -5233,8 +5441,8 @@ class TransactionService {
5233
5441
  return {
5234
5442
  data: null,
5235
5443
  error: true,
5236
- error_code: data ? data.error_code : response.status,
5237
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5444
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5445
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5238
5446
  };
5239
5447
  }
5240
5448
  }
@@ -5280,16 +5488,17 @@ class TransactionService {
5280
5488
  if (this.debug) {
5281
5489
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5282
5490
  }
5491
+ const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
5283
5492
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
5284
5493
  headers: {
5285
5494
  "Authorization": `Bearer ${this.apiKey}`,
5286
- "X-Requested-With": userAgent
5495
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5287
5496
  }
5288
5497
  }));
5289
- debugOutput(response.url, response.status ?? 429, startTime);
5290
- if (response.status === null || response.status === 429) {
5498
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5499
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5291
5500
  try {
5292
- data = await this.LIMIT(() => backoff.backOff(response.url));
5501
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5293
5502
  }
5294
5503
  catch (error) {
5295
5504
  success = true;
@@ -5319,8 +5528,8 @@ class TransactionService {
5319
5528
  return {
5320
5529
  data: null,
5321
5530
  error: true,
5322
- error_code: data ? data.error_code : response.status,
5323
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5531
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5532
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5324
5533
  };
5325
5534
  }
5326
5535
  }
@@ -5353,16 +5562,17 @@ class TransactionService {
5353
5562
  if (this.debug) {
5354
5563
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5355
5564
  }
5565
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
5356
5566
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
5357
5567
  headers: {
5358
5568
  "Authorization": `Bearer ${this.apiKey}`,
5359
- "X-Requested-With": userAgent
5569
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5360
5570
  }
5361
5571
  }));
5362
- debugOutput(response.url, response.status ?? 429, startTime);
5363
- if (response.status === null || response.status === 429) {
5572
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5573
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5364
5574
  try {
5365
- data = await this.LIMIT(() => backoff.backOff(response.url));
5575
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5366
5576
  }
5367
5577
  catch (error) {
5368
5578
  success = true;
@@ -5392,8 +5602,8 @@ class TransactionService {
5392
5602
  return {
5393
5603
  data: null,
5394
5604
  error: true,
5395
- error_code: data ? data.error_code : response.status,
5396
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5605
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5606
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5397
5607
  };
5398
5608
  }
5399
5609
  }
@@ -5442,16 +5652,17 @@ class TransactionService {
5442
5652
  if (this.debug) {
5443
5653
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5444
5654
  }
5655
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
5445
5656
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
5446
5657
  headers: {
5447
5658
  "Authorization": `Bearer ${this.apiKey}`,
5448
- "X-Requested-With": userAgent
5659
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5449
5660
  }
5450
5661
  }));
5451
- debugOutput(response.url, response.status ?? 429, startTime);
5452
- if (response.status === null || response.status === 429) {
5662
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5663
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5453
5664
  try {
5454
- data = await this.LIMIT(() => backoff.backOff(response.url));
5665
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5455
5666
  }
5456
5667
  catch (error) {
5457
5668
  success = true;
@@ -5466,7 +5677,7 @@ class TransactionService {
5466
5677
  else {
5467
5678
  data = await response.json();
5468
5679
  }
5469
- const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
5680
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
5470
5681
  checkAndModifyResponse(dataClass);
5471
5682
  success = true;
5472
5683
  return {
@@ -5481,8 +5692,8 @@ class TransactionService {
5481
5692
  return {
5482
5693
  data: null,
5483
5694
  error: true,
5484
- error_code: data ? data.error_code : response.status,
5485
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5695
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5696
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5486
5697
  };
5487
5698
  }
5488
5699
  }
@@ -5527,16 +5738,17 @@ class TransactionService {
5527
5738
  if (this.debug) {
5528
5739
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5529
5740
  }
5741
+ const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
5530
5742
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
5531
5743
  headers: {
5532
5744
  "Authorization": `Bearer ${this.apiKey}`,
5533
- "X-Requested-With": userAgent
5745
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
5534
5746
  }
5535
5747
  }));
5536
- debugOutput(response.url, response.status ?? 429, startTime);
5537
- if (response.status === null || response.status === 429) {
5748
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5749
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5538
5750
  try {
5539
- data = await this.LIMIT(() => backoff.backOff(response.url));
5751
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5540
5752
  }
5541
5753
  catch (error) {
5542
5754
  success = true;
@@ -5551,7 +5763,7 @@ class TransactionService {
5551
5763
  else {
5552
5764
  data = await response.json();
5553
5765
  }
5554
- const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
5766
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
5555
5767
  checkAndModifyResponse(dataClass);
5556
5768
  success = true;
5557
5769
  return {
@@ -5566,40 +5778,215 @@ class TransactionService {
5566
5778
  return {
5567
5779
  data: null,
5568
5780
  error: true,
5569
- error_code: data ? data.error_code : response.status,
5570
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
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"
5571
5783
  };
5572
5784
  }
5573
5785
  }
5574
5786
  }
5575
- }
5576
-
5577
- class PoolResponse {
5578
- constructor(data) {
5579
- this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
5580
- this.chain_id = data.chain_id;
5581
- this.chain_name = data.chain_name;
5582
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Pool(itemData)) : null;
5583
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
5584
- }
5585
- }
5586
- class Pool {
5587
- constructor(data) {
5588
- this.exchange = data.exchange;
5589
- this.swap_count_24h = data.swap_count_24h;
5590
- this.total_liquidity_quote = data.total_liquidity_quote;
5591
- this.volume_24h_quote = data.volume_24h_quote;
5592
- this.fee_24h_quote = data.fee_24h_quote;
5593
- this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
5594
- this.quote_rate = data.quote_rate;
5595
- this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
5596
- this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
5597
- this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
5598
- this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
5599
- this.chain_name = data.chain_name;
5600
- this.chain_id = data.chain_id;
5601
- this.dex_name = data.dex_name;
5602
- this.volume_7d_quote = data.volume_7d_quote;
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
5921
+ }
5922
+ }));
5923
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
5924
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
5925
+ try {
5926
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
5927
+ }
5928
+ catch (error) {
5929
+ success = true;
5930
+ return {
5931
+ data: null,
5932
+ error: true,
5933
+ error_code: response.status ?? 429,
5934
+ error_message: error.message
5935
+ };
5936
+ }
5937
+ }
5938
+ else {
5939
+ data = await response.json();
5940
+ }
5941
+ const dataClass = new TransactionsBlockResponse(data.data);
5942
+ checkAndModifyResponse(dataClass);
5943
+ success = true;
5944
+ return {
5945
+ data: dataClass,
5946
+ error: data.error,
5947
+ error_code: data ? data.error_code : response.status,
5948
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5949
+ };
5950
+ }
5951
+ catch (error) {
5952
+ success = true;
5953
+ return {
5954
+ data: null,
5955
+ error: true,
5956
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
5957
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
5958
+ };
5959
+ }
5960
+ }
5961
+ }
5962
+ }
5963
+
5964
+ class PoolResponse {
5965
+ constructor(data) {
5966
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
5967
+ this.chain_id = data.chain_id;
5968
+ this.chain_name = data.chain_name;
5969
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Pool(itemData)) : null;
5970
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
5971
+ }
5972
+ }
5973
+ class Pool {
5974
+ constructor(data) {
5975
+ this.exchange = data.exchange;
5976
+ this.swap_count_24h = data.swap_count_24h;
5977
+ this.total_liquidity_quote = data.total_liquidity_quote;
5978
+ this.volume_24h_quote = data.volume_24h_quote;
5979
+ this.fee_24h_quote = data.fee_24h_quote;
5980
+ this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
5981
+ this.quote_rate = data.quote_rate;
5982
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
5983
+ this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
5984
+ this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
5985
+ this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
5986
+ this.chain_name = data.chain_name;
5987
+ this.chain_id = data.chain_id;
5988
+ this.dex_name = data.dex_name;
5989
+ this.volume_7d_quote = data.volume_7d_quote;
5603
5990
  this.annualized_fee = data.annualized_fee;
5604
5991
  this.token_0 = data.token_0 && data.token_0 !== null ? new Token(data.token_0) : null;
5605
5992
  this.token_1 = data.token_1 && data.token_1 !== null ? new Token(data.token_1) : null;
@@ -5763,6 +6150,7 @@ class PoolsDexDataItem {
5763
6150
  this.volume_24h_quote = data.volume_24h_quote;
5764
6151
  this.volume_7d_quote = data.volume_7d_quote;
5765
6152
  this.fee_24h_quote = data.fee_24h_quote;
6153
+ this.annualized_fee = data.annualized_fee;
5766
6154
  this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
5767
6155
  this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
5768
6156
  this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
@@ -5805,6 +6193,7 @@ class UniswapLikeToken {
5805
6193
  this.logo_url = data.logo_url;
5806
6194
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
5807
6195
  this.quote = data.quote;
6196
+ this.pretty_quote = data.pretty_quote;
5808
6197
  this.quote_rate = data.quote_rate;
5809
6198
  }
5810
6199
  }
@@ -5816,6 +6205,7 @@ class UniswapLikeTokenWithSupply {
5816
6205
  this.logo_url = data.logo_url;
5817
6206
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
5818
6207
  this.quote = data.quote;
6208
+ this.pretty_quote = data.pretty_quote;
5819
6209
  this.quote_rate = data.quote_rate;
5820
6210
  this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
5821
6211
  }
@@ -5852,6 +6242,75 @@ class TokenV2Volume {
5852
6242
  this.total_volume_24h_quote = data.total_volume_24h_quote;
5853
6243
  }
5854
6244
  }
6245
+ class NetworkExchangeTokenViewResponse {
6246
+ constructor(data) {
6247
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
6248
+ this.chain_id = data.chain_id;
6249
+ this.chain_name = data.chain_name;
6250
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
6251
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
6252
+ }
6253
+ }
6254
+ class TokenV2VolumeWithChartData {
6255
+ constructor(data) {
6256
+ this.chain_name = data.chain_name;
6257
+ this.chain_id = data.chain_id;
6258
+ this.dex_name = data.dex_name;
6259
+ this.contract_address = data.contract_address;
6260
+ this.contract_name = data.contract_name;
6261
+ this.total_liquidity = data.total_liquidity;
6262
+ this.total_volume_24h = data.total_volume_24h;
6263
+ this.logo_url = data.logo_url;
6264
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
6265
+ this.contract_decimals = data.contract_decimals;
6266
+ this.swap_count_24h = data.swap_count_24h;
6267
+ this.quote_rate = data.quote_rate;
6268
+ this.quote_rate_24h = data.quote_rate_24h;
6269
+ this.pretty_quote_rate = data.pretty_quote_rate;
6270
+ this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
6271
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
6272
+ this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
6273
+ this.total_liquidity_quote = data.total_liquidity_quote;
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;
6312
+ }
6313
+ }
5855
6314
  class SupportedDexesResponse {
5856
6315
  constructor(data) {
5857
6316
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
@@ -5894,12 +6353,34 @@ class ExchangeTransaction {
5894
6353
  this.sender_address = data.sender_address;
5895
6354
  this.total_quote = data.total_quote;
5896
6355
  this.pretty_total_quote = data.pretty_total_quote;
6356
+ this.value = data.value && data.value !== null ? BigInt(data.value) : null;
6357
+ this.value_quote = data.value_quote;
6358
+ this.pretty_value_quote = data.pretty_value_quote;
6359
+ this.gas_offered = data.gas_offered;
6360
+ this.gas_spent = data.gas_spent;
6361
+ this.gas_price = data.gas_price;
6362
+ this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
6363
+ this.gas_quote = data.gas_quote;
6364
+ this.pretty_gas_quote = data.pretty_gas_quote;
6365
+ this.gas_quote_rate = data.gas_quote_rate;
6366
+ this.quote_currency = data.quote_currency;
5897
6367
  this.token_0_quote_rate = data.token_0_quote_rate;
5898
6368
  this.token_1_quote_rate = data.token_1_quote_rate;
6369
+ this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
5899
6370
  this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
5900
6371
  this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
5901
6372
  }
5902
6373
  }
6374
+ class ContractMetadata {
6375
+ constructor(data) {
6376
+ this.contract_decimals = data.contract_decimals;
6377
+ this.contract_name = data.contract_name;
6378
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
6379
+ this.contract_address = data.contract_address;
6380
+ this.supports_erc = data.supports_erc;
6381
+ this.logo_url = data.logo_url;
6382
+ }
6383
+ }
5903
6384
  class PoolToken {
5904
6385
  constructor(data) {
5905
6386
  this.contract_decimals = data.contract_decimals;
@@ -5928,6 +6409,15 @@ class TransactionsForExchangeResponse {
5928
6409
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
5929
6410
  }
5930
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
+ }
5931
6421
  class EcosystemChartDataResponse {
5932
6422
  constructor(data) {
5933
6423
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
@@ -5943,13 +6433,15 @@ class UniswapLikeEcosystemCharts {
5943
6433
  this.chain_id = data.chain_id;
5944
6434
  this.quote_currency = data.quote_currency;
5945
6435
  this.gas_token_price_quote = data.gas_token_price_quote;
5946
- this.total_swaps24h = data.total_swaps24h;
5947
- this.total_active_pairs7d = data.total_active_pairs7d;
5948
- this.total_fees24h = data.total_fees24h;
5949
- this.volume_chart7d = data.volume_chart7d && data.volume_chart7d !== null ? data.volume_chart7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
5950
- this.volume_chart30d = data.volume_chart30d && data.volume_chart30d !== null ? data.volume_chart30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
5951
- this.liquidity_chart7d = data.liquidity_chart7d && data.liquidity_chart7d !== null ? data.liquidity_chart7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
5952
- this.liquidity_chart30d = data.liquidity_chart30d && data.liquidity_chart30d !== null ? data.liquidity_chart30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
6436
+ this.total_swaps_24h = data.total_swaps_24h;
6437
+ this.total_active_pairs_7d = data.total_active_pairs_7d;
6438
+ this.total_fees_24h = data.total_fees_24h;
6439
+ this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
6440
+ this.pretty_total_fees_24h = data.pretty_total_fees_24h;
6441
+ this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
6442
+ this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
6443
+ this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
6444
+ this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
5953
6445
  }
5954
6446
  }
5955
6447
  class VolumeEcosystemChart {
@@ -5959,6 +6451,7 @@ class VolumeEcosystemChart {
5959
6451
  this.dt = data.dt && data.dt !== null ? dateFns.parseISO(data.dt.toString()) : null;
5960
6452
  this.quote_currency = data.quote_currency;
5961
6453
  this.volume_quote = data.volume_quote;
6454
+ this.pretty_volume_quote = data.pretty_volume_quote;
5962
6455
  this.swap_count_24 = data.swap_count_24;
5963
6456
  }
5964
6457
  }
@@ -5969,6 +6462,7 @@ class LiquidityEcosystemChart {
5969
6462
  this.dt = data.dt && data.dt !== null ? dateFns.parseISO(data.dt.toString()) : null;
5970
6463
  this.quote_currency = data.quote_currency;
5971
6464
  this.liquidity_quote = data.liquidity_quote;
6465
+ this.pretty_liquidity_quote = data.pretty_liquidity_quote;
5972
6466
  }
5973
6467
  }
5974
6468
  class HealthDataResponse {
@@ -5993,11 +6487,13 @@ class HealthData {
5993
6487
  *
5994
6488
  */
5995
6489
  class XykService {
5996
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
6490
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
5997
6491
  this.apiKey = apiKey;
5998
6492
  this.debug = debug;
5999
6493
  this.threadCount = threadCount;
6000
6494
  this.is_key_valid = is_key_valid;
6495
+ this.enableRetry = enableRetry;
6496
+ this.source = source;
6001
6497
  this.LIMIT = pLimit$1(this.threadCount);
6002
6498
  }
6003
6499
  /**
@@ -6006,9 +6502,12 @@ class XykService {
6006
6502
  *
6007
6503
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6008
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.
6009
6508
  *
6010
6509
  */
6011
- async getPools(chainName, dexName) {
6510
+ async getPools(chainName, dexName, queryParamOpts) {
6012
6511
  let success = false;
6013
6512
  let data;
6014
6513
  let response;
@@ -6016,6 +6515,13 @@ class XykService {
6016
6515
  while (!success) {
6017
6516
  try {
6018
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
+ }
6524
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
6019
6525
  if (!this.is_key_valid) {
6020
6526
  return {
6021
6527
  data: null,
@@ -6031,13 +6537,13 @@ class XykService {
6031
6537
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
6032
6538
  headers: {
6033
6539
  "Authorization": `Bearer ${this.apiKey}`,
6034
- "X-Requested-With": userAgent
6540
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6035
6541
  }
6036
6542
  }));
6037
- debugOutput(response.url, response.status ?? 429, startTime);
6038
- if (response.status === null || response.status === 429) {
6543
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6544
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6039
6545
  try {
6040
- data = await this.LIMIT(() => backoff.backOff(response.url));
6546
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6041
6547
  }
6042
6548
  catch (error) {
6043
6549
  success = true;
@@ -6067,8 +6573,8 @@ class XykService {
6067
6573
  return {
6068
6574
  data: null,
6069
6575
  error: true,
6070
- error_code: data ? data.error_code : response.status,
6071
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6576
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6577
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6072
6578
  };
6073
6579
  }
6074
6580
  }
@@ -6089,6 +6595,7 @@ class XykService {
6089
6595
  while (!success) {
6090
6596
  try {
6091
6597
  const urlParams = new URLSearchParams();
6598
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
6092
6599
  if (!this.is_key_valid) {
6093
6600
  return {
6094
6601
  data: null,
@@ -6104,13 +6611,13 @@ class XykService {
6104
6611
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
6105
6612
  headers: {
6106
6613
  "Authorization": `Bearer ${this.apiKey}`,
6107
- "X-Requested-With": userAgent
6614
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6108
6615
  }
6109
6616
  }));
6110
- debugOutput(response.url, response.status ?? 429, startTime);
6111
- if (response.status === null || response.status === 429) {
6617
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6618
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6112
6619
  try {
6113
- data = await this.LIMIT(() => backoff.backOff(response.url));
6620
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6114
6621
  }
6115
6622
  catch (error) {
6116
6623
  success = true;
@@ -6140,8 +6647,8 @@ class XykService {
6140
6647
  return {
6141
6648
  data: null,
6142
6649
  error: true,
6143
- error_code: data ? data.error_code : response.status,
6144
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6650
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6651
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6145
6652
  };
6146
6653
  }
6147
6654
  }
@@ -6163,6 +6670,7 @@ class XykService {
6163
6670
  while (!success) {
6164
6671
  try {
6165
6672
  const urlParams = new URLSearchParams();
6673
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
6166
6674
  if (!this.is_key_valid) {
6167
6675
  return {
6168
6676
  data: null,
@@ -6178,13 +6686,13 @@ class XykService {
6178
6686
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
6179
6687
  headers: {
6180
6688
  "Authorization": `Bearer ${this.apiKey}`,
6181
- "X-Requested-With": userAgent
6689
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6182
6690
  }
6183
6691
  }));
6184
- debugOutput(response.url, response.status ?? 429, startTime);
6185
- if (response.status === null || response.status === 429) {
6692
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6693
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6186
6694
  try {
6187
- data = await this.LIMIT(() => backoff.backOff(response.url));
6695
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6188
6696
  }
6189
6697
  catch (error) {
6190
6698
  success = true;
@@ -6214,8 +6722,8 @@ class XykService {
6214
6722
  return {
6215
6723
  data: null,
6216
6724
  error: true,
6217
- error_code: data ? data.error_code : response.status,
6218
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6725
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6726
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6219
6727
  };
6220
6728
  }
6221
6729
  }
@@ -6229,6 +6737,8 @@ class XykService {
6229
6737
  * @param {number} page - The requested 0-indexed page number.
6230
6738
  * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
6231
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.
6232
6742
  *
6233
6743
  */
6234
6744
  async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
@@ -6253,6 +6763,10 @@ class XykService {
6253
6763
  if (queryParamOpts?.dexName !== undefined) {
6254
6764
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
6255
6765
  }
6766
+ if (queryParamOpts?.pageSize !== undefined) {
6767
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
6768
+ }
6769
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
6256
6770
  let startTime;
6257
6771
  if (this.debug) {
6258
6772
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6260,13 +6774,13 @@ class XykService {
6260
6774
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
6261
6775
  headers: {
6262
6776
  "Authorization": `Bearer ${this.apiKey}`,
6263
- "X-Requested-With": userAgent
6777
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6264
6778
  }
6265
6779
  }));
6266
- debugOutput(response.url, response.status ?? 429, startTime);
6267
- if (response.status === null || response.status === 429) {
6780
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6781
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6268
6782
  try {
6269
- data = await this.LIMIT(() => backoff.backOff(response.url));
6783
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6270
6784
  }
6271
6785
  catch (error) {
6272
6786
  success = true;
@@ -6296,8 +6810,8 @@ class XykService {
6296
6810
  return {
6297
6811
  data: null,
6298
6812
  error: true,
6299
- error_code: data ? data.error_code : response.status,
6300
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6813
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6814
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6301
6815
  };
6302
6816
  }
6303
6817
  }
@@ -6327,6 +6841,7 @@ class XykService {
6327
6841
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6328
6842
  };
6329
6843
  }
6844
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
6330
6845
  let startTime;
6331
6846
  if (this.debug) {
6332
6847
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6334,13 +6849,13 @@ class XykService {
6334
6849
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
6335
6850
  headers: {
6336
6851
  "Authorization": `Bearer ${this.apiKey}`,
6337
- "X-Requested-With": userAgent
6852
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6338
6853
  }
6339
6854
  }));
6340
- debugOutput(response.url, response.status ?? 429, startTime);
6341
- if (response.status === null || response.status === 429) {
6855
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6856
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6342
6857
  try {
6343
- data = await this.LIMIT(() => backoff.backOff(response.url));
6858
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6344
6859
  }
6345
6860
  catch (error) {
6346
6861
  success = true;
@@ -6370,8 +6885,8 @@ class XykService {
6370
6885
  return {
6371
6886
  data: null,
6372
6887
  error: true,
6373
- error_code: data ? data.error_code : response.status,
6374
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6888
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6889
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6375
6890
  };
6376
6891
  }
6377
6892
  }
@@ -6386,6 +6901,8 @@ class XykService {
6386
6901
  * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
6387
6902
  * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
6388
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.
6389
6906
  *
6390
6907
  */
6391
6908
  async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
@@ -6413,6 +6930,10 @@ class XykService {
6413
6930
  if (queryParamOpts?.dexName !== undefined) {
6414
6931
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
6415
6932
  }
6933
+ if (queryParamOpts?.pageSize !== undefined) {
6934
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
6935
+ }
6936
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
6416
6937
  let startTime;
6417
6938
  if (this.debug) {
6418
6939
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6420,13 +6941,13 @@ class XykService {
6420
6941
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
6421
6942
  headers: {
6422
6943
  "Authorization": `Bearer ${this.apiKey}`,
6423
- "X-Requested-With": userAgent
6944
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6424
6945
  }
6425
6946
  }));
6426
- debugOutput(response.url, response.status ?? 429, startTime);
6427
- if (response.status === null || response.status === 429) {
6947
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
6948
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6428
6949
  try {
6429
- data = await this.LIMIT(() => backoff.backOff(response.url));
6950
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6430
6951
  }
6431
6952
  catch (error) {
6432
6953
  success = true;
@@ -6456,8 +6977,8 @@ class XykService {
6456
6977
  return {
6457
6978
  data: null,
6458
6979
  error: true,
6459
- error_code: data ? data.error_code : response.status,
6460
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6980
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
6981
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6461
6982
  };
6462
6983
  }
6463
6984
  }
@@ -6468,9 +6989,12 @@ class XykService {
6468
6989
  *
6469
6990
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6470
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.
6471
6995
  *
6472
6996
  */
6473
- async getNetworkExchangeTokens(chainName, dexName) {
6997
+ async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
6474
6998
  let success = false;
6475
6999
  let data;
6476
7000
  let response;
@@ -6478,6 +7002,12 @@ class XykService {
6478
7002
  while (!success) {
6479
7003
  try {
6480
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
+ }
6481
7011
  if (!this.is_key_valid) {
6482
7012
  return {
6483
7013
  data: null,
@@ -6486,6 +7016,7 @@ class XykService {
6486
7016
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6487
7017
  };
6488
7018
  }
7019
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
6489
7020
  let startTime;
6490
7021
  if (this.debug) {
6491
7022
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6493,13 +7024,13 @@ class XykService {
6493
7024
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
6494
7025
  headers: {
6495
7026
  "Authorization": `Bearer ${this.apiKey}`,
6496
- "X-Requested-With": userAgent
7027
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6497
7028
  }
6498
7029
  }));
6499
- debugOutput(response.url, response.status ?? 429, startTime);
6500
- if (response.status === null || response.status === 429) {
7030
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7031
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6501
7032
  try {
6502
- data = await this.LIMIT(() => backoff.backOff(response.url));
7033
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6503
7034
  }
6504
7035
  catch (error) {
6505
7036
  success = true;
@@ -6529,10 +7060,90 @@ class XykService {
6529
7060
  return {
6530
7061
  data: null,
6531
7062
  error: true,
7063
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7064
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
7065
+ };
7066
+ }
7067
+ }
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,
6532
7134
  error_code: data ? data.error_code : response.status,
6533
7135
  error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6534
7136
  };
6535
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
+ }
6536
7147
  }
6537
7148
  }
6538
7149
  /**
@@ -6557,6 +7168,7 @@ class XykService {
6557
7168
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6558
7169
  };
6559
7170
  }
7171
+ const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
6560
7172
  let startTime;
6561
7173
  if (this.debug) {
6562
7174
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6564,13 +7176,13 @@ class XykService {
6564
7176
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
6565
7177
  headers: {
6566
7178
  "Authorization": `Bearer ${this.apiKey}`,
6567
- "X-Requested-With": userAgent
7179
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6568
7180
  }
6569
7181
  }));
6570
- debugOutput(response.url, response.status ?? 429, startTime);
6571
- if (response.status === null || response.status === 429) {
7182
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7183
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6572
7184
  try {
6573
- data = await this.LIMIT(() => backoff.backOff(response.url));
7185
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6574
7186
  }
6575
7187
  catch (error) {
6576
7188
  success = true;
@@ -6600,8 +7212,8 @@ class XykService {
6600
7212
  return {
6601
7213
  data: null,
6602
7214
  error: true,
6603
- error_code: data ? data.error_code : response.status,
6604
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7215
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7216
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6605
7217
  };
6606
7218
  }
6607
7219
  }
@@ -6613,9 +7225,12 @@ class XykService {
6613
7225
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6614
7226
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6615
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.
6616
7231
  *
6617
7232
  */
6618
- async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
7233
+ async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
6619
7234
  let success = false;
6620
7235
  let data;
6621
7236
  let response;
@@ -6623,6 +7238,12 @@ class XykService {
6623
7238
  while (!success) {
6624
7239
  try {
6625
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
+ }
6626
7247
  if (!this.is_key_valid) {
6627
7248
  return {
6628
7249
  data: null,
@@ -6631,6 +7252,7 @@ class XykService {
6631
7252
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6632
7253
  };
6633
7254
  }
7255
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
6634
7256
  let startTime;
6635
7257
  if (this.debug) {
6636
7258
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6638,13 +7260,13 @@ class XykService {
6638
7260
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
6639
7261
  headers: {
6640
7262
  "Authorization": `Bearer ${this.apiKey}`,
6641
- "X-Requested-With": userAgent
7263
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6642
7264
  }
6643
7265
  }));
6644
- debugOutput(response.url, response.status ?? 429, startTime);
6645
- if (response.status === null || response.status === 429) {
7266
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7267
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6646
7268
  try {
6647
- data = await this.LIMIT(() => backoff.backOff(response.url));
7269
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6648
7270
  }
6649
7271
  catch (error) {
6650
7272
  success = true;
@@ -6674,8 +7296,8 @@ class XykService {
6674
7296
  return {
6675
7297
  data: null,
6676
7298
  error: true,
6677
- error_code: data ? data.error_code : response.status,
6678
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7299
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7300
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6679
7301
  };
6680
7302
  }
6681
7303
  }
@@ -6705,6 +7327,7 @@ class XykService {
6705
7327
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6706
7328
  };
6707
7329
  }
7330
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
6708
7331
  let startTime;
6709
7332
  if (this.debug) {
6710
7333
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6712,13 +7335,13 @@ class XykService {
6712
7335
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
6713
7336
  headers: {
6714
7337
  "Authorization": `Bearer ${this.apiKey}`,
6715
- "X-Requested-With": userAgent
7338
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6716
7339
  }
6717
7340
  }));
6718
- debugOutput(response.url, response.status ?? 429, startTime);
6719
- if (response.status === null || response.status === 429) {
7341
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7342
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6720
7343
  try {
6721
- data = await this.LIMIT(() => backoff.backOff(response.url));
7344
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6722
7345
  }
6723
7346
  catch (error) {
6724
7347
  success = true;
@@ -6748,8 +7371,8 @@ class XykService {
6748
7371
  return {
6749
7372
  data: null,
6750
7373
  error: true,
6751
- error_code: data ? data.error_code : response.status,
6752
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7374
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7375
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6753
7376
  };
6754
7377
  }
6755
7378
  }
@@ -6761,9 +7384,12 @@ class XykService {
6761
7384
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6762
7385
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6763
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.
6764
7390
  *
6765
7391
  */
6766
- async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
7392
+ async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
6767
7393
  let success = false;
6768
7394
  let data;
6769
7395
  let response;
@@ -6779,6 +7405,13 @@ class XykService {
6779
7405
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6780
7406
  };
6781
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
+ }
7414
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
6782
7415
  let startTime;
6783
7416
  if (this.debug) {
6784
7417
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6786,13 +7419,13 @@ class XykService {
6786
7419
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
6787
7420
  headers: {
6788
7421
  "Authorization": `Bearer ${this.apiKey}`,
6789
- "X-Requested-With": userAgent
7422
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6790
7423
  }
6791
7424
  }));
6792
- debugOutput(response.url, response.status ?? 429, startTime);
6793
- if (response.status === null || response.status === 429) {
7425
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7426
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6794
7427
  try {
6795
- data = await this.LIMIT(() => backoff.backOff(response.url));
7428
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6796
7429
  }
6797
7430
  catch (error) {
6798
7431
  success = true;
@@ -6822,8 +7455,8 @@ class XykService {
6822
7455
  return {
6823
7456
  data: null,
6824
7457
  error: true,
6825
- error_code: data ? data.error_code : response.status,
6826
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7458
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7459
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6827
7460
  };
6828
7461
  }
6829
7462
  }
@@ -6835,9 +7468,12 @@ class XykService {
6835
7468
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
6836
7469
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
6837
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.
6838
7474
  *
6839
7475
  */
6840
- async getTransactionsForExchange(chainName, dexName, poolAddress) {
7476
+ async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
6841
7477
  let success = false;
6842
7478
  let data;
6843
7479
  let response;
@@ -6853,6 +7489,13 @@ class XykService {
6853
7489
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6854
7490
  };
6855
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
+ }
7498
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
6856
7499
  let startTime;
6857
7500
  if (this.debug) {
6858
7501
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6860,13 +7503,13 @@ class XykService {
6860
7503
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
6861
7504
  headers: {
6862
7505
  "Authorization": `Bearer ${this.apiKey}`,
6863
- "X-Requested-With": userAgent
7506
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6864
7507
  }
6865
7508
  }));
6866
- debugOutput(response.url, response.status ?? 429, startTime);
6867
- if (response.status === null || response.status === 429) {
7509
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7510
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6868
7511
  try {
6869
- data = await this.LIMIT(() => backoff.backOff(response.url));
7512
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6870
7513
  }
6871
7514
  catch (error) {
6872
7515
  success = true;
@@ -6896,10 +7539,97 @@ class XykService {
6896
7539
  return {
6897
7540
  data: null,
6898
7541
  error: true,
7542
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7543
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
7544
+ };
7545
+ }
7546
+ }
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,
6899
7620
  error_code: data ? data.error_code : response.status,
6900
7621
  error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
6901
7622
  };
6902
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
+ }
6903
7633
  }
6904
7634
  }
6905
7635
  /**
@@ -6926,6 +7656,7 @@ class XykService {
6926
7656
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6927
7657
  };
6928
7658
  }
7659
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
6929
7660
  let startTime;
6930
7661
  if (this.debug) {
6931
7662
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6933,13 +7664,13 @@ class XykService {
6933
7664
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
6934
7665
  headers: {
6935
7666
  "Authorization": `Bearer ${this.apiKey}`,
6936
- "X-Requested-With": userAgent
7667
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
6937
7668
  }
6938
7669
  }));
6939
- debugOutput(response.url, response.status ?? 429, startTime);
6940
- if (response.status === null || response.status === 429) {
7670
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7671
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
6941
7672
  try {
6942
- data = await this.LIMIT(() => backoff.backOff(response.url));
7673
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
6943
7674
  }
6944
7675
  catch (error) {
6945
7676
  success = true;
@@ -6969,8 +7700,8 @@ class XykService {
6969
7700
  return {
6970
7701
  data: null,
6971
7702
  error: true,
6972
- error_code: data ? data.error_code : response.status,
6973
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7703
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7704
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
6974
7705
  };
6975
7706
  }
6976
7707
  }
@@ -6999,6 +7730,7 @@ class XykService {
6999
7730
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
7000
7731
  };
7001
7732
  }
7733
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
7002
7734
  let startTime;
7003
7735
  if (this.debug) {
7004
7736
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -7006,13 +7738,13 @@ class XykService {
7006
7738
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
7007
7739
  headers: {
7008
7740
  "Authorization": `Bearer ${this.apiKey}`,
7009
- "X-Requested-With": userAgent
7741
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
7010
7742
  }
7011
7743
  }));
7012
- debugOutput(response.url, response.status ?? 429, startTime);
7013
- if (response.status === null || response.status === 429) {
7744
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
7745
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
7014
7746
  try {
7015
- data = await this.LIMIT(() => backoff.backOff(response.url));
7747
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
7016
7748
  }
7017
7749
  catch (error) {
7018
7750
  success = true;
@@ -7042,30 +7774,30 @@ class XykService {
7042
7774
  return {
7043
7775
  data: null,
7044
7776
  error: true,
7045
- error_code: data ? data.error_code : response.status,
7046
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
7777
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
7778
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
7047
7779
  };
7048
7780
  }
7049
7781
  }
7050
7782
  }
7051
7783
  }
7052
7784
 
7053
- const userAgent = "com.covalenthq.sdk.typescript/0.7.5";
7785
+ const userAgent = "com.covalenthq.sdk.typescript/0.8.0";
7054
7786
  /**
7055
7787
  * CovalentClient Class
7056
7788
  */
7057
7789
  class CovalentClient {
7058
- constructor(apiKey, settings) {
7059
- const { debug = false, threadCount = 3 } = settings || {};
7790
+ constructor(apiKey, settings, source) {
7791
+ const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
7060
7792
  const validator = new ApiKeyValidator(apiKey);
7061
7793
  this._is_key_valid = validator.isValidApiKey();
7062
- this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
7063
- this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
7064
- this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
7065
- this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
7066
- this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
7067
- this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
7068
- this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
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);
7069
7801
  }
7070
7802
  }
7071
7803
  /**
@@ -7075,17 +7807,17 @@ class CovalentClient {
7075
7807
  * CovalentClient Class
7076
7808
  */
7077
7809
  class Client {
7078
- constructor(apiKey, settings) {
7079
- const { debug = false, threadCount = 3 } = settings || {};
7810
+ constructor(apiKey, settings, source) {
7811
+ const { debug = false, threadCount = 3, enableRetry = true } = settings || {};
7080
7812
  const validator = new ApiKeyValidator(apiKey);
7081
7813
  this._is_key_valid = validator.isValidApiKey();
7082
- this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
7083
- this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
7084
- this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
7085
- this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
7086
- this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
7087
- this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
7088
- this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
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);
7089
7821
  }
7090
7822
  }
7091
7823