@covalenthq/client-sdk 0.6.1 → 0.6.3

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 (49) hide show
  1. package/README.md +26 -1
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/index.js +406 -3
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/services/BalanceService.d.ts +9 -0
  6. package/dist/cjs/services/CovalentClient.d.ts +1 -1
  7. package/dist/cjs/services/TransactionService.d.ts +54 -1
  8. package/dist/cjs/util/CalculatePrettyBalance.d.ts +1 -0
  9. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +3 -1
  10. package/dist/cjs/util/types/GenericTypes.d.ts +6 -0
  11. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +3 -1
  12. package/dist/es/index.d.ts +1 -0
  13. package/dist/es/index.js +406 -4
  14. package/dist/es/index.js.map +1 -1
  15. package/dist/es/services/BalanceService.d.ts +9 -0
  16. package/dist/es/services/CovalentClient.d.ts +1 -1
  17. package/dist/es/services/TransactionService.d.ts +54 -1
  18. package/dist/es/util/CalculatePrettyBalance.d.ts +1 -0
  19. package/dist/es/util/types/BalanceServiceTypes.d.ts +3 -1
  20. package/dist/es/util/types/GenericTypes.d.ts +6 -0
  21. package/dist/es/util/types/TransactionServiceTypes.d.ts +3 -1
  22. package/dist/esm/index.d.ts +1 -0
  23. package/dist/esm/index.js +406 -4
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/services/BalanceService.d.ts +9 -0
  26. package/dist/esm/services/CovalentClient.d.ts +1 -1
  27. package/dist/esm/services/TransactionService.d.ts +54 -1
  28. package/dist/esm/util/CalculatePrettyBalance.d.ts +1 -0
  29. package/dist/esm/util/types/BalanceServiceTypes.d.ts +3 -1
  30. package/dist/esm/util/types/GenericTypes.d.ts +6 -0
  31. package/dist/esm/util/types/TransactionServiceTypes.d.ts +3 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/services/BalanceService.d.ts +9 -0
  36. package/dist/services/BalanceService.js +7 -0
  37. package/dist/services/BalanceService.js.map +1 -1
  38. package/dist/services/CovalentClient.d.ts +1 -1
  39. package/dist/services/CovalentClient.js +1 -1
  40. package/dist/services/TransactionService.d.ts +54 -1
  41. package/dist/services/TransactionService.js +364 -3
  42. package/dist/services/TransactionService.js.map +1 -1
  43. package/dist/util/CalculatePrettyBalance.d.ts +1 -0
  44. package/dist/util/CalculatePrettyBalance.js +22 -0
  45. package/dist/util/CalculatePrettyBalance.js.map +1 -0
  46. package/dist/util/types/BalanceServiceTypes.d.ts +3 -1
  47. package/dist/util/types/GenericTypes.d.ts +6 -0
  48. package/dist/util/types/TransactionServiceTypes.d.ts +3 -1
  49. package/package.json +3 -1
