Understanding MEV through On-Chain Data and Transactions

Understanding MEV with On-Chain Data and Transactions

Original author: Ye & Kan, Sentio; Translation: Leo, BlockBeats

MEV robot attacks are very common in DeFi, but many people’s understanding of them is limited to concepts such as arbitrage attacks and sandwich attacks. However, by tracking on-chain transaction data, one can have a better understanding of MEV. Recently, Web3 observation platform Sentio published an article interpreting MEV, which can help you understand MEV better through on-chain data and examples.

Before we begin, let’s 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. It can be used for analysis, monitoring, simulating/debugging transactions, and exporting data APIs. Sentio currently supports ETH, BSC, Polygon, Solana, Sui, Aptos, and other chains. The platform was created by senior engineers from Google, Linkedin, Microsoft, and TikTok, and has received support from top VCs such as Lightspeed Venture LianGuairtners, Hashkey Capital, and Canonical Crypto.

Introduction

With the continuous development of blockchain and DeFi, Maximum Extractable Value (MEV) has become an attractive and controversial topic. This article aims to explore MEV in depth through real transactions, data points, and simple execution examples from Sentio, unveiling the mysterious veil of the MEV concept.

What is MEV? How big is the maximum?

MEV refers to the potential profit obtained by miners, validators, or transaction originators by rearranging the transaction order in a block before adding it to the chain. This behavior of reordering transaction order also provides an opportunity to obtain profits.

The following figure shows the daily revenue and profit generated by two MEV strategies (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. The income of jaredfromsubway.eth (blue area) alone accounts for half of the total profit and income of sandwich attacks.

How does MEV work?

Arbitrage

Let’s start with the “simplest” arbitrage strategy to explain how MEV transactions work. Let’s take a look at the working process of a typical MEV arbitrage transaction from a God’s-eye view, as shown in the following figure:

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

For example, Trade A is an arbitrage trade. By clicking on the link to Trade A, you can use the Sentio debugger to view detailed fund flows, position changes, and transaction tracking to gradually understand the execution of this trade.

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

In addition, in this transaction, step 5 pays 0.047 ETH to Flashbots, which is the bribe paid by the MEV robot to the block builder to include it in the subsequent block. Considering the bribe cost, the MEV robot made a profit of 0.02 WETH privately.

Let’s take a closer look at how the MEV-bot finds profit 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, which made a large swap in the SmarDex pool (swapping 8.52 WETH on SDEX), which caused the price of ETH in that pool to rise.

The above MEV-bot quickly noticed this process and added its own transaction after this transaction, seizing the opportunity of “buying low and selling high”.

Before the transaction is included in the block, how does the MEV robot discover the transaction? This requires mentioning the mempool. Before the transaction is added to the block and chained, they exist in a pool called the mempool. Transactions in the mempool that have not been confirmed will wait to be included in the next block. Block builders are responsible for selecting which transactions to include and in what order. This process may be influenced by factors such as transaction fees and gas prices (which are the fees the MEV robot pays to participate).

In the above case, the MEV robot can view all mempool transactions and discover that a certain transaction exists. 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 the 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 build, you can click to enter the Flashbot browser built by Marto to view more transactions, and view detailed information about fund flows, balance changes, and call traces in the Sentio debugger.

Sandwich Attack

Arbitrage strategies usually add transactions after profitable transactions, but a sandwich attack is a strategy to profit by adding 1 (or more) transactions before and after the target transaction and forcing these transactions to be executed in order. Let’s take a God’s-eye view of the operating process of a typical MEV sandwich attack as shown in the following figure:

First, users submit transactions to the mempool, and MEV bots continuously monitor all transactions in the mempool, track the transactions, and determine if they can be profitable opportunities for sandwich trading. Once an opportunity is found, the MEV bot creates a bundle by inserting transactions before and after the target transaction (like wrapping a sandwich) and submits the bundle to the block builder. When mempool transactions are included in the next block and executed, the bundle transactions will be executed in the exact order below.

The MEV bot generates profits by manipulating pool liquidity. In front-running transactions, the MEV bot can buy assets at a lower price. After the target transaction, the attacker sells the previously purchased tokens at a higher price.

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

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

This transaction is inserted by the MEV bot to swap 724.6 WETH for 1.34M USDC. Before the target transaction, this transaction was conducted at a price of 1857 ETH/USDC.

Position (target trader): transaction starting with 0xc3ae

The target trader wants to swap 2743 ETH for USDT (Uniswap V3), which is eventually processed by Uniswap Router and completed at an average price of 1851 ETH/USDC. Due to the occurrence of front-running transactions, the target trader suffered from a different price and swapped 1782 ETH at a price of 1850 ETH/USDC in the front-running pool of the MEV bot.

Position 2 (back-running): transaction starting with 0x040

This transaction is inserted by the MEV bot after the target transaction, and 134M USDC is swapped for 727.6 ETH. The final result of combining Position 0 and Position 2 is that the MEV bot earns 3 ETH, while the target trader suffers from a higher swap price. The change in positions of these two Positions below allows you to quickly understand the profits obtained by the MEV bot.

To protect swaps from the impact of sandwich attacks, you should always set a maximum slippage. Otherwise, the slippage will be exploited by sandwich attacks and become income for the MEV bot (for example, when programmatically setting a percentage in the swap settings within the application UI or the amountOutMinimum/sqrtpricelimitx96 parameter).

Liquidation

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

Let’s take a transaction starting with 0x652 as an example.

A MEV bot starting with 0x310 address obtained a loan of 212 USDT through flash loan from Balancer, and then the MEV bot repaid the USDT owed by the borrower in steps 3-8. Another MEV bot starting with 0x994 address obtained the collateral at a discounted price as a reward. In steps 8-11, the MEV bot swapped all received TUSD for WETH and USDT, and in step 12, it repaid the initial flash loan. All these steps were completed in a single transaction.

Long-tail MEV

Arbitrage, sandwich attacks, and liquidations are the main ways to extract MEV. In addition, there are other niche, mysterious, and undiscovered strategies within MEV, which are referred to as long-tail MEV.

We will continue to update Blocking; if you have any questions or suggestions, please contact us!

Share:

Was this article helpful?

93 out of 132 found this helpful

Discover more

Market

SUI Token Surges to New All-Time High, What’s Driving the Rally?

SUI has shown remarkable growth in the past few days, leading the token's price to reach a new all-time high. This ac...

Market

ERC-404: The Rise and Fall of a New Token Standard on Ethereum 📉💥💰

Despite facing some challenges, the ERC-404 market has continued to grow and evolve. While there may have been a temp...

Market

Apple Blocks Cryptocurrency Exchange Apps in India: What You Need to Know 🍎🔒💱

Apple has taken a bold step in India by implementing restrictions on several popular cryptocurrency exchange apps in ...

Blockchain

Altcoin Surge: KLAY, CHZ, and BLUR Defy Bitcoin Downtrend 🚀📈

Despite the current trend, altcoins such as Chiliz, Klaytn, and Blur are bucking the trend and demonstrating strong m...

Market

Bonk: The Meme Coin That’s Going Barking Mad on Binance

Great news for fashion lovers! Binance has officially listed the BONK token and will allow withdrawal starting tomorr...

Blockchain

Ethereum’s Roadmap: Enhancing Privacy and Embracing Cypherpunk Spirit 🚀🔒

Buterin's dedication to rekindling the cypherpunk ethos of the chain's origins showcases a deep passion for safeguard...