@covalenthq/client-sdk 0.7.2 → 0.7.4

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 (39) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/index.js +285 -13
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/CovalentClient.d.ts +2 -2
  5. package/dist/cjs/services/TransactionService.d.ts +45 -0
  6. package/dist/cjs/services/XykService.d.ts +51 -10
  7. package/dist/cjs/util/Chains.d.ts +19 -1
  8. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +18 -0
  9. package/dist/cjs/util/types/XykServiceTypes.d.ts +51 -10
  10. package/dist/es/index.js +285 -13
  11. package/dist/es/index.js.map +1 -1
  12. package/dist/es/services/CovalentClient.d.ts +2 -2
  13. package/dist/es/services/TransactionService.d.ts +45 -0
  14. package/dist/es/services/XykService.d.ts +51 -10
  15. package/dist/es/util/Chains.d.ts +19 -1
  16. package/dist/es/util/types/TransactionServiceTypes.d.ts +18 -0
  17. package/dist/es/util/types/XykServiceTypes.d.ts +51 -10
  18. package/dist/esm/index.js +285 -13
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/services/CovalentClient.d.ts +2 -2
  21. package/dist/esm/services/TransactionService.d.ts +45 -0
  22. package/dist/esm/services/XykService.d.ts +51 -10
  23. package/dist/esm/util/Chains.d.ts +19 -1
  24. package/dist/esm/util/types/TransactionServiceTypes.d.ts +18 -0
  25. package/dist/esm/util/types/XykServiceTypes.d.ts +51 -10
  26. package/dist/services/CovalentClient.d.ts +2 -2
  27. package/dist/services/CovalentClient.js +1 -1
  28. package/dist/services/TransactionService.d.ts +45 -0
  29. package/dist/services/TransactionService.js +236 -2
  30. package/dist/services/TransactionService.js.map +1 -1
  31. package/dist/services/XykService.d.ts +51 -10
  32. package/dist/services/XykService.js +30 -10
  33. package/dist/services/XykService.js.map +1 -1
  34. package/dist/util/Chains.d.ts +19 -1
  35. package/dist/util/Chains.js +18 -0
  36. package/dist/util/Chains.js.map +1 -1
  37. package/dist/util/types/TransactionServiceTypes.d.ts +18 -0
  38. package/dist/util/types/XykServiceTypes.d.ts +51 -10
  39. package/package.json +1 -1
package/dist/esm/index.js CHANGED
@@ -4787,6 +4787,155 @@ class TransactionsResponse {
4787
4787
  }
4788
4788
  }
4789
4789
  }
4790
+ class TransactionsTimeBucketResponse {
4791
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4792
+ this._debug = _debug;
4793
+ this._apiKey = _apiKey;
4794
+ this._threadCount = _threadCount;
4795
+ this._urlParams = _urlParams;
4796
+ this.address = data.address;
4797
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4798
+ this.quote_currency = data.quote_currency;
4799
+ this.chain_id = data.chain_id;
4800
+ this.chain_name = data.chain_name;
4801
+ this.complete = data.complete;
4802
+ this.current_bucket = data.current_bucket;
4803
+ this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4804
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4805
+ }
4806
+ async prev() {
4807
+ let success = false;
4808
+ let data;
4809
+ let response;
4810
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4811
+ const LIMIT = pLimit$1(this._threadCount);
4812
+ while (!success) {
4813
+ try {
4814
+ let startTime;
4815
+ if (this._debug) {
4816
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4817
+ }
4818
+ if (this.links.prev === null) {
4819
+ success = true;
4820
+ return {
4821
+ data: null,
4822
+ error: true,
4823
+ error_code: 400,
4824
+ error_message: "Invalid URL: URL link cannot be null"
4825
+ };
4826
+ }
4827
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4828
+ headers: {
4829
+ "Authorization": `Bearer ${this._apiKey}`,
4830
+ "X-Requested-With": userAgent
4831
+ }
4832
+ }));
4833
+ debugOutput(response.url, response.status ?? 429, startTime);
4834
+ if (response.status === null || response.status === 429) {
4835
+ try {
4836
+ data = await LIMIT(() => backoff.backOff(response.url));
4837
+ }
4838
+ catch (error) {
4839
+ success = true;
4840
+ return {
4841
+ data: null,
4842
+ error: true,
4843
+ error_code: response.status ?? 429,
4844
+ error_message: error.message
4845
+ };
4846
+ }
4847
+ }
4848
+ else {
4849
+ data = await response.json();
4850
+ }
4851
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4852
+ checkAndModifyResponse(dataClass);
4853
+ success = true;
4854
+ return {
4855
+ data: dataClass,
4856
+ error: data.error,
4857
+ error_code: data ? data.error_code : response.status,
4858
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4859
+ };
4860
+ }
4861
+ catch (error) {
4862
+ success = true;
4863
+ return {
4864
+ data: null,
4865
+ error: true,
4866
+ error_code: data ? data.error_code : response.status,
4867
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4868
+ };
4869
+ }
4870
+ }
4871
+ }
4872
+ async next() {
4873
+ let success = false;
4874
+ let data;
4875
+ let response;
4876
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4877
+ const LIMIT = pLimit$1(this._threadCount);
4878
+ while (!success) {
4879
+ try {
4880
+ let startTime;
4881
+ if (this._debug) {
4882
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4883
+ }
4884
+ if (this.links.next === null) {
4885
+ success = true;
4886
+ return {
4887
+ data: null,
4888
+ error: true,
4889
+ error_code: 400,
4890
+ error_message: "Invalid URL: URL link cannot be null"
4891
+ };
4892
+ }
4893
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4894
+ headers: {
4895
+ "Authorization": `Bearer ${this._apiKey}`,
4896
+ "X-Requested-With": userAgent
4897
+ }
4898
+ }));
4899
+ debugOutput(response.url, response.status ?? 429, startTime);
4900
+ if (response.status === null || response.status === 429) {
4901
+ try {
4902
+ data = await LIMIT(() => backoff.backOff(response.url));
4903
+ }
4904
+ catch (error) {
4905
+ success = true;
4906
+ return {
4907
+ data: null,
4908
+ error: true,
4909
+ error_code: response.status ?? 429,
4910
+ error_message: error.message
4911
+ };
4912
+ }
4913
+ }
4914
+ else {
4915
+ data = await response.json();
4916
+ }
4917
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4918
+ checkAndModifyResponse(dataClass);
4919
+ success = true;
4920
+ return {
4921
+ data: dataClass,
4922
+ error: data.error,
4923
+ error_code: data ? data.error_code : response.status,
4924
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4925
+ };
4926
+ }
4927
+ catch (error) {
4928
+ success = true;
4929
+ return {
4930
+ data: null,
4931
+ error: true,
4932
+ error_code: data ? data.error_code : response.status,
4933
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4934
+ };
4935
+ }
4936
+ }
4937
+ }
4938
+ }
4790
4939
  /**
4791
4940
  * Transactions APIs
4792
4941
  *
@@ -5291,12 +5440,12 @@ class TransactionService {
5291
5440
  if (this.debug) {
5292
5441
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5293
5442
  }
5294
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
5443
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
5295
5444
  headers: {
5296
5445
  "Authorization": `Bearer ${this.apiKey}`,
5297
5446
  "X-Requested-With": userAgent
5298
5447
  }
5299
- });
5448
+ }));
5300
5449
  debugOutput(response.url, response.status ?? 429, startTime);
5301
5450
  if (response.status === null || response.status === 429) {
5302
5451
  try {
@@ -5336,6 +5485,91 @@ class TransactionService {
5336
5485
  }
5337
5486
  }
5338
5487
  }
5488
+ /**
5489
+ *
5490
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
5491
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
5492
+ * @param {number} timeBucket - The 0-indexed 15-minute time bucket. E.g. 27 Feb 2023 05:23 GMT = 1677475383 (Unix time). 1677475383/900=1863861 timeBucket.
5493
+ * @param {GetTimeBucketTransactionsForAddressQueryParamOpts} queryParamOpts
5494
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
5495
+ * - `noLogs`: Omit log events.
5496
+ * - `withSafe`: Include safe details.
5497
+ *
5498
+ */
5499
+ async getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, queryParamOpts) {
5500
+ let success = false;
5501
+ let data;
5502
+ let response;
5503
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
5504
+ while (!success) {
5505
+ try {
5506
+ const urlParams = new URLSearchParams();
5507
+ if (!this.is_key_valid) {
5508
+ return {
5509
+ data: null,
5510
+ error: true,
5511
+ error_code: 401,
5512
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5513
+ };
5514
+ }
5515
+ if (queryParamOpts?.quoteCurrency !== undefined) {
5516
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
5517
+ }
5518
+ if (queryParamOpts?.noLogs !== undefined) {
5519
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
5520
+ }
5521
+ if (queryParamOpts?.withSafe !== undefined) {
5522
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
5523
+ }
5524
+ let startTime;
5525
+ if (this.debug) {
5526
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
5527
+ }
5528
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
5529
+ headers: {
5530
+ "Authorization": `Bearer ${this.apiKey}`,
5531
+ "X-Requested-With": userAgent
5532
+ }
5533
+ }));
5534
+ debugOutput(response.url, response.status ?? 429, startTime);
5535
+ if (response.status === null || response.status === 429) {
5536
+ try {
5537
+ data = await this.LIMIT(() => backoff.backOff(response.url));
5538
+ }
5539
+ catch (error) {
5540
+ success = true;
5541
+ return {
5542
+ data: null,
5543
+ error: true,
5544
+ error_code: response.status ?? 429,
5545
+ error_message: error.message
5546
+ };
5547
+ }
5548
+ }
5549
+ else {
5550
+ data = await response.json();
5551
+ }
5552
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
5553
+ checkAndModifyResponse(dataClass);
5554
+ success = true;
5555
+ return {
5556
+ data: dataClass,
5557
+ error: data.error,
5558
+ error_code: data ? data.error_code : response.status,
5559
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5560
+ };
5561
+ }
5562
+ catch (error) {
5563
+ success = true;
5564
+ return {
5565
+ data: null,
5566
+ error: true,
5567
+ error_code: data ? data.error_code : response.status,
5568
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
5569
+ };
5570
+ }
5571
+ }
5572
+ }
5339
5573
  }
5340
5574
 
5341
5575
  class PoolResponse {
@@ -5356,6 +5590,10 @@ class Pool {
5356
5590
  this.fee_24h_quote = data.fee_24h_quote;
5357
5591
  this.total_supply = data.total_supply && data.total_supply !== null ? BigInt(data.total_supply) : null;
5358
5592
  this.quote_rate = data.quote_rate;
5593
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
5594
+ this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
5595
+ this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
5596
+ this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
5359
5597
  this.chain_name = data.chain_name;
5360
5598
  this.chain_id = data.chain_id;
5361
5599
  this.dex_name = data.dex_name;
@@ -5402,6 +5640,8 @@ class SupportedDex {
5402
5640
  this.chain_id = data.chain_id;
5403
5641
  this.chain_name = data.chain_name;
5404
5642
  this.dex_name = data.dex_name;
5643
+ this.display_name = data.display_name;
5644
+ this.logo_url = data.logo_url;
5405
5645
  this.factory_contract_address = data.factory_contract_address;
5406
5646
  this.router_contract_addresses = data.router_contract_addresses;
5407
5647
  this.swap_fee = data.swap_fee;
@@ -5435,6 +5675,10 @@ class PoolWithTimeseries {
5435
5675
  this.dex_name = data.dex_name;
5436
5676
  this.volume_7d_quote = data.volume_7d_quote;
5437
5677
  this.annualized_fee = data.annualized_fee;
5678
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
5679
+ this.pretty_volume_24h_quote = data.pretty_volume_24h_quote;
5680
+ this.pretty_fee_24h_quote = data.pretty_fee_24h_quote;
5681
+ this.pretty_volume_7d_quote = data.pretty_volume_7d_quote;
5438
5682
  this.token_0_reserve_quote = data.token_0_reserve_quote;
5439
5683
  this.token_1_reserve_quote = data.token_1_reserve_quote;
5440
5684
  this.token_0 = data.token_0 && data.token_0 !== null ? new Token(data.token_0) : null;
@@ -5453,11 +5697,12 @@ class VolumeTimeseries {
5453
5697
  this.chain_id = data.chain_id;
5454
5698
  this.dt = data.dt;
5455
5699
  this.exchange = data.exchange;
5456
- this.sum_amount_0_in = data.sum_amount_0_in;
5457
- this.sum_amount_0_out = data.sum_amount_0_out;
5458
- this.sum_amount_1_in = data.sum_amount_1_in;
5459
- this.sum_amount_1_out = data.sum_amount_1_out;
5700
+ this.sum_amount0in = data.sum_amount0in;
5701
+ this.sum_amount0out = data.sum_amount0out;
5702
+ this.sum_amount1in = data.sum_amount1in;
5703
+ this.sum_amount1out = data.sum_amount1out;
5460
5704
  this.volume_quote = data.volume_quote;
5705
+ this.pretty_volume_quote = data.pretty_volume_quote;
5461
5706
  this.token_0_quote_rate = data.token_0_quote_rate;
5462
5707
  this.token_1_quote_rate = data.token_1_quote_rate;
5463
5708
  this.swap_count_24 = data.swap_count_24;
@@ -5472,6 +5717,7 @@ class LiquidityTimeseries {
5472
5717
  this.r0_c = data.r0_c;
5473
5718
  this.r1_c = data.r1_c;
5474
5719
  this.liquidity_quote = data.liquidity_quote;
5720
+ this.pretty_liquidity_quote = data.pretty_liquidity_quote;
5475
5721
  this.token_0_quote_rate = data.token_0_quote_rate;
5476
5722
  this.token_1_quote_rate = data.token_1_quote_rate;
5477
5723
  }
@@ -5482,13 +5728,15 @@ class PriceTimeseries {
5482
5728
  this.chain_id = data.chain_id;
5483
5729
  this.dt = data.dt;
5484
5730
  this.exchange = data.exchange;
5485
- this.price_of_token_0_in_token_1 = data.price_of_token_0_in_token_1;
5486
- this.price_of_token_0_in_token_1_description = data.price_of_token_0_in_token_1_description;
5487
- this.price_of_token_1_in_token_0 = data.price_of_token_1_in_token_0;
5488
- this.price_of_token_1_in_token_0_description = data.price_of_token_1_in_token_0_description;
5731
+ this.price_of_token0_in_token1 = data.price_of_token0_in_token1;
5732
+ this.pretty_price_of_token0_in_token1 = data.pretty_price_of_token0_in_token1;
5733
+ this.price_of_token0_in_token1_description = data.price_of_token0_in_token1_description;
5734
+ this.price_of_token1_in_token0 = data.price_of_token1_in_token0;
5735
+ this.pretty_price_of_token1_in_token0 = data.pretty_price_of_token1_in_token0;
5736
+ this.price_of_token1_in_token0_description = data.price_of_token1_in_token0_description;
5489
5737
  this.quote_currency = data.quote_currency;
5490
- this.price_of_token_0_in_quote_currency = data.price_of_token_0_in_quote_currency;
5491
- this.price_of_token_1_in_quote_currency = data.price_of_token_1_in_quote_currency;
5738
+ this.price_of_token0_in_quote_currency = data.price_of_token0_in_quote_currency;
5739
+ this.price_of_token1_in_quote_currency = data.price_of_token1_in_quote_currency;
5492
5740
  }
5493
5741
  }
5494
5742
  class PoolsDexDataResponse {
@@ -5593,6 +5841,11 @@ class TokenV2Volume {
5593
5841
  this.contract_decimals = data.contract_decimals;
5594
5842
  this.swap_count_24h = data.swap_count_24h;
5595
5843
  this.quote_rate = data.quote_rate;
5844
+ this.quote_rate_24h = data.quote_rate_24h;
5845
+ this.pretty_quote_rate = data.pretty_quote_rate;
5846
+ this.pretty_quote_rate_24h = data.pretty_quote_rate_24h;
5847
+ this.pretty_total_liquidity_quote = data.pretty_total_liquidity_quote;
5848
+ this.pretty_total_volume_24h_quote = data.pretty_total_volume_24h_quote;
5596
5849
  this.total_liquidity_quote = data.total_liquidity_quote;
5597
5850
  this.total_volume_24h_quote = data.total_volume_24h_quote;
5598
5851
  }
@@ -5637,6 +5890,7 @@ class ExchangeTransaction {
5637
5890
  this.from_address = data.from_address;
5638
5891
  this.sender_address = data.sender_address;
5639
5892
  this.total_quote = data.total_quote;
5893
+ this.pretty_total_quote = data.pretty_total_quote;
5640
5894
  this.token_0_quote_rate = data.token_0_quote_rate;
5641
5895
  this.token_1_quote_rate = data.token_1_quote_rate;
5642
5896
  this.token_0 = data.token_0 && data.token_0 !== null ? new PoolToken(data.token_0) : null;
@@ -6793,7 +7047,7 @@ class XykService {
6793
7047
  }
6794
7048
  }
6795
7049
 
6796
- const userAgent = "com.covalenthq.sdk.typescript/0.7.2";
7050
+ const userAgent = "com.covalenthq.sdk.typescript/0.7.4";
6797
7051
  /**
6798
7052
  * CovalentClient Class
6799
7053
  */
@@ -7109,6 +7363,24 @@ var Chains;
7109
7363
  Chains["BNB_OPBNB_MAINNET"] = "bnb-opbnb-mainnet";
7110
7364
  Chains["TELOS_MAINNET"] = "telos-mainnet";
7111
7365
  Chains["TELOS_TESTNET"] = "telos-testnet";
7366
+ Chains["AVALANCHE_HUBBLE_EXCHANGE_TESTNET"] = "avalanche-hubble-exchange-testnet";
7367
+ Chains["AVALANCHE_MIHO_TESTNET"] = "avalanche-miho-testnet";
7368
+ Chains["AVALANCHE_BULLETIN_TESTNET"] = "avalanche-bulletin-testnet";
7369
+ Chains["AVALANCHE_KIWI_TESTNET"] = "avalanche-kiwi-testnet";
7370
+ Chains["AVALANCHE_HERO_TESTNET"] = "avalanche-hero-testnet";
7371
+ Chains["AVALANCHE_AVACLOUD_TESTNET"] = "avalanche-avacloud-testnet";
7372
+ Chains["AVALANCHE_THIRDWEB_TESTNET"] = "avalanche-thirdweb-testnet";
7373
+ Chains["AVALANCHE_MONDRIAN_TESTNET"] = "avalanche-mondrian-testnet";
7374
+ Chains["AVALANCHE_CONDUIT_TESTNET"] = "avalanche-conduit-testnet";
7375
+ Chains["AVALANCHE_NMAC_TESTNET"] = "avalanche-nmac-testnet";
7376
+ Chains["AVALANCHE_ORDERLY_TESTNET"] = "avalanche-orderly-testnet";
7377
+ Chains["AVALANCHE_AMPLIFY_TESTNET"] = "avalanche-amplify-testnet";
7378
+ Chains["AVALANCHE_MIRAI_TESTNET"] = "avalanche-mirai-testnet";
7379
+ Chains["AVALANCHE_WAGMI_TESTNET"] = "avalanche-wagmi-testnet";
7380
+ Chains["AVALANCHE_PLAYA3ULL_TESTNET"] = "avalanche-playa3ull-testnet";
7381
+ Chains["AVALANCHE_BEAM_MAINNET"] = "avalanche-beam-mainnet";
7382
+ Chains["SCROLL_MAINNET"] = "scroll-mainnet";
7383
+ Chains["ETH_HOLESKY"] = "eth-holesky";
7112
7384
  })(Chains || (Chains = {}));
7113
7385
 
7114
7386
  export { Chains, Client, CovalentClient, calculatePrettyBalance, prettifyCurrency };