package/README.md CHANGED
@@ -97,6 +97,16 @@ The `BalanceService` class refers to the [balances API endpoints](https://www.co
97
97
  - `getTokenHoldersV2ForTokenAddressByPage()`: 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. (Nonpaginated)
98
98
  - `getNativeTokenBalance()`: Get the native token balance for an address. This endpoint is required because native tokens are usually not ERC20 tokens and sometimes you want something lightweight.
99
99
 
100
+ The `calculatePrettyBalance` function is designed to take up to 4 inputs: the `balance` field obtained from the `tokenBalance` endpoint and the `contract_decimals`. The function also includes two optional fields, `roundOff` and `precision`, to allow developers to round the unscaled balance to a certain decimal precision. The primary purpose of this function is to convert the scaled token balance (the balance parameter) into its unscaled, human-readable form. The scaled balance needs to be divided by 10^(contractDecimals) to remove the scaling factor.
101
+
102
+ ```ts
103
+ import { CovalentClient, calculatePrettyBalance } from "@covalenthq/client-sdk";
104
+
105
+ const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
106
+ const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
107
+ const prettyBalance = calculatePrettyBalance(resp.data.items[0].balance, resp.data.items[0].contract_decimals);
108
+ ```
109
+
100
110
  ### BaseService
101
111
 
102
112
  The `BaseService` class refers to the [address activity, log events, chain status and block retrieval API endpoints](https://www.covalenthq.com/docs/api/base/get-address-activity/):
@@ -145,11 +155,26 @@ The `PricingService` class refers to the [historical token prices API endpoint](
145
155
  The `TransactionService` class refers to the [transactions API endpoints](https://www.covalenthq.com/docs/api/transactions/get-a-transaction/):
146
156
 
147
157
  - `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
148
- - `getTransactionsForAddressV3()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
158
+ - `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
159
+ - `getTransactionsForAddressV3()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
149
160
  - `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
150
161
  - `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
151
162
  - `getTransactionSummary()`: 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.
152
163
 
164
+ The functions `getAllTransactionsForAddressByPage()` and `getTransactionsForAddressV3()` have been enhanced with the introduction of `next()` and `prev()` support functions. These functions facilitate a smoother transition for developers navigating through our links object, which includes `prev` and `next` fields. Instead of requiring developers to manually extract values from these fields and create JavaScript API fetch calls for the URL values, the new `next()` and `prev()` functions provide a streamlined approach, allowing developers to simulate this behavior more efficiently.
165
+
166
+ ```ts
167
+ import { CovalentClient } from "@covalenthq/client-sdk";
168
+
169
+ const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
170
+ const resp = await client.TransactionService.getAllTransactionsForAddressByPage("eth-mainnet", "WALLET_ADDRESS");
171
+ // assuming resp.data.current_page is 10
172
+ if (resp.data !== null) {
173
+ const prevPage = await resp.data.prev() // will retrieve page 9
174
+ console.log(prevPage.data)
175
+ }
176
+ ```
177
+
153
178
  ### XykService
154
179
 
155
180
  The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/docs/api/xyk/get-xyk-pools/):
@@ -7,3 +7,4 @@ export * from "./util/types/SecurityServiceTypes";
7
7
  export * from "./util/types/XykServiceTypes";
8
8
  export * from "./util/types/GenericTypes";
9
9
  export * from "./util/types/TransactionServiceTypes";
10
+ export { calculatePrettyBalance } from "./util/CalculatePrettyBalance";
package/dist/cjs/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var chalk = require('chalk');
4
4
  var dateFns = require('date-fns');
5
+ var Big = require('big.js');
5
6
 
6
7
  const DEFAULT_BACKOFF_MAX_RETRIES = 5;
7
8
  const BASE_DELAY_MS = 1000; // Base delay in milliseconds
@@ -658,6 +659,7 @@ class BlockTransactionWithContractTransfers {
658
659
  this.gas_quote = data.gas_quote;
659
660
  this.pretty_gas_quote = data.pretty_gas_quote;
660
661
  this.gas_quote_rate = data.gas_quote_rate;
662
+ this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer$1(itemData)) : null;
661
663
  this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
662
664
  }
663
665
  }
@@ -669,6 +671,12 @@ let Pagination$3 = class Pagination {
669
671
  this.total_count = data.total_count;
670
672
  }
671
673
  };
