We have done a detailed calculation of the swap slippage of uniswap V2 in the last post. It is relatively complicated to calculate the the swap slippage of uniswap V3 due to its liquidity is a piecewise function of price. Of course, we can also obtain it through the front end of the uniswap web page: But how do you get the swap slippage by calculating it yourself? Letβs analyze it in detail below. Taking ETH-USDT as an example, we know that the price on uniswap V3 is represented by tick, that is, ????(????) = 1.0001^????, ???? is the tick order, firstly we set all liquidity of the ETH-USDT pool as segments. Suppose it is divided into n segments, then the liquidity in each tick space included in the n segment is the same. We mark it as L1, L2β¦Ln, and the price range of each segment is [Pan, Pbn], the current price is P0, we need to calculate how much you can swap u0 usdt for ETH. As we all know, the amount of USDT and Ep in the current segment as Obviously at the endpoints of the current segment Pan and Pbn will have Epn ETH and Upn USDT When u0+up<=up, the swap would be completed in the current segment, and at this time: Wherein px is the final price of pool after swap, According to (1) to (6), it can be calculated as followed: Then the swap price Pswap Then we can get the slipgage (%) When u0+up>up, that is, when tick-cross occurs, it is only necessary to repeat the calculation for the remaining part after the swap in the current segment in the next segment, and the final slippage can be calculated. https://x3finance.medium.com/how-to-calculate-swap-slippage-of-uniswap-v3-d433ed6d74b0 [link] [comments] |
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments