@augustdigital/sdk 8.9.0 → 8.10.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.
@@ -3,4 +3,4 @@
3
3
  * Generated during publish from package.json version
4
4
  * This file is gitignored and created at publish time
5
5
  */
6
- export declare const SDK_VERSION = "8.9.0";
6
+ export declare const SDK_VERSION = "8.10.0";
@@ -6,5 +6,5 @@ exports.SDK_VERSION = void 0;
6
6
  * Generated during publish from package.json version
7
7
  * This file is gitignored and created at publish time
8
8
  */
9
- exports.SDK_VERSION = '8.9.0';
9
+ exports.SDK_VERSION = '8.10.0';
10
10
  //# sourceMappingURL=version.js.map
@@ -45,6 +45,7 @@ export declare function isUserRejectionError(error: unknown): boolean;
45
45
  * ```
46
46
  */
47
47
  export declare function isExpectedRevertError(error: unknown): boolean;
48
+ export declare function isInsufficientFundsError(error: unknown): boolean;
48
49
  /**
49
50
  * Log a caught chain error at the severity its category warrants, without
50
51
  * swallowing it. When `isBenign` is `true` the failure is recorded as a `warn`
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUserRejectionError = isUserRejectionError;
4
4
  exports.isExpectedRevertError = isExpectedRevertError;
5
+ exports.isInsufficientFundsError = isInsufficientFundsError;
5
6
  exports.logChainError = logChainError;
6
7
  const logger_1 = require("../logger");
7
8
  /**
@@ -21,6 +22,9 @@ const logger_1 = require("../logger");
21
22
  * 2. **Expected on-chain read reverts** — reading a function a vault doesn't
22
23
  * implement, or an address with no/incompatible bytecode, reverts. This is a
23
24
  * routine outcome of probing heterogeneous vaults, not a defect.
25
+ * 3. **Underfunded sender accounts** — the node rejects the transaction because
26
+ * the sender can't cover gas (or, on rollups such as Citrea, the extra L1
27
+ * data-availability fee). This is a "top up your wallet" prompt, not a bug.
24
28
  *
25
29
  * These predicates let call sites demote exactly those cases to `warn` while
26
30
  * leaving genuine failures at `error`. They are intentionally dependency-free
@@ -77,6 +81,39 @@ function errorCodes(error) {
77
81
  }
78
82
  return codes;
79
83
  }
84
+ /**
85
+ * Collect every human-readable message string an error-like value carries,
86
+ * across the nested locations providers stash them in.
87
+ *
88
+ * Why this is separate from {@link errorText}: ethers v6 flattens a rejected
89
+ * `eth_estimateGas`/`eth_call` to a generic *top-level* `message` (e.g.
90
+ * `"missing revert data"`) while preserving the node's original JSON-RPC error
91
+ * one level down at `info.error.message`. The real reason (an insufficient-funds
92
+ * report, say) is therefore invisible to a top-level `.message` read. We scan
93
+ * the top-level message plus `error.message`, `info.error.message`,
94
+ * `cause.message`, and `cause.info.error.message` so a caller catches the reason
95
+ * whether it holds the raw provider error or an SDK error that wrapped it as
96
+ * `cause`.
97
+ *
98
+ * @param error - The caught value, of unknown type.
99
+ * @returns Every non-empty message string found (possibly empty array).
100
+ */
101
+ function nestedMessages(error) {
102
+ const out = [];
103
+ const push = (value) => {
104
+ if (typeof value === 'string' && value.length > 0)
105
+ out.push(value);
106
+ };
107
+ push(errorText(error));
108
+ if (error && typeof error === 'object') {
109
+ const e = error;
110
+ push(e.error?.message);
111
+ push(e.info?.error?.message);
112
+ push(e.cause?.message);
113
+ push(e.cause?.info?.error?.message);
114
+ }
115
+ return out;
116
+ }
80
117
  /**
81
118
  * Is this error a wallet/user rejection of a transaction or signature request?
82
119
  *
@@ -143,6 +180,65 @@ function isExpectedRevertError(error) {
143
180
  msg.includes('call revert exception') ||
144
181
  msg.includes('reverted'));
145
182
  }
183
+ /**
184
+ * Is this error the chain node reporting that the sender can't afford the
185
+ * transaction's gas/fee — i.e. the account needs topping up, not a defect?
186
+ *
187
+ * This is distinct from a contract revert, and easy to misclassify. When the
188
+ * node rejects `eth_estimateGas` for an underfunded account, ethers v6 discards
189
+ * the node's reason and surfaces a generic `CALL_EXCEPTION` / `"missing revert
190
+ * data"` at the top level — which {@link isExpectedRevertError} matches. The
191
+ * real reason survives only in the nested JSON-RPC error, so this predicate
192
+ * scans there (via `nestedMessages`). On a write path, check this **before**
193
+ * {@link isExpectedRevertError}, or a genuine funds shortfall reads as a benign
194
+ * revert.
195
+ *
196
+ * Matching is anchored to the node's pre-execution funds-check phrasings (see
197
+ * `INSUFFICIENT_FUNDS_PHRASES`), each of which carries a `for <purpose>`
198
+ * qualifier — `insufficient funds for gas`, `insufficient funds for transfer`,
199
+ * `not enough funds for L1 fee` (Citrea's data-availability fee), etc. This is
200
+ * deliberately narrower than a bare `"insufficient funds"` substring: a
201
+ * *contract revert reason* that merely contains the word "funds" (e.g.
202
+ * `execution reverted: insufficient funds in pool`) must stay a genuine failure,
203
+ * not be demoted to an ACCOUNT_NOT_FUNDED "top up gas" prompt.
204
+ *
205
+ * @param error - The caught value, of unknown type.
206
+ * @returns `true` when the failure is an unfunded/underfunded sender account.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * try { await vault.requestRedeem(...); }
211
+ * catch (e) {
212
+ * if (isInsufficientFundsError(e))
213
+ * throw new AugustValidationError(
214
+ * 'ACCOUNT_NOT_FUNDED',
215
+ * 'Add gas to continue',
216
+ * { cause: e },
217
+ * );
218
+ * throw e;
219
+ * }
220
+ * ```
221
+ */
222
+ /**
223
+ * The node pre-execution funds-check phrasings {@link isInsufficientFundsError}
224
+ * recognises, lower-cased. Each keeps the `for <purpose>` qualifier so the match
225
+ * is anchored to a funding rejection and can't be tripped by a contract revert
226
+ * reason that merely mentions "funds". `insufficient funds for gas` covers the
227
+ * geth/reth `"... for gas * price + value"` message; `not enough funds for l1
228
+ * fee` is the rollup (Citrea) data-availability-fee shortfall.
229
+ */
230
+ const INSUFFICIENT_FUNDS_PHRASES = [
231
+ 'insufficient funds for gas',
232
+ 'insufficient funds for transfer',
233
+ 'insufficient funds for intrinsic transaction cost',
234
+ 'not enough funds for l1 fee',
235
+ ];
236
+ function isInsufficientFundsError(error) {
237
+ return nestedMessages(error).some((raw) => {
238
+ const msg = raw.toLowerCase();
239
+ return INSUFFICIENT_FUNDS_PHRASES.some((phrase) => msg.includes(phrase));
240
+ });
241
+ }
146
242
  /**
147
243
  * Log a caught chain error at the severity its category warrants, without
148
244
  * swallowing it. When `isBenign` is `true` the failure is recorded as a `warn`
@@ -185,6 +185,39 @@ async function tryRecoverTxHash(error, signer, wait) {
185
185
  }
186
186
  return txHash;
187
187
  }
188
+ /**
189
+ * Rethrow a caught write-path error as a typed {@link AugustValidationError}
190
+ * when it is the chain node reporting the sender can't afford the transaction's
191
+ * gas/fee (see {@link isInsufficientFundsError}).
192
+ *
193
+ * Why: for an underfunded account ethers surfaces an opaque `CALL_EXCEPTION` /
194
+ * "missing revert data" that gives the caller no stable way to tell "user needs
195
+ * gas" apart from a genuine on-chain failure. Converting it to the
196
+ * `ACCOUNT_NOT_FUNDED` code lets a consuming UI branch on `err.code` (e.g. show
197
+ * a "top up to cover network fees" prompt) instead of string-matching. Every
198
+ * write path shares this so the classification is identical across
199
+ * deposit/redeem/approve rather than drifting per call site.
200
+ *
201
+ * A no-op when `isInsufficient` is `false`, so callers fall through to their
202
+ * existing handling unchanged. The caller passes the already-computed
203
+ * classification (it also feeds the telemetry-demotion decision) so
204
+ * {@link isInsufficientFundsError} runs once per catch, not twice.
205
+ *
206
+ * @param isInsufficient - Result of {@link isInsufficientFundsError} for
207
+ * `error`, computed once by the caller and shared with the benign-log flag.
208
+ * @param operation - Human-readable label for the attempted write (e.g.
209
+ * `'Request redeem'`), used verbatim in the thrown error's message.
210
+ * @param error - The caught value, of unknown type, preserved as the thrown
211
+ * error's `cause`.
212
+ * @param context - Structured context attached to the thrown error for logging.
213
+ * @throws {AugustValidationError} with code `ACCOUNT_NOT_FUNDED` when
214
+ * `isInsufficient` is `true`.
215
+ */
216
+ function throwIfInsufficientFunds(isInsufficient, operation, error, context) {
217
+ if (!isInsufficient)
218
+ return;
219
+ throw new core_1.AugustValidationError('ACCOUNT_NOT_FUNDED', `${operation} failed: insufficient native balance to cover gas/network fees`, { cause: error, context });
220
+ }
188
221
  async function approveCore(signer, options) {
189
222
  const { wallet, target, wait, amount, depositAsset } = options;
190
223
  const [goodWallet, goodPool] = [
@@ -293,7 +326,12 @@ async function approveCore(signer, options) {
293
326
  throw e;
294
327
  // A user declining the approval in their wallet is product behaviour, not
295
328
  // an SDK fault — demote it to a breadcrumb so it doesn't bill as an issue.
296
- (0, core_1.logChainError)('vaultApprove', e, (0, core_1.isUserRejectionError)(e), {
329
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
330
+ (0, core_1.logChainError)('vaultApprove', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
331
+ target,
332
+ amount,
333
+ });
334
+ throwIfInsufficientFunds(insufficientFunds, 'Approval', e, {
297
335
  target,
298
336
  amount,
299
337
  });
@@ -601,7 +639,13 @@ async function vaultDeposit(signer, options) {
601
639
  if (e instanceof core_1.AugustSDKError)
602
640
  throw e;
603
641
  // User-cancelled deposits are normal; only genuine failures stay at error.
604
- (0, core_1.logChainError)('deposit', e, (0, core_1.isUserRejectionError)(e), {
642
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
643
+ (0, core_1.logChainError)('deposit', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
644
+ target,
645
+ amount,
646
+ depositAsset,
647
+ });
648
+ throwIfInsufficientFunds(insufficientFunds, 'Deposit', e, {
605
649
  target,
606
650
  amount,
607
651
  depositAsset,
@@ -754,7 +798,12 @@ async function vaultRequestRedeem(signer, options) {
754
798
  if (e instanceof core_1.AugustSDKError)
755
799
  throw e;
756
800
  // User-cancelled redeem requests are normal; only genuine failures stay at error.
757
- (0, core_1.logChainError)('requestRedeem', e, (0, core_1.isUserRejectionError)(e), {
801
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
802
+ (0, core_1.logChainError)('requestRedeem', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
803
+ target,
804
+ amount,
805
+ });
806
+ throwIfInsufficientFunds(insufficientFunds, 'Request redeem', e, {
758
807
  target,
759
808
  amount,
760
809
  });
@@ -801,7 +850,15 @@ async function vaultRedeem(signer, options) {
801
850
  if (e instanceof core_1.AugustSDKError)
802
851
  throw e;
803
852
  // User-cancelled redeems are normal; only genuine failures stay at error.
804
- (0, core_1.logChainError)('redeem', e, (0, core_1.isUserRejectionError)(e), {
853
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
854
+ (0, core_1.logChainError)('redeem', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
855
+ target,
856
+ year,
857
+ month,
858
+ day,
859
+ receiverIndex,
860
+ });
861
+ throwIfInsufficientFunds(insufficientFunds, 'Redeem', e, {
805
862
  target,
806
863
  year,
807
864
  month,
@@ -899,7 +956,13 @@ async function depositNative(signer, options) {
899
956
  if (e instanceof core_1.AugustSDKError)
900
957
  throw e;
901
958
  // User-cancelled native deposits are normal; only genuine failures stay at error.
902
- (0, core_1.logChainError)('depositNative', e, (0, core_1.isUserRejectionError)(e), {
959
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
960
+ (0, core_1.logChainError)('depositNative', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
961
+ wrapperAddress,
962
+ receiver,
963
+ amount,
964
+ });
965
+ throwIfInsufficientFunds(insufficientFunds, 'Deposit native', e, {
903
966
  wrapperAddress,
904
967
  receiver,
905
968
  amount,
@@ -978,7 +1041,14 @@ async function rwaRedeemAsset(signer, options) {
978
1041
  if (e instanceof core_1.AugustSDKError)
979
1042
  throw e;
980
1043
  // User-cancelled RWA redeems are normal; only genuine failures stay at error.
981
- (0, core_1.logChainError)('rwaRedeemAsset', e, (0, core_1.isUserRejectionError)(e), {
1044
+ const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
1045
+ (0, core_1.logChainError)('rwaRedeemAsset', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
1046
+ target,
1047
+ asset,
1048
+ amount,
1049
+ minOut,
1050
+ });
1051
+ throwIfInsufficientFunds(insufficientFunds, 'RWA redeem', e, {
982
1052
  target,
983
1053
  asset,
984
1054
  amount,
package/lib/sdk.d.ts CHANGED
@@ -20191,6 +20191,8 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
20191
20191
  */
20192
20192
  export declare function isHubOnlyReceipt(vault: IAddress): boolean;
20193
20193
 
20194
+ export declare function isInsufficientFundsError(error: unknown): boolean;
20195
+
20194
20196
  /**
20195
20197
  * True when `NODE_ENV` is `'development'` or `'test'`. The SDK auto-disables
20196
20198
  * analytics in these environments so partners' local dev runs and Jest suites
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augustdigital/sdk",
3
- "version": "8.9.0",
3
+ "version": "8.10.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/sdk.d.ts",
6
6
  "keywords": [