674
+ let Explorer$1 = class Explorer {
675
+ constructor(data) {
676
+ this.label = data.label;
677
+ this.url = data.url;
678
+ }
679
+ };
672
680
  class TokenTransferItem {
673
681
  constructor(data) {
674
682
  this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? dateFns.parseISO(data.block_signed_at.toString()) : null;
@@ -3877,6 +3885,7 @@ class Transaction {
3877
3885
  this.pretty_gas_quote = data.pretty_gas_quote;
3878
3886
  this.gas_quote_rate = data.gas_quote_rate;
3879
3887
  this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
3888
+ this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
3880
3889
  this.dex_details = data.dex_details && data.dex_details !== null ? new DexReport(data.dex_details) : null;
3881
3890
  this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? new NftSalesReport(data.nft_sale_details) : null;
3882
3891
  this.lending_details = data.lending_details && data.lending_details !== null ? new LendingReport(data.lending_details) : null;
@@ -3894,6 +3903,12 @@ class ContractMetadata {
3894
3903
  this.logo_url = data.logo_url;
3895
3904
  }
3896
3905
  }
3906
+ class Explorer {
3907
+ constructor(data) {
3908
+ this.label = data.label;
3909
+ this.url = data.url;
3910
+ }
3911
+ }
3897
3912
  class DexReport {
3898
3913
  constructor(data) {
3899
3914
  this.log_offset = data.log_offset;
@@ -4051,6 +4066,154 @@ class Param {
4051
4066
  this.value = data.value;
4052
4067
  }
4053
4068
  }
4069
+ class RecentTransactionsResponse {
4070
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4071
+ this._debug = _debug;
4072
+ this._apiKey = _apiKey;
4073
+ this._threadCount = _threadCount;
4074
+ this._urlParams = _urlParams;
4075
+ this.address = data.address;
4076
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
4077
+ this.quote_currency = data.quote_currency;
4078
+ this.chain_id = data.chain_id;
4079
+ this.chain_name = data.chain_name;
4080
+ this.current_page = data.current_page;
4081
+ this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4082
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4083
+ }
4084
+ async prev() {
4085
+ let success = false;
4086
+ let data;
4087
+ let response;
4088
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4089
+ const LIMIT = pLimit$1(this._threadCount);
4090
+ while (!success) {
4091
+ try {
4092
+ let startTime;
4093
+ if (this._debug) {
4094
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4095
+ }
4096
+ if (this.links.prev === null) {
4097
+ success = true;
4098
+ return {
4099
+ data: null,
4100
+ error: true,
4101
+ error_code: 400,
4102
+ error_message: "Invalid URL: URL link cannot be null"
4103
+ };
4104
+ }
4105
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4106
+ headers: {
4107
+ "Authorization": `Bearer ${this._apiKey}`,
4108
+ "X-Requested-With": userAgent
4109
+ }
4110
+ }));
4111
+ debugOutput(response.url, response.status, startTime);
4112
+ if (response.status === 429) {
4113
+ try {
4114
+ data = await LIMIT(() => backoff.backOff(response.url));
4115
+ }
4116
+ catch (error) {
4117
+ success = true;
4118
+ return {
4119
+ data: null,
4120
+ error: true,
4121
+ error_code: response.status,
4122
+ error_message: error.message
4123
+ };
4124
+ }
4125
+ }
4126
+ else {
4127
+ data = await response.json();
4128
+ }
4129
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4130
+ checkAndModifyResponse(dataClass);
4131
+ success = true;
4132
+ return {
4133
+ data: dataClass,
4134
+ error: data.error,
4135
+ error_code: data ? data.error_code : response.status,
4136
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4137
+ };
4138
+ }
4139
+ catch (error) {
4140
+ success = true;
4141
+ return {
4142
+ data: null,
4143
+ error: true,
4144
+ error_code: data ? data.error_code : response.status,
4145
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4146
+ };
4147
+ }
4148
+ }
4149
+ }
4150
+ async next() {
4151
+ let success = false;
4152
+ let data;
4153
+ let response;
4154
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4155
+ const LIMIT = pLimit$1(this._threadCount);
4156
+ while (!success) {
4157
+ try {
4158
+ let startTime;
4159
+ if (this._debug) {
4160
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4161
+ }
4162
+ if (this.links.next === null) {
4163
+ success = true;
4164
+ return {
4165
+ data: null,
4166
+ error: true,
4167
+ error_code: 400,
4168
+ error_message: "Invalid URL: URL link cannot be null"
4169
+ };
4170
+ }
4171
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4172
+ headers: {
4173
+ "Authorization": `Bearer ${this._apiKey}`,
4174
+ "X-Requested-With": userAgent
4175
+ }
4176
+ }));
4177
+ debugOutput(response.url, response.status, startTime);
4178
+ if (response.status === 429) {
4179
+ try {
4180
+ data = await LIMIT(() => backoff.backOff(response.url));
4181
+ }
4182
+ catch (error) {
4183
+ success = true;
4184
+ return {
4185
+ data: null,
4186
+ error: true,
4187
+ error_code: response.status,
4188
+ error_message: error.message
4189
+ };
4190
+ }
4191
+ }
4192
+ else {
4193
+ data = await response.json();
4194
+ }
4195
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4196
+ checkAndModifyResponse(dataClass);
4197
+ success = true;
4198
+ return {
4199
+ data: dataClass,
4200
+ error: data.error,
4201
+ error_code: data ? data.error_code : response.status,
4202
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4203
+ };
4204
+ }
4205
+ catch (error) {
4206
+ success = true;
4207
+ return {
4208
+ data: null,
4209
+ error: true,
4210
+ error_code: data ? data.error_code : response.status,
4211
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4212
+ };
4213
+ }
4214
+ }
4215
+ }
4216
+ }
4054
4217
  class PaginationLinks {
4055
4218
  constructor(data) {
4056
4219
  this.prev = data.prev;
@@ -4089,7 +4252,11 @@ class TransactionSummary {
4089
4252
  }
4090
4253
  }
4091
4254
  class TransactionsResponse {
4092
- constructor(data) {
4255
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4256
+ this._debug = _debug;
4257
+ this._apiKey = _apiKey;
4258
+ this._threadCount = _threadCount;
4259
+ this._urlParams = _urlParams;
4093
4260
  this.address = data.address;
4094
4261
  this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
4095
4262
  this.quote_currency = data.quote_currency;
@@ -4099,6 +4266,138 @@ class TransactionsResponse {
4099
4266
  this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4100
4267
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4101
4268
  }
4269
+ async prev() {
4270
+ let success = false;
4271
+ let data;
4272
+ let response;
4273
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4274
+ const LIMIT = pLimit$1(this._threadCount);
4275
+ while (!success) {
4276
+ try {
4277
+ let startTime;
4278
+ if (this._debug) {
4279
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4280
+ }
4281
+ if (this.links.prev === null) {
4282
+ success = true;
4283
+ return {
4284
+ data: null,
4285
+ error: true,
4286
+ error_code: 400,
4287
+ error_message: "Invalid URL: URL link cannot be null"
4288
+ };
4289
+ }
4290
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4291
+ headers: {
4292
+ "Authorization": `Bearer ${this._apiKey}`,
4293
+ "X-Requested-With": userAgent
4294
+ }
4295
+ }));
4296
+ debugOutput(response.url, response.status, startTime);
4297
+ if (response.status === 429) {
4298
+ try {
4299
+ data = await LIMIT(() => backoff.backOff(response.url));
4300
+ }
4301
+ catch (error) {
4302
+ success = true;
4303
+ return {
4304
+ data: null,
4305
+ error: true,
4306
+ error_code: response.status,
4307
+ error_message: error.message
4308
+ };
4309
+ }
4310
+ }
4311
+ else {
4312
+ data = await response.json();
4313
+ }
4314
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4315
+ checkAndModifyResponse(dataClass);
4316
+ success = true;
4317
+ return {
4318
+ data: dataClass,
4319
+ error: data.error,
4320
+ error_code: data ? data.error_code : response.status,
4321
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4322
+ };
4323
+ }
4324
+ catch (error) {
4325
+ success = true;
4326
+ return {
4327
+ data: null,
4328
+ error: true,
4329
+ error_code: data ? data.error_code : response.status,
4330
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4331
+ };
4332
+ }
4333
+ }
4334
+ }
4335
+ async next() {
4336
+ let success = false;
4337
+ let data;
4338
+ let response;
4339
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4340
+ const LIMIT = pLimit$1(this._threadCount);
4341
+ while (!success) {
4342
+ try {
4343
+ let startTime;
4344
+ if (this._debug) {
4345
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4346
+ }
4347
+ if (this.links.next === null) {
4348
+ success = true;
4349
+ return {
4350
+ data: null,
4351
+ error: true,
4352
+ error_code: 400,
4353
+ error_message: "Invalid URL: URL link cannot be null"
4354
+ };
4355
+ }
4356
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4357
+ headers: {
4358
+ "Authorization": `Bearer ${this._apiKey}`,
4359
+ "X-Requested-With": userAgent
4360
+ }
4361
+ }));
4362
+ debugOutput(response.url, response.status, startTime);
4363
+ if (response.status === 429) {
4364
+ try {
4365
+ data = await LIMIT(() => backoff.backOff(response.url));
4366
+ }
4367
+ catch (error) {
4368
+ success = true;
4369
+ return {
4370
+ data: null,
4371
+ error: true,
4372
+ error_code: response.status,
4373
+ error_message: error.message
4374
+ };
4375
+ }
4376
+ }
4377
+ else {
4378
+ data = await response.json();
4379
+ }
4380
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4381
+ checkAndModifyResponse(dataClass);
4382
+ success = true;
4383
+ return {
4384
+ data: dataClass,
4385
+ error: data.error,
4386
+ error_code: data ? data.error_code : response.status,
4387
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4388
+ };
4389
+ }
4390
+ catch (error) {
4391
+ success = true;
4392
+ return {
4393
+ data: null,
4394
+ error: true,
4395
+ error_code: data ? data.error_code : response.status,
4396
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4397
+ };
4398
+ }
4399
+ }
4400
+ }
4102
4401
  }
