Skip to content

Commit f58e271

Browse files
committed
Merge branch 'mconcat/refactor-emission-part-1' of https://github.com/gnoswap-labs/gnoswap into mconcat/refactor-emission-part-1
2 parents 951587e + b682b59 commit f58e271

File tree

2 files changed

+192
-220
lines changed

2 files changed

+192
-220
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package staker
2+
3+
import (
4+
"math"
5+
"std"
6+
"testing"
7+
8+
"gno.land/p/demo/uassert"
9+
10+
"gno.land/r/gnoswap/v1/consts"
11+
12+
en "gno.land/r/gnoswap/v1/emission"
13+
pl "gno.land/r/gnoswap/v1/pool"
14+
pn "gno.land/r/gnoswap/v1/position"
15+
16+
"gno.land/r/gnoswap/v1/gnft"
17+
"gno.land/r/gnoswap/v1/gns"
18+
19+
"gno.land/r/onbloc/bar"
20+
"gno.land/r/onbloc/qux"
21+
)
22+
23+
func TestShortWarmUpInternalSmallLiq(t *testing.T) {
24+
testInit(t)
25+
testDoubleMint(t)
26+
testCreatePool(t)
27+
testMintBarQux100_1(t)
28+
testMintBarQux100_2(t)
29+
testStakeToken_1_2(t)
30+
testNow(t)
31+
testCollectRewardBoth(t)
32+
}
33+
34+
func testInit(t *testing.T) {
35+
t.Run("init pool tiers", func(t *testing.T) {
36+
std.TestSetRealm(adminRealm)
37+
38+
// init pool tiers
39+
// tier 1
40+
deletePoolTier(t, MUST_EXISTS_IN_TIER_1)
41+
addPoolTier(t, `gno.land/r/onbloc/bar:gno.land/r/onbloc/qux:100`, 1)
42+
std.TestSkipHeights(1)
43+
44+
// override warm-up period for testing
45+
changeWarmup(t, 0, 150)
46+
changeWarmup(t, 1, 300)
47+
changeWarmup(t, 2, 900)
48+
changeWarmup(t, 3, math.MaxInt64)
49+
50+
// set unstaking fee to 0
51+
SetUnstakingFeeByAdmin(0)
52+
53+
// set pool creation fee to 0
54+
pl.SetPoolCreationFeeByAdmin(0)
55+
56+
// set community pool distribution to 0% (give it to devOps)
57+
en.ChangeDistributionPctByAdmin(
58+
1, 7500,
59+
2, 2500,
60+
3, 0,
61+
4, 0,
62+
)
63+
})
64+
}
65+
66+
func testDoubleMint(t *testing.T) {
67+
t.Run("mint and distribute gns", func(t *testing.T) {
68+
en.MintAndDistributeGns()
69+
en.MintAndDistributeGns()
70+
71+
std.TestSkipHeights(1)
72+
})
73+
}
74+
75+
func testCreatePool(t *testing.T) {
76+
t.Run("create pool", func(t *testing.T) {
77+
std.TestSetRealm(adminRealm)
78+
79+
gns.Approve(a2u(consts.POOL_ADDR), pl.GetPoolCreationFee()*3)
80+
81+
pl.CreatePool(barPath, quxPath, 100, "79228162514264337593543950337")
82+
pl.CreatePool(barPath, bazPath, 3000, "79228162514264337593543950337")
83+
84+
std.TestSkipHeights(1)
85+
})
86+
}
87+
88+
func testMintBarQux100_1(t *testing.T) {
89+
t.Run("mint position 01, bar:qux:100", func(t *testing.T) {
90+
std.TestSetRealm(adminRealm)
91+
92+
bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
93+
qux.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
94+
95+
tokenId, liquidity, amount0, amount1 := pn.Mint(
96+
barPath, // token0
97+
quxPath, // token1
98+
fee100, // fee
99+
int32(-1000), // tickLower
100+
int32(1000), // tickUpper
101+
"500000000", // amount0Desired
102+
"500000000", // amount1Desired
103+
"1", // amount0Min
104+
"1", // amount1Min
105+
max_timeout,
106+
adminAddr,
107+
adminAddr,
108+
)
109+
110+
uassert.Equal(t, tokenId, uint64(1))
111+
uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr)
112+
113+
gpi := getPrintInfo(t)
114+
// {"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":[]}]}
115+
116+
std.TestSkipHeights(1)
117+
})
118+
}
119+
120+
func testMintBarQux100_2(t *testing.T) {
121+
t.Run("mint position 02, bar:qux:100", func(t *testing.T) {
122+
std.TestSetRealm(adminRealm)
123+
124+
bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
125+
qux.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
126+
127+
tokenId, liquidity, amount0, amount1 := pn.Mint(
128+
barPath, // token0
129+
quxPath, // token1
130+
fee100, // fee
131+
int32(-1000), // tickLower
132+
int32(1000), // tickUpper
133+
"50", // amount0Desired
134+
"50", // amount1Desired
135+
"1", // amount0Min
136+
"1", // amount1Min
137+
max_timeout,
138+
adminAddr,
139+
adminAddr,
140+
)
141+
142+
uassert.Equal(t, tokenId, uint64(2))
143+
uassert.Equal(t, gnft.MustOwnerOf(tid(tokenId)), adminAddr)
144+
145+
gpi := getPrintInfo(t)
146+
// {"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":[]}]}
147+
148+
std.TestSkipHeights(1)
149+
})
150+
}
151+
152+
func testStakeToken_1_2(t *testing.T) {
153+
t.Run("stake position 01 and 02", func(t *testing.T) {
154+
std.TestSetRealm(adminRealm)
155+
156+
gnft.Approve(consts.STAKER_ADDR, tid(1))
157+
StakeToken(1)
158+
159+
gnft.Approve(consts.STAKER_ADDR, tid(2))
160+
StakeToken(2)
161+
162+
gpi := getPrintInfo(t)
163+
// {"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"}]}]}
164+
165+
std.TestSkipHeights(1)
166+
})
167+
}
168+
169+
func testNow(t *testing.T) {
170+
t.Run("now", func(t *testing.T) {
171+
std.TestSetRealm(adminRealm)
172+
173+
gpi := getPrintInfo(t)
174+
// {"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"}]}]}
175+
176+
std.TestSkipHeights(1)
177+
})
178+
}
179+
180+
func testCollectRewardBoth(t *testing.T) {
181+
t.Run("collect reward for position 01 and 02", func(t *testing.T) {
182+
std.TestSetRealm(adminRealm)
183+
184+
CollectReward(1, false)
185+
CollectReward(2, false)
186+
187+
gpi := getPrintInfo(t)
188+
// {"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"}]}]}
189+
190+
std.TestSkipHeights(1)
191+
})
192+
}

0 commit comments

Comments
 (0)