feat: ensure amountOut's are rounded down and amountIn's are roundedUp #562
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.
2F6F
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.
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
Tested
Related issues
https://discord.com/channels/812037309376495636/1220753099283763292/1313168114019729468
Backwards compatibility
Documentation