4103
4402
  /**
4104
4403
  * Transactions APIs
@@ -4299,6 +4598,88 @@ class TransactionService {
4299
4598
  }
4300
4599
  }
4301
4600
  }
4601
+ /**
4602
+ *
4603
+ * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
4604
+ *
4605
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
4606
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
4607
+ * @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
4608
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
4609
+ * - `noLogs`: Omit log events.
4610
+ * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
4611
+ * - `withSafe`: Include safe details.
4612
+ *
4613
+ */
4614
+ async getAllTransactionsForAddressByPage(chainName, walletAddress, queryParamOpts) {
4615
+ let success = false;
4616
+ let data;
4617
+ let response;
4618
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
4619
+ while (!success) {
4620
+ try {
4621
+ const urlParams = new URLSearchParams();
4622
+ if (queryParamOpts?.quoteCurrency !== undefined) {
4623
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4624
+ }
4625
+ if (queryParamOpts?.noLogs !== undefined) {
4626
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
4627
+ }
4628
+ if (queryParamOpts?.blockSignedAtAsc !== undefined) {
4629
+ urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
4630
+ }
4631
+ if (queryParamOpts?.withSafe !== undefined) {
4632
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
4633
+ }
4634
+ let startTime;
4635
+ if (this.debug) {
4636
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4637
+ }
4638
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
4639
+ headers: {
4640
+ "Authorization": `Bearer ${this.apiKey}`,
4641
+ "X-Requested-With": userAgent
4642
+ }
4643
+ }));
4644
+ debugOutput(response.url, response.status, startTime);
4645
+ if (response.status === 429) {
4646
+ try {
4647
+ data = await this.LIMIT(() => backoff.backOff(response.url));
4648
+ }
4649
+ catch (error) {
4650
+ success = true;
4651
+ return {
4652
+ data: null,
4653
+ error: true,
4654
+ error_code: response.status,
4655
+ error_message: error.message
4656
+ };
4657
+ }
4658
+ }
4659
+ else {
4660
+ data = await response.json();
4661
+ }
4662
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
4663
+ checkAndModifyResponse(dataClass);
4664
+ success = true;
4665
+ return {
4666
+ data: dataClass,
4667
+ error: data.error,
4668
+ error_code: data ? data.error_code : response.status,
4669
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4670
+ };
4671
+ }
4672
+ catch (error) {
4673
+ success = true;
4674
+ return {
4675
+ data: null,
4676
+ error: true,
4677
+ error_code: data ? data.error_code : response.status,
4678
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4679
+ };
4680
+ }
4681
+ }
4682
+ }
4302
4683
  /**
4303
4684
  *
4304
4685
  * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
@@ -4502,7 +4883,7 @@ class TransactionService {
4502
4883
  else {
4503
4884
  data = await response.json();
4504
4885
  }
4505
- const dataClass = new TransactionsResponse(data.data);
4886
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
4506
4887
  checkAndModifyResponse(dataClass);
4507
4888
  success = true;
4508
4889
  return {
@@ -5867,7 +6248,7 @@ class XykService {
5867
6248
  }
5868
6249
  }
5869
6250
 
5870
- const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
6251
+ const userAgent = "com.covalenthq.sdk.typescript/0.6.3";
5871
6252
  /**
5872
6253
  * CovalentClient Class
5873
6254
  */
