-
Notifications
You must be signed in to change notification settings - Fork 51
/
params.go
108 lines (90 loc) · 2.32 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
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"gopkg.in/yaml.v2"
)
// NewParams creates a new Params instance
func NewParams(
lpIncentives *IncentiveInfo,
rewardPortionForLps sdk.Dec,
rewardPortionForStakers sdk.Dec,
maxEdenRewardAprLps sdk.Dec,
protocolRevenueAddress string,
) Params {
return Params{
LpIncentives: lpIncentives,
RewardPortionForLps: rewardPortionForLps,
RewardPortionForStakers: rewardPortionForStakers,
MaxEdenRewardAprLps: maxEdenRewardAprLps,
SupportedRewardDenoms: nil,
ProtocolRevenueAddress: protocolRevenueAddress,
}
}
// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams(
nil,
sdk.NewDecWithPrec(60, 2),
sdk.NewDecWithPrec(25, 2),
sdk.NewDecWithPrec(5, 1),
"elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3",
)
}
// Validate validates the set of params
func (p Params) Validate() error {
if err := validateRewardPortionForLps(p.RewardPortionForLps); err != nil {
return err
}
if err := validateLPIncentives(p.LpIncentives); err != nil {
return err
}
return nil
}
// String implements the Stringer interface.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
func validateRewardPortionForLps(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("reward percent for lp must be not nil")
}
if v.IsNegative() {
return fmt.Errorf("reward percent for lp must be positive: %s", v)
}
if v.GT(sdk.OneDec()) {
return fmt.Errorf("reward percent for lp too large: %s", v)
}
return nil
}
func validateLPIncentives(i interface{}) error {
vv, ok := i.(*IncentiveInfo)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if vv == nil {
return nil
}
if vv.EdenAmountPerYear.LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid eden amount per year: %v", vv)
}
if vv.BlocksDistributed.LT(sdk.NewInt(0)) {
return fmt.Errorf("invalid BlocksDistributed: %v", vv)
}
if vv.DistributionStartBlock.LT(sdk.NewInt(0)) {
return fmt.Errorf("invalid DistributionStartBlock: %v", vv)
}
return nil
}
func validateDexRewardsLps(i interface{}) error {
_, ok := i.(DexRewardsTracker)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}