This repository includes the code and data for reproducibility of the paper: "RediSwap: MEV Redistribution Mechanism for CFMMs".
To set up the environment, ensure you have Python installed. You can install the required dependencies by running:
pip install -r requirements.txtTo download price data from Binance, run the script get_binance_data.py. It will automatically fetch and save the data in the data/binance folder.
The cowswap folder contains trades executed through CoWSwap from September 2023 to August 2024, compressed into separate archives for each month. As mentioned in the paper, each file only includes the trades involving tokens from the list: [USDC, USDT, DAI, WBTC, BTC, ETH, WETH, PEPE, MATIC, LINK].
The file cowswap_count.csv provides a monthly count of trades executed through CoWSwap that utilized the liquidity pool.
The uniswapx folder contains trades executed through UniswapX from September 2023 to August 2024, compressed into separate archives for each month. As mentioned in the paper, each file only includes the trades involving tokens from the list: [USDC, USDT, DAI, WBTC, BTC, ETH, WETH, PEPE, MATIC, LINK].
The file uniswapx_count.csv provides a monthly count of trades executed through UniswapX that utilized the liquidity pool.
The files UniswapV2-USDC.csv.zip and UniswapV2-USDT.csv.zip include the liquidity data for the USDC-ETH and USDT-ETH pools on Uniswap V2 (Ethereum). The data spans the period from September 2023 to August 2024, with liquidity recorded at each block.
To generate the figures shown in the paper, you can navigate to each corresponding subdirectory and execute the scripts.
There are three scripts in the simulation folder that generate the figures in Section 5:
-
compare_cowswap.py: Fig. 2 (a). Percentage of orders with execution prices better than those on CoWSwap. After running the script, it will generate the following figure in thefiguresfolder.cowswap-ratio.pdf
-
compare_uniswapx.py:- Fig. 2 (b). Percentage of orders with execution prices better than those on UniswapX.
- Fig. 3. Candlestick charts of Binance and UniswapX ETH/USDT prices over time.
After running the script, it will generate the following figures in the
figuresfolder.eth-usdt.pdfusdt-eth.pdf
-
lvr.py: Fig. 4. The CDF of LVR reduction for WETH-USDC and WETH-USDT using RediSwap. After running the script, it will generate the following figures in thefiguresfolder.eth-usdc-cdf.pdfeth-usdt-cdf.pdf
Besides, base.py and utils.py contain helper functions and constants used by the scripts mentioned above.
There are two scripts in the appendix folder that generate the figures in Appendix A:
searcher_without_pools.py: Fig. 5 - Percentage of orders filled by direct exchange between users and solvers. After running the script, it will generate the following figures in thefiguresfolder.figures/cowswap_searcher_without_pools.pdffigures/uniswapx_searcher_without_pools.pdf
trade_per_tx.py: Fig. 6 - Distribution of the number of orders per batch. After running the script, it will generate the following figures in thefiguresfolder.figures/cowswap_order_per_tx.pdffigures/uniswapx_order_per_tx.pdf
Consider citing our work if you find it helpful!
@inproceedings{zhang2025rediswap,
title={RediSwap: MEV Redistribution Mechanism for CFMMs},
author={Zhang, Mengqian and Yang, Sen and Zhang, Fan},
booktitle={Proceedings of the 2025 Workshop on Decentralized Finance and Security},
pages={27--36},
year={2025}
}