Skip to content

Commit

Permalink
feat(incentives): feature flag to enable/disable epoch end distributi…
Browse files Browse the repository at this point in the history
…on (#1648)
  • Loading branch information
keruch authored Dec 12, 2024
1 parent 29d227f commit c3eaedf
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 35 deletions.
3 changes: 3 additions & 0 deletions proto/dymensionxyz/dymension/incentives/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];
// FeatureFlagEpochEndDistribution enables distribution of gauge rewards
// at the end of each epoch. If disabled, rewards are not distributed.
bool feature_flag_epoch_end_distribution = 5;
}
5 changes: 5 additions & 0 deletions x/incentives/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN
// AfterEpochEnd is the epoch end hook.
func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
params := k.GetParams(ctx)

if !params.FeatureFlagEpochEndDistribution {
return nil
}

if epochIdentifier == params.DistrEpochIdentifier {
// begin distribution if it's start time
gauges := k.GetUpcomingGauges(ctx)
Expand Down
41 changes: 28 additions & 13 deletions x/incentives/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

// Incentives parameters key store.
var (
KeyDistrEpochIdentifier = []byte("DistrEpochIdentifier")
KeyCreateGaugeFee = []byte("CreateGaugeFee")
KeyAddToGaugeFee = []byte("AddToGaugeFee")
KeyAddDenomFee = []byte("AddDenomFee")
KeyDistrEpochIdentifier = []byte("DistrEpochIdentifier")
KeyCreateGaugeFee = []byte("CreateGaugeFee")
KeyAddToGaugeFee = []byte("AddToGaugeFee")
KeyAddDenomFee = []byte("AddDenomFee")
KeyFeatureFlagEpochEndDistribution = []byte("FeatureFlagEpochEndDistribution")
)

// ParamKeyTable returns the key table for the incentive module's parameters.
Expand All @@ -24,22 +25,24 @@ func ParamKeyTable() paramtypes.KeyTable {
}

// NewParams takes an epoch distribution identifier, then returns an incentives Params struct.
func NewParams(distrEpochIdentifier string, createGaugeFee, addToGaugeFee, addDenomFee math.Int) Params {
func NewParams(distrEpochIdentifier string, createGaugeFee, addToGaugeFee, addDenomFee math.Int, ffEpochEndDistribution bool) Params {
return Params{
DistrEpochIdentifier: distrEpochIdentifier,
CreateGaugeBaseFee: createGaugeFee,
AddToGaugeBaseFee: addToGaugeFee,
AddDenomFee: addDenomFee,
DistrEpochIdentifier: distrEpochIdentifier,
CreateGaugeBaseFee: createGaugeFee,
AddToGaugeBaseFee: addToGaugeFee,
AddDenomFee: addDenomFee,
FeatureFlagEpochEndDistribution: ffEpochEndDistribution,
}
}

// DefaultParams returns the default incentives module parameters.
func DefaultParams() Params {
return Params{
DistrEpochIdentifier: DefaultDistrEpochIdentifier,
CreateGaugeBaseFee: DefaultCreateGaugeFee,
AddToGaugeBaseFee: DefaultAddToGaugeFee,
AddDenomFee: DefaultAddDenomFee,
DistrEpochIdentifier: DefaultDistrEpochIdentifier,
CreateGaugeBaseFee: DefaultCreateGaugeFee,
AddToGaugeBaseFee: DefaultAddToGaugeFee,
AddDenomFee: DefaultAddDenomFee,
FeatureFlagEpochEndDistribution: false,
}
}

Expand All @@ -57,6 +60,9 @@ func (p Params) Validate() error {
if err := validateAddDenomFee(p.AddDenomFee); err != nil {
return err
}
if err := validateBool(p.FeatureFlagEpochEndDistribution); err != nil {
return err
}
return nil
}

Expand All @@ -67,6 +73,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyCreateGaugeFee, &p.CreateGaugeBaseFee, validateCreateGaugeFeeInterface),
paramtypes.NewParamSetPair(KeyAddToGaugeFee, &p.AddToGaugeBaseFee, validateAddToGaugeFeeInterface),
paramtypes.NewParamSetPair(KeyAddDenomFee, &p.AddDenomFee, validateAddDenomFee),
paramtypes.NewParamSetPair(KeyFeatureFlagEpochEndDistribution, &p.FeatureFlagEpochEndDistribution, validateBool),
}
}

Expand Down Expand Up @@ -102,3 +109,11 @@ func validateAddDenomFee(i interface{}) error {
}
return nil
}

func validateBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
90 changes: 68 additions & 22 deletions x/incentives/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3eaedf

Please sign in to comment.