Skip to content

Commit

Permalink
test(fix): fix internal gnoA
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Jan 19, 2025
1 parent 870009c commit 4a4b42b
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 476 deletions.
89 changes: 64 additions & 25 deletions staker/__TEST_staker_short_warmup_period_internal_01_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)
})
}
Expand All @@ -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)
})
Expand All @@ -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

})
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ func TestShortWarmUpInternalSmallLiq(t *testing.T) {
testMintBarQux100_1(t)
testMintBarQux100_2(t)
testStakeToken_1_2(t)
testNow(t)
testCollectRewardBoth(t)
}

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)
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
})
}
Expand All @@ -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,
Expand All @@ -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)
})
}
Expand All @@ -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
})
}
Loading

0 comments on commit 4a4b42b

Please sign in to comment.