In the ever-evolving landscape of blockchain and DeFi, Maximal extractable value (MEV) has emerged as a captivating and contentious subject. This blog article aims to demystify the concept of MEV and delve into the most interesting topics surrounding it with real transactions, data points and simple execution examples from Sentio (website).
What is MEV and How big is it?
MEV refers to the potential profits that miners, validators, or transaction orderers can extract from the act of sequencing transactions in a block before adding them to the blockchain. This ability to reorganize the transaction order opens the door to various profit-seeking opportunities.
To provide an idea of how big the MEV opportunities are, the visual below plots the daily revenue and profit generated from two types of MEV strategies (i.e. arbitrage and sandwich) in recent 14 days. The daily revenue combined averages more than USD$500k per day, and the daily profit averages around $100k. The well-know
jaredfromsubway.eth alone, shown in blue colour at the left side of the visual, took half of all sandwich profit and revenue.
Refer to https://app.sentio.xyz/qiaokan/eth-mev-analytics/dashboards/e50idSGx for the up-to-date data with more details(🚨: Sentio team puts limited effort maintaining this dashboard. It might contain mistakes, welcome to contact us to right the wrongs!)
How Does MEV Work?
Let’s start from a “simple” strategy called arbitrage to illustrate how an MEV transaction works. Let’s take a high-level look at the workflow of a typical MEV arbitrage transaction as the image below shows.
An arbitrage transaction (1) starts from an MEV-bot (a.k.a searchers) discovers that there’s price gap between 2 liquidity pools. (2) Then the bot can buy from the low-price pool and sell at the high-price pool within a single transaction, to generate profit.
For example, transaction
0xa62d6125bead1ce19f37715ad16ef0560a48aa0bb9e884a8a9f9101d885271b5 is an arbitrage transaction. You can see the detailed Fund Flow, Balance Changes and Call Trace to understand the execution of this transaction step by step, with the help of Sentio Debugger at https://app.sentio.xyz/qiaokan/eth-mev-analytics/transaction/1/0xa62d6125bead1ce19f37715ad16ef0560a48aa0bb9e884a8a9f9101d885271b5.
0x1a6... in the middle of the figure is the one who initiated this transaction. In this transaction, the MEV-bot was able to detect that the price of
WETH was cheaper in Uniswap V3
0xc7c... than the SmarDex
0xf3a... (SmarDex is a Uniswap V2 alike DEX). The MEV-bot swapped
5.91 WETH for
1.05M SDEX in the low-price pool first, then swapped the received
1.05M SDEX to
5.98 WETH in the high-price pool. The MEV-bot ended up with
0.07 ETH revenue.
You might have noticed that #5 step in this transaction pays
0.047 ETH to the
Flashbots: Builder, this is the bribe MEV-bot pays the block builder to get included in the coming block. Taking consideration of the bribe fee, the MEV-bot made
0.02 WETH profit where he kept to himself.
Diving a little deeper, let’s also understand how MEV-bot
0x1a6... found this opportunity. We can see this MEV transaction
0xa62d... sits at
position 1 of
block 17935927 ( https://etherscan.io/txs?block=17935927). Right before this transaction, there is a transaction
position 0 of the same block. This transaction at https://app.sentio.xyz/qiaokan/eth-mev-analytics/transaction/1/0x77f8e42e7d3686f2dc95fa8a2dfbb254b96ca324b4c18acc9c917ad3c74cceb2 swapped a large volume swap from
8.52 ETH to
1.5M SDEX in the SmarDex pool (
0xf3a...). This transaction moved the price of
WETH higher in this pool.
MEV-bot above was able to notice this and added a transaction of his own right after this transaction to capture this ‘buy low, sell high’ opportunity.
How did the MEV-bot ‘see’ a transaction before it was included in a block? Here comes the mempool: before transactions are added to a block and added to the blockchain, they exist in a pool called the mempool. Transactions in the mempool are not yet confirmed and are waiting for inclusion in the next block. Block builders are responsible for selecting which transactions to include and in what order. This process can be influenced by factors such as transaction fees and gas prices (Remember the bribe fee we discussed in the last section? That’s the fee MEV-bot pays to get included).
In the above context, the MEV-bot at
position 1 was able to view all mempool transactions and it discovered the
0x8fa... transaction was an opportunity. Next, the MEV-bot added another transaction right behind it to form a bundle to capture the profits. MEV-bot can create bundle by using tools like Flashbot and force the bundle transactions get included in same block and executed in the wanted order.
In fact, there are more MEV transactions happened in this particular block. As this is a flashbot built block, you can click into this Flashbot explorer built by Marto to see more tranctions and see the Fund Flow, Balance Changes, and Call Trace details in Sentio Debugger.
While arbitrage typically appends a transaction after a profitable transaction, sandwich is a strategy that profits from adding 1 (or more) transaction(s) before and after a victim transaction and force these transactions to get executed sequentially. Let’s take a high-level look at the workflow of a typical MEV sandwich transaction as the image below.
Firstly, an user submits a transaction to mempool. An MEV bot that constantly monitors all mempool transactions, is able to capture this transaction, and determines if this transaction could be a profitable opportunity for sandwich. Once the opportunity is identified, the MEV bot needs to create a bundle by inserting transactions before and after this victim transaction (like wrapping a sandwich), and propose the bundle to the block builder. When the mempool transactions get included and executed in the next block, bundled transactions will get executed in the exact sequence per below (visual by Jeiwan in Uniswap V3 development book).
The MEV-bot generates profit by manipulating the pool liquidity. At the front-running transaction, so that the MEV-bot can buy asset at a lower price. After the victim position, the attacker sell previously bought tokens at a higher price.
Let’s use below 3 recent transactions at position 0–2 of block
17786884 as the example.
Position 0 (front-running):
This transaction was inserted by MEV-bot to swap
724.6 WETH to
1.34M USDC before the victim transaction, which was transacted at
1857 ETH/USDC price.
Position 1 (the victim):
The victim user
0xc3a... wanted swap
2743 ETH to
USDT in Uniswap V3, which was handled by the Uniswap Router and eventually transacted at an average
1851 ETH/USDC price. Because of the front-running transaction, the victim suffered from a higher price. On the pool
0x88e... that the MEV-bot had front-run in the previous position,
1782 ETH was swapped to
1850.5 ETH/USDC price.
Position 2 (back-running):
This transaction was inserted by MEV-bot after the victim transaction.
134M USDC was swapped to
Net result of position 0 and 2 combined, is that MEV-bot gained
3 ETH, and the victim suffered a higher swap price. Below visuals of balance changes in these two positions can provide a quick view of how much the MEV-bot received.
To protect swaps from sandwich, you shall always set a maximum slippage. Otherwise the slippage will be be utilised by the sandwich attack and becomes revenue for MEV-bot (e.g. set a percentage in the swap setting inside the app UI or amountOutMinimum/sqrtPriceLimitX96 parameters when you do it programmatically).
Lending protocols are decentralised platforms that connect lenders and borrows (e.g. MakerDAO, Aave, Compound, etc). Borrowers can borrow a certain value of debts when collaterals are supplied in the platforms. Liquidation happens when a borrower’s collateral can’t cover their debt. Liquidators are incentived to buy collateral at a discount to cover the borrower’s debt. (Read more about liquidation from Aave’s article)
Let’s use the following transaction as an example https://app.sentio.xyz/qiaokan/eth-mev-analytics/transaction/1/0x652ebf2f56716ed0ce2412839cd1ed0c9cf44105ab9e688fb0a7572b82ebec9f
0x310... started the liquidation by getting a
212 USDT flashloan from Balancer. Then the MEV-bot paid off the USDT owed by borrower
0x994... in step 3-8, and MEV-bot got the collateral
223 TUSD at a discount in return. In step 8-11 the MEV-bot swapped all received
USDT and paid off the initial flashloan at step 12. All steps are completed in one single transaction.
4. Long tail MEV
Arbitrages, sandwiches and liquidations represent the majority of MEV being extracted. There are other strategies being exploit in MEV out there which are niche, arcane and undiscovered ( reference). These are known as the long tail MEV.
If you are MEV researcher/searcher/anyone who’s interseted in MEV, let us know what you are most interested in, this will help us to decide the topic of in the upcoming serie 2.
If you think Sentio’s product could be helpful for what you are working on, shoot us a message at email@example.com and we’d love your suggestions and feedback to navigate future product roadmap.
A Little About Sentio
Sentio is an observability platform for Web3. Sentio generates metrics, logs, and traces from smart contracts data through our low code solution, which could be used for anaytics & monitoring, simulate/debug transactions, data export API and more. Sentio supports Ethereum, BSC, Polygon, Solana, Sui, Aptos and more chains. Sentio is built by veteran engineers from Google, Linkedin, Microsoft, and TikTok, and backed by top investors like Lightspeed Venture Partners, Hashkey Capital, and Canonical Crypto.