Repository navigation
fix(trade): size token approvals from the bound quote input - #846
Conversation
Approval sizing read the quote input as `inputAmount || inAmount`, while the intent and maximum-input checks read `inputAmount ?? inAmount` through quoteInputAmountRaw. A quote with an empty inputAmount passed the maximum-input check as 0 but was approved for its inAmount. Every approval site (plan preview, dry-run preflight, and the Privy, WalletConnect and local execute branches) now reads the shared accessor, so such a quote hits the existing zero-input refusal before any approval. The plan's Sell row and formatQuote's Input line read the same field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quoteInputAmountRaw returned an empty inputAmount unchanged, and
BigInt('') is 0, so the maximum-input check accepted an exactOut quote
with an empty inputAmount as a zero input. Approval sizing now refuses
such a quote, but one with no approval step (or a Solana quote) still
passed with nothing binding the real input.
An empty or blank inputAmount now counts as missing, without falling
through to inAmount, so the intent, maximum-input and native-value
checks refuse it. formatQuote shows '?' for a missing input, and the
quote-time --max-input filter reads the same accessor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nansen-pr-reviewer summaryThe change consistently centralizes quote input resolution across validation, display, spend ceilings, native-value checks, and ERC-20 approval sizing. Empty inputAmount values now fail closed instead of falling back to inAmount, and the added tests cover the relevant signing paths and output behavior. No correctness or security issues found. Deterministic check: success — No issues found Risk: 2/5 (Low) ✅ Auto-approved — Deterministic gates passed: severity thresholds met, recommendation "approve", risk level 2/5 within threshold 3. Token usage: 102,072 input, 1,014 output, 6,534 cache read | Usage Guide Cooldown: for the next 10 minutes (counting from when this review finished), new pushes to this PR will not trigger another review — the next push after the window expires will. Need a fresh review sooner? Comment |
There was a problem hiding this comment.
✅ Auto-approved by Nansen review
Deterministic gates passed: severity thresholds met, recommendation "approve", risk level 2/5 within threshold 3.
- The deterministic severity check passed: No issues found
- Risk level 2/5 (Low)
- The model recommended: approve
Approval was decided by deterministic gates, not by the model. The model's recommendation can block auto-approval but never cause it.
What
trade executenow sizes ERC-20 approvals from the same quote input field that the input-amount and maximum-input checks read (quoteInputAmountRaw, i.e.inputAmount ?? inAmount).Why
Approval sizing read the input as
inputAmount || inAmount; the intent binding and the maximum-input check readinputAmount ?? inAmount. For a quote withinputAmount: "", the maximum-input check saw 0 while the approval was sized frominAmount. The approval was still capped by the persisted maximum, so this was a consistency gap rather than a drain, but the approval amount was never checked against the field the checks bind.How
quoteInputAmountRaw(quote)toapprovalAmountForSwap. A missing or non-integer input clamps to 0 and hits the existing "zero input amount" refusal (preflight) or skip (execute), before any approval.quoteInputAmountRawnow treats an empty or blankinputAmountas missing, without falling through toinAmount. Before,BigInt('')read it as a zero input, so the maximum-input check accepted an exactOut quote with an empty input, including one with no approval step. The intent, maximum-input and native-value checks now refuse it as missing.formatQuote's Input line and the quote-time--max-inputfilter read the same accessor; a missing input shows as?.Before / after (exactOut,
inputAmount: "",inAmount: "900000", max input 1000000)--dry-runTesting
mainon the approval being sized frominAmountand passes here. Unit tests cover the accessor,assertInputWithinMaxandassertQuoteMatchesRequestwith an empty input, an exactOut quote with no approval step, andformatQuote.npm testandnpm run lintpass.mainand this branch over 14 scenarios (null/missing/"0"/blank inputs, fallback to a second quote, concurrent executes, exactIn): fixed, no regressions.🤖 Generated with Claude Code