Skip to content

Commit

Permalink
fix swap strategy test
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Sep 11, 2023
1 parent f8fb807 commit d4ad039
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions x/concentrated-liquidity/swapstrategy/one_for_zero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,21 @@ func (suite *StrategyTestSuite) TestComputeSwapStepOutGivenIn_OneForZero() {
expectedAmountInConsumed: osmomath.NewDec(99),
// liquidity * (sqrtPriceNext - sqrtPriceCurrent) / (sqrtPriceNext * sqrtPriceCurrent)
// calculated with x/concentrated-liquidity/python/clmath.py
// # Calculate amount in until sqrtPriceTarget
// amountIn = calc_amount_one_delta(liquidity, sqrtPriceCurrent, sqrtPriceTarget, True)
// Decimal('100.002498062401598791937822606808718081')
// # Greater than amountOneInRemaining => calculate sqrtPriceNext
//
// amountOneInRemaining = Decimal('99')
// sqrtPriceNext = get_next_sqrt_price_from_amount1_in_round_down(liquidity, sqrtPriceCurrent, amountOneInRemaining)
// Decimal("0.000001000049998750989975269800000000")
//
// diff = (sqrtPriceNext - sqrtPriceCurrent)
// diff = round_decimal(diff, 36, ROUND_FLOOR) (0.000000000000000000989975269800000000)
// mul = (sqrtPriceNext * sqrtPriceCurrent)
// mul = round_decimal(mul, 36, ROUND_CEILING) (0.000000000001000100000000865026329827)
// round_decimal(liquidity * diff / mul, 36, ROUND_FLOOR)
expectedAmountOut: osmomath.MustNewBigDecFromStr("98990100989815.389417309844929293132374729779331247").Dec(),
// diff = round_decimal(diff, 36, ROUND_FLOOR)
// mul = round_decimal(liquidity * diff, 36, ROUND_FLOOR)
// div1= round_decimal(mul / sqrtPriceNext, 36, ROUND_FLOOR)
// round_decimal(div1 / sqrtPriceCurrent, 36, ROUND_FLOOR)
expectedAmountOut: osmomath.MustNewBigDecFromStr("98990100989815.389417309941839547862158319016747061").Dec(),
expectedSpreadRewardChargeTotal: osmomath.ZeroDec(),
},
"8: invalid zero difference between sqrt price current and sqrt price next due to precision loss. Returns 0 for amounts out. Note that the caller should detect this and fail.": {
Expand Down

0 comments on commit d4ad039

Please sign in to comment.