LP-Swap

# How many tokens you get when removing liquidity

In a liquidity pool, for example one that contains $x^{\mathrm{BUSD}}$ and $x^{\mathrm{WBNB}}$ tokens BUSD and WBNB, a liquidity provider owns a share of the BUSD and WBNB in the pool that is proportional to its number of LP tokens. For instance, if you own 1 BUSD-WBNB LP token out of a total of 100 BUSD-WBNB LP tokens shared among the liquidity providers, you will get $x^{\mathrm{BUSD}}/100$ and $x^{\mathrm{WBNB}}/100$ tokens BUSD and WBNB when removing your liquidity from the pool.

However, the ratio between the quantities $x^{\mathrm{BUSD}}$ and $x^{\mathrm{WBNB}}$ may evolve with time, and so the quantities of each token that you obtain when removing your liquidity may be different to the quantities you provided initially! There are two mechanisms that explain the variations of both tokens in the pool:

1. When liquidity providers remove or add liquidities.
2. When a user swaps tokens using the pool, for instance BUSD against WBNB, he deposits some BUSD into the pool and in exchange he withdraws WBNB from the pool.

In the first case, tokens are removed or added exactly in the proportion $x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}$ of the pool. Therefore these operations do not change the relative proportions of each token in the pool and so there is no change in the quantities of tokens a liquidity provider will obtain from removing its liquidity.

In the case of swaps, let us say that before the swap, the BUSD-WBNB pool contains $x^{\mathrm{BUSD}}_{pre}$ and $x_{pre}^{\mathrm{WBNB}}$ tokens BUSD and WBNB respectively. After your swap, there will be $x^{\mathrm{BUSD}}_{post}$ and $x_{post}^{\mathrm{WBNB}}$ such tokens. These quantities are related by the constant product rule:

$x_{post}^{\mathrm{BUSD}}\times x_{post}^{\mathrm{WBNB}}= x_{pre}^{\mathrm{BUSD}} \times x_{pre}^{\mathrm{WBNB}}.$

In other words, the product of the quantities of BUSD and WBNB tokens inside the pool is constant.

$x^{\mathrm{BUSD}}\times x^{\mathrm{WBNB}}= \underline{constant}.$

For example we see that if the quantity of BUSD in the pool increases then the quantity of WBNB decreases. The exact quantity of WBNB obtained by swapping in this pool also depends on a liquidity provider fee, as we will see next with the swap formula in the article

In particular, we see that after the swap we have $x_{post}^{\mathrm{BUSD}}/ x_{post}^{\mathrm{WBNB}}>x_{pre}^{\mathrm{BUSD}} /x_{pre}^{\mathrm{WBNB}}$. Thus a liquidity provider who redeems its tokens from the pool after the swap will get more BUSD tokens and less WBNB tokens than he initially provided.

Docs