Skip to content

fix(swap): forward caller slippage to jupiter instead of hardcoded 1%#599

Draft
gomesalexandre wants to merge 1 commit into
mainfrom
fix_jupiter_forward_tolerance
Draft

fix(swap): forward caller slippage to jupiter instead of hardcoded 1%#599
gomesalexandre wants to merge 1 commit into
mainfrom
fix_jupiter_forward_tolerance

Conversation

@gomesalexandre

Copy link
Copy Markdown
Contributor

what

JupiterProvider.GetQuote always sent slippageBps=100 (the 1% default) and ignored QuoteRequest.ToleranceBps entirely — a caller could neither tighten (e.g. 0.3% for a deep pool) nor loosen (e.g. 3% for a volatile one) the swap's slippage. Not a fund-loss (1% is a sane floor), but the requested tolerance was silently dropped.

how

Jupiter bakes the resulting min-out into the quote's otherAmountThreshold, which is cached in ProviderData and reused by BuildTx — so forwarding a positive tolerance at the quote call is sufficient (single-site fix). Honor req.ToleranceBps (same basis-point units) when positive; fall back to the 1% default when omitted or 0 (0 would demand exact-out and revert on any price movement). Regression test asserts the outgoing slippageBps tracks the requested tolerance, defaults to 100 when omitted, and falls back on 0.

risk

Low — default behavior is unchanged; only an explicit positive tolerance now takes effect. go build ./sdk/swap/ + go vet clean; test passes under the go.mod toolchain (GOTOOLCHAIN=go1.24.2 — the package test binary doesn't link on Go >=1.24 due to a pinned bytedance/sonic/go:linkname issue, unrelated to this change).

receipts

Found by the recipes swap-providers fund-safety audit (the MayaChain-CRITICAL / Relay-min-out vein — recipes#597, #598). Sibling finding: 1inch (oneinch.go) has the same hardcoded-1% ignore-tolerance behavior but threads slippage at two sites (quote + BuildTx) and needs the tolerance carried through SwapRequest/Quote, so it's left for a follow-up. LiFi's omitted-slippage default was live-verified conservative (0.5%).

JupiterProvider.GetQuote always sent slippageBps=100 (the 1% default) and
ignored QuoteRequest.ToleranceBps entirely, so a caller could neither
tighten nor loosen the swap's slippage. Jupiter bakes the resulting min-out
into the quote's otherAmountThreshold (carried to BuildTx via ProviderData),
so forwarding a positive tolerance at the quote call is sufficient.

Honor req.ToleranceBps (same bps units) when positive; fall back to the 1%
default when omitted or 0 (0 would demand exact-out and revert on any
movement). Regression test asserts the outgoing slippageBps tracks the
requested tolerance and defaults correctly.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d972f93-19ea-4123-81d0-911dcdff9745

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_jupiter_forward_tolerance

Comment @coderabbitai help to get the list of available commands.

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