@covalenthq/client-sdk 0.2.9 → 0.5.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 (116) hide show
  1. package/README.md +117 -46
  2. package/dist/cjs/index.d.ts +9 -0
  3. package/dist/cjs/index.js +5226 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/services/BalanceService.d.ts +543 -0
  6. package/dist/cjs/services/BaseService.d.ts +357 -0
  7. package/dist/cjs/services/CovalentClient.d.ts +65 -0
  8. package/dist/cjs/services/NftService.d.ts +620 -0
  9. package/dist/cjs/services/PricingService.d.ts +88 -0
  10. package/dist/cjs/services/SecurityService.d.ts +158 -0
  11. package/dist/cjs/services/TransactionService.d.ts +457 -0
  12. package/dist/cjs/services/XykService.d.ts +686 -0
  13. package/dist/cjs/util/ApiHelpers.d.ts +5 -0
  14. package/dist/cjs/util/backoff.d.ts +11 -0
  15. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +322 -0
  16. package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
  17. package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
  18. package/dist/cjs/util/types/NftServiceTypes.d.ts +297 -0
  19. package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
  20. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +121 -0
  21. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +322 -0
  22. package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
  23. package/dist/es/index.d.ts +9 -0
  24. package/dist/es/index.js +5223 -0
  25. package/dist/es/index.js.map +1 -0
  26. package/dist/es/services/BalanceService.d.ts +543 -0
  27. package/dist/es/services/BaseService.d.ts +357 -0
  28. package/dist/es/services/CovalentClient.d.ts +65 -0
  29. package/dist/es/services/NftService.d.ts +620 -0
  30. package/dist/es/services/PricingService.d.ts +88 -0
  31. package/dist/es/services/SecurityService.d.ts +158 -0
  32. package/dist/es/services/TransactionService.d.ts +457 -0
  33. package/dist/es/services/XykService.d.ts +686 -0
  34. package/dist/es/util/ApiHelpers.d.ts +5 -0
  35. package/dist/es/util/backoff.d.ts +11 -0
  36. package/dist/es/util/types/BalanceServiceTypes.d.ts +322 -0
  37. package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
  38. package/dist/es/util/types/GenericTypes.d.ts +96 -0
  39. package/dist/es/util/types/NftServiceTypes.d.ts +297 -0
  40. package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
  41. package/dist/es/util/types/SecurityServiceTypes.d.ts +121 -0
  42. package/dist/es/util/types/TransactionServiceTypes.d.ts +322 -0
  43. package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
  44. package/dist/esm/index.d.ts +9 -0
  45. package/dist/esm/index.js +5223 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/services/BalanceService.d.ts +543 -0
  48. package/dist/esm/services/BaseService.d.ts +357 -0
  49. package/dist/esm/services/CovalentClient.d.ts +65 -0
  50. package/dist/esm/services/NftService.d.ts +620 -0
  51. package/dist/esm/services/PricingService.d.ts +88 -0
  52. package/dist/esm/services/SecurityService.d.ts +158 -0
  53. package/dist/esm/services/TransactionService.d.ts +457 -0
  54. package/dist/esm/services/XykService.d.ts +686 -0
  55. package/dist/esm/util/ApiHelpers.d.ts +5 -0
  56. package/dist/esm/util/backoff.d.ts +11 -0
  57. package/dist/esm/util/types/BalanceServiceTypes.d.ts +322 -0
  58. package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
  59. package/dist/esm/util/types/GenericTypes.d.ts +96 -0
  60. package/dist/esm/util/types/NftServiceTypes.d.ts +297 -0
  61. package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
  62. package/dist/esm/util/types/SecurityServiceTypes.d.ts +121 -0
  63. package/dist/esm/util/types/TransactionServiceTypes.d.ts +322 -0
  64. package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +9 -27
  67. package/dist/index.js.map +1 -1
  68. package/dist/services/BalanceService.d.ts +149 -11
  69. package/dist/services/BalanceService.js +300 -84
  70. package/dist/services/BalanceService.js.map +1 -1
  71. package/dist/services/BaseService.d.ts +46 -10
  72. package/dist/services/BaseService.js +199 -151
  73. package/dist/services/BaseService.js.map +1 -1
  74. package/dist/services/CovalentClient.d.ts +65 -0
  75. package/dist/services/CovalentClient.js +44 -0
  76. package/dist/services/CovalentClient.js.map +1 -0
  77. package/dist/services/NftService.d.ts +182 -16
  78. package/dist/services/NftService.js +490 -211
  79. package/dist/services/NftService.js.map +1 -1
  80. package/dist/services/PricingService.d.ts +8 -3
  81. package/dist/services/PricingService.js +44 -38
  82. package/dist/services/PricingService.js.map +1 -1
  83. package/dist/services/SecurityService.d.ts +71 -3
  84. package/dist/services/SecurityService.js +140 -32
  85. package/dist/services/SecurityService.js.map +1 -1
  86. package/dist/services/TransactionService.d.ts +58 -9
  87. package/dist/services/TransactionService.js +152 -103
  88. package/dist/services/TransactionService.js.map +1 -1
  89. package/dist/services/XykService.d.ts +85 -19
  90. package/dist/services/XykService.js +470 -291
  91. package/dist/services/XykService.js.map +1 -1
  92. package/dist/util/ApiHelpers.d.ts +2 -1
  93. package/dist/util/ApiHelpers.js +57 -36
  94. package/dist/util/ApiHelpers.js.map +1 -1
  95. package/dist/util/backoff.d.ts +5 -3
  96. package/dist/util/backoff.js +35 -13
  97. package/dist/util/backoff.js.map +1 -1
  98. package/dist/util/types/BalanceServiceTypes.d.ts +63 -0
  99. package/dist/util/types/BalanceServiceTypes.js +1 -2
  100. package/dist/util/types/BaseServiceTypes.d.ts +8 -0
  101. package/dist/util/types/BaseServiceTypes.js +1 -2
  102. package/dist/util/types/GenericTypes.d.ts +7 -0
  103. package/dist/util/types/GenericTypes.js +1 -2
  104. package/dist/util/types/NftServiceTypes.d.ts +86 -2
  105. package/dist/util/types/NftServiceTypes.js +1 -2
  106. package/dist/util/types/PricingServiceTypes.js +1 -2
  107. package/dist/util/types/SecurityServiceTypes.d.ts +51 -0
  108. package/dist/util/types/SecurityServiceTypes.js +1 -2
  109. package/dist/util/types/TransactionServiceTypes.d.ts +24 -2
  110. package/dist/util/types/TransactionServiceTypes.js +1 -2
  111. package/dist/util/types/XykServiceTypes.d.ts +20 -6
  112. package/dist/util/types/XykServiceTypes.js +1 -2
  113. package/package.json +19 -4
  114. package/dist/services/Client.d.ts +0 -29
  115. package/dist/services/Client.js +0 -30
  116. package/dist/services/Client.js.map +0 -1
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.XykService = void 0;
4
- const Client_1 = require("./Client");
5
- const ApiHelpers_1 = require("../util/ApiHelpers");
6
- const date_fns_1 = require("date-fns");
7
- const backoff_1 = require("../util/backoff");
1
+ import { userAgent } from "./CovalentClient";
2
+ import { checkAndModifyResponse, debugOutput } from "../util/ApiHelpers";
3
+ import { parseISO } from "date-fns";
4
+ import { ExponentialBackoff } from "../util/backoff";
5
+ import pLimit from "p-limit";
8
6
  class PoolResponse {
9
7
  constructor(data) {
10
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
8
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
11
9
  this.chain_id = data.chain_id;
12
10
  this.chain_name = data.chain_name;
13
11
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Pool(itemData)) : null;
@@ -57,7 +55,7 @@ class Token {
57
55
  }
58
56
  class PoolToDexResponse {
59
57
  constructor(data) {
60
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
58
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
61
59
  this.address = data.address;
62
60
  this.chain_id = data.chain_id;
63
61
  this.chain_name = data.chain_name;
@@ -82,7 +80,7 @@ class PoolToDexItem extends SupportedDex {
82
80
  }
83
81
  class PoolByAddressResponse {
84
82
  constructor(data) {
85
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
83
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
86
84
  this.chain_id = data.chain_id;
87
85
  this.chain_name = data.chain_name;
88
86
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolWithTimeseries(itemData)) : null;
@@ -160,7 +158,7 @@ class PriceTimeseries {
160
158
  }
161
159
  class PoolsDexDataResponse {
162
160
  constructor(data) {
163
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
161
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
164
162
  this.address = data.address;
165
163
  this.chain_id = data.chain_id;
166
164
  this.chain_name = data.chain_name;
@@ -177,24 +175,31 @@ class PoolsDexDataItem {
177
175
  this.exchange_logo_url = data.exchange_logo_url;
178
176
  this.total_liquidity_quote = data.total_liquidity_quote;
179
177
  this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
178
+ this.volume_24h_quote = data.volume_24h_quote;
179
+ this.volume_7d_quote = data.volume_7d_quote;
180
+ this.fee_24h_quote = data.fee_24h_quote;
181
+ this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
182
+ this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
183
+ this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
180
184
  this.token_0 = data.token_0 && data.token_0 !== null ? new PoolsDexToken(data.token_0) : null;
181
185
  this.token_1 = data.token_1 && data.token_1 !== null ? new PoolsDexToken(data.token_1) : null;
182
186
  }
183
187
  }
184
188
  class PoolsDexToken {
185
189
  constructor(data) {
190
+ this.reserve = data.reserve;
191
+ this.contract_name = data.contract_name;
186
192
  this.contract_decimals = data.contract_decimals;
187
193
  this.contract_ticker_symbol = data.contract_ticker_symbol;
188
194
  this.contract_address = data.contract_address;
189
195
  this.logo_url = data.logo_url;
190
- this.reserve = data.reserve;
191
196
  this.quote_rate = data.quote_rate;
192
197
  }
193
198
  }
194
199
  class AddressExchangeBalancesResponse {
195
200
  constructor(data) {
196
201
  this.address = data.address;
197
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
202
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
198
203
  this.chain_id = data.chain_id;
199
204
  this.chain_name = data.chain_name;
200
205
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new UniswapLikeBalanceItem(itemData)) : null;
@@ -232,7 +237,7 @@ class UniswapLikeTokenWithSupply {
232
237
  }
233
238
  class NetworkExchangeTokensResponse {
234
239
  constructor(data) {
235
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
240
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
236
241
  this.chain_id = data.chain_id;
237
242
  this.chain_name = data.chain_name;
238
243
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenV2Volume(itemData)) : null;
@@ -259,14 +264,14 @@ class TokenV2Volume {
259
264
  }
260
265
  class SupportedDexesResponse {
261
266
  constructor(data) {
262
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
267
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
263
268
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new SupportedDex(itemData)) : null;
264
269
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
265
270
  }
266
271
  }
267
272
  class SingleNetworkExchangeTokenResponse {
268
273
  constructor(data) {
269
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
274
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
270
275
  this.chain_id = data.chain_id;
271
276
  this.chain_name = data.chain_name;
272
277
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new PoolWithTimeseries(itemData)) : null;
@@ -275,7 +280,7 @@ class SingleNetworkExchangeTokenResponse {
275
280
  }
276
281
  class TransactionsForAccountAddressResponse {
277
282
  constructor(data) {
278
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
283
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
279
284
  this.chain_id = data.chain_id;
280
285
  this.chain_name = data.chain_name;
281
286
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
@@ -284,7 +289,7 @@ class TransactionsForAccountAddressResponse {
284
289
  }
285
290
  class ExchangeTransaction {
286
291
  constructor(data) {
287
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
292
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
288
293
  this.tx_hash = data.tx_hash;
289
294
  this.act = data.act;
290
295
  this.address = data.address;
@@ -315,7 +320,7 @@ class PoolToken {
315
320
  }
316
321
  class TransactionsForTokenAddressResponse {
317
322
  constructor(data) {
318
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
323
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
319
324
  this.chain_id = data.chain_id;
320
325
  this.chain_name = data.chain_name;
321
326
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
@@ -324,7 +329,7 @@ class TransactionsForTokenAddressResponse {
324
329
  }
325
330
  class TransactionsForExchangeResponse {
326
331
  constructor(data) {
327
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
332
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
328
333
  this.chain_id = data.chain_id;
329
334
  this.chain_name = data.chain_name;
330
335
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ExchangeTransaction(itemData)) : null;
@@ -333,7 +338,7 @@ class TransactionsForExchangeResponse {
333
338
  }
334
339
  class EcosystemChartDataResponse {
335
340
  constructor(data) {
336
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
341
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
337
342
  this.chain_id = data.chain_id;
338
343
  this.chain_name = data.chain_name;
339
344
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new UniswapLikeEcosystemCharts(itemData)) : null;
@@ -359,7 +364,7 @@ class VolumeEcosystemChart {
359
364
  constructor(data) {
360
365
  this.dex_name = data.dex_name;
361
366
  this.chain_id = data.chain_id;
362
- this.dt = data.dt && data.dt !== null ? (0, date_fns_1.parseISO)(data.dt.toString()) : null;
367
+ this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
363
368
  this.quote_currency = data.quote_currency;
364
369
  this.volume_quote = data.volume_quote;
365
370
  this.swap_count_24 = data.swap_count_24;
@@ -369,14 +374,14 @@ class LiquidityEcosystemChart {
369
374
  constructor(data) {
370
375
  this.dex_name = data.dex_name;
371
376
  this.chain_id = data.chain_id;
372
- this.dt = data.dt && data.dt !== null ? (0, date_fns_1.parseISO)(data.dt.toString()) : null;
377
+ this.dt = data.dt && data.dt !== null ? parseISO(data.dt.toString()) : null;
373
378
  this.quote_currency = data.quote_currency;
374
379
  this.liquidity_quote = data.liquidity_quote;
375
380
  }
376
381
  }
377
382
  class HealthDataResponse {
378
383
  constructor(data) {
379
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
384
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
380
385
  this.chain_id = data.chain_id;
381
386
  this.chain_name = data.chain_name;
382
387
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new HealthData(itemData)) : null;
@@ -386,20 +391,25 @@ class HealthDataResponse {
386
391
  class HealthData {
387
392
  constructor(data) {
388
393
  this.synced_block_height = data.synced_block_height;
389
- this.synced_block_signed_at = data.synced_block_signed_at && data.synced_block_signed_at !== null ? (0, date_fns_1.parseISO)(data.synced_block_signed_at.toString()) : null;
394
+ this.synced_block_signed_at = data.synced_block_signed_at && data.synced_block_signed_at !== null ? parseISO(data.synced_block_signed_at.toString()) : null;
390
395
  this.latest_block_height = data.latest_block_height;
391
- this.latest_block_signed_at = data.latest_block_signed_at && data.latest_block_signed_at !== null ? (0, date_fns_1.parseISO)(data.latest_block_signed_at.toString()) : null;
396
+ this.latest_block_signed_at = data.latest_block_signed_at && data.latest_block_signed_at !== null ? parseISO(data.latest_block_signed_at.toString()) : null;
392
397
  }
393
398
  }
394
399
  /**
395
400
  * XYK APIs
396
401
  *
397
402
  */
398
- class XykService {
399
- constructor(apiKey) {
403
+ export class XykService {
404
+ constructor(apiKey, debug = false, threadCount = 3) {
400
405
  this.apiKey = apiKey;
406
+ this.debug = debug;
407
+ this.threadCount = threadCount;
408
+ this.LIMIT = pLimit(this.threadCount);
401
409
  }
402
410
  /**
411
+ *
412
+ * Commonly used to get all the pools of a particular DEX. Supports most common DEXs (Uniswap, SushiSwap, etc), and returns detailed trading data (volume, liquidity, swap counts, fees, LP token prices).
403
413
  *
404
414
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
405
415
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -409,42 +419,47 @@ class XykService {
409
419
  let success = false;
410
420
  let data;
411
421
  let response;
412
- const backoff = new backoff_1.ExponentialBackoff();
422
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
413
423
  while (!success) {
414
424
  try {
415
425
  const urlParams = new URLSearchParams();
416
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
426
+ let startTime;
427
+ if (this.debug) {
428
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
429
+ }
430
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/?${urlParams}`, {
417
431
  headers: {
418
432
  "Authorization": `Bearer ${this.apiKey}`,
419
- "X-Requested-With": Client_1.userAgent
433
+ "X-Requested-With": userAgent
420
434
  }
421
- });
422
- data = await response.json();
423
- if (data.error && data.error_code === 429) {
435
+ }));
436
+ debugOutput(response.url, response.status, startTime);
437
+ if (response.status === 429) {
424
438
  try {
425
- await backoff.backOff();
439
+ data = await this.LIMIT(() => backoff.backOff(response.url));
426
440
  }
427
441
  catch (error) {
428
442
  success = true;
429
443
  return {
430
444
  data: null,
431
- error: data.error,
432
- error_code: data ? data.error_code : response.status,
433
- error_message: data ? data.error_message : "401 Authorization Required"
445
+ error: true,
446
+ error_code: response.status,
447
+ error_message: error.message
434
448
  };
435
449
  }
436
450
  }
437
451
  else {
438
- const dataClass = new PoolResponse(data.data);
439
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
440
- success = true;
441
- return {
442
- data: dataClass,
443
- error: data.error,
444
- error_code: data ? data.error_code : response.status,
445
- error_message: data ? data.error_message : "401 Authorization Required"
446
- };
452
+ data = await response.json();
447
453
  }
454
+ const dataClass = new PoolResponse(data.data);
455
+ checkAndModifyResponse(dataClass);
456
+ success = true;
457
+ return {
458
+ data: dataClass,
459
+ error: data.error,
460
+ error_code: data ? data.error_code : response.status,
461
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
462
+ };
448
463
  }
449
464
  catch (error) {
450
465
  success = true;
@@ -452,12 +467,14 @@ class XykService {
452
467
  data: null,
453
468
  error: true,
454
469
  error_code: data ? data.error_code : response.status,
455
- error_message: data ? data.error_message : "401 Authorization Required"
470
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
456
471
  };
457
472
  }
458
473
  }
459
474
  }
460
475
  /**
476
+ *
477
+ * Commonly used to get the corresponding supported DEX given a pool address, along with the swap fees, DEX's logo url, and factory addresses. Useful to identifying the specific DEX to which a pair address is associated.
461
478
  *
462
479
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
463
480
  * @param {string} poolAddress - The requested pool address.
@@ -467,42 +484,47 @@ class XykService {
467
484
  let success = false;
468
485
  let data;
469
486
  let response;
470
- const backoff = new backoff_1.ExponentialBackoff();
487
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
471
488
  while (!success) {
472
489
  try {
473
490
  const urlParams = new URLSearchParams();
474
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
491
+ let startTime;
492
+ if (this.debug) {
493
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
494
+ }
495
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${poolAddress}/dex_name/?${urlParams}`, {
475
496
  headers: {
476
497
  "Authorization": `Bearer ${this.apiKey}`,
477
- "X-Requested-With": Client_1.userAgent
498
+ "X-Requested-With": userAgent
478
499
  }
479
- });
480
- data = await response.json();
481
- if (data.error && data.error_code === 429) {
500
+ }));
501
+ debugOutput(response.url, response.status, startTime);
502
+ if (response.status === 429) {
482
503
  try {
483
- await backoff.backOff();
504
+ data = await this.LIMIT(() => backoff.backOff(response.url));
484
505
  }
485
506
  catch (error) {
486
507
  success = true;
487
508
  return {
488
509
  data: null,
489
- error: data.error,
490
- error_code: data ? data.error_code : response.status,
491
- error_message: data ? data.error_message : "401 Authorization Required"
510
+ error: true,
511
+ error_code: response.status,
512
+ error_message: error.message
492
513
  };
493
514
  }
494
515
  }
495
516
  else {
496
- const dataClass = new PoolToDexResponse(data.data);
497
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
498
- success = true;
499
- return {
500
- data: dataClass,
501
- error: data.error,
502
- error_code: data ? data.error_code : response.status,
503
- error_message: data ? data.error_message : "401 Authorization Required"
504
- };
517
+ data = await response.json();
505
518
  }
519
+ const dataClass = new PoolToDexResponse(data.data);
520
+ checkAndModifyResponse(dataClass);
521
+ success = true;
522
+ return {
523
+ data: dataClass,
524
+ error: data.error,
525
+ error_code: data ? data.error_code : response.status,
526
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
527
+ };
506
528
  }
507
529
  catch (error) {
508
530
  success = true;
@@ -510,12 +532,14 @@ class XykService {
510
532
  data: null,
511
533
  error: true,
512
534
  error_code: data ? data.error_code : response.status,
513
- error_message: data ? data.error_message : "401 Authorization Required"
535
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
514
536
  };
515
537
  }
516
538
  }
517
539
  }
518
540
  /**
541
+ *
542
+ * Commonly used to get the 7 day and 30 day time-series data (volume, liquidity, price) of a particular liquidity pool in a DEX. Useful for building time-series charts on DEX trading activity.
519
543
  *
520
544
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
521
545
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -526,42 +550,47 @@ class XykService {
526
550
  let success = false;
527
551
  let data;
528
552
  let response;
529
- const backoff = new backoff_1.ExponentialBackoff();
553
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
530
554
  while (!success) {
531
555
  try {
532
556
  const urlParams = new URLSearchParams();
533
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
557
+ let startTime;
558
+ if (this.debug) {
559
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
560
+ }
561
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/?${urlParams}`, {
534
562
  headers: {
535
563
  "Authorization": `Bearer ${this.apiKey}`,
536
- "X-Requested-With": Client_1.userAgent
564
+ "X-Requested-With": userAgent
537
565
  }
538
- });
539
- data = await response.json();
540
- if (data.error && data.error_code === 429) {
566
+ }));
567
+ debugOutput(response.url, response.status, startTime);
568
+ if (response.status === 429) {
541
569
  try {
542
- await backoff.backOff();
570
+ data = await this.LIMIT(() => backoff.backOff(response.url));
543
571
  }
544
572
  catch (error) {
545
573
  success = true;
546
574
  return {
547
575
  data: null,
548
- error: data.error,
549
- error_code: data ? data.error_code : response.status,
550
- error_message: data ? data.error_message : "401 Authorization Required"
576
+ error: true,
577
+ error_code: response.status,
578
+ error_message: error.message
551
579
  };
552
580
  }
553
581
  }
554
582
  else {
555
- const dataClass = new PoolByAddressResponse(data.data);
556
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
557
- success = true;
558
- return {
559
- data: dataClass,
560
- error: data.error,
561
- error_code: data ? data.error_code : response.status,
562
- error_message: data ? data.error_message : "401 Authorization Required"
563
- };
583
+ data = await response.json();
564
584
  }
585
+ const dataClass = new PoolByAddressResponse(data.data);
586
+ checkAndModifyResponse(dataClass);
587
+ success = true;
588
+ return {
589
+ data: dataClass,
590
+ error: data.error,
591
+ error_code: data ? data.error_code : response.status,
592
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
593
+ };
565
594
  }
566
595
  catch (error) {
567
596
  success = true;
@@ -569,62 +598,73 @@ class XykService {
569
598
  data: null,
570
599
  error: true,
571
600
  error_code: data ? data.error_code : response.status,
572
- error_message: data ? data.error_message : "401 Authorization Required"
601
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
573
602
  };
574
603
  }
575
604
  }
576
605
  }
577
606
  /**
607
+ *
608
+ * Commonly used to get all pools and the supported DEX for a token. Useful for building a table of top pairs across all supported DEXes that the token is trading on.
578
609
  *
579
610
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
580
611
  * @param {string} tokenAddress - The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
612
+ * @param {number} page - The requested 0-indexed page number.
581
613
  * @param {GetPoolsForTokenAddressQueryParamOpts} queryParamOpts
582
614
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
583
615
  *
584
616
  */
585
- async getPoolsForTokenAddress(chainName, tokenAddress, queryParamOpts) {
617
+ async getPoolsForTokenAddress(chainName, tokenAddress, page, queryParamOpts) {
586
618
  let success = false;
587
619
  let data;
588
620
  let response;
589
- const backoff = new backoff_1.ExponentialBackoff();
621
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
590
622
  while (!success) {
591
623
  try {
592
624
  const urlParams = new URLSearchParams();
593
625
  if (queryParamOpts?.quoteCurrency !== undefined) {
594
626
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
595
627
  }
596
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${tokenAddress}/pools/?${urlParams}`, {
628
+ if (queryParamOpts?.dexName !== undefined) {
629
+ urlParams.append("dex-name", queryParamOpts?.dexName.toString());
630
+ }
631
+ let startTime;
632
+ if (this.debug) {
633
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
634
+ }
635
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
597
636
  headers: {
598
637
  "Authorization": `Bearer ${this.apiKey}`,
599
- "X-Requested-With": Client_1.userAgent
638
+ "X-Requested-With": userAgent
600
639
  }
601
- });
602
- data = await response.json();
603
- if (data.error && data.error_code === 429) {
640
+ }));
641
+ debugOutput(response.url, response.status, startTime);
642
+ if (response.status === 429) {
604
643
  try {
605
- await backoff.backOff();
644
+ data = await this.LIMIT(() => backoff.backOff(response.url));
606
645
  }
607
646
  catch (error) {
608
647
  success = true;
609
648
  return {
610
649
  data: null,
611
- error: data.error,
612
- error_code: data ? data.error_code : response.status,
613
- error_message: data ? data.error_message : "401 Authorization Required"
650
+ error: true,
651
+ error_code: response.status,
652
+ error_message: error.message
614
653
  };
615
654
  }
616
655
  }
617
656
  else {
618
- const dataClass = new PoolsDexDataResponse(data.data);
619
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
620
- success = true;
621
- return {
622
- data: dataClass,
623
- error: data.error,
624
- error_code: data ? data.error_code : response.status,
625
- error_message: data ? data.error_message : "401 Authorization Required"
626
- };
657
+ data = await response.json();
627
658
  }
659
+ const dataClass = new PoolsDexDataResponse(data.data);
660
+ checkAndModifyResponse(dataClass);
661
+ success = true;
662
+ return {
663
+ data: dataClass,
664
+ error: data.error,
665
+ error_code: data ? data.error_code : response.status,
666
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
667
+ };
628
668
  }
629
669
  catch (error) {
630
670
  success = true;
@@ -632,12 +672,14 @@ class XykService {
632
672
  data: null,
633
673
  error: true,
634
674
  error_code: data ? data.error_code : response.status,
635
- error_message: data ? data.error_message : "401 Authorization Required"
675
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
636
676
  };
637
677
  }
638
678
  }
639
679
  }
640
680
  /**
681
+ *
682
+ * Commonly used to return balance of a wallet/contract address on a specific DEX.
641
683
  *
642
684
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
643
685
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -648,42 +690,47 @@ class XykService {
648
690
  let success = false;
649
691
  let data;
650
692
  let response;
651
- const backoff = new backoff_1.ExponentialBackoff();
693
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
652
694
  while (!success) {
653
695
  try {
654
696
  const urlParams = new URLSearchParams();
655
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
697
+ let startTime;
698
+ if (this.debug) {
699
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
700
+ }
701
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
656
702
  headers: {
657
703
  "Authorization": `Bearer ${this.apiKey}`,
658
- "X-Requested-With": Client_1.userAgent
704
+ "X-Requested-With": userAgent
659
705
  }
660
- });
661
- data = await response.json();
662
- if (data.error && data.error_code === 429) {
706
+ }));
707
+ debugOutput(response.url, response.status, startTime);
708
+ if (response.status === 429) {
663
709
  try {
664
- await backoff.backOff();
710
+ data = await this.LIMIT(() => backoff.backOff(response.url));
665
711
  }
666
712
  catch (error) {
667
713
  success = true;
668
714
  return {
669
715
  data: null,
670
- error: data.error,
671
- error_code: data ? data.error_code : response.status,
672
- error_message: data ? data.error_message : "401 Authorization Required"
716
+ error: true,
717
+ error_code: response.status,
718
+ error_message: error.message
673
719
  };
674
720
  }
675
721
  }
676
722
  else {
677
- const dataClass = new AddressExchangeBalancesResponse(data.data);
678
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
679
- success = true;
680
- return {
681
- data: dataClass,
682
- error: data.error,
683
- error_code: data ? data.error_code : response.status,
684
- error_message: data ? data.error_message : "401 Authorization Required"
685
- };
723
+ data = await response.json();
686
724
  }
725
+ const dataClass = new AddressExchangeBalancesResponse(data.data);
726
+ checkAndModifyResponse(dataClass);
727
+ success = true;
728
+ return {
729
+ data: dataClass,
730
+ error: data.error,
731
+ error_code: data ? data.error_code : response.status,
732
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
733
+ };
687
734
  }
688
735
  catch (error) {
689
736
  success = true;
@@ -691,12 +738,92 @@ class XykService {
691
738
  data: null,
692
739
  error: true,
693
740
  error_code: data ? data.error_code : response.status,
694
- error_message: data ? data.error_message : "401 Authorization Required"
741
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
695
742
  };
696
743
  }
697
744
  }
698
745
  }
699
746
  /**
747
+ *
748
+ * Commonly used to get all pools and supported DEX for a wallet. Useful for building a personal DEX UI showcasing pairs and supported DEXes associated to the wallet.
749
+ *
750
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
751
+ * @param {string} walletAddress - The account address.
752
+ * @param {number} page - The requested 0-indexed page number.
753
+ * @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
754
+ * - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
755
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
756
+ *
757
+ */
758
+ async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
759
+ let success = false;
760
+ let data;
761
+ let response;
762
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
763
+ while (!success) {
764
+ try {
765
+ const urlParams = new URLSearchParams();
766
+ if (queryParamOpts?.tokenAddress !== undefined) {
767
+ urlParams.append("token-address", queryParamOpts?.tokenAddress.toString());
768
+ }
769
+ if (queryParamOpts?.quoteCurrency !== undefined) {
770
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
771
+ }
772
+ if (queryParamOpts?.dexName !== undefined) {
773
+ urlParams.append("dex-name", queryParamOpts?.dexName.toString());
774
+ }
775
+ let startTime;
776
+ if (this.debug) {
777
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
778
+ }
779
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
780
+ headers: {
781
+ "Authorization": `Bearer ${this.apiKey}`,
782
+ "X-Requested-With": userAgent
783
+ }
784
+ }));
785
+ debugOutput(response.url, response.status, startTime);
786
+ if (response.status === 429) {
787
+ try {
788
+ data = await this.LIMIT(() => backoff.backOff(response.url));
789
+ }
790
+ catch (error) {
791
+ success = true;
792
+ return {
793
+ data: null,
794
+ error: true,
795
+ error_code: response.status,
796
+ error_message: error.message
797
+ };
798
+ }
799
+ }
800
+ else {
801
+ data = await response.json();
802
+ }
803
+ const dataClass = new PoolsDexDataResponse(data.data);
804
+ checkAndModifyResponse(dataClass);
805
+ success = true;
806
+ return {
807
+ data: dataClass,
808
+ error: data.error,
809
+ error_code: data ? data.error_code : response.status,
810
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
811
+ };
812
+ }
813
+ catch (error) {
814
+ success = true;
815
+ return {
816
+ data: null,
817
+ error: true,
818
+ error_code: data ? data.error_code : response.status,
819
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
820
+ };
821
+ }
822
+ }
823
+ }
824
+ /**
825
+ *
826
+ * Commonly used to retrieve all network exchange tokens for a specific DEX. Useful for building a top tokens table by total liquidity within a particular DEX.
700
827
  *
701
828
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
702
829
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -706,42 +833,47 @@ class XykService {
706
833
  let success = false;
707
834
  let data;
708
835
  let response;
709
- const backoff = new backoff_1.ExponentialBackoff();
836
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
710
837
  while (!success) {
711
838
  try {
712
839
  const urlParams = new URLSearchParams();
713
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
840
+ let startTime;
841
+ if (this.debug) {
842
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
843
+ }
844
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
714
845
  headers: {
715
846
  "Authorization": `Bearer ${this.apiKey}`,
716
- "X-Requested-With": Client_1.userAgent
847
+ "X-Requested-With": userAgent
717
848
  }
718
- });
719
- data = await response.json();
720
- if (data.error && data.error_code === 429) {
849
+ }));
850
+ debugOutput(response.url, response.status, startTime);
851
+ if (response.status === 429) {
721
852
  try {
722
- await backoff.backOff();
853
+ data = await this.LIMIT(() => backoff.backOff(response.url));
723
854
  }
724
855
  catch (error) {
725
856
  success = true;
726
857
  return {
727
858
  data: null,
728
- error: data.error,
729
- error_code: data ? data.error_code : response.status,
730
- error_message: data ? data.error_message : "401 Authorization Required"
859
+ error: true,
860
+ error_code: response.status,
861
+ error_message: error.message
731
862
  };
732
863
  }
733
864
  }
734
865
  else {
735
- const dataClass = new NetworkExchangeTokensResponse(data.data);
736
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
737
- success = true;
738
- return {
739
- data: dataClass,
740
- error: data.error,
741
- error_code: data ? data.error_code : response.status,
742
- error_message: data ? data.error_message : "401 Authorization Required"
743
- };
866
+ data = await response.json();
744
867
  }
868
+ const dataClass = new NetworkExchangeTokensResponse(data.data);
869
+ checkAndModifyResponse(dataClass);
870
+ success = true;
871
+ return {
872
+ data: dataClass,
873
+ error: data.error,
874
+ error_code: data ? data.error_code : response.status,
875
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
876
+ };
745
877
  }
746
878
  catch (error) {
747
879
  success = true;
@@ -749,56 +881,62 @@ class XykService {
749
881
  data: null,
750
882
  error: true,
751
883
  error_code: data ? data.error_code : response.status,
752
- error_message: data ? data.error_message : "401 Authorization Required"
884
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
753
885
  };
754
886
  }
755
887
  }
756
888
  }
757
889
  /**
758
890
  *
759
-
891
+ * Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
892
+ *
760
893
  *
761
894
  */
762
895
  async getSupportedDEXes() {
763
896
  let success = false;
764
897
  let data;
765
898
  let response;
766
- const backoff = new backoff_1.ExponentialBackoff();
899
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
767
900
  while (!success) {
768
901
  try {
769
902
  const urlParams = new URLSearchParams();
770
- response = await fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
903
+ let startTime;
904
+ if (this.debug) {
905
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
906
+ }
907
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
771
908
  headers: {
772
909
  "Authorization": `Bearer ${this.apiKey}`,
773
- "X-Requested-With": Client_1.userAgent
910
+ "X-Requested-With": userAgent
774
911
  }
775
- });
776
- data = await response.json();
777
- if (data.error && data.error_code === 429) {
912
+ }));
913
+ debugOutput(response.url, response.status, startTime);
914
+ if (response.status === 429) {
778
915
  try {
779
- await backoff.backOff();
916
+ data = await this.LIMIT(() => backoff.backOff(response.url));
780
917
  }
781
918
  catch (error) {
782
919
  success = true;
783
920
  return {
784
921
  data: null,
785
- error: data.error,
786
- error_code: data ? data.error_code : response.status,
787
- error_message: data ? data.error_message : "401 Authorization Required"
922
+ error: true,
923
+ error_code: response.status,
924
+ error_message: error.message
788
925
  };
789
926
  }
790
927
  }
791
928
  else {
792
- const dataClass = new SupportedDexesResponse(data.data);
793
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
794
- success = true;
795
- return {
796
- data: dataClass,
797
- error: data.error,
798
- error_code: data ? data.error_code : response.status,
799
- error_message: data ? data.error_message : "401 Authorization Required"
800
- };
929
+ data = await response.json();
801
930
  }
931
+ const dataClass = new SupportedDexesResponse(data.data);
932
+ checkAndModifyResponse(dataClass);
933
+ success = true;
934
+ return {
935
+ data: dataClass,
936
+ error: data.error,
937
+ error_code: data ? data.error_code : response.status,
938
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
939
+ };
802
940
  }
803
941
  catch (error) {
804
942
  success = true;
@@ -806,12 +944,14 @@ class XykService {
806
944
  data: null,
807
945
  error: true,
808
946
  error_code: data ? data.error_code : response.status,
809
- error_message: data ? data.error_message : "401 Authorization Required"
947
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
810
948
  };
811
949
  }
812
950
  }
813
951
  }
814
952
  /**
953
+ *
954
+ * Commonly used to get historical daily swap count for a single network exchange token.
815
955
  *
816
956
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
817
957
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -822,42 +962,47 @@ class XykService {
822
962
  let success = false;
823
963
  let data;
824
964
  let response;
825
- const backoff = new backoff_1.ExponentialBackoff();
965
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
826
966
  while (!success) {
827
967
  try {
828
968
  const urlParams = new URLSearchParams();
829
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
969
+ let startTime;
970
+ if (this.debug) {
971
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
972
+ }
973
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
830
974
  headers: {
831
975
  "Authorization": `Bearer ${this.apiKey}`,
832
- "X-Requested-With": Client_1.userAgent
976
+ "X-Requested-With": userAgent
833
977
  }
834
- });
835
- data = await response.json();
836
- if (data.error && data.error_code === 429) {
978
+ }));
979
+ debugOutput(response.url, response.status, startTime);
980
+ if (response.status === 429) {
837
981
  try {
838
- await backoff.backOff();
982
+ data = await this.LIMIT(() => backoff.backOff(response.url));
839
983
  }
840
984
  catch (error) {
841
985
  success = true;
842
986
  return {
843
987
  data: null,
844
- error: data.error,
845
- error_code: data ? data.error_code : response.status,
846
- error_message: data ? data.error_message : "401 Authorization Required"
988
+ error: true,
989
+ error_code: response.status,
990
+ error_message: error.message
847
991
  };
848
992
  }
849
993
  }
850
994
  else {
851
- const dataClass = new SingleNetworkExchangeTokenResponse(data.data);
852
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
853
- success = true;
854
- return {
855
- data: dataClass,
856
- error: data.error,
857
- error_code: data ? data.error_code : response.status,
858
- error_message: data ? data.error_message : "401 Authorization Required"
859
- };
995
+ data = await response.json();
860
996
  }
997
+ const dataClass = new SingleNetworkExchangeTokenResponse(data.data);
998
+ checkAndModifyResponse(dataClass);
999
+ success = true;
1000
+ return {
1001
+ data: dataClass,
1002
+ error: data.error,
1003
+ error_code: data ? data.error_code : response.status,
1004
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1005
+ };
861
1006
  }
862
1007
  catch (error) {
863
1008
  success = true;
@@ -865,12 +1010,14 @@ class XykService {
865
1010
  data: null,
866
1011
  error: true,
867
1012
  error_code: data ? data.error_code : response.status,
868
- error_message: data ? data.error_message : "401 Authorization Required"
1013
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
869
1014
  };
870
1015
  }
871
1016
  }
872
1017
  }
873
1018
  /**
1019
+ *
1020
+ * Commonly used to get all the DEX transactions of a wallet. Useful for building tables of DEX activity segmented by wallet.
874
1021
  *
875
1022
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
876
1023
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -881,42 +1028,47 @@ class XykService {
881
1028
  let success = false;
882
1029
  let data;
883
1030
  let response;
884
- const backoff = new backoff_1.ExponentialBackoff();
1031
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
885
1032
  while (!success) {
886
1033
  try {
887
1034
  const urlParams = new URLSearchParams();
888
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
1035
+ let startTime;
1036
+ if (this.debug) {
1037
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1038
+ }
1039
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
889
1040
  headers: {
890
1041
  "Authorization": `Bearer ${this.apiKey}`,
891
- "X-Requested-With": Client_1.userAgent
1042
+ "X-Requested-With": userAgent
892
1043
  }
893
- });
894
- data = await response.json();
895
- if (data.error && data.error_code === 429) {
1044
+ }));
1045
+ debugOutput(response.url, response.status, startTime);
1046
+ if (response.status === 429) {
896
1047
  try {
897
- await backoff.backOff();
1048
+ data = await this.LIMIT(() => backoff.backOff(response.url));
898
1049
  }
899
1050
  catch (error) {
900
1051
  success = true;
901
1052
  return {
902
1053
  data: null,
903
- error: data.error,
904
- error_code: data ? data.error_code : response.status,
905
- error_message: data ? data.error_message : "401 Authorization Required"
1054
+ error: true,
1055
+ error_code: response.status,
1056
+ error_message: error.message
906
1057
  };
907
1058
  }
908
1059
  }
909
1060
  else {
910
- const dataClass = new TransactionsForAccountAddressResponse(data.data);
911
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
912
- success = true;
913
- return {
914
- data: dataClass,
915
- error: data.error,
916
- error_code: data ? data.error_code : response.status,
917
- error_message: data ? data.error_message : "401 Authorization Required"
918
- };
1061
+ data = await response.json();
919
1062
  }
1063
+ const dataClass = new TransactionsForAccountAddressResponse(data.data);
1064
+ checkAndModifyResponse(dataClass);
1065
+ success = true;
1066
+ return {
1067
+ data: dataClass,
1068
+ error: data.error,
1069
+ error_code: data ? data.error_code : response.status,
1070
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1071
+ };
920
1072
  }
921
1073
  catch (error) {
922
1074
  success = true;
@@ -924,12 +1076,14 @@ class XykService {
924
1076
  data: null,
925
1077
  error: true,
926
1078
  error_code: data ? data.error_code : response.status,
927
- error_message: data ? data.error_message : "401 Authorization Required"
1079
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
928
1080
  };
929
1081
  }
930
1082
  }
931
1083
  }
932
1084
  /**
1085
+ *
1086
+ * Commonly used to get all the transactions of a token within a particular DEX. Useful for getting a per-token view of DEX activity.
933
1087
  *
934
1088
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
935
1089
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -940,42 +1094,47 @@ class XykService {
940
1094
  let success = false;
941
1095
  let data;
942
1096
  let response;
943
- const backoff = new backoff_1.ExponentialBackoff();
1097
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
944
1098
  while (!success) {
945
1099
  try {
946
1100
  const urlParams = new URLSearchParams();
947
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
1101
+ let startTime;
1102
+ if (this.debug) {
1103
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1104
+ }
1105
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
948
1106
  headers: {
949
1107
  "Authorization": `Bearer ${this.apiKey}`,
950
- "X-Requested-With": Client_1.userAgent
1108
+ "X-Requested-With": userAgent
951
1109
  }
952
- });
953
- data = await response.json();
954
- if (data.error && data.error_code === 429) {
1110
+ }));
1111
+ debugOutput(response.url, response.status, startTime);
1112
+ if (response.status === 429) {
955
1113
  try {
956
- await backoff.backOff();
1114
+ data = await this.LIMIT(() => backoff.backOff(response.url));
957
1115
  }
958
1116
  catch (error) {
959
1117
  success = true;
960
1118
  return {
961
1119
  data: null,
962
- error: data.error,
963
- error_code: data ? data.error_code : response.status,
964
- error_message: data ? data.error_message : "401 Authorization Required"
1120
+ error: true,
1121
+ error_code: response.status,
1122
+ error_message: error.message
965
1123
  };
966
1124
  }
967
1125
  }
968
1126
  else {
969
- const dataClass = new TransactionsForTokenAddressResponse(data.data);
970
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
971
- success = true;
972
- return {
973
- data: dataClass,
974
- error: data.error,
975
- error_code: data ? data.error_code : response.status,
976
- error_message: data ? data.error_message : "401 Authorization Required"
977
- };
1127
+ data = await response.json();
978
1128
  }
1129
+ const dataClass = new TransactionsForTokenAddressResponse(data.data);
1130
+ checkAndModifyResponse(dataClass);
1131
+ success = true;
1132
+ return {
1133
+ data: dataClass,
1134
+ error: data.error,
1135
+ error_code: data ? data.error_code : response.status,
1136
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1137
+ };
979
1138
  }
980
1139
  catch (error) {
981
1140
  success = true;
@@ -983,12 +1142,14 @@ class XykService {
983
1142
  data: null,
984
1143
  error: true,
985
1144
  error_code: data ? data.error_code : response.status,
986
- error_message: data ? data.error_message : "401 Authorization Required"
1145
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
987
1146
  };
988
1147
  }
989
1148
  }
990
1149
  }
991
1150
  /**
1151
+ *
1152
+ * Commonly used for getting all the transactions of a particular DEX liquidity pool. Useful for building a transactions history table for an individual pool.
992
1153
  *
993
1154
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
994
1155
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -999,42 +1160,47 @@ class XykService {
999
1160
  let success = false;
1000
1161
  let data;
1001
1162
  let response;
1002
- const backoff = new backoff_1.ExponentialBackoff();
1163
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1003
1164
  while (!success) {
1004
1165
  try {
1005
1166
  const urlParams = new URLSearchParams();
1006
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
1167
+ let startTime;
1168
+ if (this.debug) {
1169
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1170
+ }
1171
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
1007
1172
  headers: {
1008
1173
  "Authorization": `Bearer ${this.apiKey}`,
1009
- "X-Requested-With": Client_1.userAgent
1174
+ "X-Requested-With": userAgent
1010
1175
  }
1011
- });
1012
- data = await response.json();
1013
- if (data.error && data.error_code === 429) {
1176
+ }));
1177
+ debugOutput(response.url, response.status, startTime);
1178
+ if (response.status === 429) {
1014
1179
  try {
1015
- await backoff.backOff();
1180
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1016
1181
  }
1017
1182
  catch (error) {
1018
1183
  success = true;
1019
1184
  return {
1020
1185
  data: null,
1021
- error: data.error,
1022
- error_code: data ? data.error_code : response.status,
1023
- error_message: data ? data.error_message : "401 Authorization Required"
1186
+ error: true,
1187
+ error_code: response.status,
1188
+ error_message: error.message
1024
1189
  };
1025
1190
  }
1026
1191
  }
1027
1192
  else {
1028
- const dataClass = new TransactionsForExchangeResponse(data.data);
1029
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
1030
- success = true;
1031
- return {
1032
- data: dataClass,
1033
- error: data.error,
1034
- error_code: data ? data.error_code : response.status,
1035
- error_message: data ? data.error_message : "401 Authorization Required"
1036
- };
1193
+ data = await response.json();
1037
1194
  }
1195
+ const dataClass = new TransactionsForExchangeResponse(data.data);
1196
+ checkAndModifyResponse(dataClass);
1197
+ success = true;
1198
+ return {
1199
+ data: dataClass,
1200
+ error: data.error,
1201
+ error_code: data ? data.error_code : response.status,
1202
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1203
+ };
1038
1204
  }
1039
1205
  catch (error) {
1040
1206
  success = true;
@@ -1042,12 +1208,14 @@ class XykService {
1042
1208
  data: null,
1043
1209
  error: true,
1044
1210
  error_code: data ? data.error_code : response.status,
1045
- error_message: data ? data.error_message : "401 Authorization Required"
1211
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1046
1212
  };
1047
1213
  }
1048
1214
  }
1049
1215
  }
1050
1216
  /**
1217
+ *
1218
+ * Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
1051
1219
  *
1052
1220
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1053
1221
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -1057,42 +1225,47 @@ class XykService {
1057
1225
  let success = false;
1058
1226
  let data;
1059
1227
  let response;
1060
- const backoff = new backoff_1.ExponentialBackoff();
1228
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1061
1229
  while (!success) {
1062
1230
  try {
1063
1231
  const urlParams = new URLSearchParams();
1064
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
1232
+ let startTime;
1233
+ if (this.debug) {
1234
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1235
+ }
1236
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
1065
1237
  headers: {
1066
1238
  "Authorization": `Bearer ${this.apiKey}`,
1067
- "X-Requested-With": Client_1.userAgent
1239
+ "X-Requested-With": userAgent
1068
1240
  }
1069
- });
1070
- data = await response.json();
1071
- if (data.error && data.error_code === 429) {
1241
+ }));
1242
+ debugOutput(response.url, response.status, startTime);
1243
+ if (response.status === 429) {
1072
1244
  try {
1073
- await backoff.backOff();
1245
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1074
1246
  }
1075
1247
  catch (error) {
1076
1248
  success = true;
1077
1249
  return {
1078
1250
  data: null,
1079
- error: data.error,
1080
- error_code: data ? data.error_code : response.status,
1081
- error_message: data ? data.error_message : "401 Authorization Required"
1251
+ error: true,
1252
+ error_code: response.status,
1253
+ error_message: error.message
1082
1254
  };
1083
1255
  }
1084
1256
  }
1085
1257
  else {
1086
- const dataClass = new EcosystemChartDataResponse(data.data);
1087
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
1088
- success = true;
1089
- return {
1090
- data: dataClass,
1091
- error: data.error,
1092
- error_code: data ? data.error_code : response.status,
1093
- error_message: data ? data.error_message : "401 Authorization Required"
1094
- };
1258
+ data = await response.json();
1095
1259
  }
1260
+ const dataClass = new EcosystemChartDataResponse(data.data);
1261
+ checkAndModifyResponse(dataClass);
1262
+ success = true;
1263
+ return {
1264
+ data: dataClass,
1265
+ error: data.error,
1266
+ error_code: data ? data.error_code : response.status,
1267
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1268
+ };
1096
1269
  }
1097
1270
  catch (error) {
1098
1271
  success = true;
@@ -1100,12 +1273,14 @@ class XykService {
1100
1273
  data: null,
1101
1274
  error: true,
1102
1275
  error_code: data ? data.error_code : response.status,
1103
- error_message: data ? data.error_message : "401 Authorization Required"
1276
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1104
1277
  };
1105
1278
  }
1106
1279
  }
1107
1280
  }
1108
1281
  /**
1282
+ *
1283
+ * Commonly used to ping the health of xy=k endpoints to get the synced block height per chain.
1109
1284
  *
1110
1285
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
1111
1286
  * @param {string} dexName - The DEX name eg: `uniswap_v2`.
@@ -1115,42 +1290,47 @@ class XykService {
1115
1290
  let success = false;
1116
1291
  let data;
1117
1292
  let response;
1118
- const backoff = new backoff_1.ExponentialBackoff();
1293
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1119
1294
  while (!success) {
1120
1295
  try {
1121
1296
  const urlParams = new URLSearchParams();
1122
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
1297
+ let startTime;
1298
+ if (this.debug) {
1299
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1300
+ }
1301
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
1123
1302
  headers: {
1124
1303
  "Authorization": `Bearer ${this.apiKey}`,
1125
- "X-Requested-With": Client_1.userAgent
1304
+ "X-Requested-With": userAgent
1126
1305
  }
1127
- });
1128
- data = await response.json();
1129
- if (data.error && data.error_code === 429) {
1306
+ }));
1307
+ debugOutput(response.url, response.status, startTime);
1308
+ if (response.status === 429) {
1130
1309
  try {
1131
- await backoff.backOff();
1310
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1132
1311
  }
1133
1312
  catch (error) {
1134
1313
  success = true;
1135
1314
  return {
1136
1315
  data: null,
1137
- error: data.error,
1138
- error_code: data ? data.error_code : response.status,
1139
- error_message: data ? data.error_message : "401 Authorization Required"
1316
+ error: true,
1317
+ error_code: response.status,
1318
+ error_message: error.message
1140
1319
  };
1141
1320
  }
1142
1321
  }
1143
1322
  else {
1144
- const dataClass = new HealthDataResponse(data.data);
1145
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
1146
- success = true;
1147
- return {
1148
- data: dataClass,
1149
- error: data.error,
1150
- error_code: data ? data.error_code : response.status,
1151
- error_message: data ? data.error_message : "401 Authorization Required"
1152
- };
1323
+ data = await response.json();
1153
1324
  }
1325
+ const dataClass = new HealthDataResponse(data.data);
1326
+ checkAndModifyResponse(dataClass);
1327
+ success = true;
1328
+ return {
1329
+ data: dataClass,
1330
+ error: data.error,
1331
+ error_code: data ? data.error_code : response.status,
1332
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1333
+ };
1154
1334
  }
1155
1335
  catch (error) {
1156
1336
  success = true;
@@ -1158,11 +1338,10 @@ class XykService {
1158
1338
  data: null,
1159
1339
  error: true,
1160
1340
  error_code: data ? data.error_code : response.status,
1161
- error_message: data ? data.error_message : "401 Authorization Required"
1341
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1162
1342
  };
1163
1343
  }
1164
1344
  }
1165
1345
  }
1166
1346
  }
1167
- exports.XykService = XykService;
1168
1347
  //# sourceMappingURL=XykService.js.map