MEV-Tax provides a simple way for developers to incorporate MEV taxes into their contracts, enabling them to automatically capture MEV based on the priority fee.
- Easy integration with existing smart contracts
- Tax calculation based on transaction priority fee
- Customizable tax recipient
- Enables various use cases for MEV mitigation (e.g., DEX routers, AMMs, backrunning auctions)
Background: Priority Is All You Need by Dan Robinson and Dave White (Paradigm).
The library calculates a tax amount based on the priority fee per gas of the transaction. When a function with the applyTax()
modifier is called, the library tries to transfer a sufficient amount of an ERC20 currency to cover the tax. If that succeeds, the transaction proceeds. Otherwise, the transaction reverts.
- Install the library in your Solidity project
forge install 0xfuturistic/mev-tax
- Import and inherit
MEVTax
in your smart contract
import {MEVTax} from "mev-tax/src/MEVTax.sol";
- Add
MEVTax
to your constructor
constructor() MEVTax(currencyAddress) {}
replacing currencyAddress
by the address of the ERC20 token for paying the MEV tax.
The implementation works especially well when this is the address of WETH in the network.
For other tokens, an exchange rate from eth may be needed to compute the tax accurately.
- Apply the
applyTax()
modifier to functions where you want to capture MEV
Whoever pays for the tax must have enough amount of currencyAddress
to cover the tax and to have approved at least that amount for the contract.
- Optionally, override the
_getTaxAmount()
function for a custom tax function
The library relies on the assumption of competitive priority ordering, which means it only works for L2s like Base and Optimism, where there's a trusted sequencer, but not for Ethereum Mainnet. Enforcing these rules trustlessly is an open problem.
Feel free to raise an issue, suggest a feature, or even fork the repository for personal tweaks. If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.
For questions and feedback, you can also reach out via Twitter.