-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
params.go
155 lines (135 loc) · 4.89 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
package v1
import (
"fmt"
"time"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Default period for deposits & voting
const (
DefaultPeriod time.Duration = time.Hour * 24 * 2 // 2 days
)
// Default governance params
var (
DefaultMinDepositTokens = sdk.NewInt(10000000)
DefaultQuorum = sdk.NewDecWithPrec(334, 3)
DefaultThreshold = sdk.NewDecWithPrec(5, 1)
DefaultVetoThreshold = sdk.NewDecWithPrec(334, 3)
DefaultMinInitialDepositRatio = sdk.ZeroDec()
DefaultBurnProposalPrevote = false // set to false to replicate behavior of when this change was made (0.47)
DefaultBurnVoteQuorom = false // set to false to replicate behavior of when this change was made (0.47)
DefaultBurnVoteVeto = true // set to true to replicate behavior of when this change was made (0.47)
)
// Deprecated: NewDepositParams creates a new DepositParams object
func NewDepositParams(minDeposit sdk.Coins, maxDepositPeriod *time.Duration) DepositParams {
return DepositParams{
MinDeposit: minDeposit,
MaxDepositPeriod: maxDepositPeriod,
}
}
// Deprecated: NewTallyParams creates a new TallyParams object
func NewTallyParams(quorum, threshold, vetoThreshold string) TallyParams {
return TallyParams{
Quorum: quorum,
Threshold: threshold,
VetoThreshold: vetoThreshold,
}
}
// Deprecated: NewVotingParams creates a new VotingParams object
func NewVotingParams(votingPeriod *time.Duration) VotingParams {
return VotingParams{
VotingPeriod: votingPeriod,
}
}
// NewParams creates a new Params instance with given values.
func NewParams(
minDeposit sdk.Coins, maxDepositPeriod, votingPeriod time.Duration,
quorum, threshold, vetoThreshold, minInitialDepositRatio string, burnProposalDeposit, burnVoteQuorum, burnVoteVeto bool,
) Params {
return Params{
MinDeposit: minDeposit,
MaxDepositPeriod: &maxDepositPeriod,
VotingPeriod: &votingPeriod,
Quorum: quorum,
Threshold: threshold,
VetoThreshold: vetoThreshold,
MinInitialDepositRatio: minInitialDepositRatio,
BurnProposalDepositPrevote: burnProposalDeposit,
BurnVoteQuorum: burnVoteQuorum,
BurnVoteVeto: burnVoteVeto,
}
}
// DefaultParams returns the default governance params
func DefaultParams() Params {
return NewParams(
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinDepositTokens)),
DefaultPeriod,
DefaultPeriod,
DefaultQuorum.String(),
DefaultThreshold.String(),
DefaultVetoThreshold.String(),
DefaultMinInitialDepositRatio.String(),
DefaultBurnProposalPrevote,
DefaultBurnVoteQuorom,
DefaultBurnVoteVeto,
)
}
// ValidateBasic performs basic validation on governance parameters.
func (p Params) ValidateBasic() error {
if minDeposit := sdk.Coins(p.MinDeposit); minDeposit.Empty() || !minDeposit.IsValid() {
return fmt.Errorf("invalid minimum deposit: %s", minDeposit)
}
if p.MaxDepositPeriod == nil {
return fmt.Errorf("maximum deposit period must not be nil: %d", p.MaxDepositPeriod)
}
if p.MaxDepositPeriod.Seconds() <= 0 {
return fmt.Errorf("maximum deposit period must be positive: %d", p.MaxDepositPeriod)
}
quorum, err := sdk.NewDecFromStr(p.Quorum)
if err != nil {
return fmt.Errorf("invalid quorum string: %w", err)
}
if quorum.IsNegative() {
return fmt.Errorf("quorom cannot be negative: %s", quorum)
}
if quorum.GT(math.LegacyOneDec()) {
return fmt.Errorf("quorom too large: %s", p.Quorum)
}
threshold, err := sdk.NewDecFromStr(p.Threshold)
if err != nil {
return fmt.Errorf("invalid threshold string: %w", err)
}
if !threshold.IsPositive() {
return fmt.Errorf("vote threshold must be positive: %s", threshold)
}
if threshold.GT(math.LegacyOneDec()) {
return fmt.Errorf("vote threshold too large: %s", threshold)
}
vetoThreshold, err := sdk.NewDecFromStr(p.VetoThreshold)
if err != nil {
return fmt.Errorf("invalid vetoThreshold string: %w", err)
}
if !vetoThreshold.IsPositive() {
return fmt.Errorf("veto threshold must be positive: %s", vetoThreshold)
}
if vetoThreshold.GT(math.LegacyOneDec()) {
return fmt.Errorf("veto threshold too large: %s", vetoThreshold)
}
if p.VotingPeriod == nil {
return fmt.Errorf("voting period must not be nil: %d", p.VotingPeriod)
}
if p.VotingPeriod.Seconds() <= 0 {
return fmt.Errorf("voting period must be positive: %s", p.VotingPeriod)
}
minInitialDepositRatio, err := math.LegacyNewDecFromStr(p.MinInitialDepositRatio)
if err != nil {
return fmt.Errorf("invalid mininum initial deposit ratio of proposal: %w", err)
}
if minInitialDepositRatio.IsNegative() {
return fmt.Errorf("mininum initial deposit ratio of proposal must be positive: %s", minInitialDepositRatio)
}
if minInitialDepositRatio.GT(math.LegacyOneDec()) {
return fmt.Errorf("mininum initial deposit ratio of proposal is too large: %s", minInitialDepositRatio)
}
return nil
}