Skip to content

A customizable Uniswap V4 Hook providing cooldown management, dynamic fee calculation, and MEV protection through gas-efficient and secure CREATE2 deployment.

License

Notifications You must be signed in to change notification settings

MrLightspeed/MEVChargeHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEVChargeHook

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.

Solidity 0.8.30 License: MIT OpenZeppelin 5.x Uniswap V4 CI


Table of Contents

Quickstart

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)

Features

  • 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.

How it works

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).

Makefile targets

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

Configuration

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.

Deployment

  1. Choose PoolManager → Use official Uniswap v4 deployments for your target network. See the Deployments page for current addresses.
  2. 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.
  3. 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.

Development

  • 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.

Security

This repository is experimental and not audited. Use on testnets only. Please follow the disclosure process in SECURITY.md.

License

MIT © 2025 MrLightspeed.

References

About

A customizable Uniswap V4 Hook providing cooldown management, dynamic fee calculation, and MEV protection through gas-efficient and secure CREATE2 deployment.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •