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

Use some more mutative operations in uptime accumulator operations #7541

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions x/concentrated-liquidity/incentives.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ func (k Keeper) updatePoolUptimeAccumulatorsToNowWithPool(ctx sdk.Context, pool
}

var dec1e9 = osmomath.NewDec(1e9)
var oneDec = osmomath.OneDec()

// updateGivenPoolUptimeAccumulatorsToNow syncs all given uptime accumulators for a given pool id
// updateGivenPoolUptimeAccumulatorsToNow syncs all given uptime accumulators for a given pool id.
// Updates the pool last liquidity update time with the current block time and writes the updated pool to state.
// If last liquidity update happened in the current block, this function is a no-op.
// Specifically, it gets the time elapsed since the last update and divides it
Expand All @@ -162,10 +163,14 @@ var dec1e9 = osmomath.NewDec(1e9)
// CONTRACT: the caller validates that the pool with the given id exists.
// CONTRACT: given uptimeAccums are associated with the given pool id.
// CONTRACT: caller is responsible for the uptimeAccums to be up-to-date.
//
// WARNING: this method may mutate the pool, make sure to refetch the pool after calling this method.
// Note: the following are the differences of this function from updatePoolUptimeAccumulatorsToNow:
//
// * this function does not refetch the uptime accumulators from state.
//
// * this function operates on the given pool directly, instead of fetching it from state.
//
// This is to avoid unnecessary state reads during swaps for performance reasons.
func (k Keeper) updateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []*accum.AccumulatorObject) error {
if pool == nil {
Expand All @@ -175,7 +180,7 @@ func (k Keeper) updateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool typ
// Since our base unit of time is nanoseconds, we divide with truncation by 10^9 to get
// time elapsed in seconds
timeElapsedNanoSec := osmomath.NewDec(int64(ctx.BlockTime().Sub(pool.GetLastLiquidityUpdate())))
timeElapsedSec := timeElapsedNanoSec.Quo(dec1e9)
timeElapsedSec := timeElapsedNanoSec.QuoMut(dec1e9)

// If no time has elapsed, this function is a no-op
if timeElapsedSec.IsZero() {
Expand Down Expand Up @@ -204,7 +209,7 @@ func (k Keeper) updateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool typ

// If there is no share to be incentivized for the current uptime accumulator, we leave it unchanged
qualifyingLiquidity := pool.GetLiquidity()
if !qualifyingLiquidity.LT(osmomath.OneDec()) {
if !qualifyingLiquidity.LT(oneDec) {
for uptimeIndex := range uptimeAccums {
// Get relevant uptime-level values
curUptimeDuration := types.SupportedUptimes[uptimeIndex]
Expand Down