-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
4,378 additions
and
0 deletions.
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
staker/filetests/z_average_block_time_change_from_gns_filetest.gnoA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// PKGPATH: gno.land/r/gnoswap/v1/staker_test | ||
|
||
// POOLs: | ||
// 1. gnot:gns:3000 | ||
|
||
// POSITIONs: | ||
// 1. in-range ( will be unstaked ) | ||
|
||
// REWARDs: | ||
// - internal tier 1 ( gnot:gns:3000 ) | ||
// - halving changes | ||
|
||
package staker_test | ||
|
||
import ( | ||
"std" | ||
"strconv" | ||
|
||
"gno.land/p/demo/grc/grc721" | ||
"gno.land/p/demo/testutils" | ||
|
||
"gno.land/r/gnoswap/v1/common" | ||
"gno.land/r/gnoswap/v1/consts" | ||
|
||
"gno.land/r/demo/wugnot" | ||
"gno.land/r/gnoswap/v1/gns" | ||
|
||
"gno.land/r/gnoswap/v1/gnft" | ||
|
||
pl "gno.land/r/gnoswap/v1/pool" | ||
pn "gno.land/r/gnoswap/v1/position" | ||
sr "gno.land/r/gnoswap/v1/staker" | ||
) | ||
|
||
var ( | ||
adminAddr = consts.ADMIN | ||
adminUser = common.AddrToUser(adminAddr) | ||
adminRealm = std.NewUserRealm(adminAddr) | ||
|
||
// g1v4u8getjdeskcsmjv4shgmmjta047h6lua7mup | ||
externalCreatorAddr = testutils.TestAddress("externalCreator") | ||
externalCreatorUser = common.AddrToUser(externalCreatorAddr) | ||
externalCreatorRealm = std.NewUserRealm(externalCreatorAddr) | ||
|
||
stakerAddr = consts.STAKER_ADDR | ||
stakerUser = common.AddrToUser(stakerAddr) | ||
stakerRealm = std.NewCodeRealm(consts.STAKER_PATH) | ||
|
||
wugnotAddr = consts.WUGNOT_ADDR | ||
|
||
fooPath = "gno.land/r/onbloc/foo" | ||
barPath = "gno.land/r/onbloc/bar" | ||
bazPath = "gno.land/r/onbloc/baz" | ||
quxPath = "gno.land/r/onbloc/qux" | ||
oblPath = "gno.land/r/onbloc/obl" | ||
|
||
gnsPath = "gno.land/r/gnoswap/v1/gns" | ||
wugnotPath = "gno.land/r/demo/wugnot" | ||
|
||
fee100 uint32 = 100 | ||
fee500 uint32 = 500 | ||
fee3000 uint32 = 3000 | ||
|
||
max_timeout int64 = 9999999999 | ||
|
||
// external incentive deposit fee | ||
depositGnsAmount uint64 = 1_000_000_000 // 1_000 GNS | ||
|
||
TIMESTAMP_90DAYS int64 = 90 * 24 * 60 * 60 | ||
TIMESTAMP_180DAYS int64 = 180 * 24 * 60 * 60 | ||
TIMESTAMP_365DAYS int64 = 365 * 24 * 60 * 60 | ||
|
||
poolPath = "gno.land/r/demo/wugnot:gno.land/r/gnoswap/v1/gns:3000" | ||
) | ||
|
||
func main() { | ||
testInit() | ||
testCreatePool() | ||
testMintWugnotGnsPos01() | ||
testStakeTokenPos01() | ||
testGnsAvgBlockTime() | ||
} | ||
|
||
func testInit() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
// short warm-up period | ||
sr.SetWarmUp(100, 901) | ||
sr.SetWarmUp(70, 301) | ||
sr.SetWarmUp(50, 151) | ||
sr.SetWarmUp(30, 1) | ||
|
||
// prepare wugnot | ||
std.TestIssueCoins(adminAddr, std.Coins{{"ugnot", 100_000_000_000_000}}) | ||
banker := std.GetBanker(std.BankerTypeRealmSend) | ||
banker.SendCoins(adminAddr, wugnotAddr, std.Coins{{"ugnot", 50_000_000_000_000}}) | ||
std.TestSetOrigSend(std.Coins{{"ugnot", 50_000_000_000_000}}, nil) | ||
wugnot.Deposit() | ||
std.TestSetOrigSend(nil, nil) | ||
} | ||
|
||
func testCreatePool() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
pl.SetPoolCreationFeeByAdmin(0) | ||
|
||
std.TestSkipHeights(1) | ||
pl.CreatePool( | ||
wugnotPath, | ||
gnsPath, | ||
fee3000, | ||
common.TickMathGetSqrtRatioAtTick(0).ToString(), // 79228162514264337593543950337 | ||
) | ||
} | ||
|
||
func testMintWugnotGnsPos01() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
wugnot.Approve(common.AddrToUser(consts.POOL_ADDR), consts.UINT64_MAX) | ||
gns.Approve(common.AddrToUser(consts.POOL_ADDR), consts.UINT64_MAX) | ||
|
||
std.TestSkipHeights(1) | ||
pn.Mint( | ||
wugnotPath, | ||
gnsPath, | ||
fee3000, | ||
int32(-60), | ||
int32(60), | ||
"50", | ||
"50", | ||
"1", | ||
"1", | ||
max_timeout, | ||
adminAddr, | ||
adminAddr, | ||
) | ||
} | ||
|
||
func testStakeTokenPos01() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
// stake | ||
gnft.Approve(consts.STAKER_ADDR, tokenIdFrom(1)) | ||
sr.StakeToken(1) | ||
|
||
/* | ||
std.TestSkipHeights(100) | ||
|
||
TODO: (after fixing unit test) check collected reward | ||
- position-01 has 100 blocks of reward | ||
*/ | ||
} | ||
|
||
func testGnsAvgBlockTime() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
std.TestSkipHeights(1) | ||
gns.SetAvgBlockTimeInMsByAdmin(4000) // orig block time was 2000ms(2s), change it to 4s | ||
|
||
/* | ||
std.TestSkipHeights(100) | ||
|
||
TODO: (after fixing unit test) check collected reward | ||
- avg block time has changed | ||
- meaning emission amount per block changes | ||
- position-01 has.. | ||
- 1. 100 blocks of reward when avg block time was 2000ms(2s) | ||
- 2. 50 blocks of reward when avg block time was 4000ms(4s) | ||
*/ | ||
} | ||
|
||
func tokenIdFrom(tokenId interface{}) grc721.TokenID { | ||
if tokenId == nil { | ||
panic("tokenId is nil") | ||
} | ||
|
||
switch tokenId.(type) { | ||
case string: | ||
return grc721.TokenID(tokenId.(string)) | ||
case int: | ||
return grc721.TokenID(strconv.Itoa(tokenId.(int))) | ||
case uint64: | ||
return grc721.TokenID(strconv.Itoa(int(tokenId.(uint64)))) | ||
case grc721.TokenID: | ||
return tokenId.(grc721.TokenID) | ||
default: | ||
panic("unsupported tokenId type") | ||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
staker/filetests/z_no_position_to_give_reward_filetest.gnoA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
// PKGPATH: gno.land/r/gnoswap/v1/staker_test | ||
|
||
// POOLs: | ||
// 1. gnot:gns:3000 | ||
|
||
// POSITIONs: | ||
// 1. in-range ( will be unstaked ) | ||
|
||
// REWARDs: | ||
// - internal tier 1 ( gnot:gns:3000 ) | ||
// - external bar ( gnot:gns:3000 ) | ||
|
||
package staker_test | ||
|
||
import ( | ||
"std" | ||
"strconv" | ||
|
||
"gno.land/p/demo/grc/grc721" | ||
"gno.land/p/demo/testutils" | ||
|
||
"gno.land/r/gnoswap/v1/common" | ||
"gno.land/r/gnoswap/v1/consts" | ||
|
||
"gno.land/r/demo/wugnot" | ||
"gno.land/r/gnoswap/v1/gns" | ||
|
||
"gno.land/r/gnoswap/v1/gnft" | ||
|
||
pl "gno.land/r/gnoswap/v1/pool" | ||
pn "gno.land/r/gnoswap/v1/position" | ||
sr "gno.land/r/gnoswap/v1/staker" | ||
) | ||
|
||
var ( | ||
adminAddr = consts.ADMIN | ||
adminUser = common.AddrToUser(adminAddr) | ||
adminRealm = std.NewUserRealm(adminAddr) | ||
|
||
// g1v4u8getjdeskcsmjv4shgmmjta047h6lua7mup | ||
externalCreatorAddr = testutils.TestAddress("externalCreator") | ||
externalCreatorUser = common.AddrToUser(externalCreatorAddr) | ||
externalCreatorRealm = std.NewUserRealm(externalCreatorAddr) | ||
|
||
stakerAddr = consts.STAKER_ADDR | ||
stakerUser = common.AddrToUser(stakerAddr) | ||
stakerRealm = std.NewCodeRealm(consts.STAKER_PATH) | ||
|
||
wugnotAddr = consts.WUGNOT_ADDR | ||
|
||
fooPath = "gno.land/r/onbloc/foo" | ||
barPath = "gno.land/r/onbloc/bar" | ||
bazPath = "gno.land/r/onbloc/baz" | ||
quxPath = "gno.land/r/onbloc/qux" | ||
oblPath = "gno.land/r/onbloc/obl" | ||
|
||
gnsPath = "gno.land/r/gnoswap/v1/gns" | ||
wugnotPath = "gno.land/r/demo/wugnot" | ||
|
||
fee100 uint32 = 100 | ||
fee500 uint32 = 500 | ||
fee3000 uint32 = 3000 | ||
|
||
max_timeout int64 = 9999999999 | ||
|
||
// external incentive deposit fee | ||
depositGnsAmount uint64 = 1_000_000_000 // 1_000 GNS | ||
|
||
TIMESTAMP_90DAYS int64 = 90 * 24 * 60 * 60 | ||
TIMESTAMP_180DAYS int64 = 180 * 24 * 60 * 60 | ||
TIMESTAMP_365DAYS int64 = 365 * 24 * 60 * 60 | ||
|
||
poolPath = "gno.land/r/demo/wugnot:gno.land/r/gnoswap/v1/gns:3000" | ||
) | ||
|
||
func main() { | ||
testInit() | ||
testCreatePool() | ||
testMintWugnotGnsPos01() | ||
testStakeTokenPos01() | ||
|
||
testUnstakePos01() | ||
} | ||
|
||
func testInit() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
// short warm-up period | ||
sr.SetWarmUp(100, 901) | ||
sr.SetWarmUp(70, 301) | ||
sr.SetWarmUp(50, 151) | ||
sr.SetWarmUp(30, 1) | ||
|
||
// prepare wugnot | ||
std.TestIssueCoins(adminAddr, std.Coins{{"ugnot", 100_000_000_000_000}}) | ||
banker := std.GetBanker(std.BankerTypeRealmSend) | ||
banker.SendCoins(adminAddr, wugnotAddr, std.Coins{{"ugnot", 50_000_000_000_000}}) | ||
std.TestSetOrigSend(std.Coins{{"ugnot", 50_000_000_000_000}}, nil) | ||
wugnot.Deposit() | ||
std.TestSetOrigSend(nil, nil) | ||
} | ||
|
||
func testCreatePool() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
pl.SetPoolCreationFeeByAdmin(0) | ||
|
||
std.TestSkipHeights(1) | ||
pl.CreatePool( | ||
wugnotPath, | ||
gnsPath, | ||
fee3000, | ||
common.TickMathGetSqrtRatioAtTick(0).ToString(), // 79228162514264337593543950337 | ||
) | ||
} | ||
|
||
func testMintWugnotGnsPos01() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
wugnot.Approve(common.AddrToUser(consts.POOL_ADDR), consts.UINT64_MAX) | ||
gns.Approve(common.AddrToUser(consts.POOL_ADDR), consts.UINT64_MAX) | ||
|
||
std.TestSkipHeights(1) | ||
pn.Mint( | ||
wugnotPath, | ||
gnsPath, | ||
fee3000, | ||
int32(-60), | ||
int32(60), | ||
"50", | ||
"50", | ||
"1", | ||
"1", | ||
max_timeout, | ||
adminAddr, | ||
adminAddr, | ||
) | ||
} | ||
|
||
func testStakeTokenPos01() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
// stake | ||
gnft.Approve(consts.STAKER_ADDR, tokenIdFrom(1)) | ||
sr.StakeToken(1) | ||
} | ||
|
||
func testUnstakePos01() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
std.TestSkipHeights(1) | ||
sr.UnstakeToken(1, false) | ||
|
||
/* | ||
std.TestSkipHeights(1) | ||
|
||
TODO: (after fixing unit test) check collected reward | ||
- no positions staked at gnot:gns:3000 | ||
- community_pool will receive empty pool's reward | ||
*/ | ||
} | ||
|
||
func tokenIdFrom(tokenId interface{}) grc721.TokenID { | ||
if tokenId == nil { | ||
panic("tokenId is nil") | ||
} | ||
|
||
switch tokenId.(type) { | ||
case string: | ||
return grc721.TokenID(tokenId.(string)) | ||
case int: | ||
return grc721.TokenID(strconv.Itoa(tokenId.(int))) | ||
case uint64: | ||
return grc721.TokenID(strconv.Itoa(int(tokenId.(uint64)))) | ||
case grc721.TokenID: | ||
return tokenId.(grc721.TokenID) | ||
default: | ||
panic("unsupported tokenId type") | ||
} | ||
} |
Oops, something went wrong.