diff --git a/staker/__TEST_staker_short_warmup_period_internal_01_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_01_test.gnoA index efc5ad7e9..adc78512f 100644 --- a/staker/__TEST_staker_short_warmup_period_internal_01_test.gnoA +++ b/staker/__TEST_staker_short_warmup_period_internal_01_test.gnoA @@ -14,6 +14,7 @@ import ( pn "gno.land/r/gnoswap/v1/position" "gno.land/r/gnoswap/v1/gnft" + "gno.land/r/gnoswap/v1/gns" "gno.land/r/onbloc/bar" "gno.land/r/onbloc/baz" @@ -35,12 +36,6 @@ func testInit(t *testing.T) { t.Run("init pool tiers", func(t *testing.T) { std.TestSetRealm(adminRealm) - // init pool tiers - // tier 1 - deletePoolTier(t, MUST_EXISTS_IN_TIER_1) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) - std.TestSkipHeights(1) - // override warm-up period for testing changeWarmup(t, 0, 150) changeWarmup(t, 1, 300) @@ -74,7 +69,9 @@ func testCreatePool(t *testing.T) { t.Run("create pool", func(t *testing.T) { std.TestSetRealm(adminRealm) - pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") // current tier 1 + pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") // current tier 1 + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) + pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") // will be tier 2 std.TestSkipHeights(1) @@ -106,10 +103,6 @@ func testMintBarQux100_1(t *testing.T) { uassert.Equal(t, tokenId, uint64(1)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - println(gpi) - // {"height":"126","time":"1234567905","gns":{"staker":"32106164","devOps":"10702053","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -139,9 +132,6 @@ func testMintBarBaz100_2(t *testing.T) { uassert.Equal(t, tokenId, uint64(2)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"127","time":"1234567910","gns":{"staker":"42808219","devOps":"14269404","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -153,8 +143,27 @@ func testStakeToken_1(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(1)) StakeToken(1) - gpi := getPrintInfo(t) - // {"height":"128","time":"1234567915","gns":{"staker":"53510274","devOps":"17836755","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567915","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + std.TestSkipHeights(1) + }) + + t.Run("collect reward position 01", func(t *testing.T) { + std.TestSetRealm(adminRealm) + + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) + afterGns := gns.BalanceOf(admin) + println(afterGns - beforeGns) + uassert.True(t, isInErrorRange(uint64(1605308), afterGns-beforeGns)) + // reward 1605307 + // penalty 3745719 + // total 5351026 + + // reward per block is 10702054 + // 2 pools have tier 1 + // each pool will have 10702054 * 50% = 5351027 + + // position warm up is 30% + // 5351027 * 30% = 1605308.1 std.TestSkipHeights(1) }) @@ -164,27 +173,57 @@ func testSetPoolTier(t *testing.T) { t.Run("set pool tier", func(t *testing.T) { std.TestSetRealm(adminRealm) - addPoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", 2) - gpi := getPrintInfo(t) - // {"height":"129","time":"1234567920","gns":{"staker":"64212329","devOps":"21404106","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567915","stakedDuration":"1","fullAmount":"10702053","ratio":"30","warmUpAmount":"3210616","full30":"10702053","give30":"3210616","penalty30":"7491437","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 2) std.TestSkipHeights(1) }) } func testStakeToken_2(t *testing.T) { t.Run("stake token 2", func(t *testing.T) { - std.TestSetRealm(adminRealm) gnft.Approve(consts.STAKER_ADDR, tid(2)) StakeToken(2) - // @mconcat FIXME - // when emission pool has no target position to distribute, it needs to sent to community pool - - gpi := getPrintInfo(t) - // {"height":"130","time":"1234567925","gns":{"staker":"74914384","devOps":"24971457","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"130","stakedTimestamp":"1234567925","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567915","stakedDuration":"2","fullAmount":"14982873","ratio":"30","warmUpAmount":"4494862","full30":"14982873","give30":"4494862","penalty30":"10488011","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + std.TestSkipHeights(1) + // clear reward + CollectReward(1, false) + CollectReward(2, false) std.TestSkipHeights(1) }) + + t.Run("collect reward position 01", func(t *testing.T) { + std.TestSetRealm(adminRealm) + + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(uint64(1123715), afterGns-beforeGns)) + // reward 1123715 + // penalty 2622002 + // total 3745717 + + // reward per block is 10702054 + // 2 pools have tier 1 + 1 pools have tier 2 + // each pool in tier 1 will have 10702054 * 70% * 50% = 3745718.9 + // > warm up 30% = 3745718.9 * 30% = 1123715.67 + + // each pool in tier 2 will have 10702054 * 30% = 3210616.2 + // > warm up 30% = 3210616.2 * 30% = 963184.86 + }) + + t.Run("collect reward position 02", func(t *testing.T) { + std.TestSetRealm(adminRealm) + + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(uint64(963184), afterGns-beforeGns)) + + // reward 963184 + // penalty 2247431 + // total 3210615 + + }) } diff --git a/staker/__TEST_staker_short_warmup_period_internal_02_small_liq_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_02_small_liq_test.gnoA index 6fc0407a5..f73449477 100644 --- a/staker/__TEST_staker_short_warmup_period_internal_02_small_liq_test.gnoA +++ b/staker/__TEST_staker_short_warmup_period_internal_02_small_liq_test.gnoA @@ -27,7 +27,6 @@ func TestShortWarmUpInternalSmallLiq(t *testing.T) { testMintBarQux100_1(t) testMintBarQux100_2(t) testStakeToken_1_2(t) - testNow(t) testCollectRewardBoth(t) } @@ -35,11 +34,8 @@ func testInit(t *testing.T) { t.Run("init pool tiers", func(t *testing.T) { std.TestSetRealm(adminRealm) - // init pool tiers - // tier 1 + // delete default pool deletePoolTier(t, MUST_EXISTS_IN_TIER_1) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) - std.TestSkipHeights(1) // override warm-up period for testing changeWarmup(t, 0, 150) @@ -79,7 +75,7 @@ func testCreatePool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") - pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) std.TestSkipHeights(1) }) @@ -110,9 +106,6 @@ func testMintBarQux100_1(t *testing.T) { uassert.Equal(t, tokenId, uint64(1)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"126","time":"1234567896","gns":{"staker":"32106164","devOps":"10702053","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -130,8 +123,8 @@ func testMintBarQux100_2(t *testing.T) { fee100, // fee int32(-1000), // tickLower int32(1000), // tickUpper - "50", // amount0Desired - "50", // amount1Desired + "500", // amount0Desired + "500", // amount1Desired "1", // amount0Min "1", // amount1Min max_timeout, @@ -142,9 +135,6 @@ func testMintBarQux100_2(t *testing.T) { uassert.Equal(t, tokenId, uint64(2)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"127","time":"1234567898","gns":{"staker":"42808219","devOps":"14269404","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -159,34 +149,41 @@ func testStakeToken_1_2(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(2)) StakeToken(2) - gpi := getPrintInfo(t) - // {"height":"128","time":"1234567900","gns":{"staker":"53510274","devOps":"17836755","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"},{"lpTokenId":"2","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - std.TestSkipHeights(1) }) } -func testNow(t *testing.T) { - t.Run("now", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - gpi := getPrintInfo(t) - // {"height":"129","time":"1234567902","gns":{"staker":"64212329","devOps":"21404106","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"1","fullAmount":"10702052","ratio":"30","warmUpAmount":"3210615","full30":"10702052","give30":"3210615","penalty30":"7491437","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"},{"lpTokenId":"2","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"1","fullAmount":"1","ratio":"30","warmUpAmount":"0","full30":"1","give30":"0","penalty30":"1","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} +func testCollectRewardBoth(t *testing.T) { + // reward per block 10702054 - std.TestSkipHeights(1) - }) -} + // total staked liquidity = 10252593386 + // > position-01: 10252583134 // ratio 99.9999000058% + // > 10702054 * 99.9999000058% = 10702043.2985667191 + // > warm up = 10702043.2985667191 * 30% = 3210612.9895700157 -func testCollectRewardBoth(t *testing.T) { - t.Run("collect reward for position 01 and 02", func(t *testing.T) { + // > position-02: 10252 // ratio 0.0000999942% + // > 10702054 * 0.0000999942% = 10.7014332809 + // > warm up = 10.7014332809 * 30% = 3.2104299843 + t.Run("collect reward for position 01", func(t *testing.T) { std.TestSetRealm(adminRealm) + beforeGns := gns.BalanceOf(admin) CollectReward(1, false) - CollectReward(2, false) + newGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(newGns-beforeGns, 3210614)) + // reward 3210612 + // penalty 7491431 + // total 10702043 + }) - gpi := getPrintInfo(t) - // {"height":"130","time":"1234567904","gns":{"staker":"53510277","devOps":"24971457","communityPool":"14982876","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000006421231"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"2","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"},{"lpTokenId":"2","stakedHeight":"128","stakedTimestamp":"1234567900","stakedDuration":"2","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + t.Run("collect reward for position 02", func(t *testing.T) { + std.TestSetRealm(adminRealm) - std.TestSkipHeights(1) + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + newGns := gns.BalanceOf(admin) + // reward 3 + // penalty 7 + // total 10 }) } diff --git a/staker/__TEST_staker_short_warmup_period_internal_03_change_tier_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_03_change_tier_test.gnoA index 9d39af86f..fca66bef6 100644 --- a/staker/__TEST_staker_short_warmup_period_internal_03_change_tier_test.gnoA +++ b/staker/__TEST_staker_short_warmup_period_internal_03_change_tier_test.gnoA @@ -31,9 +31,7 @@ func TestShortWarmUpChangeTier(t *testing.T) { testStakeToken_1(t) testSetPoolTier(t) testStakeToken_2(t) - testNow(t) testChangePoolTier(t) - testNow2(t) } func testInit(t *testing.T) { @@ -43,7 +41,6 @@ func testInit(t *testing.T) { // init pool tiers // tier 1 deletePoolTier(t, MUST_EXISTS_IN_TIER_1) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) std.TestSkipHeights(1) // override warm-up period for testing @@ -84,6 +81,8 @@ func testCreatePool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) + pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") std.TestSkipHeights(1) @@ -115,9 +114,6 @@ func testMintBarQux100_1(t *testing.T) { uassert.Equal(t, tokenId, uint64(1)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"126","time":"1234567896","gns":{"staker":"32106164","devOps":"10702053","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -147,8 +143,6 @@ func testMintBarBaz100_2(t *testing.T) { uassert.Equal(t, tokenId, uint64(2)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"127","time":"1234567898","gns":{"staker":"42808219","devOps":"14269404","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} std.TestSkipHeights(1) }) } @@ -157,9 +151,6 @@ func testSkip100Height(t *testing.T) { t.Run("skip 100 heights", func(t *testing.T) { std.TestSkipHeights(100) - gpi := getPrintInfo(t) - // {"height":"228","time":"1234568100","gns":{"staker":"1123715724","devOps":"374571905","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -171,9 +162,6 @@ func testStakeToken_1(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(1)) StakeToken(1) - gpi := getPrintInfo(t) - // {"height":"229","time":"1234568102","gns":{"staker":"1134417779","devOps":"378139256","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - std.TestSkipHeights(1) }) } @@ -184,9 +172,7 @@ func testSetPoolTier(t *testing.T) { std.TestSetRealm(adminRealm) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 2) - gpi := getPrintInfo(t) - // {"height":"330","time":"1234568304","gns":{"staker":"2215325284","devOps":"738441757","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"101","fullAmount":"1080907453","ratio":"30","warmUpAmount":"324272236","full30":"1080907453","give30":"324272236","penalty30":"756635217","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 2) std.TestSkipHeights(1) }) } @@ -198,39 +184,51 @@ func testStakeToken_2(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(2)) StakeToken(2) - gpi := getPrintInfo(t) - // {"height":"331","time":"1234568306","gns":{"staker":"2226027339","devOps":"742009108","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"102","fullAmount":"764126573","ratio":"30","warmUpAmount":"229237972","full30":"764126573","give30":"229237972","penalty30":"534888601","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} std.TestSkipHeights(1) }) -} -func testNow(t *testing.T) { - t.Run("now", func(t *testing.T) { + t.Run("collect reward when tier is 2", func(t *testing.T) { std.TestSetRealm(adminRealm) - gpi := getPrintInfo(t) - // {"height":"332","time":"1234568308","gns":{"staker":"2236729394","devOps":"745576459","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"1","fullAmount":"3210615","ratio":"30","warmUpAmount":"963184","full30":"3210615","give30":"963184","penalty30":"2247431","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"103","fullAmount":"771618010","ratio":"30","warmUpAmount":"231485403","full30":"771618010","give30":"231485403","penalty30":"540132607","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 963184)) + // reward 963184 + // penalty 2247431 + // total 3210615 + + // reward per block 10702054 + // tier2 will have 30% = 3210616.2 + // warm up 30% = 963184.86 std.TestSkipHeights(1) }) } func testChangePoolTier(t *testing.T) { - t.Run("change pool tier", func(t *testing.T) { + t.Run("change pool tier to 1", func(t *testing.T) { std.TestSetRealm(adminRealm) - changePoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 1) - - gpi := getPrintInfo(t) - // {"height":"333","time":"1234568310","gns":{"staker":"2247431449","devOps":"749143810","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"1","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"2","fullAmount":"6421231","ratio":"30","warmUpAmount":"1926369","full30":"6421231","give30":"1926369","penalty30":"4494862","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"2","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"104","fullAmount":"779109447","ratio":"30","warmUpAmount":"233732834","full30":"779109447","give30":"233732834","penalty30":"545376613","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - - std.TestSkipHeights(1) + ChangePoolTier(`gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 1) + CollectReward(2, false) }) -} -func testNow2(t *testing.T) { - std.TestSetRealm(adminRealm) + t.Run("check reward when tier is 1", func(t *testing.T) { + std.TestSkipHeights(1) + std.TestSetRealm(adminRealm) - gpi := getPrintInfo(t) - // {"height":"334","time":"1234568312","gns":{"staker":"2258133504","devOps":"752711161","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"1","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"3","fullAmount":"5351026","ratio":"30","warmUpAmount":"1605308","full30":"5351026","give30":"1605308","penalty30":"3745718","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"2","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"105","fullAmount":"399721625","ratio":"30","warmUpAmount":"119916487","full30":"399721625","give30":"119916487","penalty30":"279805138","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 1605308)) + // reward 1605307 + // penalty 3745719 + // total 5351026 + + // reward per block 10702054 + // 2 pool exists in tier 1 + // each pool will have 10702054 / 2 = 5351027 + // warm up 30% = 5351027 * 30% = 1605308.1 + }) } diff --git a/staker/__TEST_staker_short_warmup_period_internal_04_remove_tier_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_04_remove_tier_test.gnoA index f1084a7a8..a468dfd70 100644 --- a/staker/__TEST_staker_short_warmup_period_internal_04_remove_tier_test.gnoA +++ b/staker/__TEST_staker_short_warmup_period_internal_04_remove_tier_test.gnoA @@ -27,13 +27,10 @@ func TestShortWarmUpRemoveTier(t *testing.T) { testPoolInitCreatePool(t) testMintBarQux100_1(t) testMintBarBaz100_2(t) - testSkip100Height(t) testStakeToken_1(t) testSetPoolTier(t) testStakeToken_2(t) - testNow(t) testRemovePoolTier(t) - testNow2(t) } func testInit(t *testing.T) { @@ -43,7 +40,6 @@ func testInit(t *testing.T) { // init pool tiers // tier 1 deletePoolTier(t, MUST_EXISTS_IN_TIER_1) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) std.TestSkipHeights(1) // override warm-up period for testing @@ -85,6 +81,8 @@ func testPoolInitCreatePool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) + pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") std.TestSkipHeights(1) @@ -116,9 +114,6 @@ func testMintBarQux100_1(t *testing.T) { uassert.Equal(t, tokenId, uint64(1)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"126","time":"1234567896","gns":{"staker":"32106164","devOps":"10702053","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -148,20 +143,6 @@ func testMintBarBaz100_2(t *testing.T) { uassert.Equal(t, tokenId, uint64(2)) uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - gpi := getPrintInfo(t) - // {"height":"127","time":"1234567898","gns":{"staker":"42808219","devOps":"14269404","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - - std.TestSkipHeights(1) - }) -} - -func testSkip100Height(t *testing.T) { - t.Run("skip 100 heights", func(t *testing.T) { - std.TestSkipHeights(100) - - gpi := getPrintInfo(t) - // {"height":"228","time":"1234568100","gns":{"staker":"1123715724","devOps":"374571905","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[]}]} - std.TestSkipHeights(1) }) } @@ -173,9 +154,6 @@ func testStakeToken_1(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(1)) StakeToken(1) - gpi := getPrintInfo(t) - // {"height":"229","time":"1234568102","gns":{"staker":"1134417779","devOps":"378139256","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - std.TestSkipHeights(1) }) } @@ -185,10 +163,7 @@ func testSetPoolTier(t *testing.T) { std.TestSkipHeights(100) // this reward should go to bar:qux:100 std.TestSetRealm(adminRealm) - addPoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", 2) - - gpi := getPrintInfo(t) - // {"height":"330","time":"1234568304","gns":{"staker":"2215325284","devOps":"738441757","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"101","fullAmount":"1080907453","ratio":"30","warmUpAmount":"324272236","full30":"1080907453","give30":"324272236","penalty30":"756635217","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + SetPoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`, 2) std.TestSkipHeights(1) }) @@ -201,40 +176,47 @@ func testStakeToken_2(t *testing.T) { gnft.Approve(consts.STAKER_ADDR, tid(2)) StakeToken(2) - gpi := getPrintInfo(t) - // {"height":"331","time":"1234568306","gns":{"staker":"2226027339","devOps":"742009108","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"0","fullAmount":"0","ratio":"30","warmUpAmount":"0","full30":"0","give30":"0","penalty30":"0","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"102","fullAmount":"764126573","ratio":"30","warmUpAmount":"229237972","full30":"764126573","give30":"229237972","penalty30":"534888601","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - std.TestSkipHeights(1) - }) -} + // clear reward + CollectReward(1, false) + CollectReward(2, false) -func testNow(t *testing.T) { - t.Run("now", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - gpi := getPrintInfo(t) - // {"height":"332","time":"1234568308","gns":{"staker":"2236729394","devOps":"745576459","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"2","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"1","fullAmount":"3210615","ratio":"30","warmUpAmount":"963184","full30":"3210615","give30":"963184","penalty30":"2247431","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"103","fullAmount":"771618010","ratio":"30","warmUpAmount":"231485403","full30":"771618010","give30":"231485403","penalty30":"540132607","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} std.TestSkipHeights(1) }) } func testRemovePoolTier(t *testing.T) { - t.Run("remove pool tier", func(t *testing.T) { + t.Run("check reward for position 01", func(t *testing.T) { std.TestSetRealm(adminRealm) - deletePoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000") - - gpi := getPrintInfo(t) - // {"height":"333","time":"1234568310","gns":{"staker":"2247431449","devOps":"749143810","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"0","numPoolSameTier":"0","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"2","fullAmount":"6421231","ratio":"30","warmUpAmount":"1926369","full30":"6421231","give30":"1926369","penalty30":"4494862","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"104","fullAmount":"779109447","ratio":"30","warmUpAmount":"233732834","full30":"779109447","give30":"233732834","penalty30":"545376613","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} - std.TestSkipHeights(1) + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) // position 01 is in tier1 pool + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 2247431)) + // reward 2247430 + // penalty 5244006 + // total 7491436 + + // reward per block 10702054 + // tier1 will have 70% = 7491437.8 + // > warm up 30% = 2247431.34 + // tier2 will have 30% = 3210616.2 }) -} -func testNow2(t *testing.T) { - t.Run("now 2", func(t *testing.T) { + t.Run("remove pool tier", func(t *testing.T) { std.TestSetRealm(adminRealm) - - gpi := getPrintInfo(t) - // {"height":"334","time":"1234568312","gns":{"staker":"2258133504","devOps":"752711161","communityPool":"0","govStaker":"0","protocolFee":"0","GnoswapAdmin":"100000000000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"0","numPoolSameTier":"0","position":[{"lpTokenId":"2","stakedHeight":"331","stakedTimestamp":"1234568306","stakedDuration":"3","fullAmount":"6421231","ratio":"30","warmUpAmount":"1926369","full30":"6421231","give30":"1926369","penalty30":"4494862","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"229","stakedTimestamp":"1234568102","stakedDuration":"105","fullAmount":"799443352","ratio":"30","warmUpAmount":"239833005","full30":"799443352","give30":"239833005","penalty30":"559610347","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]} + RemovePoolTierByAdmin(`gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000`) std.TestSkipHeights(1) + // tier2 pool has been removed, only 1 pool exist in tier 1 + + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) // position 01 is in tier1 pool + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 3210616)) + // reward 3210615 + // penalty 7491438 + // total 10702053 + + // block reward per pool 10702054 + // warm up 30% = 3210616.2 }) } diff --git a/staker/__TEST_staker_short_warmup_period_internal_05_collect_rewards_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_05_collect_rewards_test.gnoA deleted file mode 100644 index c66e48aab..000000000 --- a/staker/__TEST_staker_short_warmup_period_internal_05_collect_rewards_test.gnoA +++ /dev/null @@ -1,288 +0,0 @@ -package staker - -import ( - "math" - "std" - "testing" - - "gno.land/p/demo/uassert" - - "gno.land/r/gnoswap/v1/consts" - - en "gno.land/r/gnoswap/v1/emission" - pl "gno.land/r/gnoswap/v1/pool" - pn "gno.land/r/gnoswap/v1/position" - - "gno.land/r/gnoswap/v1/gnft" - "gno.land/r/gnoswap/v1/gns" - - "gno.land/r/onbloc/bar" - "gno.land/r/onbloc/baz" - "gno.land/r/onbloc/qux" -) - -func TestShortWarmUpInternalCollectRewards(t *testing.T) { - testInit(t) - testDoubleMint(t) - testCreatePool(t) - testMintBarQux100_1(t) - testMintBarBaz100_2(t) - testStakeToken_1(t) - testSetPoolTier(t) - testStakeToken_2(t) - testCollect1_1(t) - testCollect1_2(t) - testCollect1_3(t) - testCollect1_4(t) - testCollect2_1(t) - testCollectAll_1(t) - testCollectNow(t) - testCollectSameBlock(t) - testCollectAfterSingleBlock(t) -} - -func testInit(t *testing.T) { - t.Run("init pool tiers", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - // init pool tiers - // tier 1 - deletePoolTier(t, MUST_EXISTS_IN_TIER_1) - addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1) - std.TestSkipHeights(1) - - // override warm-up period for testing - changeWarmup(t, 0, 150) - changeWarmup(t, 1, 300) - changeWarmup(t, 2, 900) - changeWarmup(t, 3, math.MaxInt64) - - // set unstaking fee to 0 - SetUnstakingFeeByAdmin(0) - - // set pool creation fee to 0 - pl.SetPoolCreationFeeByAdmin(0) - - // set community pool distribution to 0% (give it to devOps) - en.ChangeDistributionPctByAdmin( - 1, 7500, - 2, 2500, - 3, 0, - 4, 0, - ) - }) -} - -func testDoubleMint(t *testing.T) { - t.Run("double mint", func(t *testing.T) { - en.MintAndDistributeGns() - en.MintAndDistributeGns() - - std.TestSkipHeights(1) - }) -} - -func testCreatePool(t *testing.T) { - t.Run("create pool", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) - - pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") - pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337") - - std.TestSkipHeights(1) - }) -} - -func testMintBarQux100_1(t *testing.T) { - - t.Run("mint position 01, bar:qux:100", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) - qux.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) - - tokenId, liquidity, amount0, amount1 := pn.Mint( - barPath, // token0 - quxPath, // token1 - fee100, // fee - int32(-1000), // tickLower - int32(1000), // tickUpper - "50", // amount0Desired - "50", // amount1Desired - "1", // amount0Min - "1", // amount1Min - max_timeout, - adminAddr, - adminAddr, - ) - - uassert.Equal(t, tokenId, uint64(1)) - uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - - gpi := getPrintInfo(t) - // uassert.Equal(t, gpi, `{"height":126,"time":1234567896,"gns":{"staker":0,"devOps":8561643,"communityPool":34246574,"govStaker":0,"protocolFee":200000000,"GnoswapAdmin":99999800000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) - - std.TestSkipHeights(1) - }) -} - -func testMintBarBaz100_2(t *testing.T) { - t.Run("mint position 02, bar:baz:3000", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) - baz.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX) - - tokenId, liquidity, amount0, amount1 := pn.Mint( - barPath, // token0 - bazPath, // token1 - fee3000, // fee - int32(-1020), // tickLower - int32(1020), // tickUpper - "50", // amount0Desired - "50", // amount1Desired - "1", // amount0Min - "1", // amount1Min - max_timeout, - adminAddr, - adminAddr, - ) - - uassert.Equal(t, tokenId, uint64(2)) - uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr) - - std.TestSkipHeights(1) - }) -} - -func testStakeToken_1(t *testing.T) { - t.Run("stake token 01", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - gnft.Approve(consts.STAKER_ADDR, tid(1)) - StakeToken(1) - - std.TestSkipHeights(1) - }) -} - -func testSetPoolTier(t *testing.T) { - t.Run("set pool tier", func(t *testing.T) { - - std.TestSkipHeights(800) // this reward should go to bar:qux:100 - - std.TestSetRealm(adminRealm) - addPoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", 2) - - std.TestSkipHeights(1) - }) -} - -func testStakeToken_2(t *testing.T) { - t.Run("stake token 02", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - gnft.Approve(consts.STAKER_ADDR, tid(2)) - StakeToken(2) - - std.TestSkipHeights(1) - }) -} - -func testCollect1_1(t *testing.T) { - t.Run("collect reward for position 01, 1st time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - - std.TestSkipHeights(5) - }) -} - -func testCollect1_2(t *testing.T) { - t.Run("collect reward for position 01, 2nd time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - - std.TestSkipHeights(500) - }) -} - -func testCollect1_3(t *testing.T) { - t.Run("collect reward for position 01, 3rd time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - - std.TestSkipHeights(50) - }) -} - -func testCollect1_4(t *testing.T) { - t.Run("collect reward for position 01, 4th time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - - std.TestSkipHeights(50) - }) -} - -func testCollect2_1(t *testing.T) { - t.Run("collect reward for position 02, 1st time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(2, false) - - std.TestSkipHeights(5) - }) -} - -func testCollectAll_1(t *testing.T) { - t.Run("collect reward for all positions, 1st time", func(t *testing.T) { - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - CollectReward(2, false) - - std.TestSkipHeights(5) - }) -} - -func testCollectNow(t *testing.T) { - t.Run("collect reward for position 01, now", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - }) -} - -func testCollectSameBlock(t *testing.T) { - t.Run("collect reward for position 01, same block", func(t *testing.T) { - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - }) -} - -func testCollectAfterSingleBlock(t *testing.T) { - t.Run("collect reward for position 01, after single block", func(t *testing.T) { - std.TestSkipHeights(1) - - std.TestSetRealm(adminRealm) - - CollectReward(1, false) - }) -} diff --git a/staker/__TEST_staker_short_warmup_period_internal_06_position_in_out_range_changed_by_swap_test.gnoA b/staker/__TEST_staker_short_warmup_period_internal_05_position_in_out_range_changed_by_swap_test.gnoA similarity index 50% rename from staker/__TEST_staker_short_warmup_period_internal_06_position_in_out_range_changed_by_swap_test.gnoA rename to staker/__TEST_staker_short_warmup_period_internal_05_position_in_out_range_changed_by_swap_test.gnoA index 99f976c08..55b93b1ad 100644 --- a/staker/__TEST_staker_short_warmup_period_internal_06_position_in_out_range_changed_by_swap_test.gnoA +++ b/staker/__TEST_staker_short_warmup_period_internal_05_position_in_out_range_changed_by_swap_test.gnoA @@ -1,9 +1,9 @@ package staker import ( + "math" "std" "testing" - "time" "gno.land/p/demo/uassert" @@ -29,20 +29,24 @@ func TestShortWarmUpInternalPositionInOutRangeChangedBySwap(t *testing.T) { testMintBarQux100_2(t) testStakeToken_1_2(t) testMakePosition1OutRange(t) - // testCheckRewardAfter1Block(t) + testCheckRewardAfter1Block(t) } func testInit(t *testing.T) { t.Run("initialize", func(t *testing.T) { - deletePoolTier(t, MUST_EXISTS_IN_TIER_1) + std.TestSetRealm(adminRealm) - addPoolTier(t, poolPath, 1) + deletePoolTier(t, MUST_EXISTS_IN_TIER_1) std.TestSkipHeights(1) - changeWarmup(t, 0, 901) - changeWarmup(t, 1, 301) - changeWarmup(t, 2, 151) - changeWarmup(t, 3, 1) + // override warm-up period for testing + changeWarmup(t, 0, 150) + changeWarmup(t, 1, 300) + changeWarmup(t, 2, 900) + changeWarmup(t, 3, math.MaxInt64) + + // set unstaking fee to 0 + SetUnstakingFeeByAdmin(0) }) } @@ -53,6 +57,7 @@ func testCreatePool(t *testing.T) { gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3) pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337") + SetPoolTierByAdmin(poolPath, 1) std.TestSkipHeights(1) }) @@ -79,13 +84,9 @@ func testMintBarQux100_1(t *testing.T) { adminAddr, adminAddr, ) + println(tokenId, liquidity) uassert.Equal(t, tokenId, uint64(1)) - // uassert.Equal(t, gnft.OwnerOf(tid(tokenId)), admin) - - // gpi := GetPrintInfo() - // uassert.Equal(t, gpi, `{"height":125,"time":1234567894,"gns":{"staker":0,"devOps":5707762,"communityPool":22831049,"govStaker":0,"protocolFee":100000000,"GnoswapAdmin":99999900000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) - std.TestSkipHeights(1) }) } @@ -111,13 +112,9 @@ func testMintBarQux100_2(t *testing.T) { adminAddr, adminAddr, ) + println(tokenId, liquidity) uassert.Equal(t, tokenId, uint64(2)) - // uassert.Equal(t, gnft.OwnerOf(tid(tokenId)), admin) - - // gpi := GetPrintInfo() - // uassert.Equal(t, gpi, `{"height":126,"time":1234567896,"gns":{"staker":0,"devOps":8561643,"communityPool":34246574,"govStaker":0,"protocolFee":100000000,"GnoswapAdmin":99999900000000},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","startTimestamp":1234567890,"tier":1,"numPoolSameTier":1,"poolReward":0,"position":[]}]}`) - std.TestSkipHeights(1) }) } @@ -133,10 +130,52 @@ func testStakeToken_1_2(t *testing.T) { StakeToken(2) std.TestSkipHeights(1) + + // clear reward + CollectReward(1, false) + CollectReward(2, false) + + std.TestSkipHeights(1) + }) + + /* + total staked liquidity: 1058618 + > position 01: 33360 || 3.1512783648% + > position 02: 1025258 || 96.8487216352% + + reward per block: 10702054 + > position 01: 10702054 * 3.1512783648% = 337251.512291213 + > warmUp 30% => 337251.512291213 * 30% = 101175.4536873639 + > position 02: 10702054 * 96.8487216352% = 10364802.487708787 + > warmUp 30% => 10364802.487708787 * 30% = 3109440.7463126361 + */ + + t.Run("collect reward position 01, while in-range", func(t *testing.T) { + std.TestSetRealm(adminRealm) + + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 101175)) + // reward 101175 + // penalty 236076 + // total 337251 + + }) + + t.Run("collect reward position 02, while in-range", func(t *testing.T) { + std.TestSetRealm(adminRealm) + + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + afterGns := gns.BalanceOf(admin) + uassert.True(t, isInErrorRange(afterGns-beforeGns, 3109440)) + // reward 3109440 + // penalty 7255362 + // total 10364802 }) } -// XXX func testMakePosition1OutRange(t *testing.T) { t.Run("make position 01 out of range", func(t *testing.T) { poolTick := pl.PoolGetSlot0Tick(poolPath) @@ -151,7 +190,6 @@ func testMakePosition1OutRange(t *testing.T) { bar.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX) qux.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX) - // PANIC: ./staker: test pkg: panic: runtime error: invalid memory address or nil pointer dereference tokenIn, tokenOut := rr.ExactInSwapRoute( barPath, quxPath, @@ -159,40 +197,38 @@ func testMakePosition1OutRange(t *testing.T) { "gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100", "100", "0", - time.Now().Unix()+100, - // max_timeout, + max_timeout, ) uassert.Equal(t, tokenIn, "10000") uassert.Equal(t, tokenOut, "-9884") std.TestSkipHeights(1) + + // position-01 became out-range + // position-01 is only in-range position }) } -// XXX func testCheckRewardAfter1Block(t *testing.T) { - // t.Run("check reward after 1 block", func(t *testing.T) { - // poolTick := pl.PoolGetSlot0Tick(poolPath) - // uassert.Equal(t, poolTick, int32(-194)) - // // AT THIS POINT position #1 is out of range - - // lpToken01Rewards := ApiGetRewardsByLpTokenId(1) - // uassert.Equal(t, lpToken01Rewards, `{"stat":{"height":129,"timestamp":1234567902},"response":[{"lpTokenId":1,"address":"g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d","rewards":[{"incentiveType":"INTERNAL","incentiveId":"","targetPoolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","rewardTokenPath":"gno.land/r/gnoswap/v1/gns","rewardTokenAmount":101175,"stakeTimestamp":1234567898,"stakeHeight":127,"incentiveStart":1234567898}]}]}`) + t.Run("check reward position 01, out-range", func(t *testing.T) { + std.TestSetRealm(adminRealm) - // lpToken02Rewards := ApiGetRewardsByLpTokenId(2) - // uassert.Equal(t, lpToken02Rewards, `{"stat":{"height":129,"timestamp":1234567902},"response":[{"lpTokenId":2,"address":"g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d","rewards":[{"incentiveType":"INTERNAL","incentiveId":"","targetPoolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","rewardTokenPath":"gno.land/r/gnoswap/v1/gns","rewardTokenAmount":6320056,"stakeTimestamp":1234567898,"stakeHeight":127,"incentiveStart":1234567898}]}]}`) + beforeGns := gns.BalanceOf(admin) + CollectReward(1, false) + afterGns := gns.BalanceOf(admin) + uassert.Equal(t, uint64(0), afterGns-beforeGns) // out range has no reward + }) - // POSITION #1 PREVIOUS REWARD - // `{"stat":{"height":128,"timestamp":1234567900},"response":[{"lpTokenId":1,"address":"g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d","rewards":[{"incentiveType":"INTERNAL","incentiveId":"","targetPoolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","rewardTokenPath":"gno.land/r/gnoswap/v1/gns","rewardTokenAmount":101175,"stakeTimestamp":1234567898,"stakeHeight":127,"incentiveStart":1234567898}]}]}`) + t.Run("check reward position 02, in-range", func(t *testing.T) { + std.TestSetRealm(adminRealm) - // POSITION #2 PREVIOUS REWARD - // `{"stat":{"height":128,"timestamp":1234567900},"response":[{"lpTokenId":2,"address":"g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d","rewards":[{"incentiveType":"INTERNAL","incentiveId":"","targetPoolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","rewardTokenPath":"gno.land/r/gnoswap/v1/gns","rewardTokenAmount":3109440,"stakeTimestamp":1234567898,"stakeHeight":127,"incentiveStart":1234567898}]}]}`) + beforeGns := gns.BalanceOf(admin) + CollectReward(2, false) + afterGns := gns.BalanceOf(admin) + // reward 3210615 + // penalty 7491438 + // total 10702053 - /* - PREVIOUS REWARD -> NOW - - POSITION #1 - 101175 > 101175 - - POSITION #2 - 3109440 > 6320056 - */ - // }) + // since position-01 has become out-range, position-02 is the only in-range position + // so position-02 will get entire block reward + }) }