Skip to content

Commit

Permalink
removed eq (#4321)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 authored Feb 16, 2023
1 parent dd1d910 commit d0e4d3f
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions x/concentrated-liquidity/internal/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,15 @@ func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB sdk.Dec, roundUp bool) sdk.Dec

// getNextSqrtPriceFromAmount0RoundingUp utilizes the current squareRootPrice, liquidity of denom0, and amount of denom0 that still needs
// to be swapped in order to determine the next squareRootPrice
// TODO: make an issue to determine if we can remove the less precise formula
// Note: we are using only using the precise formula here.
func GetNextSqrtPriceFromAmount0RoundingUp(sqrtPriceCurrent, liquidity, amountRemaining sdk.Dec) (sqrtPriceNext sdk.Dec) {
if amountRemaining.Equal(sdk.ZeroDec()) {
return sqrtPriceCurrent
}

product := amountRemaining.Mul(sqrtPriceCurrent)
// use precise formula if product doesn't overflow
if (product.Quo(amountRemaining)).Equal(sqrtPriceCurrent) {
denominator := liquidity.Add(product)
if denominator.GTE(liquidity) {
return liquidity.Mul(sqrtPriceCurrent).QuoRoundUp(denominator)
}
}
// if the product does overflow, use less precise formula
return liquidity.QuoRoundUp(liquidity.Quo(sqrtPriceCurrent).Add(amountRemaining))
denominator := liquidity.Add(product)
return liquidity.Mul(sqrtPriceCurrent).QuoRoundUp(denominator)
}

// getNextSqrtPriceFromAmount1RoundingDown utilizes the current squareRootPrice, liquidity of denom1, and amount of denom1 that still needs
Expand Down

0 comments on commit d0e4d3f

Please sign in to comment.