[ad_1]
We have now accomplished an in depth calculation of the swap slippage of uniswap V2 within the final put up. It’s comparatively sophisticated to calculate the the swap slippage of uniswap V3 because of its liquidity is a piecewise perform of value. In fact, we will additionally get hold of it by means of the entrance finish of the uniswap net web page:

However how do you get the swap slippage by calculating it your self? Let’s analyze it intimately under. Taking ETH-USDT for instance, we all know that the value on uniswap V3 is represented by tick, that’s, 𝑝(𝑖) = 1.0001^𝑖, 𝑖 is the tick order, firstly we set all liquidity of the ETH-USDT pool as segments. Suppose it’s divided into n segments, then the liquidity in every tick area included within the n section is similar. We mark it as L1, L2…Ln, and the value vary of every section is [Pan, Pbn], the present value is P0, we have to calculate how a lot you’ll be able to swap u0 usdt for ETH. As everyone knows, the quantity of USDT and Ep within the present section as

Clearly on the endpoints of the present section Pan and Pbn may have Epn ETH and Upn USDT

When u0+up<=up, the swap could be accomplished within the present section, and presently:

Whereby px is the ultimate value of pool after swap,
In response to (1) to (6), it may be calculated as adopted:

Then the swap value Pswap

Then we will get the slipgage (%)

When u0+up>up, that’s, when tick-cross happens, it’s only essential to repeat the calculation for the remaining half after the swap within the present section within the subsequent section, and the ultimate slippage may be calculated.
https://x3finance.medium.com/how-to-calculate-swap-slippage-of-uniswap-v3-d433ed6d74b0
[ad_2]
Source link