utils.gno
1.05 Kb · 38 lines
1package gns
2
3import (
4 gnsmath "gno.land/p/gnoswap/gnsmath"
5 ufmt "gno.land/p/nt/ufmt/v0"
6)
7
8// validYear validates that year is within halving period range (1-12).
9// Returns error if year is outside the valid range.
10func validYear(year int64) error {
11 if year < HALVING_START_YEAR || year > HALVING_END_YEAR {
12 return makeErrorWithDetails(errInvalidYear, ufmt.Sprintf("year: %d", year))
13 }
14
15 return nil
16}
17
18// validEmissionAmount validates that the emission amount does not exceed maximum.
19// Returns error if minting the amount would exceed MAX_EMISSION_AMOUNT.
20func validEmissionAmount(amount int64) error {
21 if amount < 0 {
22 return makeErrorWithDetails(errInvalidEmissionAmount, ufmt.Sprintf("emission amount cannot be negative: %d", amount))
23 }
24
25 if gnsmath.SafeAddInt64(amount, MintedEmissionAmount()) > MAX_EMISSION_AMOUNT {
26 return makeErrorWithDetails(errTooManyEmission, ufmt.Sprintf("too many emission amount: %d", amount))
27 }
28
29 return nil
30}
31
32// i64Min returns the smaller of two int64 values.
33func i64Min(x, y int64) int64 {
34 if x < y {
35 return x
36 }
37 return y
38}