Avoid recomputing amountIn when exactIn and `amountRemainingLessF…#718
Merged
Conversation
hensha256
previously approved these changes
Aug 26, 2024
Contributor
|
@snreynolds is also going to review this. Please dont merge without approvals from both of us 🙏 |
9c526ac to
a36d08a
Compare
…ee < amountIn` Simplify the flow in SwapMath library by removing unnecessary calculations related to input amounts. The removed calculations are replaced with a direct assignment of the remaining amount which simplifies the logic. Moreover, the potential for any rounding issues is significantly reduced.
a36d08a to
03a2948
Compare
snreynolds
previously approved these changes
Aug 28, 2024
snreynolds
left a comment
Contributor
There was a problem hiding this comment.
makes sense to me! that edge case I believe is really just a rounding error and with this change it rounds the fee down which I believe is more accurate behavior?
hensha256
approved these changes
Aug 28, 2024
snreynolds
approved these changes
Aug 29, 2024
GianfrancoBazzani
pushed a commit
to GianfrancoBazzani/v4-core
that referenced
this pull request
Aug 30, 2024
Uniswap#718) Avoid recomputing `amountIn` when `exactIn` and `amountRemainingLessFee < amountIn` Simplify the flow in SwapMath library by removing unnecessary calculations related to input amounts. The removed calculations are replaced with a direct assignment of the remaining amount which simplifies the logic. Moreover, the potential for any rounding issues is significantly reduced.
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.
…ee < amountIn`
Originally part of #280.
Related Issue
Which issue does this pull request resolve?
Description of changes
Simplify the flow in SwapMath library by removing unnecessary calculations related to input amounts. The removed calculations are replaced with a direct assignment of the remaining amount which simplifies the logic. Moreover, the potential for any rounding issues is significantly reduced.
In the case of
exactInandamountRemainingLessFee < amountIn, the original logic computessqrtPriceNextX96fromamountRemainingLessFee. It then usessqrtPriceNextX96to computeamountIn, which shouldn't differs much fromamountRemainingLessFee, whileamountIncan simply exhaustamountRemainingLessFee.