@covalenthq/client-sdk 0.7.6 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/index.js +2762 -199
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +14 -13
  5. package/dist/cjs/services/BaseService.d.ts +12 -11
  6. package/dist/cjs/services/CovalentClient.d.ts +5 -3
  7. package/dist/cjs/services/NftService.d.ts +18 -17
  8. package/dist/cjs/services/PricingService.d.ts +4 -3
  9. package/dist/cjs/services/SecurityService.d.ts +5 -4
  10. package/dist/cjs/services/TransactionService.d.ts +79 -12
  11. package/dist/cjs/services/XykService.d.ts +226 -15
  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 +114 -0
  16. package/dist/es/index.js +2762 -199
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +14 -13
  19. package/dist/es/services/BaseService.d.ts +12 -11
  20. package/dist/es/services/CovalentClient.d.ts +5 -3
  21. package/dist/es/services/NftService.d.ts +18 -17
  22. package/dist/es/services/PricingService.d.ts +4 -3
  23. package/dist/es/services/SecurityService.d.ts +5 -4
  24. package/dist/es/services/TransactionService.d.ts +79 -12
  25. package/dist/es/services/XykService.d.ts +226 -15
  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 +114 -0
  30. package/dist/esm/index.js +2762 -199
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +14 -13
  33. package/dist/esm/services/BaseService.d.ts +12 -11
  34. package/dist/esm/services/CovalentClient.d.ts +5 -3
  35. package/dist/esm/services/NftService.d.ts +18 -17
  36. package/dist/esm/services/PricingService.d.ts +4 -3
  37. package/dist/esm/services/SecurityService.d.ts +5 -4
  38. package/dist/esm/services/TransactionService.d.ts +79 -12
  39. package/dist/esm/services/XykService.d.ts +226 -15
  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 +114 -0
  44. package/dist/services/BalanceService.d.ts +14 -13
  45. package/dist/services/BalanceService.js +16 -15
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +12 -11
  48. package/dist/services/BaseService.js +25 -24
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +5 -3
  51. package/dist/services/CovalentClient.js +17 -17
  52. package/dist/services/CovalentClient.js.map +1 -1
  53. package/dist/services/NftService.d.ts +18 -17
  54. package/dist/services/NftService.js +30 -29
  55. package/dist/services/NftService.js.map +1 -1
  56. package/dist/services/PricingService.d.ts +4 -3
  57. package/dist/services/PricingService.js +4 -3
  58. package/dist/services/PricingService.js.map +1 -1
  59. package/dist/services/SecurityService.d.ts +5 -4
  60. package/dist/services/SecurityService.js +6 -5
  61. package/dist/services/SecurityService.js.map +1 -1
  62. package/dist/services/TransactionService.d.ts +79 -12
  63. package/dist/services/TransactionService.js +369 -41
  64. package/dist/services/TransactionService.js.map +1 -1
  65. package/dist/services/XykService.d.ts +226 -15
  66. package/dist/services/XykService.js +335 -34
  67. package/dist/services/XykService.js.map +1 -1
  68. package/dist/util/ApiHelpers.d.ts +2 -1
  69. package/dist/util/ApiHelpers.js +3 -3
  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 +114 -0
  76. package/package.json +2 -2
@@ -285,6 +285,75 @@ class TokenV2Volume {
285
285
  this.total_volume_24h_quote = data.total_volume_24h_quote;
286
286
  }
287
287
  }
