@covalenthq/client-sdk 0.2.9 → 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.
Files changed (116) hide show
  1. package/README.md +64 -14
  2. package/dist/cjs/index.d.ts +9 -0
  3. package/dist/cjs/index.js +4619 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/services/BalanceService.d.ts +443 -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 +484 -0
  9. package/dist/cjs/services/PricingService.d.ts +88 -0
  10. package/dist/cjs/services/SecurityService.d.ts +96 -0
  11. package/dist/cjs/services/TransactionService.d.ts +440 -0
  12. package/dist/cjs/services/XykService.d.ts +682 -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 +284 -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 +221 -0
  19. package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
  20. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
  21. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -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 +4616 -0
  25. package/dist/es/index.js.map +1 -0
  26. package/dist/es/services/BalanceService.d.ts +443 -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 +484 -0
  30. package/dist/es/services/PricingService.d.ts +88 -0
  31. package/dist/es/services/SecurityService.d.ts +96 -0
  32. package/dist/es/services/TransactionService.d.ts +440 -0
  33. package/dist/es/services/XykService.d.ts +682 -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 +284 -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 +221 -0
  40. package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
  41. package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
  42. package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -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 +4616 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/services/BalanceService.d.ts +443 -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 +484 -0
  51. package/dist/esm/services/PricingService.d.ts +88 -0
  52. package/dist/esm/services/SecurityService.d.ts +96 -0
  53. package/dist/esm/services/TransactionService.d.ts +440 -0
  54. package/dist/esm/services/XykService.d.ts +682 -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 +284 -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 +221 -0
  61. package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
  62. package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
  63. package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -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 +49 -11
  69. package/dist/services/BalanceService.js +110 -81
  70. package/dist/services/BalanceService.js.map +1 -1
  71. package/dist/services/BaseService.d.ts +46 -10
  72. package/dist/services/BaseService.js +193 -145
  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 +52 -22
  78. package/dist/services/NftService.js +236 -235
  79. package/dist/services/NftService.js.map +1 -1
  80. package/dist/services/PricingService.d.ts +8 -3
  81. package/dist/services/PricingService.js +43 -37
  82. package/dist/services/PricingService.js.map +1 -1
  83. package/dist/services/SecurityService.d.ts +9 -3
  84. package/dist/services/SecurityService.js +38 -31
  85. package/dist/services/SecurityService.js.map +1 -1
  86. package/dist/services/TransactionService.d.ts +41 -9
  87. package/dist/services/TransactionService.js +133 -100
  88. package/dist/services/TransactionService.js.map +1 -1
  89. package/dist/services/XykService.d.ts +81 -19
  90. package/dist/services/XykService.js +451 -278
  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 +25 -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 +10 -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 +1 -0
  108. package/dist/util/types/SecurityServiceTypes.js +1 -2
  109. package/dist/util/types/TransactionServiceTypes.d.ts +14 -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,4 +1,4 @@
