Let you understand MEV through the article on data and transactions on the chain

Original Author: Ye & Kan, Sentio; Original Compiler: Leo, BlockBeats

MEV robot attacks are very common in DeFi, but many people only understand them conceptually, such as arbitrage attacks, sandwich attacks, etc. However, MEV can be better understood by tracking transaction data on the chain. Recently, Sentio, a Web3 observation platform, published an article explaining MEV. Data and examples on the chain can help you better understand MEV.

Before the article starts, let me briefly introduce Sentio. Sentio is an on-chain data monitoring platform that generates indicators, logs, and traces from smart contract data through low-code solutions, which can be used for analysis and monitoring, simulation/debugging transactions, and data export APIs. Currently Sentio supports ETH, BSC, Polygon, Solana, Sui, Aptos and other chains. The platform was founded by senior engineers from Google, Linkedin, Microsoft, and TikTok, and is backed by top VCs like Lightspeed Venture Partners, Hashkey Capital, and Canonical Crypto.

introduce

As blockchain and DeFi continue to grow, maximum extractable value (MEV) has become an attractive and controversial topic. This article aims to delve into MEV related topics through real transactions, data points and simple execution examples from Sentio, and demystify the concept of MEV for everyone.

**What are MEVs? How big is the biggest? **

MEV refers to the potential profit that a miner, validator, or transaction orderer can obtain by ordering transactions in a block before adding them to the chain. This act of reorganizing the order of trades also provides opportunities for profit.

The chart below shows the daily revenue and profit generated by two MEV strategies (i.e. Arbitrage and Sandwich) over the past 14 days to demonstrate how big the opportunity is for MEV. The average daily gross income is over $500,000, and the average daily profit is around $100,000. jaredfromsubway.eth (blue area) revenue alone accounted for half of the sandwich attack's total profit and revenue amount.

**How does MEV work? **

arbitrage

We start with the most "simple" arbitrage strategy to illustrate how MEV trading works. Let's take a look at the workflow of a typical MEV arbitrage transaction from God's perspective, as shown in the figure below:

Arbitrage trading: First, the MEV bot finds a price gap between the 2 liquidity pools; the bot can then buy from the low-priced pool and sell to the high-priced pool in a single transaction, generating a profit.

For example, transaction A is an arbitrage transaction, click on the link of transaction A to view detailed fund flow, position changes and transaction tracking with the help of Sentio debugger to understand the execution of this transaction step by step.

The MEV transaction in the figure was initiated by a trading robot starting with 0x1a6. In this transaction, MEV-bot can detect that the price of WETH in SDEX in the Uniswap V3 pool is cheaper than the price of WETH in the SmarDex pool (SmarDex is a similar Uniswap V2 DEX). MEV-bot first swaps in the low-price pool, then sells the received WETH to the high-price pool, and finally makes a profit of 0.07ETH (5.91-5.98).

In addition, step 5 in this transaction pays 0.047 ETH to Flashbots, which is a bribe paid by MEV bots to block builders to be included in later blocks, taking into account the bribe fee, MEV bots earn Take 0.02 WETH profit.

Let’s take a deeper look at how MEV-bot finds profitable opportunities on 0x1a6. It can be seen that this MEV transaction is located on Block 17935927. Before this transaction, there was another transaction B in the same block. This transaction carried out a large amount of swap in the SmarDex pool (8.52 WETH was swapped on SDEX). Increase the price of ETH in the pool.

The MEV-bot above quickly noticed this process and added its own transaction after this transaction, seizing this "low in, high out" opportunity.

Before the transaction is included in the block, how does the MEV robot discover the transaction? This has to mention the mempool. Before the transaction is added to the block and chained, they exist in a pool called mempool, mempool When the transaction in has not been confirmed, it will wait to be included in the next block. Block builders are responsible for choosing which transactions to include and in what order, a process that may be influenced by factors such as transaction fees and gas prices (which are what MEV bots pay for participation).

