Skip to content

Fix MultiSwapper quote backcompat#161

Open
liobrasil wants to merge 5 commits intonialexsan/fix-multi-swapperfrom
lionel/fix-multiswapper-alex-backcompat
Open

Fix MultiSwapper quote backcompat#161
liobrasil wants to merge 5 commits intonialexsan/fix-multi-swapperfrom
lionel/fix-multiswapper-alex-backcompat

Conversation

@liobrasil
Copy link
Copy Markdown
Contributor

@liobrasil liobrasil commented Mar 28, 2026

Summary

This follow-up fixes two behavioral regressions introduced by the current MultiSwapper quote changes, while keeping the improved route-selection logic already in the branch.

Problem

The current branch correctly preserves the chosen inner route's real quote values so MultiSwapper can pick the right route.

That change also altered the public quote shape returned by MultiSwapper, and two existing callers rely on the previous behavior:

  1. swap(nil, ...) can fail with strict or capacity-limited inner swappers.
    quoteOut(forProvided) may now return a smaller inAmount than the vault balance forwarded by _swap, which creates a mismatch for connectors that enforce inVault.balance <= quote.inAmount.
    Example: quoteOut(100) picks a capped route and returns inAmount = 60, but _swap still forwards a vault with balance 100.

  2. SwapSource.withdrawAvailable(maxAmount) can return more than maxAmount.
    quoteIn(forDesired) may now return an outAmount larger than the requested amount, and SwapSource returns that swap result directly.
    Example: withdrawAvailable(10) uses quoteIn(10), but the quote returns outAmount = 10.00000002, so the caller gets more than 10.

Fix

Keep the current route-selection logic, but restore the previous outward quote semantics expected by those callers:

  • quoteIn(forDesired) caps full-route outAmount to forDesired
  • quoteOut(forProvided) keeps inAmount = forProvided

This preserves the selection fix while removing the caller regressions.

Tests

  • flow test ./cadence/tests/SwapConnectorsMultiSwapper_test.cdc
  • added a regression test for swap(nil, ...) with a strict capped inner swapper
  • added a regression test for SwapSource.withdrawAvailable(maxAmount) not exceeding maxAmount

@liobrasil liobrasil marked this pull request as ready for review March 28, 2026 01:26
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.

2 participants