diff --git a/pool/sqrt_price_math.gno b/pool/sqrt_price_math.gno index 30e15565..022a77c4 100644 --- a/pool/sqrt_price_math.gno +++ b/pool/sqrt_price_math.gno @@ -6,31 +6,31 @@ import ( ) func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( - sqrtPX96 bigint, - liquidity bigint, - amount bigint, - add bool, + sqrtPX96 bigint, + liquidity bigint, + amount bigint, + add bool, ) bigint { requireUnsigned( sqrtPX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected sqrtPX96 must be unsigned, got: %d", sqrtPX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) requireUnsigned( amount, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected amount must be unsigned, got: %d", amount, - )) + )) if amount == 0 { return sqrtPX96 @@ -47,7 +47,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected denominator != 0, got: %d", denominator, - )) + )) return numerator1 * sqrtPX96 / denominator } @@ -59,7 +59,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected denominator >= 0, got: %d", denominator, - )) + )) return numerator1 / ((numerator1 / sqrtPX96) + amount) } @@ -75,21 +75,21 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected sqrtPX96 must be unsigned, got: %d", sqrtPX96, - )) + )) requireUnsigned( amount, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected amount must be unsigned, got: %d", amount, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) var quotient bigint if amount <= consts.MAX_UINT160 { @@ -126,7 +126,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown( ) return result -} +} func sqrtPriceMathGetNextSqrtPriceFromInput( sqrtPX96 bigint, @@ -146,15 +146,14 @@ func sqrtPriceMathGetNextSqrtPriceFromInput( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromInput() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) requireUnsigned( amountIn, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromInput() || expected amountIn must be unsigned, got: %d", amountIn, - )) - + )) if zeroForOne { amount0Result := sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true) @@ -187,14 +186,14 @@ func sqrtPriceMathGetNextSqrtPriceFromOutput( requireUnsigned( sqrtPX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromOutput() || expected sqrtPX96 >= 0, got: %s", - sqrtPX96, - )) + sqrtPX96, + )) requireUnsigned( liquidity, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromOutput() || expected liquidity >= 0, got: %d", - liquidity, - )) + liquidity, + )) if zeroForOne { amount1Result := sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false) @@ -225,21 +224,21 @@ func sqrtPriceMathGetAmount0DeltaHelper( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected sqrtRatioAX96 must be unsigned, got: %d", sqrtRatioAX96, - )) + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) if sqrtRatioAX96 > sqrtRatioBX96 { sqrtRatioAX96, sqrtRatioBX96 = sqrtRatioBX96, sqrtRatioAX96 @@ -259,22 +258,22 @@ func sqrtPriceMathGetAmount1DeltaHelper( requireUnsigned( sqrtRatioAX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected sqrtRatioAX96 must be unsigned, got: %d", - sqrtRatioAX96, - )) + sqrtRatioAX96, + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) if sqrtRatioAX96 > sqrtRatioBX96 { sqrtRatioAX96, sqrtRatioBX96 = sqrtRatioBX96, sqrtRatioAX96 @@ -293,19 +292,20 @@ func sqrtPriceMathGetAmount0Delta( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0Delta() || expected sqrtRatioAX96 must be unsigned, got: %d", sqrtRatioAX96, - )) + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0Delta() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) if liquidity < 0 { - return -sqrtPriceMathGetAmount0DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, absBigint(-liquidity)) + return -sqrtPriceMathGetAmount0DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, liquidity) } + println("THIS") return sqrtPriceMathGetAmount0DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, liquidity) } @@ -317,15 +317,15 @@ func sqrtPriceMathGetAmount1Delta( requireUnsigned( sqrtRatioAX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1Delta() || expected sqrtRatioAX96 must be unsigned, got: %d", - sqrtRatioAX96, - )) + sqrtRatioAX96, + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1Delta() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) if liquidity < 0 { return -sqrtPriceMathGetAmount1DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, absBigint(-liquidity)) diff --git a/router/_TEST_RATIO_test.gno b/router/_TEST_RATIO_test.gno new file mode 100644 index 00000000..6bc0dff9 --- /dev/null +++ b/router/_TEST_RATIO_test.gno @@ -0,0 +1,38 @@ +package router + +import ( + "encoding/gjson" + "std" + "testing" + + pl "gno.land/r/demo/pool" +) + +func TestInitManual(t *testing.T) { + std.TestSetOrigCaller(test1) + pl.InitManual() + std.TestSkipHeights(1) +} + +func TestCreatePool(t *testing.T) { + std.TestSetOrigCaller(test1) + + pl.CreatePool(wgnotPath, barPath, fee100, common.TickMathGetSqrtRatioAtTick(1000)) // 1.1051 BAR + + jsonOutput := pl.ApiGetPools() + jsonStr := gjson.Parse(jsonOutput) + shouldEQ(t, len(jsonStr.Get("response").Array()), 1) +} + +func TestApiGetRatiosFromBase(t *testing.T) { + jsonOutput := ApiGetRatiosFromBase() + jsonStr := gjson.Parse(jsonOutput) + jsonArr := jsonStr.Get("response").Array() + shouldEQ(t, len(jsonArr), 4) + println(jsonArr[0].String()) + + // shouldEQ(t, jsonArr[0].String(), "{\"path\":\"gno.land/r/demo/wugnot\",\"price\":79228162514264337593543950336}") // 1 + // shouldEQ(t, jsonArr[1].String(), "{\"path\":\"gno.land/r/demo/bar\",\"price\":29147869410676662479573841823}") // 0.3678978344 + // shouldEQ(t, jsonArr[2].String(), "{\"path\":\"gno.land/r/demo/qux\",\"price\":10723438032895153248244559718}") // 0.1353488165 + // shouldEQ(t, jsonArr[3].String(), "{\"path\":\"gno.land/r/demo/baz\",\"price\":1451404646985709758556457134}") // 0.0183193021 +} diff --git a/router/_TEST_router_swap_route_2route_2hop_test.gno b/router/_TEST_router_swap_route_2route_2hop_test.gnoa similarity index 100% rename from router/_TEST_router_swap_route_2route_2hop_test.gno rename to router/_TEST_router_swap_route_2route_2hop_test.gnoa