LP-Swap

# 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 $q_{input}$ BUSD tokens for WBNB tokens. For this you will use a BUSD-WBNB pool containing quantities $x^{\mathrm{BUSD}}$ and $x^{\mathrm{WBNB}}$ of both tokens before the swap. Recall from the swap formula that the real quantity $q_{output}^{real}$of WBNB tokens you get from the pool is given by

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

where $0\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 $q_{input}$ of BUSD tokens compared to the sizes of the pools, we obtain an ouput of

$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:

$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 $q_{input}$ of BUSD you swap, the higher the slippage. Besides, the bigger the quantity $x^{\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 $x^{\mathrm{WBNB}}$ of WBNB already in the pool, or rather the bigger the pool ratio $x^{\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