152 lines
4.9 KiB
Go
152 lines
4.9 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
params "github.com/cosmos/cosmos-sdk/x/params/subspace"
|
|
)
|
|
|
|
// Default period for deposits & voting
|
|
const (
|
|
DefaultPeriod time.Duration = time.Hour * 24 * 2 // 2 days
|
|
)
|
|
|
|
// Default governance params
|
|
var (
|
|
DefaultMinDepositTokens = sdk.TokensFromConsensusPower(10)
|
|
DefaultQuorum = sdk.NewDecWithPrec(334, 3)
|
|
DefaultThreshold = sdk.NewDecWithPrec(5, 1)
|
|
DefaultVeto = sdk.NewDecWithPrec(334, 3)
|
|
)
|
|
|
|
// Parameter store key
|
|
var (
|
|
ParamStoreKeyDepositParams = []byte("depositparams")
|
|
ParamStoreKeyVotingParams = []byte("votingparams")
|
|
ParamStoreKeyTallyParams = []byte("tallyparams")
|
|
)
|
|
|
|
// ParamKeyTable - Key declaration for parameters
|
|
func ParamKeyTable() params.KeyTable {
|
|
return params.NewKeyTable(
|
|
ParamStoreKeyDepositParams, DepositParams{},
|
|
ParamStoreKeyVotingParams, VotingParams{},
|
|
ParamStoreKeyTallyParams, TallyParams{},
|
|
)
|
|
}
|
|
|
|
// DepositParams defines the params around deposits for governance
|
|
type DepositParams struct {
|
|
MinDeposit sdk.Coins `json:"min_deposit,omitempty" yaml:"min_deposit,omitempty"` // Minimum deposit for a proposal to enter voting period.
|
|
MaxDepositPeriod time.Duration `json:"max_deposit_period,omitempty" yaml:"max_deposit_period,omitempty"` // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
|
|
}
|
|
|
|
// NewDepositParams creates a new DepositParams object
|
|
func NewDepositParams(minDeposit sdk.Coins, maxDepositPeriod time.Duration) DepositParams {
|
|
return DepositParams{
|
|
MinDeposit: minDeposit,
|
|
MaxDepositPeriod: maxDepositPeriod,
|
|
}
|
|
}
|
|
|
|
// DefaultDepositParams default parameters for deposits
|
|
func DefaultDepositParams() DepositParams {
|
|
return NewDepositParams(
|
|
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinDepositTokens)),
|
|
DefaultPeriod,
|
|
)
|
|
}
|
|
|
|
// String implements stringer insterface
|
|
func (dp DepositParams) String() string {
|
|
return fmt.Sprintf(`Deposit Params:
|
|
Min Deposit: %s
|
|
Max Deposit Period: %s`, dp.MinDeposit, dp.MaxDepositPeriod)
|
|
}
|
|
|
|
// Equal checks equality of DepositParams
|
|
func (dp DepositParams) Equal(dp2 DepositParams) bool {
|
|
return dp.MinDeposit.IsEqual(dp2.MinDeposit) && dp.MaxDepositPeriod == dp2.MaxDepositPeriod
|
|
}
|
|
|
|
// TallyParams defines the params around Tallying votes in governance
|
|
type TallyParams struct {
|
|
Quorum sdk.Dec `json:"quorum,omitempty" yaml:"quorum,omitempty"` // Minimum percentage of total stake needed to vote for a result to be considered valid
|
|
Threshold sdk.Dec `json:"threshold,omitempty" yaml:"threshold,omitempty"` // Minimum proportion of Yes votes for proposal to pass. Initial value: 0.5
|
|
Veto sdk.Dec `json:"veto,omitempty" yaml:"veto,omitempty"` // Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
|
|
}
|
|
|
|
// NewTallyParams creates a new TallyParams object
|
|
func NewTallyParams(quorum, threshold, veto sdk.Dec) TallyParams {
|
|
return TallyParams{
|
|
Quorum: quorum,
|
|
Threshold: threshold,
|
|
Veto: veto,
|
|
}
|
|
}
|
|
|
|
// DefaultTallyParams default parameters for tallying
|
|
func DefaultTallyParams() TallyParams {
|
|
return NewTallyParams(DefaultQuorum, DefaultThreshold, DefaultVeto)
|
|
}
|
|
|
|
// String implements stringer insterface
|
|
func (tp TallyParams) String() string {
|
|
return fmt.Sprintf(`Tally Params:
|
|
Quorum: %s
|
|
Threshold: %s
|
|
Veto: %s`,
|
|
tp.Quorum, tp.Threshold, tp.Veto)
|
|
}
|
|
|
|
// VotingParams defines the params around Voting in governance
|
|
type VotingParams struct {
|
|
VotingPeriod time.Duration `json:"voting_period,omitempty" yaml:"voting_period,omitempty"` // Length of the voting period.
|
|
}
|
|
|
|
// NewVotingParams creates a new VotingParams object
|
|
func NewVotingParams(votingPeriod time.Duration) VotingParams {
|
|
return VotingParams{
|
|
VotingPeriod: votingPeriod,
|
|
}
|
|
}
|
|
|
|
// DefaultVotingParams default parameters for voting
|
|
func DefaultVotingParams() VotingParams {
|
|
return NewVotingParams(DefaultPeriod)
|
|
}
|
|
|
|
// String implements stringer interface
|
|
func (vp VotingParams) String() string {
|
|
return fmt.Sprintf(`Voting Params:
|
|
Voting Period: %s`, vp.VotingPeriod)
|
|
}
|
|
|
|
// Params returns all of the governance params
|
|
type Params struct {
|
|
VotingParams VotingParams `json:"voting_params" yaml:"voting_params"`
|
|
TallyParams TallyParams `json:"tally_params" yaml:"tally_params"`
|
|
DepositParams DepositParams `json:"deposit_params" yaml:"deposit_parmas"`
|
|
}
|
|
|
|
func (gp Params) String() string {
|
|
return gp.VotingParams.String() + "\n" +
|
|
gp.TallyParams.String() + "\n" + gp.DepositParams.String()
|
|
}
|
|
|
|
// NewParams creates a new gov Params instance
|
|
func NewParams(vp VotingParams, tp TallyParams, dp DepositParams) Params {
|
|
return Params{
|
|
VotingParams: vp,
|
|
DepositParams: dp,
|
|
TallyParams: tp,
|
|
}
|
|
}
|
|
|
|
// DefaultParams default governance params
|
|
func DefaultParams() Params {
|
|
return NewParams(DefaultVotingParams(), DefaultTallyParams(), DefaultDepositParams())
|
|
}
|