-
Notifications
You must be signed in to change notification settings - Fork 2
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
4 changed files
with
1,095 additions
and
0 deletions.
There are no files selected for viewing
194 changes: 194 additions & 0 deletions
194
staker/filetests/z_emission_distribution_pct_change_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,194 @@ | ||
// PKGPATH: gno.land/r/gnoswap/v1/staker_test | ||
|
||
// POOLs: | ||
// 1. gnot:gns:3000 | ||
|
||
// POSITIONs: | ||
// 1. in-range | ||
|
||
// REWARDs: | ||
// - internal tier 1 ( gnot:gns:3000 ) | ||
// > amount of reward changes due to emission distribution percentage change | ||
|
||
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" | ||
|
||
en "gno.land/r/gnoswap/v1/emission" | ||
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() | ||
testChangeEmissionDistributionPct() | ||
} | ||
|
||
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(1) | ||
|
||
TODO: (after fixing unit test) check reward | ||
- position-01 has 1 block of reward | ||
- `1 block` for when staker gets 75% of emission reward | ||
*/ | ||
} | ||
|
||
func testChangeEmissionDistributionPct() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
// staker gets 100% of emission reward | ||
en.ChangeDistributionPctByAdmin( | ||
en.LIQUIDITY_STAKER, 10000, | ||
en.DEVOPS, 0, | ||
en.COMMUNITY_POOL, 0, | ||
en.GOV_STAKER, 0, | ||
) | ||
|
||
/* | ||
std.TestSkipHeights(1) | ||
|
||
TODO: (after fixing unit test) check reward | ||
- position-01 has 2 block of reward | ||
- `1 block` for when staker gets 75% of emission reward | ||
- `1 block` for when staker gets 100% of emission 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") | ||
} | ||
} |
196 changes: 196 additions & 0 deletions
196
staker/filetests/z_warmup_duration_change_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,196 @@ | ||
// PKGPATH: gno.land/r/gnoswap/v1/staker_test | ||
|
||
// POOLs: | ||
// 1. gnot:gns:3000 | ||
|
||
// POSITIONs: | ||
// 1. in-range | ||
|
||
// REWARDs: | ||
// - internal tier 1 ( gnot:gns:3000 ) | ||
// > warmup duration 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() | ||
testChangeWarmupDuration() | ||
} | ||
|
||
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) | ||
|
||
/* | ||
CURRENT WARM UP | ||
30% // stakedHeight ~ 150 block || duration 150 block | ||
50% // 151 ~ 300 block || duration 150 block | ||
70% // 301 ~ 900 block || duration 600 block | ||
100% // 901 ~ | ||
|
||
std.TestSkipHeights(200) | ||
- skip 200 blocks (position-01 is in 50% warmup period) | ||
- position-01 will have rewards from | ||
-- 30% warmup period | ||
-- 50% warmup period // currently in | ||
*/ | ||
} | ||
|
||
func testChangeWarmupDuration() { | ||
std.TestSetRealm(adminRealm) | ||
|
||
sr.SetWarmUp(50, 251) // increase 50 block more than before | ||
|
||
/* | ||
NEW WARM UP | ||
30% // stakedHeight ~ 250 block || duration 250 block | ||
50% // 251 ~ 300 block || duration 50 block | ||
70% // 301 ~ 900 block || duration 600 block | ||
100% // 901 ~ | ||
|
||
std.TestSkipHeights(10) | ||
- 30% warm up period has been increased by 50 block | ||
- after changing, position-01 is in 30% warm up period // check reward increment for that period | ||
*/ | ||
} | ||
|
||
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.