Skip to content

Commit 73090fb

Browse files
authored
Merge pull request #107 from gnoswap-labs/GSW-609-change-ugnot-handling
GSW-609 change ugnot handling
2 parents 2633134 + 2c0fc06 commit 73090fb

24 files changed

+710
-117
lines changed

_setup/grc20_wrapper/grc20_wrapper.gno

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func init() {
189189
rRegistry.RegisterGRC20Interface("gno.land/r/gns", GnsTokenInterface{})
190190

191191
// staker register
192-
// sRegistry.RegisterGRC20Interface("gno.land/r/wugnot", WugnotTokenInterface{})
192+
sRegistry.RegisterGRC20Interface("gno.land/r/wugnot", WugnotTokenInterface{})
193193
sRegistry.RegisterGRC20Interface("gno.land/r/obl", OblTokenInterface{})
194194
sRegistry.RegisterGRC20Interface("gno.land/r/gns", GnsTokenInterface{})
195195
}

_setup/wugnot/wugnot.gno

+11-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
poolAddr = std.DerivePkgAddr("gno.land/r/pool")
2828
posAddr = std.DerivePkgAddr("gno.land/r/position")
2929
routerAddr = std.DerivePkgAddr("gno.land/r/router")
30+
stakerAddr = std.DerivePkgAddr("gno.land/r/staker")
3031
)
3132

3233
func init() {
@@ -38,13 +39,15 @@ func init() {
3839
lp02 = testutils.TestAddress("lp02") // Liquidity Provider 02
3940
lp03 = testutils.TestAddress("lp03") // Liquidity Provider 03
4041
tr01 = testutils.TestAddress("tr01") // Trader 01
42+
ci01 = testutils.TestAddress("ci01") // Create Incentive Caller
4143
)
4244

4345
wugnot.Approve(lp01, poolAddr, 50000000000)
4446
wugnot.Approve(lp02, poolAddr, 50000000000)
4547
wugnot.Approve(lp03, poolAddr, 50000000000)
4648
wugnot.Approve(tr01, poolAddr, 50000000000)
4749

50+
wugnot.Approve(ci01, stakerAddr, 50000000000)
4851
}
4952

5053
// method proxies as public functions.
@@ -135,26 +138,26 @@ func assertIsAdmin(address std.Address) {
135138
// WRAP & UNWRAP
136139
func Wrap(address users.AddressOrName, amount uint64) {
137140
caller := std.PrevRealm().Addr()
138-
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
139-
panic("only pool, position, router contract can wrap")
141+
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
142+
panic("only pool, position, router, staker contract can wrap")
140143
}
141144

142145
wugnot.Mint(address.Resolve(), amount) // mint to user
143146
}
144147

145148
func Unwrap(address users.AddressOrName, amount uint64) {
146149
caller := std.PrevRealm().Addr()
147-
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
148-
panic("only pool, position, router contract can unwrap")
150+
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
151+
panic("only pool, position, router, staker contract can unwrap")
149152
}
150153

151154
wugnot.Burn(address.Resolve(), amount) // burn from user
152155
}
153156

154157
func Transfer(to users.AddressOrName, amount uint64) {
155158
caller := std.PrevRealm().Addr()
156-
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
157-
panic("only pool, position, router contract can transfer")
159+
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
160+
panic("only pool, position, router, staker contract can transfer")
158161
}
159162
err := wugnot.Transfer(caller, to.Resolve(), amount)
160163
if err != nil {
@@ -164,8 +167,8 @@ func Transfer(to users.AddressOrName, amount uint64) {
164167

165168
func TransferFrom(from, to users.AddressOrName, amount uint64) {
166169
caller := std.PrevRealm().Addr()
167-
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
168-
panic("only pool, position, router contract can transferFrom")
170+
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
171+
panic("only pool, position, router, staker contract can transferFrom")
169172
}
170173
err := wugnot.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
171174
if err != nil {

_test/gs_test.gno renamed to _test/_TEST_gs_test.gno

+38-56
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ var (
5454
rouAddr = rou.GetOrigPkgAddr() // Router Contract
5555

5656
// token path
57-
fooPath = "gno.land/r/foo"
58-
barPath = "gno.land/r/bar"
59-
bazPath = "gno.land/r/baz"
60-
quxPath = "gno.land/r/qux"
61-
wugnotPath = "gno.land/r/wugnot"
62-
gnsPath = "gno.land/r/gns"
63-
oblPath = "gno.land/r/obl"
57+
fooPath = "gno.land/r/foo"
58+
barPath = "gno.land/r/bar"
59+
bazPath = "gno.land/r/baz"
60+
quxPath = "gno.land/r/qux"
61+
gnsPath = "gno.land/r/gns"
62+
oblPath = "gno.land/r/obl"
63+
64+
gnotPath = "gnot"
6465

6566
MIN_TICK bigint = -887272
6667
MAX_TICK bigint = 887272
@@ -102,13 +103,13 @@ func TestPoolCreatePool(t *testing.T) {
102103

103104
gsaOldGnsBalance := gns.BalanceOf(a2u(gsa))
104105

105-
pl.CreatePool(wugnotPath, barPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
106-
pl.CreatePool(barPath, bazPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
107-
pl.CreatePool(bazPath, quxPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
106+
pl.CreatePool(gnotPath, barPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
107+
pl.CreatePool(barPath, bazPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
108+
pl.CreatePool(bazPath, quxPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
108109

109-
pl.CreatePool(wugnotPath, barPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
110-
pl.CreatePool(barPath, bazPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
111-
pl.CreatePool(bazPath, quxPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
110+
pl.CreatePool(gnotPath, barPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
111+
pl.CreatePool(barPath, bazPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
112+
pl.CreatePool(bazPath, quxPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
112113
std.TestSkipHeights(7)
113114

114115
gsaNewGnsBalance := gns.BalanceOf(a2u(gsa))
@@ -119,7 +120,7 @@ func TestPoolCreatePool(t *testing.T) {
119120

120121
// 3. [TC - POSITION] Mint LP
121122
func TestPositionMint(t *testing.T) {
122-
// bar_wugnot_100 by lp01
123+
// gnot_bar_100 by lp01
123124
{
124125
std.TestSetOrigCaller(lp01)
125126

@@ -140,7 +141,7 @@ func TestPositionMint(t *testing.T) {
140141
testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 10000000)
141142

142143
// Mint
143-
tokenId, liquidity, amount0, amount1 := pos.Mint(wugnotPath, barPath, uint16(100), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
144+
tokenId, liquidity, amount0, amount1 := pos.Mint(gnotPath, barPath, uint16(100), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
144145
std.TestSkipHeights(1)
145146

146147
shouldEQ(t, gnft.OwnerOf(tid(1)), lp01)
@@ -223,14 +224,14 @@ func TestPositionMint(t *testing.T) {
223224
}
224225

225226
{
226-
// bar_wugnot_500 by lp01
227+
// bar_gnot_500 by lp01
227228
// simulate transfer & decrase
228229
std.TestSetOrigCaller(lp01)
229230
std.TestSetOrigSend(std.Coins{{"ugnot", 10000000}}, nil)
230231
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
231232
testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 10000000)
232-
// pos.Mint(wugnotPath, barPath, uint16(500), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
233-
pos.Mint(barPath, wugnotPath, uint16(500), int32(-6000), int32(-4000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
233+
// pos.Mint(gnotPath, barPath, uint16(500), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
234+
pos.Mint(barPath, gnotPath, uint16(500), int32(-6000), int32(-4000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
234235

235236
// bar_baz_500 by lp02
236237
std.TestSetOrigCaller(lp02)
@@ -241,7 +242,6 @@ func TestPositionMint(t *testing.T) {
241242
pos.Mint(bazPath, quxPath, uint16(500), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
242243

243244
std.TestSkipHeights(3)
244-
245245
}
246246
}
247247

@@ -251,11 +251,11 @@ func TestStakerCreateExternalIncentive(t *testing.T) {
251251
std.TestSetOrigCaller(ci01)
252252

253253
stk.CreateExternalIncentive(
254-
"gno.land/r/bar:gno.land/r/wugnot:100", // targetPoolPath
255-
"gno.land/r/obl", // rewardToken
256-
10_000_000_000, // rewardAmount
257-
GetTimestamp(), // startTimestamp
258-
GetTimestamp()+TIMESTAMP_90DAYS, // endTimestamp
254+
"gno.land/r/bar:gnot:100", // targetPoolPath
255+
"gno.land/r/obl", // rewardToken
256+
10_000_000_000, // rewardAmount
257+
GetTimestamp(), // startTimestamp
258+
GetTimestamp()+TIMESTAMP_90DAYS, // endTimestamp
259259
)
260260
std.TestSkipHeights(1)
261261
}
@@ -288,7 +288,7 @@ func TestPoolSetFeeProtocol(t *testing.T) {
288288
pl.SetFeeProtocol(6, 8)
289289
std.TestSkipHeights(1)
290290

291-
tmpPool := pl.GetPool(barPath, wugnotPath, uint16(100))
291+
tmpPool := pl.GetPool(barPath, gnotPath, uint16(100))
292292
shouldEQ(t, tmpPool.PoolGetSlot0FeeProtocol(), bigint(134))
293293
}
294294

@@ -343,11 +343,11 @@ func TestRotuerSwapRouteExactOutputMultiPath(t *testing.T) {
343343

344344
swapAmount := 987_654
345345
rou.SwapRoute(
346-
wugnotPath,
346+
gnotPath,
347347
quxPath,
348348
bigint(swapAmount),
349349
"EXACT_OUT",
350-
"gno.land/r/wugnot:gno.land/r/bar:100*POOL*gno.land/r/bar:gno.land/r/baz:100*POOL*gno.land/r/baz:gno.land/r/qux:100,gno.land/r/wugnot:gno.land/r/bar:500*POOL*gno.land/r/bar:gno.land/r/baz:500*POOL*gno.land/r/baz:gno.land/r/qux:500",
350+
"gnot:gno.land/r/bar:100*POOL*gno.land/r/bar:gno.land/r/baz:100*POOL*gno.land/r/baz:gno.land/r/qux:100,gnot:gno.land/r/bar:500*POOL*gno.land/r/bar:gno.land/r/baz:500*POOL*gno.land/r/baz:gno.land/r/qux:500",
351351
"40,60",
352352
123456789,
353353
)
@@ -365,12 +365,6 @@ func TestRotuerSwapRouteExactOutputMultiPath(t *testing.T) {
365365
func TestPositionCollect01(t *testing.T) {
366366
{
367367
// lp01 collects fee from tokenId '1'
368-
std.TestSetOrigCaller(lp01)
369-
370-
// minted at bar_wugnot_500
371-
poolOldNativeBalance := ugnotBalance(poolAddr)
372-
poolOldWugnotBalance := wugnot.BalanceOf(a2u(poolAddr))
373-
374368
std.TestSetPrevRealm("gno.land/r/position")
375369
std.TestSetOrigCaller(lp01)
376370
cAmount0, cAmount1 := pos.Collect(
@@ -382,10 +376,7 @@ func TestPositionCollect01(t *testing.T) {
382376
std.TestSkipHeights(1)
383377

384378
shouldEQ(t, cAmount0, bigint(0)) // bar
385-
shouldEQ(t, cAmount1, bigint(6)) // wugnot
386-
387-
poolNewNativeBalance := ugnotBalance(poolAddr)
388-
poolNewWugnotBalance := wugnot.BalanceOf(a2u(poolAddr))
379+
shouldEQ(t, cAmount1, bigint(6)) // ugnot
389380
}
390381

391382
{
@@ -452,19 +443,19 @@ func TestStakerEndExternalIncentive(t *testing.T) {
452443

453444
ci01OldRewardBal := obl.BalanceOf(a2u(ci01))
454445

455-
stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gno.land/r/wugnot:100", "gno.land/r/obl") // use same parameter as CreateExternalIncentive
446+
stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gnot:100", "gno.land/r/obl") // use same parameter as CreateExternalIncentive
456447
std.TestSkipHeights(1)
457448

458449
ci01NewRewardBal := obl.BalanceOf(a2u(ci01))
459450
shouldGT(t, ci01NewRewardBal, ci01OldRewardBal)
460451

461-
shouldPanicWithMsg(
462-
t,
463-
func() {
464-
stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gno.land/r/wugnot:100", "gno.land/r/obl")
465-
},
466-
"[STAKER] staker.gno__EndExternalIncentive() || cannot end non existent incentive(ZzF2ZDVucXYybHRhMDQ3aDZsdGEwNDdoNmx0YTA0N2g2bGswd2hjZDpnbm8ubGFuZC9yL2Jhcjpnbm8ubGFuZC9yL3d1Z25vdDoxMDA6Z25vLmxhbmQvci9vYmw=)",
467-
)
452+
// shouldPanicWithMsg(
453+
// t,
454+
// func() {
455+
// stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gnot:100", "gno.land/r/obl")
456+
// },
457+
// "[STAKER] staker.gno__EndExternalIncentive() || cannot end non existent incentive(ZzF2ZDVucXYybHRhMDQ3aDZsdGEwNDdoNmx0YTA0N2g2bGswd2hjZDpnbm8ubGFuZC9yL2Jhcjp1Z25vdDoxMDA6Z25vLmxhbmQvci9vYmw=)",
458+
// )
468459
}
469460

470461
/* UTILS */
@@ -547,16 +538,7 @@ func shouldPanicWithMsg(t *testing.T, f func(), msg string) {
547538
f()
548539
}
549540

550-
func ugnotBalance(addr std.Address) std.Coin {
541+
func ugnotBalance(addr std.Address) uint64 {
551542
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
552-
coins := testBanker.GetCoins(tr01)
553-
554-
if len(coins) == 0 {
555-
return nil
556-
}
557-
558-
if len(coins) == 1 {
559-
coin := coins[0]
560-
return coin
561-
}
543+
return uint64(testBanker.GetCoins(addr)[0].Amount)
562544
}

_test/gs.gno

-1
This file was deleted.

0 commit comments

Comments
 (0)