Skip to content

Maintains tick state to enables token rewards based on price in the range and liquidity amount

License

Notifications You must be signed in to change notification settings

xyek/liquidity-mining-hook

Repository files navigation

liquidity-mining-hook

This hook enables rewards for liquidity positions in any reward token based on the time spent by price in the tick range and liquidity amount.

This is a hobby project built during Hookathon C1. If you are interested to tune it to your needs, feel free to contact me on discord @ xyek3165.

Problem

In traditional liquidity mining, user has to perform additional action after addition of liquidity called "stake". Not only this requires multiple transactions and more gas fees but the user experience also degrades.

In Uniswap V3 to V4 upgrade, some tick variables were removed which makes it challenging for external liquidity mining staking contracts to function.

Solution

Maintain additional tick variables in the hook state that enable to calculate rewards for liquidity positions.

Seamless user experience when adding or removing the liquidity using standard v4 interface. And to claim the rewards for their previous liquidity positions users just require to pass a hookData when they are removing liquidity (or they can also add liquidity of 0 value which would also trigger the rewards withdrawal).

How does this work?

This hook contract extends the tick variables present in the V4.

New tick variables are added are: (source).

  • secondsOutside
  • secondsPerLiquidityOutsideX128

These tick variables are maintained using SimulateSwap library that enables a custom hook to the swap step for updating the state on tick cross.

This enables us to know how many seconds the price was present in the range and secondsPerLiquidity enables to factor in the liquidity to calculate the rewards.

Disclaimer

Contracts contain bugs.

About

Maintains tick state to enables token rewards based on price in the range and liquidity amount

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •