Skip to content

Commit

Permalink
perf(gamm/CL): backport more QuoRoundUp optimizations from v19.x (#6462)
Browse files Browse the repository at this point in the history
* perf(gamm/CL): backport more QuoRoundUp optimizations from v19.x

* fix bug
  • Loading branch information
p0mvn authored Sep 20, 2023
1 parent c54e222 commit 17569b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func GetNextSqrtPriceFromAmount0InRoundingUp(sqrtPriceCurrent, liquidity, amount
denominator := product
denominator.AddMut(liquidity)
// MulRoundUp and QuoRoundUp to make the final result larger by rounding up at precision end.
return liquidity.MulRoundUp(sqrtPriceCurrent).QuoRoundUp(denominator)
return liquidity.MulRoundUp(sqrtPriceCurrent).QuoRoundUpMut(denominator)
}

// GetNextSqrtPriceFromAmount0OutRoundingUp utilizes sqrtPriceCurrent, liquidity, and amount of denom0 that still needs
Expand All @@ -158,7 +158,7 @@ func GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidity, amoun
denominator := liquidity.Sub(product)
// mul round up numerator to make the final result larger
// quo round up to make the final result larger
return liquidity.MulRoundUp(sqrtPriceCurrent).QuoRoundUp(denominator)
return liquidity.MulRoundUp(sqrtPriceCurrent).QuoRoundUpMut(denominator)
}

// GetNextSqrtPriceFromAmount1InRoundingDown utilizes the current sqrtPriceCurrent, liquidity, and amount of denom1 that still needs
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/pool-models/stableswap/amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (p *Pool) calcInAmtGivenOut(tokenOut sdk.Coin, tokenInDenom string, spreadF
// We invert that negative here.
cfmmIn = cfmmIn.Neg()
// divide by (1 - spread factor) to force a corresponding increase in input asset
inAmt := cfmmIn.QuoRoundUp(oneMinus(spreadFactor))
inAmt := cfmmIn.QuoRoundUpMut(oneMinus(spreadFactor))
inCoinAmt := p.getDescaledPoolAmt(tokenInDenom, inAmt)
return inCoinAmt, nil
}
Expand Down

0 comments on commit 17569b1

Please sign in to comment.