diff --git a/proto/coreum/customparams/v1/params.proto b/proto/coreum/customparams/v1/params.proto index 1b2f24b60..139597f9c 100644 --- a/proto/coreum/customparams/v1/params.proto +++ b/proto/coreum/customparams/v1/params.proto @@ -1,16 +1,2 @@ -syntax = "proto3"; -package coreum.customparams.v1; -import "gogoproto/gogo.proto"; -option go_package = "github.com/CoreumFoundation/coreum/v6/x/customparams/types"; - -// StakingParams defines the set of additional staking params for the staking module wrapper. -message StakingParams { - // min_self_delegation is the validators global self declared minimum for delegation. - string min_self_delegation = 1 [ - (gogoproto.moretags) = "yaml:\"min_self_delegation\"", - (gogoproto.customtype) = "cosmossdk.io/math.Int", - (gogoproto.nullable) = false - ]; -} diff --git a/x/customparams/types/params.go b/x/customparams/types/params.go index acdb51948..ea4cada97 100644 --- a/x/customparams/types/params.go +++ b/x/customparams/types/params.go @@ -2,35 +2,44 @@ package types import ( sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" // <--- 1. ADD THIS IMPORT paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/pkg/errors" ) -// ParamStoreKeyMinSelfDelegation defines the param key for the min_self_delegation param. -var ParamStoreKeyMinSelfDelegation = []byte("minselfdelegation") +// 2. ADD THE NEW KEY HERE +var ( + ParamStoreKeyMinSelfDelegation = []byte("minselfdelegation") + ParamStoreKeyMinCommissionRate = []byte("mincommissionrate") +) // StakingParamKeyTable returns the parameter key table. func StakingParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&StakingParams{}) } -// DefaultStakingParams returns default staking parameters. +// 3. UPDATE DEFAULT PARAMS HERE func DefaultStakingParams() StakingParams { return StakingParams{ MinSelfDelegation: sdkmath.OneInt(), + MinCommissionRate: sdk.NewDecWithPrec(5, 2), // Sets default to 5% } } -// ParamSetPairs returns the parameter set pairs. +// 4. REGISTER THE NEW PARAMETER HERE func (p *StakingParams) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(ParamStoreKeyMinSelfDelegation, &p.MinSelfDelegation, validateMinSelfDelegation), + paramtypes.NewParamSetPair(ParamStoreKeyMinCommissionRate, &p.MinCommissionRate, validateMinCommissionRate), } } // ValidateBasic performs basic validation on staking parameters. func (p StakingParams) ValidateBasic() error { - return validateMinSelfDelegation(p.MinSelfDelegation) + if err := validateMinSelfDelegation(p.MinSelfDelegation); err != nil { + return err + } + return validateMinCommissionRate(p.MinCommissionRate) } func validateMinSelfDelegation(i interface{}) error { @@ -48,3 +57,28 @@ func validateMinSelfDelegation(i interface{}) error { return nil } + +// validateMinCommissionRate enforces the 5% floor +func validateMinCommissionRate(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return errors.Errorf("invalid parameter type: %T", i) + } + + if v.IsNil() { + return errors.New("param min_commission_rate must be not nil") + } + + // Define the 5% floor (0.05) + minAllowed := sdk.NewDecWithPrec(5, 2) + + if v.LT(minAllowed) { + return errors.Errorf("param min_commission_rate cannot be lower than %s (5%%)", minAllowed) + } + + if v.GT(sdk.OneDec()) { + return errors.New("param min_commission_rate cannot be greater than 1 (100%)") + } + + return nil +}