diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b3a5a9ca03..029090644d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#7106](https://github.com/osmosis-labs/osmosis/pull/7106) Halve the time of log2 calculation (speeds up TWAP code) * [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7172) Lower CPU overheads of the Osmosis epoch. * [#7203](https://github.com/osmosis-labs/osmosis/pull/7203) Make a maximum number of pools of 100 billion. +* [#7258](https://github.com/osmosis-labs/osmosis/pull/7258) Remove an iterator call in CL swaps and spot price calls. ### Bug Fixes diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index f6baeb245d4..65275beb7c8 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -164,6 +164,17 @@ func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error) return denoms, nil } +// Return true if the Pool has a position. This is guaranteed to be equi-satisfiable to +// the current sqrt price being 0. +// We also check that the current tick is 0, which is also guaranteed in this situation. +// That derisks any edge-case where the sqrt price is 0 but the tick is not 0. +func (k Keeper) PoolHasPosition(ctx sdk.Context, pool types.ConcentratedPoolExtension) bool { + if pool.GetCurrentSqrtPrice().IsZero() && pool.GetCurrentTick() == 0 { + return false + } + return true +} + func (k Keeper) CalculateSpotPrice( ctx sdk.Context, poolId uint64, @@ -175,10 +186,7 @@ func (k Keeper) CalculateSpotPrice( return osmomath.BigDec{}, err } - hasPositions, err := k.HasAnyPositionForPool(ctx, poolId) - if err != nil { - return osmomath.BigDec{}, err - } + hasPositions := k.PoolHasPosition(ctx, concentratedPool) if !hasPositions { return osmomath.BigDec{}, types.NoSpotPriceWhenNoLiquidityError{PoolId: poolId} diff --git a/x/concentrated-liquidity/swaps.go b/x/concentrated-liquidity/swaps.go index 93b45633e48..72811dc621e 100644 --- a/x/concentrated-liquidity/swaps.go +++ b/x/concentrated-liquidity/swaps.go @@ -787,10 +787,7 @@ func (k Keeper) getPoolForSwap(ctx sdk.Context, poolId uint64) (types.Concentrat if err != nil { return p, err } - hasPositionInPool, err := k.HasAnyPositionForPool(ctx, poolId) - if err != nil { - return p, err - } + hasPositionInPool := k.PoolHasPosition(ctx, p) if !hasPositionInPool { return p, types.NoSpotPriceWhenNoLiquidityError{PoolId: poolId} }