@augustdigital/sdk 8.5.0 → 8.6.0

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 (101) hide show
  1. package/README.md +207 -117
  2. package/lib/adapters/evm/index.d.ts +4 -4
  3. package/lib/adapters/evm/index.js +2 -0
  4. package/lib/adapters/solana/constants.d.ts +1 -1
  5. package/lib/adapters/solana/getters.d.ts +1 -1
  6. package/lib/adapters/solana/index.d.ts +4 -4
  7. package/lib/adapters/solana/index.js +4 -0
  8. package/lib/adapters/solana/types.d.ts +1 -1
  9. package/lib/adapters/solana/utils.d.ts +3 -3
  10. package/lib/adapters/solana/vault.actions.d.ts +4 -4
  11. package/lib/adapters/stellar/actions.d.ts +1 -1
  12. package/lib/adapters/stellar/index.d.ts +24 -2
  13. package/lib/adapters/stellar/index.js +25 -2
  14. package/lib/adapters/stellar/soroban.d.ts +1 -1
  15. package/lib/adapters/stellar/soroban.js +1 -1
  16. package/lib/adapters/stellar/submit.d.ts +20 -3
  17. package/lib/adapters/stellar/submit.js +74 -8
  18. package/lib/adapters/sui/getters.d.ts +1 -1
  19. package/lib/adapters/sui/index.d.ts +1 -1
  20. package/lib/adapters/sui/index.js +2 -0
  21. package/lib/adapters/sui/transformer.d.ts +2 -2
  22. package/lib/adapters/sui/transformer.js +1 -0
  23. package/lib/adapters/sui/types.d.ts +1 -1
  24. package/lib/core/analytics/sentry-runtime.js +1 -1
  25. package/lib/core/analytics/sentry.d.ts +2 -2
  26. package/lib/core/analytics/types.d.ts +1 -1
  27. package/lib/core/analytics/user-identity.d.ts +2 -2
  28. package/lib/core/analytics/user-identity.js +1 -1
  29. package/lib/core/analytics/version.d.ts +1 -1
  30. package/lib/core/analytics/version.js +1 -1
  31. package/lib/core/base.class.d.ts +3 -3
  32. package/lib/core/base.class.js +10 -4
  33. package/lib/core/constants/adapters.d.ts +1 -1
  34. package/lib/core/constants/core.d.ts +2 -0
  35. package/lib/core/constants/core.js +6 -0
  36. package/lib/core/constants/swap-router.d.ts +37 -1
  37. package/lib/core/constants/swap-router.js +41 -1
  38. package/lib/core/constants/vaults.d.ts +1 -1
  39. package/lib/core/constants/web3.d.ts +1 -1
  40. package/lib/core/constants/web3.js +0 -3
  41. package/lib/core/errors/index.d.ts +2 -2
  42. package/lib/core/errors/index.js +9 -0
  43. package/lib/core/fetcher.d.ts +39 -39
  44. package/lib/core/fetcher.js +75 -57
  45. package/lib/core/helpers/adapters.d.ts +1 -1
  46. package/lib/core/helpers/core.d.ts +21 -18
  47. package/lib/core/helpers/core.js +22 -20
  48. package/lib/core/helpers/explorer-link.d.ts +1 -1
  49. package/lib/core/helpers/signer.d.ts +1 -1
  50. package/lib/core/helpers/swap-router.d.ts +1 -1
  51. package/lib/core/helpers/vault-version.d.ts +1 -1
  52. package/lib/core/helpers/vaults.d.ts +1 -1
  53. package/lib/core/helpers/web3.d.ts +2 -2
  54. package/lib/core/helpers/web3.js +9 -9
  55. package/lib/core/vault-metadata.d.ts +1 -1
  56. package/lib/core/version-check.js +1 -1
  57. package/lib/evm/methods/crossChainVault.js +1 -1
  58. package/lib/evm/types/crossChain.js +1 -1
  59. package/lib/main.d.ts +1 -1
  60. package/lib/main.js +7 -0
  61. package/lib/modules/sub-accounts/fetcher.d.ts +2 -2
  62. package/lib/modules/sub-accounts/main.d.ts +2 -2
  63. package/lib/modules/sub-accounts/main.js +1 -1
  64. package/lib/modules/sub-accounts/utils.d.ts +1 -1
  65. package/lib/modules/vaults/adapter.helpers.d.ts +3 -3
  66. package/lib/modules/vaults/fetcher.d.ts +25 -0
  67. package/lib/modules/vaults/fetcher.js +51 -1
  68. package/lib/modules/vaults/getters.d.ts +50 -50
  69. package/lib/modules/vaults/getters.js +68 -67
  70. package/lib/modules/vaults/main.js +3 -1
  71. package/lib/modules/vaults/read.actions.d.ts +2 -2
  72. package/lib/modules/vaults/utils/call-data-decoder.d.ts +1 -1
  73. package/lib/modules/vaults/utils.d.ts +19 -3
  74. package/lib/modules/vaults/utils.js +39 -6
  75. package/lib/modules/vaults/write.actions.js +35 -1
  76. package/lib/polyfills.js +3 -3
  77. package/lib/sdk.d.ts +1339 -1197
  78. package/lib/services/coingecko/fetcher.d.ts +10 -9
  79. package/lib/services/coingecko/fetcher.js +22 -18
  80. package/lib/services/debank/fetcher.d.ts +1 -1
  81. package/lib/services/debank/utils.d.ts +1 -1
  82. package/lib/services/debank/utils.js +1 -1
  83. package/lib/services/layerzero/deposits.d.ts +1 -1
  84. package/lib/services/layerzero/redeems.d.ts +1 -1
  85. package/lib/services/octavfi/fetcher.d.ts +1 -1
  86. package/lib/services/octavfi/types.d.ts +1 -1
  87. package/lib/services/octavfi/utils.d.ts +2 -2
  88. package/lib/services/subgraph/fetcher.js +1 -1
  89. package/lib/services/subgraph/vaults.js +76 -0
  90. package/lib/services/swap-quotes/index.d.ts +9 -0
  91. package/lib/services/swap-quotes/index.js +2 -1
  92. package/lib/services/swap-quotes/paraswap.d.ts +8 -0
  93. package/lib/services/swap-quotes/paraswap.js +8 -0
  94. package/lib/types/pools.d.ts +2 -2
  95. package/lib/types/staking.d.ts +1 -1
  96. package/lib/types/sub-accounts.d.ts +1 -1
  97. package/lib/types/subgraph.d.ts +10 -1
  98. package/lib/types/vaults.d.ts +26 -0
  99. package/lib/types/web3.d.ts +1 -1
  100. package/lib/types/webserver.d.ts +2 -2
  101. package/package.json +1 -1
