Skip to content

Commit

Permalink
feat: ticl init/deinit for CL
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Feb 27, 2024
1 parent 0fa56f3 commit 8b01046
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#7590](https://github.com/osmosis-labs/osmosis/pull/7590) fix cwpool migration prop disallowing only one of code id or bytecode.
* [#7582](https://github.com/osmosis-labs/osmosis/pull/7582) IAVL v1
* [#7619](https://github.com/osmosis-labs/osmosis/pull/7619) Create/remove tick events.

## v23.0.0

Expand Down
39 changes: 25 additions & 14 deletions x/concentrated-liquidity/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ func (k Keeper) initOrUpdateTick(ctx sdk.Context, poolId uint64, currentTick int
// calculate liquidityGross, which does not care about whether liquidityIn is positive or negative
liquidityBefore := tickInfo.LiquidityGross

// if given tickIndex is LTE to the current tick and the liquidityBefore is zero,
// set the tick's spread reward growth opposite direction of last traversal to the spread factor accumulator's value
if liquidityBefore.IsZero() {
if tickIndex <= currentTick {
accum, err := k.GetSpreadRewardAccumulator(ctx, poolId)
if err != nil {
return false, err
}

tickInfo.SpreadRewardGrowthOppositeDirectionOfLastTraversal = accum.GetValue()
}
}

// note that liquidityIn can be either positive or negative.
// If negative, this would work as a subtraction from liquidityBefore
liquidityAfter := liquidityBefore.Add(liquidityDelta)
Expand Down Expand Up @@ -153,7 +140,21 @@ func (k Keeper) makeInitialTickInfo(ctx sdk.Context, poolId uint64, tickIndex in
initialUptimeTrackers = append(initialUptimeTrackers, model.UptimeTracker{UptimeGrowthOutside: uptimeTrackerValue})
}

return model.TickInfo{LiquidityGross: osmomath.ZeroDec(), LiquidityNet: osmomath.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: initialSpreadRewardGrowthOppositeDirectionOfLastTraversal, UptimeTrackers: model.UptimeTrackers{List: initialUptimeTrackers}}, nil
uptimeTrackers := model.UptimeTrackers{List: initialUptimeTrackers}

// Emit init tick event
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.TypeEvtInitTick,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
sdk.NewAttribute(types.AttributeKeyTickIndex, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(types.AttributeKeySpreadRewardGrowthOppositeDirectionOfLastTraversal, initialSpreadRewardGrowthOppositeDirectionOfLastTraversal.String()),
sdk.NewAttribute(types.AttributeKeyUptimeGrowthOppositeDirectionOfLastTraversal, uptimeTrackers.String()),
),
})

return model.TickInfo{LiquidityGross: osmomath.ZeroDec(), LiquidityNet: osmomath.ZeroDec(), SpreadRewardGrowthOppositeDirectionOfLastTraversal: initialSpreadRewardGrowthOppositeDirectionOfLastTraversal, UptimeTrackers: uptimeTrackers}, nil
}

func (k Keeper) SetTickInfo(ctx sdk.Context, poolId uint64, tickIndex int64, tickInfo *model.TickInfo) {
Expand All @@ -167,6 +168,16 @@ func (k Keeper) RemoveTickInfo(ctx sdk.Context, poolId uint64, tickIndex int64)
store := ctx.KVStore(k.storeKey)
key := types.KeyTick(poolId, tickIndex)
store.Delete(key)

// Emit remove tick event
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.TypeEvtRemoveTick,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
sdk.NewAttribute(types.AttributeKeyTickIndex, strconv.FormatInt(tickIndex, 10)),
),
})
}

func (k Keeper) GetAllInitializedTicksForPool(ctx sdk.Context, poolId uint64) ([]genesis.FullTick, error) {
Expand Down
2 changes: 2 additions & 0 deletions x/concentrated-liquidity/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
TypeEvtMoveRewards = "move_rewards"
TypeEvtCrossTick = "cross_tick"
TypeEvtTransferPositions = "transfer_positions"
TypeEvtInitTick = "init_tick"
TypeEvtRemoveTick = "remove_tick"

AttributeValueCategory = ModuleName
AttributeKeyPositionId = "position_id"
Expand Down

0 comments on commit 8b01046

Please sign in to comment.