In the above case, the MEV bot can look at all mempool transactions and see that such a transaction exists. The MEV robot then adds another transaction behind it, forming a bundle for profit. MEV bots can use tools like Flashbot to create bundles and force bundle transactions to be included in the same block and executed in the desired order.

In fact, more MEV transactions occurred in this particular block. Since this is a Flashbot building block, you can click into the Flashbot browser built by Marto to see more transactions, and view fund flow, balance changes, and call trace details in the Sentio debugger.

SANDWICH ATTACK

An arbitrage strategy is usually to append a trade after a profitable one, but a sandwich attack is a strategy that makes a profit by adding 1 (or more) trades before and after the target trade and forcing those trades to execute sequentially. Let us look at the operation process of a typical MEV sandwich attack from the perspective of God, as shown in the following figure:

First, a user submits a transaction to the mempool, and the MEV robot continuously monitors all mempool transactions and tracks the transaction to determine if it could be a profitable opportunity for the sandwich. Once an opportunity is identified, the MEV bot needs to create a bundle by inserting transactions before and after the target transaction (like wrapping a sandwich), and submit that bundle to the block builder. When the mempool transaction is included in the next block and executed, the bundle transaction will be executed in the exact order below.

MEV bots generate profits by manipulating pool liquidity. In front-running, MEV robots can buy assets at a lower price. After the targeted transaction, the attacker sells the previously purchased tokens at a higher price.

Let's take the last 3 transactions on block 17786884 as an example (Position 0-2).

Position 0 (preemptive transaction): transactions starting with 0×850

The transaction was inserted by the MEV robot to swap 724.6 WETH for 1.34M USDC. Before the target transaction, the transaction was carried out at the price of 1857 ETH/USDC.

Position (Target Trader): Transactions starting with 0xc3ae

The target trader wants to swap 2743 ETH to USDT (Uniswap V3), which will eventually be processed by Uniswap Router and complete the transaction at an average price of 1851 ETH/USDC. Target traders suffered from different prices due to front-running, swapping 1782 ETH at a price of 1850 ETH/USDC in the MEV bot front-running pool.

Position 2 (back run): transactions starting with 0×040

The transaction was inserted by MEV-bot after the target transaction, and 134M USDC was swapped to 727.6 ETH. The end result of the combination of Position 0 and Position 2 is that MEV-bot made a profit of 3 ETH, while the target trader suffered a higher swap price. The position changes of the following two Positions allow you to quickly understand the profits obtained by the MEV robot.

Through the data and transactions on the chain, this article will take you to understand MEV

To protect swap from sandwich attacks, you should always set a maximum slippage. Otherwise, the slippage will be exploited by a sandwich attack and become revenue for the MEV-bot (eg, when set programmatically, set a percentage in the app UI or in the swap setting within the amountOutMinimum/sqrtpricelimitx 96 parameters).

** liquidation **

MEV bots can also profit on lending protocols, which are DEXs that connect lenders and borrowers (e.g. MakerDAO, Aave, Compound, etc.). Borrowers can borrow assets of a certain value after providing collateral supported by the platform. When the borrower's collateral cannot repay the debt, liquidation will occur, and the liquidator is motivated to buy collateral at a low price to repay the debt.

Let's take the transaction starting with 0x652 as an example.

The MEV robot whose address starts with 0×310 obtained a 212 USDT loan by obtaining a flash loan from Balancer, and then MEV-bot paid off the USDT owed by the borrower in steps 3-8, and the MEV robot whose address started with 0×994 obtained it at a discounted price In return for the collateral, in steps 8-11, the MEV robot swaps all received TUSD into WETH and USDT, and pays off the initial flash loan in step 12, all steps are completed in one transaction.

Long Tail MEV

Arbitrage, sandwich attacks, and liquidations are the primary ways to extract MEV. Additionally, there are other strategies in MEV that are niche, mysterious, and undiscovered, and these are known as long-tail MEV.

View Original
The content is for reference only, not a solicitation or offer. No investment, tax, or legal advice provided. See Disclaimer for more risks disclosure.
  • Reward
  • Comment
  • Share
Comment
0/400
No comments