Skip to content

chore(scripts): quote-compare diagnostic for amount-too-small gate#135

Closed
passandscore wants to merge 2 commits into
mainfrom
amount-to-small
Closed

chore(scripts): quote-compare diagnostic for amount-too-small gate#135
passandscore wants to merge 2 commits into
mainfrom
amount-to-small

Conversation

@passandscore
Copy link
Copy Markdown
Contributor

Summary

  • Adds scripts/quote-compare.ts, an on-demand CLI that fetches Uniswap V3 QuoterV2 and Barter /route quotes side-by-side for a given pair and sell amount, then compares both against a CoinGecko reference price.
  • Produces an attribution verdict (which side is the outlier) and prints tailored developer options only for the determined outlier — so on-call can immediately tell whether an "Amount too small to swap" UI block is Uniswap's fault (thin single-hop pool) or Barter's fault / routing-overhead-on-small-trades.
  • No runtime/app code changes. Dev-only script.

Why

The swap UI's "Amount too small to swap" copy actually fires on a >2% disagreement between Uniswap and Barter quotes (MAX_SLIPPAGE_PCT in src/hooks/use-barter-validation.ts:10), not on the sell amount being literally small. Without this tool we had no way to quickly attribute which router was the outlier when a user reports the message.

Usage

npx tsx scripts/quote-compare.ts \
  --source 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 \
  --target 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 \
  --sell   9490316901682634

Env vars required: ALCHEMY_API_KEY, BARTER_API_KEY (already present for the app). Optional: COINGECKO_API_KEY for higher rate limits on the reference price.

Test plan

  • Run with the reported WETH→USDC example above and verify the output attributes the outlier correctly.
  • Run with a liquid pair (e.g. USDC→USDT) and confirm shortfall stays well under 2% and the "Gate not triggered" path prints.
  • Run without COINGECKO_API_KEY and confirm the script still runs, skipping the attribution section gracefully.
  • Run with a nonexistent v3 pair and confirm the "Uniswap returned no quote on any fee tier" error fires cleanly.

Adds scripts/quote-compare.ts, a CLI that fetches Uniswap V3 QuoterV2 and
Barter /route quotes side-by-side and compares them against a CoinGecko
reference so on-call can attribute which side is responsible when the swap
button shows "Amount too small to swap" (>2% Uniswap/Barter disagreement).

Output prints inputs, quotes, the gate check, a CoinGecko-anchored
attribution verdict, and tailored developer options that only surface when
the gate actually fires and only for the determined outlier.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fastprotocolapp Ready Ready Preview, Comment Apr 22, 2026 5:03pm

Request Review

quote-compare.ts hit a viem readContract overload resolution bug in the
Next.js build where authorizationList was incorrectly required. Scripts
run via tsx and aren't part of the app bundle, so excluding them from
tsc's include keeps the main build green.

Also swapped erc20Abi for a minimal inline ABI in quote-compare.ts
(decimals + symbol only) for self-containment.
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