header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP

Understanding MEV through on-chain data and transactions - a comprehensive guide.

23-08-23 15:56
Read this article in 19 Minutes
总结 AI summary
View the summary 收起
Original author: Ye & Kan, Sentio
Original translation: Leo, BlockBeats


MEV robot attacks are common in DeFi, but many people only have a conceptual understanding of them, such as arbitrage attacks, sandwich attacks, etc. However, by tracking on-chain transaction data, MEV can be better understood. Recently, the Web3 observation platform Sentio published an article interpreting MEV, which can help you better understand MEV through on-chain data and examples. The following is compiled by BlockBeats:


Before starting the article, let me briefly introduce Sentio. Sentio is an on-chain data monitoring platform that provides low-code solutions to generate metrics, logs, and tracking from smart contract data. It can be used for analysis and monitoring, simulation/debugging of transactions, data export APIs, etc. Currently, Sentio supports chains such as ETH, BSC, Polygon, Solana, Sui, and Aptos. The platform was created by senior engineers from Google, LinkedIn, Microsoft, and TikTok, and has received support from top VCs such as Lightspeed Venture Partners, Hashkey Capital, and Canonical Crypto.



I am a professional in the encryption industry. Please translate the following Chinese text into English without considering the context or industry-specific terms and names. Do not omit any English words or phrases, including capitalized ones such as ZKS, STARK, and SCROLL. If there are English characters in an tag, do not translate them and return the tag as is. If the content consists only of punctuation marks, return them as is. Do not translate HTML tags such as

, , , and

. If an HTML tag contains English characters, omit the translation and return the tag as is. Please preserve any content within tags. Translate all Chinese characters. The text to be translated is:

Introduction


With the continuous development of blockchain and DeFi, Maximum Extractable Value (MEV) has become a highly attractive and controversial topic. This article aims to delve into MEV-related topics through real transactions, data points, and simple execution examples from Sentio, revealing the mysterious veil of the MEV concept.


What is MEV? How big can it be?


MEV refers to the potential profit that miners, validators, or transaction orderers can obtain by rearranging the order of transactions in a block before adding them to the chain. This behavior of rearranging transaction orders also provides an opportunity to obtain profits.


The following figure shows the daily revenue and profit generated by two MEV strategies (i.e. arbitrage and sandwich) in the past 14 days, to demonstrate the magnitude of MEV opportunities. The average daily total revenue exceeds $500,000, and the average daily profit is around $100,000. Only jaredfromsubway.eth (blue area) accounts for half of the total profit and revenue generated by sandwich attacks.



MEV operates in what way?


Arbitrage


We will start with the "simplest" arbitrage strategy to explain the working principle of MEV trading. Let's take a God's-eye view of the typical workflow of MEV arbitrage trading, as shown in the following figure:



Arbitrage trading: First, the MEV robot discovers a price difference between two liquidity pools; then the robot can buy from the low-price pool and sell to the high-price pool in a single transaction, generating profits.


For example, if trade A is an arbitrage trade, click on the trade A link to view detailed fund flows, position changes, and transaction tracking with the help of Sentio debugger, in order to gradually understand the execution of this trade.



The MEV transaction in the picture was initiated by a trading bot starting with 0x1a6 on Etherscan. In this transaction, the MEV-bot was able to detect that the price of WETH in SDEX in the Uniswap V3 pool was cheaper than the price of WETH in the SmarDex pool (SmarDex is a DEX similar to Uniswap V2). The MEV-bot first swapped in the low-price pool, then sold the received WETH in the high-price pool, ultimately earning 0.07 ETH (5.91-5.98).


In addition, in the fifth step of this transaction, 0.047 ETH was paid to Flashbots, which is a bribe paid by the MEV robot to the block builder to include it in the subsequent blocks. Considering the bribe fee, the MEV robot privately earned 0.02 WETH in profit.


Let's take a deeper look at how MEV-bot finds profit opportunities on 0x1a6. It can be seen that this MEV transaction is located in Block 17935927. Prior to this transaction, there was another Transaction B in the same block, which involved a large swap (8.52 WETH swapped on SDEX) in the SmarDex pool, causing the ETH price in the pool to rise.



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


