@covalenthq/client-sdk 0.2.8 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -14
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +4619 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/BalanceService.d.ts +443 -0
- package/dist/cjs/services/BaseService.d.ts +357 -0
- package/dist/cjs/services/CovalentClient.d.ts +65 -0
- package/dist/cjs/services/NftService.d.ts +484 -0
- package/dist/cjs/services/PricingService.d.ts +88 -0
- package/dist/cjs/services/SecurityService.d.ts +96 -0
- package/dist/cjs/services/TransactionService.d.ts +440 -0
- package/dist/cjs/services/XykService.d.ts +682 -0
- package/dist/cjs/util/ApiHelpers.d.ts +5 -0
- package/dist/cjs/util/backoff.d.ts +11 -0
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
- package/dist/cjs/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/es/index.d.ts +9 -0
- package/dist/es/index.js +4616 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/services/BalanceService.d.ts +443 -0
- package/dist/es/services/BaseService.d.ts +357 -0
- package/dist/es/services/CovalentClient.d.ts +65 -0
- package/dist/es/services/NftService.d.ts +484 -0
- package/dist/es/services/PricingService.d.ts +88 -0
- package/dist/es/services/SecurityService.d.ts +96 -0
- package/dist/es/services/TransactionService.d.ts +440 -0
- package/dist/es/services/XykService.d.ts +682 -0
- package/dist/es/util/ApiHelpers.d.ts +5 -0
- package/dist/es/util/backoff.d.ts +11 -0
- package/dist/es/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/es/util/types/GenericTypes.d.ts +96 -0
- package/dist/es/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +4616 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/services/BalanceService.d.ts +443 -0
- package/dist/esm/services/BaseService.d.ts +357 -0
- package/dist/esm/services/CovalentClient.d.ts +65 -0
- package/dist/esm/services/NftService.d.ts +484 -0
- package/dist/esm/services/PricingService.d.ts +88 -0
- package/dist/esm/services/SecurityService.d.ts +96 -0
- package/dist/esm/services/TransactionService.d.ts +440 -0
- package/dist/esm/services/XykService.d.ts +682 -0
- package/dist/esm/util/ApiHelpers.d.ts +5 -0
- package/dist/esm/util/backoff.d.ts +11 -0
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +284 -0
- package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
- package/dist/esm/util/types/GenericTypes.d.ts +96 -0
- package/dist/esm/util/types/NftServiceTypes.d.ts +221 -0
- package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
- package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -0
- package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -27
- package/dist/index.js.map +1 -1
- package/dist/services/BalanceService.d.ts +49 -11
- package/dist/services/BalanceService.js +110 -81
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/BaseService.d.ts +46 -10
- package/dist/services/BaseService.js +193 -145
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +65 -0
- package/dist/services/CovalentClient.js +44 -0
- package/dist/services/CovalentClient.js.map +1 -0
- package/dist/services/NftService.d.ts +52 -22
- package/dist/services/NftService.js +236 -235
- package/dist/services/NftService.js.map +1 -1
- package/dist/services/PricingService.d.ts +8 -3
- package/dist/services/PricingService.js +43 -37
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/SecurityService.d.ts +9 -3
- package/dist/services/SecurityService.js +38 -31
- package/dist/services/SecurityService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +41 -9
- package/dist/services/TransactionService.js +133 -100
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/XykService.d.ts +81 -19
- package/dist/services/XykService.js +451 -278
- package/dist/services/XykService.js.map +1 -1
- package/dist/util/ApiHelpers.d.ts +2 -1
- package/dist/util/ApiHelpers.js +57 -36
- package/dist/util/ApiHelpers.js.map +1 -1
- package/dist/util/backoff.d.ts +5 -3
- package/dist/util/backoff.js +35 -13
- package/dist/util/backoff.js.map +1 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +25 -0
- package/dist/util/types/BalanceServiceTypes.js +1 -2
- package/dist/util/types/BaseServiceTypes.d.ts +8 -0
- package/dist/util/types/BaseServiceTypes.js +1 -2
- package/dist/util/types/GenericTypes.d.ts +21 -0
- package/dist/util/types/GenericTypes.js +1 -2
- package/dist/util/types/NftServiceTypes.d.ts +10 -2
- package/dist/util/types/NftServiceTypes.js +1 -2
- package/dist/util/types/PricingServiceTypes.d.ts +1 -14
- package/dist/util/types/PricingServiceTypes.js +1 -2
- package/dist/util/types/SecurityServiceTypes.d.ts +1 -0
- package/dist/util/types/SecurityServiceTypes.js +1 -2
- package/dist/util/types/TransactionServiceTypes.d.ts +15 -17
- package/dist/util/types/TransactionServiceTypes.js +1 -2
- package/dist/util/types/XykServiceTypes.d.ts +20 -6
- package/dist/util/types/XykServiceTypes.js +1 -2
- package/package.json +19 -4
- package/dist/services/Client.d.ts +0 -29
- package/dist/services/Client.js +0 -30
- package/dist/services/Client.js.map +0 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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 ?
|
|
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
|
|
422
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
413
423
|
while (!success) {
|
|
414
424
|
try {
|
|
415
425
|
const urlParams = new URLSearchParams();
|
|
416
|
-
|
|
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":
|
|
433
|
+
"X-Requested-With": userAgent
|
|
420
434
|
}
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
if (
|
|
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:
|
|
432
|
-
error_code:
|
|
433
|
-
error_message:
|
|
445
|
+
error: true,
|
|
446
|
+
error_code: response.status,
|
|
447
|
+
error_message: error.message
|
|
434
448
|
};
|
|
435
449
|
}
|
|
436
450
|
}
|
|
437
451
|
else {
|
|
438
|
-
|
|
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 : "401 Authorization Required"
|
|
462
|
+
};
|
|
448
463
|
}
|
|
449
464
|
catch (error) {
|
|
450
465
|
success = true;
|
|
@@ -458,6 +473,8 @@ class XykService {
|
|
|
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
|
|
487
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
471
488
|
while (!success) {
|
|
472
489
|
try {
|
|
473
490
|
const urlParams = new URLSearchParams();
|
|
474
|
-
|
|
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":
|
|
498
|
+
"X-Requested-With": userAgent
|
|
478
499
|
}
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
if (
|
|
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:
|
|
490
|
-
error_code:
|
|
491
|
-
error_message:
|
|
510
|
+
error: true,
|
|
511
|
+
error_code: response.status,
|
|
512
|
+
error_message: error.message
|
|
492
513
|
};
|
|
493
514
|
}
|
|
494
515
|
}
|
|
495
516
|
else {
|
|
496
|
-
|
|
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 : "401 Authorization Required"
|
|
527
|
+
};
|
|
506
528
|
}
|
|
507
529
|
catch (error) {
|
|
508
530
|
success = true;
|
|
@@ -516,6 +538,8 @@ class XykService {
|
|
|
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
|
|
553
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
530
554
|
while (!success) {
|
|
531
555
|
try {
|
|
532
556
|
const urlParams = new URLSearchParams();
|
|
533
|
-
|
|
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":
|
|
564
|
+
"X-Requested-With": userAgent
|
|
537
565
|
}
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
if (
|
|
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:
|
|
549
|
-
error_code:
|
|
550
|
-
error_message:
|
|
576
|
+
error: true,
|
|
577
|
+
error_code: response.status,
|
|
578
|
+
error_message: error.message
|
|
551
579
|
};
|
|
552
580
|
}
|
|
553
581
|
}
|
|
554
582
|
else {
|
|
555
|
-
|
|
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 : "401 Authorization Required"
|
|
593
|
+
};
|
|
565
594
|
}
|
|
566
595
|
catch (error) {
|
|
567
596
|
success = true;
|
|
@@ -575,56 +604,64 @@ class XykService {
|
|
|
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
|
|
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
|
-
|
|
628
|
+
let startTime;
|
|
629
|
+
if (this.debug) {
|
|
630
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
631
|
+
}
|
|
632
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/tokens/address/${tokenAddress}/pools/page/${page}/?${urlParams}`, {
|
|
597
633
|
headers: {
|
|
598
634
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
599
|
-
"X-Requested-With":
|
|
635
|
+
"X-Requested-With": userAgent
|
|
600
636
|
}
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
if (
|
|
637
|
+
}));
|
|
638
|
+
debugOutput(response.url, response.status, startTime);
|
|
639
|
+
if (response.status === 429) {
|
|
604
640
|
try {
|
|
605
|
-
await backoff.backOff();
|
|
641
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
606
642
|
}
|
|
607
643
|
catch (error) {
|
|
608
644
|
success = true;
|
|
609
645
|
return {
|
|
610
646
|
data: null,
|
|
611
|
-
error:
|
|
612
|
-
error_code:
|
|
613
|
-
error_message:
|
|
647
|
+
error: true,
|
|
648
|
+
error_code: response.status,
|
|
649
|
+
error_message: error.message
|
|
614
650
|
};
|
|
615
651
|
}
|
|
616
652
|
}
|
|
617
653
|
else {
|
|
618
|
-
|
|
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
|
-
};
|
|
654
|
+
data = await response.json();
|
|
627
655
|
}
|
|
656
|
+
const dataClass = new PoolsDexDataResponse(data.data);
|
|
657
|
+
checkAndModifyResponse(dataClass);
|
|
658
|
+
success = true;
|
|
659
|
+
return {
|
|
660
|
+
data: dataClass,
|
|
661
|
+
error: data.error,
|
|
662
|
+
error_code: data ? data.error_code : response.status,
|
|
663
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
664
|
+
};
|
|
628
665
|
}
|
|
629
666
|
catch (error) {
|
|
630
667
|
success = true;
|
|
@@ -638,6 +675,8 @@ class XykService {
|
|
|
638
675
|
}
|
|
639
676
|
}
|
|
640
677
|
/**
|
|
678
|
+
*
|
|
679
|
+
* Commonly used to return balance of a wallet/contract address on a specific DEX.
|
|
641
680
|
*
|
|
642
681
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
643
682
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -648,42 +687,122 @@ class XykService {
|
|
|
648
687
|
let success = false;
|
|
649
688
|
let data;
|
|
650
689
|
let response;
|
|
651
|
-
const backoff = new
|
|
690
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
691
|
+
while (!success) {
|
|
692
|
+
try {
|
|
693
|
+
const urlParams = new URLSearchParams();
|
|
694
|
+
let startTime;
|
|
695
|
+
if (this.debug) {
|
|
696
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
697
|
+
}
|
|
698
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/balances/?${urlParams}`, {
|
|
699
|
+
headers: {
|
|
700
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
701
|
+
"X-Requested-With": userAgent
|
|
702
|
+
}
|
|
703
|
+
}));
|
|
704
|
+
debugOutput(response.url, response.status, startTime);
|
|
705
|
+
if (response.status === 429) {
|
|
706
|
+
try {
|
|
707
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
708
|
+
}
|
|
709
|
+
catch (error) {
|
|
710
|
+
success = true;
|
|
711
|
+
return {
|
|
712
|
+
data: null,
|
|
713
|
+
error: true,
|
|
714
|
+
error_code: response.status,
|
|
715
|
+
error_message: error.message
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
data = await response.json();
|
|
721
|
+
}
|
|
722
|
+
const dataClass = new AddressExchangeBalancesResponse(data.data);
|
|
723
|
+
checkAndModifyResponse(dataClass);
|
|
724
|
+
success = true;
|
|
725
|
+
return {
|
|
726
|
+
data: dataClass,
|
|
727
|
+
error: data.error,
|
|
728
|
+
error_code: data ? data.error_code : response.status,
|
|
729
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
success = true;
|
|
734
|
+
return {
|
|
735
|
+
data: null,
|
|
736
|
+
error: true,
|
|
737
|
+
error_code: data ? data.error_code : response.status,
|
|
738
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
*
|
|
745
|
+
* 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.
|
|
746
|
+
*
|
|
747
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
748
|
+
* @param {string} walletAddress - The account address.
|
|
749
|
+
* @param {number} page - The requested 0-indexed page number.
|
|
750
|
+
* @param {GetPoolsForWalletAddressQueryParamOpts} queryParamOpts
|
|
751
|
+
* - `tokenAddress`: The token contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
752
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
753
|
+
*
|
|
754
|
+
*/
|
|
755
|
+
async getPoolsForWalletAddress(chainName, walletAddress, page, queryParamOpts) {
|
|
756
|
+
let success = false;
|
|
757
|
+
let data;
|
|
758
|
+
let response;
|
|
759
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
652
760
|
while (!success) {
|
|
653
761
|
try {
|
|
654
762
|
const urlParams = new URLSearchParams();
|
|
655
|
-
|
|
763
|
+
if (queryParamOpts?.tokenAddress !== undefined) {
|
|
764
|
+
urlParams.append("token-address", queryParamOpts?.tokenAddress.toString());
|
|
765
|
+
}
|
|
766
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
767
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
768
|
+
}
|
|
769
|
+
let startTime;
|
|
770
|
+
if (this.debug) {
|
|
771
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
772
|
+
}
|
|
773
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/address/${walletAddress}/pools/page/${page}/?${urlParams}`, {
|
|
656
774
|
headers: {
|
|
657
775
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
658
|
-
"X-Requested-With":
|
|
776
|
+
"X-Requested-With": userAgent
|
|
659
777
|
}
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
if (
|
|
778
|
+
}));
|
|
779
|
+
debugOutput(response.url, response.status, startTime);
|
|
780
|
+
if (response.status === 429) {
|
|
663
781
|
try {
|
|
664
|
-
await backoff.backOff();
|
|
782
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
665
783
|
}
|
|
666
784
|
catch (error) {
|
|
667
785
|
success = true;
|
|
668
786
|
return {
|
|
669
787
|
data: null,
|
|
670
|
-
error:
|
|
671
|
-
error_code:
|
|
672
|
-
error_message:
|
|
788
|
+
error: true,
|
|
789
|
+
error_code: response.status,
|
|
790
|
+
error_message: error.message
|
|
673
791
|
};
|
|
674
792
|
}
|
|
675
793
|
}
|
|
676
794
|
else {
|
|
677
|
-
|
|
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
|
-
};
|
|
795
|
+
data = await response.json();
|
|
686
796
|
}
|
|
797
|
+
const dataClass = new PoolsDexDataResponse(data.data);
|
|
798
|
+
checkAndModifyResponse(dataClass);
|
|
799
|
+
success = true;
|
|
800
|
+
return {
|
|
801
|
+
data: dataClass,
|
|
802
|
+
error: data.error,
|
|
803
|
+
error_code: data ? data.error_code : response.status,
|
|
804
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
805
|
+
};
|
|
687
806
|
}
|
|
688
807
|
catch (error) {
|
|
689
808
|
success = true;
|
|
@@ -697,6 +816,8 @@ class XykService {
|
|
|
697
816
|
}
|
|
698
817
|
}
|
|
699
818
|
/**
|
|
819
|
+
*
|
|
820
|
+
* 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
821
|
*
|
|
701
822
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
702
823
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -706,42 +827,47 @@ class XykService {
|
|
|
706
827
|
let success = false;
|
|
707
828
|
let data;
|
|
708
829
|
let response;
|
|
709
|
-
const backoff = new
|
|
830
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
710
831
|
while (!success) {
|
|
711
832
|
try {
|
|
712
833
|
const urlParams = new URLSearchParams();
|
|
713
|
-
|
|
834
|
+
let startTime;
|
|
835
|
+
if (this.debug) {
|
|
836
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
837
|
+
}
|
|
838
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/?${urlParams}`, {
|
|
714
839
|
headers: {
|
|
715
840
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
716
|
-
"X-Requested-With":
|
|
841
|
+
"X-Requested-With": userAgent
|
|
717
842
|
}
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
if (
|
|
843
|
+
}));
|
|
844
|
+
debugOutput(response.url, response.status, startTime);
|
|
845
|
+
if (response.status === 429) {
|
|
721
846
|
try {
|
|
722
|
-
await backoff.backOff();
|
|
847
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
723
848
|
}
|
|
724
849
|
catch (error) {
|
|
725
850
|
success = true;
|
|
726
851
|
return {
|
|
727
852
|
data: null,
|
|
728
|
-
error:
|
|
729
|
-
error_code:
|
|
730
|
-
error_message:
|
|
853
|
+
error: true,
|
|
854
|
+
error_code: response.status,
|
|
855
|
+
error_message: error.message
|
|
731
856
|
};
|
|
732
857
|
}
|
|
733
858
|
}
|
|
734
859
|
else {
|
|
735
|
-
|
|
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
|
-
};
|
|
860
|
+
data = await response.json();
|
|
744
861
|
}
|
|
862
|
+
const dataClass = new NetworkExchangeTokensResponse(data.data);
|
|
863
|
+
checkAndModifyResponse(dataClass);
|
|
864
|
+
success = true;
|
|
865
|
+
return {
|
|
866
|
+
data: dataClass,
|
|
867
|
+
error: data.error,
|
|
868
|
+
error_code: data ? data.error_code : response.status,
|
|
869
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
870
|
+
};
|
|
745
871
|
}
|
|
746
872
|
catch (error) {
|
|
747
873
|
success = true;
|
|
@@ -756,49 +882,55 @@ class XykService {
|
|
|
756
882
|
}
|
|
757
883
|
/**
|
|
758
884
|
*
|
|
759
|
-
|
|
885
|
+
* Commonly used to get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
|
|
886
|
+
*
|
|
760
887
|
*
|
|
761
888
|
*/
|
|
762
889
|
async getSupportedDEXes() {
|
|
763
890
|
let success = false;
|
|
764
891
|
let data;
|
|
765
892
|
let response;
|
|
766
|
-
const backoff = new
|
|
893
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
767
894
|
while (!success) {
|
|
768
895
|
try {
|
|
769
896
|
const urlParams = new URLSearchParams();
|
|
770
|
-
|
|
897
|
+
let startTime;
|
|
898
|
+
if (this.debug) {
|
|
899
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
900
|
+
}
|
|
901
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/xy=k/supported_dexes/?${urlParams}`, {
|
|
771
902
|
headers: {
|
|
772
903
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
773
|
-
"X-Requested-With":
|
|
904
|
+
"X-Requested-With": userAgent
|
|
774
905
|
}
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
if (
|
|
906
|
+
}));
|
|
907
|
+
debugOutput(response.url, response.status, startTime);
|
|
908
|
+
if (response.status === 429) {
|
|
778
909
|
try {
|
|
779
|
-
await backoff.backOff();
|
|
910
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
780
911
|
}
|
|
781
912
|
catch (error) {
|
|
782
913
|
success = true;
|
|
783
914
|
return {
|
|
784
915
|
data: null,
|
|
785
|
-
error:
|
|
786
|
-
error_code:
|
|
787
|
-
error_message:
|
|
916
|
+
error: true,
|
|
917
|
+
error_code: response.status,
|
|
918
|
+
error_message: error.message
|
|
788
919
|
};
|
|
789
920
|
}
|
|
790
921
|
}
|
|
791
922
|
else {
|
|
792
|
-
|
|
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
|
-
};
|
|
923
|
+
data = await response.json();
|
|
801
924
|
}
|
|
925
|
+
const dataClass = new SupportedDexesResponse(data.data);
|
|
926
|
+
checkAndModifyResponse(dataClass);
|
|
927
|
+
success = true;
|
|
928
|
+
return {
|
|
929
|
+
data: dataClass,
|
|
930
|
+
error: data.error,
|
|
931
|
+
error_code: data ? data.error_code : response.status,
|
|
932
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
933
|
+
};
|
|
802
934
|
}
|
|
803
935
|
catch (error) {
|
|
804
936
|
success = true;
|
|
@@ -812,6 +944,8 @@ class XykService {
|
|
|
812
944
|
}
|
|
813
945
|
}
|
|
814
946
|
/**
|
|
947
|
+
*
|
|
948
|
+
* Commonly used to get historical daily swap count for a single network exchange token.
|
|
815
949
|
*
|
|
816
950
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
817
951
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -822,42 +956,47 @@ class XykService {
|
|
|
822
956
|
let success = false;
|
|
823
957
|
let data;
|
|
824
958
|
let response;
|
|
825
|
-
const backoff = new
|
|
959
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
826
960
|
while (!success) {
|
|
827
961
|
try {
|
|
828
962
|
const urlParams = new URLSearchParams();
|
|
829
|
-
|
|
963
|
+
let startTime;
|
|
964
|
+
if (this.debug) {
|
|
965
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
966
|
+
}
|
|
967
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/?${urlParams}`, {
|
|
830
968
|
headers: {
|
|
831
969
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
832
|
-
"X-Requested-With":
|
|
970
|
+
"X-Requested-With": userAgent
|
|
833
971
|
}
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
if (
|
|
972
|
+
}));
|
|
973
|
+
debugOutput(response.url, response.status, startTime);
|
|
974
|
+
if (response.status === 429) {
|
|
837
975
|
try {
|
|
838
|
-
await backoff.backOff();
|
|
976
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
839
977
|
}
|
|
840
978
|
catch (error) {
|
|
841
979
|
success = true;
|
|
842
980
|
return {
|
|
843
981
|
data: null,
|
|
844
|
-
error:
|
|
845
|
-
error_code:
|
|
846
|
-
error_message:
|
|
982
|
+
error: true,
|
|
983
|
+
error_code: response.status,
|
|
984
|
+
error_message: error.message
|
|
847
985
|
};
|
|
848
986
|
}
|
|
849
987
|
}
|
|
850
988
|
else {
|
|
851
|
-
|
|
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
|
-
};
|
|
989
|
+
data = await response.json();
|
|
860
990
|
}
|
|
991
|
+
const dataClass = new SingleNetworkExchangeTokenResponse(data.data);
|
|
992
|
+
checkAndModifyResponse(dataClass);
|
|
993
|
+
success = true;
|
|
994
|
+
return {
|
|
995
|
+
data: dataClass,
|
|
996
|
+
error: data.error,
|
|
997
|
+
error_code: data ? data.error_code : response.status,
|
|
998
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
999
|
+
};
|
|
861
1000
|
}
|
|
862
1001
|
catch (error) {
|
|
863
1002
|
success = true;
|
|
@@ -871,6 +1010,8 @@ class XykService {
|
|
|
871
1010
|
}
|
|
872
1011
|
}
|
|
873
1012
|
/**
|
|
1013
|
+
*
|
|
1014
|
+
* Commonly used to get all the DEX transactions of a wallet. Useful for building tables of DEX activity segmented by wallet.
|
|
874
1015
|
*
|
|
875
1016
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
876
1017
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -881,42 +1022,47 @@ class XykService {
|
|
|
881
1022
|
let success = false;
|
|
882
1023
|
let data;
|
|
883
1024
|
let response;
|
|
884
|
-
const backoff = new
|
|
1025
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
885
1026
|
while (!success) {
|
|
886
1027
|
try {
|
|
887
1028
|
const urlParams = new URLSearchParams();
|
|
888
|
-
|
|
1029
|
+
let startTime;
|
|
1030
|
+
if (this.debug) {
|
|
1031
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1032
|
+
}
|
|
1033
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/address/${accountAddress}/transactions/?${urlParams}`, {
|
|
889
1034
|
headers: {
|
|
890
1035
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
891
|
-
"X-Requested-With":
|
|
1036
|
+
"X-Requested-With": userAgent
|
|
892
1037
|
}
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
if (
|
|
1038
|
+
}));
|
|
1039
|
+
debugOutput(response.url, response.status, startTime);
|
|
1040
|
+
if (response.status === 429) {
|
|
896
1041
|
try {
|
|
897
|
-
await backoff.backOff();
|
|
1042
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
898
1043
|
}
|
|
899
1044
|
catch (error) {
|
|
900
1045
|
success = true;
|
|
901
1046
|
return {
|
|
902
1047
|
data: null,
|
|
903
|
-
error:
|
|
904
|
-
error_code:
|
|
905
|
-
error_message:
|
|
1048
|
+
error: true,
|
|
1049
|
+
error_code: response.status,
|
|
1050
|
+
error_message: error.message
|
|
906
1051
|
};
|
|
907
1052
|
}
|
|
908
1053
|
}
|
|
909
1054
|
else {
|
|
910
|
-
|
|
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
|
-
};
|
|
1055
|
+
data = await response.json();
|
|
919
1056
|
}
|
|
1057
|
+
const dataClass = new TransactionsForAccountAddressResponse(data.data);
|
|
1058
|
+
checkAndModifyResponse(dataClass);
|
|
1059
|
+
success = true;
|
|
1060
|
+
return {
|
|
1061
|
+
data: dataClass,
|
|
1062
|
+
error: data.error,
|
|
1063
|
+
error_code: data ? data.error_code : response.status,
|
|
1064
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
1065
|
+
};
|
|
920
1066
|
}
|
|
921
1067
|
catch (error) {
|
|
922
1068
|
success = true;
|
|
@@ -930,6 +1076,8 @@ class XykService {
|
|
|
930
1076
|
}
|
|
931
1077
|
}
|
|
932
1078
|
/**
|
|
1079
|
+
*
|
|
1080
|
+
* 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
1081
|
*
|
|
934
1082
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
935
1083
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -940,42 +1088,47 @@ class XykService {
|
|
|
940
1088
|
let success = false;
|
|
941
1089
|
let data;
|
|
942
1090
|
let response;
|
|
943
|
-
const backoff = new
|
|
1091
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
944
1092
|
while (!success) {
|
|
945
1093
|
try {
|
|
946
1094
|
const urlParams = new URLSearchParams();
|
|
947
|
-
|
|
1095
|
+
let startTime;
|
|
1096
|
+
if (this.debug) {
|
|
1097
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1098
|
+
}
|
|
1099
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/tokens/address/${tokenAddress}/transactions/?${urlParams}`, {
|
|
948
1100
|
headers: {
|
|
949
1101
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
950
|
-
"X-Requested-With":
|
|
1102
|
+
"X-Requested-With": userAgent
|
|
951
1103
|
}
|
|
952
|
-
});
|
|
953
|
-
|
|
954
|
-
if (
|
|
1104
|
+
}));
|
|
1105
|
+
debugOutput(response.url, response.status, startTime);
|
|
1106
|
+
if (response.status === 429) {
|
|
955
1107
|
try {
|
|
956
|
-
await backoff.backOff();
|
|
1108
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
957
1109
|
}
|
|
958
1110
|
catch (error) {
|
|
959
1111
|
success = true;
|
|
960
1112
|
return {
|
|
961
1113
|
data: null,
|
|
962
|
-
error:
|
|
963
|
-
error_code:
|
|
964
|
-
error_message:
|
|
1114
|
+
error: true,
|
|
1115
|
+
error_code: response.status,
|
|
1116
|
+
error_message: error.message
|
|
965
1117
|
};
|
|
966
1118
|
}
|
|
967
1119
|
}
|
|
968
1120
|
else {
|
|
969
|
-
|
|
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
|
-
};
|
|
1121
|
+
data = await response.json();
|
|
978
1122
|
}
|
|
1123
|
+
const dataClass = new TransactionsForTokenAddressResponse(data.data);
|
|
1124
|
+
checkAndModifyResponse(dataClass);
|
|
1125
|
+
success = true;
|
|
1126
|
+
return {
|
|
1127
|
+
data: dataClass,
|
|
1128
|
+
error: data.error,
|
|
1129
|
+
error_code: data ? data.error_code : response.status,
|
|
1130
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
1131
|
+
};
|
|
979
1132
|
}
|
|
980
1133
|
catch (error) {
|
|
981
1134
|
success = true;
|
|
@@ -989,6 +1142,8 @@ class XykService {
|
|
|
989
1142
|
}
|
|
990
1143
|
}
|
|
991
1144
|
/**
|
|
1145
|
+
*
|
|
1146
|
+
* 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
1147
|
*
|
|
993
1148
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
994
1149
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -999,42 +1154,47 @@ class XykService {
|
|
|
999
1154
|
let success = false;
|
|
1000
1155
|
let data;
|
|
1001
1156
|
let response;
|
|
1002
|
-
const backoff = new
|
|
1157
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1003
1158
|
while (!success) {
|
|
1004
1159
|
try {
|
|
1005
1160
|
const urlParams = new URLSearchParams();
|
|
1006
|
-
|
|
1161
|
+
let startTime;
|
|
1162
|
+
if (this.debug) {
|
|
1163
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1164
|
+
}
|
|
1165
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/pools/address/${poolAddress}/transactions/?${urlParams}`, {
|
|
1007
1166
|
headers: {
|
|
1008
1167
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1009
|
-
"X-Requested-With":
|
|
1168
|
+
"X-Requested-With": userAgent
|
|
1010
1169
|
}
|
|
1011
|
-
});
|
|
1012
|
-
|
|
1013
|
-
if (
|
|
1170
|
+
}));
|
|
1171
|
+
debugOutput(response.url, response.status, startTime);
|
|
1172
|
+
if (response.status === 429) {
|
|
1014
1173
|
try {
|
|
1015
|
-
await backoff.backOff();
|
|
1174
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1016
1175
|
}
|
|
1017
1176
|
catch (error) {
|
|
1018
1177
|
success = true;
|
|
1019
1178
|
return {
|
|
1020
1179
|
data: null,
|
|
1021
|
-
error:
|
|
1022
|
-
error_code:
|
|
1023
|
-
error_message:
|
|
1180
|
+
error: true,
|
|
1181
|
+
error_code: response.status,
|
|
1182
|
+
error_message: error.message
|
|
1024
1183
|
};
|
|
1025
1184
|
}
|
|
1026
1185
|
}
|
|
1027
1186
|
else {
|
|
1028
|
-
|
|
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
|
-
};
|
|
1187
|
+
data = await response.json();
|
|
1037
1188
|
}
|
|
1189
|
+
const dataClass = new TransactionsForExchangeResponse(data.data);
|
|
1190
|
+
checkAndModifyResponse(dataClass);
|
|
1191
|
+
success = true;
|
|
1192
|
+
return {
|
|
1193
|
+
data: dataClass,
|
|
1194
|
+
error: data.error,
|
|
1195
|
+
error_code: data ? data.error_code : response.status,
|
|
1196
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
1197
|
+
};
|
|
1038
1198
|
}
|
|
1039
1199
|
catch (error) {
|
|
1040
1200
|
success = true;
|
|
@@ -1048,6 +1208,8 @@ class XykService {
|
|
|
1048
1208
|
}
|
|
1049
1209
|
}
|
|
1050
1210
|
/**
|
|
1211
|
+
*
|
|
1212
|
+
* Commonly used to get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
|
|
1051
1213
|
*
|
|
1052
1214
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1053
1215
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -1057,42 +1219,47 @@ class XykService {
|
|
|
1057
1219
|
let success = false;
|
|
1058
1220
|
let data;
|
|
1059
1221
|
let response;
|
|
1060
|
-
const backoff = new
|
|
1222
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1061
1223
|
while (!success) {
|
|
1062
1224
|
try {
|
|
1063
1225
|
const urlParams = new URLSearchParams();
|
|
1064
|
-
|
|
1226
|
+
let startTime;
|
|
1227
|
+
if (this.debug) {
|
|
1228
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1229
|
+
}
|
|
1230
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/ecosystem/?${urlParams}`, {
|
|
1065
1231
|
headers: {
|
|
1066
1232
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1067
|
-
"X-Requested-With":
|
|
1233
|
+
"X-Requested-With": userAgent
|
|
1068
1234
|
}
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1235
|
+
}));
|
|
1236
|
+
debugOutput(response.url, response.status, startTime);
|
|
1237
|
+
if (response.status === 429) {
|
|
1072
1238
|
try {
|
|
1073
|
-
await backoff.backOff();
|
|
1239
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1074
1240
|
}
|
|
1075
1241
|
catch (error) {
|
|
1076
1242
|
success = true;
|
|
1077
1243
|
return {
|
|
1078
1244
|
data: null,
|
|
1079
|
-
error:
|
|
1080
|
-
error_code:
|
|
1081
|
-
error_message:
|
|
1245
|
+
error: true,
|
|
1246
|
+
error_code: response.status,
|
|
1247
|
+
error_message: error.message
|
|
1082
1248
|
};
|
|
1083
1249
|
}
|
|
1084
1250
|
}
|
|
1085
1251
|
else {
|
|
1086
|
-
|
|
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
|
-
};
|
|
1252
|
+
data = await response.json();
|
|
1095
1253
|
}
|
|
1254
|
+
const dataClass = new EcosystemChartDataResponse(data.data);
|
|
1255
|
+
checkAndModifyResponse(dataClass);
|
|
1256
|
+
success = true;
|
|
1257
|
+
return {
|
|
1258
|
+
data: dataClass,
|
|
1259
|
+
error: data.error,
|
|
1260
|
+
error_code: data ? data.error_code : response.status,
|
|
1261
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
1262
|
+
};
|
|
1096
1263
|
}
|
|
1097
1264
|
catch (error) {
|
|
1098
1265
|
success = true;
|
|
@@ -1106,6 +1273,8 @@ class XykService {
|
|
|
1106
1273
|
}
|
|
1107
1274
|
}
|
|
1108
1275
|
/**
|
|
1276
|
+
*
|
|
1277
|
+
* Commonly used to ping the health of xy=k endpoints to get the synced block height per chain.
|
|
1109
1278
|
*
|
|
1110
1279
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1111
1280
|
* @param {string} dexName - The DEX name eg: `uniswap_v2`.
|
|
@@ -1115,42 +1284,47 @@ class XykService {
|
|
|
1115
1284
|
let success = false;
|
|
1116
1285
|
let data;
|
|
1117
1286
|
let response;
|
|
1118
|
-
const backoff = new
|
|
1287
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1119
1288
|
while (!success) {
|
|
1120
1289
|
try {
|
|
1121
1290
|
const urlParams = new URLSearchParams();
|
|
1122
|
-
|
|
1291
|
+
let startTime;
|
|
1292
|
+
if (this.debug) {
|
|
1293
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
1294
|
+
}
|
|
1295
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/xy=k/${dexName}/health/?${urlParams}`, {
|
|
1123
1296
|
headers: {
|
|
1124
1297
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
1125
|
-
"X-Requested-With":
|
|
1298
|
+
"X-Requested-With": userAgent
|
|
1126
1299
|
}
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
if (
|
|
1300
|
+
}));
|
|
1301
|
+
debugOutput(response.url, response.status, startTime);
|
|
1302
|
+
if (response.status === 429) {
|
|
1130
1303
|
try {
|
|
1131
|
-
await backoff.backOff();
|
|
1304
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
1132
1305
|
}
|
|
1133
1306
|
catch (error) {
|
|
1134
1307
|
success = true;
|
|
1135
1308
|
return {
|
|
1136
1309
|
data: null,
|
|
1137
|
-
error:
|
|
1138
|
-
error_code:
|
|
1139
|
-
error_message:
|
|
1310
|
+
error: true,
|
|
1311
|
+
error_code: response.status,
|
|
1312
|
+
error_message: error.message
|
|
1140
1313
|
};
|
|
1141
1314
|
}
|
|
1142
1315
|
}
|
|
1143
1316
|
else {
|
|
1144
|
-
|
|
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
|
-
};
|
|
1317
|
+
data = await response.json();
|
|
1153
1318
|
}
|
|
1319
|
+
const dataClass = new HealthDataResponse(data.data);
|
|
1320
|
+
checkAndModifyResponse(dataClass);
|
|
1321
|
+
success = true;
|
|
1322
|
+
return {
|
|
1323
|
+
data: dataClass,
|
|
1324
|
+
error: data.error,
|
|
1325
|
+
error_code: data ? data.error_code : response.status,
|
|
1326
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
1327
|
+
};
|
|
1154
1328
|
}
|
|
1155
1329
|
catch (error) {
|
|
1156
1330
|
success = true;
|
|
@@ -1164,5 +1338,4 @@ class XykService {
|
|
|
1164
1338
|
}
|
|
1165
1339
|
}
|
|
1166
1340
|
}
|
|
1167
|
-
exports.XykService = XykService;
|
|
1168
1341
|
//# sourceMappingURL=XykService.js.map
|