From 3bfa6ba02481022bce59a26af8e03d69c92c773d Mon Sep 17 00:00:00 2001 From: Roman Akhtariev Date: Mon, 25 Jul 2022 17:43:11 -0700 Subject: [PATCH] move fee to types and reuse in simulation --- x/incentives/keeper/export_test.go | 7 ------- x/incentives/keeper/gauge.go | 7 ------- x/incentives/keeper/msg_server.go | 4 ++-- x/incentives/keeper/msg_server_test.go | 4 ++-- x/incentives/simulation/operations.go | 11 ++--------- x/incentives/types/gauge.go | 7 +++++++ 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/x/incentives/keeper/export_test.go b/x/incentives/keeper/export_test.go index 47602af7137..9eeb06ac191 100644 --- a/x/incentives/keeper/export_test.go +++ b/x/incentives/keeper/export_test.go @@ -6,13 +6,6 @@ import ( "github.com/osmosis-labs/osmosis/v10/x/incentives/types" ) -var ( - // CreateGaugeFee is the fee required to create a new gauge. - CreateGaugeFee = createGaugeFee - // AddToGagugeFee is the fee required to add to gauge. - AddToGaugeFee = addToGaugeFee -) - // AddGaugeRefByKey appends the provided gauge ID into an array associated with the provided key. func (k Keeper) AddGaugeRefByKey(ctx sdk.Context, key []byte, gaugeID uint64) error { return k.addGaugeRefByKey(ctx, key, gaugeID) diff --git a/x/incentives/keeper/gauge.go b/x/incentives/keeper/gauge.go index cf4dc318c4a..8a8638bc243 100644 --- a/x/incentives/keeper/gauge.go +++ b/x/incentives/keeper/gauge.go @@ -19,13 +19,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var ( - // createGaugeFee is the fee required to create a new gauge. - createGaugeFee = sdk.NewInt(50 * 1_000_000) - // addToGagugeFee is the fee required to add to gauge. - addToGaugeFee = sdk.NewInt(25 * 1_000_000) -) - // getGaugesFromIterator iterates over everything in a gauge's iterator, until it reaches the end. Return all gauges iterated over. func (k Keeper) getGaugesFromIterator(ctx sdk.Context, iterator db.Iterator) []types.Gauge { gauges := []types.Gauge{} diff --git a/x/incentives/keeper/msg_server.go b/x/incentives/keeper/msg_server.go index f936c19f967..c966ab5f4bb 100644 --- a/x/incentives/keeper/msg_server.go +++ b/x/incentives/keeper/msg_server.go @@ -33,7 +33,7 @@ func (server msgServer) CreateGauge(goCtx context.Context, msg *types.MsgCreateG return nil, err } - if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, createGaugeFee, msg.Coins); err != nil { + if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, types.CreateGaugeFee, msg.Coins); err != nil { return nil, err } @@ -61,7 +61,7 @@ func (server msgServer) AddToGauge(goCtx context.Context, msg *types.MsgAddToGau return nil, err } - if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, addToGaugeFee, msg.Rewards); err != nil { + if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, types.AddToGaugeFee, msg.Rewards); err != nil { return nil, err } err = server.keeper.AddToGaugeRewards(ctx, owner, msg.Rewards, msg.GaugeId) diff --git a/x/incentives/keeper/msg_server_test.go b/x/incentives/keeper/msg_server_test.go index f744a01a580..497a5d2d92b 100644 --- a/x/incentives/keeper/msg_server_test.go +++ b/x/incentives/keeper/msg_server_test.go @@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestCreateGauge_Fee() { if tc.expectErr { suite.Require().Equal(tc.accountBalanceToFund.String(), balanceAmount.String(), "test: %v", tc.name) } else { - fee := sdk.NewCoins(sdk.NewCoin(appparams.BaseCoinUnit, keeper.CreateGaugeFee)) + fee := sdk.NewCoins(sdk.NewCoin(appparams.BaseCoinUnit, types.CreateGaugeFee)) accountBalance := tc.accountBalanceToFund.Sub(tc.gaugeAddition) finalAccountBalance := accountBalance.Sub(fee) suite.Require().Equal(finalAccountBalance.String(), balanceAmount.String(), "test: %v", tc.name) @@ -234,7 +234,7 @@ func (suite *KeeperTestSuite) TestAddToGauge_Fee() { if tc.expectErr { suite.Require().Equal(tc.accountBalanceToFund.String(), bal.String(), "test: %v", tc.name) } else { - fee := sdk.NewCoins(sdk.NewCoin(appparams.BaseCoinUnit, keeper.AddToGaugeFee)) + fee := sdk.NewCoins(sdk.NewCoin(appparams.BaseCoinUnit, types.AddToGaugeFee)) accountBalance := tc.accountBalanceToFund.Sub(tc.gaugeAddition) finalAccountBalance := accountBalance.Sub(fee) suite.Require().Equal(finalAccountBalance.String(), bal.String(), "test: %v", tc.name) diff --git a/x/incentives/simulation/operations.go b/x/incentives/simulation/operations.go index f989028dbee..81d4e0854c7 100644 --- a/x/incentives/simulation/operations.go +++ b/x/incentives/simulation/operations.go @@ -30,13 +30,6 @@ const ( OpWeightMsgAddToGauge = "op_weight_msg_add_to_gauge" ) -var ( - // createGaugeFee is the fee required to create a new gauge. - createGaugeFee = sdk.NewInt(50 * 1_000_000) - // addToGagugeFee is the fee required to add to gauge. - addToGaugeFee = sdk.NewInt(25 * 1_000_000) -) - // WeightedOperations returns all the operations from the module with their respective weights. func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak stakingTypes.AccountKeeper, @@ -124,7 +117,7 @@ func SimulateMsgCreateGauge(ak stakingTypes.AccountKeeper, bk stakingTypes.BankK ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) simCoins := bk.SpendableCoins(ctx, simAccount.Address) - if simCoins.Len() <= 0 || simCoins.AmountOf(appparams.BaseCoinUnit).LT(createGaugeFee) { + if simCoins.Len() <= 0 || simCoins.AmountOf(appparams.BaseCoinUnit).LT(types.CreateGaugeFee) { return simtypes.NoOpMsg( types.ModuleName, types.TypeMsgCreateGauge, "Account have no coin"), nil, nil } @@ -163,7 +156,7 @@ func SimulateMsgAddToGauge(ak stakingTypes.AccountKeeper, bk stakingTypes.BankKe ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) simCoins := bk.SpendableCoins(ctx, simAccount.Address) - if simCoins.Len() <= 0 || simCoins.AmountOf(appparams.BaseCoinUnit).LT(addToGaugeFee) { + if simCoins.Len() <= 0 || simCoins.AmountOf(appparams.BaseCoinUnit).LT(types.AddToGaugeFee) { return simtypes.NoOpMsg( types.ModuleName, types.TypeMsgAddToGauge, "Account have no coin"), nil, nil } diff --git a/x/incentives/types/gauge.go b/x/incentives/types/gauge.go index bb0f97d087c..ec3b112d31f 100644 --- a/x/incentives/types/gauge.go +++ b/x/incentives/types/gauge.go @@ -8,6 +8,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +var ( + // CreateGaugeFee is the fee required to create a new gauge. + CreateGaugeFee = sdk.NewInt(50 * 1_000_000) + // AddToGagugeFee is the fee required to add to gauge. + AddToGaugeFee = sdk.NewInt(25 * 1_000_000) +) + // NewGauge creates a new gauge struct given the required gauge parameters. func NewGauge(id uint64, isPerpetual bool, distrTo lockuptypes.QueryCondition, coins sdk.Coins, startTime time.Time, numEpochsPaidOver uint64, filledEpochs uint64, distrCoins sdk.Coins) Gauge { return Gauge{