Before a transaction is included in a block, how do MEV bots discover it? This brings us to the mempool. Before transactions are added to a block and placed on the chain, they exist in a pool called the mempool. Transactions in the mempool that have not been confirmed wait to be included in the next block. Block builders are responsible for selecting which transactions to include and in what order, a process that may be influenced by factors such as transaction fees and gas prices (which MEV bots pay to participate).


Under the above circumstances, the MEV robot can view all mempool transactions and discover the existence of a certain transaction. Subsequently, the MEV robot adds another transaction behind it to form a bundle to obtain profits. The MEV robot can use tools such as 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. As this is a Flashbot construct, you can click to enter the Flashbot browser built by Marto to view more transactions and view detailed information on fund flows, balance changes, and call tracking in the Sentio debugger.


Sandwich Attack


Arbitrage strategies usually involve adding trades after profitable trades, but sandwich attacks are a strategy that profits by adding one or more trades before and after the target trade and forcing these trades to be executed in order. Let's take a God's-eye view of the typical MEV sandwich attack process, as shown in the following figure:



First, the user submits a transaction to the mempool. MEV robots continuously monitor all mempool transactions, track the transaction, and determine if it can be a profitable opportunity for sandwich. Once an opportunity is found, the MEV robot needs to create a bundle by inserting transactions before and after the target transaction (just like packaging a sandwich) and submit the 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 robots generate profits by manipulating pool liquidity. In front-running trades, MEV robots can purchase assets at a lower price. After the target trade, the attacker sells the tokens purchased earlier at a higher price.


We take the latest 3 transactions on block 17786884 as an example (Position 0-2).


Position 0 (front-running): Transaction starting with 0x850


This transaction was inserted by a MEV robot, swapping 724.6 WETH for 1.34M USDC. Prior to the target transaction, this transaction was executed at a price of 1857 ETH/USDC.



Position (Target Trader): The transaction starting with 0xc3ae here.


The target trader wants to swap 2743 ETH for USDT (Uniswap V3), which will be processed by Uniswap Router and completed at an average price of 1851 ETH/USDC. Due to the emergence of frontrunning trades, the target trader suffered different prices and swapped 1782 ETH at a price of 1850 ETH/USDC in the pool where MEV robots raced ahead.



Position 2 (rear run): Transactions starting with 0x040 in this link.



This transaction was inserted by MEV-bot after the target transaction, where 134M USDC was swapped for 727.6 ETH. The final result of combining Position 0 and Position 2 was a profit of 3 ETH for MEV-bot, while the target trader suffered a higher swap price. The changes in the positions of these two positions below can quickly show you the profit obtained by the MEV bot.



In order to protect the swap from the impact of sandwich attacks, you should always set the maximum slippage. Otherwise, the slippage will be exploited by sandwich attacks and become the income of MEV-bots (for example, setting a percentage when programmatically setting it, or setting it in the swap settings within the application UI or the amountOutMinimum/sqrtpricelimitx 96 parameter).


Clearing


The MEV robot can also profit from lending protocols, which are DEXs (such as MakerDAO, Aave, Compound, etc.) that connect lenders and borrowers. Borrowers can borrow a certain amount of assets after providing collateral supported by the platform. When the borrower's collateral is unable to repay the debt, liquidation occurs, and liquidators are incentivized to purchase collateral at a low price to repay the debt. (



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



0x310 MEV robot starting address obtained a lightning loan from Balancer for 212 USDT, and then in steps 3-8, the MEV-bot cleared the USDT owed by the borrower. The 0x994 MEV robot starting address obtained collateral at a discounted price as a reward in steps 8-11, and in step 12, it repaid the initial lightning loan. All steps were completed in one transaction.


Long-tail MEV


Arbitrage, sandwich attacks, and liquidation are the main ways to extract MEV. In addition, there are other niche, mysterious, and undiscovered strategies in MEV (reference link), which are collectively known as long-tail MEV.


Original article link


欢迎加入律动 BlockBeats 官方社群:

Telegram 订阅群:https://t.me/theblockbeats

Telegram 交流群:https://t.me/BlockBeats_App

Twitter 官方账号:https://twitter.com/BlockBeatsAsia

举报 Correction/Report
This platform has fully integrated the Farcaster protocol. If you have a Farcaster account, you canLogin to comment
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit