Fix slippage calculation in swap minimum receive - #710
Merged
Conversation
Minimum receive divided slippage bps by 100 into whole percent before applying it, so sub-percent slippage truncated to zero: with 0.3% or 0.5% slippage (two of the three suggested values) the swap details showed the full quote amount as the guaranteed minimum, and 1.5% was applied as 1%. Apply the slippage directly in basis points, matching how core and Android compute it.
Minimum receive went through a double detour: bps to percent to fraction via Double, folded into BigDecimal. Numerically it lands on the same values, but it drifts from how core (apply_slippage_in_bp) and iOS compute slippage. Use integer basis point math on the atomic value and name the computation.
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.
The swap minimum receive divided slippage bps into whole percents, so fractional slippage (0.5% = 50 bps) truncated to 0% and displayed a higher minimum receive than the quote guarantees. Apply the basis points directly, on iOS and Android.