From e5dbf0098544353e271984b8a9befd319d9f9590 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Sat, 21 Dec 2024 23:23:17 +0900 Subject: [PATCH] test: fix scenario gnoA tests --- pool/pool_transfer.gno | 2 +- ..._TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA | 51 ----- pool/tests/__TEST_pool_burn_test.gnoA | 56 ++--- .../__TEST_pool_dryswap_and_swap_test.gnoA | 4 +- pool/tests/__TEST_pool_fee_protocol_test.gnoA | 12 +- pool/tests/__TEST_pool_init_test.gnoA | 18 +- pool/tests/__TEST_pool_limit_test.gnoA | 32 +-- ...EST_pool_limit_with_protocol_fee_test.gnoA | 24 +-- pool/tests/__TEST_pool_mint_test.gnoA | 6 +- pool/tests/__TEST_pool_multi_token_test.gnoA | 128 ++++++------ pool/tests/__TEST_pool_native_swap_test.gnoA | 31 +-- pool/tests/__TEST_pool_single_lp_test.gnoA | 195 +++++++++--------- pool/tests/__TEST_pool_spec_#1_test.gnoA | 50 ++--- pool/tests/__TEST_pool_spec_#2_test.gnoA | 45 ++-- pool/tests/__TEST_pool_spec_#3_test.gnoA | 23 +-- pool/tests/__TEST_pool_spec_#4_test.gnoA | 21 +- pool/tests/__TEST_pool_spec_#5_test.gnoA | 22 +- pool/tests/__TEST_pool_spec_#6_test.gnoA | 16 +- pool/tests/__TEST_pool_test.gnoA | 12 +- pool/tests/__TEST_pool_tick_test.gnoA | 73 ++++--- .../__TEST_pool_tick_transaction_test.gnoA | 9 +- 21 files changed, 376 insertions(+), 454 deletions(-) delete mode 100644 pool/tests/__TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA diff --git a/pool/pool_transfer.gno b/pool/pool_transfer.gno index da3951f0..bd8d2e82 100644 --- a/pool/pool_transfer.gno +++ b/pool/pool_transfer.gno @@ -39,7 +39,7 @@ func (p *Pool) safeTransfer( amount *i256.Int, isToken0 bool, ) { - if amount.Sign() != -1 { + if amount.Gt(i256.Zero()) { panic(ufmt.Sprintf( "%v. got: %s", errMustBeNegative, amount.ToString(), )) diff --git a/pool/tests/__TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA b/pool/tests/__TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA deleted file mode 100644 index e92df972..00000000 --- a/pool/tests/__TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA +++ /dev/null @@ -1,51 +0,0 @@ -package pool - -import ( - "std" - - "gno.land/r/gnoswap/v1/common" - "gno.land/r/gnoswap/v1/consts" -) - -var ( - admin std.Address = consts.ADMIN - - fooPath string = "gno.land/r/onbloc/foo" - barPath string = "gno.land/r/onbloc/bar" - bazPath string = "gno.land/r/onbloc/baz" - quxPath string = "gno.land/r/onbloc/qux" - - oblPath string = "gno.land/r/onbloc/obl" - // wugnotPath string = "gno.land/r/demo/wugnot" // from consts - // gnsPath string = "gno.land/r/gnoswap/v1/gns" // from consts - - fee100 uint32 = 100 - fee500 uint32 = 500 - fee3000 uint32 = 3000 - - maxApprove uint64 = 18446744073709551615 -) - -// Realms to mock frames -var ( - adminRealm = std.NewUserRealm(admin) - posRealm = std.NewCodeRealm(consts.POSITION_PATH) - rouRealm = std.NewCodeRealm(consts.ROUTER_PATH) -) - -/* HELPER */ -func ugnotBalanceOf(addr std.Address) uint64 { - testBanker := std.GetBanker(std.BankerTypeRealmIssue) - - coins := testBanker.GetCoins(addr) - if len(coins) == 0 { - return 0 - } - - return uint64(coins.AmountOf("ugnot")) -} - -func balanceOfByRegisterCall(tokenPath string, caller std.Address) uint64 { - token := common.GetToken(tokenPath) - return token.BalanceOf(caller) -} diff --git a/pool/tests/__TEST_pool_burn_test.gnoA b/pool/tests/__TEST_pool_burn_test.gnoA index 64d59735..858cbb46 100644 --- a/pool/tests/__TEST_pool_burn_test.gnoA +++ b/pool/tests/__TEST_pool_burn_test.gnoA @@ -38,7 +38,7 @@ func TestDoesNotClear(t *testing.T) { -887160, 887160, test_liquidityExpectStr, - admin, + adminAddr, ) std.TestSetRealm(rouRealm) @@ -46,22 +46,22 @@ func TestDoesNotClear(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "10000", consts.MIN_PRICE, - admin, + adminAddr, ) Swap( barPath, fooPath, fee500, - admin, + adminAddr, false, "10000", consts.MAX_PRICE, - admin, + adminAddr, ) // did swap t0 => t1 and t1 => t0 @@ -82,7 +82,7 @@ func TestDoesNotClear(t *testing.T) { // tokensOwed thisPositionKey := getPositionKey(consts.POSITION_ADDR, -887160, 887160) - thisPosition := thisPool.positions[thisPositionKey] + thisPosition := thisPool.mustGetPosition(thisPositionKey) tokensOwed0 := thisPosition.tokensOwed0 tokensOwed1 := thisPosition.tokensOwed1 @@ -113,7 +113,7 @@ func TestClearOnlyLowTick(t *testing.T) { -887160, 887160, "1", - admin, + adminAddr, ) Mint( @@ -124,7 +124,7 @@ func TestClearOnlyLowTick(t *testing.T) { -887100, 887160, "1", - admin, + adminAddr, ) std.TestSetRealm(rouRealm) @@ -132,11 +132,11 @@ func TestClearOnlyLowTick(t *testing.T) { barPath, fooPath, fee3000, - admin, + adminAddr, true, "10000", consts.MIN_PRICE, - admin, + adminAddr, ) std.TestSetRealm(posRealm) @@ -150,13 +150,13 @@ func TestClearOnlyLowTick(t *testing.T) { ) thisPool := GetPool(barPath, fooPath, fee3000) - lowerInfo := thisPool.ticks[-887160] - uassert.Equal(t, lowerInfo.liquidityGross.ToString(), "") - uassert.Equal(t, lowerInfo.feeGrowthOutside0X128.ToString(), "") - uassert.Equal(t, lowerInfo.feeGrowthOutside1X128.ToString(), "") - // uassert.Equal(t, lowerInfo.liquidityNet.ToString(), "") // i256 nil check + lowerInfo := thisPool.getTick(-887160) + uassert.Equal(t, lowerInfo.liquidityGross.ToString(), "0") + uassert.Equal(t, lowerInfo.feeGrowthOutside0X128.ToString(), "0") + uassert.Equal(t, lowerInfo.feeGrowthOutside1X128.ToString(), "0") + uassert.Equal(t, lowerInfo.liquidityNet.ToString(), "0") - upperInfo := thisPool.ticks[887160] + upperInfo := thisPool.getTick(887160) uassert.NotEqual(t, upperInfo.liquidityGross.ToString(), "") } @@ -177,7 +177,7 @@ func TestClearOnlyUpperTick(t *testing.T) { -887160, 887160, "1", - admin, + adminAddr, ) Mint( @@ -188,7 +188,7 @@ func TestClearOnlyUpperTick(t *testing.T) { -887160, 887100, "1", - admin, + adminAddr, ) std.TestSetRealm(rouRealm) @@ -196,11 +196,11 @@ func TestClearOnlyUpperTick(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, true, "10000", consts.MIN_PRICE, - admin, + adminAddr, ) std.TestSetRealm(posRealm) @@ -214,12 +214,12 @@ func TestClearOnlyUpperTick(t *testing.T) { ) thisPool := GetPool(barPath, fooPath, fee100) - lowerInfo := thisPool.ticks[-887160] - uassert.NotEqual(t, lowerInfo.liquidityGross.ToString(), "") - - upperInfo := thisPool.ticks[887160] - uassert.Equal(t, upperInfo.liquidityGross.ToString(), "") - uassert.Equal(t, upperInfo.feeGrowthOutside0X128.ToString(), "") - uassert.Equal(t, upperInfo.feeGrowthOutside1X128.ToString(), "") - // uassert.Equal(t, upperInfo.liquidityNet.ToString(), "") // i256 nil check + lowerInfo := thisPool.getTick(-887160) + uassert.NotEqual(t, lowerInfo.liquidityGross.ToString(), "0") + + upperInfo := thisPool.getTick(887160) + uassert.Equal(t, upperInfo.liquidityGross.ToString(), "0") + uassert.Equal(t, upperInfo.feeGrowthOutside0X128.ToString(), "0") + uassert.Equal(t, upperInfo.feeGrowthOutside1X128.ToString(), "0") + uassert.Equal(t, upperInfo.liquidityNet.ToString(), "0") } diff --git a/pool/tests/__TEST_pool_dryswap_and_swap_test.gnoA b/pool/tests/__TEST_pool_dryswap_and_swap_test.gnoA index 1c81f5f7..c214ffc1 100644 --- a/pool/tests/__TEST_pool_dryswap_and_swap_test.gnoA +++ b/pool/tests/__TEST_pool_dryswap_and_swap_test.gnoA @@ -31,7 +31,7 @@ func TestCreatePool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), poolCreationFee) CreatePool(barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(-10000).ToString()) // tick -10000 - uassert.Equal(t, len(pools), 1) + uassert.Equal(t, pools.Size(), 1) } func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) { @@ -52,7 +52,7 @@ func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) { std.TestSetRealm(adminRealm) std.TestSetRealm(posRealm) - Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, liquidityExpect, admin) // -11000 ~ -9000 + Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, liquidityExpect, adminAddr) // -11000 ~ -9000 // zeroForOne true // amountSpecified 16000 diff --git a/pool/tests/__TEST_pool_fee_protocol_test.gnoA b/pool/tests/__TEST_pool_fee_protocol_test.gnoA index 79eb61fe..702b1585 100644 --- a/pool/tests/__TEST_pool_fee_protocol_test.gnoA +++ b/pool/tests/__TEST_pool_fee_protocol_test.gnoA @@ -33,37 +33,37 @@ func TestProtocolFee(t *testing.T) { t.Run("fails if fee is lt 4 or gt 10", func(t *testing.T) { uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`, func() { setFeeProtocol(3, 3) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`, func() { setFeeProtocol(6, 3) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`, func() { setFeeProtocol(3, 6) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`, func() { setFeeProtocol(11, 11) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`, func() { setFeeProtocol(6, 11) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`, + `[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`, func() { setFeeProtocol(11, 6) }, ) }) diff --git a/pool/tests/__TEST_pool_init_test.gnoA b/pool/tests/__TEST_pool_init_test.gnoA index e2f0a170..9f4b989a 100644 --- a/pool/tests/__TEST_pool_init_test.gnoA +++ b/pool/tests/__TEST_pool_init_test.gnoA @@ -41,7 +41,7 @@ func TestMintPostInit(t *testing.T) { -1000, 1000, test_liquidityExpectStr, - admin, + adminAddr, ) }) currentLiq := thisPool.liquidity.ToString() @@ -56,7 +56,7 @@ func TestMintPostInit(t *testing.T) { -2000, -1000, test_liquidityExpectStr, - admin, + adminAddr, ) nowLiq := thisPool.liquidity.ToString() @@ -73,7 +73,7 @@ func TestMintPostInit(t *testing.T) { 1000, 2000, test_liquidityExpectStr, - admin, + adminAddr, ) nowLiq := thisPool.liquidity.ToString() @@ -92,7 +92,7 @@ func TestMintPostInit(t *testing.T) { 0, 10, test_liquidityExpectStr, - admin, + adminAddr, ) nowLiq := thisPool.liquidity.ToString() @@ -101,11 +101,11 @@ func TestMintPostInit(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "1", consts.MIN_PRICE, - admin, + adminAddr, ) poolTick := thisPool.slot0.tick @@ -124,7 +124,7 @@ func TestMintPostInit(t *testing.T) { -10, 0, test_liquidityExpectStr, - admin, + adminAddr, ) nowLiq := thisPool.liquidity.ToString() @@ -133,11 +133,11 @@ func TestMintPostInit(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "1", consts.MIN_PRICE, - admin, + adminAddr, ) poolTick := thisPool.slot0.tick diff --git a/pool/tests/__TEST_pool_limit_test.gnoA b/pool/tests/__TEST_pool_limit_test.gnoA index 346501ba..69bbfc56 100644 --- a/pool/tests/__TEST_pool_limit_test.gnoA +++ b/pool/tests/__TEST_pool_limit_test.gnoA @@ -40,10 +40,8 @@ func TestLimitOrderThru_Positive_1(t *testing.T) { 0, 120, test_liquidityExpectStr, - admin, + adminAddr, ) - // println("mint0", mint0) // 59817378 - // println("mint1", mint1) // 0 // SWAP 1 -> 0 std.TestSetRealm(rouRealm) @@ -51,14 +49,12 @@ func TestLimitOrderThru_Positive_1(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, false, "60183363", consts.MAX_PRICE, - admin, + adminAddr, ) - // println("swap0", swap0) // -59817378 - // println("swap1", swap1) // 60183363 // BURN std.TestSetRealm(posRealm) @@ -70,8 +66,6 @@ func TestLimitOrderThru_Positive_1(t *testing.T) { 120, test_liquidityExpectStr, ) - // println("burn0", burn0) // 0 - // println("burn1", burn1) // 60177342 // COLLECT std.TestSetRealm(posRealm) @@ -79,14 +73,12 @@ func TestLimitOrderThru_Positive_1(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, 0, 120, consts.MAX_UINT128, consts.MAX_UINT128, ) - // println("collect0", collect0) // 0 - // println("collect1", collect1) // 60177342 slotTick := thisPool.slot0.tick if slotTick < 120 { @@ -116,10 +108,8 @@ func TestLimitOrderThru_Negative_1(t *testing.T) { -120, 0, test_liquidityExpectStr, - admin, + adminAddr, ) - // println("mint0", mint0) // 0 - // println("mint1", mint1) // 59817378 // SWAP 0 -> 1 std.TestSetRealm(rouRealm) @@ -127,14 +117,12 @@ func TestLimitOrderThru_Negative_1(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "60283363", consts.MIN_PRICE, - admin, + adminAddr, ) - // println("swap0", swap0) // 60207447 - // println("swap1", swap1) // -59817377 // BURN std.TestSetRealm(posRealm) @@ -146,8 +134,6 @@ func TestLimitOrderThru_Negative_1(t *testing.T) { 0, test_liquidityExpectStr, ) - // println("burn0", burn0) // 60177342 - // println("burn1", burn1) // 0 // COLLECT std.TestSetRealm(posRealm) @@ -155,14 +141,12 @@ func TestLimitOrderThru_Negative_1(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, -120, 0, consts.MAX_UINT128, consts.MAX_UINT128, ) - // println("collect0", collect0) // 60207445 - // println("collect1", collect1) // 0 slotTick := thisPool.slot0.tick if slotTick >= -120 { diff --git a/pool/tests/__TEST_pool_limit_with_protocol_fee_test.gnoA b/pool/tests/__TEST_pool_limit_with_protocol_fee_test.gnoA index 3993c9c0..9399e71d 100644 --- a/pool/tests/__TEST_pool_limit_with_protocol_fee_test.gnoA +++ b/pool/tests/__TEST_pool_limit_with_protocol_fee_test.gnoA @@ -46,10 +46,8 @@ func TestLimitOrderThru_Positive_1_WithFee(t *testing.T) { 0, 120, test_liquidityExpectStr, - admin, + adminAddr, ) - // println("mint0", mint0) // 59817378 - // println("mint1", mint1) // 0 // SWAP 1 -> 0 std.TestSetRealm(rouRealm) @@ -57,14 +55,12 @@ func TestLimitOrderThru_Positive_1_WithFee(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, false, "60183363", consts.MAX_PRICE, - admin, + adminAddr, ) - // println("swap0", swap0) // -59817378 - // println("swap1", swap1) // 60183363 // BURN std.TestSetRealm(posRealm) @@ -76,8 +72,6 @@ func TestLimitOrderThru_Positive_1_WithFee(t *testing.T) { 120, test_liquidityExpectStr, ) - // println("burn0", burn0) // 0 - // println("burn1", burn1) // 60177342 // COLLECT std.TestSetRealm(posRealm) @@ -85,14 +79,12 @@ func TestLimitOrderThru_Positive_1_WithFee(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, 0, 120, consts.MAX_UINT128, consts.MAX_UINT128, ) - // println("collect0", collect0) // 0 - // println("collect1", collect1) // 60177342 slotTick := thisPool.slot0.tick if slotTick < 120 { @@ -122,7 +114,7 @@ func TestLimitOrderThru_Negative_1_WithFee(t *testing.T) { -120, 0, test_liquidityExpectStr, - admin, + adminAddr, ) // println("mint0", mint0) // 0 // println("mint1", mint1) // 59817378 @@ -133,11 +125,11 @@ func TestLimitOrderThru_Negative_1_WithFee(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "60283363", consts.MIN_PRICE, - admin, + adminAddr, ) // println("swap0", swap0) // 60207447 // println("swap1", swap1) // -59817377 @@ -161,7 +153,7 @@ func TestLimitOrderThru_Negative_1_WithFee(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, -120, 0, consts.MAX_UINT128, diff --git a/pool/tests/__TEST_pool_mint_test.gnoA b/pool/tests/__TEST_pool_mint_test.gnoA index 23a95f4e..6951f6f8 100644 --- a/pool/tests/__TEST_pool_mint_test.gnoA +++ b/pool/tests/__TEST_pool_mint_test.gnoA @@ -47,7 +47,7 @@ func TestMintMiscellaneous(t *testing.T) { 1000, 2000, test_liquidityExpectStr, - admin, + adminAddr, ) liqAfter := thisPool.liquidity.ToString() @@ -69,7 +69,7 @@ func TestMintMiscellaneous(t *testing.T) { -2000, -1000, test_liquidityExpectStr, - admin, + adminAddr, ) liqAfter := thisPool.liquidity.ToString() @@ -83,7 +83,7 @@ func TestMintMiscellaneous(t *testing.T) { std.TestSetRealm(posRealm) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidity_math.gno__liquidityMathAddDelta() || LS(z must be < x) (x: 0, y: -1001, z:115792089237316195423570985008687907853269984665640564039457584007913129638935)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || Condition failed: (z must be < x) (x: 0, y: -1001, z:115792089237316195423570985008687907853269984665640564039457584007913129638935)`, func() { Burn( barPath, diff --git a/pool/tests/__TEST_pool_multi_token_test.gnoA b/pool/tests/__TEST_pool_multi_token_test.gnoA index 6ab6e1e8..bf193c77 100644 --- a/pool/tests/__TEST_pool_multi_token_test.gnoA +++ b/pool/tests/__TEST_pool_multi_token_test.gnoA @@ -34,7 +34,7 @@ func TestCreateFooBarPool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), poolCreationFee) CreatePool(barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(-10000).ToString()) // tick -10000 - uassert.Equal(t, len(pools), 1) + uassert.Equal(t, pools.Size(), 1) } // Create Bar:Baz Pool @@ -45,7 +45,7 @@ func TestCreateBarBazPool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), poolCreationFee) CreatePool(barPath, bazPath, fee500, "130621891405341611593710811006") - uassert.Equal(t, len(pools), 2) + uassert.Equal(t, pools.Size(), 2) } // Mint Foo:Bar Liquidity by admin @@ -63,7 +63,7 @@ func TestMintFooBarLiquidity(t *testing.T) { -test_tickUpper, -test_tickLower, test_liquidityExpectStr, - admin, + adminAddr, ) uassert.Equal(t, amount0, "8040316") uassert.Equal(t, amount1, "2958015") @@ -84,7 +84,7 @@ func TestMintBarBazLiquidity(t *testing.T) { test_tickLower, test_tickUpper, test_liquidityExpectStr, - admin, + adminAddr, ) uassert.Equal(t, amount0, "2958015") uassert.Equal(t, amount1, "8040316") @@ -92,11 +92,11 @@ func TestMintBarBazLiquidity(t *testing.T) { // Swap Foo:Bar Foo > Bar by admin func TestSwapFooBarFooToBar(t *testing.T) { - oldTest1Bar := balanceOfByRegisterCall(barPath, admin) - oldTest1Foo := balanceOfByRegisterCall(fooPath, admin) + oldTest1Bar := barToken.BalanceOf(adminAddr) + oldTest1Foo := fooToken.BalanceOf(adminAddr) - oldPoolBar := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - oldPoolFoo := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + oldPoolBar := barToken.BalanceOf(consts.POOL_ADDR) + oldPoolFoo := fooToken.BalanceOf(consts.POOL_ADDR) std.TestSetRealm(adminRealm) bar.Approve(a2u(consts.POOL_ADDR), 16000) @@ -106,20 +106,20 @@ func TestSwapFooBarFooToBar(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "16000", consts.MIN_PRICE, - admin, + adminAddr, ) uassert.Equal(t, poolIn, "16000") uassert.Equal(t, poolOut, "-5882") - newTest1Bar := balanceOfByRegisterCall(barPath, admin) - newTest1Foo := balanceOfByRegisterCall(fooPath, admin) + newTest1Bar := barToken.BalanceOf(adminAddr) + newTest1Foo := fooToken.BalanceOf(adminAddr) - newPoolBar := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - newPoolFoo := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + newPoolBar := barToken.BalanceOf(consts.POOL_ADDR) + newPoolFoo := fooToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, oldTest1Bar-newTest1Bar, uint64(16000)) uassert.Equal(t, newTest1Foo-oldTest1Foo, uint64(5882)) @@ -130,10 +130,10 @@ func TestSwapFooBarFooToBar(t *testing.T) { // Swap Bar:Baz Bar > Baz by admin func TestSwapBarBazBarToBaz(t *testing.T) { - oldTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - oldadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + oldTest1Token0Balance := barToken.BalanceOf(adminAddr) + oldadminBazBalance := bazToken.BalanceOf(adminAddr) + oldPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + oldPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) std.TestSetRealm(adminRealm) bar.Approve(a2u(consts.POOL_ADDR), 16000) @@ -143,20 +143,20 @@ func TestSwapBarBazBarToBaz(t *testing.T) { barPath, bazPath, fee500, - admin, + adminAddr, true, "16000", consts.MIN_PRICE, - admin, + adminAddr, ) uassert.Equal(t, poolIn, "16000") uassert.Equal(t, poolOut, "-43457") - newTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - newadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + newTest1Token0Balance := barToken.BalanceOf(adminAddr) + newadminBazBalance := bazToken.BalanceOf(adminAddr) + newPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + newPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, oldTest1Token0Balance-newTest1Token0Balance, uint64(16000)) uassert.Equal(t, newadminBazBalance-oldadminBazBalance, uint64(43457)) @@ -168,10 +168,10 @@ func TestSwapBarBazBarToBaz(t *testing.T) { func TestCollectFooBarFees(t *testing.T) { std.TestSetRealm(posRealm) - oldTest1Token1Balance := balanceOfByRegisterCall(fooPath, admin) - oldTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + oldTest1Token1Balance := fooToken.BalanceOf(adminAddr) + oldTest1Token0Balance := barToken.BalanceOf(adminAddr) + oldPoolToken1Balance := fooToken.BalanceOf(consts.POOL_ADDR) + oldPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) // burn 0 to collect swap fees Burn(fooPath, barPath, fee500, -test_tickUpper, -test_tickLower, "0") @@ -180,7 +180,7 @@ func TestCollectFooBarFees(t *testing.T) { fooPath, barPath, fee500, - admin, + adminAddr, -test_tickUpper, -test_tickLower, "100000", @@ -190,10 +190,10 @@ func TestCollectFooBarFees(t *testing.T) { uassert.NotEqual(t, c0, "0") // swap was foo > bar, so only foo has fees uassert.Equal(t, c1, "0") // swap was foo > bar, so bar has no fees - newTest1Token1Balance := balanceOfByRegisterCall(fooPath, admin) - newTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - newPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + newTest1Token1Balance := fooToken.BalanceOf(adminAddr) + newTest1Token0Balance := barToken.BalanceOf(adminAddr) + newPoolToken1Balance := fooToken.BalanceOf(consts.POOL_ADDR) + newPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, newTest1Token1Balance-oldTest1Token1Balance, strToUint64(c1)) uassert.Equal(t, newTest1Token0Balance-oldTest1Token0Balance, strToUint64(c0)) @@ -205,10 +205,10 @@ func TestCollectFooBarFees(t *testing.T) { func TestCollectBarBazFees(t *testing.T) { std.TestSetRealm(posRealm) - oldTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - oldadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + oldTest1Token0Balance := barToken.BalanceOf(adminAddr) + oldadminBazBalance := bazToken.BalanceOf(adminAddr) + oldPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + oldPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) // burn 0 to collect swap fees Burn(barPath, bazPath, fee500, test_tickLower, test_tickUpper, "0") @@ -217,7 +217,7 @@ func TestCollectBarBazFees(t *testing.T) { barPath, bazPath, fee500, - admin, + adminAddr, test_tickLower, test_tickUpper, "100000", @@ -227,10 +227,10 @@ func TestCollectBarBazFees(t *testing.T) { uassert.NotEqual(t, c0, "0") // swap was foo > bar, so only foo has fees uassert.Equal(t, c1, "0") // swap was foo > bar, so bar has no fees - newTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - newadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + newTest1Token0Balance := barToken.BalanceOf(adminAddr) + newadminBazBalance := bazToken.BalanceOf(adminAddr) + newPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + newPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, newTest1Token0Balance-oldTest1Token0Balance, strToUint64(c0)) uassert.Equal(t, newadminBazBalance-oldadminBazBalance, strToUint64(c1)) @@ -243,7 +243,7 @@ func TestBurnFooBarLiquidity(t *testing.T) { std.TestSetRealm(posRealm) pool := GetPool(fooPath, barPath, fee500) - poolOldLiquidity := pool.PoolGetLiquidity() + poolOldLiquidity := pool.Liquidity() b0, b1 := Burn( fooPath, @@ -257,7 +257,7 @@ func TestBurnFooBarLiquidity(t *testing.T) { uassert.NotEqual(t, b0, "0") uassert.NotEqual(t, b1, "0") - poolNewLiquidity := pool.PoolGetLiquidity() + poolNewLiquidity := pool.Liquidity() uassert.Equal(t, true, new(u256.Uint).Sub(poolOldLiquidity, poolNewLiquidity).Eq(test_liquidityExpect256)) } @@ -267,7 +267,7 @@ func TestBurnBarBazLiquidity(t *testing.T) { std.TestSetRealm(posRealm) pool := GetPool(barPath, bazPath, fee500) - poolOldLiquidity := pool.PoolGetLiquidity() + poolOldLiquidity := pool.Liquidity() b0, b1 := Burn( barPath, @@ -281,7 +281,7 @@ func TestBurnBarBazLiquidity(t *testing.T) { uassert.NotEqual(t, b0, "0") uassert.NotEqual(t, b1, "0") - poolNewLiquidity := pool.PoolGetLiquidity() + poolNewLiquidity := pool.Liquidity() // uassert.Equal(t, poolOldLiquidity-poolNewLiquidity, test_liquidityExpect256) } @@ -290,16 +290,16 @@ func TestBurnBarBazLiquidity(t *testing.T) { func TestCollectFooBarLiquidity(t *testing.T) { std.TestSetRealm(posRealm) - oldTest1Token1Balance := balanceOfByRegisterCall(fooPath, admin) - oldTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + oldTest1Token1Balance := fooToken.BalanceOf(adminAddr) + oldTest1Token0Balance := barToken.BalanceOf(adminAddr) + oldPoolToken1Balance := fooToken.BalanceOf(consts.POOL_ADDR) + oldPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) c0, c1 := Collect( fooPath, barPath, fee500, - admin, + adminAddr, -test_tickUpper, -test_tickLower, "100000", @@ -309,10 +309,10 @@ func TestCollectFooBarLiquidity(t *testing.T) { uassert.NotEqual(t, c0, "0") uassert.NotEqual(t, c1, "0") - newTest1Token1Balance := balanceOfByRegisterCall(fooPath, admin) - newTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - newPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + newTest1Token1Balance := fooToken.BalanceOf(adminAddr) + newTest1Token0Balance := barToken.BalanceOf(adminAddr) + newPoolToken1Balance := fooToken.BalanceOf(consts.POOL_ADDR) + newPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, newTest1Token1Balance-oldTest1Token1Balance, strToUint64(c0)) uassert.Equal(t, newTest1Token0Balance-oldTest1Token0Balance, strToUint64(c1)) @@ -324,16 +324,16 @@ func TestCollectFooBarLiquidity(t *testing.T) { func TestCollectBarBazLiquidity(t *testing.T) { std.TestSetRealm(posRealm) - oldTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - oldadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + oldTest1Token0Balance := barToken.BalanceOf(adminAddr) + oldadminBazBalance := bazToken.BalanceOf(adminAddr) + oldPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + oldPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) c0, c1 := Collect( barPath, bazPath, fee500, - admin, + adminAddr, test_tickLower, test_tickUpper, "100000", @@ -343,10 +343,10 @@ func TestCollectBarBazLiquidity(t *testing.T) { uassert.NotEqual(t, c0, "0") uassert.NotEqual(t, c1, "0") - newTest1Token0Balance := balanceOfByRegisterCall(barPath, admin) - newadminBazBalance := balanceOfByRegisterCall(bazPath, admin) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) + newTest1Token0Balance := barToken.BalanceOf(adminAddr) + newadminBazBalance := bazToken.BalanceOf(adminAddr) + newPoolToken0Balance := barToken.BalanceOf(consts.POOL_ADDR) + newPoolBazBalance := bazToken.BalanceOf(consts.POOL_ADDR) uassert.Equal(t, newTest1Token0Balance-oldTest1Token0Balance, strToUint64(c0)) uassert.Equal(t, newadminBazBalance-oldadminBazBalance, strToUint64(c1)) diff --git a/pool/tests/__TEST_pool_native_swap_test.gnoA b/pool/tests/__TEST_pool_native_swap_test.gnoA index efebc4be..660b2313 100644 --- a/pool/tests/__TEST_pool_native_swap_test.gnoA +++ b/pool/tests/__TEST_pool_native_swap_test.gnoA @@ -6,6 +6,7 @@ import ( "gno.land/p/demo/uassert" + "gno.land/r/gnoswap/v1/common" "gno.land/r/gnoswap/v1/consts" "gno.land/r/gnoswap/v1/gns" @@ -37,11 +38,11 @@ func TestMint(t *testing.T) { // prepare ugnot testBanker := std.GetBanker(std.BankerTypeRealmIssue) - testBanker.IssueCoin(admin, "ugnot", 1_000_000) + testBanker.IssueCoin(adminAddr, "ugnot", 1_000_000) // simulate transfer & decrase std.TestSetOrigSend(std.Coins{{"ugnot", 1_000_000}}, nil) - testBanker.RemoveCoin(admin, "ugnot", 1_000_000) + testBanker.RemoveCoin(adminAddr, "ugnot", 1_000_000) // Deposit(wrap) std.TestSetRealm(adminRealm) @@ -61,7 +62,7 @@ func TestMint(t *testing.T) { test_tickLower, test_tickUpper, "10000000", - admin, + adminAddr, ) uassert.Equal(t, amount0, "295802") @@ -71,8 +72,8 @@ func TestMint(t *testing.T) { func TestSwapBuyNative(t *testing.T) { pool := GetPool(fooPath, consts.WRAPPED_WUGNOT, fee500) - adminOldT0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminOldT1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminOldT0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminOldT1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, adminOldT0Bal, uint64(704198)) uassert.Equal(t, adminOldT1Bal, uint64(99999999195968)) @@ -84,18 +85,18 @@ func TestSwapBuyNative(t *testing.T) { fooPath, // token0 consts.WRAPPED_WUGNOT, // token1 fee500, - admin, + adminAddr, true, "10000", consts.MIN_PRICE, - admin, + adminAddr, ) uassert.Equal(t, amount0, "10000") uassert.Equal(t, amount1, "-27123") - adminNewT0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminNewT1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminNewT0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminNewT1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, adminNewT0Bal, uint64(694198)) // - 10_000 // user sells 10_000 uassert.Equal(t, adminNewT1Bal, uint64(99999999223091)) // gets WGNOT } @@ -103,8 +104,8 @@ func TestSwapBuyNative(t *testing.T) { func TestSwapSellNative(t *testing.T) { pool := GetPool(fooPath, consts.WRAPPED_WUGNOT, fee500) - adminOldT0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminOldT1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminOldT0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminOldT1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, adminOldT0Bal, uint64(694198)) // foo uassert.Equal(t, adminOldT1Bal, uint64(99999999223091)) // wugnot @@ -116,18 +117,18 @@ func TestSwapSellNative(t *testing.T) { fooPath, // token0 consts.WRAPPED_WUGNOT, // token1 fee500, - admin, + adminAddr, false, "10000", consts.MAX_PRICE, - admin, + adminAddr, ) uassert.Equal(t, amount0, "-3687") // pool sent uassert.Equal(t, amount1, "10000") // pool recv - adminNewT0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminNewT1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminNewT0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminNewT1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, adminNewT0Bal, uint64(697885)) // foo uassert.Equal(t, adminNewT1Bal, uint64(99999999213091)) // wugnot } diff --git a/pool/tests/__TEST_pool_single_lp_test.gnoA b/pool/tests/__TEST_pool_single_lp_test.gnoA index f15e39e7..87fd45e0 100644 --- a/pool/tests/__TEST_pool_single_lp_test.gnoA +++ b/pool/tests/__TEST_pool_single_lp_test.gnoA @@ -11,6 +11,7 @@ import ( "gno.land/r/onbloc/bar" "gno.land/r/onbloc/foo" + "gno.land/r/gnoswap/v1/common" "gno.land/r/gnoswap/v1/consts" "gno.land/p/demo/json" @@ -53,58 +54,58 @@ func TestMint(t *testing.T) { test_tickLower, test_tickUpper, test_liquidityExpectStr, - admin, + adminAddr, ) uassert.Equal(t, amount0, "30") uassert.Equal(t, amount1, "81") pool := GetPool(barPath, fooPath, fee500) - test_liquidity := pool.PoolGetLiquidity() + test_liquidity := pool.Liquidity() uassert.Equal(t, test_liquidity.Dec(), test_liquidityExpectStr) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) - m81, m82 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - m101, m102 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) + m81, m82 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + m101, m102 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) uassert.NotEqual(t, m81, "0") uassert.NotEqual(t, m82, "0") uassert.Equal(t, m81, m101) uassert.Equal(t, m82, m102) - test_liquidity = pool.PoolGetLiquidity() + test_liquidity = pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(10)))) // tickLower > currentTick == don't add to current liquidity - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower2, test_tickUpper2, test_liquidityExpectStr, admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower2, test_tickUpper2, test_liquidityExpectStr, adminAddr) // tickUpper < current tick == don't add to current liquidity - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper2, -test_tickLower2, test_liquidityExpectStr, admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper2, -test_tickLower2, test_liquidityExpectStr, adminAddr) // tickUpper < tickLower == don't add to current liquidity - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper, -test_tickLower, test_liquidityExpectStr, admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper, -test_tickLower, test_liquidityExpectStr, adminAddr) - // test_liquidity = pool.PoolGetLiquidity() + // test_liquidity = pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(10)))) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, admin) - - test_liquidity = pool.PoolGetLiquidity() + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpectStr, adminAddr) + + test_liquidity = pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(20)))) } @@ -119,23 +120,23 @@ func TestBurn(t *testing.T) { uassert.Equal(t, b12, b22) pool := GetPool(barPath, fooPath, fee500) - test_liquidity := pool.PoolGetLiquidity() + test_liquidity := pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(18)))) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(8)).ToString()) - test_liquidity = pool.PoolGetLiquidity() + test_liquidity = pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(10)))) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, "1") - test_liquidity = pool.PoolGetLiquidity() + test_liquidity = pool.Liquidity() uassert.Equal(t, test_liquidity.ToString(), "9999") Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, "999") - test_liquidity = pool.PoolGetLiquidity() + test_liquidity = pool.Liquidity() uassert.Equal(t, true, test_liquidity.Eq(new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(9)))) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(9)).ToString()) - test_liquidity = pool.PoolGetLiquidity() + test_liquidity = pool.Liquidity() uassert.Equal(t, test_liquidity.ToString(), "0") } @@ -144,44 +145,44 @@ func TestCollect(t *testing.T) { std.TestSetRealm(posRealm) // withdraw all token before test `Collect` - Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") // pool should have zero liquidity pool := GetPool(barPath, fooPath, fee500) - test_liquidity := pool.PoolGetLiquidity() + test_liquidity := pool.Liquidity() uassert.Equal(t, test_liquidity.ToString(), "0") - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), adminAddr) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString()) - c11, c12 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + c11, c12 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), adminAddr) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString()) - c21, c22 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + c21, c22 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") uassert.Equal(t, c11, c21) // 443 uassert.Equal(t, c12, c22) // 1206 - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), adminAddr) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString()) - c31, c32 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "100", "100") + c31, c32 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "100", "100") uassert.Equal(t, c31, "100") uassert.Equal(t, c32, "100") - c41, c42 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + c41, c42 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") uassert.Equal(t, c41, "343") // 343 = c21 - 100 uassert.Equal(t, c42, "1106") // 1106 = c22 - 100 // Mint > No Burn => nothing to collect - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString(), adminAddr) // Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpectStr*15) - c51, c52 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + c51, c52 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") uassert.Equal(t, c51, "0") uassert.Equal(t, c52, "0") // Burn Now => something to collect Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(15)).ToString()) - c61, c62 := Collect(barPath, fooPath, fee500, admin, test_tickLower, test_tickUpper, "50000000", "50000000") + c61, c62 := Collect(barPath, fooPath, fee500, adminAddr, test_tickLower, test_tickUpper, "50000000", "50000000") uassert.NotEqual(t, c61, "0") uassert.NotEqual(t, c62, "0") } @@ -189,31 +190,31 @@ func TestCollect(t *testing.T) { // 5. Swap by admin func TestSwap(t *testing.T) { pool := GetPool(barPath, fooPath, fee500) - test_liquidity := pool.PoolGetLiquidity() + test_liquidity := pool.Liquidity() uassert.Equal(t, test_liquidity.ToString(), "0") std.TestSetRealm(posRealm) - Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(20000)).ToString(), admin) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, new(u256.Uint).Mul(test_liquidityExpect256, u256.NewUint(20000)).ToString(), adminAddr) // Swap several times std.TestSetRealm(rouRealm) test_price := consts.MIN_PRICE { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) amount0, amount1 := Swap( fooPath, // token0Path barPath, // token1Path fee500, // fee - admin, // recipient + adminAddr, // recipient true, // zeroForOne "10000", // _amountSpecified test_price, // _sqrtPriceLimitX96 - admin, // payer + adminAddr, // payer ) uassert.NotEqual(t, amount0, "0") @@ -221,11 +222,11 @@ func TestSwap(t *testing.T) { intAmount0, _ := strconv.Atoi(amount0) intAmount1, _ := strconv.Atoi(amount1) - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, userOldToken0Bal-userNewToken0Bal, uint64(intAmount0)) uassert.Equal(t, userNewToken1Bal-userOldToken1Bal, uint64(-intAmount1)) @@ -234,22 +235,22 @@ func TestSwap(t *testing.T) { } { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) - amount0, amount1 := Swap(barPath, fooPath, fee500, admin, true, "5000", test_price, admin) // give enough amount to take fees away + amount0, amount1 := Swap(barPath, fooPath, fee500, adminAddr, true, "5000", test_price, adminAddr) // give enough amount to take fees away intAmount0, _ := strconv.Atoi(amount0) intAmount1, _ := strconv.Atoi(amount1) - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, userOldToken0Bal-userNewToken0Bal, uint64(intAmount0)) uassert.Equal(t, userNewToken1Bal-userOldToken1Bal, uint64(-intAmount1)) @@ -258,22 +259,22 @@ func TestSwap(t *testing.T) { } { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) - amount0, amount1 := Swap(barPath, fooPath, fee500, admin, true, "1000", test_price, admin) // give enough amount to take fees away + amount0, amount1 := Swap(barPath, fooPath, fee500, adminAddr, true, "1000", test_price, adminAddr) // give enough amount to take fees away intAmount0, _ := strconv.Atoi(amount0) intAmount1, _ := strconv.Atoi(amount1) - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, userOldToken0Bal-userNewToken0Bal, uint64(intAmount0)) uassert.Equal(t, userNewToken1Bal-userOldToken1Bal, uint64(-intAmount1)) @@ -283,22 +284,22 @@ func TestSwap(t *testing.T) { // Swap token1 -> token0 { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) - amount0, amount1 := Swap(barPath, fooPath, fee500, admin, false, "16000", consts.MAX_PRICE, admin) // give enough amount to take fees away + amount0, amount1 := Swap(barPath, fooPath, fee500, adminAddr, false, "16000", consts.MAX_PRICE, adminAddr) // give enough amount to take fees away intAmount0, _ := strconv.Atoi(amount0) intAmount1, _ := strconv.Atoi(amount1) - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) + poolNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(consts.POOL_ADDR) + poolNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(consts.POOL_ADDR) - userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + userNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + userNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) uassert.Equal(t, userOldToken0Bal-userNewToken0Bal, uint64(intAmount0)) uassert.Equal(t, userNewToken1Bal-userOldToken1Bal, uint64(-intAmount1)) @@ -312,7 +313,7 @@ func TestSetFeeProtocolByAdmin(t *testing.T) { // non admin call uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-001] caller has no permission || pool.gno__SetFeeProtocolByAdmin() || only admin(g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d) can set fee protocol, called from g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm`, + `caller(g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm) has no permission`, func() { SetFeeProtocolByAdmin(2, 2) }, ) @@ -320,9 +321,12 @@ func TestSetFeeProtocolByAdmin(t *testing.T) { std.TestSetRealm(adminRealm) SetFeeProtocolByAdmin(6, 8) - for _, pool := range pools { - uassert.Equal(t, pool.PoolGetSlot0().feeProtocol, uint8(134)) - } + pools.Iterate("", "", func(poolPath string, iPool interface{}) bool { + pool := iPool.(*Pool) + uassert.Equal(t, pool.Slot0FeeProtocol(), uint8(134)) + return false + }) + } // 7. CollectProtocol by admin @@ -331,23 +335,22 @@ func TestCollectProtocol(t *testing.T) { SetFeeProtocolByAdmin(6, 8) pool := GetPool(barPath, fooPath, fee500) - test_slot0 := pool.PoolGetSlot0() - uassert.Equal(t, test_slot0.feeProtocol, uint8(134)) + uassert.Equal(t, pool.Slot0FeeProtocol(), uint8(134)) // Make ProtocolFee via Swap by admin ( Mint by admin ) { std.TestSetRealm(rouRealm) - Swap(barPath, fooPath, fee500, admin, true, "200000", consts.MIN_PRICE, admin) // swap token0 -> token1 => fee only in token0 + Swap(barPath, fooPath, fee500, adminAddr, true, "200000", consts.MIN_PRICE, adminAddr) // swap token0 -> token1 => fee only in token0 - adminOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminOldToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminOldToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) std.TestSetRealm(adminRealm) - amount0, amount1 := CollectProtocolByAdmin(barPath, fooPath, fee500, admin, "100000", "100000") + amount0, amount1 := CollectProtocolByAdmin(barPath, fooPath, fee500, adminAddr, "100000", "100000") - adminNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, admin) - adminNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, admin) + adminNewToken0Bal := common.GetToken(pool.token0Path).BalanceOf(adminAddr) + adminNewToken1Bal := common.GetToken(pool.token1Path).BalanceOf(adminAddr) _token0Diff := adminNewToken0Bal - adminOldToken0Bal _token1Diff := adminNewToken1Bal - adminOldToken1Bal diff --git a/pool/tests/__TEST_pool_spec_#1_test.gnoA b/pool/tests/__TEST_pool_spec_#1_test.gnoA index 05ed9ee5..d6dea24a 100644 --- a/pool/tests/__TEST_pool_spec_#1_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#1_test.gnoA @@ -34,9 +34,9 @@ func AfterTest(t *testing.T) { std.TestSetRealm(poolRealm) barBal := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBal := foo.BalanceOf(a2u(consts.POOL_ADDR)) - bar.Transfer(a2u(admin), barBal) - foo.Transfer(a2u(admin), fooBal) - delete(pools, "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") + bar.Transfer(a2u(adminAddr), barBal) + foo.Transfer(a2u(adminAddr), fooBal) + pools.Remove("gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") } func TestCreateFooBarPool_Should_be_failed_if_price_is_too_low(t *testing.T) { @@ -126,14 +126,14 @@ func TestMint_fail_if_tickLower_greater_than_tickUpper(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if tickLower greater than tickUpper========================== uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-022] invalid tick and tick spacing requested || tick_bitmap.gno__tickBitmapFlipTick() || tick(1) MOD tickSpacing(60) != 0(1)`, + `[GNOSWAP-POOL-024] tickLower is greater than or equal to tickUpper || tickLower(1), tickUpper(0)`, func() { - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", 1, 0, "1", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", 1, 0, "1", adminAddr) }, ) AfterTest(t) @@ -151,14 +151,14 @@ func TestMint_fail_if_tickLower_less_than_min_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if tickLower less than min tick========================== uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-022] invalid tick and tick spacing requested || tick_bitmap.gno__tickBitmapFlipTick() || tick(-887273) MOD tickSpacing(60) != 0(-53)`, + `[GNOSWAP-POOL-028] tickLower is invalid || tickLower(-887273) < MIN_TICK(-887272)`, func() { - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", -887273, 0, "1", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", -887273, 0, "1", adminAddr) }, ) AfterTest(t) @@ -175,14 +175,14 @@ func TestMint_fail_if_tickUpper_greater_than_max_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if tickUpper greater than max tick========================== uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-022] invalid tick and tick spacing requested || tick_bitmap.gno__tickBitmapFlipTick() || tick(887273) MOD tickSpacing(60) != 0(53)`, + `[GNOSWAP-POOL-029] tickUpper is invalid || tickUpper(887273) > MAX_TICK(887272)`, func() { - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", 0, 887273, "1", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", 0, 887273, "1", adminAddr) }, ) AfterTest(t) @@ -200,7 +200,7 @@ func TestMint_fail_if_amount_exceeds_the_max(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if amount exceeds the max ========================== pool := GetPool(barPath, fooPath, 3000) @@ -209,9 +209,9 @@ func TestMint_fail_if_amount_exceeds_the_max(t *testing.T) { tickSpacing := pool.tickSpacing uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || tick.gno__tickUpdate() || liquidityGrossAfter(11505743598341114571880798222544995) overflows maxLiquidity(11505743598341114571880798222544994)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidityGrossAfter(11505743598341114571880798222544995) overflows maxLiquidity(11505743598341114571880798222544994)`, func() { - pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), admin) + pl.Mint(barPath, fooPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), adminAddr) }, ) AfterTest(t) @@ -229,7 +229,7 @@ func TestMint_fail_if_total_amount_at_tick_exceeds_the_max(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if total amount at tick exceeds the max======================== pool := GetPool(fooPath, barPath, 3000) @@ -243,25 +243,25 @@ func TestMint_fail_if_total_amount_at_tick_exceeds_the_max(t *testing.T) { uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-005] out of range for numeric value || pool.gno__checkAmountRange() || amountAbs(36384355944659449090771081304848911) overflows uint64 range`, + `[GNOSWAP-POOL-005] out of range for numeric value: amount(36384355944659449090771081304848911) overflows uint64 range`, func() { - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), adminAddr) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || tick.gno__tickUpdate() || liquidityGrossAfter(23011487196682229143761596445087990) overflows maxLiquidity(11505743598341114571880798222544994)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidityGrossAfter(23011487196682229143761596445087990) overflows maxLiquidity(11505743598341114571880798222544994)`, func() { - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing*2, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing*2, maxTick-tickSpacing, maxLiquidityPerTick.ToString(), adminAddr) }, ) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || tick.gno__tickUpdate() || liquidityGrossAfter(23011487196682229143761596445087990) overflows maxLiquidity(11505743598341114571880798222544994)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidityGrossAfter(23011487196682229143761596445087990) overflows maxLiquidity(11505743598341114571880798222544994)`, func() { - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing*2, maxLiquidityPerTick.ToString(), admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing*2, maxLiquidityPerTick.ToString(), adminAddr) }, ) AfterTest(t) @@ -281,7 +281,7 @@ func TestMint_fail_if_amount_is_0(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // =====================fails if total amount at tick exceeds the max======================== @@ -289,9 +289,9 @@ func TestMint_fail_if_amount_is_0(t *testing.T) { tickSpacing := pool.tickSpacing uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-010] zero liquidity || pool.gno__Mint() || liquidityAmount == 0`, + `[GNOSWAP-POOL-010] zero liquidity`, func() { - pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, "0", admin) + pl.Mint(fooPath, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick+tickSpacing, maxTick-tickSpacing, "0", adminAddr) }, ) } diff --git a/pool/tests/__TEST_pool_spec_#2_test.gnoA b/pool/tests/__TEST_pool_spec_#2_test.gnoA index 070fde8a..ec96d0ab 100644 --- a/pool/tests/__TEST_pool_spec_#2_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#2_test.gnoA @@ -35,9 +35,9 @@ func AfterTest(t *testing.T) { std.TestSetRealm(poolRealm) barBal := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBal := foo.BalanceOf(a2u(consts.POOL_ADDR)) - bar.Transfer(a2u(admin), barBal) - foo.Transfer(a2u(admin), fooBal) - delete(pools, "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") + bar.Transfer(a2u(adminAddr), barBal) + foo.Transfer(a2u(adminAddr), fooBal) + pools.Remove("gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") } func TestSuccess_case_init_balance(t *testing.T) { @@ -54,7 +54,7 @@ func TestSuccess_case_init_balance(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== initial balance ======================== @@ -81,7 +81,7 @@ func TestSuccess_case_init_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== initial tick ======================== @@ -106,12 +106,12 @@ func TestSuccess_case_transfer_token0_only(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== transfer token0 only ======================== std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -22980, 0, "10000", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -22980, 0, "10000", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -135,7 +135,7 @@ func TestSuccess_case_max_tick_with_max_leverage(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== max tick with max leverage ======================== @@ -143,7 +143,7 @@ func TestSuccess_case_max_tick_with_max_leverage(t *testing.T) { tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", maxTick-tickSpacing, maxTick, "5070602400912917605986812821504", admin) // 2**102 + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", maxTick-tickSpacing, maxTick, "5070602400912917605986812821504", adminAddr) // 2**102 barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -167,7 +167,7 @@ func TestSuccess_case_work_for_max_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== work for max tick ======================== @@ -175,7 +175,7 @@ func TestSuccess_case_work_for_max_tick(t *testing.T) { tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -22980, maxTick, "10000", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -22980, maxTick, "10000", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -199,7 +199,7 @@ func TestSuccess_case_removing_works(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== removing works ======================== @@ -207,11 +207,11 @@ func TestSuccess_case_removing_works(t *testing.T) { tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, 0, "10000", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, 0, "10000", adminAddr) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidity_math.gno__liquidityMathAddDelta() || LS(z must be < x) (x: 0, y: -10000, z:115792089237316195423570985008687907853269984665640564039457584007913129629936)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || Condition failed: (z must be < x) (x: 0, y: -10000, z:115792089237316195423570985008687907853269984665640564039457584007913129629936)`, func() { pl.Burn(token0Path, barPath, 3000, -240, 0, "10000") // LS panic }, @@ -234,7 +234,7 @@ func TestSuccess_case_adds_liquidity_to_liquidityGross(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", minTick, maxTick, "3161", adminAddr) // ===================== adds liquidity to liquiditygross ======================== @@ -242,7 +242,7 @@ func TestSuccess_case_adds_liquidity_to_liquidityGross(t *testing.T) { tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, 0, "100", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, 0, "100", adminAddr) _, _, liquidityGross, _, _, _, _, _ := pool.GetTicks(-240) uassert.Equal(t, liquidityGross.ToString(), "100") _, _, liquidityGross, _, _, _, _, _ = pool.GetTicks(0) @@ -253,7 +253,7 @@ func TestSuccess_case_adds_liquidity_to_liquidityGross(t *testing.T) { uassert.Equal(t, liquidityGross.ToString(), "0") std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, tickSpacing, "150", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", -240, tickSpacing, "150", adminAddr) _, _, liquidityGross, _, _, _, _, _ = pool.GetTicks(-240) uassert.Equal(t, liquidityGross.ToString(), "250") _, _, liquidityGross, _, _, _, _, _ = pool.GetTicks(0) @@ -264,7 +264,7 @@ func TestSuccess_case_adds_liquidity_to_liquidityGross(t *testing.T) { uassert.Equal(t, liquidityGross.ToString(), "0") std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", 0, tickSpacing*2, "60", admin) + pl.Mint(token0Path, barPath, 3000, "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", 0, tickSpacing*2, "60", adminAddr) _, _, liquidityGross, _, _, _, _, _ = pool.GetTicks(-240) uassert.Equal(t, liquidityGross.ToString(), "250") _, _, liquidityGross, _, _, _, _, _ = pool.GetTicks(0) @@ -289,17 +289,17 @@ func TestSuccess_case_removes_liquidity_from_liquidityGross(t *testing.T) { bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) std.TestSetRealm(posRealm) - mint0, mint1 := pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + mint0, mint1 := pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== removes liquidity from liquidityGross ======================== pool := GetPool(barPath, fooPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - mint0, mint1 = pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, -240, 0, "100", admin) + mint0, mint1 = pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, -240, 0, "100", adminAddr) std.TestSetRealm(posRealm) - mint0, mint1 = pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, -240, 0, "40", admin) + mint0, mint1 = pl.Mint(barPath, fooPath, 3000, consts.POSITION_ADDR, -240, 0, "40", adminAddr) pl.Burn(barPath, fooPath, 3000, -240, 0, "90") @@ -317,8 +317,7 @@ func gnsBalance(addr std.Address) uint64 { func (pool *Pool) GetTicks( tick int32, ) (feeGrowthOutside0X128 *u256.Uint, feeGrowthOutside1X128 *u256.Uint, liquidityGross *u256.Uint, liquidityNet *i256.Int, secondsPerLiquidityOutsideX128 *u256.Uint, tickCumulativeOutside int64, secondsOutside uint32, initialized bool) { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) return info.feeGrowthOutside0X128, info.feeGrowthOutside1X128, info.liquidityGross, info.liquidityNet, info.secondsPerLiquidityOutsideX128, info.tickCumulativeOutside, info.secondsOutside, info.initialized } diff --git a/pool/tests/__TEST_pool_spec_#3_test.gnoA b/pool/tests/__TEST_pool_spec_#3_test.gnoA index 66286e96..94061451 100644 --- a/pool/tests/__TEST_pool_spec_#3_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#3_test.gnoA @@ -35,9 +35,9 @@ func AfterTest(t *testing.T) { std.TestSetRealm(poolRealm) barBal := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBal := foo.BalanceOf(a2u(consts.POOL_ADDR)) - bar.Transfer(a2u(admin), barBal) - foo.Transfer(a2u(admin), fooBal) - delete(pools, "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") + bar.Transfer(a2u(adminAddr), barBal) + foo.Transfer(a2u(adminAddr), fooBal) + pools.Remove("gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") } func TestSuccess_case_clear_tick_lowers_if_last_poistion_is_removed(t *testing.T) { @@ -54,7 +54,7 @@ func TestSuccess_case_clear_tick_lowers_if_last_poistion_is_removed(t *testing.T poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== clears tick lower if last position is removed ===================== @@ -62,7 +62,7 @@ func TestSuccess_case_clear_tick_lowers_if_last_poistion_is_removed(t *testing.T tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", adminAddr) pl.Burn(token0Path, barPath, 3000, -240, 0, "100") feeGrowthOutside0X128, feeGrowthOutside1X128, liquidityGross, _, _, _, _, _ := pool.GetTicks(-240) uassert.Equal(t, liquidityGross.ToString(), "0") @@ -86,7 +86,7 @@ func TestSuccess_case_clear_tick_lowers_if_last_poistion_is_removed2(t *testing. poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== clears tick lower if last position is removed ===================== @@ -94,7 +94,7 @@ func TestSuccess_case_clear_tick_lowers_if_last_poistion_is_removed2(t *testing. tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", adminAddr) pl.Burn(token0Path, barPath, 3000, -240, 0, "100") feeGrowthOutside0X128, feeGrowthOutside1X128, liquidityGross, _, _, _, _, _ := pool.GetTicks(0) @@ -119,7 +119,7 @@ func TestSuccess_case_only_clears_the_tick_that_is_not_used_at_all(t *testing.T) poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // ===================== only clears the tick that is not used at all ===================== @@ -127,8 +127,8 @@ func TestSuccess_case_only_clears_the_tick_that_is_not_used_at_all(t *testing.T) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", admin) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "250", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "100", adminAddr) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -240, 0, "250", adminAddr) pl.Burn(token0Path, barPath, 3000, -240, 0, "100") feeGrowthOutside0X128, feeGrowthOutside1X128, liquidityGross, _, _, _, _, _ := pool.GetTicks(-240) // liquidityGrossStr := liquidityGross.ToString() @@ -153,8 +153,7 @@ func gnsBalance(addr std.Address) uint64 { func (pool *Pool) GetTicks( tick int32, ) (feeGrowthOutside0X128 *u256.Uint, feeGrowthOutside1X128 *u256.Uint, liquidityGross *u256.Uint, liquidityNet *i256.Int, secondsPerLiquidityOutsideX128 *u256.Uint, tickCumulativeOutside int64, secondsOutside uint32, initialized bool) { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) return info.feeGrowthOutside0X128, info.feeGrowthOutside1X128, info.liquidityGross, info.liquidityNet, info.secondsPerLiquidityOutsideX128, info.tickCumulativeOutside, info.secondsOutside, info.initialized } diff --git a/pool/tests/__TEST_pool_spec_#4_test.gnoA b/pool/tests/__TEST_pool_spec_#4_test.gnoA index 146c5380..738c6f53 100644 --- a/pool/tests/__TEST_pool_spec_#4_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#4_test.gnoA @@ -34,9 +34,9 @@ func AfterTest(t *testing.T) { std.TestSetRealm(poolRealm) barBal := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBal := foo.BalanceOf(a2u(consts.POOL_ADDR)) - bar.Transfer(a2u(admin), barBal) - foo.Transfer(a2u(admin), fooBal) - delete(pools, "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") + bar.Transfer(a2u(adminAddr), barBal) + foo.Transfer(a2u(adminAddr), fooBal) + pools.Remove("gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") } func TestSuccess_price_within_range_transfers_current_price_of_both_tokens(t *testing.T) { @@ -53,14 +53,14 @@ func TestSuccess_price_within_range_transfers_current_price_of_both_tokens(t *te poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== price within range: transfers current price of both tokens ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick+tickSpacing, maxTick-tickSpacing, "100", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick+tickSpacing, maxTick-tickSpacing, "100", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -117,14 +117,14 @@ func TestSuccess_works_for_min_max_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // ===================== only clears the tick that is not used at all ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "10000", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "10000", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -148,7 +148,7 @@ func TestSuccess_removing_works(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, "g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec", minTick, maxTick, "3161", adminAddr) // ===================== only clears the tick that is not used at all ===================== @@ -156,7 +156,7 @@ func TestSuccess_removing_works(t *testing.T) { tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick+tickSpacing, maxTick-tickSpacing, "10000", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick+tickSpacing, maxTick-tickSpacing, "10000", adminAddr) pl.Burn(token0Path, barPath, 3000, minTick+tickSpacing, maxTick-tickSpacing, "100") amount0, amount1 := pl.Collect(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick+tickSpacing, maxTick-tickSpacing, consts.MAX_UINT128, consts.MAX_UINT128) @@ -172,8 +172,7 @@ func gnsBalance(addr std.Address) uint64 { func (pool *Pool) GetTicks( tick int32, ) (feeGrowthOutside0X128 *u256.Uint, feeGrowthOutside1X128 *u256.Uint, liquidityGross *u256.Uint, liquidityNet *i256.Int, secondsPerLiquidityOutsideX128 *u256.Uint, tickCumulativeOutside int64, secondsOutside uint32, initialized bool) { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) return info.feeGrowthOutside0X128, info.feeGrowthOutside1X128, info.liquidityGross, info.liquidityNet, info.secondsPerLiquidityOutsideX128, info.tickCumulativeOutside, info.secondsOutside, info.initialized } diff --git a/pool/tests/__TEST_pool_spec_#5_test.gnoA b/pool/tests/__TEST_pool_spec_#5_test.gnoA index c70e68c5..02343835 100644 --- a/pool/tests/__TEST_pool_spec_#5_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#5_test.gnoA @@ -33,9 +33,9 @@ func AfterTest(t *testing.T) { std.TestSetRealm(poolRealm) barBal := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBal := foo.BalanceOf(a2u(consts.POOL_ADDR)) - bar.Transfer(a2u(admin), barBal) - foo.Transfer(a2u(admin), fooBal) - delete(pools, "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") + bar.Transfer(a2u(adminAddr), barBal) + foo.Transfer(a2u(adminAddr), fooBal) + pools.Remove("gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000") } func TestSuccess_transfers_token1_only(t *testing.T) { @@ -52,14 +52,14 @@ func TestSuccess_transfers_token1_only(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== transfers token1 only ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -46080, -23040, "10000", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -46080, -23040, "10000", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -84,14 +84,14 @@ func TestSuccess_min_tick_with_max_leverage(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== min tick with max leverage ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, minTick+tickSpacing, "5070602400912917605986812821504", admin) // 2**102 + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, minTick+tickSpacing, "5070602400912917605986812821504", adminAddr) // 2**102 barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -116,14 +116,14 @@ func TestSuccess_work_for_min_tick(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== work for min tick ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, -23040, "10000", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, -23040, "10000", adminAddr) barBalance := bar.BalanceOf(a2u(consts.POOL_ADDR)) fooBalance := foo.BalanceOf(a2u(consts.POOL_ADDR)) @@ -148,14 +148,14 @@ func TestSuccess_removing_works(t *testing.T) { poolPath := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000" std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, minTick, maxTick, "3161", adminAddr) // ===================== removing works ===================== pool := GetPool(token0Path, barPath, 3000) tickSpacing := pool.tickSpacing std.TestSetRealm(posRealm) - pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -46080, -46020, "10000", admin) + pl.Mint(token0Path, barPath, 3000, consts.POSITION_ADDR, -46080, -46020, "10000", adminAddr) amount0, amount1 := pl.Burn(token0Path, barPath, 3000, -46080, -46020, "10000") uassert.Equal(t, amount0, "0") diff --git a/pool/tests/__TEST_pool_spec_#6_test.gnoA b/pool/tests/__TEST_pool_spec_#6_test.gnoA index 1e36d3c2..0d3581cc 100644 --- a/pool/tests/__TEST_pool_spec_#6_test.gnoA +++ b/pool/tests/__TEST_pool_spec_#6_test.gnoA @@ -40,7 +40,7 @@ func TestPositionsProtected(t *testing.T) { -887160, 887160, test_liquidityExpectStr, - admin, + adminAddr, ) std.TestSetRealm(rouRealm) @@ -48,22 +48,22 @@ func TestPositionsProtected(t *testing.T) { barPath, fooPath, fee500, - admin, + adminAddr, true, "10000", consts.MIN_PRICE, - admin, + adminAddr, ) Swap( barPath, fooPath, fee500, - admin, + adminAddr, false, "10000", consts.MAX_PRICE, - admin, + adminAddr, ) // did swap t0 => t1 and t1 => t0 @@ -81,7 +81,7 @@ func TestPokeIsNotAllowedOnUninitilaizedPosition(t *testing.T) { std.TestSetRealm(posRealm) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-010] zero liquidity || position.gno__positionUpdate() || both liquidityDelta and (self)liquidity are zero`, + `[GNOSWAP-POOL-010] zero liquidity || both liquidityDelta and current position's liquidity are zero`, func() { Burn( barPath, @@ -113,7 +113,7 @@ func TestWorkAccross(t *testing.T) { -887270, 887270, "100000000000", - admin, + adminAddr, ) // type(uint128).max * 2**128 / 1e18 @@ -134,7 +134,7 @@ func TestWorkAccross(t *testing.T) { // tokensOwed thisPositionKey := getPositionKey(consts.POSITION_ADDR, -887270, 887270) - thisPosition := thisPool.positions[thisPositionKey] + thisPosition := thisPool.mustGetPosition(thisPositionKey) tokensOwed0 := thisPosition.tokensOwed0 tokensOwed1 := thisPosition.tokensOwed1 diff --git a/pool/tests/__TEST_pool_test.gnoA b/pool/tests/__TEST_pool_test.gnoA index 017ffc5e..6f3c6e73 100644 --- a/pool/tests/__TEST_pool_test.gnoA +++ b/pool/tests/__TEST_pool_test.gnoA @@ -36,7 +36,7 @@ func TestCreateFooBarPool(t *testing.T) { CreatePool(barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(-10000).ToString()) // tick -10000 - uassert.Equal(t, len(pools), 1) + uassert.Equal(t, pools.Size(), 1) std.TestSkipHeights(1) } @@ -53,7 +53,7 @@ func TestCreateBarBazPool(t *testing.T) { CreatePool(barPath, bazPath, fee500, "130621891405341611593710811006") // tick 10000 - uassert.Equal(t, len(pools), 2) + uassert.Equal(t, pools.Size(), 2) std.TestSkipHeights(1) } @@ -73,7 +73,7 @@ func TestMintFooBarLiquidity(t *testing.T) { -11000, // -11000 -9000, // -9000 test_liquidityExpectStr, - admin, + adminAddr, ) uassert.Equal(t, amount0, "8040316") uassert.Equal(t, amount1, "2958015") @@ -96,7 +96,7 @@ func TestMintBarBazLiquidity(t *testing.T) { test_tickLower, test_tickUpper, test_liquidityExpectStr, - admin, + adminAddr, ) uassert.Equal(t, amount0, "2958015") uassert.Equal(t, amount1, "8040316") @@ -131,7 +131,7 @@ func TestSetWithdrawalFeeByAdminNoPermission(t *testing.T) { uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-001] caller has no permission || protocol_fee_withdrawal.gno__SetWithdrawalFeeByAdmin() || only admin(g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d) can set withdrawal fee, called from g1v36k6mteta047h6lta047h6lta047h6lz7gmv8`, + `caller(g1v36k6mteta047h6lta047h6lta047h6lz7gmv8) has no permission`, func() { SetWithdrawalFeeByAdmin(2) }, @@ -167,7 +167,7 @@ func TestSetPoolCreationFeeByAdminNoPermission(t *testing.T) { uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-001] caller has no permission || protocol_fee_pool_creation.gno__SetPoolCreationFeeByAdmin() || only admin(g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d) can set pool creation fee, called from g1v36k6mteta047h6lta047h6lta047h6lz7gmv8`, + `caller(g1v36k6mteta047h6lta047h6lta047h6lz7gmv8) has no permission`, func() { SetPoolCreationFeeByAdmin(2) }, diff --git a/pool/tests/__TEST_pool_tick_test.gnoA b/pool/tests/__TEST_pool_tick_test.gnoA index b9e5fd14..11eaf57a 100644 --- a/pool/tests/__TEST_pool_tick_test.gnoA +++ b/pool/tests/__TEST_pool_tick_test.gnoA @@ -2,8 +2,10 @@ package pool import ( "std" + "strconv" "testing" + "gno.land/p/demo/avl" "gno.land/p/demo/uassert" i256 "gno.land/p/gnoswap/int256" u256 "gno.land/p/gnoswap/uint256" @@ -18,7 +20,7 @@ import ( var ( tickSpacing int32 maxLiquidityPerTick *u256.Uint - pool *Pool + singlePool *Pool ) const ( @@ -42,6 +44,7 @@ func TestInitCreatePool(t *testing.T) { } func DeployPool(token0 string, token1 string) { + pools = avl.NewTree() std.TestSetRealm(adminRealm) gns.Approve(a2u(consts.POOL_ADDR), poolCreationFee) std.TestSetRealm(adminRealm) @@ -196,8 +199,8 @@ func TestTickGetFeeGrowthInside_4(t *testing.T) { } func TestTickGetFeeGrowthInside_5(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar1" - var token1 string = "gno.land/r/onbloc/foo1" + var token0 string = "gno.land/r/onbloc/bar" + var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) // subtracts lower tick if above @@ -326,8 +329,8 @@ func TestTickGetFeeGrowthInside_7(t *testing.T) { } func TestTickUpdate_1(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar2" - var token1 string = "gno.land/r/onbloc/foo2" + var token0 string = "gno.land/r/onbloc/bar" + var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) // flips from zero to non zero @@ -347,8 +350,8 @@ func TestTickUpdate_1(t *testing.T) { } func TestTickUpdate_2(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar3" - var token1 string = "gno.land/r/onbloc/foo3" + var token0 string = "gno.land/r/onbloc/bar" + var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) // does not flip from nonzero to greater nonzero @@ -371,8 +374,8 @@ func TestTickUpdate_2(t *testing.T) { } func TestTickUpdate_3(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar4" - var token1 string = "gno.land/r/onbloc/foo3" + var token0 string = "gno.land/r/onbloc/bar" + var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -398,7 +401,7 @@ func TestTickUpdate_3(t *testing.T) { } func TestTickUpdate_4(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar4" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -425,7 +428,7 @@ func TestTickUpdate_4(t *testing.T) { } func TestTickUpdate_5(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar5" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -450,7 +453,7 @@ func TestTickUpdate_5(t *testing.T) { uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || tick.gno__tickUpdate() || liquidityGrossAfter(4) overflows maxLiquidity(3)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidityGrossAfter(4) overflows maxLiquidity(3)`, func() { pool.tickUpdate(tick, tickCurrent, liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, upper, maxLiquidity) }, @@ -461,7 +464,7 @@ func TestTickUpdate_6(t *testing.T) { var liquidityGross *u256.Uint var liquidityNet *i256.Int - var token0 string = "gno.land/r/onbloc/bar6" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -497,7 +500,7 @@ func TestTickUpdate_6(t *testing.T) { } func TestTickUpdate_7(t *testing.T) { - var token0 string = "gno.land/r/onbloc/bar7" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -519,7 +522,7 @@ func TestTickUpdate_7(t *testing.T) { flipped = pool.tickUpdate(tick, tickCurrent, liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, upper, maxLiquidityPerTick) uassert.PanicsWithMessage( t, - `[GNOSWAP-POOL-009] invalid liquidity calculated || tick.gno__tickUpdate() || liquidityGrossAfter(1917569901783203986719870431555992) overflows maxLiquidity(1917569901783203986719870431555990)`, + `[GNOSWAP-POOL-009] invalid liquidity calculated || liquidityGrossAfter(1917569901783203986719870431555992) overflows maxLiquidity(1917569901783203986719870431555990)`, func() { pool.tickUpdate(tick, tickCurrent, liquidityDelta, feeGrowthGlobal0X128, feeGrowthGlobal1X128, upper, maxLiquidityPerTick) }, @@ -536,7 +539,7 @@ func TestTickUpdate_8(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/bar8" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -574,7 +577,7 @@ func TestTickUpdate_9(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/bar9" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -614,7 +617,7 @@ func TestTickUpdate_10(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/bar10" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) pool := GetPool(token0, token1, 500) @@ -654,7 +657,7 @@ func TestClear_1(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/clear1" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) @@ -693,7 +696,7 @@ func TestTickCross_1(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/cross1" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) @@ -730,7 +733,7 @@ func TestTickCross_2(t *testing.T) { var secondsOutside uint32 var initialized bool - var token0 string = "gno.land/r/onbloc/cross2" + var token0 string = "gno.land/r/onbloc/bar" var token1 string = "gno.land/r/onbloc/foo" DeployPool(token0, token1) @@ -776,11 +779,8 @@ func (pool *Pool) TickGetFeeGrowthInside( feeGrowthGlobal0X128 *u256.Uint, // uint256 feeGrowthGlobal1X128 *u256.Uint, // uint256 ) (*u256.Uint, *u256.Uint) { // uint256 - lower := pool.ticks[tickLower] - lower.init() - - upper := pool.ticks[tickUpper] - upper.init() + lower := pool.getTick(tickLower) + upper := pool.getTick(tickUpper) var feeGrowthBelow0X128, feeGrowthBelow1X128 *u256.Uint if tickCurrent >= tickLower { @@ -817,8 +817,7 @@ func (pool *Pool) SetTick( secondsOutside uint32, initialized bool, ) { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) info.feeGrowthOutside0X128 = feeGrowthOutside0X128 info.feeGrowthOutside1X128 = feeGrowthOutside1X128 @@ -829,7 +828,7 @@ func (pool *Pool) SetTick( info.secondsOutside = secondsOutside info.initialized = initialized - pool.ticks[tick] = info + pool.setTick(tick, info) } func (pool *Pool) TickUpdate( @@ -846,8 +845,7 @@ func (pool *Pool) TickUpdate( feeGrowthGlobal0X128 = feeGrowthGlobal0X128.NilToZero() feeGrowthGlobal1X128 = feeGrowthGlobal1X128.NilToZero() - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) liquidityGrossBefore := info.liquidityGross liquidityGrossAfter := liquidityMathAddDelta(liquidityGrossBefore, liquidityDelta) @@ -875,7 +873,7 @@ func (pool *Pool) TickUpdate( info.liquidityNet = i256.Zero().Add(info.liquidityNet, liquidityDelta) } - pool.ticks[tick] = info + pool.setTick(tick, info) return flipped } @@ -883,8 +881,7 @@ func (pool *Pool) TickUpdate( func (pool *Pool) GetTicks( tick int32, ) (feeGrowthOutside0X128 *u256.Uint, feeGrowthOutside1X128 *u256.Uint, liquidityGross *u256.Uint, liquidityNet *i256.Int, secondsPerLiquidityOutsideX128 *u256.Uint, tickCumulativeOutside int64, secondsOutside uint32, initialized bool) { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) return info.feeGrowthOutside0X128, info.feeGrowthOutside1X128, info.liquidityGross, info.liquidityNet, info.secondsPerLiquidityOutsideX128, info.tickCumulativeOutside, info.secondsOutside, info.initialized } @@ -892,7 +889,8 @@ func (pool *Pool) GetTicks( func (pool *Pool) Clear( tick int32, ) { - delete(pool.ticks, tick) + tickStr := strconv.Itoa(int(tick)) + pool.ticks.Remove(tickStr) } func (pool *Pool) TickCross( @@ -900,13 +898,12 @@ func (pool *Pool) TickCross( feeGrowthGlobal0X128 *u256.Uint, // uint256 feeGrowthGlobal1X128 *u256.Uint, // uint256 ) *i256.Int { - info := pool.ticks[tick] - info.init() + info := pool.getTick(tick) info.feeGrowthOutside0X128 = new(u256.Uint).Sub(feeGrowthGlobal0X128, info.feeGrowthOutside0X128) info.feeGrowthOutside1X128 = new(u256.Uint).Sub(feeGrowthGlobal1X128, info.feeGrowthOutside1X128) - pool.ticks[tick] = info + pool.setTick(tick, info) liquidityNet := info.liquidityNet return liquidityNet diff --git a/pool/tests/__TEST_pool_tick_transaction_test.gnoA b/pool/tests/__TEST_pool_tick_transaction_test.gnoA index 5a44910c..cddde99d 100644 --- a/pool/tests/__TEST_pool_tick_transaction_test.gnoA +++ b/pool/tests/__TEST_pool_tick_transaction_test.gnoA @@ -45,7 +45,7 @@ func TestTickTransaction(t *testing.T) { -24082, -24080, liqToMint, - admin, + adminAddr, ) uassert.Equal(t, thisPool.liquidity.ToString(), "10000000000") @@ -58,7 +58,7 @@ func TestTickTransaction(t *testing.T) { -24082, -24081, liqToMint, - admin, + adminAddr, ) uassert.Equal(t, thisPool.liquidity.ToString(), "10000000000") @@ -83,15 +83,14 @@ func TestTickTransaction(t *testing.T) { barPath, fooPath, fee100, - admin, + adminAddr, true, "3", consts.MIN_PRICE, - admin, + adminAddr, ) uassert.Equal(t, thisPool.slot0.tick, int32(-24082)) uassert.Equal(t, thisPool.slot0.sqrtPriceX96.ToString(), testSqrtSubOne.ToString()) uassert.Equal(t, thisPool.liquidity.ToString(), "20000000000") } -