Skip to content
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

fix: bug decrease liquidity #140

Merged
merged 3 commits into from
Nov 24, 2024
Merged

fix: bug decrease liquidity #140

merged 3 commits into from
Nov 24, 2024

Conversation

Senna46
Copy link
Contributor

@Senna46 Senna46 commented Nov 23, 2024

Overview

Fixed a problem in the DecreaseLiquidity and IncreaseLiquidity process that caused incorrect settlements.
Rewards are now correctly earned with IncreaseLiquidity and DecreaseLiquidity.

Details

  • L149-159
    Remove unnecessary SetPosition. No need to update DB here.

  • R217-225
    Changed so that rewards are claimed before positions are deleted. Fixed typo liquiditDelta

  • L247-L264
    The location of the rewards claim was changed before the position was changed (R217-225). Other logic has been integrated into the UpdatePosition function to avoid wasteful processing.

  • R356-R374 & R382-R400
    The deleted L247-L264 process has been integrated here. To avoid both deleting and updating positions.

@Senna46 Senna46 requested a review from kimurayu45z November 23, 2024 01:37
Senna46 added a commit that referenced this pull request Nov 23, 2024
@Senna46 Senna46 mentioned this pull request Nov 23, 2024
Senna46 added a commit that referenced this pull request Nov 23, 2024
@@ -226,8 +214,15 @@ func (k Keeper) DecreaseLiquidity(ctx sdk.Context, sender sdk.AccAddress, positi
return math.Int{}, math.Int{}, errorsmod.Wrapf(types.ErrPoolNotFound, "pool id: %d", position.PoolId)
}

liquiditDelta := liquidity.Neg()
amountBase, amountQuote, lowerTickEmpty, upperTickEmpty, err := k.UpdatePosition(ctx, position.PoolId, sender, position.LowerTick, position.UpperTick, liquiditDelta, positionId)
if liquidity.Equal(position.Liquidity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

Is if liquidity.Equal(position.Liquidity) { really needed?
I am thinking of a possibility that we should collect fees anytime

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to dig the relation with k.SetAccumulatorPositionFeeAccumulator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem since this function is only called for DecreaseLiquidity and IncreaseLiquidity.
simple and good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already merged #141, and to avoid confusion, it's better to change the spec from v0.3.x.

@kimurayu45z kimurayu45z merged commit 17f833b into main Nov 24, 2024
1 check passed
@kimurayu45z kimurayu45z deleted the fix/decrease-liquidity branch November 24, 2024 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants