@covalenthq/client-sdk 2.2.4 → 2.2.6

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/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "2.2.4";
1
+ var version = "2.2.6";
2
2
 
3
3
  const bigIntParser = (val) => {
4
4
  if (val === null || val === undefined) {
@@ -2302,6 +2302,35 @@ class PricingService {
2302
2302
  };
2303
2303
  return await this.execution.execute(endpoint, parseData);
2304
2304
  }
2305
+ /**
2306
+ *
2307
+ * Get the spot token pair prices for a specified pool contract address. Supports pools on Uniswap V2, V3 and their forks.
2308
+ *
2309
+ * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2310
+ * @param {string} contractAddress - The pool contract address.
2311
+ * @param {GetTokenPricesQueryParamOpts} queryParamOpts
2312
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, `GBP`, `BTC` and `ETH`.
2313
+ *
2314
+ */
2315
+ async getPoolSpotPrices(chainName, contractAddress, queryParamOpts) {
2316
+ const endpoint = endpointGenerator(`pricing/spot_prices/${chainName}/pools/${contractAddress}`, [
2317
+ {
2318
+ key: "quote-currency",
2319
+ value: queryParamOpts?.quoteCurrency,
2320
+ },
2321
+ ]);
2322
+ const parseData = (data) => {
2323
+ if (data.data) {
2324
+ data.data.forEach((dataItem) => {
2325
+ dataItem.updated_at = dataItem.updated_at
2326
+ ? new Date(dataItem.updated_at)
2327
+ : null;
2328
+ });
2329
+ }
2330
+ return data;
2331
+ };
2332
+ return await this.execution.execute(endpoint, parseData);
2333
+ }
2305
2334
  }
2306
2335
 
2307
2336
  /**
@@ -2452,6 +2481,119 @@ class TransactionService {
2452
2481
  };
2453
2482
  return await this.execution.execute(endpoint, parseData);
2454
2483
  }
2484
+ /**
2485
+ *
2486
+ * Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
2487
+ *
2488
+ * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2489
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2490
+ * @param {GetTransactionSummaryQueryParamOpts} queryParamOpts
2491
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2492
+ * - `withGas`: Include gas summary details. Additional charge of 1 credit when true. Response times may be impacted for wallets with millions of transactions.
2493
+ *
2494
+ */
2495
+ async getTransactionSummary(chainName, walletAddress, queryParamOpts) {
2496
+ const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_summary`, [
2497
+ {
2498
+ key: "quote-currency",
2499
+ value: queryParamOpts?.quoteCurrency,
2500
+ },
2501
+ {
2502
+ key: "with-gas",
2503
+ value: queryParamOpts?.withGas,
2504
+ },
2505
+ ]);
2506
+ const parseData = (data) => {
2507
+ if (data.data) {
2508
+ data.data.updated_at = data.data.updated_at
2509
+ ? new Date(data.data.updated_at)
2510
+ : null;
2511
+ data.data.items = data.data.items
2512
+ ? data.data.items.map((txsItem) => ({
2513
+ ...txsItem,
2514
+ earliest_transaction: {
2515
+ ...txsItem.earliest_transaction,
2516
+ block_signed_at: txsItem?.earliest_transaction?.block_signed_at
2517
+ ? new Date(txsItem.earliest_transaction.block_signed_at)
2518
+ : null,
2519
+ },
2520
+ latest_transaction: {
2521
+ ...txsItem.latest_transaction,
2522
+ block_signed_at: txsItem?.latest_transaction?.block_signed_at
2523
+ ? new Date(txsItem?.latest_transaction?.block_signed_at)
2524
+ : null,
2525
+ },
2526
+ // ? API vs docs non-consistent
2527
+ // gas_summary: {
2528
+ // ...txsItem.gas_summary,
2529
+ // total_fees_paid: bigIntParser(
2530
+ // txsItem.gas_summary.total_fees_paid
2531
+ // ),
2532
+ // },
2533
+ }))
2534
+ : null;
2535
+ }
2536
+ return data;
2537
+ };
2538
+ return await this.execution.execute(endpoint, parseData);
2539
+ }
2540
+ /**
2541
+ *
2542
+ * Commonly used to fetch and render the earliest transactions involving an address. Frequently seen in wallet applications.
2543
+ *
2544
+ * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2545
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2546
+ * @param {GetEarliestTransactionsForAddressQueryParamOpts} queryParamOpts
2547
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2548
+ * - `noLogs`: Omit log events.
2549
+ *
2550
+ */
2551
+ async getEarliestTransactionsForAddress(chainName, walletAddress, queryParamOpts) {
2552
+ const searchParams = [
2553
+ {
2554
+ key: "quote-currency",
2555
+ value: queryParamOpts?.quoteCurrency,
2556
+ },
2557
+ {
2558
+ key: "no-logs",
2559
+ value: queryParamOpts?.noLogs,
2560
+ },
2561
+ ];
2562
+ const endpoint = endpointGenerator(`${chainName}/bulk/transactions/${walletAddress}`, searchParams);
2563
+ const parseData = (data) => {
2564
+ if (data.data) {
2565
+ data.data.prev = data.data?.links?.prev
2566
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
2567
+ : null;
2568
+ data.data.next = data.data?.links?.next
2569
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
2570
+ : null;
2571
+ data.data.updated_at = data.data.updated_at
2572
+ ? new Date(data.data.updated_at)
2573
+ : null;
2574
+ data.data.items = data.data.items
2575
+ ? data.data.items.map((txItem) => ({
2576
+ ...txItem,
2577
+ value: bigIntParser(txItem.value),
2578
+ fees_paid: bigIntParser(txItem.fees_paid),
2579
+ block_signed_at: txItem.block_signed_at
2580
+ ? new Date(txItem.block_signed_at)
2581
+ : null,
2582
+ log_events: txItem.log_events
2583
+ ? txItem.log_events.map((logItem) => ({
2584
+ ...logItem,
2585
+ block_signed_at: logItem.block_signed_at
2586
+ ? new Date(logItem.block_signed_at)
2587
+ : null,
2588
+ }))
2589
+ : null,
2590
+ }))
2591
+ : null;
2592
+ }
2593
+ return data;
2594
+ };
2595
+ return await this.execution.execute(endpoint, parseData);
2596
+ }
2455
2597
  /**
2456
2598
  *
2457
2599
  * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
@@ -2602,18 +2744,18 @@ class TransactionService {
2602
2744
  return await this.execution.execute(endpoint, parseData);
2603
2745
  }
2604
2746
  /**
2605
- *
2606
- * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
2607
2747
  *
2608
2748
  * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2609
- * @param {number} blockHeight - The requested block height.
2610
- * @param {GetTransactionsForBlockQueryParamOpts} queryParamOpts
2749
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2750
+ * @param {number} page - The requested page, 0-indexed.
2751
+ * @param {getPaginatedTransactionsForAddressQueryParamOpts} queryParamOpts
2611
2752
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2612
2753
  * - `noLogs`: Omit log events.
2754
+ * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
2613
2755
  *
2614
2756
  */
2615
- async getTransactionsForBlock(chainName, blockHeight, queryParamOpts) {
2616
- const endpoint = endpointGenerator(`${chainName}/block/${blockHeight}/transactions_v3`, [
2757
+ async getPaginatedTransactionsForAddress(chainName, walletAddress, page, queryParamOpts) {
2758
+ const searchParams = [
2617
2759
  {
2618
2760
  key: "quote-currency",
2619
2761
  value: queryParamOpts?.quoteCurrency,
@@ -2622,9 +2764,20 @@ class TransactionService {
2622
2764
  key: "no-logs",
2623
2765
  value: queryParamOpts?.noLogs,
2624
2766
  },
2625
- ]);
2767
+ {
2768
+ key: "block-signed-at-asc",
2769
+ value: queryParamOpts?.blockSignedAtAsc,
2770
+ },
2771
+ ];
2772
+ const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3/page/${page}`, searchParams);
2626
2773
  const parseData = (data) => {
2627
2774
  if (data.data) {
2775
+ data.data.prev = data.data?.links?.prev
2776
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
2777
+ : null;
2778
+ data.data.next = data.data?.links?.next
2779
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
2780
+ : null;
2628
2781
  data.data.updated_at = data.data.updated_at
2629
2782
  ? new Date(data.data.updated_at)
2630
2783
  : null;
@@ -2652,54 +2805,54 @@ class TransactionService {
2652
2805
  return await this.execution.execute(endpoint, parseData);
2653
2806
  }
2654
2807
  /**
2655
- *
2656
- * Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
2657
2808
  *
2658
2809
  * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2659
2810
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2660
- * @param {GetTransactionSummaryQueryParamOpts} queryParamOpts
2811
+ * @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.
2812
+ * @param {GetTimeBucketTransactionsForAddressQueryParamOpts} queryParamOpts
2661
2813
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2662
- * - `withGas`: Include gas summary details. Additional charge of 1 credit when true. Response times may be impacted for wallets with millions of transactions.
2814
+ * - `noLogs`: Omit log events.
2663
2815
  *
2664
2816
  */
2665
- async getTransactionSummary(chainName, walletAddress, queryParamOpts) {
2666
- const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_summary`, [
2817
+ async getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, queryParamOpts) {
2818
+ const searchParams = [
2667
2819
  {
2668
2820
  key: "quote-currency",
2669
2821
  value: queryParamOpts?.quoteCurrency,
2670
2822
  },
2671
2823
  {
2672
- key: "with-gas",
2673
- value: queryParamOpts?.withGas,
2824
+ key: "no-logs",
2825
+ value: queryParamOpts?.noLogs,
2674
2826
  },
2675
- ]);
2827
+ ];
2828
+ const endpoint = endpointGenerator(`${chainName}/bulk/transactions/${walletAddress}/${timeBucket}`, searchParams);
2676
2829
  const parseData = (data) => {
2677
2830
  if (data.data) {
2831
+ data.data.prev = data.data?.links?.prev
2832
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
2833
+ : null;
2834
+ data.data.next = data.data?.links?.next
2835
+ ? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
2836
+ : null;
2678
2837
  data.data.updated_at = data.data.updated_at
2679
2838
  ? new Date(data.data.updated_at)
2680
2839
  : null;
2681
2840
  data.data.items = data.data.items
2682
- ? data.data.items.map((txsItem) => ({
2683
- ...txsItem,
2684
- earliest_transaction: {
2685
- ...txsItem.earliest_transaction,
2686
- block_signed_at: txsItem?.earliest_transaction?.block_signed_at
2687
- ? new Date(txsItem.earliest_transaction.block_signed_at)
2688
- : null,
2689
- },
2690
- latest_transaction: {
2691
- ...txsItem.latest_transaction,
2692
- block_signed_at: txsItem?.latest_transaction?.block_signed_at
2693
- ? new Date(txsItem?.latest_transaction?.block_signed_at)
2694
- : null,
2695
- },
2696
- // ? API vs docs non-consistent
2697
- // gas_summary: {
2698
- // ...txsItem.gas_summary,
2699
- // total_fees_paid: bigIntParser(
2700
- // txsItem.gas_summary.total_fees_paid
2701
- // ),
2702
- // },
2841
+ ? data.data.items.map((txItem) => ({
2842
+ ...txItem,
2843
+ value: bigIntParser(txItem.value),
2844
+ fees_paid: bigIntParser(txItem.fees_paid),
2845
+ block_signed_at: txItem.block_signed_at
2846
+ ? new Date(txItem.block_signed_at)
2847
+ : null,
2848
+ log_events: txItem.log_events
2849
+ ? txItem.log_events.map((logItem) => ({
2850
+ ...logItem,
2851
+ block_signed_at: logItem.block_signed_at
2852
+ ? new Date(logItem.block_signed_at)
2853
+ : null,
2854
+ }))
2855
+ : null,
2703
2856
  }))
2704
2857
  : null;
2705
2858
  }
@@ -2708,17 +2861,18 @@ class TransactionService {
2708
2861
  return await this.execution.execute(endpoint, parseData);
2709
2862
  }
2710
2863
  /**
2864
+ *
2865
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
2711
2866
  *
2712
2867
  * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2713
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2868
+ * @param {number} blockHeight - The requested block height.
2714
2869
  * @param {number} page - The requested page, 0-indexed.
2715
- * @param {GetTransactionsForAddressV3QueryParamOpts} queryParamOpts
2870
+ * @param {getTransactionsForBlockByPageQueryParamOpts} queryParamOpts
2716
2871
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2717
2872
  * - `noLogs`: Omit log events.
2718
- * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
2719
2873
  *
2720
2874
  */
2721
- async getTransactionsForAddressV3(chainName, walletAddress, page, queryParamOpts) {
2875
+ async getTransactionsForBlockByPage(chainName, blockHeight, page, queryParamOpts) {
2722
2876
  const searchParams = [
2723
2877
  {
2724
2878
  key: "quote-currency",
@@ -2728,23 +2882,19 @@ class TransactionService {
2728
2882
  key: "no-logs",
2729
2883
  value: queryParamOpts?.noLogs,
2730
2884
  },
2731
- {
2732
- key: "block-signed-at-asc",
2733
- value: queryParamOpts?.blockSignedAtAsc,
2734
- },
2735
2885
  ];
2736
- const endpoint = endpointGenerator(`${chainName}/address/${walletAddress}/transactions_v3/page/${page}`, searchParams);
2886
+ const endpoint = endpointGenerator(`${chainName}/block/${blockHeight}/transactions_v3/page/${page}`, searchParams);
2737
2887
  const parseData = (data) => {
2738
2888
  if (data.data) {
2889
+ data.data.updated_at = data.data.updated_at
2890
+ ? new Date(data.data.updated_at)
2891
+ : null;
2739
2892
  data.data.prev = data.data?.links?.prev
2740
2893
  ? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
2741
2894
  : null;
2742
2895
  data.data.next = data.data?.links?.next
2743
2896
  ? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
2744
2897
  : null;
2745
- data.data.updated_at = data.data.updated_at
2746
- ? new Date(data.data.updated_at)
2747
- : null;
2748
2898
  data.data.items = data.data.items
2749
2899
  ? data.data.items.map((txItem) => ({
2750
2900
  ...txItem,
@@ -2769,16 +2919,17 @@ class TransactionService {
2769
2919
  return await this.execution.execute(endpoint, parseData);
2770
2920
  }
2771
2921
  /**
2922
+ *
2923
+ * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
2772
2924
  *
2773
2925
  * @param {Chain} chainName - The chain name eg: `eth-mainnet` or 1.
2774
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
2775
- * @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.
2776
- * @param {GetTimeBucketTransactionsForAddressQueryParamOpts} queryParamOpts
2926
+ * @param {string} blockHash - The requested block hash.
2927
+ * @param {getTransactionsForBlockByPageQueryParamOpts} queryParamOpts
2777
2928
  * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2778
2929
  * - `noLogs`: Omit log events.
2779
2930
  *
2780
2931
  */
2781
- async getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, queryParamOpts) {
2932
+ async getTransactionsForBlock(chainName, blockHash, queryParamOpts) {
2782
2933
  const searchParams = [
2783
2934
  {
2784
2935
  key: "quote-currency",
@@ -2789,15 +2940,9 @@ class TransactionService {
2789
2940
  value: queryParamOpts?.noLogs,
2790
2941
  },
2791
2942
  ];
2792
- const endpoint = endpointGenerator(`${chainName}/bulk/transactions/${walletAddress}/${timeBucket}`, searchParams);
2943
+ const endpoint = endpointGenerator(`${chainName}/block_hash/${blockHash}/transactions_v3`, searchParams);
2793
2944
  const parseData = (data) => {
2794
2945
  if (data.data) {
2795
- data.data.prev = data.data?.links?.prev
2796
- ? async () => this.execution.execute(endpointGenerator(data.data?.links?.prev, searchParams), parseData)
2797
- : null;
2798
- data.data.next = data.data?.links?.next
2799
- ? async () => this.execution.execute(endpointGenerator(data.data?.links?.next, searchParams), parseData)
2800
- : null;
2801
2946
  data.data.updated_at = data.data.updated_at
2802
2947
  ? new Date(data.data.updated_at)
2803
2948
  : null;
@@ -2824,6 +2969,12 @@ class TransactionService {
2824
2969
  };
2825
2970
  return await this.execution.execute(endpoint, parseData);
2826
2971
  }
2972
+ /**
2973
+ * @deprecated This method has been deprecated and will be removed in future releases. Use `getPaginatedTransactionsForAddress` instead.
2974
+ */
2975
+ async getTransactionsForAddressV3(chainName, walletAddress, page, queryParamOpts) {
2976
+ return this.getPaginatedTransactionsForAddress(chainName, walletAddress, page, queryParamOpts);
2977
+ }
2827
2978
  }
2828
2979
 
2829
2980
  async function debugOutput(settings, ...content) {