Skip to content

Commit

Permalink
Merge pull request #170 from gnoswap-labs/GSW-872-detailed-condition-…
Browse files Browse the repository at this point in the history
…to-check-staking-reward

GSW-872 detailed condition to check staking reward
  • Loading branch information
r3v4s authored Feb 19, 2024
2 parents 1a0c567 + fa30584 commit b32c233
Show file tree
Hide file tree
Showing 20 changed files with 379 additions and 278 deletions.
16 changes: 8 additions & 8 deletions _setup/gnft/gnft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func mintNNFT(owner std.Address, n uint64) {
func BalanceOf(user users.AddressOrName) uint64 {
balance, err := nft.BalanceOf(user.Resolve())
if err != nil {
panic(err)
panic(err.Error())
}

return balance
Expand All @@ -42,7 +42,7 @@ func BalanceOf(user users.AddressOrName) uint64 {
func OwnerOf(tid grc721.TokenID) std.Address {
owner, err := nft.OwnerOf(tid)
if err != nil {
panic(err)
panic(err.Error())
}

return owner
Expand All @@ -56,7 +56,7 @@ func GetApproved(tid grc721.TokenID) (std.Address, bool) {
addr, err := nft.GetApproved(tid)
if err != nil {
return "", false
// panic(err)
// panic(err.Error())
}

return addr, true
Expand All @@ -67,21 +67,21 @@ func GetApproved(tid grc721.TokenID) (std.Address, bool) {
func Approve(user users.AddressOrName, tid grc721.TokenID) {
err := nft.Approve(user.Resolve(), tid)
if err != nil {
panic(err)
panic(err.Error())
}
}

func SetApprovalForAll(user users.AddressOrName, approved bool) {
err := nft.SetApprovalForAll(user.Resolve(), approved)
if err != nil {
panic(err)
panic(err.Error())
}
}

func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) {
err := nft.TransferFrom(from.Resolve(), to.Resolve(), tid)
if err != nil {
panic(err)
panic(err.Error())
}
}

Expand All @@ -93,7 +93,7 @@ func Mint(to users.AddressOrName, tid grc721.TokenID) {
assertIsAdmin(caller)
err := nft.Mint(to.Resolve(), tid)
if err != nil {
panic(err)
panic(err.Error())
}
}

Expand All @@ -103,7 +103,7 @@ func Burn(tid grc721.TokenID) {
assertIsAdmin(caller)
err := nft.Burn(tid)
if err != nil {
panic(err)
panic(err.Error())
}
}

Expand Down
6 changes: 3 additions & 3 deletions _setup/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var (
)

const (
admin std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
admin std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm" // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
)

func init() {
Expand All @@ -27,7 +27,7 @@ func init() {
gns.Mint(INTERNAL_REWARD_ACCOUNT, 400_000_000_000_000) // @INTERNAL_REWARD_ACCOUNT
gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // default test1

stakerAddr := std.DerivePkgAddr("gno.land/r/demo/staker")
stakerAddr := std.DerivePkgAddr("gno.land/r/demo/staker") // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
admins = append(admins, string(stakerAddr))
admins = append(admins, string(admin))

Expand Down
9 changes: 8 additions & 1 deletion consts/consts.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

// GNOSWAP SERVICE
const (
GNOSWAP_ADMIN std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4"
GNOSWAP_ADMIN std.Address = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // GSA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
INTERNAL_REWARD_ACCOUNT std.Address = "g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm"

// 500 GNS as creation fee (r3v4_xxx: 500 or 500_000_000)
POOL_CREATION_FEE uint64 = 500
Expand Down Expand Up @@ -35,6 +36,12 @@ const (

GOV_PATH string = "gno.land/r/demo/gov"
GOV_ADDR std.Address = std.DerivePkgAddr(GOV_PATH)

GNS_PATH string = "gno.land/r/demo/gns"
GNS_ADDR std.Address = std.DerivePkgAddr(GNS_PATH)

GNFT_PATH string = "gno.land/r/demo/gnft"
GNFT_ADDR std.Address = std.DerivePkgAddr(GNFT_PATH)
)

// NUMBER
Expand Down
36 changes: 0 additions & 36 deletions pool/_TEST_INIT_register_tokens_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (

"gno.land/r/demo/qux"

"gno.land/r/demo/fred"

"gno.land/r/demo/thud"

"gno.land/r/demo/wugnot"

"gno.land/r/demo/obl"
Expand Down Expand Up @@ -82,36 +78,6 @@ func (QuxToken) Approve() func(spender users.AddressOrName, amount uint64) {
return qux.Approve
}

type FredToken struct{}

func (FredToken) Transfer() func(to users.AddressOrName, amount uint64) {
return fred.Transfer
}
func (FredToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return fred.TransferFrom
}
func (FredToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return fred.BalanceOf
}
func (FredToken) Approve() func(spender users.AddressOrName, amount uint64) {
return fred.Approve
}

type ThudToken struct{}

func (ThudToken) Transfer() func(to users.AddressOrName, amount uint64) {
return thud.Transfer
}
func (ThudToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return thud.TransferFrom
}
func (ThudToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return thud.BalanceOf
}
func (ThudToken) Approve() func(spender users.AddressOrName, amount uint64) {
return thud.Approve
}

type WugnotToken struct{}

func (WugnotToken) Transfer() func(to users.AddressOrName, amount uint64) {
Expand Down Expand Up @@ -165,8 +131,6 @@ func init() {
RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
RegisterGRC20Interface("gno.land/r/demo/fred", FredToken{})
RegisterGRC20Interface("gno.land/r/demo/thud", ThudToken{})
RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})
Expand Down
36 changes: 0 additions & 36 deletions position/_TEST_INIT_register_tokens_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (

"gno.land/r/demo/qux"

"gno.land/r/demo/fred"

"gno.land/r/demo/thud"

"gno.land/r/demo/wugnot"

"gno.land/r/demo/obl"
Expand Down Expand Up @@ -84,36 +80,6 @@ func (QuxToken) Approve() func(spender users.AddressOrName, amount uint64) {
return qux.Approve
}

type FredToken struct{}

func (FredToken) Transfer() func(to users.AddressOrName, amount uint64) {
return fred.Transfer
}
func (FredToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return fred.TransferFrom
}
func (FredToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return fred.BalanceOf
}
func (FredToken) Approve() func(spender users.AddressOrName, amount uint64) {
return fred.Approve
}

type ThudToken struct{}

func (ThudToken) Transfer() func(to users.AddressOrName, amount uint64) {
return thud.Transfer
}
func (ThudToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return thud.TransferFrom
}
func (ThudToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return thud.BalanceOf
}
func (ThudToken) Approve() func(spender users.AddressOrName, amount uint64) {
return thud.Approve
}

type WugnotToken struct{}

func (WugnotToken) Transfer() func(to users.AddressOrName, amount uint64) {
Expand Down Expand Up @@ -167,8 +133,6 @@ func init() {
pl.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/fred", FredToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/thud", ThudToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})
Expand Down
2 changes: 1 addition & 1 deletion router/_TEST_INIT_basic_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() {

wugnot.Approve(a2u(poolAddr), 500_000_000_000_000)

std.TestSetPrevAddr(std.Address("g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm")) // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
std.TestSetPrevAddr(std.Address("g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm")) // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
gns.Approve(a2u(stakerAddr), 500_000_000_000_000) // to create internal incentive
}

Expand Down
38 changes: 0 additions & 38 deletions router/_TEST_INIT_register_tokens_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (

"gno.land/r/demo/qux"

"gno.land/r/demo/fred"

"gno.land/r/demo/thud"

"gno.land/r/demo/wugnot"

"gno.land/r/demo/obl"
Expand Down Expand Up @@ -84,36 +80,6 @@ func (QuxToken) Approve() func(spender users.AddressOrName, amount uint64) {
return qux.Approve
}

type FredToken struct{}

func (FredToken) Transfer() func(to users.AddressOrName, amount uint64) {
return fred.Transfer
}
func (FredToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return fred.TransferFrom
}
func (FredToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return fred.BalanceOf
}
func (FredToken) Approve() func(spender users.AddressOrName, amount uint64) {
return fred.Approve
}

type ThudToken struct{}

func (ThudToken) Transfer() func(to users.AddressOrName, amount uint64) {
return thud.Transfer
}
func (ThudToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) {
return thud.TransferFrom
}
func (ThudToken) BalanceOf() func(owner users.AddressOrName) uint64 {
return thud.BalanceOf
}
func (ThudToken) Approve() func(spender users.AddressOrName, amount uint64) {
return thud.Approve
}

type WugnotToken struct{}

func (WugnotToken) Transfer() func(to users.AddressOrName, amount uint64) {
Expand Down Expand Up @@ -168,8 +134,6 @@ func init() {
pool.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/fred", FredToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/thud", ThudToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
pool.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})
Expand All @@ -179,8 +143,6 @@ func init() {
RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
RegisterGRC20Interface("gno.land/r/demo/fred", FredToken{})
RegisterGRC20Interface("gno.land/r/demo/thud", ThudToken{})
RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})
Expand Down
8 changes: 4 additions & 4 deletions router/router_register.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"std"

"gno.land/r/demo/users"
)

const APPROVED_CALLER = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
"gno.land/r/demo/consts"
)

var registered = []GRC20Pair{}

Expand Down Expand Up @@ -51,7 +51,7 @@ func RegisterGRC20Interface(pkgPath string, igrc20 GRC20Interface) {
// r3v4_xxx: however must be used in production

// caller := std.GetOrigCaller()
// if caller != APPROVED_CALLER {
// if caller != consts.GNOSWAP_ADMIN {
// panic("unauthorized address to register")
// }

Expand All @@ -67,7 +67,7 @@ func UnregisterGRC20Interface(pkgPath string) {

// only admin can unregister
caller := std.GetOrigCaller()
if caller != APPROVED_CALLER {
if caller != consts.GNOSWAP_ADMIN {
panic("unauthorized address to unregister")
}

Expand Down
31 changes: 15 additions & 16 deletions staker/_TEST_INIT_basic_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"std"
"testing"

"gno.land/r/demo/consts"

"gno.land/r/demo/gns"

"gno.land/r/demo/bar"
Expand All @@ -19,8 +21,7 @@ import (
)

var (
test1 std.Address
poolAddr, posAddr, stakerAddr std.Address
test1 std.Address

barPath = "gno.land/r/demo/bar"
bazPath = "gno.land/r/demo/baz"
Expand All @@ -32,6 +33,8 @@ var (
fee100 = uint16(100)
fee500 = uint16(500)
fee3000 = uint16(3000)

max_timeout = bigint(9999999999)
)

func init() {
Expand All @@ -40,26 +43,22 @@ func init() {
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
testBanker.IssueCoin(test1, "ugnot", 500_000_000_000_000)

poolAddr = std.DerivePkgAddr("gno.land/r/demo/pool")
posAddr = std.DerivePkgAddr("gno.land/r/demo/position")
stakerAddr = std.DerivePkgAddr("gno.land/r/demo/staker")

std.TestSetPrevAddr(test1)

gns.Approve(a2u(poolAddr), 500_000_000_000_000)
gns.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)

bar.Approve(a2u(poolAddr), 500_000_000_000_000)
baz.Approve(a2u(poolAddr), 500_000_000_000_000)
foo.Approve(a2u(poolAddr), 500_000_000_000_000)
qux.Approve(a2u(poolAddr), 500_000_000_000_000)
bar.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
baz.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
foo.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
qux.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)

obl.Approve(a2u(stakerAddr), 500_000_000_000_000) // to create external incentive
wugnot.Approve(a2u(stakerAddr), 500_000_000_000_000) // to create (native) external incentive
obl.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create external incentive
wugnot.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create (native) external incentive

wugnot.Approve(a2u(poolAddr), 500_000_000_000_000)
wugnot.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)

std.TestSetPrevAddr(std.Address("g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm"))
gns.Approve(a2u(stakerAddr), 500_000_000_000_000) // to create internal incentive
std.TestSetPrevAddr(std.Address("g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm")) // IRA, r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK
gns.Approve(a2u(consts.STAKER_ADDR), 500_000_000_000_000) // to create internal incentive
}

/* HELPER */
Expand Down
Loading

0 comments on commit b32c233

Please sign in to comment.