Anthony
Anthony

Reputation: 125

Uniswap V2 pool priceImpact

How do you calculate the priceImpact on Uniswap v2 pools? I can't find documentation to help me. The price impact appears on the UI when you select two tokens you want to swap.

Upvotes: 3

Views: 8980

Answers (3)

Luis Porras
Luis Porras

Reputation: 31

First is important to differentiate between price impact and price slippage.

First one being responsible of the impact you have within the pool with your trade size (the bigger the trade the bigger the price impact).

Price slippage would be the change made in the price by the market. There we would need to talk about the expected slippage vs the real slippage. (Imagine someone swaps before your trade gets executed and you incur in a bigger slippage than expected)

More info here

Following what Khanh said, the calculations for price impact given by Anthony is innacurate. With zero fees and not taking into account slippage, the price impact would be calculated as the % in difference from the original spot price (2000) and the current spot price after the trade (2009.64).

So 2009.64/2000-1 = 0.482%

Upvotes: 2

Khanh
Khanh

Reputation: 91

The price impact calculation is mostly similar to that of Anthony but the final calculation of price impact is inaccurate. The correct way is to determine the executed price and initial price ratio. In his example, assuming zero LP fee (usually it's 0.3% for Uniswap V2), the original price was 2,000,000 / 1,000 = 2,000; however, your executed price was 10,000/4.98 = 2008.032. So the price slippage is 2008.032/2000 - 1 = 0.4%. Hope this helps.

Upvotes: 2

Anthony
Anthony

Reputation: 125

You can calculate the price impact using the constant product formula.

Imagine you have a pool with 2,000,000 USDC and 1,000 ETH. The price of 1 ETH is 2,000 USDC.

Using the constant product formula (x*y=k) where x is USDC and y is ETH, k is 2,000,000,000.

Now, I'm going to swap 10,000 USDC for ETH.

2,000,000 USDC + 10,000 USDC = 2,010,000 USDC

x * y = k => y = k/x = 2,000,000,000/2,010,000 = 995.02 ETH

We receive 1,000 ETH - 995.02 ETH = 4.98 ETH

Price Impact = 4.98 ETH / 995.02 ETH = 0.5%

This article covers price impact in more detail.

Upvotes: 8

Related Questions