@@ -14,7 +14,7 @@ export type IFetchAugustMethods = 'get' | 'post' | 'put';
14
14
  export type IFetchAugustOptions = {
15
15
  method?: IFetchAugustMethods;
16
16
  headers?: Record<string, string>;
17
- data?: any;
17
+ data?: unknown;
18
18
  server?: keyof typeof WEBSERVER_URL;
19
19
  /** Caller-supplied AbortSignal; combined with the default timeout. */
20
20
  signal?: AbortSignal;
@@ -32,7 +32,7 @@ export type IFetchAugustOptions = {
32
32
  * call with no arguments) to clear the override and fall back to the
33
33
  * compiled-in `REQUEST_TIMEOUT_MS`.
34
34
  *
35
- * @param ms Positive number of milliseconds to wait before aborting, or
35
+ * @param ms - Positive number of milliseconds to wait before aborting, or
36
36
  * `null` to clear.
37
37
  */
38
38
  export declare function setSdkRequestTimeout(ms?: number | null): void;
@@ -46,9 +46,9 @@ export { CACHE, getSafeCache, setSafeCache };
46
46
  /**
47
47
  * Make authenticated requests to August backend services using API key.
48
48
  * Automatically logs errors with correlation IDs for debugging.
49
- * @param apiKey August API key for authentication
50
- * @param relativeUrl Endpoint path relative to base URL
51
- * @param options Request configuration including method and headers
49
+ * @param apiKey - August API key for authentication
50
+ * @param relativeUrl - Endpoint path relative to base URL
51
+ * @param options - Request configuration including method and headers
52
52
  * @returns Response object if successful
53
53
  * @throws Error with correlation ID if request fails
54
54
  */
@@ -56,8 +56,8 @@ export declare function fetchAugustWithKey(apiKey: string, relativeUrl: string,
56
56
  /**
57
57
  * Make unauthenticated requests to August public API endpoints.
58
58
  * Used for fetching vault metadata and public market data.
59
- * @param relativeUrl Endpoint path relative to public API base URL
60
- * @param options Request configuration including method and headers
59
+ * @param relativeUrl - Endpoint path relative to public API base URL
60
+ * @param options - Request configuration including method and headers
61
61
  * @returns Response object if successful
62
62
  * @throws Error with correlation ID if request fails
63
63
  */
@@ -65,9 +65,9 @@ export declare function fetchAugustPublic(relativeUrl: string, options?: IFetchA
65
65
  /**
66
66
  * Make authenticated requests using Bearer token authentication.
67
67
  * Typically used for user-specific operations requiring OAuth tokens.
68
- * @param bearerToken OAuth bearer token
69
- * @param relativeUrl Endpoint path relative to base URL
70
- * @param options Request configuration including method and headers
68
+ * @param bearerToken - OAuth bearer token
69
+ * @param relativeUrl - Endpoint path relative to base URL
70
+ * @param options - Request configuration including method and headers
71
71
  * @returns Response object if successful
72
72
  * @throws Error with correlation ID if request fails
73
73
  */
@@ -80,10 +80,10 @@ export declare function isRetryableError(error: Error): boolean;
80
80
  /**
81
81
  * Wrap async operations with exponential backoff retry logic.
82
82
  * Retries on network errors with increasing delays between attempts.
83
- * @param fn Async function to execute with retry logic
84
- * @param maxRetries Maximum number of retry attempts
85
- * @param baseDelay Initial delay in milliseconds (doubles each retry)
86
- * @param shouldRetry Custom function to determine if error is retryable
83
+ * @param fn - Async function to execute with retry logic
84
+ * @param maxRetries - Maximum number of retry attempts
85
+ * @param baseDelay - Initial delay in milliseconds (doubles each retry)
86
+ * @param shouldRetry - Custom function to determine if error is retryable
87
87
  * @returns Result of successful function execution
88
88
  * @throws Last error if all retries exhausted
89
89
  */
@@ -91,17 +91,17 @@ export declare function withRetry<T>(fn: () => Promise<T>, maxRetries?: number,
91
91
  /**
92
92
  * Fetch tokenized vault configurations from backend API.
93
93
  * Results are cached to reduce API calls. Optionally filter by specific vault address.
94
- * @param pool Optional vault address to filter results
95
- * @param headers Monitoring headers for request tracking
94
+ * @param pool - Optional vault address to filter results
95
+ * @param headers - Monitoring headers for request tracking
96
96
  * @returns Array of tokenized vault configurations
97
97
  */
98
98
  export declare function fetchTokenizedVault(pool: VaultAddress, headers?: IWSMonitorHeaders, loadSubaccounts?: boolean, loadSnapshots?: boolean): Promise<ITokenizedVault[]>;
99
99
  /**
100
100
  * Fetch tokenized vault configurations from backend API.
101
101
  * Results are cached to reduce API calls. Optionally filter by specific vault address.
102
- * @param pool Optional vault address to filter results
103
- * @param headers Monitoring headers for request tracking
104
- * @param loadSubaccounts Optional flag to load subaccounts and EOA operators (defaults to true on API)
102
+ * @param pool - Optional vault address to filter results
103
+ * @param headers - Monitoring headers for request tracking
104
+ * @param loadSubaccounts - Optional flag to load subaccounts and EOA operators (defaults to true on API)
105
105
  * @returns Array of tokenized vault configurations
106
106
  */
107
107
  export declare function fetchTokenizedVaults(pool?: IAddress, headers?: IWSMonitorHeaders, loadSubaccounts?: boolean, loadSnapshots?: boolean): Promise<ITokenizedVault[]>;
@@ -109,45 +109,45 @@ export declare function fetchTokenizedVaults(pool?: IAddress, headers?: IWSMonit
109
109
  * Fetch current USD price for a token symbol or vault LP token.
110
110
  * For vault LP tokens, calculates share price using totalAssets/totalSupply ratio.
111
111
  * Falls back to CoinGecko if primary source fails.
112
- * @param symbol Token symbol or contract address
113
- * @param provider Optional web3 provider for on-chain price calculations
114
- * @param coinGeckoKey Optional CoinGecko API key for fallback pricing
115
- * @param headers Monitoring headers for request tracking
112
+ * @param symbol - Token symbol or contract address
113
+ * @param provider - Optional web3 provider for on-chain price calculations
114
+ * @param coinGeckoKey - Optional CoinGecko API key for fallback pricing
115
+ * @param headers - Monitoring headers for request tracking
116
116
  * @returns Token price in USD
117
117
  */
118
- export declare function fetchTokenPrice(symbol: string, provider?: IContractRunner, coinGeckoKey?: string, headers?: IWSMonitorHeaders): Promise<any>;
118
+ export declare function fetchTokenPrice(symbol: string, provider?: IContractRunner, coinGeckoKey?: string, headers?: IWSMonitorHeaders): Promise<number>;
119
119
  /**
120
120
  * Fetch token price by contract address and chain ID from August price server.
121
- * @param address Token contract address
122
- * @param chainId Network chain ID
123
- * @param headers Optional monitoring headers for request tracking
121
+ * @param address - Token contract address
122
+ * @param chainId - Network chain ID
123
+ * @param headers - Optional monitoring headers for request tracking
124
124
  * @returns Token price in USD, or 0 if not found
125
125
  */
126
126
  export declare function fetchTokenPriceByAddress(address: VaultAddress, chainId: number, headers?: IWSMonitorHeaders): Promise<number>;
127
127
  /**
128
128
  * Fetch active loans for a specific vault from backend API.
129
129
  * Results are cached per vault and chain to reduce API calls.
130
- * @param pool Vault address
131
- * @param chainId Network chain ID
132
- * @param headers Monitoring headers for request tracking
130
+ * @param pool - Vault address
131
+ * @param chainId - Network chain ID
132
+ * @param headers - Monitoring headers for request tracking
133
133
  * @returns Array of active loan objects
134
134
  */
135
135
  export declare function fetchTokenizedVaultLoans(pool: VaultAddress, chainId: number, headers?: IWSMonitorHeaders): Promise<IWSVaultLoan[]>;
136
136
  /**
137
137
  * Fetch subaccount loans for a specific tokenized vault (lending pool).
138
138
  * Retrieves all active subaccount loan data from the backend.
139
- * @param pool Vault address
140
- * @param chainId Network chain ID
141
- * @param headers Monitoring headers for request tracking
139
+ * @param pool - Vault address
140
+ * @param chainId - Network chain ID
141
+ * @param headers - Monitoring headers for request tracking
142
142
  * @returns Array of active subaccount loan objects
143
143
  */
144
144
  export declare function fetchTokenizedVaultSubaccountLoans(pool: VaultAddress, chainId: number, headers?: IWSMonitorHeaders): Promise<IWSVaultLoan[]>;
145
145
  /**
146
146
  * Fetch historical timeseries data for a specific vault.
147
147
  * Returns TVL, APY, PnL, and share price data over time.
148
- * @param vaultAddress Vault contract address
149
- * @param nDays Number of days of historical data to fetch (default 30, min 1)
150
- * @param headers Monitoring headers for request tracking
148
+ * @param vaultAddress - Vault contract address
149
+ * @param nDays - Number of days of historical data to fetch (default 30, min 1)
150
+ * @param headers - Monitoring headers for request tracking
151
151
  * @returns Historical timeseries data with date keys
152
152
  */
153
153
  export declare function fetchVaultHistoricalTimeseries(vaultAddress: IAddress, nDays?: number, headers?: IWSMonitorHeaders): Promise<IHistoricalTimeseriesResponse>;
@@ -155,9 +155,9 @@ export declare function fetchVaultHistoricalTimeseries(vaultAddress: IAddress, n
155
155
  * Execute multiple promises with retry logic and allow partial failures.
156
156
  * Unlike Promise.all, continues execution if some promises fail.
157
157
  * Failed promises return null to maintain array index alignment.
158
- * @param promises Array of promises to execute
159
- * @param maxRetries Maximum retry attempts per promise
160
- * @param baseDelay Initial delay for exponential backoff
158
+ * @param promises - Array of promises to execute
159
+ * @param maxRetries - Maximum retry attempts per promise
160
+ * @param baseDelay - Initial delay for exponential backoff
161
161
  * @returns Array of results with null for failed promises
162
162
  */
163
163
  export declare function promiseSettle<T>(promises: Promise<T>[], maxRetries?: number, baseDelay?: number): Promise<T[]>;
@@ -50,7 +50,7 @@ let SDK_REQUEST_TIMEOUT_OVERRIDE = null;
50
50
  * call with no arguments) to clear the override and fall back to the
51
51
  * compiled-in `REQUEST_TIMEOUT_MS`.
52
52
  *
53
- * @param ms Positive number of milliseconds to wait before aborting, or
53
+ * @param ms - Positive number of milliseconds to wait before aborting, or
54
54
  * `null` to clear.
55
55
  */
56
56
  function setSdkRequestTimeout(ms = null) {
@@ -90,18 +90,23 @@ function buildRequestAbortSignal(options) {
90
90
  timeoutController.abort();
91
91
  }, timeoutMs);
92
92
  let signal = timeoutController.signal;
93
- let relayCleanup = () => { };
93
+ // No-op by default; replaced with a real listener-removal closure only when
94
+ // the manual relay fallback path below registers an 'abort' listener.
95
+ let relayCleanup = () => undefined;
94
96
  if (options?.signal) {
97
+ // Capture in a local so the cleanup closure below keeps the non-nullable
98
+ // narrowing (a closure over `options.signal` would otherwise be re-widened).
99
+ const callerSignal = options.signal;
95
100
  if (typeof AbortSignal.any === 'function') {
96
- signal = AbortSignal.any([timeoutController.signal, options.signal]);
101
+ signal = AbortSignal.any([timeoutController.signal, callerSignal]);
97
102
  }
98
- else if (options.signal.aborted) {
103
+ else if (callerSignal.aborted) {
99
104
  timeoutController.abort();
100
105
  }
101
106
  else {
102
107
  const relay = () => timeoutController.abort();
103
- options.signal.addEventListener('abort', relay, { once: true });
104
- relayCleanup = () => options.signal.removeEventListener('abort', relay);
108
+ callerSignal.addEventListener('abort', relay, { once: true });
109
+ relayCleanup = () => callerSignal.removeEventListener('abort', relay);
105
110
  }
106
111
  }
107
112
  return {
@@ -207,9 +212,9 @@ function buildAugustUrl(server, relativeUrl) {
207
212
  /**
208
213
  * Make authenticated requests to August backend services using API key.
209
214
  * Automatically logs errors with correlation IDs for debugging.
210
- * @param apiKey August API key for authentication
211
- * @param relativeUrl Endpoint path relative to base URL
212
- * @param options Request configuration including method and headers
215
+ * @param apiKey - August API key for authentication
216
+ * @param relativeUrl - Endpoint path relative to base URL
217
+ * @param options - Request configuration including method and headers
213
218
  * @returns Response object if successful
214
219
  * @throws Error with correlation ID if request fails
215
220
  */
@@ -272,8 +277,8 @@ async function fetchAugustWithKey(apiKey, relativeUrl, options) {
272
277
  /**
273
278
  * Make unauthenticated requests to August public API endpoints.
274
279
  * Used for fetching vault metadata and public market data.
275
- * @param relativeUrl Endpoint path relative to public API base URL
276
- * @param options Request configuration including method and headers
280
+ * @param relativeUrl - Endpoint path relative to public API base URL
281
+ * @param options - Request configuration including method and headers
277
282
  * @returns Response object if successful
278
283
  * @throws Error with correlation ID if request fails
279
284
  */
@@ -327,9 +332,9 @@ async function fetchAugustPublic(relativeUrl, options) {
327
332
  /**
328
333
  * Make authenticated requests using Bearer token authentication.
329
334
  * Typically used for user-specific operations requiring OAuth tokens.
330
- * @param bearerToken OAuth bearer token
331
- * @param relativeUrl Endpoint path relative to base URL
332
- * @param options Request configuration including method and headers
335
+ * @param bearerToken - OAuth bearer token
336
+ * @param relativeUrl - Endpoint path relative to base URL
337
+ * @param options - Request configuration including method and headers
333
338
  * @returns Response object if successful
334
339
  * @throws Error with correlation ID if request fails
335
340
  */
@@ -398,10 +403,10 @@ function isRetryableError(error) {
398
403
  /**
399
404
  * Wrap async operations with exponential backoff retry logic.
400
405
  * Retries on network errors with increasing delays between attempts.
401
- * @param fn Async function to execute with retry logic
402
- * @param maxRetries Maximum number of retry attempts
403
- * @param baseDelay Initial delay in milliseconds (doubles each retry)
404
- * @param shouldRetry Custom function to determine if error is retryable
406
+ * @param fn - Async function to execute with retry logic
407
+ * @param maxRetries - Maximum number of retry attempts
408
+ * @param baseDelay - Initial delay in milliseconds (doubles each retry)
409
+ * @param shouldRetry - Custom function to determine if error is retryable
405
410
  * @returns Result of successful function execution
406
411
  * @throws Last error if all retries exhausted
407
412
  */
@@ -422,13 +427,15 @@ async function withRetry(fn, maxRetries = 3, baseDelay = 1000, shouldRetry = isR
422
427
  throw error;
423
428
  }
424
429
  }
425
- throw lastError;
430
+ // Unreachable in practice: the final attempt re-throws inside the loop. This
431
+ // satisfies the compiler's control-flow analysis without a non-null assertion.
432
+ throw lastError ?? new Error('withRetry exhausted retries without an error');
426
433
  }
427
434
  /**
428
435
  * Fetch tokenized vault configurations from backend API.
429
436
  * Results are cached to reduce API calls. Optionally filter by specific vault address.
430
- * @param pool Optional vault address to filter results
431
- * @param headers Monitoring headers for request tracking
437
+ * @param pool - Optional vault address to filter results
438
+ * @param headers - Monitoring headers for request tracking
432
439
  * @returns Array of tokenized vault configurations
433
440
  */
434
441
  async function fetchTokenizedVault(pool, headers, loadSubaccounts, loadSnapshots) {
@@ -459,7 +466,7 @@ async function fetchTokenizedVault(pool, headers, loadSubaccounts, loadSnapshots
459
466
  }
460
467
  const queryString = params.toString();
461
468
  if (queryString) {
462
- endpoint += '?' + queryString;
469
+ endpoint += `?${queryString}`;
463
470
  }
464
471
  const tokenizedVaultsResponse = await fetchAugustPublic(endpoint, {
465
472
  headers: headers,
@@ -477,9 +484,9 @@ async function fetchTokenizedVault(pool, headers, loadSubaccounts, loadSnapshots
477
484
  /**
478
485
  * Fetch tokenized vault configurations from backend API.
479
486
  * Results are cached to reduce API calls. Optionally filter by specific vault address.
480
- * @param pool Optional vault address to filter results
481
- * @param headers Monitoring headers for request tracking
482
- * @param loadSubaccounts Optional flag to load subaccounts and EOA operators (defaults to true on API)
487
+ * @param pool - Optional vault address to filter results
488
+ * @param headers - Monitoring headers for request tracking
489
+ * @param loadSubaccounts - Optional flag to load subaccounts and EOA operators (defaults to true on API)
483
490
  * @returns Array of tokenized vault configurations
484
491
  */
485
492
  async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshots) {
@@ -509,7 +516,7 @@ async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshot
509
516
  }
510
517
  const queryString = params.toString();
511
518
  if (queryString) {
512
- endpoint += '?' + queryString;
519
+ endpoint += `?${queryString}`;
513
520
  }
514
521
  const tokenizedVaultsResponse = await fetchAugustPublic(endpoint, {
515
522
  headers: headers,
@@ -531,10 +538,10 @@ async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshot
531
538
  * Fetch current USD price for a token symbol or vault LP token.
532
539
  * For vault LP tokens, calculates share price using totalAssets/totalSupply ratio.
533
540
  * Falls back to CoinGecko if primary source fails.
534
- * @param symbol Token symbol or contract address
535
- * @param provider Optional web3 provider for on-chain price calculations
536
- * @param coinGeckoKey Optional CoinGecko API key for fallback pricing
537
- * @param headers Monitoring headers for request tracking
541
+ * @param symbol - Token symbol or contract address
542
+ * @param provider - Optional web3 provider for on-chain price calculations
543
+ * @param coinGeckoKey - Optional CoinGecko API key for fallback pricing
544
+ * @param headers - Monitoring headers for request tracking
538
545
  * @returns Token price in USD
539
546
  */
540
547
  async function fetchTokenPrice(symbol, provider, coinGeckoKey, headers) {
@@ -592,6 +599,15 @@ async function fetchTokenPrice(symbol, provider, coinGeckoKey, headers) {
592
599
  PRICE_REQUESTS.set(cacheKey, pricePromise);
593
600
  return pricePromise;
594
601
  }
602
+ // Normalize both raw integers to the same decimal scale BEFORE dividing —
603
+ // dividing the raw bigints first floors the ratio to ~1 and loses all
604
+ // fractional precision. Returns 1 for an empty vault (priced 1:1).
605
+ function normalizedSharePrice(totalAssets, totalSupply, decimals) {
606
+ const supply = Number((0, core_1.toNormalizedBn)(totalSupply, decimals).normalized);
607
+ if (!supply)
608
+ return 1;
609
+ return Number((0, core_1.toNormalizedBn)(totalAssets, decimals).normalized) / supply;
610
+ }
595
611
  /**
596
612
  * Internal price fetching implementation.
597
613
  * This is separated to allow caching and request deduplication in the public function.
@@ -616,7 +632,7 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
616
632
  const sharePrice = await vaultContract.getSharePrice();
617
633
  return Number((0, core_1.toNormalizedBn)(sharePrice, decimals).normalized);
618
634
  }
619
- catch (e) {
635
+ catch {
620
636
  throw new Error('failed to fetch token price for evm-2 vault');
621
637
  }
622
638
  }
@@ -640,12 +656,12 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
640
656
  vaultContract.decimals(),
641
657
  ]);
642
658
  const decimals = Number(rawDecimals);
643
- const ratio = (totalAssets || BigInt(0)) / (totalSupply || BigInt(0)) || 1;
644
- return json.price * Number((0, core_1.toNormalizedBn)(ratio, decimals).normalized);
659
+ const sharePrice = normalizedSharePrice(totalAssets, totalSupply, decimals);
660
+ return json.price * sharePrice;
645
661
  }
646
662
  return json.price;
647
663
  }
648
- catch (e) {
664
+ catch {
649
665
  // Fallback to CoinGecko if primary source fails
650
666
  const fallbackPrice = await (0, fetcher_1.fetchTokenPricesFromCoinGecko)(symbol, coinGeckoKey);
651
667
  if (foundVaultLpAsset && provider) {
@@ -656,8 +672,8 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
656
672
  vaultContract.decimals(),
657
673
  ]);
658
674
  const decimals = Number(rawDecimals);
659
- const ratio = (totalAssets || BigInt(0)) / (totalSupply || BigInt(0)) || 1;
660
- return fallbackPrice * Number((0, core_1.toNormalizedBn)(ratio, decimals).normalized);
675
+ const sharePrice = normalizedSharePrice(totalAssets, totalSupply, decimals);
676
+ return fallbackPrice * sharePrice;
661
677
  }
662
678
  if (fallbackPrice) {
663
679
  return fallbackPrice;
@@ -669,9 +685,9 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
669
685
  }
670
686
  /**
671
687
  * Fetch token price by contract address and chain ID from August price server.
672
- * @param address Token contract address
673
- * @param chainId Network chain ID
674
- * @param headers Optional monitoring headers for request tracking
688
+ * @param address - Token contract address
689
+ * @param chainId - Network chain ID
690
+ * @param headers - Optional monitoring headers for request tracking
675
691
  * @returns Token price in USD, or 0 if not found
676
692
  */
677
693
  async function fetchTokenPriceByAddress(address, chainId, headers) {
@@ -703,51 +719,53 @@ async function fetchTokenPriceByAddress(address, chainId, headers) {
703
719
  /**
704
720
  * Fetch active loans for a specific vault from backend API.
705
721
  * Results are cached per vault and chain to reduce API calls.
706
- * @param pool Vault address
707
- * @param chainId Network chain ID
708
- * @param headers Monitoring headers for request tracking
722
+ * @param pool - Vault address
723
+ * @param chainId - Network chain ID
724
+ * @param headers - Monitoring headers for request tracking
709
725
  * @returns Array of active loan objects
710
726
  */
711
727
  async function fetchTokenizedVaultLoans(pool, chainId, headers) {
712
728
  const key = `loans-${chainId}-${pool}`;
713
729
  let loans;
714
- if (cache_1.CACHE.get(key)) {
715
- loans = cache_1.CACHE.get(key);
730
+ const cached = await (0, cache_1.getSafeCache)(key);
731
+ if (cached) {
732
+ loans = cached;
716
733
  }
717
734
  else {
718
735
  const tokenizedVaultsResponse = await fetchAugustPublic(core_2.WEBSERVER_ENDPOINTS.public.tokenizedVault.loans(pool, chainId, true), { headers: headers });
719
736
  loans = (await tokenizedVaultsResponse.json()).loans;
720
- cache_1.CACHE.set(key, loans);
737
+ await (0, cache_1.setSafeCache)(key, loans);
721
738
  }
722
739
  return loans?.filter((l) => l.state.toLowerCase() === 'active');
723
740
  }
724
741
  /**
725
742
  * Fetch subaccount loans for a specific tokenized vault (lending pool).
726
743
  * Retrieves all active subaccount loan data from the backend.
727
- * @param pool Vault address
728
- * @param chainId Network chain ID
729
- * @param headers Monitoring headers for request tracking
744
+ * @param pool - Vault address
745
+ * @param chainId - Network chain ID
746
+ * @param headers - Monitoring headers for request tracking
730
747
  * @returns Array of active subaccount loan objects
731
748
  */
732
749
  async function fetchTokenizedVaultSubaccountLoans(pool, chainId, headers) {
733
750
  const key = `subaccount-loans-${chainId}-${pool}`;
734
751
  let loans;
735
- if (cache_1.CACHE.get(key)) {
736
- loans = cache_1.CACHE.get(key);
752
+ const cached = await (0, cache_1.getSafeCache)(key);
753
+ if (cached) {
754
+ loans = cached;
737
755
  }
738
756
  else {
739
757
  const tokenizedVaultsResponse = await fetchAugustPublic(core_2.WEBSERVER_ENDPOINTS.public.tokenizedVault.subaccountLoans(pool, chainId, true), { headers: headers });
740
758
  loans = (await tokenizedVaultsResponse.json()).loans;
741
- cache_1.CACHE.set(key, loans);
759
+ await (0, cache_1.setSafeCache)(key, loans);
742
760
  }
743
761
  return loans?.filter((l) => l.state.toLowerCase() === 'active');
744
762
  }
745
763
  /**
746
764
  * Fetch historical timeseries data for a specific vault.
747
765
  * Returns TVL, APY, PnL, and share price data over time.
748
- * @param vaultAddress Vault contract address
749
- * @param nDays Number of days of historical data to fetch (default 30, min 1)
750
- * @param headers Monitoring headers for request tracking
766
+ * @param vaultAddress - Vault contract address
767
+ * @param nDays - Number of days of historical data to fetch (default 30, min 1)
768
+ * @param headers - Monitoring headers for request tracking
751
769
  * @returns Historical timeseries data with date keys
752
770
  */
753
771
  async function fetchVaultHistoricalTimeseries(vaultAddress, nDays, headers) {
@@ -768,9 +786,9 @@ async function fetchVaultHistoricalTimeseries(vaultAddress, nDays, headers) {
768
786
  * Execute multiple promises with retry logic and allow partial failures.
769
787
  * Unlike Promise.all, continues execution if some promises fail.
770
788
  * Failed promises return null to maintain array index alignment.
771
- * @param promises Array of promises to execute
772
- * @param maxRetries Maximum retry attempts per promise
773
- * @param baseDelay Initial delay for exponential backoff
789
+ * @param promises - Array of promises to execute
790
+ * @param maxRetries - Maximum retry attempts per promise
791
+ * @param baseDelay - Initial delay for exponential backoff
774
792
  * @returns Array of results with null for failed promises
775
793
  */
776
794
  async function promiseSettle(promises, maxRetries = 3, baseDelay = 1000) {
@@ -1,4 +1,4 @@
1
- import { IAddress, IVaultAdapterConfig } from '../../types';
1
+ import type { IAddress, IVaultAdapterConfig } from '../../types';
2
2
  /**
3
3
  * Get adapter configuration for a vault
4
4
  */
@@ -18,12 +18,13 @@ export declare const filterOutBySize: (usdAmount: number) => boolean;
18
18
  export declare function toTitleCase(str: string, type?: 'camel'): string;
19
19
  export declare function truncate(s: string, amount?: number): string;
20
20
  /**
21
- * @function round formats any type number value to a standard
21
+ * Formats any numeric value (number, string, or bigint) to a standardized string.
22
22
  *
23
- * @param value amount to be formatted
24
- * @param options.showing amount of decimals to cut off at
25
- * @param options.usd if wanting to display USD value
26
- * @param options.decimals if passing type bigint, how many decimals to parse to
23
+ * @param value - amount to be formatted
24
+ * @param options - formatting options:
25
+ * `showing` is the number of decimals to cut off at (or `'all'`);
26
+ * `usd` toggles USD-value display;
27
+ * `decimals` is how many decimals to parse to when `value` is a bigint.
27
28
  *
28
29
  * @returns standardized string type value
29
30
  */
@@ -44,22 +45,24 @@ export declare function prepareDateForDb(date: string | Date): string;
44
45
  /**
45
46
  * Arrays
46
47
  */
47
- export declare function orderObjArrByDate(objectArray: any[], options?: {
48
+ export declare function orderObjArrByDate<T extends Record<string, unknown>>(objectArray: T[], options?: {
48
49
  key?: string;
49
50
  order?: 'asc' | 'desc';
50
- }): any[];
51
+ }): T[];
51
52
  /**
52
- * Calculate weights based on a specific property in array of objects
53
- * @param {Array<Object>} data - Array of objects to calculate weights for
54
- * @param {string} weightProperty - Property name to base weights on
55
- * @returns {Array<Object>} Original data with weights added
53
+ * Calculate weights based on a specific property in array of objects.
54
+ * @param data - Array of objects to calculate weights for
55
+ * @param weightProperty - Property name to base weights on
56
+ * @returns Original data with each item's `weight` added
56
57
  */
57
- export declare function calculateWeights(data?: Array<any>, weightProperty?: string): any[];
58
+ export declare function calculateWeights<T extends Record<string, unknown>>(data?: T[], weightProperty?: string): Array<T & {
59
+ weight: number;
60
+ }>;
58
61
  /**
59
- * Calculate weighted average for array of objects
60
- * @param {Array<Object>} data - Array of objects with values
61
- * @param {string} valueProperty - Property name containing the value to average
62
- * @param {string} [weightProperty] - Optional property to base weights on
63
- * @returns {number} Weighted average
62
+ * Calculate weighted average for array of objects.
63
+ * @param data - Array of objects with values
64
+ * @param valueProperty - Property name containing the value to average
65
+ * @param weightProperty - Optional property to base weights on
66
+ * @returns Weighted average
64
67
  */
65
- export declare function calculateWeightedAverage(data?: Array<any>, valueProperty?: string, weightProperty?: string): any;
68
+ export declare function calculateWeightedAverage<T extends Record<string, unknown>>(data?: T[], valueProperty?: string, weightProperty?: string): number;
@@ -67,7 +67,7 @@ function toNormalizedBn(value, decimals = 18) {
67
67
  function getFallbackRpcUrls(chainId) {
68
68
  return web3_1.FALLBACK_RPC_URLS[chainId] || [];
69
69
  }
70
- const filterOutBySize = (usdAmount) => usdAmount > 3000;
70
+ const filterOutBySize = (usdAmount) => usdAmount > 3_000;
71
71
  exports.filterOutBySize = filterOutBySize;
72
72
  /**
73
73
  * Formatters
@@ -120,12 +120,13 @@ function truncate(s, amount) {
120
120
  return `${s.slice(0, amount ? amount : 4)}...${s.slice(amount ? amount * -1 : -4)}`;
121
121
  }
122
122
  /**
123
- * @function round formats any type number value to a standard
123
+ * Formats any numeric value (number, string, or bigint) to a standardized string.
124
124
  *
125
- * @param value amount to be formatted
126
- * @param options.showing amount of decimals to cut off at
127
- * @param options.usd if wanting to display USD value
128
- * @param options.decimals if passing type bigint, how many decimals to parse to
125
+ * @param value - amount to be formatted
126
+ * @param options - formatting options:
127
+ * `showing` is the number of decimals to cut off at (or `'all'`);
128
+ * `usd` toggles USD-value display;
129
+ * `decimals` is how many decimals to parse to when `value` is a bigint.
129
130
  *
130
131
  * @returns standardized string type value
131
132
  */
@@ -133,7 +134,7 @@ function round(value, options) {
133
134
  // standardize to string
134
135
  let _value;
135
136
  if (typeof value === 'bigint') {
136
- _value = toNormalizedBn(value, options.decimals ?? web3_1.FALLBACK_DECIMALS).normalized;
137
+ _value = toNormalizedBn(value, options?.decimals ?? web3_1.FALLBACK_DECIMALS).normalized;
137
138
  }
138
139
  else {
139
140
  _value = String(value);
@@ -202,7 +203,7 @@ function loanStateToReadable(loanState) {
202
203
  */
203
204
  function dateToUnix(date) {
204
205
  if (!date)
205
- return Math.floor(new Date().getTime());
206
+ return Math.floor(Date.now());
206
207
  return Math.floor(new Date(date).getTime());
207
208
  }
208
209
  function unixToDate(epoch) {
@@ -230,19 +231,20 @@ function prepareDateForDb(date) {
230
231
  function orderObjArrByDate(objectArray, options) {
231
232
  const selectedOrder = options?.order ?? 'desc';
232
233
  const selectedKey = options?.key ?? 'date';
234
+ const toTime = (item) => new Date(item[selectedKey]).valueOf();
233
235
  return objectArray.sort((a, b) => {
234
236
  // Turn your strings into dates, and then subtract them
235
237
  // to get a value that is either negative, positive, or zero.
236
238
  if (selectedOrder === 'asc')
237
- return (new Date(a[selectedKey]).valueOf() - new Date(b[selectedKey]).valueOf());
238
- return (new Date(b[selectedKey]).valueOf() - new Date(a[selectedKey]).valueOf());
239
+ return toTime(a) - toTime(b);
240
+ return toTime(b) - toTime(a);
239
241
  });
240
242
  }
241
243
  /**
242
- * Calculate weights based on a specific property in array of objects
243
- * @param {Array<Object>} data - Array of objects to calculate weights for
244
- * @param {string} weightProperty - Property name to base weights on
245
- * @returns {Array<Object>} Original data with weights added
244
+ * Calculate weights based on a specific property in array of objects.
245
+ * @param data - Array of objects to calculate weights for
246
+ * @param weightProperty - Property name to base weights on
247
+ * @returns Original data with each item's `weight` added
246
248
  */
247
249
  function calculateWeights(data, weightProperty) {
248
250
  if (!data || data.length === 0 || !weightProperty)
@@ -256,16 +258,16 @@ function calculateWeights(data, weightProperty) {
256
258
  }));
257
259
  }
258
260
  /**
259
- * Calculate weighted average for array of objects
260
- * @param {Array<Object>} data - Array of objects with values
261
- * @param {string} valueProperty - Property name containing the value to average
262
- * @param {string} [weightProperty] - Optional property to base weights on
263
- * @returns {number} Weighted average
261
+ * Calculate weighted average for array of objects.
262
+ * @param data - Array of objects with values
263
+ * @param valueProperty - Property name containing the value to average
264
+ * @param weightProperty - Optional property to base weights on
265
+ * @returns Weighted average
264
266
  */
265
267
  function calculateWeightedAverage(data, valueProperty, weightProperty) {
266
268
  if (!data || data.length === 0 || !valueProperty)
267
269
  return 0;
268
- let weightedData = data;
270
+ let weightedData;
269
271
  // If no weightProperty specified, use equal weights
270
272
  if (!weightProperty) {
271
273
  weightedData = data.map((item) => ({
@@ -1,4 +1,4 @@
1
- import { IAddress, IChainId, IExplorerType } from '../../types';
1
+ import type { IAddress, IChainId, IExplorerType } from '../../types';
2
2
  /**
3
3
  * Generate a block-explorer URL for an address or transaction hash.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { Signer, Wallet } from 'ethers';
1
+ import { type Signer, type Wallet } from 'ethers';
2
2
  /**
3
3
  * Signer Compatibility Helpers
4
4
  *
@@ -1,4 +1,4 @@
1
- import { IAddress } from '../../types';
1
+ import type { IAddress } from '../../types';
2
2
  /**
3
3
  * Resolve the `SwapRouter` address for a chain.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
1
+ import type { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
2
2
  /** Classify an address by chain family (evm / solana / stellar / sui). */
3
3
  export declare function getAddressChainType(address: string): ChainType;
4
4
  export declare function getVaultVersion(vault: string): IVaultVersion | undefined;