fix: normalize decimals in quoteTokenToWethValue#287
Open
jpgonzalezra wants to merge 1 commit into
Open
Conversation
44fb6d9 to
15d2378
Compare
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.
missing decimal normalization (univ2, univ3, balancer):
reserve0 comes in the token’s native decimals (WBTC has 8 decimals), but the quoteTokenToWethValue expects the amount to already be in 18 decimals (wei).
Example
A WBTC balance of 74,162,977 (0.74162977 WBTC) was treated as 74 million WBTC, so the returned WETH amount was tiny (≈ 5,386,287,934 wei, i.e. 0.000000005 ETH).
Fix:
1- Normalize the reserve
Convert the raw reserve (8-decimal WBTC) into an 18-decimal value by multiplying by 10^(18−8).
2- Quote with correct wei amount
Now quoteTokenToWethValue sees the true “wei amount” of token0 and returns an accurate WETH equivalent.