-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow donate() to specify tick #346
Comments
I need this functionality. Thanks for opening the issue! |
@snreynolds Is this change going to be in the v4 release? |
✨ Thanks to the community, there's an estimated bounty value of $68.13 USD for a successful merge request of this issue via contributions such as 6.09375 UNI tokens. Happy coding 😀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component
PoolManager/Pool
Describe the suggested feature and problem it solves.
Right now, donate() can donate additional fees to currently in-range liquidity provides. But there is no way to donate fees to out-of-range liquidity providers—specifically liquidity providers who would be in range if liquidity was at a different tick.
The most common use cases would be for hooks that want to distribute some kind of rent to liquidity providers who have not been traded against (which is currently impossible), or who want to distribute fees or rent to liquidity providers after a trade in some way other than proportional to volume (which would require splitting the swap up and donating after each step).
Some examples:
Describe the desired implementation.
Change
donate
signature to:amount0
,amount1
, andticks
would all have to be arrays of the same length.ticks
would indicate the buckets into which the fees should be donated (identified by the tick immediately below them).ticks
must be sorted from low to high (reverts if it is not).Algorithm
ticks[0]
by walking down to it.liquidityAtTick = liquidityCurrent
.ticks[0]
, applyingliquidityNet
toliquidityAtTick
. The last tick applied should be the last one to the right ofticks[0]
.cumulativeFeeGrowth
s to the respectivefeeGrowthGlobal
s in the current state.ticks
array. If so, loop over them and updatecumulativeFeeGrowth0
andcumulativeFeeGrowth1
by adding the respectiveamount / liquidityCurrent
. Also check that those ticks are in increasing order and revert if not.liquidityCurrent
by applyingliquidityNet
, and update eachfeeGrowthOutside
by addingcumulativeFeeGrowth
to it.Once that's complete, repeat all of those steps, but for the ticks to the right of the current tick. That means you'll need to keep walking up to the last tick to get the liquidityCurrent, and then walk back down, tracking new
cumulativeFeeGrowth
values and applying them to each initialized tick, until you get back to the current tick.Describe alternatives.
The main alternatives hooks can use right now for custom distribution of fees to different liquidity providers who were traded against:
If hooks want to distribute rent to liquidity providers who weren't traded against at all (which is something ex ante auctions might want), only the last option is available.
Another alternative would be for donate to only take one tick, but in that case, donations to all ticks crossed after a large swap would require quadratic gas costs rather than linear.
Additional context.
No response
The text was updated successfully, but these errors were encountered: