Review: Risks and opportunities of MEV in USDC panic run tide
DAOrayaki
2023-03-19 06:30
本文约5226字,阅读全文需要约21分钟
A zero-based quick start guide on MEV.

A Zero-Based Quick Start Guide to MEV - by Wyeeh

Note: This article only involves academic analysis and communication of current affairs hotspots.

Event origin

On March 8, 2023, SVB Financial Group, the parent company of Silicon Valley Bank (SVB), announced that it would sell securities assets worth US$21 billion at a loss in order to cope with the continuous increase in funds caused by user withdrawals in the context of the Federal Reserve raising interest rates and the continued downturn in technology stocks. flow out. The news of selling assets at a loss to deal with the liquidity crisis further triggered investor panic in the market. On the 9th, the stock price of SVB Financial plummeted 60.41%. Investors and depositors tried to withdraw $42 billion from Silicon Valley Bank. One of the largest bank runs in the United States. On the 10th, California regulators shut down Silicon Valley Bank and sent it into receivership.

The black swan of SVB’s collapse triggered a series of chain crises that spread to the crypto market. On March 11, Circle, the issuer of the stablecoin USDC, tweeted that out of its total fund reserves of about 40 billion US dollars, about 3.3 billion cash reserves are stored in SVB. After Circle’s announcement, its exposure to SVB also sparked panic in the market. To limit their losses, investors began selling their USDC in exchange for other stablecoins like Tether (USDT). USDC faced a severe run and its price continued to unpeg, dropping as low as $0.88. At the same time, centralized trading platforms such as Binance and Coinbase announced the closure of some USDC exchange services.

In the midst of panic runs and market chaos, token prices fluctuated wildly, and MEV searchers were able to see profit opportunities instead. And being a victim of an MEV target can unfortunately result in huge losses. In the current wave of USDC runs, there was one such MEV arbitrage incident. An investor whose address starts with 0x 8 ff is trying to convert his stablecoin position, and wants to exchange his 2.03 million 3 CRV tokens for USDT (3 CRV is the LP token of the Curve liquidity pool, which consists of USDT, USDC, DAI three stable coins), but it did not release the LP token directly through Curve, but sent the transaction to an almost completely illiquid Uniswap (only about $2 in liquidity) via KyberSwap aggregation routing ), this fund pool has been idle for the past 251 days.

In addition, according to the analysis of Twitter user @BowTiedPickle, in addition to the KyberSwap routing problem, the giant whale probably did not set the slippage correctly in a hurry, making this transaction an unfortunate target for MEV robot arbitrage.

After the transaction was sent, the MEV robot completed a trailing transaction, paid a gas fee of $45 and a builder tip of 23.8 ETH (worth about $39,000), and exchanged 1.45 USDC in LP for the victim sent The 2.03 million 3 CRV, took away about 2.045 million US dollars in profits. The 2.03 million 3 CRV sent by the victim was only exchanged for 0.05 USDT in the end.

Victim transaction:

https://etherscan.io/tx/0xde46a6bb1fc7834dde4d01428c88f84d65a607f4dc11b7f3dd710e86b7d226a8

https://eigenphi.io/mev/eigentx/0x de 46 a 6 bb 1 fc 7834 dde 4 d 01428 c 88 f 84 d 65 a 607 f 4 dc 11 b 7 f 3d d 710 e 86 b 7 d 226 a 8 

Trailing transactions for MEV robots:

https://etherscan.io/tx/0x8a6be1e4db4375c1a1c9d1e5c5fcaa5c255b2d24f5da3de05f3b25d7c3508021

https://eigenphi.io/mev/eigentx/0x8a6be1e4db4375c1a1c9d1e5c5fcaa5c255b2d24f5da3de05f3b25d7c3508021

In the DeFi ecosystem, MEV is the most troublesome but difficult risk issue for traders in the process of token exchange in DEX. Especially in a crisis, MEV is the most dynamic and destructive presence in a volatile market.

