@augustdigital/sdk 8.5.0 → 8.6.1

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 (108) 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/instrumentation.js +7 -11
  25. package/lib/core/analytics/sentry-runtime.js +1 -1
  26. package/lib/core/analytics/sentry.d.ts +3 -3
  27. package/lib/core/analytics/sentry.js +31 -5
  28. package/lib/core/analytics/types.d.ts +1 -1
  29. package/lib/core/analytics/user-identity.d.ts +2 -2
  30. package/lib/core/analytics/user-identity.js +1 -1
  31. package/lib/core/analytics/version.d.ts +1 -1
  32. package/lib/core/analytics/version.js +1 -1
  33. package/lib/core/base.class.d.ts +3 -3
  34. package/lib/core/base.class.js +10 -4
  35. package/lib/core/constants/adapters.d.ts +1 -1
  36. package/lib/core/constants/core.d.ts +2 -0
  37. package/lib/core/constants/core.js +6 -0
  38. package/lib/core/constants/swap-router.d.ts +37 -1
  39. package/lib/core/constants/swap-router.js +41 -1
  40. package/lib/core/constants/vaults.d.ts +1 -1
  41. package/lib/core/constants/web3.d.ts +1 -1
  42. package/lib/core/constants/web3.js +0 -3
  43. package/lib/core/errors/index.d.ts +2 -2
  44. package/lib/core/errors/index.js +9 -0
  45. package/lib/core/fetcher.d.ts +39 -39
  46. package/lib/core/fetcher.js +75 -57
  47. package/lib/core/helpers/adapters.d.ts +1 -1
  48. package/lib/core/helpers/chain-error.d.ts +66 -0
  49. package/lib/core/helpers/chain-error.js +174 -0
  50. package/lib/core/helpers/core.d.ts +21 -18
  51. package/lib/core/helpers/core.js +22 -20
  52. package/lib/core/helpers/explorer-link.d.ts +1 -1
  53. package/lib/core/helpers/signer.d.ts +1 -1
  54. package/lib/core/helpers/swap-router.d.ts +1 -1
  55. package/lib/core/helpers/vault-version.d.ts +1 -1
  56. package/lib/core/helpers/vaults.d.ts +1 -1
  57. package/lib/core/helpers/web3.d.ts +2 -2
  58. package/lib/core/helpers/web3.js +9 -9
  59. package/lib/core/index.d.ts +1 -0
  60. package/lib/core/index.js +1 -0
  61. package/lib/core/vault-metadata.d.ts +1 -1
  62. package/lib/core/version-check.js +1 -1
  63. package/lib/evm/methods/crossChainVault.js +1 -1
  64. package/lib/evm/types/crossChain.js +1 -1
  65. package/lib/main.d.ts +1 -1
  66. package/lib/main.js +7 -0
  67. package/lib/modules/sub-accounts/fetcher.d.ts +2 -2
  68. package/lib/modules/sub-accounts/main.d.ts +2 -2
  69. package/lib/modules/sub-accounts/main.js +1 -1
  70. package/lib/modules/sub-accounts/utils.d.ts +1 -1
  71. package/lib/modules/vaults/adapter.helpers.d.ts +3 -3
  72. package/lib/modules/vaults/fetcher.d.ts +25 -0
  73. package/lib/modules/vaults/fetcher.js +51 -1
  74. package/lib/modules/vaults/getters.d.ts +50 -50
  75. package/lib/modules/vaults/getters.js +68 -67
  76. package/lib/modules/vaults/main.js +3 -1
  77. package/lib/modules/vaults/read.actions.d.ts +2 -2
  78. package/lib/modules/vaults/read.actions.js +26 -12
  79. package/lib/modules/vaults/utils/call-data-decoder.d.ts +1 -1
  80. package/lib/modules/vaults/utils.d.ts +19 -3
  81. package/lib/modules/vaults/utils.js +39 -6
  82. package/lib/modules/vaults/write.actions.js +73 -7
  83. package/lib/polyfills.js +3 -3
  84. package/lib/sdk.d.ts +1409 -1198
  85. package/lib/services/coingecko/fetcher.d.ts +10 -9
  86. package/lib/services/coingecko/fetcher.js +22 -18
  87. package/lib/services/debank/fetcher.d.ts +1 -1
  88. package/lib/services/debank/utils.d.ts +1 -1
  89. package/lib/services/debank/utils.js +1 -1
  90. package/lib/services/layerzero/deposits.d.ts +1 -1
  91. package/lib/services/layerzero/redeems.d.ts +1 -1
  92. package/lib/services/octavfi/fetcher.d.ts +1 -1
  93. package/lib/services/octavfi/types.d.ts +1 -1
  94. package/lib/services/octavfi/utils.d.ts +2 -2
  95. package/lib/services/subgraph/fetcher.js +1 -1
  96. package/lib/services/subgraph/vaults.js +86 -3
  97. package/lib/services/swap-quotes/index.d.ts +9 -0
  98. package/lib/services/swap-quotes/index.js +2 -1
  99. package/lib/services/swap-quotes/paraswap.d.ts +8 -0
  100. package/lib/services/swap-quotes/paraswap.js +8 -0
  101. package/lib/types/pools.d.ts +2 -2
  102. package/lib/types/staking.d.ts +1 -1
  103. package/lib/types/sub-accounts.d.ts +1 -1
  104. package/lib/types/subgraph.d.ts +10 -1
  105. package/lib/types/vaults.d.ts +26 -0
  106. package/lib/types/web3.d.ts +1 -1
  107. package/lib/types/webserver.d.ts +2 -2
  108. 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
  */
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Is this error a wallet/user rejection of a transaction or signature request?
3
+ *
4
+ * Detects ethers v6's `ACTION_REJECTED` code, the EIP-1193 `4001`
5
+ * ("User rejected the request") code (top-level or nested), and the common
6
+ * human-readable phrasings as a fallback for providers that omit a code.
7
+ *
8
+ * @param error - The caught value, of unknown type.
9
+ * @returns `true` when the failure was the user declining in their wallet.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * try { await vault.deposit(...); }
14
+ * catch (e) {
15
+ * if (isUserRejectionError(e)) return; // user cancelled — not an error
16
+ * throw e;
17
+ * }
18
+ * ```
19
+ */
20
+ export declare function isUserRejectionError(error: unknown): boolean;
21
+ /**
22
+ * Is this error a routine on-chain read revert rather than a real failure?
23
+ *
24
+ * Reading a function a contract doesn't implement, or an address that holds no
25
+ * (or incompatible) bytecode, reverts — a normal outcome when the SDK probes
26
+ * heterogeneous vaults. Matches ethers' `CALL_EXCEPTION` code and the
27
+ * message variants emitted by ethers and viem (`missing revert data`,
28
+ * `execution reverted`, `call revert exception`, and the bare `reverted`
29
+ * phrasing such as `the contract function "totalAssets" reverted`).
30
+ *
31
+ * Scope note: callers apply this on **read** paths only. A reverted *write*
32
+ * (a tx that failed on-chain) is a genuine error and is intentionally not
33
+ * demoted by this predicate's use in `write.actions`.
34
+ *
35
+ * @param error - The caught value, of unknown type.
36
+ * @returns `true` when the failure is an expected/benign contract revert.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * try { return await vaultContract.maxDepositAmount(); }
41
+ * catch (e) {
42
+ * logChainError('maxDeposit', e, isExpectedRevertError(e));
43
+ * throw e;
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function isExpectedRevertError(error: unknown): boolean;
48
+ /**
49
+ * Log a caught chain error at the severity its category warrants, without
50
+ * swallowing it. When `isBenign` is `true` the failure is recorded as a `warn`
51
+ * (a Sentry breadcrumb that rides along with the next real issue, not a billed
52
+ * standalone issue); otherwise it is logged at `error` (a Sentry issue). The
53
+ * caller is still responsible for re-throwing — this only routes telemetry.
54
+ *
55
+ * Pass the benign decision explicitly (via {@link isUserRejectionError} or
56
+ * {@link isExpectedRevertError}) so the call site documents *why* the demotion
57
+ * is safe and each path opts into only the category that applies to it.
58
+ *
59
+ * @param tag - Low-cardinality call-site label (e.g. `'deposit'`), used as the
60
+ * Sentry breadcrumb/issue grouping key.
61
+ * @param error - The caught value, of unknown type.
62
+ * @param isBenign - `true` to demote to `warn`; `false` to keep at `error`.
63
+ * @param context - Optional structured context attached to the log entry. It is
64
+ * sanitized by the logger before transport.
65
+ */
66
+ export declare function logChainError(tag: string, error: unknown, isBenign: boolean, context?: Record<string, unknown>): void;