-
Notifications
You must be signed in to change notification settings - Fork 193
/
params.go
115 lines (100 loc) · 3.25 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
package types
import (
fmt "fmt"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"gopkg.in/yaml.v2"
)
// Default init params
var (
// these are default intervals _in epochs_ NOT in blocks
DefaultDepositInterval uint64 = 30
DefaultDelegateInterval uint64 = 30
DefaultReinvestInterval uint64 = 30
DefaultRewardsInterval uint64 = 30
DefaultExchangeRateInterval uint64 = 30
// you apparantly cannot safely encode floats, so we make commission / 100
DefaultStrideCommission uint64 = 10
// KeyDepositInterval is store's key for the DepositInterval option
KeyDepositInterval = []byte("DepositInterval")
KeyDelegateInterval = []byte("DelegateInterval")
KeyReinvestInterval = []byte("ReinvestInterval")
KeyRewardsInterval = []byte("RewardsInterval")
KeyExchangeRateInterval = []byte("ExchangeRateInterval")
KeyStrideCommission = []byte("StrideCommission")
)
var _ paramtypes.ParamSet = (*Params)(nil)
// ParamKeyTable the param key table for launch module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
// NewParams creates a new Params instance
func NewParams(
deposit_interval uint64,
delegate_interval uint64,
rewards_interval uint64,
exchange_rate_interval uint64,
stride_commission uint64,
withdraw_interval uint64,
) Params {
return Params{
DepositInterval: deposit_interval,
DelegateInterval: delegate_interval,
RewardsInterval: rewards_interval,
ExchangeRateInterval: exchange_rate_interval,
StrideCommission: stride_commission,
ReinvestInterval: withdraw_interval,
}
}
// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams(
DefaultDepositInterval,
DefaultDelegateInterval,
DefaultRewardsInterval,
DefaultExchangeRateInterval,
DefaultStrideCommission,
DefaultReinvestInterval,
)
}
// ParamSetPairs get the params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyDepositInterval, &p.DepositInterval, isPositive),
paramtypes.NewParamSetPair(KeyDelegateInterval, &p.DelegateInterval, isPositive),
paramtypes.NewParamSetPair(KeyRewardsInterval, &p.RewardsInterval, isPositive),
paramtypes.NewParamSetPair(KeyExchangeRateInterval, &p.ExchangeRateInterval, isPositive),
paramtypes.NewParamSetPair(KeyStrideCommission, &p.StrideCommission, isCommission),
paramtypes.NewParamSetPair(KeyReinvestInterval, &p.ReinvestInterval, isPositive),
}
}
func isPositive(i interface{}) error {
ival, ok := i.(uint64)
if !ok {
return fmt.Errorf("parameter not accepted: %T", i)
}
if ival <= 0 {
return fmt.Errorf("parameter must be positive: %d", ival)
}
return nil
}
func isCommission(i interface{}) error {
ival, ok := i.(uint64)
if !ok {
return fmt.Errorf("commission not accepted: %T", i)
}
if ival < 0 {
return fmt.Errorf("commission must be non-negative: %d", ival)
} else if ival > 100 {
return fmt.Errorf("commission must be less than 100: %d", ival)
}
return nil
}
// Validate validates the set of params
func (p Params) Validate() error {
return nil
}
// String implements the Stringer interface.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}