1

When exchanging the smallest possible amount of USDC/WETH - 0.000001 USDC - on Uniswap V3 the price impact soars to 99.95%.

Is this accurate, or is this an error in price impact estimation? Why is this high estimation appearing?

The price impact diminishes as the swap amount increases:

USDC amount price impact
0.000001 99.95%
0.00001 9.0%
0.0001 0.7%
0.001 0.00000000035%
0.01 0.0000000027% note the price impact grows again as expected
0.1 0.000000026%

Same happens when doing the inverse for WETH/USDC, or for other pairs such as WBTC/DAI, etc.


I got these estimations from the Uniswap Interface and where it displayed 0.00% I used the price impact estimation logic from the https://uniswap-python.com/

1 Answer 1

3

Rounding errors.

Solidity does not have floating-point math, all fractional calculations are done with fixed-point math, meaning that when the amounts are very small, rounding errors become huge. Specifically in the example, USDC ERC-20 token only has 6 decimals, so the 0.000001 USDC value is the smallest value possible - one micro-USDC to be exact.

In order to compute the result amounts in a swap from y to x, formulas 6.11 and 6.12 from the whitepaper are used:

6.11

6.12

Gamma is the fee paid by the swappers, for example 0.003. In your example then input token is USDC. In the implementation of the delta y calculation, the fee term is rounded up, meaning it can never be zero.

  • When y_in = 100 micro-USDC, the expected fee amount is computed by the frontend as 0.3 micro-USDC, but you actually end up paying 1 micro-USD, leading to 1.0 - 0.3 = 0.7% price impact.
  • When y_in = 10 micro-USDC, the 1 micro-USDC fee is 10% of the input value, so it shows as nearly 10% price impact.
  • When y_in = 1 micro-USDC, the 1 micro-USDC fee is 100% of the input amount, so it shows as nearly 100% price impact. Moreover, you'll get zero wei in the output because all of the input is "eaten" away by the fee!

On the other hand, when y_in = 1000 the expected fee is exactly 3.0 micro-USDC, so there are no rounding errors.

3
  • An excellent answer, thanks! Jan 18 at 10:05
  • 1
    Great answer! However aren't the LP fees subtracted from the price impact before being shown in the Uniswap Interface? See computeRealizedPriceImpact: github.com/Uniswap/interface/blob/main/src/utils/prices.ts#L19 - the realizedLpFeePercent are the combined fees as %, the trade.priceImpact is the price impact including fees, and the output of that function is being displayed in the interface where I got these values from. What do you recon? Nevertheless, great job pointing me in the right direction 👏
    – Voy
    Jan 18 at 12:16
  • 1
    I think I understand why now - the Uniswap Interface subtracts the pool fee value that is set for the pool (eg. 0.3% or 0.05%), rather than subtracting the result of calculating what would the actual fee be (possibly rounded up), and figuring out what fraction of input amount this actual fee would be. If we do that, the price impact indeed is very small again: 0% for y_in=1, 0.00000000795% for y_in=10, 0.000000000762% for y_in=100. I'd appreciate if someone could confirm this reasoning. You may want to add this to your answer kfx
    – Voy
    Jan 18 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.