What are MEVs? How does it generate profits for traders? What does a complete arbitrage trading process look like? How to use DeFi's flash loan function to achieve "zero capital and huge profits" return? The purpose of this article is to answer the above questions and provide a primer for traders interested in MEV. Welcome to the world of MEVs.

Overview of MEVs

In the context of Proof of Work (PoW), MEV originally referred to Miners extractable value, which refers to the ability of miners to arbitrarily add, exclude, or reorder transactions within the blocks they produce. profit.

With the merger of Ethereum (Merge) and the addition of the Proof of Stake consensus layer (PoS), the Proposer/Builder Separation (PBS: Proposer/Builder Separation) will be implemented, which will collect transactions and propose block roles and sort build blocks role (i.e. determining which transactions are included in a block in what order) separately. Among them, the previous role of miners was taken by the validator in the PoS network. In the context of PoS, the definition of MEV is extended to Maximal extractable value, which means that the verifier adds, deletes and changes the order of transactions in the block, in the block production that exceeds the standard block reward and gas fee The maximum value that can be extracted.

Although in theory, MEV should be earned entirely by validators, since they are the only party who can guarantee that the arbitrage opportunity will be put into practice. However, in practice MEV will not be fully extracted by validators, but may be divided up by arbitrage traders and robots (MEV-bots) called "searchers".

In fact, the logic of MEV is similar to high-frequency trading (HFT) in securities trading. In an automated market maker (AMM)-based DEX, every trade generates slippage: every dollar of asset sold pushes the new exchange price down a bit. This opens up the possibility for searchers who want to make a profit from the price difference. MEV Seekers rely on the specific order of transactions in Ethereum blocks to make a profit. They scan the blockchain data to capture the DEX transactions of ordinary users, and look for potential arbitrage opportunities from the price difference between different DEXs, and then pay high gas fees to seize the opportunity. In general, MEV is also a general term for arbitrage transactions that occur on the chain.

Several types of MEV

Front-runs

This type of MEV refers to executing transactions ahead of known transactions in the mempool. MEV Seekers scan the mempool for profitable transactions. For example, if the MEV robot finds a large transaction, it will copy the user's transaction and pay a higher gas fee to ensure that it has the highest priority in the order of transactions in the block and can be confirmed earlier.

Trailing transactions (back-runs)

arbitrage

arbitrage

The basic logic of arbitrage is to "buy low and sell high" between different DEX liquidity pools (Liquidity Pool), and use the exchange price difference to earn profits.

Bilateral arbitrage is also called direct arbitrage. It discovers the price difference relationship between two fund pools of the same trading pair (such as WETH/USDC), sells high and buys low, and arbitrages profit from the difference. A typical bilateral arbitrage process is as follows:

image description

Figure: Schematic diagram of bilateral arbitrage process

On the basis of simple bilateral arbitrage, searchers can also scan the price difference of token pairs between three or more fund pools (such as WETH/USDC, WETH/DAI, DAI/USDC), and exchange continuously through three, four or more times Different token pairs to achieve arbitrage.

image description

Figure: Schematic diagram of the three-sided arbitrage process

By analogy, in the actual arbitrage transaction, the searcher can also use the price difference of multiple token pairs from multiple fund pools to realize arbitrage of buying low and selling high. At present, through smart contracts, MEV robots can even complete the exchange of hundreds of token pairs from hundreds of fund pools in an instant. For example, in the following arbitrage transaction, the MEV robot completed the exchange of token pairs in 172 fund pools, involving a total of 81 tokens.

sandwich attack

sandwich attack

Sandwich MEV exists because DeFi transaction users must send the expected transaction to the blockchain's memory pool (memepool) to wait for confirmation. In other words, these transactions are not put into the block immediately, but are ordered within the block according to the gas fee/priority fee paid. Whereas MEV bots typically look for specific trades in the mempool and attempt to front-run or trail trades according to a predetermined algorithm.