288
+ class NetworkExchangeTokenViewResponse {
289
+ constructor(data) {
290
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
291
+ this.chain_id = data.chain_id;
292
+ this.chain_name = data.chain_name;
293
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2VolumeWithChartData(itemData)) : null;
294
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
295
+ }
296
+ }
297
+ class TokenV2VolumeWithChartData {
298
+ constructor(data) {
299
+ this.chain_name = data.chain_name;
300
+ this.chain_id = data.chain_id;
301
+ this.dex_name = data.dex_name;
302
+ this.contract_address = data.contract_address;
303
+ this.contract_name = data.contract_name;
304
+ this.total_liquidity = data.total_liquidity;
305
+ this.total_volume_24h = data.total_volume_24h;
306
+ this.logo_url = data.logo_url;
307
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
308
+ this.contract_decimals = data.contract_decimals;
309
+ this.swap_count_24h = data.swap_count_24h;
310
+ this.quote_rate = data.quote_rate;
311
+ this.quote_rate_24h = data.quote_rate_24h;
312
+ this.pretty_quote_rate = data.pretty_quote_rate;
313
+ this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
314
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
315
+ this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
316
+ this.total_liquidity_quote = data.total_liquidity_quote;
317
+ this.total_volume_24h_quote = data.total_volume_24h_quote;
318
+ this.transactions_24h = data.transactions_24h;
319
+ this.volume_timeseries_7d = data.volume_timeseries_7d && data.volume_timeseries_7d !== null ? data.volume_timeseries_7d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
320
+ this.volume_timeseries_30d = data.volume_timeseries_30d && data.volume_timeseries_30d !== null ? data.volume_timeseries_30d.map((itemData) => new VolumeTokenTimeseries(itemData)) : null;
321
+ this.liquidity_timeseries_7d = data.liquidity_timeseries_7d && data.liquidity_timeseries_7d !== null ? data.liquidity_timeseries_7d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
322
+ this.liquidity_timeseries_30d = data.liquidity_timeseries_30d && data.liquidity_timeseries_30d !== null ? data.liquidity_timeseries_30d.map((itemData) => new LiquidityTokenTimeseries(itemData)) : null;
323
+ this.price_timeseries_7d = data.price_timeseries_7d && data.price_timeseries_7d !== null ? data.price_timeseries_7d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
324
+ this.price_timeseries_30d = data.price_timeseries_30d && data.price_timeseries_30d !== null ? data.price_timeseries_30d.map((itemData) => new PriceTokenTimeseries(itemData)) : null;
325
+ }
326
+ }
327
+ class VolumeTokenTimeseries {
328
+ constructor(data) {
329
+ this.dex_name = data.dex_name;
330
+ this.chain_id = data.chain_id;
331
+ this.dt = data.dt;
332
+ this.total_volume = data.total_volume;
333
+ this.volume_quote = data.volume_quote;
334
+ this.pretty_volume_quote = data.pretty_volume_quote;
335
+ }
336
+ }
337
+ class LiquidityTokenTimeseries {
338
+ constructor(data) {
339
+ this.dex_name = data.dex_name;
340
+ this.chain_id = data.chain_id;
341
+ this.dt = data.dt;
342
+ this.total_liquidity = data.total_liquidity;
343
+ this.liquidity_quote = data.liquidity_quote;
344
+ this.pretty_liquidity_quote = data.pretty_liquidity_quote;
345
+ }
346
+ }
347
+ class PriceTokenTimeseries {
348
+ constructor(data) {
349
+ this.dex_name = data.dex_name;
350
+ this.chain_id = data.chain_id;
351
+ this.dt = data.dt;
352
+ this.quote_currency = data.quote_currency;
353
+ this.quote_rate = data.quote_rate;
354
+ this.pretty_quote_rate = data.pretty_quote_rate;
355
+ }
356
+ }
288
357
  class SupportedDexesResponse {
289
358
  constructor(data) {
290
359
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -383,6 +452,15 @@ class TransactionsForExchangeResponse {
383
452
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
384
453
  }
385
454
  }
455
+ class NetworkTransactionsResponse {
456
+ constructor(data) {
457
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
458
+ this.chain_id = data.chain_id;
459
+ this.chain_name = data.chain_name;
460
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
461
+ this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
462
+ }
463
+ }
386
464
  class EcosystemChartDataResponse {
387
465
  constructor(data) {
388
466
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -452,12 +530,13 @@ class HealthData {
452
530
  *
453
531
  */
454
532
  export class XykService {
455
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
533
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
456
534
  this.apiKey = apiKey;
457
535
  this.debug = debug;
458
536
  this.threadCount = threadCount;
459
537
  this.is_key_valid = is_key_valid;
460
538
  this.enableRetry = enableRetry;
539
+ this.source = source;
461
540
  this.LIMIT = pLimit(this.threadCount);
462
541
  }
463
542
  /**
@@ -466,9 +545,12 @@ export class XykService {
466
545
  *
467
546
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
468
547
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
548
+ * @param {GetPoolsQueryParamOpts} queryParamOpts
549
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
550
+ * - `pageNumber`: 0-indexed page number to begin pagination.
469
551
  *
470
552
  */
471
- async getPools(chainName, dexName) {
553
+ async getPools(chainName, dexName, queryParamOpts) {
472
554
  let success = false;
473
555
  let data;
474
556
  let response;
@@ -476,6 +558,12 @@ export class XykService {
476
558
  while (!success) {
477
559
  try {
478
560
  const urlParams = new URLSearchParams();
561
+ if (queryParamOpts?.pageSize !== undefined) {
562
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
563
+ }
564
+ if (queryParamOpts?.pageNumber !== undefined) {
565
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
566
+ }
479
567
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
480
568
  if (!this.is_key_valid) {
481
569
  return {
@@ -492,13 +580,13 @@ export class XykService {
492
580
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
493
581
  headers: {
494
582
  "Authorization": `Bearer ${this.apiKey}`,
495
- "X-Requested-With": userAgent
583
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
496
584
  }
497
585
  }));
498
586
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
499
587
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
500
588
  try {
501
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
589
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
502
590
  }
503
591
  catch (error) {
504
592
  success = true;
@@ -566,13 +654,13 @@ export class XykService {
566
654
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
567
655
  headers: {
568
656
  "Authorization": `Bearer ${this.apiKey}`,
569
- "X-Requested-With": userAgent
657
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
570
658
  }
571
659
  }));
572
660
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
573
661
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
574
662
  try {
575
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
663
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
576
664
  }
577
665
  catch (error) {
578
666
  success = true;
@@ -641,13 +729,13 @@ export class XykService {
641
729
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
642
730
  headers: {
643
731
  "Authorization": `Bearer ${this.apiKey}`,
644
- "X-Requested-With": userAgent
732
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
645
733
  }
646
734
  }));
647
735
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
648
736
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
649
737
  try {
650
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
738
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
651
739
  }
652
740
  catch (error) {
653
741
  success = true;
@@ -692,6 +780,8 @@ export class XykService {
692
780
  * @param {number} page - The requested 0-indexed page number.
693
781
  * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
694
782
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
783
+ * - `dexName`: The DEX name eg: `uniswap_v2`.
784
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
695
785
  *
696
786
  */
697
787
  async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
@@ -716,6 +806,9 @@ export class XykService {
716
806
  if (queryParamOpts?.dexName !== undefined) {
717
807
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
718
808
  }
809
+ if (queryParamOpts?.pageSize !== undefined) {
810
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
811
+ }
719
812
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
720
813
  let startTime;
721
814
  if (this.debug) {
@@ -724,13 +817,13 @@ export class XykService {
724
817
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
725
818
  headers: {
726
819
  "Authorization": `Bearer ${this.apiKey}`,
727
- "X-Requested-With": userAgent
820
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
728
821
  }
729
822
  }));
730
823
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
731
824
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
732
825
  try {
733
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
826
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
734
827
  }
735
828
  catch (error) {
736
829
  success = true;
@@ -799,13 +892,13 @@ export class XykService {
799
892
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
800
893
  headers: {
801
894
  "Authorization": `Bearer ${this.apiKey}`,
802
- "X-Requested-With": userAgent
895
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
803
896
  }
804
897
  }));
805
898
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
806
899
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
807
900
  try {
808
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
901
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
809
902
  }
810
903
  catch (error) {
811
904
  success = true;
@@ -851,6 +944,8 @@ export class XykService {
851
944
  * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
852
945
  * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
853
946
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
947
+ * - `dexName`: The DEX name eg: `uniswap_v2`.
948
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
854
949
  *
855
950
  */
856
951
  async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
@@ -878,6 +973,9 @@ export class XykService {
878
973
  if (queryParamOpts?.dexName !== undefined) {
879
974
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
880
975
  }
976
+ if (queryParamOpts?.pageSize !== undefined) {
977
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
978
+ }
881
979
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
882
980
  let startTime;
883
981
  if (this.debug) {
@@ -886,13 +984,13 @@ export class XykService {
886
984
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
887
985
  headers: {
888
986
  "Authorization": `Bearer ${this.apiKey}`,
889
- "X-Requested-With": userAgent
987
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
890
988
  }
891
989
  }));
892
990
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
893
991
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
894
992
  try {
895
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
993
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
896
994
  }
897
995
  catch (error) {
898
996
  success = true;
@@ -934,9 +1032,12 @@ export class XykService {
934
1032
  *
935
1033
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
936
1034
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1035
+ * @param {GetNetworkExchangeTokensQueryParamOpts} queryParamOpts
1036
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1037
+ * - `pageNumber`: 0-indexed page number to begin pagination.
937
1038
  *
938
1039
  */
939
- async getNetworkExchangeTokens(chainName, dexName) {
1040
+ async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
940
1041
  let success = false;
941
1042
  let data;
942
1043
  let response;
@@ -944,6 +1045,12 @@ export class XykService {
944
1045
  while (!success) {
945
1046
  try {
946
1047
  const urlParams = new URLSearchParams();
1048
+ if (queryParamOpts?.pageSize !== undefined) {
1049
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1050
+ }
1051
+ if (queryParamOpts?.pageNumber !== undefined) {
1052
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1053
+ }
947
1054
  if (!this.is_key_valid) {
948
1055
  return {
949
1056
  data: null,
@@ -960,13 +1067,13 @@ export class XykService {
960
1067
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
961
1068
  headers: {
962
1069
  "Authorization": `Bearer ${this.apiKey}`,
963
- "X-Requested-With": userAgent
1070
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
964
1071
  }
965
1072
  }));
966
1073
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
967
1074
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
968
1075
  try {
969
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1076
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
970
1077
  }
971
1078
  catch (error) {
972
1079
  success = true;
@@ -1002,6 +1109,86 @@ export class XykService {
1002
1109
  }
1003
1110
  }
1004
1111
  }
1112
+ /**
1113
+ *
1114
+ * Commonly used to get a detailed view for a single liquidity pool token. Includes time series data.
1115
+ *
1116
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1117
+ * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1118
+ * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1119
+ * @param {GetLpTokenViewQueryParamOpts} queryParamOpts
1120
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1121
+ *
1122
+ */
1123
+ async getLpTokenView(chainName, dexName, tokenAddress, queryParamOpts) {
1124
+ let success = false;
1125
+ let data;
1126
+ let response;
1127
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1128
+ while (!success) {
1129
+ try {
1130
+ const urlParams = new URLSearchParams();
1131
+ if (!this.is_key_valid) {
1132
+ return {
1133
+ data: null,
1134
+ error: true,
1135
+ error_code: 401,
1136
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1137
+ };
1138
+ }
1139
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1140
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1141
+ }
1142
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`;
1143
+ let startTime;
1144
+ if (this.debug) {
1145
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1146
+ }
1147
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/view/?${urlParams}`, {
1148
+ headers: {
1149
+ "Authorization": `Bearer ${this.apiKey}`,
1150
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1151
+ }
1152
+ }));
1153
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1154
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1155
+ try {
1156
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1157
+ }
1158
+ catch (error) {
1159
+ success = true;
1160
+ return {
1161
+ data: null,
1162
+ error: true,
1163
+ error_code: response.status ?? 429,
1164
+ error_message: error.message
1165
+ };
1166
+ }
1167
+ }
1168
+ else {
1169
+ data = await response.json();
1170
+ }
1171
+ const dataClass = new NetworkExchangeTokenViewResponse(data.data);
1172
+ checkAndModifyResponse(dataClass);
1173
+ success = true;
1174
+ return {
1175
+ data: dataClass,
1176
+ error: data.error,
1177
+ error_code: data ? data.error_code : response.status,
1178
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1179
+ };
1180
+ }
1181
+ catch (error) {
1182
+ success = true;
1183
+ return {
1184
+ data: null,
1185
+ error: true,
1186
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1187
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1188
+ };
1189
+ }
1190
+ }
1191
+ }
1005
1192
  /**
1006
1193
  *
1007
1194
  * Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
@@ -1032,13 +1219,13 @@ export class XykService {
1032
1219
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
1033
1220
  headers: {
1034
1221
  "Authorization": `Bearer ${this.apiKey}`,
1035
- "X-Requested-With": userAgent
1222
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1036
1223
  }
1037
1224
  }));
1038
1225
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1039
1226
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1040
1227
  try {
1041
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1228
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1042
1229
  }
1043
1230
  catch (error) {
1044
1231
  success = true;
@@ -1081,9 +1268,12 @@ export class XykService {
1081
1268
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1082
1269
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1083
1270
  * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1271
+ * @param {GetSingleNetworkExchangeTokenQueryParamOpts} queryParamOpts
1272
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1273
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1084
1274
  *
1085
1275
  */
1086
- async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
1276
+ async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
1087
1277
  let success = false;
1088
1278
  let data;
1089
1279
  let response;
@@ -1091,6 +1281,12 @@ export class XykService {
1091
1281
  while (!success) {
1092
1282
  try {
1093
1283
  const urlParams = new URLSearchParams();
1284
+ if (queryParamOpts?.pageSize !== undefined) {
1285
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1286
+ }
1287
+ if (queryParamOpts?.pageNumber !== undefined) {
1288
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1289
+ }
1094
1290
  if (!this.is_key_valid) {
1095
1291
  return {
1096
1292
  data: null,
@@ -1107,13 +1303,13 @@ export class XykService {
1107
1303
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
1108
1304
  headers: {
1109
1305
  "Authorization": `Bearer ${this.apiKey}`,
1110
- "X-Requested-With": userAgent
1306
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1111
1307
  }
1112
1308
  }));
1113
1309
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1114
1310
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1115
1311
  try {
1116
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1312
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1117
1313
  }
1118
1314
  catch (error) {
1119
1315
  success = true;
@@ -1182,13 +1378,13 @@ export class XykService {
1182
1378
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
1183
1379
  headers: {
1184
1380
  "Authorization": `Bearer ${this.apiKey}`,
1185
- "X-Requested-With": userAgent
1381
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1186
1382
  }
1187
1383
  }));
1188
1384
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1189
1385
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1190
1386
  try {
1191
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1387
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1192
1388
  }
1193
1389
  catch (error) {
1194
1390
  success = true;
@@ -1231,9 +1427,12 @@ export class XykService {
1231
1427
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1232
1428
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1233
1429
  * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1430
+ * @param {GetTransactionsForTokenAddressQueryParamOpts} queryParamOpts
1431
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1432
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1234
1433
  *
1235
1434
  */
1236
- async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
1435
+ async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
1237
1436
  let success = false;
1238
1437
  let data;
1239
1438
  let response;
@@ -1249,6 +1448,12 @@ export class XykService {
1249
1448
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1250
1449
  };
1251
1450
  }
1451
+ if (queryParamOpts?.pageSize !== undefined) {
1452
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1453
+ }
1454
+ if (queryParamOpts?.pageNumber !== undefined) {
1455
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1456
+ }
1252
1457
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
1253
1458
  let startTime;
1254
1459
  if (this.debug) {
@@ -1257,13 +1462,13 @@ export class XykService {
1257
1462
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
1258
1463
  headers: {
1259
1464
  "Authorization": `Bearer ${this.apiKey}`,
1260
- "X-Requested-With": userAgent
1465
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1261
1466
  }
1262
1467
  }));
1263
1468
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1264
1469
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1265
1470
  try {
1266
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1471
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1267
1472
  }
1268
1473
  catch (error) {
1269
1474
  success = true;
@@ -1306,9 +1511,12 @@ export class XykService {
1306
1511
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1307
1512
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1308
1513
  * @param {string} poolAddress - The pool contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1514
+ * @param {GetTransactionsForExchangeQueryParamOpts} queryParamOpts
1515
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1516
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1309
1517
  *
1310
1518
  */
1311
- async getTransactionsForExchange(chainName, dexName, poolAddress) {
1519
+ async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
1312
1520
  let success = false;
1313
1521
  let data;
1314
1522
  let response;
@@ -1324,6 +1532,12 @@ export class XykService {
1324
1532
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1325
1533
  };
1326
1534
  }
1535
+ if (queryParamOpts?.pageSize !== undefined) {
1536
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1537
+ }
1538
+ if (queryParamOpts?.pageNumber !== undefined) {
1539
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1540
+ }
1327
1541
  const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
1328
1542
  let startTime;
1329
1543
  if (this.debug) {
@@ -1332,13 +1546,13 @@ export class XykService {
1332
1546
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
1333
1547
  headers: {
1334
1548
  "Authorization": `Bearer ${this.apiKey}`,
1335
- "X-Requested-With": userAgent
1549
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1336
1550
  }
1337
1551
  }));
1338
1552
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1339
1553
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1340
1554
  try {
1341
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1555
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1342
1556
  }
1343
1557
  catch (error) {
1344
1558
  success = true;
@@ -1374,6 +1588,93 @@ export class XykService {
1374
1588
  }
1375
1589
  }
1376
1590
  }
1591
+ /**
1592
+ *
1593
+ * Commonly used to get all the the transactions for a given DEX. Useful for building DEX activity views.
1594
+ *
1595
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1596
+ * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1597
+ * @param {GetTransactionsForDexQueryParamOpts} queryParamOpts
1598
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1599
+ * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
1600
+ * - `pageNumber`: 0-indexed page number to begin pagination.
1601
+ *
1602
+ */
1603
+ async getTransactionsForDex(chainName, dexName, queryParamOpts) {
1604
+ let success = false;
1605
+ let data;
1606
+ let response;
1607
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1608
+ while (!success) {
1609
+ try {
1610
+ const urlParams = new URLSearchParams();
1611
+ if (!this.is_key_valid) {
1612
+ return {
1613
+ data: null,
1614
+ error: true,
1615
+ error_code: 401,
1616
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1617
+ };
1618
+ }
1619
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1620
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1621
+ }
1622
+ if (queryParamOpts?.pageSize !== undefined) {
1623
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1624
+ }
1625
+ if (queryParamOpts?.pageNumber !== undefined) {
1626
+ urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
1627
+ }
1628
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`;
1629
+ let startTime;
1630
+ if (this.debug) {
1631
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1632
+ }
1633
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/transactions/?${urlParams}`, {
1634
+ headers: {
1635
+ "Authorization": `Bearer ${this.apiKey}`,
1636
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1637
+ }
1638
+ }));
1639
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1640
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1641
+ try {
1642
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1643
+ }
1644
+ catch (error) {
1645
+ success = true;
1646
+ return {
1647
+ data: null,
1648
+ error: true,
1649
+ error_code: response.status ?? 429,
1650
+ error_message: error.message
1651
+ };
1652
+ }
1653
+ }
1654
+ else {
1655
+ data = await response.json();
1656
+ }
1657
+ const dataClass = new NetworkTransactionsResponse(data.data);
1658
+ checkAndModifyResponse(dataClass);
1659
+ success = true;
1660
+ return {
1661
+ data: dataClass,
1662
+ error: data.error,
1663
+ error_code: data ? data.error_code : response.status,
1664
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1665
+ };
1666
+ }
1667
+ catch (error) {
1668
+ success = true;
1669
+ return {
1670
+ data: null,
1671
+ error: true,
1672
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1673
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1674
+ };
1675
+ }
1676
+ }
1677
+ }
1377
1678
  /**
1378
1679
  *
1379
1680
  * Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
@@ -1406,13 +1707,13 @@ export class XykService {
1406
1707
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
1407
1708
  headers: {
1408
1709
  "Authorization": `Bearer ${this.apiKey}`,
1409
- "X-Requested-With": userAgent
1710
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1410
1711
  }
1411
1712
  }));
1412
1713
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1413
1714
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1414
1715
  try {
1415
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1716
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1416
1717
  }
1417
1718
  catch (error) {
1418
1719
  success = true;
@@ -1480,13 +1781,13 @@ export class XykService {
1480
1781
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
1481
1782
  headers: {
1482
1783
  "Authorization": `Bearer ${this.apiKey}`,
1483
- "X-Requested-With": userAgent
1784
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1484
1785
  }
1485
1786
  }));
1486
1787
  debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1487
1788
  if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1488
1789
  try {
1489
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1790
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1490
1791
  }
1491
1792
  catch (error) {
1492
1793
  success = true;