LP-Swap

# How to do arbitrage with liquidity pools

When you add liquidity to a liquidity pool, for example in BUSD-WBNB one, you must provide quantities of both tokens by respecting the ratio $x^{\mathrm{BUSD}}/ x^{\mathrm{WBNB}}$ of tokens already in the pool. Why does this correspond to providing equal values (expressed in dollars for instance) of BUSD and WBNB? This is because otherwise, arbitrage between the prices of the tokens and the ratio of the pool is made possible. We make this arbitrage opportunity precise in this article, but first let us reformulate the problematic with numbers.

Let $p^{\mathrm{BUSD}}$ and $p^{\mathrm{WBNB}}$ be the respective prices of BUSD and WBNB expressed in dollars. If you have $Q$ dollars to invest in this liquidity and you split these dollars equally in BUSD and WBNB, then you obtain $\frac{Q}{2}\times \frac{1}{p^{\mathrm{BUSD}}}$ tokens BUSD $\frac{Q}{2}\times \frac{1}{p^{\mathrm{WBNB}}}$ tokens WBNB. The ratio of tokens you obtain is then $p^{\mathrm{WBNB}}/{p^{\mathrm{BUSD}}}$. The arbitrage-free formula then states that this ratio matches the ratio of the pool:

$\frac{p^{\mathrm{WBNB}}}{{p^{\mathrm{BUSD}}}}= \frac{x^{\mathrm{BUSD}}}{{x^{\mathrm{WBNB}}}}.$

The arbitrage-free formula is also equivalent to the following equation:

$p^{\mathrm{BUSD}} \times x^{\mathrm{BUSD}}= p^{\mathrm{WBNB}} \times x^{\mathrm{WBNB}}$

which means that inside the BUSD-WBNB pool, the total value of BUSD tokens equal the total value of WBNB tokens.

Recall the swap formula that expresses the output quantity $q_{output}$ of WBNB tokens obtained from swapping an input quantity $q_{input}$ tokens BUSD:

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

In the absence of transaction fees ($r = 0$) and of slippage ($x^{\text{BUSD}} + q_{input} \approx x^{\text{BUSD}}$), the output quantity of WBNB would be:

$q_{output} = \frac{x^{\mathrm{WBNB}}}{x^{\mathrm{BUSD}}} q_{input}$

In other words, in the absence of slippage and transaction fees, the ratio $x^{\mathrm{WBNB}} /x^{\mathrm{BUSD}}$ gives the amount of WBNB you would get per BUSD. This ratio is called the pool price of BUSD. Similarly, $x^{\mathrm{BUSD}}/ x^{\mathrm{WBNB}}$is called the pool price of WBNB.

So the arbitrage-free formula states that the pool price equals the ratio of the actual prices, expressed in dollars or any currency:

$\frac{x^{\mathrm{BUSD}}}{{x^{\mathrm{WBNB}}}} = \frac{p^{\mathrm{WBNB}}}{{p^{\mathrm{BUSD}}}}.$

When the arbitrage-free formula does not hold, there is a possibility of arbitrage.

Let's say for instance that $x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}>p^{\mathrm{WBNB}}/ p^{\mathrm{BUSD}}.$ With $p^{\mathrm{WBNB}}$ dollars you can buy 1 WBNB token. Using the price pool (without transaction fees and slippage), you can then swap the WBNB token in the pool to obtain $x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}$ tokens BUSD. Selling the BUSD tokens you get back $p^{\mathrm{BUSD}}\times x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}$ dollars, which is bigger than your initial investment $p^{\mathrm{WBNB}}$.

The case where $x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}} is symmetric: You can buy BUSD with dollars, then swap BUSD against WBNB using the pool and finally sell the resulting WBNB to obtain more dollars than you started with.

Docs