-
Notifications
You must be signed in to change notification settings - Fork 31
/
params.go
77 lines (64 loc) · 2.15 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
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// Farm params default values
var (
DefaultPoolCreationFee = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5000)) // 5000stake
DefaulttTaxRate = sdk.NewDecWithPrec(4, 1) // 0.4 (40%)
DefaultMaxRewardCategories = uint32(2)
)
// Keys for parameter access
// nolint
var (
KeyPoolCreationFee = []byte("CreatePoolFee")
KeyTaxRate = []byte("TaxRate") // fee key
KeyMaxRewardCategories = []byte("MaxRewardCategories")
)
// NewParams creates a new Params instance
func NewParams(createPoolFee sdk.Coin, maxRewardCategories uint32, taxRate sdk.Dec) Params {
return Params{
PoolCreationFee: createPoolFee,
TaxRate: taxRate,
MaxRewardCategories: maxRewardCategories,
}
}
// ParamSetPairs implements paramstypes.ParamSet
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, validatePoolCreationFee),
paramstypes.NewParamSetPair(KeyMaxRewardCategories, &p.MaxRewardCategories, validateMaxRewardCategories),
paramstypes.NewParamSetPair(KeyTaxRate, &p.TaxRate, validateTaxRate),
}
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return NewParams(DefaultPoolCreationFee, DefaultMaxRewardCategories, DefaulttTaxRate)
}
// Validate validates a set of params
func (p Params) Validate() error {
return validatePoolCreationFee(p.PoolCreationFee)
}
func validatePoolCreationFee(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !v.IsValid() {
return fmt.Errorf("invalid minimum deposit: %s", v)
}
return nil
}
func validateTaxRate(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !v.GT(sdk.ZeroDec()) || !v.LT(sdk.OneDec()) {
return fmt.Errorf("tax rate must be positive and less than 1: %s", v.String())
}
return nil
}
func validateMaxRewardCategories(i interface{}) error { return nil }