8000 Avoid recomputing `amountIn` when `exactIn` and `amountRemainingLessF… by shuhuiluo · Pull Request #718 · Uniswap/v4-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid recomputing amountIn when exactIn and `amountRemainingLessF… #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

8000 Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

shuhuiluo
Copy link
Contributor

…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 exactIn and amountRemainingLessFee < amountIn, the original logic computes sqrtPriceNextX96 from amountRemainingLessFee. It then uses sqrtPriceNextX96 to compute amountIn, which shouldn't differs much from amountRemainingLessFee, while amountIn can simply exhaust amountRemainingLessFee.

hensha256
hensha256 previously approved these changes Aug 26, 2024
@hensha256
Copy link
Contributor

@snreynolds is also going to review this. Please dont merge without approvals from both of us 🙏

8000

…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.
@shuhuiluo shuhuiluo force-pushed the no-recompute-amount-in branch from a36d08a to 03a2948 Compare August 27, 2024 17:34
snreynolds
snreynolds previously approved these changes Aug 28, 2024
Copy link
Member
@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@snreynolds snreynolds merged commit 8f147f1 into Uniswap:main Aug 29, 2024
5 of 6 checks passed
@shuhuiluo shuhuiluo deleted the no-recompute-amount-in branch August 29, 2024 21:01
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.
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.

3 participants
0