Skip to content

fix(trade): size token approvals from the bound quote input - #846

Merged
kome12 merged 2 commits into
mainfrom
fix/approval-sizing-quote-input-accessor
Nov 17, 2026
Merged

kome12 merged 2 commits into
mainfrom
fix/approval-sizing-quote-input-accessor

Conversation

@kome12

@kome12 kome12 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What

trade execute now 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 read inputAmount ?? inAmount. For a quote with inputAmount: "", the maximum-input check saw 0 while the approval was sized from inAmount. 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

  • Every approval site (plan preview, dry-run preflight, and the Privy, WalletConnect and local execute branches) passes quoteInputAmountRaw(quote) to approvalAmountForSwap. A missing or non-integer input clamps to 0 and hits the existing "zero input amount" refusal (preflight) or skip (execute), before any approval.
  • quoteInputAmountRaw now treats an empty or blank inputAmount as missing, without falling through to inAmount. 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.
  • The dry-run plan's Sell row, formatQuote's Input line and the quote-time --max-input filter read the same accessor; a missing input shows as ?.

Before / after (exactOut, inputAmount: "", inAmount: "900000", max input 1000000)

path before after
WalletConnect approval sent for 927000 refused: quote is missing the input amount, no approval
local / Privy "Approval required", approval tx refused: missing the input amount
--dry-run plan: Sell 900000, approval scoped to 927000 refused: missing the input amount
exactOut, no approval step passed the maximum-input check as 0, went on to signing refused: missing the input amount

Testing

  • New tests for the WalletConnect, local, Privy and dry-run paths; each fails on main on the approval being sized from inAmount and passes here. Unit tests cover the accessor, assertInputWithinMax and assertQuoteMatchesRequest with an empty input, an exactOut quote with no approval step, and formatQuote.
  • npm test and npm run lint pass.
  • An independent check compared main and 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

kome12 and others added 2 commits November 17, 2026 09:55
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

Copy link
Copy Markdown

nansen-pr-reviewer summary

The 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 @nansen-pr-reviewer[bot] re-review.

@nansen-pr-reviewer nansen-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@kome12 kome12 self-assigned this Nov 17, 2026
@kome12
kome12 merged commit d0570ff into main Nov 17, 2026
16 checks passed
@kome12
kome12 deleted the fix/approval-sizing-quote-input-accessor branch November 17, 2026 04:37
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant