Skip to content

Commit 0402512

Browse files
committed
fixme: new emission pool reward being 0
1 parent 51c1813 commit 0402512

File tree

1 file changed

+197
-76
lines changed

1 file changed

+197
-76
lines changed

staker/__TEST_staker_short_warmup_period_internal_01_test.gno

Lines changed: 197 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func TestShortWarmUpInternal(t *testing.T) {
3131
testMintBarBaz100Pos02(t)
3232
testStakeTokenPos01(t)
3333
checkReward(t)
34-
// testSetPoolTier(t)
35-
// testStakeTokenPos02(t)
34+
testSetPoolTier(t)
35+
testStakeTokenPos02(t)
3636
}
3737

3838
func testInit(t *testing.T) {
@@ -150,14 +150,14 @@ func testStakeTokenPos01(t *testing.T) {
150150
StakeToken(1)
151151
std.TestSkipHeights(1)
152152

153-
expected := `{"height":"128","time":"1234567915","gns":{"staker":"42808219","devOps":"14269404","communityPool":"0","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999800000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"127","stakedTimestamp":"1234567910","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"}]}]}`
153+
expected := `{"height":"128","time":"1234567915","gns":{"staker":"53510274","devOps":"17836755","communityPool":"0","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999800000000"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"127","stakedTimestamp":"1234567910","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"}]}]}`
154154
/*
155155
{
156156
"height": "128",
157157
"time": "1234567915",
158158
"gns": {
159-
"staker": "42808219",
160-
"devOps": "14269404",
159+
"staker": "53510274",
160+
"devOps": "17836755",
161161
"communityPool": "0",
162162
"govStaker": "0",
163163
"protocolFee": "200000000",
@@ -222,27 +222,123 @@ func checkReward(t *testing.T) {
222222
uassert.True(t, isInErrorRange(communityPoolDiff, 7491437))
223223
})
224224

225-
t.Run("check reward after collecting", func(t *testing.T) {
225+
t.Run("check reward after collecting (same block)", func(t *testing.T) {
226226
std.TestSetRealm(adminRealm)
227227

228-
std.TestSkipHeights(1)
228+
expected := `{"height":"128","time":"1234567915","gns":{"staker":"42808221","devOps":"17836755","communityPool":"7491437","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999803210616"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"127","stakedTimestamp":"1234567910","stakedDuration":"1","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"}]}]}`
229229
internalRewards := getPrintInfo(t)
230-
println(internalRewards)
230+
uassert.Equal(t, internalRewards, expected)
231+
/*
232+
{
233+
"height": "128",
234+
"time": "1234567915",
235+
"gns": {
236+
"staker": "42808221",
237+
"devOps": "17836755",
238+
"communityPool": "7491437",
239+
"govStaker": "0",
240+
"protocolFee": "200000000",
241+
"GnoswapAdmin": "99999803210616"
242+
},
243+
"pool": [
244+
{
245+
"poolPath": "gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100",
246+
"tier": "1",
247+
"numPoolSameTier": "1",
248+
"position": [
249+
{
250+
"lpTokenId": "1",
251+
"stakedHeight": "127",
252+
"stakedTimestamp": "1234567910",
253+
"stakedDuration": "1",
254+
"fullAmount": "0",
255+
"ratio": "30",
256+
"warmUpAmount": "0",
257+
"full30": "0",
258+
"give30": "0",
259+
"penalty30": "0",
260+
"full50": "0",
261+
"give50": "0",
262+
"penalty50": "0",
263+
"full70": "0",
264+
"give70": "0",
265+
"penalty70": "0",
266+
"full100": "0",
267+
"give100": "0",
268+
"penalty100": "0"
269+
}
270+
]
271+
}
272+
]
273+
}
274+
*/
275+
276+
beforeUserGnsBalance := gns.BalanceOf(admin)
277+
beforeCommunityPoolGnsBalance := gns.BalanceOf(a2u(consts.COMMUNITY_POOL_ADDR))
231278

232-
// TODO:
233-
// panic("need to fix, collect reward keeps remaining")
234-
t.Skip("need to fix, collect reward keeps remaining")
279+
// collect reward requested in same block
280+
// no reward should be collected
281+
CollectReward(1, false)
235282

236-
// beforeUserGnsBalance := gns.BalanceOf(admin)
237-
// beforeCommunityPoolGnsBalance := gns.BalanceOf(a2u(consts.COMMUNITY_POOL_ADDR))
283+
afterUserGnsBalance := gns.BalanceOf(admin)
284+
afterCommunityPoolGnsBalance := gns.BalanceOf(a2u(consts.COMMUNITY_POOL_ADDR))
238285

239-
// CollectReward(1, false)
286+
uassert.Equal(t, afterUserGnsBalance, beforeUserGnsBalance)
287+
uassert.Equal(t, afterCommunityPoolGnsBalance, beforeCommunityPoolGnsBalance)
288+
289+
})
240290

