8000 feat: ensure amountOut's are rounded down and amountIn's are roundedUp by philbow61 · Pull Request #562 · mento-protocol/mento-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: ensure amountOut's are rounded down and amountIn's are roundedUp #562

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

Conversation

philbow61
Copy link
Contributor
@philbow61 philbow61 commented Dec 3, 2024

Description

This PR ensures that amountOut's returned are always rounded down when tokenPrecisionMultipliers are applied and amountIn's are always rounded up. The rounding down of amountOut's was already done through the division by tokenPrecisionMultipliers the same was done to the the amountIn. This meant that when a token has less than 18 decimals the amountIn was wrongly scaled down -> returning a better price than what the calculation returned.
This has been changed by adding a new divAndRoundUp function. The function adds a +1 when the amountIn is scaled down to a different decimal precision and decimals are lossed.

Other changes

  • added tests that verify we also do the rounding down correctly for amountOut.

Tested

  • new tests added for both getAmountIn and swapOut

Related issues

https://discord.com/channels/812037309376495636/1220753099283763292/1313168114019729468

Backwards compatibility

Documentation

@philbow61 philbow61 marked this pull request as ready for review December 3, 2024 17:09
@philbow61 philbow61 merged commit 20fc515 into develop Dec 4, 2024
5 checks passed
@philbow61 philbow61 deleted the feat/ensure-reserveBalance-is-always-larger-tan-accounting branch December 4, 2024 14:55
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