Skip to content

Commit

Permalink
Feat/incentive param (#296)
Browse files Browse the repository at this point in the history
* chore: update incentive module update param gov tx and set LM defaultmax APR to 50

* chore: add incentive module param migrator

* chore: fix unit test failure in incentive module

* chore: update newParam function to receive parameters

---------

Co-authored-by: kenta-elys <kenta@elys.enetwork>
  • Loading branch information
kenta-elys and kenta-elys authored Dec 11, 2023
1 parent 5201e91 commit 2f6d10e
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 113 deletions.
14 changes: 9 additions & 5 deletions proto/elys/incentive/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ message MsgUpdateIncentiveParams {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
int64 elysStakeTrackingRate = 5;
string maxEdenRewardAprStakers = 6 [
string rewardPortionForStakers = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string maxEdenRewardAprLps = 7 [
int64 elysStakeTrackingRate = 6;
string maxEdenRewardAprStakers = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
int64 distributionEpochForStakers = 8;
int64 distributionEpochForLps = 9;
string maxEdenRewardAprLps = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
int64 distributionEpochForStakers = 9;
int64 distributionEpochForLps = 10;
}

message MsgUpdateIncentiveParamsResponse {}
Expand Down
19 changes: 11 additions & 8 deletions x/incentive/client/cli/tx_update_incentive_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ var _ = strconv.Itoa(0)

func CmdUpdateIncentiveParams() *cobra.Command {
cmd := &cobra.Command{
Use: "update-incentive-params [community-tax] [withdraw-addr-enabled] [reward-portion-for-lps] [elys-stake-tracking-rate] [max-eden-reward-apr-stakers] [max-eden-reward-apr-lps] [distribution-epoch-for-stakers] [distribution-epoch-for-lps]",
Short: "Broadcast message update-incentive-params",
Args: cobra.ExactArgs(8),
Use: "update-incentive-params [community-tax] [withdraw-addr-enabled] [reward-portion-for-lps] [reward-portion-for-stakers] [elys-stake-tracking-rate] [max-eden-reward-apr-stakers] [max-eden-reward-apr-lps] [distribution-epoch-for-stakers] [distribution-epoch-for-lps]",
Short: "Broadcast message update-incentive-params update-incentive-params [community-tax] [withdraw-addr-enabled] [reward-portion-for-lps] [reward-portion-for-stakers] [elys-stake-tracking-rate] [max-eden-reward-apr-stakers] [max-eden-reward-apr-lps] [distribution-epoch-for-stakers] [distribution-epoch-for-lps]",
Args: cobra.ExactArgs(9),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argCommunityTax := args[0]
argWithdrawAddrEnabled := args[1]
argRewardPortionForLps := args[2]
argElysStakeTrackingRate := args[3]
argMaxEdenRewardAprStakers := args[4]
argMaxEdenRewardAprLps := args[5]
argDistributionEpochForStakers := args[6]
argDistributionEpochForLps := args[7]
argRewardPortionForStakers := args[3]
argElysStakeTrackingRate := args[4]
argMaxEdenRewardAprStakers := args[5]
argMaxEdenRewardAprLps := args[6]
argDistributionEpochForStakers := args[7]
argDistributionEpochForLps := args[8]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down Expand Up @@ -63,6 +64,7 @@ func CmdUpdateIncentiveParams() *cobra.Command {
return err
}
rewardPortionForLps := sdk.MustNewDecFromStr(argRewardPortionForLps)
rewardPortionForStakers := sdk.MustNewDecFromStr(argRewardPortionForStakers)
elysStakeTrackingRate, err := strconv.ParseInt(argElysStakeTrackingRate, 10, 64)
if err != nil {
return err
Expand All @@ -84,6 +86,7 @@ func CmdUpdateIncentiveParams() *cobra.Command {
communityTax,
withdarwAddrEnabled,
rewardPortionForLps,
rewardPortionForStakers,
elysStakeTrackingRate,
maxEdenRewardAprStakers,
maxEdenRewardLps,
Expand Down
3 changes: 2 additions & 1 deletion x/incentive/client/cli/tx_update_incentive_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func TestGovUpdateIncentiveParams(t *testing.T) {
args := []string{
"0.00",
"true",
"0.65",
"0.60",
"0.30",
"10",
"0.30",
"0.30",
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/migrations/v2_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V2Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v3_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V3Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v4_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V4Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v5_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V5Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v6_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V6Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v7_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V7Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
2 changes: 1 addition & 1 deletion x/incentive/migrations/v8_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func (m Migrator) V8Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.NewParams())
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
11 changes: 11 additions & 0 deletions x/incentive/migrations/v9_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/incentive/types"
)

func (m Migrator) V9Migration(ctx sdk.Context) error {
m.keeper.SetParams(ctx, types.DefaultParams())
return nil
}
4 changes: 2 additions & 2 deletions x/incentive/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 7, m.V8Migration)
err := cfg.RegisterMigration(types.ModuleName, 8, m.V9Migration)
if err != nil {
panic(err)
}
Expand All @@ -137,7 +137,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 8 }
func (AppModule) ConsensusVersion() uint64 { return 9 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
Expand Down
9 changes: 8 additions & 1 deletion x/incentive/types/message_update_incentive_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const TypeMsgUpdateIncentiveParams = "update_incentive_params"

var _ sdk.Msg = &MsgUpdateIncentiveParams{}

func NewMsgUpdateIncentiveParams(creator string, communityTax sdk.Dec, withdrawAddrEnabled bool, rewardPortionForLps sdk.Dec, elysStakeTrackingRate int64, maxEdenRewardAprStakers sdk.Dec, maxEdenRewardParLps sdk.Dec, distributionEpochForStakers int64, distributionEpochForLps int64) *MsgUpdateIncentiveParams {
func NewMsgUpdateIncentiveParams(creator string, communityTax sdk.Dec, withdrawAddrEnabled bool, rewardPortionForLps sdk.Dec, rewardPortionForStakers sdk.Dec, elysStakeTrackingRate int64, maxEdenRewardAprStakers sdk.Dec, maxEdenRewardParLps sdk.Dec, distributionEpochForStakers int64, distributionEpochForLps int64) *MsgUpdateIncentiveParams {
return &MsgUpdateIncentiveParams{
Authority: creator,
CommunityTax: communityTax,
WithdrawAddrEnabled: withdrawAddrEnabled,
RewardPortionForLps: rewardPortionForLps,
RewardPortionForStakers: rewardPortionForStakers,
ElysStakeTrackingRate: elysStakeTrackingRate,
MaxEdenRewardAprStakers: maxEdenRewardAprStakers,
MaxEdenRewardAprLps: maxEdenRewardParLps,
Expand Down Expand Up @@ -54,6 +55,12 @@ func (msg *MsgUpdateIncentiveParams) ValidateBasic() error {
if msg.RewardPortionForLps.GT(sdk.NewDec(1)) {
return sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "invalid rewards portion for LPs (%s)", errors.New("Invalid LP portion"))
}
if msg.RewardPortionForStakers.GT(sdk.NewDec(1)) {
return sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "invalid rewards portion for Stakers (%s)", errors.New("Invalid Staker portion"))
}
if msg.RewardPortionForLps.Add(msg.RewardPortionForStakers).GT(sdk.NewDec(1)) {
return sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "invalid rewards portion for Stakers and LPs (%s)", errors.New("Invalid Staker and LP portion"))
}
if msg.MaxEdenRewardAprStakers.LT(sdk.ZeroDec()) {
return sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "invalid max eden rewards apr for stakers (%s)", errors.New("Invalid Rewards APR"))
}
Expand Down
6 changes: 4 additions & 2 deletions x/incentive/types/message_update_incentive_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func TestMsgUpdateIncentiveParams_ValidateBasic(t *testing.T) {
name: "invalid address",
msg: MsgUpdateIncentiveParams{
Authority: "invalid_address",
RewardPortionForLps: sdk.NewDecWithPrec(65, 2),
RewardPortionForLps: sdk.NewDecWithPrec(60, 2),
RewardPortionForStakers: sdk.NewDecWithPrec(30, 2),
MaxEdenRewardAprStakers: sdk.NewDecWithPrec(3, 1),
MaxEdenRewardAprLps: sdk.NewDecWithPrec(3, 1),
DistributionEpochForStakers: 10,
Expand All @@ -31,7 +32,8 @@ func TestMsgUpdateIncentiveParams_ValidateBasic(t *testing.T) {
name: "valid address",
msg: MsgUpdateIncentiveParams{
Authority: sample.AccAddress(),
RewardPortionForLps: sdk.NewDecWithPrec(65, 2),
RewardPortionForLps: sdk.NewDecWithPrec(60, 2),
RewardPortionForStakers: sdk.NewDecWithPrec(30, 2),
MaxEdenRewardAprStakers: sdk.NewDecWithPrec(3, 1),
MaxEdenRewardAprLps: sdk.NewDecWithPrec(3, 1),
DistributionEpochForStakers: 10,
Expand Down
72 changes: 51 additions & 21 deletions x/incentive/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,66 @@ func ParamKeyTable() paramtypes.KeyTable {
}

// NewParams creates a new Params instance
func NewParams() Params {
func NewParams(
lpIncentives []IncentiveInfo,
stkIncentives []IncentiveInfo,
communityTax sdk.Dec,
withdrawAddrEnabled bool,
rewardPortionForLps sdk.Dec,
rewardPortionForStakers sdk.Dec,
poolInfos []PoolInfo,
elysStakeTrackingRate int64,
dexRewardsStakers DexRewardsTracker,
dexRewardsLps DexRewardsTracker,
maxEdenRewardAprStakers sdk.Dec,
maxEdenRewardAprLps sdk.Dec,
distributionEpochForStakersInBlocks int64,
distributionEpochForLPsInBlocks int64,
) Params {
return Params{
LpIncentives: []IncentiveInfo(nil),
StakeIncentives: []IncentiveInfo(nil),
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
WithdrawAddrEnabled: true,
RewardPortionForLps: sdk.NewDecWithPrec(60, 2),
RewardPortionForStakers: sdk.NewDecWithPrec(30, 2),
PoolInfos: []PoolInfo(nil),
ElysStakeTrackingRate: 10,
DexRewardsStakers: DexRewardsTracker{
LpIncentives: lpIncentives,
StakeIncentives: stkIncentives,
CommunityTax: communityTax,
WithdrawAddrEnabled: withdrawAddrEnabled,
RewardPortionForLps: rewardPortionForLps,
RewardPortionForStakers: rewardPortionForStakers,
PoolInfos: poolInfos,
ElysStakeTrackingRate: elysStakeTrackingRate,
DexRewardsStakers: dexRewardsStakers,
DexRewardsLps: dexRewardsLps,
MaxEdenRewardAprStakers: maxEdenRewardAprStakers,
MaxEdenRewardAprLps: maxEdenRewardAprLps,
DistributionEpochForStakersInBlocks: distributionEpochForStakersInBlocks,
DistributionEpochForLpsInBlocks: distributionEpochForLPsInBlocks,
}
}

// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams(
[]IncentiveInfo(nil),
[]IncentiveInfo(nil),
sdk.NewDecWithPrec(2, 2), // 2%
true,
sdk.NewDecWithPrec(60, 2),
sdk.NewDecWithPrec(30, 2),
[]PoolInfo(nil),
10,
DexRewardsTracker{
NumBlocks: sdk.NewInt(1),
Amount: sdk.ZeroDec(),
AmountCollectedByOtherTracker: sdk.ZeroDec(),
},
DexRewardsLps: DexRewardsTracker{
DexRewardsTracker{
NumBlocks: sdk.NewInt(1),
Amount: sdk.ZeroDec(),
AmountCollectedByOtherTracker: sdk.ZeroDec(),
},
MaxEdenRewardAprStakers: sdk.NewDecWithPrec(3, 1),
MaxEdenRewardAprLps: sdk.NewDecWithPrec(3, 1),
DistributionEpochForStakersInBlocks: 10,
DistributionEpochForLpsInBlocks: 10,
}
}

// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams()
sdk.NewDecWithPrec(3, 1),
sdk.NewDecWithPrec(5, 1),
10,
10,
)
}

// ParamSetPairs get the params.ParamSet
Expand Down
Loading

0 comments on commit 2f6d10e

Please sign in to comment.