Skip to content

SeanJCasey/uni-v4-rate-deviation-dynamic-fee-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEV Sharing is Caring: Uniswap v4 dynamic fee hook for pool deviation from reference price

This repo provides a Uniswap v4 hook that applies a dynamic pool fee based on the deviation between the implied pool price and a reference rate.

POC FOR UNISWAP HOOK INCUBATOR; DEFINITELY NOT PROD-READY AND ALMOST GUARANTEED TO CONTAIN BUGS

Why?

There are many proposed approaches to handling MEV. While some solutions propose MEV as a "problem" to stop, this takes the opposite approach of treating MEV as profit to be shared amongst liquidity providers.

How it works

To share MEV, this hook:

  1. is invoked during beforeSwap
  2. calculates the approx expected finalPoolPricerice post-swap (using a custom, read-only fork of PoolManager.swap() calculations logic)
  3. queries the referenceRate call associated with the pool
  4. calculates the percent deviation of finalPoolPrice from referenceRate (e.g., 5%)
  5. applies a dynamic fee that increases with percent deviation

Current version and future improvements

  • the reference rate is hardcoded to be a ChainlinkAggregatorV3 interface. It will work with any contract adhering to that interface.
    • improvement: handle arbitrary rate calldata
  • uses a binary fee that is either "base" or "elevated"
    • improvement: add a dynamic fee curve
  • uses the same fee and deviation tolerance for all pools
    • improvement: per-pool fees and deviation tolerances
  • current assumption: final price deviation is assumed to represent MEV
    • improvement: account for direction, size, and initial tick of swap
  • general improvement: optimize for gas by caching pool and reference rate precisions

Build

$ forge build

Test

$ forge test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published