This post will discuss MEV, a form of value extractions from transactions occurring on the Ethereum blockchain. A special thanks goes to @MEVIntern on twitter, for inspiring this post and explaining MEV in an incredibly clear and concise method.
On January 28, 2021, Robinhood announced that it would restrict purchases on GameStop stock. Having just soared from around $11 in November to around $500 intraday Jan. 27, the stock had become of magnet for retail frenzy. In the wake of Robinhood’s decision, a PR nightmare was forming, with message board filled with conspiracies of “short ladder attacks” and market manipulation by market makers Citadel and Virtu.
While many of the rumors around market manipulation are unfounded, it is true the market makers do extract some value from the trades placed by investors. While some advocates may argue that such a system should be overthrown and replaced by a decentralized system that excludes these “vampires,” DeFi has its own version of vampires.
To understand the different ways that value is extracted from transactions placed on the blockchain, it’s important to understand how an order placed on someone’s computers gets put into a block. Let’s take a simple transaction on a decentralized exchange (DEX) like Uniswap. Trader A swaps USDC for ETH. For this transaction to occur, a miner must put it into a block. To incentivize the miner to do this, traders pay “gas.” On Ethereum, this is measured by gwei. Paying more gwei will get the transaction placed into a block quicker; while the transaction is waiting, it sits in the “mempool.”
The mempool is public. In fact, you can see it here: https://etherscan.io/txsPending. That means every trade placed on Ethereum can be seen by anyone monitoring the mempool. This is where “searchers” enter the picture. These searchers look for trades that they can extract some value from. This value extraction, known as MEV, generally falls into three buckets: liquidations, arbitrage, and sandwiches. While there are more complex forms of MEV, they are outside the scope of this post.
Liquidations
Liquidations occur when a user’s collateral falls under a certain threshold relative to their debt. When the collateral falls below this threshold, the protocol takes possession and sells the assets to pay off the debt, leaving whatever was left in the account. For orderly liquidations to occur, protocols rely on third parties, generally bots, to bid on the assets subject to liquidation. While the best bots include custom code, many protocol will include some code on their github to help participants get started. For instance, you can see Aave’s here: https://docs.aave.com/developers/guides/liquidations
To extract value from a liquidation, the bot must pay less then what the assets are worth plus gas fees. In most instances, the profits are relatively small; however, there have been certain instances where the rewards were enormous.
Specifically, on March 12th, 2020, the price of ETH was tumbling at a dizzying pace. At the same time, gas prices were spiking. Maker, a lending protocol, began to liquidate accounts with collateral no longer covering the outstanding debt; unfortunately, the bots that normally bid on this collateral had been programmed with a relatively low gas limit; because their bids had paid too little gas, they had no chance of their transactions being place into a block in a normal time window. Thus, a few savvy bots paying enough gas were able to bid for 100s of ETH for effectively 0 Dai (a stable coin = $1). The bots ultimately exploited this issue for around $8 million.
Another frustrating element of liquidation can be front running by bots when a debtor near liquidation goes to increase their collateral. Let’s say a debtor can be liquidated if the price of ETH falls below $2,000, and the price is currently $1,999. The debtor may place a transaction to re-collateralize their vault, but a bot places a transaction in the block before them to buy the collateral. This results in the assets in the vault going to the bot and the user incurs a liquidation penalty. While you could argue that the user should have never let the vault get into this precarious spot, compare this to TradFi, where the user gets a margin call and has until the end of day to top off collateral.
Arbitrage
While there are many forms of arbitrage, this post will only focus on a relatively simple form. Decentralized exchanges like Uniswap have pools with asset pairs. These pools do not know the price of the assets in the pool. Rather, they rely on arbitrageurs to trade within the pool to keep prices aligned. Specifically, for a constant-product market maker, the pool must stay in 50/50 alignment. This means if a USDC/ ETH pool has $100k in it, it has $50k ETH and $50k USDC.
Now let’s say the price of ETH quickly moves to $3k. The Uniswap pool doesn’t know this. That means an arbitrage bot could go into the pool, begin buying ETH at $2k, and immediately sell it on another exchange for $3k. Because every purchase shifts the price of ETH in the pool, eventually the arbitrageur will put the price imbalance back in order.
Sandwiches
Sandwiches involve buying before a transaction and then immediately selling after. Let say an order to purchase $1 million ETH is sitting in the mempool. A bot can front-run this transaction, buying the ETH at a lower price. The large transaction will almost inevitability cause the price of ETH to increase. Then immediately after, the sandwicher back-runs the purchase for a small profit. If the price of gas spent on this transaction is lower than the profit, the sandwicher has a net profit.
The real innovation in sandwiches came with the creation of MEV-GETH, a fork of go-ethereum, by Flashbots. This fork allows sandwichers to submit bundled transaction. Because it is critical that the sandwicher’s transaction come directly prior to and after the large order, the sandwicher needs a way to ensure that if this does not occur, the entire transaction is reverted. This is exactly what MEV-GETH allows. As can be seen in the tweet below, bundled transactions have become common on Ethereum.
Solutions
While some MEV is inevitable, traders can protect themselves against some of the most egregious forms of MEV. For instance, a newer DEX called Cow Swap uses an off-chain order book to attempt to match as many orders as possible. This has a dual benefit; by keeping most of the order off AMMs, not only is there less slippage, but MEV cannot be extracted. Also, SushiSwap recently integrated Archer Swap into the protocol, which prevents MEV.
Traders can also avoid the mempool by sending transactions directly to miners. While this isn’t necessarily feasible for small traders, most MEV is not being extracted from small trades anyway.
Beyond the two mentioned solutions above, other fixes are currently in the works. Protocols that encrypt order details and others that extract MEV and return the majority to users are in the works. Further, much of the MEV currently extracted from the blockchain won’t be possible with Ethereum 2.0.
Conclusion
This post only touches the surface of the different ways value is extracted from the Ethereum blockchain. If you want to learn more, I recommend listening to the podcast below featuring @hasufl and @mevintern. As you’ll learn, the methods of extracting value are only getting more sophisticated, leaving hobbyists behind. It seems almost inevitable that MEV will become institutionalized, with teams of searchers collaborating for maximum effect. On the other hand, protocols are fighting back, implementing measures to protect their users. Only time will tell who wins this battle.
Sources
https://insights.glassnode.com/what-really-happened-to-makerdao/
https://docs.aave.com/developers/guides/liquidations
https://github.com/flashbots/mev-geth/blob/master/README.md
https://cowswap.exchange/#/about