fix(swap): forward tolerance_bps on mayachain quotes (zero-slippage fund-loss)#597
Draft
gomesalexandre wants to merge 1 commit into
Draft
fix(swap): forward tolerance_bps on mayachain quotes (zero-slippage fund-loss)#597gomesalexandre wants to merge 1 commit into
gomesalexandre wants to merge 1 commit into
Conversation
…und-loss) MayachainProvider.GetQuote built the Mayanode /quote/swap request from from_asset, to_asset, amount, destination, streaming_interval, streaming_quantity — but never set tolerance_bps, unlike its sibling THORChainProvider.GetQuote which does. An omitted tolerance_bps makes Mayanode return a market-order memo (=:c:maya1..., no LIM field), so the swap executes with ZERO slippage protection — full MEV/sandwich exposure on the entire amount — regardless of the slippage_tolerance_percent the caller (agent-backend-ts / the Go MCP build_swap_tx / execute_swap) threaded down into QuoteRequest.ToleranceBps. The value was silently dropped only inside this provider. Live-confirmed against production Mayanode: without tolerance_bps the memo is '=:c:maya1...' (no limit); with tolerance_bps it carries '=:c:maya1...:<LIM>' and the API rejects quotes that would violate it. Mirror THORChainProvider exactly (same 2500bps default + 0-10000 bound) — a straight parity fix, not a design change. Added a regression test capturing the outgoing query to assert tolerance_bps is forwarded (explicit + 2500 default). Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
what — MayaChain swaps ship with zero slippage protection (MEV / fund-loss)
MayachainProvider.GetQuote(sdk/swap/mayachain.go) builds the Mayanode/quote/swaprequest fromfrom_asset,to_asset,amount,destination,streaming_interval,streaming_quantity— but never setstolerance_bps, unlike its siblingTHORChainProvider.GetQuote(same file) which does.An omitted
tolerance_bpsmakes Mayanode return a market-order memo (=:c:maya1..., noLIMfield), so the swap executes with zero slippage protection — full MEV/sandwich exposure on the entire amount — regardless of theslippage_tolerance_percentthe caller threaded down intoQuoteRequest.ToleranceBps. The value is correctly plumbed by the consumers (the Go MCP'sbuild_swap_tx/execute_swap, agent-backend-ts) and silently dropped only inside this provider.live verification (production Mayanode)
how
Mirror
THORChainProvider.GetQuoteexactly — same2500bps default, same0-10000bound, sameparams.Set("tolerance_bps", …). This is a straight parity fix;mayachain.gootherwise mirrorsthorchain.gofunction-for-function. Addedmayachain_tolerance_test.go(httptest captures the outgoing query) assertingtolerance_bpsis forwarded (explicit value + the2500default when omitted).risk
Low, strictly corrective — the only prior behavior was "no slippage floor." Isolated to the MayaChain provider.
note
The separate question of whether the shared
2500bps (25%) default is itself too loose vs. 1inch/Jupiter's 1% (it applies to both THORChain and MayaChain today) is a broader design decision, not addressed here — this PR just brings Maya to parity so a floor exists at all.receipts
Live-verified against the production Mayanode API (curls above). Regression test passes under the go.mod toolchain (
GOTOOLCHAIN=go1.24.2 go test ./sdk/swap/ -run TestMayachainGetQuoteForwardsToleranceBps— the package's test binary doesn't link on Go ≥1.24 due to a pinnedbytedance/sonic/go:linknameincompatibility, unrelated to this change;go build ./sdk/swap/+go vetare clean on the default toolchain). Found by a fund-safety audit of the Go MCP swap builders that consume this provider.