@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
@@ -193,6 +193,7 @@ class PoolsDexDataItem {
193
193
  this.volume_24h_quote = data.volume_24h_quote;
194
194
  this.volume_7d_quote = data.volume_7d_quote;
195
195
  this.fee_24h_quote = data.fee_24h_quote;
196
+ this.annualized_fee = data.annualized_fee;
196
197
  this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
197
198
  this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
198
199
  this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
@@ -235,6 +236,7 @@ class UniswapLikeToken {
235
236
  this.logo_url = data.logo_url;
236
237
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
237
238
  this.quote = data.quote;
239
+ this.pretty_quote = data.pretty_quote;
238
240
  this.quote_rate = data.quote_rate;
239
241
  }
240
242
  }
@@ -246,6 +248,7 @@ class UniswapLikeTokenWithSupply {
246
248
  this.logo_url = data.logo_url;
247
249
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
248
250
  this.quote = data.quote;
251
+ this.pretty_quote = data.pretty_quote;
249
252
  this.quote_rate = data.quote_rate;
250
253
  this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
251
254
  }
@@ -282,6 +285,75 @@ class TokenV2Volume {
282
285
  this.total_volume_24h_quote = data.total_volume_24h_quote;
283
286
  }
284
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
+ }
285
357
  class SupportedDexesResponse {
286
358
  constructor(data) {
287
359
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -324,12 +396,34 @@ class ExchangeTransaction {
324
396
  this.sender_address = data.sender_address;
325
397
  this.total_quote = data.total_quote;
326
398
  this.pretty_total_quote = data.pretty_total_quote;
399
+ this.value = data.value && data.value !== null ? BigInt(data.value) : null;
400
+ this.value_quote = data.value_quote;
401
+ this.pretty_value_quote = data.pretty_value_quote;
402
+ this.gas_offered = data.gas_offered;
403
+ this.gas_spent = data.gas_spent;
404
+ this.gas_price = data.gas_price;
405
+ this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
406
+ this.gas_quote = data.gas_quote;
407
+ this.pretty_gas_quote = data.pretty_gas_quote;
408
+ this.gas_quote_rate = data.gas_quote_rate;
409
+ this.quote_currency = data.quote_currency;
327
410
  this.token_0_quote_rate = data.token_0_quote_rate;
328
411
  this.token_1_quote_rate = data.token_1_quote_rate;
412
+ this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
329
413
  this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
330
414
  this.token_1 = data.token_1 && data.token_1 !== null ? new PoolToken(data.token_1) : null;
331
415
  }
332
416
  }
417
+ class ContractMetadata {
418
+ constructor(data) {
419
+ this.contract_decimals = data.contract_decimals;
420
+ this.contract_name = data.contract_name;
421
+ this.contract_ticker_symbol = data.contract_ticker_symbol;
422
+ this.contract_address = data.contract_address;
423
+ this.supports_erc = data.supports_erc;
424
+ this.logo_url = data.logo_url;
425
+ }
426
+ }
333
427
  class PoolToken {
334
428
  constructor(data) {
335
429
  this.contract_decimals = data.contract_decimals;
@@ -358,6 +452,15 @@ class TransactionsForExchangeResponse {
358
452
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
359
453
  }
360
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
+ }
361
464
  class EcosystemChartDataResponse {
362
465
  constructor(data) {
363
466
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -373,13 +476,15 @@ class UniswapLikeEcosystemCharts {
373
476
  this.chain_id = data.chain_id;
374
477
  this.quote_currency = data.quote_currency;
375
478
  this.gas_token_price_quote = data.gas_token_price_quote;
376
- this.total_swaps24h = data.total_swaps24h;
377
- this.total_active_pairs7d = data.total_active_pairs7d;
378
- this.total_fees24h = data.total_fees24h;
379
- this.volume_chart7d = data.volume_chart7d && data.volume_chart7d !== null ? data.volume_chart7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
380
- this.volume_chart30d = data.volume_chart30d && data.volume_chart30d !== null ? data.volume_chart30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
381
- this.liquidity_chart7d = data.liquidity_chart7d && data.liquidity_chart7d !== null ? data.liquidity_chart7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
382
- this.liquidity_chart30d = data.liquidity_chart30d && data.liquidity_chart30d !== null ? data.liquidity_chart30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
479
+ this.total_swaps_24h = data.total_swaps_24h;
480
+ this.total_active_pairs_7d = data.total_active_pairs_7d;
481
+ this.total_fees_24h = data.total_fees_24h;
482
+ this.pretty_gas_token_price_quote = data.pretty_gas_token_price_quote;
483
+ this.pretty_total_fees_24h = data.pretty_total_fees_24h;
484
+ this.volume_chart_7d = data.volume_chart_7d && data.volume_chart_7d !== null ? data.volume_chart_7d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
485
+ this.volume_chart_30d = data.volume_chart_30d && data.volume_chart_30d !== null ? data.volume_chart_30d.map((itemData) => new VolumeEcosystemChart(itemData)) : null;
486
+ this.liquidity_chart_7d = data.liquidity_chart_7d && data.liquidity_chart_7d !== null ? data.liquidity_chart_7d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
487
+ this.liquidity_chart_30d = data.liquidity_chart_30d && data.liquidity_chart_30d !== null ? data.liquidity_chart_30d.map((itemData) => new LiquidityEcosystemChart(itemData)) : null;
383
488
  }
384
489
  }
385
490
  class VolumeEcosystemChart {
@@ -389,6 +494,7 @@ class VolumeEcosystemChart {
389
494
  this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
390
495
  this.quote_currency = data.quote_currency;
391
496
  this.volume_quote = data.volume_quote;
497
+ this.pretty_volume_quote = data.pretty_volume_quote;
392
498
  this.swap_count_24 = data.swap_count_24;
393
499
  }
394
500
  }
@@ -399,6 +505,7 @@ class LiquidityEcosystemChart {
399
505
  this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
400
506
  this.quote_currency = data.quote_currency;
401
507
  this.liquidity_quote = data.liquidity_quote;
508
+ this.pretty_liquidity_quote = data.pretty_liquidity_quote;
402
509
  }
403
510
  }
404
511
  class HealthDataResponse {
@@ -423,11 +530,13 @@ class HealthData {
423
530
  *
424
531
  */
425
532
  export class XykService {
426
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
533
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
427
534
  this.apiKey = apiKey;
428
535
  this.debug = debug;
429
536
  this.threadCount = threadCount;
430
537
  this.is_key_valid = is_key_valid;
538
+ this.enableRetry = enableRetry;
539
+ this.source = source;
431
540
  this.LIMIT = pLimit(this.threadCount);
432
541
  }
433
542
  /**
@@ -436,9 +545,12 @@ export class XykService {
436
545
  *
437
546
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
438
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.
439
551
  *
440
552
  */
441
- async getPools(chainName, dexName) {
553
+ async getPools(chainName, dexName, queryParamOpts) {
442
554
  let success = false;
443
555
  let data;
444
556
  let response;
@@ -446,6 +558,13 @@ export class XykService {
446
558
  while (!success) {
447
559
  try {
448
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
+ }
567
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`;
449
568
  if (!this.is_key_valid) {
450
569
  return {
451
570
  data: null,
@@ -461,13 +580,13 @@ export class XykService {
461
580
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
462
581
  headers: {
463
582
  "Authorization": `Bearer ${this.apiKey}`,
464
- "X-Requested-With": userAgent
583
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
465
584
  }
466
585
  }));
467
- debugOutput(response.url, response.status ?? 429, startTime);
468
- if (response.status === null || response.status === 429) {
586
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
587
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
469
588
  try {
470
- data = await this.LIMIT(() => backoff.backOff(response.url));
589
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
471
590
  }
472
591
  catch (error) {
473
592
  success = true;
@@ -497,8 +616,8 @@ export class XykService {
497
616
  return {
498
617
  data: null,
499
618
  error: true,
500
- error_code: data ? data.error_code : response.status,
501
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
619
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
620
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
502
621
  };
503
622
  }
504
623
  }
@@ -519,6 +638,7 @@ export class XykService {
519
638
  while (!success) {
520
639
  try {
521
640
  const urlParams = new URLSearchParams();
641
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`;
522
642
  if (!this.is_key_valid) {
523
643
  return {
524
644
  data: null,
@@ -534,13 +654,13 @@ export class XykService {
534
654
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
535
655
  headers: {
536
656
  "Authorization": `Bearer ${this.apiKey}`,
537
- "X-Requested-With": userAgent
657
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
538
658
  }
539
659
  }));
540
- debugOutput(response.url, response.status ?? 429, startTime);
541
- if (response.status === null || response.status === 429) {
660
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
661
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
542
662
  try {
543
- data = await this.LIMIT(() => backoff.backOff(response.url));
663
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
544
664
  }
545
665
  catch (error) {
546
666
  success = true;
@@ -570,8 +690,8 @@ export class XykService {
570
690
  return {
571
691
  data: null,
572
692
  error: true,
573
- error_code: data ? data.error_code : response.status,
574
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
693
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
694
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
575
695
  };
576
696
  }
577
697
  }
@@ -593,6 +713,7 @@ export class XykService {
593
713
  while (!success) {
594
714
  try {
595
715
  const urlParams = new URLSearchParams();
716
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`;
596
717
  if (!this.is_key_valid) {
597
718
  return {
598
719
  data: null,
@@ -608,13 +729,13 @@ export class XykService {
608
729
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
609
730
  headers: {
610
731
  "Authorization": `Bearer ${this.apiKey}`,
611
- "X-Requested-With": userAgent
732
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
612
733
  }
613
734
  }));
614
- debugOutput(response.url, response.status ?? 429, startTime);
615
- if (response.status === null || response.status === 429) {
735
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
736
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
616
737
  try {
617
- data = await this.LIMIT(() => backoff.backOff(response.url));
738
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
618
739
  }
619
740
  catch (error) {
620
741
  success = true;
@@ -644,8 +765,8 @@ export class XykService {
644
765
  return {
645
766
  data: null,
646
767
  error: true,
647
- error_code: data ? data.error_code : response.status,
648
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
768
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
769
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
649
770
  };
650
771
  }
651
772
  }
@@ -659,6 +780,8 @@ export class XykService {
659
780
  * @param {number} page - The requested 0-indexed page number.
660
781
  * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
661
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.
662
785
  *
663
786
  */
664
787
  async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
@@ -683,6 +806,10 @@ export class XykService {
683
806
  if (queryParamOpts?.dexName !== undefined) {
684
807
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
685
808
  }
809
+ if (queryParamOpts?.pageSize !== undefined) {
810
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
811
+ }
812
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`;
686
813
  let startTime;
687
814
  if (this.debug) {
688
815
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -690,13 +817,13 @@ export class XykService {
690
817
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
691
818
  headers: {
692
819
  "Authorization": `Bearer ${this.apiKey}`,
693
- "X-Requested-With": userAgent
820
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
694
821
  }
695
822
  }));
696
- debugOutput(response.url, response.status ?? 429, startTime);
697
- if (response.status === null || response.status === 429) {
823
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
824
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
698
825
  try {
699
- data = await this.LIMIT(() => backoff.backOff(response.url));
826
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
700
827
  }
701
828
  catch (error) {
702
829
  success = true;
@@ -726,8 +853,8 @@ export class XykService {
726
853
  return {
727
854
  data: null,
728
855
  error: true,
729
- error_code: data ? data.error_code : response.status,
730
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
856
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
857
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
731
858
  };
732
859
  }
733
860
  }
@@ -757,6 +884,7 @@ export class XykService {
757
884
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
758
885
  };
759
886
  }
887
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`;
760
888
  let startTime;
761
889
  if (this.debug) {
762
890
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -764,13 +892,13 @@ export class XykService {
764
892
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
765
893
  headers: {
766
894
  "Authorization": `Bearer ${this.apiKey}`,
767
- "X-Requested-With": userAgent
895
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
768
896
  }
769
897
  }));
770
- debugOutput(response.url, response.status ?? 429, startTime);
771
- if (response.status === null || response.status === 429) {
898
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
899
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
772
900
  try {
773
- data = await this.LIMIT(() => backoff.backOff(response.url));
901
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
774
902
  }
775
903
  catch (error) {
776
904
  success = true;
@@ -800,8 +928,8 @@ export class XykService {
800
928
  return {
801
929
  data: null,
802
930
  error: true,
803
- error_code: data ? data.error_code : response.status,
804
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
931
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
932
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
805
933
  };
806
934
  }
807
935
  }
@@ -816,6 +944,8 @@ export class XykService {
816
944
  * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
817
945
  * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
818
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.
819
949
  *
820
950
  */
821
951
  async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
@@ -843,6 +973,10 @@ export class XykService {
843
973
  if (queryParamOpts?.dexName !== undefined) {
844
974
  urlParams.append("dex-name", queryParamOpts?.dexName.toString());
845
975
  }
976
+ if (queryParamOpts?.pageSize !== undefined) {
977
+ urlParams.append("page-size", queryParamOpts?.pageSize.toString());
978
+ }
979
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`;
846
980
  let startTime;
847
981
  if (this.debug) {
848
982
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -850,13 +984,13 @@ export class XykService {
850
984
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
851
985
  headers: {
852
986
  "Authorization": `Bearer ${this.apiKey}`,
853
- "X-Requested-With": userAgent
987
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
854
988
  }
855
989
  }));
856
- debugOutput(response.url, response.status ?? 429, startTime);
857
- if (response.status === null || response.status === 429) {
990
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
991
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
858
992
  try {
859
- data = await this.LIMIT(() => backoff.backOff(response.url));
993
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
860
994
  }
861
995
  catch (error) {
862
996
  success = true;
@@ -886,8 +1020,8 @@ export class XykService {
886
1020
  return {
887
1021
  data: null,
888
1022
  error: true,
889
- error_code: data ? data.error_code : response.status,
890
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1023
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1024
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
891
1025
  };
892
1026
  }
893
1027
  }
@@ -898,9 +1032,12 @@ export class XykService {
898
1032
  *
899
1033
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
900
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.
901
1038
  *
902
1039
  */
903
- async getNetworkExchangeTokens(chainName, dexName) {
1040
+ async getNetworkExchangeTokens(chainName, dexName, queryParamOpts) {
904
1041
  let success = false;
905
1042
  let data;
906
1043
  let response;
@@ -908,6 +1045,12 @@ export class XykService {
908
1045
  while (!success) {
909
1046
  try {
910
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
+ }
911
1054
  if (!this.is_key_valid) {
912
1055
  return {
913
1056
  data: null,
@@ -916,6 +1059,7 @@ export class XykService {
916
1059
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
917
1060
  };
918
1061
  }
1062
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`;
919
1063
  let startTime;
920
1064
  if (this.debug) {
921
1065
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -923,13 +1067,13 @@ export class XykService {
923
1067
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
924
1068
  headers: {
925
1069
  "Authorization": `Bearer ${this.apiKey}`,
926
- "X-Requested-With": userAgent
1070
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
927
1071
  }
928
1072
  }));
929
- debugOutput(response.url, response.status ?? 429, startTime);
930
- if (response.status === null || response.status === 429) {
1073
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1074
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
931
1075
  try {
932
- data = await this.LIMIT(() => backoff.backOff(response.url));
1076
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
933
1077
  }
934
1078
  catch (error) {
935
1079
  success = true;
@@ -959,10 +1103,90 @@ export class XykService {
959
1103
  return {
960
1104
  data: null,
961
1105
  error: true,
1106
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1107
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1108
+ };
1109
+ }
1110
+ }
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,
962
1177
  error_code: data ? data.error_code : response.status,
963
1178
  error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
964
1179
  };
965
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
+ }
966
1190
  }
967
1191
  }
968
1192
  /**
@@ -987,6 +1211,7 @@ export class XykService {
987
1211
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
988
1212
  };
989
1213
  }
1214
+ const url = `https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`;
990
1215
  let startTime;
991
1216
  if (this.debug) {
992
1217
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -994,13 +1219,13 @@ export class XykService {
994
1219
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
995
1220
  headers: {
996
1221
  "Authorization": `Bearer ${this.apiKey}`,
997
- "X-Requested-With": userAgent
1222
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
998
1223
  }
999
1224
  }));
1000
- debugOutput(response.url, response.status ?? 429, startTime);
1001
- if (response.status === null || response.status === 429) {
1225
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1226
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1002
1227
  try {
1003
- data = await this.LIMIT(() => backoff.backOff(response.url));
1228
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1004
1229
  }
1005
1230
  catch (error) {
1006
1231
  success = true;
@@ -1030,8 +1255,8 @@ export class XykService {
1030
1255
  return {
1031
1256
  data: null,
1032
1257
  error: true,
1033
- error_code: data ? data.error_code : response.status,
1034
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1258
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1259
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1035
1260
  };
1036
1261
  }
1037
1262
  }
@@ -1043,9 +1268,12 @@ export class XykService {
1043
1268
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1044
1269
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1045
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.
1046
1274
  *
1047
1275
  */
1048
- async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress) {
1276
+ async getSingleNetworkExchangeToken(chainName, dexName, tokenAddress, queryParamOpts) {
1049
1277
  let success = false;
1050
1278
  let data;
1051
1279
  let response;
@@ -1053,6 +1281,12 @@ export class XykService {
1053
1281
  while (!success) {
1054
1282
  try {
1055
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
+ }
1056
1290
  if (!this.is_key_valid) {
1057
1291
  return {
1058
1292
  data: null,
@@ -1061,6 +1295,7 @@ export class XykService {
1061
1295
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1062
1296
  };
1063
1297
  }
1298
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`;
1064
1299
  let startTime;
1065
1300
  if (this.debug) {
1066
1301
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1068,13 +1303,13 @@ export class XykService {
1068
1303
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
1069
1304
  headers: {
1070
1305
  "Authorization": `Bearer ${this.apiKey}`,
1071
- "X-Requested-With": userAgent
1306
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1072
1307
  }
1073
1308
  }));
1074
- debugOutput(response.url, response.status ?? 429, startTime);
1075
- if (response.status === null || response.status === 429) {
1309
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1310
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1076
1311
  try {
1077
- data = await this.LIMIT(() => backoff.backOff(response.url));
1312
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1078
1313
  }
1079
1314
  catch (error) {
1080
1315
  success = true;
@@ -1104,8 +1339,8 @@ export class XykService {
1104
1339
  return {
1105
1340
  data: null,
1106
1341
  error: true,
1107
- error_code: data ? data.error_code : response.status,
1108
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1342
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1343
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1109
1344
  };
1110
1345
  }
1111
1346
  }
@@ -1135,6 +1370,7 @@ export class XykService {
1135
1370
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1136
1371
  };
1137
1372
  }
1373
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`;
1138
1374
  let startTime;
1139
1375
  if (this.debug) {
1140
1376
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1142,13 +1378,13 @@ export class XykService {
1142
1378
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
1143
1379
  headers: {
1144
1380
  "Authorization": `Bearer ${this.apiKey}`,
1145
- "X-Requested-With": userAgent
1381
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1146
1382
  }
1147
1383
  }));
1148
- debugOutput(response.url, response.status ?? 429, startTime);
1149
- if (response.status === null || response.status === 429) {
1384
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1385
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1150
1386
  try {
1151
- data = await this.LIMIT(() => backoff.backOff(response.url));
1387
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1152
1388
  }
1153
1389
  catch (error) {
1154
1390
  success = true;
@@ -1178,8 +1414,8 @@ export class XykService {
1178
1414
  return {
1179
1415
  data: null,
1180
1416
  error: true,
1181
- error_code: data ? data.error_code : response.status,
1182
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1417
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1418
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1183
1419
  };
1184
1420
  }
1185
1421
  }
@@ -1191,9 +1427,12 @@ export class XykService {
1191
1427
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1192
1428
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1193
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.
1194
1433
  *
1195
1434
  */
1196
- async getTransactionsForTokenAddress(chainName, dexName, tokenAddress) {
1435
+ async getTransactionsForTokenAddress(chainName, dexName, tokenAddress, queryParamOpts) {
1197
1436
  let success = false;
1198
1437
  let data;
1199
1438
  let response;
@@ -1209,6 +1448,13 @@ export class XykService {
1209
1448
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1210
1449
  };
1211
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
+ }
1457
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`;
1212
1458
  let startTime;
1213
1459
  if (this.debug) {
1214
1460
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1216,13 +1462,13 @@ export class XykService {
1216
1462
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
1217
1463
  headers: {
1218
1464
  "Authorization": `Bearer ${this.apiKey}`,
1219
- "X-Requested-With": userAgent
1465
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1220
1466
  }
1221
1467
  }));
1222
- debugOutput(response.url, response.status ?? 429, startTime);
1223
- if (response.status === null || response.status === 429) {
1468
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1469
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1224
1470
  try {
1225
- data = await this.LIMIT(() => backoff.backOff(response.url));
1471
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1226
1472
  }
1227
1473
  catch (error) {
1228
1474
  success = true;
@@ -1252,8 +1498,8 @@ export class XykService {
1252
1498
  return {
1253
1499
  data: null,
1254
1500
  error: true,
1255
- error_code: data ? data.error_code : response.status,
1256
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1501
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1502
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1257
1503
  };
1258
1504
  }
1259
1505
  }
@@ -1265,9 +1511,12 @@ export class XykService {
1265
1511
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1266
1512
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
1267
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.
1268
1517
  *
1269
1518
  */
1270
- async getTransactionsForExchange(chainName, dexName, poolAddress) {
1519
+ async getTransactionsForExchange(chainName, dexName, poolAddress, queryParamOpts) {
1271
1520
  let success = false;
1272
1521
  let data;
1273
1522
  let response;
@@ -1283,6 +1532,13 @@ export class XykService {
1283
1532
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1284
1533
  };
1285
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
+ }
1541
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`;
1286
1542
  let startTime;
1287
1543
  if (this.debug) {
1288
1544
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1290,13 +1546,13 @@ export class XykService {
1290
1546
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
1291
1547
  headers: {
1292
1548
  "Authorization": `Bearer ${this.apiKey}`,
1293
- "X-Requested-With": userAgent
1549
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1294
1550
  }
1295
1551
  }));
1296
- debugOutput(response.url, response.status ?? 429, startTime);
1297
- if (response.status === null || response.status === 429) {
1552
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1553
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1298
1554
  try {
1299
- data = await this.LIMIT(() => backoff.backOff(response.url));
1555
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1300
1556
  }
1301
1557
  catch (error) {
1302
1558
  success = true;
@@ -1326,10 +1582,97 @@ export class XykService {
1326
1582
  return {
1327
1583
  data: null,
1328
1584
  error: true,
1585
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1586
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1587
+ };
1588
+ }
1589
+ }
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,
1329
1663
  error_code: data ? data.error_code : response.status,
1330
1664
  error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1331
1665
  };
1332
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
+ }
1333
1676
  }
1334
1677
  }
1335
1678
  /**
@@ -1356,6 +1699,7 @@ export class XykService {
1356
1699
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1357
1700
  };
1358
1701
  }
1702
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`;
1359
1703
  let startTime;
1360
1704
  if (this.debug) {
1361
1705
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1363,13 +1707,13 @@ export class XykService {
1363
1707
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
1364
1708
  headers: {
1365
1709
  "Authorization": `Bearer ${this.apiKey}`,
1366
- "X-Requested-With": userAgent
1710
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1367
1711
  }
1368
1712
  }));
1369
- debugOutput(response.url, response.status ?? 429, startTime);
1370
- if (response.status === null || response.status === 429) {
1713
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1714
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1371
1715
  try {
1372
- data = await this.LIMIT(() => backoff.backOff(response.url));
1716
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1373
1717
  }
1374
1718
  catch (error) {
1375
1719
  success = true;
@@ -1399,8 +1743,8 @@ export class XykService {
1399
1743
  return {
1400
1744
  data: null,
1401
1745
  error: true,
1402
- error_code: data ? data.error_code : response.status,
1403
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1746
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1747
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1404
1748
  };
1405
1749
  }
1406
1750
  }
@@ -1429,6 +1773,7 @@ export class XykService {
1429
1773
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1430
1774
  };
1431
1775
  }
1776
+ const url = `https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`;
1432
1777
  let startTime;
1433
1778
  if (this.debug) {
1434
1779
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1436,13 +1781,13 @@ export class XykService {
1436
1781
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
1437
1782
  headers: {
1438
1783
  "Authorization": `Bearer ${this.apiKey}`,
1439
- "X-Requested-With": userAgent
1784
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1440
1785
  }
1441
1786
  }));
1442
- debugOutput(response.url, response.status ?? 429, startTime);
1443
- if (response.status === null || response.status === 429) {
1787
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1788
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1444
1789
  try {
1445
- data = await this.LIMIT(() => backoff.backOff(response.url));
1790
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1446
1791
  }
1447
1792
  catch (error) {
1448
1793
  success = true;
@@ -1472,8 +1817,8 @@ export class XykService {
1472
1817
  return {
1473
1818
  data: null,
1474
1819
  error: true,
1475
- error_code: data ? data.error_code : response.status,
1476
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1820
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1821
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1477
1822
  };
1478
1823
  }
1479
1824
  }