v3-periphery icon indicating copy to clipboard operation
v3-periphery copied to clipboard

Loss of precision in the double division of `LiquidityAmounts#getLiquidityForAmount0`

Open moodysalem opened this issue 3 years ago • 1 comments

https://github.com/Uniswap/uniswap-v3-periphery/blob/cd6b3775af80c745389fa5cd323ed6759b6926c3/contracts/libraries/LiquidityAmounts.sol#L28-L30

This method could be more precise by at least 32 bits by dividing by Q64 instead of Q96 in the intermediate step, and shifting the subtracted ratio left by 32 bits

As a result, this change was required in the v3-sdk to accommodate the less than complete precision of the calculation that is used in the NFT contract for adding liquidity https://github.com/Uniswap/uniswap-v3-sdk/commit/9ff7531842993d3493404fb622dae4a809957231

moodysalem avatar May 17 '21 19:05 moodysalem

The desired fix here is to create an additional LiquidityAmountsPrecise library that does not have this issue

moodysalem avatar May 19 '21 16:05 moodysalem