241-
// afterUserGnsBalance := gns.BalanceOf(admin)
242-
// afterCommunityPoolGnsBalance := gns.BalanceOf(a2u(consts.COMMUNITY_POOL_ADDR))
291+
t.Run("check reward after collecting (next block)", func(t *testing.T) {
292+
std.TestSetRealm(adminRealm)
293+
std.TestSkipHeights(1)
243294

244-
// userDiff := afterUserGnsBalance - beforeUserGnsBalance
245-
// communityPoolDiff := afterCommunityPoolGnsBalance - beforeCommunityPoolGnsBalance
295+
expected := `{"height":"129","time":"1234567920","gns":{"staker":"53510276","devOps":"21404106","communityPool":"7491437","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999803210616"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"127","stakedTimestamp":"1234567910","stakedDuration":"2","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"}]}]}`
296+
internalRewards := getPrintInfo(t)
297+
uassert.Equal(t, internalRewards, expected)
298+
/*
299+
{
300+
"height": "129",
301+
"time": "1234567920",
302+
"gns": {
303+
"staker": "53510276",
304+
"devOps": "21404106",
305+
"communityPool": "7491437",
306+
"govStaker": "0",
307+
"protocolFee": "200000000",
308+
"GnoswapAdmin": "99999803210616"
309+
},
310+
"pool": [
311+
{
312+
"poolPath": "gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100",
313+
"tier": "1",
314+
"numPoolSameTier": "1",
315+
"position": [
316+
{
317+
"lpTokenId": "1",
318+
"stakedHeight": "127",
319+
"stakedTimestamp": "1234567910",
320+
"stakedDuration": "2",
321+
"fullAmount": "10702053",
322+
"ratio": "30",
323+
"warmUpAmount": "3210616",
324+
"full30": "10702053",
325+
"give30": "3210616",
326+
"penalty30": "7491437",
327+
"full50": "0",
328+
"give50": "0",
329+
"penalty50": "0",
330+
"full70": "0",
331+
"give70": "0",
332+
"penalty70": "0",
333+
"full100": "0",
334+
"give100": "0",
335+
"penalty100": "0"
336+
}
337+
]
338+
}
339+
]
340+
}
341+
*/
246342
})
247343
}
248344

