Understanding MEV through on-chain data and transactions

“A More Intuitive MEV Profit Process”

Original Author: Ye & Kan, Sentio

Translation: Leo

MEV robot attacks are 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 explaining MEV, using on-chain data and examples to help you better understand MEV. The following is the translation by BlockBeats:

Before we begin, let’s briefly introduce Sentio. Sentio is an on-chain data monitoring platform that generates metrics, logs, and traces from smart contract data through a low-code solution. It can be used for analysis, monitoring, simulating/debugging transactions, and data export APIs. Currently, Sentio 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 delve into MEV using real transactions, data points, and simple execution examples from Sentio, revealing the mysterious veil of the MEV concept.

What is MEV? How big is the maximum?

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

The following chart shows the daily revenue and profit generated by two MEV strategies (arbitrage and sandwich) in the past 14 days, demonstrating the size of the MEV opportunity. The average daily total revenue exceeds $500,000, with an average daily profit of around $100,000. The revenue of jaredfromsubway.eth (the blue area) alone accounts for half of the total profit and revenue amount 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 workflow of a typical MEV arbitrage transaction from a god’s-eye view, as shown in the following diagram:

Arbitrage transaction: 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, thus generating profits.

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

The MEV transaction in the picture is initiated by a trading robot starting with 0x1a6. In this transaction, the MEV-bot is able to detect that the price of WETH in the SDEX in the Uniswap V3 pool 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 step 5 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. Taking into account the bribe fee, the MEV robot secretly earned a profit of 0.02 WETH.

Let’s take a deeper look at how the MEV-bot found the profit opportunity 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 (swapped 8.52 WETH on SDEX), causing the price of ETH in that pool to rise.

The MEV-bot above 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 brings us to the mempool. Before the transactions are added to the block and put on the chain, 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. The block builder is responsible for selecting which transactions to include and in what order, and this process may be influenced by factors such as transaction fees and gas prices (which are the fees paid by the MEV robot 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 like Flashbot to create bundles and force bundle transactions to be included in the same block and executed in the desired order.

In fact, there are more MEV transactions that 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 on fund flows, balance changes, and call traces in the Sentio debugger.

Sandwich Attack

Arbitrage strategies usually add transactions after profitable trades, but a sandwich attack is a strategy that profits 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 look at the operation process of a typical MEV sandwich attack from a bird’s eye view, as shown in the following figure:

First, users submit transactions to the mempool, and MEV bots continuously monitor all transactions in the mempool, track those transactions, and determine if they can be profitable opportunities for sandwich trading. Once an opportunity is found, the MEV bot needs to create a bundle by inserting transactions before and after the target transaction (like wrapping a sandwich) and submit 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.

MEV bots generate profits by manipulating pool liquidity. In sandwich trades, MEV bots can buy assets at a lower price. After the target transaction, the attacker sells the tokens purchased earlier at a higher price.

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

Position 0 (Front-runner transaction): Transaction starting with 0x850

This transaction was inserted by the MEV bot to swap 724.6 WETH for 1.34M USDC. Before the target transaction, this transaction was executed 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 ultimately processed by Uniswap Router and completed at an average price of 1851 ETH/USDC. Due to the presence of the front-runner transaction, the target trader suffered from a different price and swapped 1782 ETH at a price of 1850 ETH/USDC in the front-runner’s pool.

Position 2 (Back-runner): Transaction starting with 0x040

This transaction was inserted by the MEV bot after the target transaction. 134M USDC was swapped for 727.6 ETH. The final result of combining Position 0 and Position 2 is that the MEV bot made a profit of 3 ETH, while the target trader suffered from a higher swap price. The change in positions of these two transactions below can give you a quick understanding of the profit obtained by the MEV bot.

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

Liquidation

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

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

The MEV bot starting with the address 0x310 obtains a lightning loan of 212 USDT from Balancer, and then in steps 3-8, the MEV bot settles the debt owed by the borrower in USDT. The MEV bot starting with the address 0x994 obtains collateral at a discounted price as a reward. In steps 8-11, the MEV bot swaps all received TUSD for WETH and USDT, and in step 12, the initial lightning loan is repaid. All steps are completed in one transaction.

Long-tail MEV

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

Like what you're reading? Subscribe to our top stories.

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

Follow us on Twitter, Facebook, YouTube, and TikTok.

Share:

Was this article helpful?

93 out of 132 found this helpful

Gambling Chain Logo
Industry
Digital Asset Investment
Location
Real world, Metaverse and Network.
Goals
Build Daos that bring Decentralized finance to more and more persons Who love Web3.
Type
Website and other Media Daos

Products used

GC Wallet

Send targeted currencies to the right people at the right time.