Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSW-1035 feat: check normal time-range for incentive creation #212

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions staker/staker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package staker

import (
"std"
"strconv"
"time"

"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -31,6 +32,8 @@ const (
TIMESTAMP_180DAYS = 15552000
TIMESTAMP_365DAYS = 31536000

MAX_UNIX_EPOCH_TIME = 253402300799 // 9999-12-31 23:59:59

MUST_EXISTS_IN_TIER_1 = "gno.land/r/demo/gns:gno.land/r/demo/wugnot:3000"
)

Expand Down Expand Up @@ -59,10 +62,16 @@ func CreateExternalIncentive(

rewardAmount := u256.MustFromDecimal(_rewardAmount)

// must be in seconds format, not milliseconds
// must be at least +1 day midnight
// must be midnight of the day
checkStartTime(startTimestamp)

// endTimestamp cannot be later than 253402300799 (9999-12-31 23:59:59)
if endTimestamp >= MAX_UNIX_EPOCH_TIME {
panic(ufmt.Sprintf("[STAKER] staker.gno__CreateExternalIncentive() || endTimestamp(%d) cannot be later than 253402300799 (9999-12-31 23:59:59)", endTimestamp))
}

externalDuration := uint64(endTimestamp - startTimestamp)
if !(externalDuration == TIMESTAMP_90DAYS || externalDuration == TIMESTAMP_180DAYS || externalDuration == TIMESTAMP_365DAYS) {
panic(ufmt.Sprintf("[STAKER] staker.gno__CreateExternalIncentive() || externalDuration(%d) must be 90, 180, 365 days)", externalDuration))
Expand Down Expand Up @@ -284,6 +293,13 @@ func EndExternalIncentive(_refundee, targetPoolPath, rewardToken string) {
}

func checkStartTime(startTimestamp int64) {
// must be in seconds format, not milliseconds
// REF: https://stackoverflow.com/a/23982005
numStr := strconv.Itoa(int(startTimestamp))
if len(numStr) >= 13 {
panic(ufmt.Sprintf("[STAKER] staker.gno__checkStartTime() || startTimestamp(%d) must be in seconds format, not milliseconds", startTimestamp))
}

// must be at least +1 day midnight
tomorrowMidnight := time.Now().AddDate(0, 0, 1).Truncate(24 * time.Hour).Unix()
if startTimestamp < tomorrowMidnight {
Expand Down
Loading