1
- import { Chains, Quotes, Response } from "./Client";
1
+ import { Chain, Quote, Response } from "./CovalentClient";
2
2
  declare class BalancesResponse {
3
3
  /** * The requested address. */
4
4
  address: string;
@@ -37,12 +37,20 @@ declare class BalanceItem {
37
37
  is_spam: boolean;
38
38
  /** * The asset balance. Use `contract_decimals` to scale this balance for display purposes. */
39
39
  balance: bigint | null;
40
+ /** * The 24h asset balance. Use `contract_decimals` to scale this balance for display purposes. */
41
+ balance_24h: bigint | null;
40
42
  /** * The exchange rate for the requested quote currency. */
41
43
  quote_rate: number;
44
+ /** * The 24h exchange rate for the requested quote currency. */
45
+ quote_rate_24h: number;
42
46
  /** * The current balance converted to fiat in `quote-currency`. */
43
47
  quote: number;
48
+ /** * The 24h balance converted to fiat in `quote-currency`. */
49
+ quote_24h: number;
44
50
  /** * A prettier version of the quote for rendering purposes. */
45
51
  pretty_quote: string;
52
+ /** * A prettier version of the 24h quote for rendering purposes. */
53
+ pretty_quote_24h: string;
46
54
  /** * NFT-specific data. */
47
55
  nft_data: NftData[];
48
56
  constructor(data: BalanceItem);
@@ -123,6 +131,7 @@ declare class HoldingItem {
123
131
  declare class OhlcItem {
124
132
  /** * The asset balance. Use `contract_decimals` to scale this balance for display purposes. */
125
133
  balance: bigint | null;
134
+ /** * The current balance converted to fiat in `quote-currency`. */
126
135
  quote: number;
127
136
  /** * A prettier version of the quote for rendering purposes. */
128
137
  pretty_quote: string;
@@ -137,10 +146,15 @@ declare class BlockTransactionWithContractTransfers {
137
146
  tx_hash: string;
138
147
  /** * The offset is the position of the tx in the block. */
139
148
  tx_offset: number;
149
+ /** * Whether or not transaction is successful. */
140
150
  successful: boolean;
151
+ /** * The sender's wallet address. */
141
152
  from_address: string;
153
+ /** * The label of `from` address. */
142
154
  from_address_label: string;
155
+ /** * The receiver's wallet address. */
143
156
  to_address: string;
157
+ /** * The label of `to` address. */
144
158
  to_address_label: string;
145
159
  /** * The value attached to this tx. */
146
160
  value: bigint | null;
@@ -149,7 +163,9 @@ declare class BlockTransactionWithContractTransfers {
149
163
  /** * A prettier version of the quote for rendering purposes. */
150
164
  pretty_value_quote: string;
151
165
  gas_offered: number;
166
+ /** * The gas spent for this tx. */
152
167
  gas_spent: number;
168
+ /** * The gas price at the time of this tx. */
153
169
  gas_price: number;
154
170
  /** * The transaction's gas_price * gas_spent, denoted in wei. */
155
171
  fees_paid: bigint | null;
@@ -167,9 +183,13 @@ declare class TokenTransferItem {
167
183
  block_signed_at: Date;
168
184
  /** * The requested transaction hash. */
169
185
  tx_hash: string;
186
+ /** * The sender's wallet address. */
170
187
  from_address: string;
188
+ /** * The label of `from` address. */
171
189
  from_address_label: string;
190
+ /** * The receiver's wallet address. */
172
191
  to_address: string;
192
+ /** * The label of `to` address. */
173
193
  to_address_label: string;
174
194
  /** * Use contract decimals to format the token balance for display purposes - divide the balance by `10^{contract_decimals}`. */
175
195
  contract_decimals: number;
@@ -181,6 +201,7 @@ declare class TokenTransferItem {
181
201
  contract_address: string;
182
202
  /** * The contract logo URL. */
183
203
  logo_url: string;
204
+ /** * Categorizes token transactions as either `transfer-in` or `transfer-out`, indicating whether tokens are being received or sent from an account. */
184
205
  transfer_type: string;
185
206
  /** * The delta attached to this transfer. */
186
207
  delta: bigint | null;
@@ -188,14 +209,18 @@ declare class TokenTransferItem {
188
209
  balance: bigint | null;
189
210
  /** * The exchange rate for the requested quote currency. */
190
211
  quote_rate: number;
212
+ /** * The current delta converted to fiat in `quote-currency`. */
191
213
  delta_quote: number;
192
214
  /** * A prettier version of the quote for rendering purposes. */
193
215
  pretty_delta_quote: string;
216
+ /** * The current balance converted to fiat in `quote-currency`. */
194
217
  balance_quote: number;
218
+ /** * Additional details on which transfer events were invoked. Defaults to `true`. */
195
219
  method_calls: MethodCallsForTransfers[];
196
220
  constructor(data: TokenTransferItem);
197
221
  }
198
222
  declare class MethodCallsForTransfers {
223
+ /** * The address of the sender. */
199
224
  sender_address: string;
200
225
  method: string;
201
226
  constructor(data: MethodCallsForTransfers);
@@ -277,7 +302,7 @@ declare class HistoricalBalanceItem {
277
302
  }
278
303
  export interface GetTokenBalancesForWalletAddressQueryParamOpts {
279
304
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
280
- quoteCurrency?: Quotes;
305
+ quoteCurrency?: Quote;
281
306
  /** * If `true`, NFTs will be included in the response. */
282
307
  nft?: boolean;
283
308
  /** * If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times. */
@@ -289,13 +314,13 @@ export interface GetTokenBalancesForWalletAddressQueryParamOpts {
289
314
  }
290
315
  export interface GetHistoricalPortfolioForWalletAddressQueryParamOpts {
291
316
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
292
- quoteCurrency?: Quotes;
317
+ quoteCurrency?: Quote;
293
318
  /** * The number of days to return data for. Defaults to 30 days. */
294
319
  days?: number;
295
320
  }
296
321
  export interface GetErc20TransfersForWalletAddressQueryParamOpts {
297
322
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
298
- quoteCurrency?: Quotes;
323
+ quoteCurrency?: Quote;
299
324
  /** * The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically. */
300
325
  contractAddress?: string;
301
326
  /** * The block height to start from, defaults to `0`. */
@@ -317,7 +342,7 @@ export interface GetTokenHoldersV2ForTokenAddressQueryParamOpts {
317
342
  }
318
343
  export interface GetHistoricalTokenBalancesForWalletAddressQueryParamOpts {
319
344
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
320
- quoteCurrency?: Quotes;
345
+ quoteCurrency?: Quote;
321
346
  /** * If `true`, NFTs will be included in the response. */
322
347
  nft?: boolean;
323
348
  /** * If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times. */
@@ -337,8 +362,13 @@ export interface GetHistoricalTokenBalancesForWalletAddressQueryParamOpts {
337
362
  */
338
363
  export declare class BalanceService {
339
364
  private apiKey;
340
- constructor(apiKey: string);
365
+ private debug;
366
+ private threadCount;
367
+ private LIMIT;
368
+ constructor(apiKey: string, debug?: boolean, threadCount?: number);
341
369
  /**
370
+ *
371
+ * Commonly used to fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
342
372
  *
343
373
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
344
374
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -350,8 +380,10 @@ export declare class BalanceService {
350
380
  * - `noNftAssetMetadata`: If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
351
381
  *
352
382
  */
353
- getTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<BalancesResponse>>;
383
+ getTokenBalancesForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<BalancesResponse>>;
354
384
  /**
385
+ *
386
+ * Commonly used to render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
355
387
  *
356
388
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
357
389
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -360,8 +392,10 @@ export declare class BalanceService {
360
392
  * - `days`: The number of days to return data for. Defaults to 30 days.
361
393
  *
362
394
  */
363
- getHistoricalPortfolioForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetHistoricalPortfolioForWalletAddressQueryParamOpts): Promise<Response<PortfolioResponse>>;
395
+ getHistoricalPortfolioForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetHistoricalPortfolioForWalletAddressQueryParamOpts): Promise<Response<PortfolioResponse>>;
364
396
  /**
397
+ *
398
+ * Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
365
399
  *
366
400
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
367
401
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -374,8 +408,10 @@ export declare class BalanceService {
374
408
  * - `pageNumber`: 0-indexed page number to begin pagination.
375
409
  *
376
410
  */
377
- getErc20TransfersForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetErc20TransfersForWalletAddressQueryParamOpts): AsyncIterable<BlockTransactionWithContractTransfers>;
411
+ getErc20TransfersForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetErc20TransfersForWalletAddressQueryParamOpts): AsyncIterable<BlockTransactionWithContractTransfers>;
378
412
  /**
413
+ *
414
+ * Commonly used to get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to `latest`). Useful for building pie charts of token holders.
379
415
  *
380
416
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
381
417
  * @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -385,8 +421,10 @@ export declare class BalanceService {
385
421
  * - `pageNumber`: 0-indexed page number to begin pagination.
386
422
  *
387
423
  */
388
- getTokenHoldersV2ForTokenAddress(chainName: Chains, tokenAddress: string, queryParamOpts?: GetTokenHoldersV2ForTokenAddressQueryParamOpts): AsyncIterable<TokenHolder>;
424
+ getTokenHoldersV2ForTokenAddress(chainName: Chain, tokenAddress: string, queryParamOpts?: GetTokenHoldersV2ForTokenAddressQueryParamOpts): AsyncIterable<TokenHolder>;
389
425
  /**
426
+ *
427
+ * Commonly used to fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
390
428
  *
391
429
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
392
430
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -400,6 +438,6 @@ export declare class BalanceService {
400
438
  * - `date`: Ending date to define a block range (YYYY-MM-DD). Omitting this parameter defaults to the current date.
401
439
  *
402
440
  */
403
- getHistoricalTokenBalancesForWalletAddress(chainName: Chains, walletAddress: string, queryParamOpts?: GetHistoricalTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<HistoricalBalancesResponse>>;
441
+ getHistoricalTokenBalancesForWalletAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetHistoricalTokenBalancesForWalletAddressQueryParamOpts): Promise<Response<HistoricalBalancesResponse>>;
404
442
  }
405
443
  export {};
@@ -1,17 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BalanceService = 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, paginateEndpoint } from "../util/ApiHelpers";
3
+ import { parseISO } from "date-fns";
4
+ import { ExponentialBackoff } from "../util/backoff";
5
+ import pLimit from "p-limit";
8
6
  class BalancesResponse {
9
7
  constructor(data) {
10
8
  this.address = data.address;
11
9
  this.chain_id = data.chain_id;
12
10
  this.chain_name = data.chain_name;
13
11
  this.quote_currency = data.quote_currency;
14
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
12
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
15
13
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new BalanceItem(itemData)) : null;
16
14
  }
17
15
  }
@@ -23,14 +21,18 @@ class BalanceItem {
23
21
  this.contract_address = data.contract_address;
24
22
  this.supports_erc = data.supports_erc;
25
23
  this.logo_url = data.logo_url;
26
- this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? (0, date_fns_1.parseISO)(data.last_transferred_at.toString()) : null;
24
+ this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? parseISO(data.last_transferred_at.toString()) : null;
27
25
  this.native_token = data.native_token;
28
26
  this.type = data.type;
29
27
  this.is_spam = data.is_spam;
30
28
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
29
+ this.balance_24h = data.balance_24h && data.balance_24h !== null ? BigInt(data.balance_24h) : null;
31
30
  this.quote_rate = data.quote_rate;
31
+ this.quote_rate_24h = data.quote_rate_24h;
32
32
  this.quote = data.quote;
33
+ this.quote_24h = data.quote_24h;
33
34
  this.pretty_quote = data.pretty_quote;
35
+ this.pretty_quote_24h = data.pretty_quote_24h;
34
36
  this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
35
37
  }
36
38
  }
@@ -70,7 +72,7 @@ class NftCollectionAttribute {
70
72
  class PortfolioResponse {
71
73
  constructor(data) {
72
74
  this.address = data.address;
73
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
75
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
74
76
  this.quote_currency = data.quote_currency;
75
77
  this.chain_id = data.chain_id;
76
78
  this.chain_name = data.chain_name;
@@ -90,7 +92,7 @@ class PortfolioItem {
90
92
  class HoldingItem {
91
93
  constructor(data) {
92
94
  this.quote_rate = data.quote_rate;
93
- this.timestamp = data.timestamp && data.timestamp !== null ? (0, date_fns_1.parseISO)(data.timestamp.toString()) : null;
95
+ this.timestamp = data.timestamp && data.timestamp !== null ? parseISO(data.timestamp.toString()) : null;
94
96
  this.close = data.close && data.close !== null ? new OhlcItem(data.close) : null;
95
97
  this.high = data.high && data.high !== null ? new OhlcItem(data.high) : null;
96
98
  this.low = data.low && data.low !== null ? new OhlcItem(data.low) : null;
@@ -107,7 +109,7 @@ class OhlcItem {
107
109
  class Erc20TransfersResponse {
108
110
  constructor(data) {
109
111
  this.address = data.address;
110
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
112
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
111
113
  this.quote_currency = data.quote_currency;
112
114
  this.chain_id = data.chain_id;
113
115
  this.chain_name = data.chain_name;
@@ -117,7 +119,7 @@ class Erc20TransfersResponse {
117
119
  }
118
120
  class BlockTransactionWithContractTransfers {
119
121
  constructor(data) {
120
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
122
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
121
123
  this.block_height = data.block_height;
122
124
  this.tx_hash = data.tx_hash;
123
125
  this.tx_offset = data.tx_offset;
@@ -149,7 +151,7 @@ class Pagination {
149
151
  }
150
152
  class TokenTransferItem {
151
153
  constructor(data) {
152
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
154
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
153
155
  this.tx_hash = data.tx_hash;
154
156
  this.from_address = data.from_address;
155
157
  this.from_address_label = data.from_address_label;
@@ -178,7 +180,7 @@ class MethodCallsForTransfers {
178
180
  }
179
181
  class TokenHoldersResponse {
180
182
  constructor(data) {
181
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
183
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
182
184
  this.chain_id = data.chain_id;
183
185
  this.chain_name = data.chain_name;
184
186
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new TokenHolder(itemData)) : null;
@@ -202,7 +204,7 @@ class TokenHolder {
202
204
  class HistoricalBalancesResponse {
203
205
  constructor(data) {
204
206
  this.address = data.address;
205
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
207
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
206
208
  this.quote_currency = data.quote_currency;
207
209
  this.chain_id = data.chain_id;
208
210
  this.chain_name = data.chain_name;
@@ -219,7 +221,7 @@ class HistoricalBalanceItem {
219
221
  this.logo_url = data.logo_url;
220
222
  this.block_height = data.block_height;
221
223
  this.last_transferred_block_height = data.last_transferred_block_height;
222
- this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? (0, date_fns_1.parseISO)(data.last_transferred_at.toString()) : null;
224
+ this.last_transferred_at = data.last_transferred_at && data.last_transferred_at !== null ? parseISO(data.last_transferred_at.toString()) : null;
223
225
  this.native_token = data.native_token;
224
226
  this.type = data.type;
225
227
  this.is_spam = data.is_spam;
@@ -234,11 +236,16 @@ class HistoricalBalanceItem {
234
236
  * Balances APIs
235
237
  *
236
238
  */
237
- class BalanceService {
238
- constructor(apiKey) {
239
+ export class BalanceService {
240
+ constructor(apiKey, debug = false, threadCount = 3) {
239
241
  this.apiKey = apiKey;
242
+ this.debug = debug;
243
+ this.threadCount = threadCount;
244
+ this.LIMIT = pLimit(this.threadCount);
240
245
  }
241
246
  /**
247
+ *
248
+ * Commonly used to fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
242
249
  *
243
250
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
244
251
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -254,7 +261,7 @@ class BalanceService {
254
261
  let success = false;
255
262
  let data;
256
263
  let response;
257
- const backoff = new backoff_1.ExponentialBackoff();
264
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
258
265
  while (!success) {
259
266
  try {
260
267
  const urlParams = new URLSearchParams();
@@ -273,38 +280,43 @@ class BalanceService {
273
280
  if (queryParamOpts?.noNftAssetMetadata !== undefined) {
274
281
  urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
275
282
  }
276
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
283
+ let startTime;
284
+ if (this.debug) {
285
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
286
+ }
287
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_v2/?${urlParams}`, {
277
288
  headers: {
278
289
  "Authorization": `Bearer ${this.apiKey}`,
279
- "X-Requested-With": Client_1.userAgent
290
+ "X-Requested-With": userAgent
280
291
  }
281
- });
282
- data = await response.json();
283
- if (data.error && data.error_code === 429) {
292
+ }));
293
+ debugOutput(response.url, response.status, startTime);
294
+ if (response.status === 429) {
284
295
  try {
285
- await backoff.backOff();
296
+ data = await this.LIMIT(() => backoff.backOff(response.url));
286
297
  }
287
298
  catch (error) {
288
299
  success = true;
289
300
  return {
290
301
  data: null,
291
- error: data.error,
292
- error_code: data ? data.error_code : response.status,
293
- error_message: data ? data.error_message : "401 Authorization Required"
302
+ error: true,
303
+ error_code: response.status,
304
+ error_message: error.message
294
305
  };
295
306
  }
296
307
  }
297
308
  else {
298
- const dataClass = new BalancesResponse(data.data);
299
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
300
- success = true;
301
- return {
302
- data: dataClass,
303
- error: data.error,
304
- error_code: data ? data.error_code : response.status,
305
- error_message: data ? data.error_message : "401 Authorization Required"
306
- };
309
+ data = await response.json();
307
310
  }
311
+ const dataClass = new BalancesResponse(data.data);
312
+ checkAndModifyResponse(dataClass);
313
+ success = true;
314
+ return {
315
+ data: dataClass,
316
+ error: data.error,
317
+ error_code: data ? data.error_code : response.status,
318
+ error_message: data ? data.error_message : "401 Authorization Required"
319
+ };
308
320
  }
309
321
  catch (error) {
310
322
  success = true;
@@ -318,6 +330,8 @@ class BalanceService {
318
330
  }
319
331
  }
320
332
  /**
333
+ *
334
+ * Commonly used to render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
321
335
  *
322
336
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
323
337
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -330,7 +344,7 @@ class BalanceService {
330
344
  let success = false;
331
345
  let data;
332
346
  let response;
333
- const backoff = new backoff_1.ExponentialBackoff();
347
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
334
348
  while (!success) {
335
349
  try {
336
350
  const urlParams = new URLSearchParams();
@@ -340,38 +354,43 @@ class BalanceService {
340
354
  if (queryParamOpts?.days !== undefined) {
341
355
  urlParams.append("days", queryParamOpts?.days.toString());
342
356
  }
343
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
357
+ let startTime;
358
+ if (this.debug) {
359
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
360
+ }
361
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/portfolio_v2/?${urlParams}`, {
344
362
  headers: {
345
363
  "Authorization": `Bearer ${this.apiKey}`,
346
- "X-Requested-With": Client_1.userAgent
364
+ "X-Requested-With": userAgent
347
365
  }
348
- });
349
- data = await response.json();
350
- if (data.error && data.error_code === 429) {
366
+ }));
367
+ debugOutput(response.url, response.status, startTime);
368
+ if (response.status === 429) {
351
369
  try {
352
- await backoff.backOff();
370
+ data = await this.LIMIT(() => backoff.backOff(response.url));
353
371
  }
354
372
  catch (error) {
355
373
  success = true;
356
374
  return {
357
375
  data: null,
358
- error: data.error,
359
- error_code: data ? data.error_code : response.status,
360
- error_message: data ? data.error_message : "401 Authorization Required"
376
+ error: true,
377
+ error_code: response.status,
378
+ error_message: error.message
361
379
  };
362
380
  }
363
381
  }
364
382
  else {
365
- const dataClass = new PortfolioResponse(data.data);
366
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
367
- success = true;
368
- return {
369
- data: dataClass,
370
- error: data.error,
371
- error_code: data ? data.error_code : response.status,
372
- error_message: data ? data.error_message : "401 Authorization Required"
373
- };
383
+ data = await response.json();
374
384
  }
385
+ const dataClass = new PortfolioResponse(data.data);
386
+ checkAndModifyResponse(dataClass);
387
+ success = true;
388
+ return {
389
+ data: dataClass,
390
+ error: data.error,
391
+ error_code: data ? data.error_code : response.status,
392
+ error_message: data ? data.error_message : "401 Authorization Required"
393
+ };
375
394
  }
376
395
  catch (error) {
377
396
  success = true;
@@ -385,6 +404,8 @@ class BalanceService {
385
404
  }
386
405
  }
387
406
  /**
407
+ *
408
+ * Commonly used to render the transfer-in and transfer-out of a token along with historical prices from an address.
388
409
  *
389
410
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
390
411
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -421,18 +442,20 @@ class BalanceService {
421
442
  if (queryParamOpts?.pageNumber !== undefined) {
422
443
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
423
444
  }
424
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers)) {
445
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transfers_v2/`, this.apiKey, urlParams, BlockTransactionWithContractTransfers, this.debug, this.threadCount)) {
425
446
  yield res;
426
447
  }
427
448
  success = true;
428
449
  }
429
450
  catch (error) {
430
451
  success = true;
431
- return res;
452
+ throw new Error(error.message);
432
453
  }
433
454
  }
434
455
  }
435
456
  /**
457
+ *
458
+ * Commonly used to get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to `latest`). Useful for building pie charts of token holders.
436
459
  *
437
460
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
438
461
  * @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -457,18 +480,20 @@ class BalanceService {
457
480
  if (queryParamOpts?.pageNumber !== undefined) {
458
481
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
459
482
  }
460
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder)) {
483
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/tokens/${tokenAddress}/token_holders_v2/`, this.apiKey, urlParams, TokenHolder, this.debug, this.threadCount)) {
461
484
  yield res;
462
485
  }
463
486
  success = true;
464
487
  }
465
488
  catch (error) {
466
489
  success = true;
467
- return res;
490
+ throw new Error(error.message);
468
491
  }
469
492
  }
470
493
  }
471
494
  /**
495
+ *
496
+ * Commonly used to fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
472
497
  *
473
498
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
474
499
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -486,7 +511,7 @@ class BalanceService {
486
511
  let success = false;
487
512
  let data;
488
513
  let response;
489
- const backoff = new backoff_1.ExponentialBackoff();
514
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
490
515
  while (!success) {
491
516
  try {
492
517
  const urlParams = new URLSearchParams();
@@ -511,38 +536,43 @@ class BalanceService {
511
536
  if (queryParamOpts?.date !== undefined) {
512
537
  urlParams.append("date", queryParamOpts?.date.toString());
513
538
  }
514
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
539
+ let startTime;
540
+ if (this.debug) {
541
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
542
+ }
543
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/historical_balances/?${urlParams}`, {
515
544
  headers: {
516
545
  "Authorization": `Bearer ${this.apiKey}`,
517
- "X-Requested-With": Client_1.userAgent
546
+ "X-Requested-With": userAgent
518
547
  }
519
- });
520
- data = await response.json();
521
- if (data.error && data.error_code === 429) {
548
+ }));
549
+ debugOutput(response.url, response.status, startTime);
550
+ if (response.status === 429) {
522
551
  try {
523
- await backoff.backOff();
552
+ data = await this.LIMIT(() => backoff.backOff(response.url));
524
553
  }
525
554
  catch (error) {
526
555
  success = true;
527
556
  return {
528
557
  data: null,
529
- error: data.error,
530
- error_code: data ? data.error_code : response.status,
531
- error_message: data ? data.error_message : "401 Authorization Required"
558
+ error: true,
559
+ error_code: response.status,
560
+ error_message: error.message
532
561
  };
533
562
  }
534
563
  }
535
564
  else {
536
- const dataClass = new HistoricalBalancesResponse(data.data);
537
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
538
- success = true;
539
- return {
540
- data: dataClass,
541
- error: data.error,
542
- error_code: data ? data.error_code : response.status,
543
- error_message: data ? data.error_message : "401 Authorization Required"
544
- };
565
+ data = await response.json();
545
566
  }
567
+ const dataClass = new HistoricalBalancesResponse(data.data);
568
+ checkAndModifyResponse(dataClass);
569
+ success = true;
570
+ return {
571
+ data: dataClass,
572
+ error: data.error,
573
+ error_code: data ? data.error_code : response.status,
574
+ error_message: data ? data.error_message : "401 Authorization Required"
575
+ };
546
576
  }
547
577
  catch (error) {
548
578
  success = true;
@@ -556,5 +586,4 @@ class BalanceService {
556
586
  }
557
587
  }
558
588
  }
559
- exports.BalanceService = BalanceService;
560
589
  //# sourceMappingURL=BalanceService.js.map