-
Notifications
You must be signed in to change notification settings - Fork 838
/
params.go
176 lines (147 loc) · 4.68 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
// Copyright 2022 Evmos Foundation
// This file is part of the Evmos Network packages.
//
// Evmos is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Evmos packages are distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Evmos packages. If not, see https://github.com/evmos/evmos/blob/main/LICENSE
package types
import (
"errors"
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
evm "github.com/evmos/ethermint/x/evm/types"
)
var ParamsKey = []byte("Params")
var (
DefaultInflationDenom = evm.DefaultEVMDenom
DefaultInflation = true
DefaultExponentialCalculation = ExponentialCalculation{
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 = InflationDistribution{
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%)
}
)
func NewParams(
mintDenom string,
exponentialCalculation ExponentialCalculation,
inflationDistribution InflationDistribution,
enableInflation bool,
) Params {
return Params{
MintDenom: mintDenom,
ExponentialCalculation: exponentialCalculation,
InflationDistribution: inflationDistribution,
EnableInflation: enableInflation,
}
}
// default minting module parameters
func DefaultParams() Params {
return Params{
MintDenom: DefaultInflationDenom,
ExponentialCalculation: DefaultExponentialCalculation,
InflationDistribution: DefaultInflationDistribution,
EnableInflation: DefaultInflation,
}
}
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 validateExponentialCalculation(i interface{}) error {
v, ok := i.(ExponentialCalculation)
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.(InflationDistribution)
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 Params) 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)
}