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.
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.
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).
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.
Contracts contain bugs.