diff --git a/osmomath/decimal.go b/osmomath/decimal.go index bef9f86cbf0..cb6eb82bcdd 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -261,7 +261,8 @@ func (d BigDec) LT(d2 BigDec) bool { return (d.i).Cmp(d2.i) < 0 } / func (d BigDec) LTE(d2 BigDec) bool { return (d.i).Cmp(d2.i) <= 0 } // less than or equal func (d BigDec) Neg() BigDec { return BigDec{new(big.Int).Neg(d.i)} } // reverse the decimal sign // nolint: stylecheck -func (d BigDec) Abs() BigDec { return BigDec{new(big.Int).Abs(d.i)} } // absolute value +func (d BigDec) Abs() BigDec { return BigDec{new(big.Int).Abs(d.i)} } // absolute value +func (d BigDec) AbsMut() BigDec { d.i.Abs(d.i); return d } // absolute value // BigInt returns a copy of the underlying big.Int. func (d BigDec) BigInt() *big.Int { diff --git a/osmomath/decimal_test.go b/osmomath/decimal_test.go index 0afb3d45a02..9d927a7a408 100644 --- a/osmomath/decimal_test.go +++ b/osmomath/decimal_test.go @@ -618,7 +618,7 @@ func (s *decimalTestSuite) TestApproxRoot() { for i, tc := range testCases { res, err := tc.input.ApproxRoot(tc.root) s.Require().NoError(err) - s.Require().True(tc.expected.Sub(res).Abs().LTE(osmomath.SmallestBigDec()), "unexpected result for test case %d, input: %v", i, tc.input) + s.Require().True(tc.expected.Sub(res).AbsMut().LTE(osmomath.SmallestBigDec()), "unexpected result for test case %d, input: %v", i, tc.input) } } diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index fe459160c37..de58a333ae4 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -97,6 +97,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // CalcAmount1Delta = liq * (sqrtPriceB - sqrtPriceA) func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { // make sqrtPriceA the smaller value amongst sqrtPriceA and sqrtPriceB + // TODO: Remove this GT check and just do .AbsMut if sqrtPriceA.GT(sqrtPriceB) { sqrtPriceA, sqrtPriceB = sqrtPriceB, sqrtPriceA }