A typical sandwich process is as follows: First, the searcher finds that a user has sent a transaction to exchange 130,500 USDC for WETH. At this time, the exchange price of WETH/USDC in the fund pool is 1300. At this time, the searcher can ① send a transaction of exchanging 130,000 USDC for WETH, and pay a higher gas fee to advance the order of transactions, complete the pre-emptive transaction, and purchase 100 WETH at an exchange price of 1300. As mentioned above, every exchange may generate slippage in the DEX. After front-running, suppose the price of WETH/USDC in the DEX is pulled up to 1305. ②The transaction of 130,500 USDC exchanged for WETH originally submitted by the user is executed, and 100 WETH is purchased at the new exchange price. ③At the same time, the searcher sent a trailing transaction, and exchanged 100 WETH back to 130,500 USDC at a price of 1305. In summary, the total income available to the searcher is 500 USDC. Assuming that the priority gas fee that needs to be paid to ensure the execution of the front-running transaction is 0.05 ETH, then the net profit is equal to 500 USDC minus 0.05 ETH.

to liquidate

to liquidate

Generally speaking, lending protocols such as AAVE and Compound require users to deposit a certain amount of assets as collateral, and then lend these deposited collateral to other users. As the value of collateralized assets fluctuates, so does the borrowing power of users. When the borrower's collateral value is not enough to cover the value of its debt, the lending agreement will liquidate the borrower, and anyone in the market can complete the liquidation. To incentivize liquidation, the protocol charges the borrower a liquidation fee and hands a portion of that fee to the liquidator. So Seekers race to monitor the positions of all borrowers to determine which ones can be liquidated and be the first to submit a liquidation transaction and collect a liquidation fee.

Arbitrage on the MEV chain based on flash loans

flash loan

A block can contain multiple transactions, and multiple operations can be performed in one transaction, as long as the final state of the transaction is correct, the operation can be completed. In view of this characteristic, the DeFi lending platform AAVE created "flash loan". Flash loans are instant unsecured loans that allow users to borrow assets from on-chain liquidity pools without collateral, but the borrowed assets must be repaid in the same blockchain transaction. This means that the borrower must call the smart contract, repay the loan immediately before the transaction is closed, and pay a loan service fee according to a certain percentage. Because the transaction usually closes within seconds, this type of lending is called a flash loan. If the borrower does not repay the loan in the same transaction, the entire transaction is reversed, including the initial borrowing and any actions taken afterward. Flash loans can provide DeFi users with low-cost and instant liquidity. At present, many protocols (such as AAVE, Balancer Vault, Uniswap V3, dYdX, etc.) provide flash loan services, which creates an opportunity for MEV searchers with insufficient liquidity Opportunities of "a lot of money" or even "zero money". The following article will introduce how to use flash loans to achieve risk-free arbitrage.

Arbitrage Trading Analysis Actual Combat

Currently, the data products that can be used to analyze MEV transactions include EigenPhi, zeromev, MEV-Explore of flash bots, etc. In the following, we will use EigenPhi’s EigenTx visualization tool to analyze a real flash loan arbitrage transaction. in this transaction

(0x2ac586b83b5222cac59c854cca1e202605919fe2fdacfbef1d2e0489bbb26e53), the searcher made a net profit of $11,981 at a cost of $5.6.

The figure below presents the token flow of a flash loan arbitrage transaction using Uniswap V3.

There are five transaction nodes in the figure: two WOOL/WETH token pair liquidity pools (UNI-V2 LP 1 and UNI-V3 LP 2), to address (that is, the address of the smart contract submitted by the searcher), and the flash loan agreement (Uniswap V3 Pool), and the wallet address of the searcher (leaf leaf node).

