@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
@@ -212,6 +212,8 @@ declare class BlockTransactionWithContractTransfers {
212
212
  pretty_gas_quote: string;
213
213
  /** * The native gas exchange rate for the requested `quote-currency`. */
214
214
  gas_quote_rate: number;
215
+ /** * The explorer links for this transaction. */
216
+ explorers: Explorer[];
215
217
  transfers: TokenTransferItem[];
216
218
  constructor(data: BlockTransactionWithContractTransfers);
217
219
  }
@@ -226,6 +228,13 @@ declare class Pagination {
226
228
  total_count: number;
227
229
  constructor(data: Pagination);
228
230
  }
231
+ declare class Explorer {
232
+ /** * The name of the explorer. */
233
+ label: string;
234
+ /** * The URL of the explorer. */
235
+ url: string;
236
+ constructor(data: Explorer);
237
+ }
229
238
  declare class TokenTransferItem {
230
239
  /** * The block signed timestamp in UTC. */
231
240
  block_signed_at: Date;
@@ -21,7 +21,7 @@ export type Chains = "btc-mainnet" | "eth-mainnet" | "matic-mainnet" | "bsc-main
21
21
  * CovalentClient Class
22
22
  */
23
23
  export type Quotes = "USD" | "CAD" | "EUR" | "SGD" | "INR" | "JPY" | "VND" | "CNY" | "KRW" | "RUB" | "TRY" | "NGN" | "ARS" | "AUD" | "CHF" | "GBP";
24
- export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
24
+ export declare const userAgent = "com.covalenthq.sdk.typescript/0.6.3";
25
25
  export declare class Response<T> {
26
26
  data: T;
27
27
  error: boolean;
@@ -54,6 +54,8 @@ declare class Transaction {
54
54
  pretty_gas_quote: string;
55
55
  /** * The native gas exchange rate for the requested `quote-currency`. */
56
56
  gas_quote_rate: number;
57
+ /** * The explorer links for this transaction. */
58
+ explorers: Explorer[];
57
59
  /** * The details for the dex transaction. */
58
60
  dex_details: DexReport;
59
61
  /** * The details for the NFT sale transaction. */
@@ -81,6 +83,13 @@ declare class ContractMetadata {
81
83
  logo_url: string;
82
84
  constructor(data: ContractMetadata);
83
85
  }
86
+ declare class Explorer {
87
+ /** * The name of the explorer. */
88
+ label: string;
89
+ /** * The URL of the explorer. */
90
+ url: string;
91
+ constructor(data: Explorer);
92
+ }
84
93
  declare class DexReport {
85
94
  /** * The offset is the position of the log entry within an event log. */
86
95
  log_offset: number;
@@ -324,6 +333,30 @@ declare class Param {
324
333
  value: string;
325
334
  constructor(data: Param);
326
335
  }
336
+ declare class RecentTransactionsResponse {
337
+ private _debug;
338
+ private _apiKey;
339
+ private _threadCount;
340
+ private _urlParams;
341
+ /** * The requested address. */
342
+ address: string;
343
+ /** * The timestamp when the response was generated. Useful to show data staleness to users. */
344
+ updated_at: Date;
345
+ /** * The requested quote currency eg: `USD`. */
346
+ quote_currency: string;
347
+ /** * The requested chain ID eg: `1`. */
348
+ chain_id: number;
349
+ /** * The requested chain name eg: `eth-mainnet`. */
350
+ chain_name: string;
351
+ /** * The current page of the response. */
352
+ current_page: number;
353
+ links: PaginationLinks;
354
+ /** * List of response items. */
355
+ items: Transaction[];
356
+ constructor(data: RecentTransactionsResponse, _debug: boolean, _apiKey: string, _threadCount: number, _urlParams: URLSearchParams);
357
+ prev(): Promise<Response<RecentTransactionsResponse>>;
358
+ next(): Promise<Response<RecentTransactionsResponse>>;
359
+ }
327
360
  declare class PaginationLinks {
328
361
  /** * URL link to the next page. */
329
362
  prev: string;
@@ -374,6 +407,10 @@ declare class TransactionSummary {
374
407
  constructor(data: TransactionSummary);
375
408
  }
376
409
  declare class TransactionsResponse {
410
+ private _debug;
411
+ private _apiKey;
412
+ private _threadCount;
413
+ private _urlParams;
377
414
  /** * The requested address. */
378
415
  address: string;
379
416
  /** * The timestamp when the response was generated. Useful to show data staleness to users. */
@@ -389,7 +426,9 @@ declare class TransactionsResponse {
389
426
  links: PaginationLinks;
390
427
  /** * List of response items. */
391
428
  items: Transaction[];
392
- constructor(data: TransactionsResponse);
429
+ constructor(data: TransactionsResponse, _debug: boolean, _apiKey: string, _threadCount: number, _urlParams: URLSearchParams);
430
+ prev(): Promise<Response<TransactionsResponse>>;
431
+ next(): Promise<Response<TransactionsResponse>>;
393
432
  }
394
433
  export interface GetTransactionQueryParamOpts {
395
434
  /** * The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`. */
@@ -469,6 +508,20 @@ export declare class TransactionService {
469
508
  *
470
509
  */
471
510
  getAllTransactionsForAddress(chainName: Chain, walletAddress: string, queryParamOpts?: GetAllTransactionsForAddressQueryParamOpts): AsyncIterable<Transaction>;
511
+ /**
512
+ *
513
+ * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
514
+ *
515
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
516
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
517
+ * @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
518
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
519
+ * - `noLogs`: Omit log events.
520
+ * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
521
+ * - `withSafe`: Include safe details.
522
+ *
523
+ */
524
+ getAllTransactionsForAddressByPage(chainName: Chain, walletAddress: string, queryParamOpts?: GetAllTransactionsForAddressQueryParamOpts): Promise<Response<RecentTransactionsResponse>>;
472
525
  /**
473
526
  *
474
527
  * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
@@ -0,0 +1 @@
1
+ export declare const calculatePrettyBalance: (value: number | bigint, decimals?: number, roundOff?: boolean, precision?: number) => string;
@@ -1,4 +1,4 @@
1
- import { NftData, Pagination } from "./GenericTypes";
1
+ import { NftData, Pagination, Explorer } from "./GenericTypes";
2
2
  export interface BalancesResponse {
3
3
  /** * The requested address. */
4
4
  address: string;
@@ -169,6 +169,8 @@ export interface BlockTransactionWithContractTransfers {
169
169
  pretty_gas_quote: string;
170
170
  /** * The native gas exchange rate for the requested `quote-currency`. */
171
171
  gas_quote_rate: number;
172
+ /** * The explorer links for this transaction. */
173
+ explorers: Explorer[];
172
174
  transfers: TokenTransferItem[];
173
175
  }
174
176
  export interface TokenTransferItem {
@@ -94,3 +94,9 @@ export interface ContractMetadata {
94
94
  /** * The contract logo URL. */
95
95
  logo_url: string;
96
96
  }
97
+ export interface Explorer {
98
+ /** * The name of the explorer. */
99
+ label: string;
100
+ /** * The URL of the explorer. */
101
+ url: string;
102
+ }
@@ -1,4 +1,4 @@
1
- import { ContractMetadata, LogEvent } from "./GenericTypes";
1
+ import { ContractMetadata, LogEvent, Explorer } from "./GenericTypes";
2
2
  export interface TransactionResponse {
3
3
  /** * The timestamp when the response was generated. Useful to show data staleness to users. */
4
4
  updated_at: Date;
@@ -53,6 +53,8 @@ export interface Transaction {
53
53
  pretty_gas_quote: string;
54
54
  /** * The native gas exchange rate for the requested `quote-currency`. */
55
55
  gas_quote_rate: number;
56
+ /** * The explorer links for this transaction. */
57
+ explorers: Explorer[];
56
58
  /** * The details for the dex transaction. */
57
59
  dex_details: DexReport;
58
60
  /** * The details for the NFT sale transaction. */
@@ -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/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { parseISO } from 'date-fns';
3
+ import Big from 'big.js';
3
4
 
4
5
  const DEFAULT_BACKOFF_MAX_RETRIES = 5;
5
6
  const BASE_DELAY_MS = 1000; // Base delay in milliseconds
@@ -656,6 +657,7 @@ class BlockTransactionWithContractTransfers {
656
657
  this.gas_quote = data.gas_quote;
657
658
  this.pretty_gas_quote = data.pretty_gas_quote;
658
659
  this.gas_quote_rate = data.gas_quote_rate;
660
+ this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer$1(itemData)) : null;
659
661
  this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
660
662
  }
661
663
  }
@@ -667,6 +669,12 @@ let Pagination$3 = class Pagination {
667
669
  this.total_count = data.total_count;
668
670
  }
669
671
  };
672
+ let Explorer$1 = class Explorer {
673
+ constructor(data) {
674
+ this.label = data.label;
675
+ this.url = data.url;
676
+ }
677
+ };
670
678
  class TokenTransferItem {
671
679
  constructor(data) {
672
680
  this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
@@ -3875,6 +3883,7 @@ class Transaction {
3875
3883
  this.pretty_gas_quote = data.pretty_gas_quote;
3876
3884
  this.gas_quote_rate = data.gas_quote_rate;
3877
3885
  this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
3886
+ this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
3878
3887
  this.dex_details = data.dex_details && data.dex_details !== null ? new DexReport(data.dex_details) : null;
3879
3888
  this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? new NftSalesReport(data.nft_sale_details) : null;
3880
3889
  this.lending_details = data.lending_details && data.lending_details !== null ? new LendingReport(data.lending_details) : null;
@@ -3892,6 +3901,12 @@ class ContractMetadata {
3892
3901
  this.logo_url = data.logo_url;
3893
3902
  }
3894
3903
  }
3904
+ class Explorer {
3905
+ constructor(data) {
3906
+ this.label = data.label;
3907
+ this.url = data.url;
3908
+ }
3909
+ }
3895
3910
  class DexReport {
3896
3911
  constructor(data) {
3897
3912
  this.log_offset = data.log_offset;
@@ -4049,6 +4064,154 @@ class Param {
4049
4064
  this.value = data.value;
4050
4065
  }
4051
4066
  }
4067
+ class RecentTransactionsResponse {
4068
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4069
+ this._debug = _debug;
4070
+ this._apiKey = _apiKey;
4071
+ this._threadCount = _threadCount;
4072
+ this._urlParams = _urlParams;
4073
+ this.address = data.address;
4074
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4075
+ this.quote_currency = data.quote_currency;
4076
+ this.chain_id = data.chain_id;
4077
+ this.chain_name = data.chain_name;
4078
+ this.current_page = data.current_page;
4079
+ this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4080
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4081
+ }
4082
+ async prev() {
4083
+ let success = false;
4084
+ let data;
4085
+ let response;
4086
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4087
+ const LIMIT = pLimit$1(this._threadCount);
4088
+ while (!success) {
4089
+ try {
4090
+ let startTime;
4091
+ if (this._debug) {
4092
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4093
+ }
4094
+ if (this.links.prev === null) {
4095
+ success = true;
4096
+ return {
4097
+ data: null,
4098
+ error: true,
4099
+ error_code: 400,
4100
+ error_message: "Invalid URL: URL link cannot be null"
4101
+ };
4102
+ }
4103
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4104
+ headers: {
4105
+ "Authorization": `Bearer ${this._apiKey}`,
4106
+ "X-Requested-With": userAgent
4107
+ }
4108
+ }));
4109
+ debugOutput(response.url, response.status, startTime);
4110
+ if (response.status === 429) {
4111
+ try {
4112
+ data = await LIMIT(() => backoff.backOff(response.url));
4113
+ }
4114
+ catch (error) {
4115
+ success = true;
4116
+ return {
4117
+ data: null,
4118
+ error: true,
4119
+ error_code: response.status,
4120
+ error_message: error.message
4121
+ };
4122
+ }
4123
+ }
4124
+ else {
4125
+ data = await response.json();
4126
+ }
4127
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4128
+ checkAndModifyResponse(dataClass);
4129
+ success = true;
4130
+ return {
4131
+ data: dataClass,
4132
+ error: data.error,
4133
+ error_code: data ? data.error_code : response.status,
4134
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4135
+ };
4136
+ }
4137
+ catch (error) {
4138
+ success = true;
4139
+ return {
4140
+ data: null,
4141
+ error: true,
4142
+ error_code: data ? data.error_code : response.status,
4143
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4144
+ };
4145
+ }
4146
+ }
4147
+ }
4148
+ async next() {
4149
+ let success = false;
4150
+ let data;
4151
+ let response;
4152
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4153
+ const LIMIT = pLimit$1(this._threadCount);
4154
+ while (!success) {
4155
+ try {
4156
+ let startTime;
4157
+ if (this._debug) {
4158
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4159
+ }
4160
+ if (this.links.next === null) {
4161
+ success = true;
4162
+ return {
4163
+ data: null,
4164
+ error: true,
4165
+ error_code: 400,
4166
+ error_message: "Invalid URL: URL link cannot be null"
4167
+ };
4168
+ }
4169
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4170
+ headers: {
4171
+ "Authorization": `Bearer ${this._apiKey}`,
4172
+ "X-Requested-With": userAgent
4173
+ }
4174
+ }));
4175
+ debugOutput(response.url, response.status, startTime);
4176
+ if (response.status === 429) {
4177
+ try {
4178
+ data = await LIMIT(() => backoff.backOff(response.url));
4179
+ }
4180
+ catch (error) {
4181
+ success = true;
4182
+ return {
4183
+ data: null,
4184
+ error: true,
4185
+ error_code: response.status,
4186
+ error_message: error.message
4187
+ };
4188
+ }
4189
+ }
4190
+ else {
4191
+ data = await response.json();
4192
+ }
4193
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4194
+ checkAndModifyResponse(dataClass);
4195
+ success = true;
4196
+ return {
4197
+ data: dataClass,
4198
+ error: data.error,
4199
+ error_code: data ? data.error_code : response.status,
4200
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4201
+ };
4202
+ }
4203
+ catch (error) {
4204
+ success = true;
4205
+ return {
4206
+ data: null,
4207
+ error: true,
4208
+ error_code: data ? data.error_code : response.status,
4209
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4210
+ };
4211
+ }
4212
+ }
4213
+ }
4214
+ }
4052
4215
  class PaginationLinks {
4053
4216
  constructor(data) {
4054
4217
  this.prev = data.prev;
@@ -4087,7 +4250,11 @@ class TransactionSummary {
4087
4250
  }
4088
4251
  }
4089
4252
  class TransactionsResponse {
4090
- constructor(data) {
4253
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
4254
+ this._debug = _debug;
4255
+ this._apiKey = _apiKey;
4256
+ this._threadCount = _threadCount;
4257
+ this._urlParams = _urlParams;
4091
4258
  this.address = data.address;
4092
4259
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
4093
4260
  this.quote_currency = data.quote_currency;
@@ -4097,6 +4264,138 @@ class TransactionsResponse {
4097
4264
  this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
4098
4265
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
4099
4266
  }
4267
+ async prev() {
4268
+ let success = false;
4269
+ let data;
4270
+ let response;
4271
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4272
+ const LIMIT = pLimit$1(this._threadCount);
4273
+ while (!success) {
4274
+ try {
4275
+ let startTime;
4276
+ if (this._debug) {
4277
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4278
+ }
4279
+ if (this.links.prev === null) {
4280
+ success = true;
4281
+ return {
4282
+ data: null,
4283
+ error: true,
4284
+ error_code: 400,
4285
+ error_message: "Invalid URL: URL link cannot be null"
4286
+ };
4287
+ }
4288
+ response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
4289
+ headers: {
4290
+ "Authorization": `Bearer ${this._apiKey}`,
4291
+ "X-Requested-With": userAgent
4292
+ }
4293
+ }));
4294
+ debugOutput(response.url, response.status, startTime);
4295
+ if (response.status === 429) {
4296
+ try {
4297
+ data = await LIMIT(() => backoff.backOff(response.url));
4298
+ }
4299
+ catch (error) {
4300
+ success = true;
4301
+ return {
4302
+ data: null,
4303
+ error: true,
4304
+ error_code: response.status,
4305
+ error_message: error.message
4306
+ };
4307
+ }
4308
+ }
4309
+ else {
4310
+ data = await response.json();
4311
+ }
4312
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4313
+ checkAndModifyResponse(dataClass);
4314
+ success = true;
4315
+ return {
4316
+ data: dataClass,
4317
+ error: data.error,
4318
+ error_code: data ? data.error_code : response.status,
4319
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4320
+ };
4321
+ }
4322
+ catch (error) {
4323
+ success = true;
4324
+ return {
4325
+ data: null,
4326
+ error: true,
4327
+ error_code: data ? data.error_code : response.status,
4328
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4329
+ };
4330
+ }
4331
+ }
4332
+ }
4333
+ async next() {
4334
+ let success = false;
4335
+ let data;
4336
+ let response;
4337
+ const backoff = new ExponentialBackoff(this._apiKey, this._debug);
4338
+ const LIMIT = pLimit$1(this._threadCount);
4339
+ while (!success) {
4340
+ try {
4341
+ let startTime;
4342
+ if (this._debug) {
4343
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4344
+ }
4345
+ if (this.links.next === null) {
4346
+ success = true;
4347
+ return {
4348
+ data: null,
4349
+ error: true,
4350
+ error_code: 400,
4351
+ error_message: "Invalid URL: URL link cannot be null"
4352
+ };
4353
+ }
4354
+ response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
4355
+ headers: {
4356
+ "Authorization": `Bearer ${this._apiKey}`,
4357
+ "X-Requested-With": userAgent
4358
+ }
4359
+ }));
4360
+ debugOutput(response.url, response.status, startTime);
4361
+ if (response.status === 429) {
4362
+ try {
4363
+ data = await LIMIT(() => backoff.backOff(response.url));
4364
+ }
4365
+ catch (error) {
4366
+ success = true;
4367
+ return {
4368
+ data: null,
4369
+ error: true,
4370
+ error_code: response.status,
4371
+ error_message: error.message
4372
+ };
4373
+ }
4374
+ }
4375
+ else {
4376
+ data = await response.json();
4377
+ }
4378
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
4379
+ checkAndModifyResponse(dataClass);
4380
+ success = true;
4381
+ return {
4382
+ data: dataClass,
4383
+ error: data.error,
4384
+ error_code: data ? data.error_code : response.status,
4385
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4386
+ };
4387
+ }
4388
+ catch (error) {
4389
+ success = true;
4390
+ return {
4391
+ data: null,
4392
+ error: true,
4393
+ error_code: data ? data.error_code : response.status,
4394
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4395
+ };
4396
+ }
4397
+ }
4398
+ }
4100
4399
  }
4101
4400
  /**
4102
4401
  * Transactions APIs
@@ -4297,6 +4596,88 @@ class TransactionService {
4297
4596
  }
4298
4597
  }
4299
4598
  }
4599
+ /**
4600
+ *
4601
+ * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
4602
+ *
4603
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
4604
+ * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
4605
+ * @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
4606
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
4607
+ * - `noLogs`: Omit log events.
4608
+ * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
4609
+ * - `withSafe`: Include safe details.
4610
+ *
4611
+ */
4612
+ async getAllTransactionsForAddressByPage(chainName, walletAddress, queryParamOpts) {
4613
+ let success = false;
4614
+ let data;
4615
+ let response;
4616
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
4617
+ while (!success) {
4618
+ try {
4619
+ const urlParams = new URLSearchParams();
4620
+ if (queryParamOpts?.quoteCurrency !== undefined) {
4621
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4622
+ }
4623
+ if (queryParamOpts?.noLogs !== undefined) {
4624
+ urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
4625
+ }
4626
+ if (queryParamOpts?.blockSignedAtAsc !== undefined) {
4627
+ urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
4628
+ }
4629
+ if (queryParamOpts?.withSafe !== undefined) {
4630
+ urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
4631
+ }
4632
+ let startTime;
4633
+ if (this.debug) {
4634
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
4635
+ }
4636
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
4637
+ headers: {
4638
+ "Authorization": `Bearer ${this.apiKey}`,
4639
+ "X-Requested-With": userAgent
4640
+ }
4641
+ }));
4642
+ debugOutput(response.url, response.status, startTime);
4643
+ if (response.status === 429) {
4644
+ try {
4645
+ data = await this.LIMIT(() => backoff.backOff(response.url));
4646
+ }
4647
+ catch (error) {
4648
+ success = true;
4649
+ return {
4650
+ data: null,
4651
+ error: true,
4652
+ error_code: response.status,
4653
+ error_message: error.message
4654
+ };
4655
+ }
4656
+ }
4657
+ else {
4658
+ data = await response.json();
4659
+ }
4660
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
4661
+ checkAndModifyResponse(dataClass);
4662
+ success = true;
4663
+ return {
4664
+ data: dataClass,
4665
+ error: data.error,
4666
+ error_code: data ? data.error_code : response.status,
4667
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4668
+ };
4669
+ }
4670
+ catch (error) {
4671
+ success = true;
4672
+ return {
4673
+ data: null,
4674
+ error: true,
4675
+ error_code: data ? data.error_code : response.status,
4676
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
4677
+ };
4678
+ }
4679
+ }
4680
+ }
4300
4681
  /**
4301
4682
  *
4302
4683
  * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
@@ -4500,7 +4881,7 @@ class TransactionService {
4500
4881
  else {
4501
4882
  data = await response.json();
4502
4883
  }
4503
- const dataClass = new TransactionsResponse(data.data);
4884
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
4504
4885
  checkAndModifyResponse(dataClass);
4505
4886
  success = true;
4506
4887
  return {
@@ -5865,7 +6246,7 @@ class XykService {
5865
6246
  }
5866
6247
  }
5867
6248
 
5868
- const userAgent = "com.covalenthq.sdk.typescript/0.6.1";
6249
+ const userAgent = "com.covalenthq.sdk.typescript/0.6.3";
5869
6250
  /**
5870
6251
  * CovalentClient Class
5871
6252
  */
@@ -5900,5 +6281,26 @@ class Client {
5900
6281
  }
5901
6282
  }
5902
6283
 
5903
- export { Client, CovalentClient };
6284
+ const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
6285
+ const bigIntValue = BigInt(value);
6286
+ const bigDecimalValue = new Big(bigIntValue.toString());
6287
+ const _decimals = decimals || 18;
6288
+ const _expoValue = BigInt(Math.pow(10, _decimals));
6289
+ const bigDecimalExpo = new Big(_expoValue.toString());
6290
+ const _calculated = bigDecimalValue.div(bigDecimalExpo);
6291
+ // removes the decimal places, true by default so it adds decimals
6292
+ if (!roundOff) {
6293
+ return _calculated.toString();
6294
+ }
6295
+ let _decimalFixed = precision;
6296
+ if (precision === 0) {
6297
+ _decimalFixed = 2;
6298
+ if (_calculated.lt(100)) {
6299
+ _decimalFixed = 6;
6300
+ }
6301
+ }
6302
+ return _calculated.toFixed(_decimalFixed);
6303
+ };
6304
+
6305
+ export { Client, CovalentClient, calculatePrettyBalance };
5904
6306
  //# sourceMappingURL=index.js.map