Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions proto/coreum/customparams/v1/params.proto
Original file line number Diff line number Diff line change
@@ -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
];
}
44 changes: 39 additions & 5 deletions x/customparams/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}