The overall arbitrage logic of this transaction is: the searcher found that in the two liquidity pools (LP 1 is located in Uniswap V2, LP 2 is located in Uniswap V3), there is a difference in the exchange price of the WOOL/WETH token pair, which has room for arbitrage. The searcher first exchanged 1.1474 WETH for 851,424 WOOL in LP 1 (see steps 1 and 2 in the figure), and exchanged the exchanged 851,424 WOOL for 11.4902 WETH in LP 2 (see steps 3 and 4 ). The income from this arbitrage is equal to the 11.4902 WETH obtained in step 3 minus the 1.1474 WETH paid in step 1, which is about 10.34 WETH.

In the above arbitrage process, the "startup capital" in step 1, namely 1.1474 WETH, is a flash loan borrowed from Uniswap V3 (see step 0). After the arbitrage is completed, the searcher repays the flash loan and pays the service fee, returning a total of 1.1479 WETH to the platform (see step 5). Ultimately, the searcher's profit from this transaction is equal to its income (10.34 WETH) minus the Flash Loan service fee and gas fee (see step 6).

It should be noted that although the above diagram splits the entire transaction into several steps, the above steps are all completed at the same time in the smart contract. The searcher does not even need to pay the initial capital to complete the arbitrage, so this transaction is actually a zero-cost "empty glove wolf".

Summarize

Summarize

MEV is a special product of the DeFi ecosystem, where arbitrage and liquidation can promote market efficiency, but sandwich attacks will threaten every DeFi trader. According to data from MEV-Explore, the cumulative profit of MEV on Ethereum has reached 687 million US dollars. With the merger of Ethereum, the activity of MEV has been suppressed, but it is still a market disturbance force that cannot be ignored.

refer to

refer to

  • Ethereum Development Documentation https://ethereum.org/en/developers/docs/mev/

  • The First Five Years of MEV: Before Flashbots https://foresightnews.pro/article/detail/22060

  • The Next Five Years of MEV: Understanding the Latest Trends in the MEV Field https://foresightnews.pro/article/detail/23394

  • An article to understand MEV chain arbitrage https://foresightnews.pro/article/detail/16585

  • In-Depth Research: Past, Present and Future of MEV https://foresightnews.pro/article/detail/18044

  • Depth | An overview of MEV's cutting-edge development and track project panorama https://www.defidaonews.com/article/6790242

  • The 0 to 1 GuideforMEVhttps://calblockchain.mirror.xyz/c 56 CHOu-Wow_ 50 qPp 2 Wlg 0 rhUvdz 1 HLbGSUWlB_KX 9 o

  • EigenPhi Classroom https://eigenphi-1.gitbook.io/classroom/

  • Is MEV a good investment opportunity? https://mp.weixin.qq.com/s/s 7 fTlOIlxP 92 w 5 fK 7 wsE 3 Q

  • Ethereum is a Dark Forest https://www.paradigm.xyz/2020/08/ethereum-is-a-dark-forest

  • An article to understand how MEV is generated and its flow mechanism in the Ethereum network https://cointelegraphcn.com/news/best-understand-mev

  • AAVE's documentation of flash loans https://docs.aave.com/developers/guides/flash-loans

  • What Is a Flash Loan? A guide to one of DeFi’s most innovative and controversial features. https://www.coindesk.com/learn/what-is-a-flash-loan/

  • Aave and Flash Loans: Uncollateralized Lending in DeFi https://www.gemini.com/cryptopedia/aave-flashloans

  • What Are Flash Loans? https://chain.link/education-hub/flash-loans

  • How to Use AAVE Loan to Launch a Sandwich MEV Attack? https://eigenphi.substack.com/p/aave-loan-sandwich-attack

  • Get Everything for Nothing: How to Use Flash Loans to Launch an Arbitrage? https://eigenphi.substack.com/p/complicated-flash-loan-mev

  • What Is MEV, aka Maximal Extractable Value? https://www.coindesk.com/learn/what-is-mev-aka-maximal-extractable-value/

  • Ethereum’s Hidden Tax: Maximal Extractable Value (MEV) https://www.treehouse.finance/insights/ethereums-hidden-tax-maximal-extractable-value-mev

  • https://www.mev.wiki/

DAOrayaki
作者文库