Advanced MEV‑aware fee logic for Uniswap V4 pools. It combines cooldown‑based and impact‑based fees with Anti‑JIT liquidity penalties, multi‑address collusion detection, and fee donation back to the pool. Experimental — testnet/research only.
- Quickstart
- Features
- How it works
- Makefile targets
- Configuration
- Deployment
- Development
- Security
- License
- References
git clone https://github.com/MrLightspeed/MEVChargeHook.git
cd MEVChargeHook
./bootstrap.sh # (optional) install toolchain from ./tools cache
make build # compile contracts
make test # run unit tests
make analyze # slither & mythril
make fuzz # echidna (requires local install)
- Dynamic, decaying fees after trades (cooldown‑based)
- Impact‑based fees for large sell orders
- Anti‑JIT penalties on early liquidity removals
- Fee donation: extra dynamic sell fees (beyond fixed LP fee) and Anti‑JIT penalties donated to the pool
- Collusion deterrence: linked addresses share cooldown windows
- Explicit events + custom errors for auditability
Stateful
_getFee
:_getFee
computes fees and immediately charges and donates any extra portion via_processExtraFeeDonation
. Integrators must not treat it as a pure or view-like function.
See the Project Overview for diagrams and the full mechanism design.
MEVChargeHook is a Uniswap V4 Hook contract. Hooks attach custom logic that runs before/after pool lifecycle actions and are selected by permission bits encoded into the hook address. The PoolManager only calls the hook functions that match the encoded bits. A deployer must therefore mine a CREATE2 salt that yields the correct address pattern (see Deployment).
Run make help
to list all targets. Common ones:
Target | Purpose |
---|---|
build |
Compile with Forge |
test |
Run unit tests + gas report |
lint |
Run solhint / markdownlint |
analyze |
Slither & Mythril |
fuzz |
Echidna fuzz tests |
clean |
Remove build artifacts |
qa |
lint + analyze + test |
Configure the following environment variables:
Variable | Purpose |
---|---|
RPC_URL |
JSON‑RPC endpoint for deployments |
ETHERSCAN_API_KEY |
API key for contract verification |
DEPLOYER_ADDRESS |
Named deployer address in Foundry |
See foundry.toml
for additional options and remappings.
- Choose PoolManager → Use official Uniswap v4 deployments for your target network. See the Deployments page for current addresses.
- Mine the hook address → The enabled hook callbacks are encoded in the least significant bits
of the contract address. Use the provided
scripts/salt-miner.js
or your own miner to find a salt that yields the required bits. - Deploy → Use
forge script
or the provided scripts to broadcast and verify.
Tip: for local testing, Foundry’s
vm.deployCodeTo
can spoof addresses without mining. For real networks you must mine a valid address.
- Solidity: 0.8.30 (EVM =
prague
),via-ir
builds, optimizer enabled. - Contracts: Leverages OpenZeppelin 5.x utilities including
ReentrancyGuardTransient
. - Testing: Forge tests cover fee donation flow and events; static + symbolic analysis in CI; optional Echidna fuzzing.
This repository is experimental and not audited. Use on testnets only. Please follow the disclosure process in SECURITY.md.
MIT © 2025 MrLightspeed.