@@ -5902,6 +6283,28 @@ class Client {
5902
6283
  }
5903
6284
  }
5904
6285
 
6286
+ const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
6287
+ const bigIntValue = BigInt(value);
6288
+ const bigDecimalValue = new Big(bigIntValue.toString());
6289
+ const _decimals = decimals || 18;
6290
+ const _expoValue = BigInt(Math.pow(10, _decimals));
6291
+ const bigDecimalExpo = new Big(_expoValue.toString());
6292
+ const _calculated = bigDecimalValue.div(bigDecimalExpo);
6293
+ // removes the decimal places, true by default so it adds decimals
6294
+ if (!roundOff) {
6295
+ return _calculated.toString();
6296
+ }
6297
+ let _decimalFixed = precision;
6298
+ if (precision === 0) {
6299
+ _decimalFixed = 2;
6300
+ if (_calculated.lt(100)) {
6301
+ _decimalFixed = 6;
6302
+ }
6303
+ }
6304
+ return _calculated.toFixed(_decimalFixed);
6305
+ };
6306
+
5905
6307
  exports.Client = Client;
5906
6308
  exports.CovalentClient = CovalentClient;
6309
+ exports.calculatePrettyBalance = calculatePrettyBalance;
5907
6310
  //# sourceMappingURL=index.js.map