Fix MultiSwapper quote backcompat#161
Open
liobrasil wants to merge 5 commits intonialexsan/fix-multi-swapperfrom
Open
Fix MultiSwapper quote backcompat#161liobrasil wants to merge 5 commits intonialexsan/fix-multi-swapperfrom
liobrasil wants to merge 5 commits intonialexsan/fix-multi-swapperfrom
Conversation
…er-alex-backcompat
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.
Summary
This follow-up fixes two behavioral regressions introduced by the current
MultiSwapperquote 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
MultiSwappercan pick the right route.That change also altered the public quote shape returned by
MultiSwapper, and two existing callers rely on the previous behavior:swap(nil, ...)can fail with strict or capacity-limited inner swappers.quoteOut(forProvided)may now return a smallerinAmountthan the vault balance forwarded by_swap, which creates a mismatch for connectors that enforceinVault.balance <= quote.inAmount.Example:
quoteOut(100)picks a capped route and returnsinAmount = 60, but_swapstill forwards a vault with balance100.SwapSource.withdrawAvailable(maxAmount)can return more thanmaxAmount.quoteIn(forDesired)may now return anoutAmountlarger than the requested amount, andSwapSourcereturns that swap result directly.Example:
withdrawAvailable(10)usesquoteIn(10), but the quote returnsoutAmount = 10.00000002, so the caller gets more than10.Fix
Keep the current route-selection logic, but restore the previous outward quote semantics expected by those callers:
quoteIn(forDesired)caps full-routeoutAmounttoforDesiredquoteOut(forProvided)keepsinAmount = forProvidedThis preserves the selection fix while removing the caller regressions.
Tests
flow test ./cadence/tests/SwapConnectorsMultiSwapper_test.cdcswap(nil, ...)with a strict capped inner swapperSwapSource.withdrawAvailable(maxAmount)not exceedingmaxAmount