-
Notifications
You must be signed in to change notification settings - Fork 9
/
params.go
231 lines (200 loc) · 5.4 KB
/
params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package types
import (
"errors"
"fmt"
"strings"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewParams returns Params instance with the given values.
func NewParams(
mintDenom string,
inflationRateChange,
inflationMax,
inflationMin,
goalBonded math.LegacyDec,
blocksPerYear uint64,
maxSupply math.Uint,
halvingInterval uint64,
currentBlockProvision math.Uint,
) Params {
return Params{
MintDenom: mintDenom,
InflationRateChange: inflationRateChange,
InflationMax: inflationMax,
InflationMin: inflationMin,
GoalBonded: goalBonded,
BlocksPerYear: blocksPerYear,
MaxSupply: maxSupply,
HalvingInterval: halvingInterval,
CurrentBlockProvision: currentBlockProvision,
}
}
// DefaultParams returns default x/mint module parameters.
func DefaultParams() Params {
return Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: math.LegacyNewDecWithPrec(3573582624, 7),
InflationMax: math.LegacyNewDecWithPrec(3573582624, 7),
InflationMin: math.LegacyNewDecWithPrec(0, 2),
GoalBonded: math.LegacyNewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times
MaxSupply: math.NewUintFromString("1000000000000000000000000000"), //1 billion allo * 1e18 (exponent) = 1e27 uallo
HalvingInterval: uint64(25246080),
CurrentBlockProvision: math.NewUintFromString("2831000000000000000000"), // uallo per block
}
}
// Validate does the sanity check on the params.
func (p Params) Validate() error {
if err := validateMintDenom(p.MintDenom); err != nil {
return err
}
if err := validateInflationRateChange(p.InflationRateChange); err != nil {
return err
}
if err := validateInflationMax(p.InflationMax); err != nil {
return err
}
if err := validateInflationMin(p.InflationMin); err != nil {
return err
}
if err := validateGoalBonded(p.GoalBonded); err != nil {
return err
}
if err := validateBlocksPerYear(p.BlocksPerYear); err != nil {
return err
}
if p.InflationMax.LT(p.InflationMin) {
return fmt.Errorf(
"max inflation (%s) must be greater than or equal to min inflation (%s)",
p.InflationMax, p.InflationMin,
)
}
if err := validateMaxSupply(p.MaxSupply); err != nil {
return err
}
if err := validateHalvingInterval(p.HalvingInterval); err != nil {
return err
}
if err := validateCurrentBlockProvision(p.CurrentBlockProvision); err != nil {
return err
}
return nil
}
func validateMintDenom(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if strings.TrimSpace(v) == "" {
return errors.New("mint denom cannot be blank")
}
if err := sdk.ValidateDenom(v); err != nil {
return err
}
return nil
}
func validateInflationRateChange(i interface{}) error {
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("inflation rate change cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("inflation rate change cannot be negative: %s", v)
}
return nil
}
func validateInflationMax(i interface{}) error {
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("max inflation cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("max inflation cannot be negative: %s", v)
}
return nil
}
func validateInflationMin(i interface{}) error {
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("min inflation cannot be nil: %s", v)
}
if v.IsNegative() {
return fmt.Errorf("min inflation cannot be negative: %s", v)
}
if v.GT(math.LegacyOneDec()) {
return fmt.Errorf("min inflation too large: %s", v)
}
return nil
}
func validateGoalBonded(i interface{}) error {
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("goal bonded cannot be nil: %s", v)
}
if v.IsNegative() || v.IsZero() {
return fmt.Errorf("goal bonded must be positive: %s", v)
}
if v.GT(math.LegacyOneDec()) {
return fmt.Errorf("goal bonded too large: %s", v)
}
return nil
}
func validateBlocksPerYear(i interface{}) error {
v, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v == 0 {
return fmt.Errorf("blocks per year must be positive: %d", v)
}
return nil
}
func validateMaxSupply(i interface{}) error {
v, ok := i.(math.Uint)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("max supply cannot be nil: %s", v)
}
if v.LTE(math.NewUint(0)) {
return fmt.Errorf("max supply must be positive: %s", v)
}
return nil
}
func validateHalvingInterval(i interface{}) error {
v, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v == 0 {
return fmt.Errorf("halving interval must be positive: %d", v)
}
return nil
}
func validateCurrentBlockProvision(i interface{}) error {
v, ok := i.(math.Uint)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("current block provision cannot be nil: %s", v)
}
if v.LT(math.NewUint(0)) {
return fmt.Errorf("current block provision cannot be negative: %s", v)
}
return nil
}