An analysis of Maximal Extractable Value (MEV) on the Ethereum network by Garret Nourse, Josh Garbuio, Lia Garrett, Padelis Deligiannis, and Rohan Sanjay. Check out our presentation here!
.
├── LICENSE
├── README.md
├── data
│ ├── mev_api
│ │ ├── blocks.csv
│ │ └── transactions.csv
│ └── mev_inspect
│ ├── arbitrage_swaps.csv
│ ├── arbitrages.csv
│ ├── blocks.csv
│ ├── latest_block_update.csv
│ ├── liquidations.csv
│ ├── miner_payments.csv
│ ├── prices.csv
│ ├── punk_bid_acceptances.csv
│ ├── punk_bids.csv
│ ├── punk_snipes.csv
│ ├── swaps.csv
│ └── transfers.csv
├── notebooks
│ ├── analysis
│ │ ├── ML_models_MEV.ipynb
│ │ ├── flashbots.ipynb
│ │ └── mev_eth2.ipynb
│ └── data_extraction
│ ├── mev_api_data.ipynb
│ └── mev_inspect_data.ipynb
└── presentation.pdf
Our data folder contains CSV files of our data pulled from Flashbot's mev-inspect and mev-blocks API data sources. Note that our mev-inspect data corresponds to all blocks mined on 2021-12-10 (0ver 7000 blocks) and our mev-blocks API data corresponds to the 10,000 most recent Flashbots blocks as of 2021-12-13.
Our notebooks folder contains our code used to analyze the Flashbots data and MEV in ETH2.
We pulled data from Flashbots, a research and development organization working on mitigating the negative externalities of current Maximal Extractable Value (from now on MEV) extraction techniques and avoiding the existential risks MEV could cause to state-rich blockchains like Ethereum.
They offer two free services for MEV data: mev-inspect and the mev-blocks API.
mev-inspect is a Flashbots tool for analyzing historical MEV activity on-chain that finds miner payments, tokens transfers and profit, swaps and arbitrages, and more for any given block. The data is stored in a Postgres instance on a local Kubernetes cluster. To set up mev-insepct on your local machine, follow the instructions below:
-
Clone the mev-inspect-py repo
-
Follow the installation instructions on the repository README
- Running the client requires a RPC_URL endpoint connection to a node on the Ethereum blockchain to fetch blocks, which can be setup for free through Pokt Portal's "Ethereum Mainnet Archival with trace calls" host
-
Note: when applying the database migrations for the first time, type "heads" instead of "head"
./mev exec alembic upgrade heads
-
Happy inspecting and exploring!
While it's a bit of a process to setup, the mev-inspect client is a phenomenal resource with a comprehensive variety of MEV data. Once blocks are inspected, the corresponding data is automatically stored in the Postgres instance database. You can connect to this database directly from the command line through the Kubernetes pod to query and explore the data. However, we wanted to conduct our analysis in Python, so we wrote a script to establish a connection to the database from a python shell on a local machine, query all the data frames, and download them into CSV files on the host machine.
The mev-blocks API contains data for Flashbots blocks and transactions. These are blocks mined by Flashbot miners who select the most profitable bundle of transactions (selected by searchers in the public mempool) and mine it in the next block. Miners get paid by searchers through a direct transfer smart contract, instead of through transaction fees, so that searchers only pay miners if the transaction didn’t fail.
The API is fairly easy to access and use with requests—our code to pull the 10,000 most recent blocks and corresponding transactions can be found here.
MEV: Maximal (or miner) Extractable Value
Front-running: when a miner steals a profitable opportunity (such as arbitrage) for themselves by sending the same transaction with a higher gas price
Sandwiching: profiting off slippage in liquidity pools by buying and selling before and after large transactions posted in the mempool
DEX arbitrage: If two DEXes are offering a token at two different prices, one can buy the token on the lower-priced DEX and sell it on the higher-priced DEX
Liquidations: if the value of a borrowed asset exceeds the collateral, anyone can liquidate the collateral and collect the liquidation fee for themselves