@@ -252,16 +348,16 @@ func testSetPoolTier(t *testing.T) {
252348
addPoolTier(t, "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", 2)
253349
std.TestSkipHeights(1)
254350

255-
// reward check
351+
expected := `{"height":"130","time":"1234567925","gns":{"staker":"64212331","devOps":"24971457","communityPool":"7491437","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999803210616"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"1","position":[]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100","tier":"1","numPoolSameTier":"1","position":[{"lpTokenId":"1","stakedHeight":"127","stakedTimestamp":"1234567910","stakedDuration":"3","fullAmount":"18193490","ratio":"30","warmUpAmount":"5458047","full30":"18193490","give30":"5458047","penalty30":"12735443","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]}`
256352
internalRewards := getPrintInfo(t)
257-
println(internalRewards)
353+
uassert.Equal(t, internalRewards, expected)
258354
/*
259355
{
260356
"height": "130",
261357
"time": "1234567925",
262358
"gns": {
263-
"staker": "42808221",
264-
"devOps": "17836755",
359+
"staker": "64212331",
360+
"devOps": "24971457",
265361
"communityPool": "7491437",
266362
"govStaker": "0",
267363
"protocolFee": "200000000",
@@ -284,12 +380,12 @@ func testSetPoolTier(t *testing.T) {
284380
"stakedHeight": "127",
285381
"stakedTimestamp": "1234567910",
286382
"stakedDuration": "3",
287-
"fullAmount": "28895544",
383+
"fullAmount": "18193490",
288384
"ratio": "30",
289-
"warmUpAmount": "8668663",
290-
"full30": "28895544",
291-
"give30": "8668663",
292-
"penalty30": "20226881",
385+
"warmUpAmount": "5458047",
386+
"full30": "18193490",
387+
"give30": "5458047",
388+
"penalty30": "12735443",
293389
"full50": "0",
294390
"give50": "0",
295391
"penalty50": "0",
@@ -317,56 +413,81 @@ func testStakeTokenPos02(t *testing.T) {
317413
StakeToken(2)
318414
std.TestSkipHeights(10)
319415

320-
// CollectReward(1, false)
321-
// CollectReward(2, false)
322-
323-
// gpi := getPrintInfo()
324-
// uassert.Equal(t, gpi, `{"height":130,"time":1234567904,"gns":{"staker":18193494,"devOps":19977167,"communityPool":61715180,"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":18193493,"position":[{"lpTokenId":1,"stakedHeight":128,"stakedTimestamp":1234567900,"stakedDuration":2,"fullAmount":18193493,"ratio":30,"warmUpAmount":5458047,"full30":18193493,"give30":5458047,"full50":0,"give50":0,"full70":0,"give70":0,"full100":0}]},{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","startTimestamp":1234567902,"tier":2,"numPoolSameTier":1,"poolReward":0,"position":[{"lpTokenId":2,"stakedHeight":130,"stakedTimestamp":1234567904,"stakedDuration":0,"fullAmount":0,"ratio":0,"warmUpAmount":0,"full30":0,"give30":0,"full50":0,"give50":0,"full70":0,"give70":0,"full100":0}]}]}`)
325-
326-
// std.TestSkipHeights(1)
327-
416+
expected := `{"height":"140","time":"1234567975","gns":{"staker":"171232876","devOps":"60644972","communityPool":"7491437","govStaker":"0","protocolFee":"200000000","GnoswapAdmin":"99999803210616"},"pool":[{"poolPath":"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000","tier":"2","numPoolSameTier":"1","position":[{"lpTokenId":"2","stakedHeight":"130","stakedTimestamp":"1234567925","stakedDuration":"10","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":"127","stakedTimestamp":"1234567910","stakedDuration":"13","fullAmount":"93107860","ratio":"30","warmUpAmount":"27932358","full30":"93107860","give30":"27932358","penalty30":"65175502","full50":"0","give50":"0","penalty50":"0","full70":"0","give70":"0","penalty70":"0","full100":"0","give100":"0","penalty100":"0"}]}]}`
417+
internalRewards := getPrintInfo(t)
418+
uassert.Equal(t, internalRewards, expected)
419+
panic("fix position02 reward calculation (must have certain amount but 0 calculated)")
328420
/*
329-
소문자
330-
calcPositionReward
331-
332-
웜업별
333-
- 리워드
334-
- 페널티
335-
- 익스터널 리워드
336-
- 익스터널 페널티
337-
- 마지막 시점부터
421+
{
422+
"height": "140",
423+
"time": "1234567975",
424+
"gns": {
425+
"staker": "171232876",
426+
"devOps": "60644972",
427+
"communityPool": "7491437",
428+
"govStaker": "0",
429+
"protocolFee": "200000000",
430+
"GnoswapAdmin": "99999803210616"
431+
},
432+
"pool": [
433+
{
434+
"poolPath": "gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000",
435+
"tier": "2",
436+
"numPoolSameTier": "1",
437+
"position": [
438+
{
439+
"lpTokenId": "2",
440+
"stakedHeight": "130",
441+
"stakedTimestamp": "1234567925",
442+
"stakedDuration": "10",
443+
"fullAmount": "0",
444+
"ratio": "30",
445+
"warmUpAmount": "0",
446+
"full30": "0",
447+
"give30": "0",
448+
"penalty30": "0",
449+
"full50": "0",
450+
"give50": "0",
451+
"penalty50": "0",
452+
"full70": "0",
453+
"give70": "0",
454+
"penalty70": "0",
455+
"full100": "0",
456+
"give100": "0",
457+
"penalty100": "0"
458+
}
459+
]
460+
},
461+
{
462+
"poolPath": "gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100",
463+
"tier": "1",
464+
"numPoolSameTier": "1",
465+
"position": [
466+
{
467+
"lpTokenId": "1",
468+
"stakedHeight": "127",
469+
"stakedTimestamp": "1234567910",
470+
"stakedDuration": "13",
471+
"fullAmount": "93107860",
472+
"ratio": "30",
473+
"warmUpAmount": "27932358",
474+
"full30": "93107860",
475+
"give30": "27932358",
476+
"penalty30": "65175502",
477+
"full50": "0",
478+
"give50": "0",
479+
"penalty50": "0",
480+
"full70": "0",
481+
"give70": "0",
482+
"penalty70": "0",
483+
"full100": "0",
484+
"give100": "0",
485+
"penalty100": "0"
486+
}
487+
]
488+
}
489+
]
490+
}
338491
*/
339-
340-
// std.TestSkipHeights(1)
341-
// calcPositionReward(uint64(std.GetHeight()), 1)
342492
})
343-
344-
t.Run("check reward for position 01", func(t *testing.T) {
345-
std.TestSetRealm(adminRealm)
346-
347-
resStr := getPrintInfo(t)
348-
println(resStr)
349-
350-
// rewards := calcPositionRewardByWarmups(uint64(std.GetHeight()), 1)
351-
// // for _, reward := range rewards {
352-
// // println("total internal", reward.Internal)
353-
// // println("total internal penalty", reward.InternalPenalty)
354-
// // println("total external", reward.External)
355-
// // println("total external penalty", reward.ExternalPenalty)
356-
// // println()
357-
// // }
358-
})
359-
360-
// t.Run("check reward for position 02", func(t *testing.T) {
361-
// std.TestSetRealm(adminRealm)
362-
363-
// rewards := calcPositionRewardByWarmups(uint64(std.GetHeight()), 2)
364-
// // for _, reward := range rewards {
365-
// // println("total internal", reward.Internal)
366-
// // println("total internal penalty", reward.InternalPenalty)
367-
// // println("total external", reward.External)
368-
// // println("total external penalty", reward.ExternalPenalty)
369-
// // println()
370-
// // }
371-
// })
372493
}

0 commit comments

Comments
 (0)