Skip to content

Conversation

@jpgonzalezra
Copy link
Contributor

@jpgonzalezra jpgonzalezra commented May 29, 2025

missing decimal normalization (univ2, univ3, balancer):

  • In pools that don’t contain WETH directly (like WBTC–USDC), for example previous fallback logic for univ2 did:
uint256 wethValue = quoteTokenToWethValue(token0, reserve0);
return wethValue * 2;

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

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.

@jpgonzalezra jpgonzalezra marked this pull request as draft May 29, 2025 17:17
@jpgonzalezra jpgonzalezra force-pushed the fix-normalize-decimals-handleUniswapV2Pool branch from 44fb6d9 to 15d2378 Compare May 29, 2025 17:46
@jpgonzalezra jpgonzalezra marked this pull request as ready for review May 29, 2025 17:48
@jpgonzalezra jpgonzalezra changed the title fix: normalize decimals in handleUniswapV2Pool for pools without WETH fix: normalize decimals in quoteTokenToWethValue May 29, 2025
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.

1 participant