Skip to content

Commit

Permalink
Remove some 0 allocations in CL routing (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Apr 12, 2024
1 parent 4a528c6 commit 473b040
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions router/usecase/pools/routable_concentrated_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
)

var _ sqsdomain.RoutablePool = &routableConcentratedPoolImpl{}
var zeroDec = osmomath.ZeroDec()
var zeroBigDec = osmomath.ZeroBigDec()

type routableConcentratedPoolImpl struct {
ChainPool *concentratedmodel.Pool "json:\"cl_pool\""
Expand Down Expand Up @@ -128,7 +130,7 @@ func (r *routableConcentratedPoolImpl) CalculateTokenOutByTokenIn(ctx context.Co
}

// Initialize the swap strategy.
swapStrategy := swapstrategy.New(isZeroForOne, osmomath.ZeroBigDec(), &storetypes.KVStoreKey{}, concentratedPool.SpreadFactor)
swapStrategy := swapstrategy.New(isZeroForOne, zeroBigDec, &storetypes.KVStoreKey{}, concentratedPool.SpreadFactor)

var (
// Swap state
Expand All @@ -145,7 +147,7 @@ func (r *routableConcentratedPoolImpl) CalculateTokenOutByTokenIn(ctx context.Co
}

// Compute swap over all buckets.
for amountRemainingIn.GT(osmomath.ZeroDec()) {
for amountRemainingIn.GT(zeroDec) {
if currentBucketIndex >= int64(len(tickModel.Ticks)) || currentBucketIndex < 0 {
// This happens when there is not enough liquidity in the pool to complete the swap
// for a given amount of token in.
Expand Down

0 comments on commit 473b040

Please sign in to comment.