Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(incentives): feature flag to enable/disable epoch end distribution #1648

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
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.

5 changes: 4 additions & 1 deletion x/iro/types/iro.pb.go

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

Loading