Skip to content

Commit

Permalink
Remove an extra argument from crossTick (#7729)
Browse files Browse the repository at this point in the history
* Remove an extra argument from crossTick

* Fix test
  • Loading branch information
ValarDragon authored Mar 15, 2024
1 parent 5001247 commit 7b7f86b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (k Keeper) GetPoolById(ctx sdk.Context, poolId uint64) (types.ConcentratedP
return k.getPoolById(ctx, poolId)
}

func (k Keeper) CrossTick(ctx sdk.Context, poolId uint64, tickIndex int64, nextTickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (liquidityDelta osmomath.Dec, err error) {
func (k Keeper) CrossTick(ctx sdk.Context, poolId uint64, tickIndex int64, nextTickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (err error) {
return k.crossTick(ctx, poolId, tickIndex, nextTickInfo, swapStateSpreadRewardGrowth, spreadRewardAccumValue, uptimeAccums)
}

Expand Down
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (s *KeeperTestSuite) crossTickAndChargeSpreadReward(poolId uint64, tickInde
s.Require().NoError(err)

// Cross the tick to update it.
_, err = s.Clk.CrossTick(s.Ctx, poolId, tickIndexToCross, &nextTickInfo, DefaultSpreadRewardAccumCoins[0], feeAccum.GetValue(), uptimeAccums)
err = s.Clk.CrossTick(s.Ctx, poolId, tickIndexToCross, &nextTickInfo, DefaultSpreadRewardAccumCoins[0], feeAccum.GetValue(), uptimeAccums)
s.Require().NoError(err)
s.AddToSpreadRewardAccumulator(poolId, DefaultSpreadRewardAccumCoins[0])
}
Expand Down
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func (k Keeper) swapCrossTickLogic(ctx sdk.Context,

// Retrieve the liquidity held in the next closest initialized tick
spreadRewardGrowth := sdk.DecCoin{Denom: tokenInDenom, Amount: swapState.globalSpreadRewardGrowthPerUnitLiquidity}
_, err := k.crossTick(ctx, p.GetId(), nextInitializedTick, &nextInitializedTickInfo, spreadRewardGrowth, spreadRewardAccum.GetValue(), *uptimeAccums)
err := k.crossTick(ctx, p.GetId(), nextInitializedTick, &nextInitializedTickInfo, spreadRewardGrowth, spreadRewardAccum.GetValue(), *uptimeAccums)
if err != nil {
return swapState, err
}
Expand Down
6 changes: 3 additions & 3 deletions x/concentrated-liquidity/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (k Keeper) initOrUpdateTick(ctx sdk.Context, poolId uint64, tickIndex int64
// CONTRACT: the caller validates that the pool with the given id exists.
// CONTRACT: caller is responsible for the uptimeAccums to be up-to-date.
// CONTRACT: uptimeAccums are associated with the given pool id.
func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (liquidityDelta osmomath.Dec, err error) {
func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickInfo *model.TickInfo, swapStateSpreadRewardGrowth sdk.DecCoin, spreadRewardAccumValue sdk.DecCoins, uptimeAccums []*accum.AccumulatorObject) (err error) {
if tickInfo == nil {
return osmomath.Dec{}, types.ErrNextTickInfoNil
return types.ErrNextTickInfoNil
}

// subtract tick's spread reward growth opposite direction of last traversal from current spread reward growth global, including the spread reward growth of the current swap.
Expand All @@ -93,7 +93,7 @@ func (k Keeper) crossTick(ctx sdk.Context, poolId uint64, tickIndex int64, tickI
),
})

return tickInfo.LiquidityNet, nil
return nil
}

// GetTickInfo gets the tickInfo given a poolId and tickIndex. If the tick has not been initialized, it will initialize it.
Expand Down
3 changes: 2 additions & 1 deletion x/concentrated-liquidity/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,13 @@ func (s *KeeperTestSuite) TestCrossTick() {
}

// System under test
liquidityDelta, err := s.App.ConcentratedLiquidityKeeper.CrossTick(s.Ctx, test.poolToGet, test.tickToGet, nextTickInfo, test.additiveSpreadFactor, spreadRewardAccum.GetValue(), uptimeAccums)
err = s.App.ConcentratedLiquidityKeeper.CrossTick(s.Ctx, test.poolToGet, test.tickToGet, nextTickInfo, test.additiveSpreadFactor, spreadRewardAccum.GetValue(), uptimeAccums)
if test.expectedErr != nil {
s.Require().Error(err)
s.Require().ErrorAs(err, &test.expectedErr)
} else {
s.Require().NoError(err)
liquidityDelta := nextTickInfo.LiquidityNet
s.Require().Equal(test.expectedLiquidityDelta, liquidityDelta)

// now check if spread factor accumulator has been properly updated
Expand Down

0 comments on commit 7b7f86b

Please sign in to comment.