Liquidity Backrun — MEV analysis

How searchers make money by backrunning adding liquidity events

yuichiro aoki
3 min readJul 11, 2023

Arbitrage MEV bots watch the swap transactions to see if there is any opportunities to backrun for the most part, but sometimes they make money by backrunning liquidity related transactions like `addLiquidity` from Uniswap V2 protocol.

Code

Here are the transactions.

Trigger transaction

Backrun transaction

In the trigger transaction, a user(0x0CF47073093Ec2f3C28f7b2A03A9fC345D6af678) added 266.29 WOO and 103 USDC to USDC/WOO pool on SushiSwap using SushiSwap Router.

trigger transaction

In the backrun transaction, a bot borrowed 22.22 USDC with flashloan from Balancer, swap 22.22 USDC to 107.8 WOO on WoofiV2, and swap 107.8 WOO to 29.62 USDC to USDC/WOO pool on SushiSwap. The bot made 7.4 USDC profit in this transaction.

liquidity backrun

Why this happened

Because the initial token market value ratio of this USDC/WOO pool was not correct, the user accidentally added the tokens with an unbalanced market value to the pool.

initial reserves
0.001537 USDC

0.00397 WOO (~$0.00087)

market value ratio
USDC:WOO = 0.001537:0.00397 = 0.387:1

Usually, MEV searchers fill this kind of gap right away, but since the amount of liquidity of the pool was too small and the profit will be too small, no one filled the gap for a while.

How to prevent

You have to be careful when you add liquidity especially when the pool is new or the liquidity is small because you are the one lose money by adding wrong token amounts.

Remove liquidity transaction for the user

As you can see, the user ended up losing some money compared to the value added to the pool.

What were the correct amounts to add

Given that a good liquidity ratio on UniV2 pools is where the market value of the two tokens roughly are equal, I thought it would be better to add the amount to meet that condition. So let’s simulate that scenario. In this simulation, I set the the amount of WOO adding to the pool to the same as the actual one and changed the amount of USDC to be equally worth to the WOO reserves after this transaction. I got the market value of WOO by querying on WoofiV2 which was used in the backrun transaction.

new trigger transaction

It turned out that the bot would still make 1.38 USDC with the same transaction, so obviously this is not perfect, but it reduces the MEV extraction. Let me know if you have know the formula to get the right amounts to add. I haven’t looked into how Woofi quotes prices. It uses a price oracle unlike Uniswap V2.

Final Thoughts

I just don’t like to see people lose tons of money with a single liquidity add transaction and give away to searchers. I hope this post helps people understand how MEV works and how they can minimize the loss.

If you have any trading strategy you want to try but don’t know how to build, please reach me out on twitter. I can help you build your bots with ~$1,000.

Thank you for reading😁

--

--