LP-Swap
Academy

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 xBUSD/xWBNBx^{\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 pBUSDp^{\mathrm{BUSD}} and pWBNBp^{\mathrm{WBNB}} be the respective prices of BUSD and WBNB expressed in dollars. If you have QQ dollars to invest in this liquidity and you split these dollars equally in BUSD and WBNB, then you obtain Q2×1pBUSD\frac{Q}{2}\times \frac{1}{p^{\mathrm{BUSD}}} tokens BUSD Q2×1pWBNB\frac{Q}{2}\times \frac{1}{p^{\mathrm{WBNB}}} tokens WBNB. The ratio of tokens you obtain is then pWBNB/pBUSDp^{\mathrm{WBNB}}/{p^{\mathrm{BUSD}}}. The arbitrage-free formula then states that this ratio matches the ratio of the pool:

pWBNBpBUSD=xBUSDxWBNB.\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:

pBUSD×xBUSD=pWBNB×xWBNBp^{\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 qoutputq_{output} of WBNB tokens obtained from swapping an input quantity qinputq_{input} tokens BUSD:

qoutput=(1r)×qinput×xWBNBxBUSD+(1r)×qinputq_{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=0r = 0) and of slippage (xBUSD+qinputxBUSDx^{\text{BUSD}} + q_{input} \approx x^{\text{BUSD}}), the output quantity of WBNB would be:

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

In other words, in the absence of slippage and transaction fees, the ratio xWBNB/xBUSDx^{\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, xBUSD/xWBNBx^{\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:

xBUSDxWBNB=pWBNBpBUSD.\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 xBUSD/xWBNB>pWBNB/pBUSD.x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}>p^{\mathrm{WBNB}}/ p^{\mathrm{BUSD}}. With pWBNBp^{\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 xBUSD/xWBNBx^{\mathrm{BUSD}}/x^{\mathrm{WBNB}} tokens BUSD. Selling the BUSD tokens you get back pBUSD×xBUSD/xWBNBp^{\mathrm{BUSD}}\times x^{\mathrm{BUSD}}/x^{\mathrm{WBNB}} dollars, which is bigger than your initial investment pWBNBp^{\mathrm{WBNB}}.

The case where xBUSD/xWBNB<pWBNB/pBUSDx^{\mathrm{BUSD}}/x^{\mathrm{WBNB}}<p^{\mathrm{WBNB}}/ p^{\mathrm{BUSD}} 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
Twitter
Telegram