# The Arbitrage and MEV Problem

1 Arbitrage

DEX is the crown jewel in the field of Defi. Starting from AMM of Uniswap V2, users on blockchain can initiate asset transactions anytime without worrying about the absence of transaction counterparties. This greatly enhances the liquidity of assets on the chain as well as user-experience. However, the problems brought about by AMM are trading slippage and impermanent loss, which is embodied in the close relationship between the price fluctuation of trading pairs and the volume of liquidity funds. Once liquidity is insufficient, users will bear considerable losses.

Who benefited from the losses? The answer is the arbitrageurs. In an ideal state, users exchange token A for token B, and the price should remain the same regardless of the way and route of exchanges. However, that is not the reality. If only one transaction pair is used for token exchange, the AMM algorithm will raise the price to a very high position because of the limited amount of liquidity funds in the transaction pair. If the user exchanges token B at this price, the arbitrageur would exchange token A for token B through other channels, and then sell at this price.

![Fig. 1 Triangular Arbitrage in DEX](https://2669990698-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mf7biEtgdSPwQ74dvkt%2F-MiQehmGYLBW5KofUAE8%2F-MiQwFVmXV-_uvybN-Au%2F1630311543001.jpg?alt=media\&token=8ac31ed1-0603-4132-9140-dcb552a9154c)

A considerable amount of profits can be gained this way. As shown in the figure below, the arbitrageur can frequently find arbitrage opportunities brought by the price difference between different trading pairs and obtain profits. In fact, the source of these profits is the losses borne by users who trade through DEX.

### 2 MEV

In the past, MEV robots were invincible and the interests of users and liquidity providers were damaged. How is it possible for Miner Bots to extract values from our transactions? The essential reasons for the on-chain attack lies in the design of the blockchain.

The first reason is the mempool design of the blockchain. After users have submitted their transactions to the network, these transactions are not directly appended to the block. Instead, they will be buffered in the mempool. Therefore, the transactions inside mempool are pending transactions. This is where miners do harmful behaviors because miners are given the access to monitor and review the transaction inside the mempool, then they can select the ones they preferred to execute in gas-priority order, which should have been the case. But MEV is the rule breaker, it refers to the value miners can obtain from exploiting their power to determine the arrangement of transactions in a block, often at the expense of users.

Secondly, the time gap between each block generation opportunities for the attackers. According to Etherscan, the current average block generation time of Ethereum is 13s, which means miners are given more than enough time to reorder, insert, or drop transactions to initiate front-running, back-running, sandwich, time zone and etc attacks to gain MEV.

### 3 Other Problems

Some DEX began to try to avoid such losses through the mechanism of Single Asset Liquidity Providing. All tokens can form trading pairs with tokens issued by DEX, and subsequently create a network of a star topology.

However, the key of Single Asset Liquidity Providing lies in the tokens issued by DEX. The price fluctuation and issuance model of this token will seriously affect the normal operation of the whole DEX ecosystem. Flaws in mechanism design will also lead to hacker attacks. In addition, there are mechanisms to introduce other exchange prices through Oracles (such as Uniswap V3, etc.), but these complex mechanisms can not balance the trading slippage and impermanent losses well.

## Our Proposing Solution

The best solution is to allow users to take advantage of the arbitrage opportunity **each time after the swap transaction**. However, this is difficult to achieve. On the one hand, not every user has enough time and ability to complete the arbitrage transaction by himself; on the other hand, it is difficult for users to seize the opportunity before professional arbitrageurs.

Fortunately, the **atomicity** of smart contract transaction solves the second problem. If users' normal transactions and arbitrage transactions are both placed in one single transaction to call a contract function, no other users can insert the transactions into them.

By splitting the swap transaction into multiple smaller routes using different liquidity pools, the price slippage on swap transactions will be lower and price will be more stable.
