简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM