Skip to content

Commit

Permalink
Merge pull request #107 from gnoswap-labs/GSW-609-change-ugnot-handling
Browse files Browse the repository at this point in the history
GSW-609 change ugnot handling
  • Loading branch information
notJoon authored Dec 4, 2023
2 parents 2633134 + 2c0fc06 commit 73090fb
Show file tree
Hide file tree
Showing 24 changed files with 710 additions and 117 deletions.
2 changes: 1 addition & 1 deletion _setup/grc20_wrapper/grc20_wrapper.gno
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func init() {
rRegistry.RegisterGRC20Interface("gno.land/r/gns", GnsTokenInterface{})

// staker register
// sRegistry.RegisterGRC20Interface("gno.land/r/wugnot", WugnotTokenInterface{})
sRegistry.RegisterGRC20Interface("gno.land/r/wugnot", WugnotTokenInterface{})
sRegistry.RegisterGRC20Interface("gno.land/r/obl", OblTokenInterface{})
sRegistry.RegisterGRC20Interface("gno.land/r/gns", GnsTokenInterface{})
}
19 changes: 11 additions & 8 deletions _setup/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
poolAddr = std.DerivePkgAddr("gno.land/r/pool")
posAddr = std.DerivePkgAddr("gno.land/r/position")
routerAddr = std.DerivePkgAddr("gno.land/r/router")
stakerAddr = std.DerivePkgAddr("gno.land/r/staker")
)

func init() {
Expand All @@ -38,13 +39,15 @@ func init() {
lp02 = testutils.TestAddress("lp02") // Liquidity Provider 02
lp03 = testutils.TestAddress("lp03") // Liquidity Provider 03
tr01 = testutils.TestAddress("tr01") // Trader 01
ci01 = testutils.TestAddress("ci01") // Create Incentive Caller
)

wugnot.Approve(lp01, poolAddr, 50000000000)
wugnot.Approve(lp02, poolAddr, 50000000000)
wugnot.Approve(lp03, poolAddr, 50000000000)
wugnot.Approve(tr01, poolAddr, 50000000000)

wugnot.Approve(ci01, stakerAddr, 50000000000)
}

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

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

func Unwrap(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can unwrap")
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
panic("only pool, position, router, staker contract can unwrap")
}

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

func Transfer(to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can transfer")
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
panic("only pool, position, router, staker contract can transfer")
}
err := wugnot.Transfer(caller, to.Resolve(), amount)
if err != nil {
Expand All @@ -164,8 +167,8 @@ func Transfer(to users.AddressOrName, amount uint64) {

func TransferFrom(from, to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
if !(caller == poolAddr || caller == posAddr || caller == routerAddr) {
panic("only pool, position, router contract can transferFrom")
if !(caller == poolAddr || caller == posAddr || caller == routerAddr || caller == stakerAddr) {
panic("only pool, position, router, staker contract can transferFrom")
}
err := wugnot.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
if err != nil {
Expand Down
94 changes: 38 additions & 56 deletions _test/gs_test.gno → _test/_TEST_gs_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ var (
rouAddr = rou.GetOrigPkgAddr() // Router Contract

// token path
fooPath = "gno.land/r/foo"
barPath = "gno.land/r/bar"
bazPath = "gno.land/r/baz"
quxPath = "gno.land/r/qux"
wugnotPath = "gno.land/r/wugnot"
gnsPath = "gno.land/r/gns"
oblPath = "gno.land/r/obl"
fooPath = "gno.land/r/foo"
barPath = "gno.land/r/bar"
bazPath = "gno.land/r/baz"
quxPath = "gno.land/r/qux"
gnsPath = "gno.land/r/gns"
oblPath = "gno.land/r/obl"

gnotPath = "gnot"

MIN_TICK bigint = -887272
MAX_TICK bigint = 887272
Expand Down Expand Up @@ -102,13 +103,13 @@ func TestPoolCreatePool(t *testing.T) {

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

pl.CreatePool(wugnotPath, barPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(barPath, bazPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(bazPath, quxPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(gnotPath, barPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(barPath, bazPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(bazPath, quxPath, uint16(100), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176

pl.CreatePool(wugnotPath, barPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(barPath, bazPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(bazPath, quxPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(gnotPath, barPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(barPath, bazPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
pl.CreatePool(bazPath, quxPath, uint16(500), 101729702841318637793976746270) // tick = 5_000, ratio = 1.648680055931176
std.TestSkipHeights(7)

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

// 3. [TC - POSITION] Mint LP
func TestPositionMint(t *testing.T) {
// bar_wugnot_100 by lp01
// gnot_bar_100 by lp01
{
std.TestSetOrigCaller(lp01)

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

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

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

{
// bar_wugnot_500 by lp01
// bar_gnot_500 by lp01
// simulate transfer & decrase
std.TestSetOrigCaller(lp01)
std.TestSetOrigSend(std.Coins{{"ugnot", 10000000}}, nil)
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 10000000)
// pos.Mint(wugnotPath, barPath, uint16(500), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
pos.Mint(barPath, wugnotPath, uint16(500), int32(-6000), int32(-4000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
// pos.Mint(gnotPath, barPath, uint16(500), int32(4000), int32(6000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)
pos.Mint(barPath, gnotPath, uint16(500), int32(-6000), int32(-4000), bigint(10000000), bigint(10000000), 0, 0, MAX_TIMEOUT)

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

std.TestSkipHeights(3)

}
}

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

stk.CreateExternalIncentive(
"gno.land/r/bar:gno.land/r/wugnot:100", // targetPoolPath
"gno.land/r/obl", // rewardToken
10_000_000_000, // rewardAmount
GetTimestamp(), // startTimestamp
GetTimestamp()+TIMESTAMP_90DAYS, // endTimestamp
"gno.land/r/bar:gnot:100", // targetPoolPath
"gno.land/r/obl", // rewardToken
10_000_000_000, // rewardAmount
GetTimestamp(), // startTimestamp
GetTimestamp()+TIMESTAMP_90DAYS, // endTimestamp
)
std.TestSkipHeights(1)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestPoolSetFeeProtocol(t *testing.T) {
pl.SetFeeProtocol(6, 8)
std.TestSkipHeights(1)

tmpPool := pl.GetPool(barPath, wugnotPath, uint16(100))
tmpPool := pl.GetPool(barPath, gnotPath, uint16(100))
shouldEQ(t, tmpPool.PoolGetSlot0FeeProtocol(), bigint(134))
}

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

swapAmount := 987_654
rou.SwapRoute(
wugnotPath,
gnotPath,
quxPath,
bigint(swapAmount),
"EXACT_OUT",
"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",
"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",
"40,60",
123456789,
)
Expand All @@ -365,12 +365,6 @@ func TestRotuerSwapRouteExactOutputMultiPath(t *testing.T) {
func TestPositionCollect01(t *testing.T) {
{
// lp01 collects fee from tokenId '1'
std.TestSetOrigCaller(lp01)

// minted at bar_wugnot_500
poolOldNativeBalance := ugnotBalance(poolAddr)
poolOldWugnotBalance := wugnot.BalanceOf(a2u(poolAddr))

std.TestSetPrevRealm("gno.land/r/position")
std.TestSetOrigCaller(lp01)
cAmount0, cAmount1 := pos.Collect(
Expand All @@ -382,10 +376,7 @@ func TestPositionCollect01(t *testing.T) {
std.TestSkipHeights(1)

shouldEQ(t, cAmount0, bigint(0)) // bar
shouldEQ(t, cAmount1, bigint(6)) // wugnot

poolNewNativeBalance := ugnotBalance(poolAddr)
poolNewWugnotBalance := wugnot.BalanceOf(a2u(poolAddr))
shouldEQ(t, cAmount1, bigint(6)) // ugnot
}

{
Expand Down Expand Up @@ -452,19 +443,19 @@ func TestStakerEndExternalIncentive(t *testing.T) {

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

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

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

shouldPanicWithMsg(
t,
func() {
stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gno.land/r/wugnot:100", "gno.land/r/obl")
},
"[STAKER] staker.gno__EndExternalIncentive() || cannot end non existent incentive(ZzF2ZDVucXYybHRhMDQ3aDZsdGEwNDdoNmx0YTA0N2g2bGswd2hjZDpnbm8ubGFuZC9yL2Jhcjpnbm8ubGFuZC9yL3d1Z25vdDoxMDA6Z25vLmxhbmQvci9vYmw=)",
)
// shouldPanicWithMsg(
// t,
// func() {
// stk.EndExternalIncentive(ci01.String(), "gno.land/r/bar:gnot:100", "gno.land/r/obl")
// },
// "[STAKER] staker.gno__EndExternalIncentive() || cannot end non existent incentive(ZzF2ZDVucXYybHRhMDQ3aDZsdGEwNDdoNmx0YTA0N2g2bGswd2hjZDpnbm8ubGFuZC9yL2Jhcjp1Z25vdDoxMDA6Z25vLmxhbmQvci9vYmw=)",
// )
}

/* UTILS */
Expand Down Expand Up @@ -547,16 +538,7 @@ func shouldPanicWithMsg(t *testing.T, f func(), msg string) {
f()
}

func ugnotBalance(addr std.Address) std.Coin {
func ugnotBalance(addr std.Address) uint64 {
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
coins := testBanker.GetCoins(tr01)

if len(coins) == 0 {
return nil
}

if len(coins) == 1 {
coin := coins[0]
return coin
}
return uint64(testBanker.GetCoins(addr)[0].Amount)
}
1 change: 0 additions & 1 deletion _test/gs.gno

This file was deleted.

Loading

0 comments on commit 73090fb

Please sign in to comment.