forked from osmosis-labs/osmosis
/
params.go
257 lines (217 loc) · 7.67 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
251
252
253
254
255
256
257
package types
import (
"errors"
"fmt"
"strings"
epochtypes "github.com/MonikaCat/osmosis/v6/x/epochs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
yaml "gopkg.in/yaml.v2"
)
// Parameter store keys
var (
KeyMintDenom = []byte("MintDenom")
KeyGenesisEpochProvisions = []byte("GenesisEpochProvisions")
KeyEpochIdentifier = []byte("EpochIdentifier")
KeyReductionPeriodInEpochs = []byte("ReductionPeriodInEpochs")
KeyReductionFactor = []byte("ReductionFactor")
KeyPoolAllocationRatio = []byte("PoolAllocationRatio")
KeyDeveloperRewardsReceiver = []byte("DeveloperRewardsReceiver")
KeyMintingRewardsDistributionStartEpoch = []byte("MintingRewardsDistributionStartEpoch")
)
// ParamTable for minting module.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
func NewParams(
mintDenom string, genesisEpochProvisions sdk.Dec, epochIdentifier string,
ReductionFactor sdk.Dec, reductionPeriodInEpochs int64, distrProportions DistributionProportions,
weightedDevRewardsReceivers []WeightedAddress, mintingRewardsDistributionStartEpoch int64,
) Params {
return Params{
MintDenom: mintDenom,
GenesisEpochProvisions: genesisEpochProvisions,
EpochIdentifier: epochIdentifier,
ReductionPeriodInEpochs: reductionPeriodInEpochs,
ReductionFactor: ReductionFactor,
DistributionProportions: distrProportions,
WeightedDeveloperRewardsReceivers: weightedDevRewardsReceivers,
MintingRewardsDistributionStartEpoch: mintingRewardsDistributionStartEpoch,
}
}
// default minting module parameters
func DefaultParams() Params {
return Params{
MintDenom: sdk.DefaultBondDenom,
GenesisEpochProvisions: sdk.NewDec(5000000),
EpochIdentifier: "week", // 1 week
ReductionPeriodInEpochs: 156, // 3 years
ReductionFactor: sdk.NewDecWithPrec(5, 1), // 0.5
DistributionProportions: DistributionProportions{
Staking: sdk.NewDecWithPrec(4, 1), // 0.4
PoolIncentives: sdk.NewDecWithPrec(3, 1), // 0.3
DeveloperRewards: sdk.NewDecWithPrec(2, 1), // 0.2
CommunityPool: sdk.NewDecWithPrec(1, 1), // 0.1
},
WeightedDeveloperRewardsReceivers: []WeightedAddress{},
MintingRewardsDistributionStartEpoch: 0,
}
}
// validate params
func (p Params) Validate() error {
if err := validateMintDenom(p.MintDenom); err != nil {
return err
}
if err := validateGenesisEpochProvisions(p.GenesisEpochProvisions); err != nil {
return err
}
if err := epochtypes.ValidateEpochIdentifierInterface(p.EpochIdentifier); err != nil {
return err
}
if err := validateReductionPeriodInEpochs(p.ReductionPeriodInEpochs); err != nil {
return err
}
if err := validateReductionFactor(p.ReductionFactor); err != nil {
return err
}
if err := validateDistributionProportions(p.DistributionProportions); err != nil {
return err
}
if err := validateWeightedDeveloperRewardsReceivers(p.WeightedDeveloperRewardsReceivers); err != nil {
return err
}
if err := validateMintingRewardsDistributionStartEpoch(p.MintingRewardsDistributionStartEpoch); err != nil {
return err
}
return nil
}
// String implements the Stringer interface.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
// Implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom),
paramtypes.NewParamSetPair(KeyGenesisEpochProvisions, &p.GenesisEpochProvisions, validateGenesisEpochProvisions),
paramtypes.NewParamSetPair(KeyEpochIdentifier, &p.EpochIdentifier, epochtypes.ValidateEpochIdentifierInterface),
paramtypes.NewParamSetPair(KeyReductionPeriodInEpochs, &p.ReductionPeriodInEpochs, validateReductionPeriodInEpochs),
paramtypes.NewParamSetPair(KeyReductionFactor, &p.ReductionFactor, validateReductionFactor),
paramtypes.NewParamSetPair(KeyPoolAllocationRatio, &p.DistributionProportions, validateDistributionProportions),
paramtypes.NewParamSetPair(KeyDeveloperRewardsReceiver, &p.WeightedDeveloperRewardsReceivers, validateWeightedDeveloperRewardsReceivers),
paramtypes.NewParamSetPair(KeyMintingRewardsDistributionStartEpoch, &p.MintingRewardsDistributionStartEpoch, validateMintingRewardsDistributionStartEpoch),
}
}
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 validateGenesisEpochProvisions(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.LT(sdk.ZeroDec()) {
return fmt.Errorf("genesis epoch provision must be non-negative")
}
return nil
}
func validateReductionPeriodInEpochs(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v <= 0 {
return fmt.Errorf("max validators must be positive: %d", v)
}
return nil
}
func validateReductionFactor(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.GT(sdk.NewDec(1)) {
return fmt.Errorf("reduction factor cannot be greater than 1")
}
if v.IsNegative() {
return fmt.Errorf("reduction factor cannot be negative")
}
return nil
}
func validateDistributionProportions(i interface{}) error {
v, ok := i.(DistributionProportions)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.Staking.IsNegative() {
return errors.New("staking distribution ratio should not be negative")
}
if v.PoolIncentives.IsNegative() {
return errors.New("pool incentives distribution ratio should not be negative")
}
if v.DeveloperRewards.IsNegative() {
return errors.New("developer rewards distribution ratio should not be negative")
}
// TODO: Maybe we should allow this :joy:, lets you burn osmo from community pool
// for new chains
if v.CommunityPool.IsNegative() {
return errors.New("community pool distribution ratio should not be negative")
}
totalProportions := v.Staking.Add(v.PoolIncentives).Add(v.DeveloperRewards).Add(v.CommunityPool)
if !totalProportions.Equal(sdk.NewDec(1)) {
return errors.New("total distributions ratio should be 1")
}
return nil
}
func validateWeightedDeveloperRewardsReceivers(i interface{}) error {
v, ok := i.([]WeightedAddress)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
// fund community pool when rewards address is empty
if len(v) == 0 {
return nil
}
weightSum := sdk.NewDec(0)
for i, w := range v {
// we allow address to be "" to go to community pool
if w.Address != "" {
_, err := sdk.AccAddressFromBech32(w.Address)
if err != nil {
return fmt.Errorf("invalid address at %dth", i)
}
}
if !w.Weight.IsPositive() {
return fmt.Errorf("non-positive weight at %dth", i)
}
if w.Weight.GT(sdk.NewDec(1)) {
return fmt.Errorf("more than 1 weight at %dth", i)
}
weightSum = weightSum.Add(w.Weight)
}
if !weightSum.Equal(sdk.NewDec(1)) {
return fmt.Errorf("invalid weight sum: %s", weightSum.String())
}
return nil
}
func validateMintingRewardsDistributionStartEpoch(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 0 {
return fmt.Errorf("start epoch must be non-negative")
}
return nil
}