forked from evmos/evmos
-
Notifications
You must be signed in to change notification settings - Fork 3
/
params.go
181 lines (150 loc) · 5.06 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
package types
import (
"errors"
"fmt"
"strings"
evm "github.com/EscanBE/evermint/v12/x/evm/types"
"github.com/EscanBE/evermint/v12/x/inflation/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
var _ types.LegacyParams = &V2Params{}
var (
ParamsKey = []byte("Params")
ParamStoreKeyMintDenom = []byte("ParamStoreKeyMintDenom")
ParamStoreKeyExponentialCalculation = []byte("ParamStoreKeyExponentialCalculation")
ParamStoreKeyInflationDistribution = []byte("ParamStoreKeyInflationDistribution")
ParamStoreKeyEnableInflation = []byte("ParamStoreKeyEnableInflation")
)
var (
DefaultInflationDenom = evm.DefaultEVMDenom
DefaultInflation = true
DefaultExponentialCalculation = V2ExponentialCalculation{
A: sdk.NewDec(int64(300_000_000)),
R: sdk.NewDecWithPrec(50, 2), // 50%
C: sdk.NewDec(int64(9_375_000)),
BondingTarget: sdk.NewDecWithPrec(66, 2), // 66%
MaxVariance: sdk.ZeroDec(), // 0%
}
DefaultInflationDistribution = V2InflationDistribution{
StakingRewards: sdk.NewDecWithPrec(533333334, 9), // 0.53 = 40% / (1 - 25%)
UsageIncentives: sdk.NewDecWithPrec(333333333, 9), // 0.33 = 25% / (1 - 25%)
CommunityPool: sdk.NewDecWithPrec(133333333, 9), // 0.13 = 10% / (1 - 25%)
}
)
// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&V2Params{})
}
func NewParams(
mintDenom string,
exponentialCalculation V2ExponentialCalculation,
inflationDistribution V2InflationDistribution,
enableInflation bool,
) V2Params {
return V2Params{
MintDenom: mintDenom,
ExponentialCalculation: exponentialCalculation,
InflationDistribution: inflationDistribution,
EnableInflation: enableInflation,
}
}
func DefaultParams() V2Params {
return V2Params{
MintDenom: DefaultInflationDenom,
ExponentialCalculation: DefaultExponentialCalculation,
InflationDistribution: DefaultInflationDistribution,
EnableInflation: DefaultInflation,
}
}
// Implements params.ParamSet
func (p *V2Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMintDenom, &p.MintDenom, validateMintDenom),
paramtypes.NewParamSetPair(ParamStoreKeyExponentialCalculation, &p.ExponentialCalculation, validateExponentialCalculation),
paramtypes.NewParamSetPair(ParamStoreKeyInflationDistribution, &p.InflationDistribution, validateInflationDistribution),
paramtypes.NewParamSetPair(ParamStoreKeyEnableInflation, &p.EnableInflation, validateBool),
}
}
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")
}
return sdk.ValidateDenom(v)
}
func validateExponentialCalculation(i interface{}) error {
v, ok := i.(V2ExponentialCalculation)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
// validate initial value
if v.A.IsNegative() {
return fmt.Errorf("initial value cannot be negative")
}
// validate reduction factor
if v.R.GT(sdk.NewDec(1)) {
return fmt.Errorf("reduction factor cannot be greater than 1")
}
if v.R.IsNegative() {
return fmt.Errorf("reduction factor cannot be negative")
}
// validate long term inflation
if v.C.IsNegative() {
return fmt.Errorf("long term inflation cannot be negative")
}
// validate bonded target
if v.BondingTarget.GT(sdk.NewDec(1)) {
return fmt.Errorf("bonded target cannot be greater than 1")
}
if !v.BondingTarget.IsPositive() {
return fmt.Errorf("bonded target cannot be zero or negative")
}
// validate max variance
if v.MaxVariance.IsNegative() {
return fmt.Errorf("max variance cannot be negative")
}
return nil
}
func validateInflationDistribution(i interface{}) error {
v, ok := i.(V2InflationDistribution)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.StakingRewards.IsNegative() {
return errors.New("staking distribution ratio must not be negative")
}
if v.UsageIncentives.IsNegative() {
return errors.New("pool incentives distribution ratio must not be negative")
}
if v.CommunityPool.IsNegative() {
return errors.New("community pool distribution ratio must not be negative")
}
totalProportions := v.StakingRewards.Add(v.UsageIncentives).Add(v.CommunityPool)
if !totalProportions.Equal(sdk.NewDec(1)) {
return errors.New("total distributions ratio should be 1")
}
return nil
}
func validateBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func (p V2Params) Validate() error {
if err := validateMintDenom(p.MintDenom); err != nil {
return err
}
if err := validateExponentialCalculation(p.ExponentialCalculation); err != nil {
return err
}
if err := validateInflationDistribution(p.InflationDistribution); err != nil {
return err
}
return validateBool(p.EnableInflation)
}