-
Notifications
You must be signed in to change notification settings - Fork 43
/
params.go
250 lines (202 loc) · 7.59 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package types
import (
"fmt"
"gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
core "github.com/classic-terra/core/types"
)
// Parameter keys
var (
KeyTaxPolicy = []byte("TaxPolicy")
KeyRewardPolicy = []byte("RewardPolicy")
KeySeigniorageBurdenTarget = []byte("SeigniorageBurdenTarget")
KeyMiningIncrement = []byte("MiningIncrement")
KeyWindowShort = []byte("WindowShort")
KeyWindowLong = []byte("WindowLong")
KeyWindowProbation = []byte("WindowProbation")
KeyBurnTaxSplit = []byte("BurnTaxSplit")
)
// Default parameter values
var (
DefaultTaxPolicy = PolicyConstraints{
RateMin: sdk.NewDecWithPrec(5, 4), // 0.05%
RateMax: sdk.NewDecWithPrec(1, 2), // 1%
Cap: sdk.NewCoin(core.MicroSDRDenom, sdk.OneInt().MulRaw(core.MicroUnit)), // 1 SDR Tax cap
ChangeRateMax: sdk.NewDecWithPrec(25, 5), // 0.025%
}
DefaultRewardPolicy = PolicyConstraints{
RateMin: sdk.NewDecWithPrec(5, 2), // 5%
RateMax: sdk.NewDecWithPrec(50, 2), // 50%
ChangeRateMax: sdk.NewDecWithPrec(25, 3), // 2.5%
Cap: sdk.NewCoin("unused", sdk.ZeroInt()), // UNUSED
}
DefaultSeigniorageBurdenTarget = sdk.NewDecWithPrec(67, 2) // 67%
DefaultMiningIncrement = sdk.NewDecWithPrec(107, 2) // 1.07 mining increment; exponential growth
DefaultWindowShort = uint64(4) // a month
DefaultWindowLong = uint64(52) // a year
DefaultWindowProbation = uint64(12) // 3 month
DefaultTaxRate = sdk.NewDecWithPrec(1, 3) // 0.1%
DefaultRewardWeight = sdk.NewDecWithPrec(5, 2) // 5%
DefaultBurnTaxSplit = sdk.NewDecWithPrec(1, 1) // 10% goes to community pool, 90% burn
)
var _ paramstypes.ParamSet = &Params{}
// DefaultParams creates default treasury module parameters
func DefaultParams() Params {
return Params{
TaxPolicy: DefaultTaxPolicy,
RewardPolicy: DefaultRewardPolicy,
SeigniorageBurdenTarget: DefaultSeigniorageBurdenTarget,
MiningIncrement: DefaultMiningIncrement,
WindowShort: DefaultWindowShort,
WindowLong: DefaultWindowLong,
WindowProbation: DefaultWindowProbation,
BurnTaxSplit: DefaultBurnTaxSplit,
}
}
// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramstypes.KeyTable {
return paramstypes.NewKeyTable().RegisterParamSet(&Params{})
}
// String implements fmt.Stringer interface
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of treasury module's parameters.
// nolint
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyTaxPolicy, &p.TaxPolicy, validateTaxPolicy),
paramstypes.NewParamSetPair(KeyRewardPolicy, &p.RewardPolicy, validateRewardPolicy),
paramstypes.NewParamSetPair(KeySeigniorageBurdenTarget, &p.SeigniorageBurdenTarget, validateSeigniorageBurdenTarget),
paramstypes.NewParamSetPair(KeyMiningIncrement, &p.MiningIncrement, validateMiningIncrement),
paramstypes.NewParamSetPair(KeyWindowShort, &p.WindowShort, validateWindowShort),
paramstypes.NewParamSetPair(KeyWindowLong, &p.WindowLong, validateWindowLong),
paramstypes.NewParamSetPair(KeyWindowProbation, &p.WindowProbation, validateWindowProbation),
paramstypes.NewParamSetPair(KeyBurnTaxSplit, &p.BurnTaxSplit, validateBurnTaxSplit),
}
}
// Validate performs basic validation on treasury parameters.
func (p Params) Validate() error {
if p.TaxPolicy.RateMax.LT(p.TaxPolicy.RateMin) {
return fmt.Errorf("treasury TaxPolicy.RateMax %s must be greater than TaxPolicy.RateMin %s",
p.TaxPolicy.RateMax, p.TaxPolicy.RateMin)
}
if p.TaxPolicy.RateMin.IsNegative() {
return fmt.Errorf("treasury parameter TaxPolicy.RateMin must be zero or positive: %s", p.TaxPolicy.RateMin)
}
if !p.TaxPolicy.Cap.IsValid() {
return fmt.Errorf("treasury parameter TaxPolicy.Cap is invalid")
}
if p.TaxPolicy.ChangeRateMax.IsNegative() {
return fmt.Errorf("treasury parameter TaxPolicy.ChangeRateMax must be positive: %s", p.TaxPolicy.ChangeRateMax)
}
if p.RewardPolicy.RateMax.LT(p.RewardPolicy.RateMin) {
return fmt.Errorf("treasury RewardPolicy.RateMax %s must be greater than RewardPolicy.RateMin %s",
p.RewardPolicy.RateMax, p.RewardPolicy.RateMin)
}
if p.RewardPolicy.RateMin.IsNegative() {
return fmt.Errorf("treasury parameter RewardPolicy.RateMin must be positive: %s", p.RewardPolicy.RateMin)
}
if p.RewardPolicy.ChangeRateMax.IsNegative() {
return fmt.Errorf("treasury parameter RewardPolicy.ChangeRateMax must be positive: %s", p.RewardPolicy.ChangeRateMax)
}
if p.SeigniorageBurdenTarget.IsNegative() {
return fmt.Errorf("treasury parameter SeigniorageBurdenTarget must be positive: %s", p.SeigniorageBurdenTarget)
}
if p.MiningIncrement.IsNegative() {
return fmt.Errorf("treasury parameter MiningIncrement must be positive: %s", p.MiningIncrement)
}
if p.WindowLong <= p.WindowShort {
return fmt.Errorf("treasury parameter WindowLong must be bigger than WindowShort: (%d, %d)", p.WindowLong, p.WindowShort)
}
return nil
}
func validateTaxPolicy(i interface{}) error {
v, ok := i.(PolicyConstraints)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.RateMin.IsNegative() {
return fmt.Errorf("rate min must be positive: %s", v)
}
if v.RateMax.LT(v.RateMin) {
return fmt.Errorf("rate max must be bigger than rate min: %s", v)
}
if !v.Cap.IsValid() {
return fmt.Errorf("cap is invalid: %s", v)
}
if v.ChangeRateMax.IsNegative() {
return fmt.Errorf("max change rate must be positive: %s", v)
}
return nil
}
func validateRewardPolicy(i interface{}) error {
v, ok := i.(PolicyConstraints)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.RateMin.IsNegative() {
return fmt.Errorf("rate min must be positive: %s", v)
}
if v.RateMax.LT(v.RateMin) {
return fmt.Errorf("rate max must be bigger than rate min: %s", v)
}
if v.ChangeRateMax.IsNegative() {
return fmt.Errorf("max change rate must be positive: %s", v)
}
return nil
}
func validateSeigniorageBurdenTarget(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNegative() {
return fmt.Errorf("seigniorage burden target must be positive: %s", v)
}
return nil
}
func validateMiningIncrement(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNegative() {
return fmt.Errorf("mining increment must be positive: %s", v)
}
return nil
}
func validateWindowShort(i interface{}) error {
_, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateWindowLong(i interface{}) error {
_, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateWindowProbation(i interface{}) error {
_, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateBurnTaxSplit(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNegative() {
return fmt.Errorf("burn tax split must be positive: %s", v)
}
return nil
}