LP-Swap
Academy

How slippage is calculated

The intuition behind slippage is the following: if you try to buy big quantities in a market that has no liquidity, then you will have to pay more than the expected price (see this article for more details). Here we focus on the slippage occurring when swapping tokens on decentralised exchanges, that is when using liquidity pools.

So let us say that you want to swap qinputq_{input} BUSD tokens for WBNB tokens. For this you will use a BUSD-WBNB pool containing quantities xBUSDx^{\mathrm{BUSD}} and xWBNBx^{\mathrm{WBNB}} of both tokens before the swap. Recall from the swap formula that the real quantity qoutputrealq_{output}^{real}of WBNB tokens you get from the pool is given by

qoutputreal=(1r)×qinput×xWBNBxBUSD+(1r)×qinput,q_{output}^{real}=\frac{(1-r)\times q_{input} \times x^{\mathrm{WBNB}} }{x^{\mathrm{BUSD}}+(1-r)\times q_{input}},

where 0r10\leq r \leq 1 is the fee rate of the pool used to pay to liquidity providers (typically it equals 0.002). However for very small input qinputq_{input} of BUSD tokens compared to the sizes of the pools, we obtain an ouput of

qoutputideal=(1r)×qinput×xWBNB/xBUSD WBNB tokens.q_{output}^{ideal}=(1-r)\times q_{input}\times x^{\mathrm{WBNB}}/x^{\mathrm{BUSD}} \text{ WBNB tokens.}

The slippage of the transaction is the amount of WBNB tokens that you loose compared to buying all the WBNB tokens at the ideal price:

qoutputrealqoutputideal=(1r)×qinput2×xWBNB(xBUSD×[xBUSD+qinput])<0.q^{real}_{output}-q_{output}^{ideal}=-\frac{(1-r)\times q_{input}^2\times x^{\mathrm{WBNB}}}{ (x^{\mathrm{BUSD}}\times [x^{\mathrm{BUSD}}+q_{input}])}<0.

The result is quite intuitive: we see for instance that the bigger the quantity qinputq_{input} of BUSD you swap, the higher the slippage. Besides, the bigger the quantity xBUSDx^{\mathrm{BUSD}} of BUSD already in the pool, the less significative your contribution to this pool and the impact of your swap, and so the lower the slippage. Similarly, the bigger the quantity xWBNBx^{\mathrm{WBNB}} of WBNB already in the pool, or rather the bigger the pool ratio xWBNB/xBUSDx^{\mathrm{WBNB}}/x^{\mathrm{BUSD}} of a BUSD token expressed in WBNB, the more WBNB tokens are withdrawn from the pool because of your swap, and so the higher the slippage.

Docs
Twitter
Telegram