From a27d903a6792422a62904577d1a04f2db84a6666 Mon Sep 17 00:00:00 2001 From: keruch Date: Wed, 5 Feb 2025 11:47:47 +0800 Subject: [PATCH] module basic, validation, scaffolding tests --- proto/dividends/events.proto | 25 + proto/dividends/gauge.proto | 23 +- proto/dividends/genesis.proto | 2 - proto/dividends/params.proto | 16 - proto/dividends/query.proto | 9 +- proto/dividends/tx.proto | 30 +- testutil/app/app.go | 22 + testutil/app/apptesting/apptesting.go | 2 +- x/dividends/client/cli/query.go | 109 ++++ x/dividends/keeper/allocation.go | 34 +- x/dividends/keeper/grpc_query.go | 2 +- x/dividends/keeper/keeper.go | 7 +- x/dividends/keeper/keeper_test.go | 18 +- x/dividends/keeper/msg_server.go | 86 ++- x/dividends/keeper/msg_server_test.go | 474 ---------------- x/dividends/keeper/storage.go | 8 + x/dividends/keeper/suite_test.go | 248 --------- x/dividends/module.go | 177 ++++++ x/dividends/types/codec.go | 41 ++ x/dividends/types/events.pb.go | 752 ++++++++++++++++++++++++++ x/dividends/types/expected_keepers.go | 9 + x/dividends/types/gauge.go | 60 +- x/dividends/types/gauge.pb.go | 429 +++++++++++---- x/dividends/types/genesis.go | 27 + x/dividends/types/genesis.pb.go | 38 +- x/dividends/types/keys.go | 9 +- x/dividends/types/msgs.go | 32 ++ x/dividends/types/params.go | 30 + x/dividends/types/query.pb.go | 134 ++--- x/dividends/types/tx.pb.go | 577 ++++++++++++++++---- 30 files changed, 2305 insertions(+), 1125 deletions(-) create mode 100644 proto/dividends/events.proto delete mode 100644 proto/dividends/params.proto create mode 100644 x/dividends/client/cli/query.go delete mode 100644 x/dividends/keeper/msg_server_test.go delete mode 100644 x/dividends/keeper/suite_test.go create mode 100644 x/dividends/module.go create mode 100644 x/dividends/types/codec.go create mode 100644 x/dividends/types/events.pb.go create mode 100644 x/dividends/types/genesis.go create mode 100644 x/dividends/types/msgs.go create mode 100644 x/dividends/types/params.go diff --git a/proto/dividends/events.proto b/proto/dividends/events.proto new file mode 100644 index 00000000..5a51ec8f --- /dev/null +++ b/proto/dividends/events.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package rollapp.dividends; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "dividends/gauge.proto"; + +option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; + +message EventUpdateParams { + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + Params new_params = 2 [ (gogoproto.nullable) = false ]; + Params old_params = 3 [ (gogoproto.nullable) = false ]; +} + +message EventCreateGauge { + // Authority is the address that controls the module. + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // query_condition is *where* the gauge rewards are distributed to + QueryCondition query_condition = 2 [ (gogoproto.nullable) = false ]; + // vesting_condition is *how long* the gauge rewards are distributed to + VestingCondition vesting_condition = 3 [ (gogoproto.nullable) = false ]; + // vesting_condition is *how frequent* the gauge rewards are distributed to + VestingFrequency vesting_frequency = 4; +} \ No newline at end of file diff --git a/proto/dividends/gauge.proto b/proto/dividends/gauge.proto index 9fb06fc3..0ce7f2e2 100644 --- a/proto/dividends/gauge.proto +++ b/proto/dividends/gauge.proto @@ -2,12 +2,19 @@ syntax = "proto3"; package rollapp.dividends; import "gogoproto/gogo.proto"; -import "google/protobuf/duration.proto"; -import "google/protobuf/timestamp.proto"; -import "cosmos/base/v1beta1/coin.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; +// Params holds parameters for the incentives module +message Params { + // distr_epoch_identifier is what epoch type distribution will be triggered by + // (day, week, etc.) + string distr_epoch_identifier = 1; + // approved_denoms is a list of allowed tokens: only gov can approve tokens + // that can be used for dividends + repeated string approved_denoms = 2; +} + // Gauge is an object that stores and distributes yields to recipients who // satisfy certain conditions. message Gauge { @@ -16,9 +23,9 @@ message Gauge { // address is a bech32-formatted address that holds the tokens to allocate string address = 2; // query_condition is *where* the gauge rewards are distributed to - QueryCondition query_condition = 3; + QueryCondition query_condition = 3 [ (gogoproto.nullable) = false ]; // vesting_condition is *how long* the gauge rewards are distributed to - VestingCondition vesting_condition = 4; + VestingCondition vesting_condition = 4 [ (gogoproto.nullable) = false ]; // vesting_condition is *how frequent* the gauge rewards are distributed to VestingFrequency vesting_frequency = 5; } @@ -32,7 +39,7 @@ message QueryCondition { message VestingCondition { oneof condition { VestingConditionPerpetual perpetual = 1; - VestingConditionLimited epoch = 2; + VestingConditionLimited limited = 2; } } @@ -61,8 +68,8 @@ message VestingConditionPerpetual {} message VestingConditionLimited { // num_units is the number of total epochs/blocks distribution will be // completed over - uint64 num_units = 1; + int64 num_units = 1; // filled_epochs is the number of epochs/blocks distribution has been // completed on already - uint64 filled_units = 2; + int64 filled_units = 2; } diff --git a/proto/dividends/genesis.proto b/proto/dividends/genesis.proto index 889c961a..85e4840f 100644 --- a/proto/dividends/genesis.proto +++ b/proto/dividends/genesis.proto @@ -2,8 +2,6 @@ syntax = "proto3"; package rollapp.dividends; import "gogoproto/gogo.proto"; -import "google/protobuf/duration.proto"; -import "dividends/params.proto"; import "dividends/gauge.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; diff --git a/proto/dividends/params.proto b/proto/dividends/params.proto deleted file mode 100644 index f13d7c76..00000000 --- a/proto/dividends/params.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; -package rollapp.dividends; - -import "gogoproto/gogo.proto"; - -option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; - -// Params holds parameters for the incentives module -message Params { - // distr_epoch_identifier is what epoch type distribution will be triggered by - // (day, week, etc.) - string distr_epoch_identifier = 1; - // approved_denoms is a list of allowed tokens: only gov can approve tokens - // that can be used for dividends - repeated string approved_denoms = 2; -} diff --git a/proto/dividends/query.proto b/proto/dividends/query.proto index 56ddcab5..0c83a5fa 100644 --- a/proto/dividends/query.proto +++ b/proto/dividends/query.proto @@ -3,11 +3,8 @@ package rollapp.dividends; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "google/protobuf/duration.proto"; -import "cosmos/base/v1beta1/coin.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "dividends/gauge.proto"; -import "dividends/params.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; @@ -31,7 +28,7 @@ message GaugeByIDRequest { } message GaugeByIDResponse { - Gauge gauge = 1; + Gauge gauge = 1 [ (gogoproto.nullable) = false ]; } message GaugesRequest { @@ -39,12 +36,12 @@ message GaugesRequest { } message GaugesResponse { - repeated Gauge data = 1 [(gogoproto.nullable) = false]; + repeated Gauge data = 1 [ (gogoproto.nullable) = false ]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } message ParamsRequest {} message ParamsResponse { - Params params = 1; + Params params = 1 [ (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/dividends/tx.proto b/proto/dividends/tx.proto index 31be5526..818e0471 100644 --- a/proto/dividends/tx.proto +++ b/proto/dividends/tx.proto @@ -2,28 +2,42 @@ syntax = "proto3"; package rollapp.dividends; import "gogoproto/gogo.proto"; -import "google/protobuf/timestamp.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; import "cosmos/base/v1beta1/coin.proto"; import "dividends/gauge.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/dividends/types"; service Msg { + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); rpc CreateGauge(MsgCreateGauge) returns (MsgCreateGaugeResponse); } // MsgCreateGauge creates a gague to distribute rewards to users message MsgCreateGauge { - // id is the unique ID of a gauge - uint64 id = 1; - // address is a bech32-formatted address that holds the tokens to allocate - string address = 2; + option (cosmos.msg.v1.signer) = "authority"; + + // Authority is the address that controls the module. + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; // query_condition is *where* the gauge rewards are distributed to - QueryCondition query_condition = 3; + QueryCondition query_condition = 2 [ (gogoproto.nullable) = false ]; // vesting_condition is *how long* the gauge rewards are distributed to - VestingCondition vesting_condition = 4; + VestingCondition vesting_condition = 3 [ (gogoproto.nullable) = false ]; // vesting_condition is *how frequent* the gauge rewards are distributed to - VestingFrequency vesting_frequency = 5; + VestingFrequency vesting_frequency = 4; } message MsgCreateGaugeResponse {} + +// MsgUpdateParams allows to update module params. +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + // Authority is the address that controls the module. + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // NewParams should be fully populated. + Params new_params = 2 [ (gogoproto.nullable) = false ]; +} + +message MsgUpdateParamsResponse {} diff --git a/testutil/app/app.go b/testutil/app/app.go index 50f9fd6b..59cc9401 100644 --- a/testutil/app/app.go +++ b/testutil/app/app.go @@ -94,6 +94,10 @@ import ( epochskeeper "github.com/dymensionxyz/dymension-rdk/x/epochs/keeper" epochstypes "github.com/dymensionxyz/dymension-rdk/x/epochs/types" + "github.com/dymensionxyz/dymension-rdk/x/dividends" + dividendskeeper "github.com/dymensionxyz/dymension-rdk/x/dividends/keeper" + dividendstypes "github.com/dymensionxyz/dymension-rdk/x/dividends/types" + "github.com/dymensionxyz/dymension-rdk/x/gasless" gaslessclient "github.com/dymensionxyz/dymension-rdk/x/gasless/client" gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper" @@ -151,6 +155,7 @@ var kvstorekeys = []string{ epochstypes.StoreKey, hubgentypes.StoreKey, hubtypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, gaslesstypes.StoreKey, wasmtypes.StoreKey, tokenfactorytypes.StoreKey, rollappparamstypes.StoreKey, timeupgradetypes.StoreKey, + dividendstypes.StoreKey, } func getGovProposalHandlers() []govclient.ProposalHandler { @@ -198,6 +203,7 @@ var ( wasm.AppModuleBasic{}, tokenfactory.NewAppModuleBasic(), rollappparams.AppModuleBasic{}, + dividends.AppModuleBasic{}, ) // module account permissions @@ -214,6 +220,7 @@ var ( wasmtypes.ModuleName: {authtypes.Burner}, rollappparamstypes.ModuleName: nil, tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + dividendstypes.ModuleName: nil, } ) @@ -249,6 +256,7 @@ type App struct { HubKeeper hubkeeper.Keeper HubGenesisKeeper hubgenkeeper.Keeper RollappParamsKeeper rollappparamskeeper.Keeper + DividendsKeeper dividendskeeper.Keeper UpgradeKeeper upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly @@ -409,6 +417,16 @@ func NewRollapp( authtypes.NewModuleAddress(timeupgradetypes.ModuleName).String(), ) + app.DividendsKeeper = dividendskeeper.NewKeeper( + appCodec, + keys[dividendstypes.StoreKey], + app.StakingKeeper, + app.AccountKeeper, + app.DistrKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(timeupgradetypes.ModuleName).String(), + ) + // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks(app.DistrKeeper.Hooks()) @@ -609,6 +627,7 @@ func NewRollapp( hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper), gasless.NewAppModule(appCodec, app.GaslessKeeper), rollappparams.NewAppModule(appCodec, app.RollappParamsKeeper), + dividends.NewAppModule(app.DividendsKeeper), } app.mm = module.NewManager(modules...) @@ -639,6 +658,7 @@ func NewRollapp( tokenfactorytypes.ModuleName, gaslesstypes.ModuleName, rollappparamstypes.ModuleName, + dividendstypes.ModuleName, } app.mm.SetOrderBeginBlockers(beginBlockersList...) @@ -663,6 +683,7 @@ func NewRollapp( tokenfactorytypes.ModuleName, gaslesstypes.ModuleName, rollappparamstypes.ModuleName, + dividendstypes.ModuleName, } app.mm.SetOrderEndBlockers(endBlockersList...) @@ -693,6 +714,7 @@ func NewRollapp( tokenfactorytypes.ModuleName, gaslesstypes.ModuleName, rollappparamstypes.ModuleName, + dividendstypes.ModuleName, } app.mm.SetOrderInitGenesis(initGenesisList...) diff --git a/testutil/app/apptesting/apptesting.go b/testutil/app/apptesting/apptesting.go index 513fea58..9e6fccfb 100644 --- a/testutil/app/apptesting/apptesting.go +++ b/testutil/app/apptesting/apptesting.go @@ -39,7 +39,7 @@ type KeeperTestHelper struct { // Setup sets up basic environment for suite (App, Ctx, and test accounts) func (s *KeeperTestHelper) Setup() { s.App = utils.Setup(s.T(), false) - s.Ctx = s.App.BaseApp.NewContext(false, tmtypes.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()}) + s.Ctx = s.App.BaseApp.NewContext(false, tmtypes.Header{Height: 1, ChainID: "dymension_1234-1", Time: time.Now().UTC()}) s.QueryHelper = &baseapp.QueryServiceTestHelper{ GRPCQueryRouter: s.App.GRPCQueryRouter(), Ctx: s.Ctx, diff --git a/x/dividends/client/cli/query.go b/x/dividends/client/cli/query.go new file mode 100644 index 00000000..f745923f --- /dev/null +++ b/x/dividends/client/cli/query.go @@ -0,0 +1,109 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/dymensionxyz/dymension-rdk/x/dividends/types" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdQueryParams(), + CmdQueryDistribution(), + CmdQueryVote(), + ) + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Get module params", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(cmd.Context(), &types.ParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryDistribution() *cobra.Command { + cmd := &cobra.Command{ + Use: "gauge-by-id [id]", + Short: "Get gauge by ID", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.GaugeByID(cmd.Context(), &types.GaugeByIDRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryVote() *cobra.Command { + cmd := &cobra.Command{ + Use: "gauges", + Short: "Get all gauges", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Gauges(cmd.Context(), &types.GaugesRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dividends/keeper/allocation.go b/x/dividends/keeper/allocation.go index 05f18127..092e9c37 100644 --- a/x/dividends/keeper/allocation.go +++ b/x/dividends/keeper/allocation.go @@ -8,27 +8,42 @@ import ( "github.com/dymensionxyz/dymension-rdk/x/dividends/types" ) -func (k Keeper) Allocate(ctx sdk.Context) error { +func (k Keeper) Allocate(ctx sdk.Context, t types.VestingFrequency) error { var ( totalStakingPower = k.stakingKeeper.GetLastTotalPower(ctx) totalStakingPowerDec = sdk.NewDecFromInt(totalStakingPower) ) err := k.IterateGauges(ctx, func(_ uint64, gauge types.Gauge) (stop bool, err error) { + // Check if it's time to allocate rewards for this gauge + if gauge.VestingFrequency != t { + return false, nil + } + var ( address = sdk.MustAccAddressFromBech32(gauge.Address) - gaugeRewards = sdk.NewDecCoinsFromCoins(k.bankKeeper.GetAllBalances(ctx, address)...) + gaugeBalance = sdk.NewDecCoinsFromCoins(k.bankKeeper.GetAllBalances(ctx, address)...) + gaugeRewards sdk.DecCoins ) - switch gauge.VestingCondition.Condition.(type) { - case *types.VestingCondition_Block: - case *types.VestingCondition_Epoch: + switch c := gauge.VestingCondition.Condition.(type) { + case *types.VestingCondition_Limited: + // Estimate how to evenly distribute rewards through epochs/blocks + if c.Limited.NumUnits >= c.Limited.FilledUnits { + // TODO: remove this gauge, there's nothing to fill anymore + return false, nil + } + + remainingUnits := c.Limited.NumUnits - c.Limited.FilledUnits + gaugeRewards = gaugeBalance.QuoDec(sdk.NewDec(remainingUnits)) + + case *types.VestingCondition_Perpetual: + gaugeRewards = gaugeBalance } switch gauge.QueryCondition.Condition.(type) { case *types.QueryCondition_Stakers: - k.AllocateStakers(ctx, totalStakingPowerDec, gaugeRewards) - case *types.QueryCondition_Funds: + k.AllocateStakers(ctx, gaugeRewards, totalStakingPowerDec) } return false, nil @@ -40,14 +55,15 @@ func (k Keeper) Allocate(ctx sdk.Context) error { return nil } -func (k Keeper) AllocateStakers(ctx sdk.Context, stakingPower sdk.Dec, gaugeRewards sdk.DecCoins) { +func (k Keeper) AllocateStakers(ctx sdk.Context, gaugeRewards sdk.DecCoins, totalStakingPower sdk.Dec) { k.stakingKeeper.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) { var ( valPower = validator.GetConsensusPower(sdk.DefaultPowerReduction) - powerFraction = sdk.NewDec(valPower).QuoTruncate(stakingPower) + powerFraction = sdk.NewDec(valPower).QuoTruncate(totalStakingPower) reward = gaugeRewards.MulDecTruncate(powerFraction) ) + // TODO: send rewards to x/distribution k.distrKeeper.AllocateTokensToValidator(ctx, validator, reward) return false }) diff --git a/x/dividends/keeper/grpc_query.go b/x/dividends/keeper/grpc_query.go index 2f7710c0..69978cf7 100644 --- a/x/dividends/keeper/grpc_query.go +++ b/x/dividends/keeper/grpc_query.go @@ -26,7 +26,7 @@ func (q Querier) GaugeByID(goCtx context.Context, req *types.GaugeByIDRequest) ( ctx := sdk.UnwrapSDKContext(goCtx) - gauge, err := q.keeper.GetGaugeByID(ctx, req.Id) + gauge, err := q.keeper.GetGauge(ctx, req.Id) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/x/dividends/keeper/keeper.go b/x/dividends/keeper/keeper.go index 8b27a24a..c53841e7 100644 --- a/x/dividends/keeper/keeper.go +++ b/x/dividends/keeper/keeper.go @@ -21,6 +21,7 @@ type Keeper struct { gauges collections.Map[uint64, types.Gauge] // GaugeID -> Gauge stakingKeeper types.StakingKeeper + accountKeeper types.AccountKeeper distrKeeper types.DistributionKeeper bankKeeper types.BankKeeper } @@ -29,13 +30,14 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper, + accountKeeper types.AccountKeeper, distrKeeper types.DistributionKeeper, bankKeeper types.BankKeeper, authority string, -) *Keeper { +) Keeper { sb := collections.NewSchemaBuilder(collcompat.NewKVStoreService(storeKey)) - k := &Keeper{ + k := Keeper{ authority: authority, schema: collections.Schema{}, // set later params: collections.NewItem( @@ -57,6 +59,7 @@ func NewKeeper( collcompat.ProtoValue[types.Gauge](cdc), ), stakingKeeper: stakingKeeper, + accountKeeper: accountKeeper, distrKeeper: distrKeeper, bankKeeper: bankKeeper, } diff --git a/x/dividends/keeper/keeper_test.go b/x/dividends/keeper/keeper_test.go index 42c2c19f..a3b0e435 100644 --- a/x/dividends/keeper/keeper_test.go +++ b/x/dividends/keeper/keeper_test.go @@ -2,13 +2,10 @@ package keeper_test import ( "testing" - "time" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/dymensionxyz/dymension-rdk/testutil/app/apptesting" + "github.com/dymensionxyz/dymension-rdk/x/dividends/keeper" "github.com/stretchr/testify/suite" - - "github.com/dymensionxyz/dymension/v3/app/apptesting" - "github.com/dymensionxyz/dymension/v3/x/incentives/keeper" ) type KeeperTestSuite struct { @@ -23,14 +20,7 @@ func TestKeeperTestSuite(t *testing.T) { // SetupTest sets incentives parameters from the suite's context func (suite *KeeperTestSuite) SetupTest() { - app := apptesting.Setup(suite.T()) - ctx := app.GetBaseApp().NewContext(false, tmproto.Header{}) - - suite.App = app - suite.Ctx = ctx + suite.Setup() - suite.querier = keeper.NewQuerier(*suite.App.IncentivesKeeper) - lockableDurations := suite.App.IncentivesKeeper.GetLockableDurations(suite.Ctx) - lockableDurations = append(lockableDurations, 2*time.Second) - suite.App.IncentivesKeeper.SetLockableDurations(suite.Ctx, lockableDurations) + suite.querier = keeper.NewQuerier(suite.App.DividendsKeeper) } diff --git a/x/dividends/keeper/msg_server.go b/x/dividends/keeper/msg_server.go index 52b65791..6963c295 100644 --- a/x/dividends/keeper/msg_server.go +++ b/x/dividends/keeper/msg_server.go @@ -5,6 +5,9 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/dymensionxyz/dymension-rdk/utils/uevent" "github.com/dymensionxyz/dymension-rdk/x/dividends/types" ) @@ -19,24 +22,89 @@ func NewMsgServer(keeper Keeper) types.MsgServer { var _ types.MsgServer = msgServer{} // CreateGauge creates a gauge. -func (s msgServer) CreateGauge(goCtx context.Context, msg *types.MsgCreateGauge) (*types.MsgCreateGaugeResponse, error) { +func (m msgServer) CreateGauge(goCtx context.Context, msg *types.MsgCreateGauge) (*types.MsgCreateGaugeResponse, error) { + err := msg.ValidateBasic() + if err != nil { + return nil, err + } + + if msg.Authority != m.keeper.authority { + return nil, sdkerrors.ErrorInvalidSigner.Wrapf("Only the gov module can update params") + } + ctx := sdk.UnwrapSDKContext(goCtx) - // TODO: validate query and vesting conditions + gaugeId, err := m.keeper.NextGaugeId(ctx) + if err != nil { + return nil, fmt.Errorf("next gauge ID: %w", err) + } + + account := m.keeper.CreateModuleAccountForGauge(ctx, gaugeId) - gauge := types.NewGauge(msg.Id, msg.Address, msg.QueryCondition, msg.VestingCondition) + // TODO: validate query and vesting conditions and vesting frequency + // TODO: create a sequential ID and a new module address. Also, add vesting frequency - err := s.keeper.gauges.Set(ctx, gauge.Id, gauge) + gauge := types.NewGauge( + gaugeId, + account.GetAddress().String(), + msg.QueryCondition, + msg.VestingCondition, + msg.VestingFrequency, + ) + + err = m.keeper.SetGauge(ctx, gauge) if err != nil { return nil, fmt.Errorf("set gauge: %w", err) } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.TypeEvtCreateGauge, - sdk.NewAttribute(types.AttributeGaugeID, osmoutils.Uint64ToString(gaugeID)), - ), + err = uevent.EmitTypedEvent(ctx, &types.EventCreateGauge{ + Authority: msg.Authority, + QueryCondition: msg.QueryCondition, + VestingCondition: msg.VestingCondition, + VestingFrequency: msg.VestingFrequency, }) + if err != nil { + return nil, fmt.Errorf("emit event: %w", err) + } return &types.MsgCreateGaugeResponse{}, nil } + +func (k Keeper) CreateModuleAccountForGauge(ctx sdk.Context, gaugeId uint64) authtypes.ModuleAccountI { + moduleAccountName := fmt.Sprintf("%s-%d", types.ModuleName, gaugeId) + moduleAccount := authtypes.NewEmptyModuleAccount(moduleAccountName) + moduleAccountI := k.accountKeeper.NewAccount(ctx, moduleAccount).(authtypes.ModuleAccountI) + k.accountKeeper.SetModuleAccount(ctx, moduleAccountI) + return moduleAccountI +} + +func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + err := msg.ValidateBasic() + if err != nil { + return nil, err + } + + if msg.Authority != m.keeper.authority { + return nil, sdkerrors.ErrorInvalidSigner.Wrapf("Only the gov module can update params") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + oldParams := m.keeper.MustGetParams(ctx) + + err = m.keeper.SetParams(ctx, msg.NewParams) + if err != nil { + return nil, err + } + + err = uevent.EmitTypedEvent(ctx, &types.EventUpdateParams{ + Authority: msg.Authority, + NewParams: msg.NewParams, + OldParams: oldParams, + }) + if err != nil { + return nil, fmt.Errorf("emit event: %w", err) + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/dividends/keeper/msg_server_test.go b/x/dividends/keeper/msg_server_test.go deleted file mode 100644 index f27e8a66..00000000 --- a/x/dividends/keeper/msg_server_test.go +++ /dev/null @@ -1,474 +0,0 @@ -package keeper_test - -import ( - "time" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/suite" - - "github.com/osmosis-labs/osmosis/v15/x/txfees" - - "github.com/dymensionxyz/dymension/v3/app/apptesting" - "github.com/dymensionxyz/dymension/v3/x/incentives/keeper" - "github.com/dymensionxyz/dymension/v3/x/incentives/types" - lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types" -) - -var _ = suite.TestingSuite(nil) - -func (suite *KeeperTestSuite) TestCreateGauge() { - tests := []struct { - name string - accountBalanceToFund sdk.Coins - gaugeAddition sdk.Coins - isPerpetual bool - isModuleAccount bool - expectErr bool - }{ - { - name: "user creates a non-perpetual gauge and fills gauge with all remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(6)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(1)))), - }, - { - name: "user creates a non-perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(7)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(1)))), - }, - { - name: "user with multiple denoms creates a non-perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(7))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(7)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(1)))), - }, - { - name: "user tries to create a non-perpetual gauge but includes too many denoms so does not have enough funds to pay fees - 1", - accountBalanceToFund: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(40))), // 40 >= 2 (adym) + 1 (creation fee) + 1 (for every denom) = 4 - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(2))), - ), - gaugeAddition: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(2))), - ), - }, - { - name: "module account creates a perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(7))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(1)))), - isPerpetual: true, - isModuleAccount: true, - }, - { - name: "user with multiple denoms creates a perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(7))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(1)))), - isPerpetual: true, - }, - { - name: "user tries to create a non-perpetual gauge but does not have enough funds to pay for the create gauge fee", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(5))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1))), - expectErr: true, - }, - { - name: "user tries to create a non-perpetual gauge but does not have the correct fee denom", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(6)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(1)))), - expectErr: true, - }, - { - name: "user tries to create a non-perpetual gauge but includes too many denoms so does not have enough funds to pay fees - 2", - accountBalanceToFund: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(3))), // 3 < 2 (adym) + 1 (creation fee) + 1 (for every denom) = 4 - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(2))), - ), - gaugeAddition: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(2))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(2))), - ), - expectErr: true, - }, - { - name: "one user tries to create a gauge, has enough funds to pay for the create gauge fee but not enough to fill the gauge", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(2)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(3)))), - expectErr: true, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - suite.SetupTest() - - testAccountPubkey := secp256k1.GenPrivKeyFromSecret([]byte("acc")).PubKey() - testAccountAddress := sdk.AccAddress(testAccountPubkey.Address()) - - ctx := suite.Ctx - bankKeeper := suite.App.BankKeeper - accountKeeper := suite.App.AccountKeeper - msgServer := keeper.NewMsgServerImpl(suite.App.IncentivesKeeper) - - suite.FundAcc(testAccountAddress, tc.accountBalanceToFund) - - if tc.isModuleAccount { - modAcc := authtypes.NewModuleAccount(authtypes.NewBaseAccount(testAccountAddress, testAccountPubkey, 1, 0), - "module", - "permission", - ) - accountKeeper.SetModuleAccount(ctx, modAcc) - } - - suite.SetupManyLocks(1, defaultLiquidTokens, defaultLPTokens, defaultLockDuration) - distrTo := lockuptypes.QueryCondition{ - LockQueryType: lockuptypes.ByDuration, - Denom: defaultLPDenom, - Duration: defaultLockDuration, - } - - msg := &types.MsgCreateGauge{ - IsPerpetual: tc.isPerpetual, - Owner: testAccountAddress.String(), - DistributeTo: distrTo, - Coins: tc.gaugeAddition, - StartTime: time.Now(), - NumEpochsPaidOver: 1, - } - txfeesBalanceBefore := bankKeeper.GetBalance(ctx, accountKeeper.GetModuleAddress(txfees.ModuleName), "stake") - - // System under test. - _, err := msgServer.CreateGauge(sdk.WrapSDKContext(ctx), msg) - - if tc.expectErr { - suite.Require().Error(err, "test: %v", tc.name) - } else { - suite.Require().NoError(err, "test: %v", tc.name) - } - - balanceAmount := bankKeeper.GetAllBalances(ctx, testAccountAddress) - - if tc.expectErr { - suite.Require().Equal(tc.accountBalanceToFund.String(), balanceAmount.String(), "test: %v", tc.name) - } else { - // Fee = CreateGaugeBaseFee + AddDenomFee * NumDenoms - params := suite.querier.GetParams(suite.Ctx) - feeRaw := params.CreateGaugeBaseFee.Add(params.AddDenomFee.MulRaw(int64(len(tc.gaugeAddition)))) - fee := sdk.NewCoins(sdk.NewCoin("stake", feeRaw)) - - accountBalance := tc.accountBalanceToFund.Sub(tc.gaugeAddition...) - finalAccountBalance := accountBalance.Sub(fee...) - suite.Require().Equal(finalAccountBalance.String(), balanceAmount.String(), "test: %v", tc.name) - - // test fee charged to txfees module account and burned - txfeesBalanceAfter := bankKeeper.GetBalance(ctx, accountKeeper.GetModuleAddress(txfees.ModuleName), "stake") - suite.Require().Equal(txfeesBalanceBefore.Amount, txfeesBalanceAfter.Amount, "test: %v", tc.name) - } - }) - } -} - -func (suite *KeeperTestSuite) TestAddToGauge() { - tests := []struct { - name string - accountBalanceToFund sdk.Coins - gaugeAddition sdk.Coins - isPerpetual bool - isModuleAccount bool - expectErr bool - }{ - { - name: "user creates a non-perpetual gauge and fills gauge with all remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(35)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(10)))), - }, - { - name: "user creates a non-perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(10)))), - }, - { - name: "user with multiple denoms creates a non-perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(70))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(10)))), - }, - { - name: "user adds to a non-perpetual gauge including many denoms", - accountBalanceToFund: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(31))), // 31 >= 20 (adym) + 10 (denoms) + 1 (initial denom) = 31 - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(20))), - ), - gaugeAddition: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(20))), - ), - }, - { - name: "module account creates a perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(70))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(10)))), - isPerpetual: true, - isModuleAccount: true, - }, - { - name: "user with multiple denoms creates a perpetual gauge and fills gauge with some remaining tokens", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(70))), sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(70)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(10)))), - isPerpetual: true, - }, - { - name: "user tries to add to a non-perpetual gauge but does not have enough funds to pay for the create gauge fee", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(20)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(20)))), - expectErr: true, - }, - { - name: "user tries to add to a non-perpetual gauge but includes too many denoms so does not have enough funds to pay fees", - accountBalanceToFund: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(30))), // 30 < 20 (adym) + 10 (denoms) + 1 (initial denom) = 31 - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(20))), - ), - gaugeAddition: sdk.NewCoins( - sdk.NewCoin("stake", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("osmo", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("atom", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("abcd", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("efgh", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("igkl", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("mnop", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("qrst", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("uvwx", types.DYM.Mul(sdk.NewInt(20))), - sdk.NewCoin("yzzz", types.DYM.Mul(sdk.NewInt(20))), - ), - expectErr: true, - }, - { - name: "user tries to add to a non-perpetual gauge but does not have the correct fee denom", - accountBalanceToFund: sdk.NewCoins(sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(60)))), - gaugeAddition: sdk.NewCoins(sdk.NewCoin("foo", types.DYM.Mul(sdk.NewInt(10)))), - expectErr: true, - }, - } - - for _, tc := range tests { - suite.Run(tc.name, func() { - suite.SetupTest() - - err := suite.App.TxFeesKeeper.SetBaseDenom(suite.Ctx, "stake") - suite.Require().NoError(err) - - testAccountPubkey := secp256k1.GenPrivKeyFromSecret([]byte("acc")).PubKey() - testAccountAddress := sdk.AccAddress(testAccountPubkey.Address()) - - ctx := suite.Ctx - bankKeeper := suite.App.BankKeeper - incentivesKeeper := suite.App.IncentivesKeeper - accountKeeper := suite.App.AccountKeeper - msgServer := keeper.NewMsgServerImpl(incentivesKeeper) - - suite.FundAcc(testAccountAddress, tc.accountBalanceToFund) - - if tc.isModuleAccount { - modAcc := authtypes.NewModuleAccount(authtypes.NewBaseAccount(testAccountAddress, testAccountPubkey, 1, 0), - "module", - "permission", - ) - accountKeeper.SetModuleAccount(ctx, modAcc) - } - - // System under test. - coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(500000000))) - gaugeID, gauge, _, _ := suite.SetupNewGauge(true, coins) - msg := &types.MsgAddToGauge{ - Owner: testAccountAddress.String(), - GaugeId: gaugeID, - Rewards: tc.gaugeAddition, - } - - params := suite.querier.GetParams(suite.Ctx) - feeRaw := params.AddToGaugeBaseFee.Add(params.AddDenomFee.MulRaw(int64(len(tc.gaugeAddition) + len(gauge.Coins)))) - suite.T().Log(feeRaw, params.AddToGaugeBaseFee, params.AddDenomFee) - - txfeesBalanceBefore := bankKeeper.GetBalance(ctx, accountKeeper.GetModuleAddress(txfees.ModuleName), "stake") - - _, err = msgServer.AddToGauge(sdk.WrapSDKContext(ctx), msg) - - if tc.expectErr { - suite.Require().Error(err, "test: %v", tc.name) - } else { - suite.Require().NoError(err, "test: %v", tc.name) - } - - bal := bankKeeper.GetAllBalances(ctx, testAccountAddress) - - if tc.expectErr { - suite.Require().Equal(tc.accountBalanceToFund.String(), bal.String(), "test: %v", tc.name) - } else { - // Fee = AddToGaugeBaseFee + AddDenomFee * (NumAddedDenoms + NumGaugeDenoms) - params := suite.querier.GetParams(suite.Ctx) - feeRaw := params.AddToGaugeBaseFee.Add(params.AddDenomFee.MulRaw(int64(len(tc.gaugeAddition) + len(gauge.Coins)))) - fee := sdk.NewCoins(sdk.NewCoin("stake", feeRaw)) - - accountBalance := tc.accountBalanceToFund.Sub(tc.gaugeAddition...) - finalAccountBalance := accountBalance.Sub(fee...) - suite.Require().Equal(finalAccountBalance.String(), bal.String(), "test: %v", tc.name) - - // test fee charged to txfees module account and burned - txfeesBalanceAfter := bankKeeper.GetBalance(ctx, accountKeeper.GetModuleAddress(txfees.ModuleName), "stake") - suite.Require().Equal(txfeesBalanceBefore.Amount, txfeesBalanceAfter.Amount, "test: %v", tc.name) - } - }) - } -} - -func (suite *KeeperTestSuite) TestChargeFeeIfSufficientFeeDenomBalance() { - const baseFee = int64(100) - - testcases := map[string]struct { - accountBalanceToFund sdk.Coin - feeToCharge int64 - gaugeCoins sdk.Coins - - expectError bool - }{ - "fee + base denom gauge coin == account balance, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee / 2, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(baseFee/2))), - }, - "fee + base denom gauge coin < account balance, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee/2 - 1, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(baseFee/2))), - }, - "fee + base denom gauge coin > account balance, error": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee/2 + 1, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(baseFee/2))), - expectError: true, - }, - "fee + base denom gauge coin < account balance, custom values, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(11793193112)), - feeToCharge: 55, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(328812))), - }, - "account funded with coins other than base denom, error": { - accountBalanceToFund: sdk.NewCoin("usdc", sdk.NewInt(baseFee)), - feeToCharge: baseFee, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(baseFee/2))), - expectError: true, - }, - "fee == account balance, no gauge coins, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee, - }, - "gauge coins == account balance, no fee, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - gaugeCoins: sdk.NewCoins(sdk.NewCoin("adym", sdk.NewInt(baseFee))), - }, - "fee == account balance, gauge coins in denom other than base, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(baseFee*2))), - }, - "fee + gauge coins == account balance, multiple gauge coins, one in denom other than base, success": { - accountBalanceToFund: sdk.NewCoin("adym", sdk.NewInt(baseFee)), - feeToCharge: baseFee / 2, - gaugeCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(baseFee*2)), sdk.NewCoin("adym", sdk.NewInt(baseFee/2))), - }, - } - - for name, tc := range testcases { - suite.Run(name, func() { - suite.SetupTest() - - err := suite.App.TxFeesKeeper.SetBaseDenom(suite.Ctx, "adym") - suite.Require().NoError(err) - - testAccount := apptesting.CreateRandomAccounts(1)[0] - ctx := suite.Ctx - incentivesKeepers := suite.App.IncentivesKeeper - bankKeeper := suite.App.BankKeeper - - // Pre-fund account. - // suite.FundAcc(testAccount, testutil.DefaultAcctFunds) - suite.FundAcc(testAccount, sdk.NewCoins(tc.accountBalanceToFund)) - - oldBalanceAmount := bankKeeper.GetBalance(ctx, testAccount, "adym").Amount - - // System under test. - err = incentivesKeepers.ChargeGaugesFee(ctx, testAccount, sdk.NewInt(tc.feeToCharge), tc.gaugeCoins) - - // Assertions. - newBalanceAmount := bankKeeper.GetBalance(ctx, testAccount, "adym").Amount - if tc.expectError { - suite.Require().Error(err) - - // check account balance unchanged - suite.Require().Equal(oldBalanceAmount, newBalanceAmount) - } else { - suite.Require().NoError(err) - - // check account balance changed. - expectedNewBalanceAmount := oldBalanceAmount.Sub(sdk.NewInt(tc.feeToCharge)) - suite.Require().Equal(expectedNewBalanceAmount.String(), newBalanceAmount.String()) - } - }) - } -} diff --git a/x/dividends/keeper/storage.go b/x/dividends/keeper/storage.go index 7fc8b9ba..a1450e80 100644 --- a/x/dividends/keeper/storage.go +++ b/x/dividends/keeper/storage.go @@ -5,6 +5,10 @@ import ( "github.com/dymensionxyz/dymension-rdk/x/dividends/types" ) +func (k Keeper) NextGaugeId(ctx sdk.Context) (uint64, error) { + return k.lastGaugeID.Next(ctx) +} + func (k Keeper) GetAllGauges(ctx sdk.Context) ([]types.Gauge, error) { i, err := k.gauges.Iterate(ctx, nil) if err != nil { @@ -26,6 +30,10 @@ func (k Keeper) GetGauge(ctx sdk.Context, gaugeId uint64) (types.Gauge, error) { return k.gauges.Get(ctx, gaugeId) } +func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { + return k.params.Set(ctx, p) +} + func (k Keeper) MustGetParams(ctx sdk.Context) types.Params { p, err := k.params.Get(ctx) if err != nil { diff --git a/x/dividends/keeper/suite_test.go b/x/dividends/keeper/suite_test.go deleted file mode 100644 index 33084938..00000000 --- a/x/dividends/keeper/suite_test.go +++ /dev/null @@ -1,248 +0,0 @@ -package keeper_test - -import ( - "crypto/rand" - "fmt" - "strings" - "time" - - tmrand "github.com/cometbft/cometbft/libs/rand" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dymensionxyz/sdk-utils/utils/urand" - - "github.com/dymensionxyz/dymension/v3/x/incentives/types" - lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types" - rollapp "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" - rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types" -) - -var ( - defaultLPDenom string = "lptoken" - defaultLPTokens sdk.Coins = sdk.Coins{sdk.NewInt64Coin(defaultLPDenom, 10)} - defaultLiquidTokens sdk.Coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} - defaultLockDuration time.Duration = time.Second - oneLockupUser userLocks = userLocks{ - lockDurations: []time.Duration{time.Second}, - lockAmounts: []sdk.Coins{defaultLPTokens}, - } - twoLockupUser userLocks = userLocks{ - lockDurations: []time.Duration{defaultLockDuration, 2 * defaultLockDuration}, - lockAmounts: []sdk.Coins{defaultLPTokens, defaultLPTokens}, - } - - defaultRewardDenom string = "rewardDenom" -) - -// TODO: Switch more code to use userLocks and perpGaugeDesc -// TODO: Create issue for the above. -type userLocks struct { - lockDurations []time.Duration - lockAmounts []sdk.Coins -} - -type perpGaugeDesc struct { - lockDenom string - lockDuration time.Duration - rewardAmount sdk.Coins -} - -// setupAddr takes a balance, prefix, and address number. Then returns the respective account address byte array. -// If prefix is left blank, it will be replaced with a random prefix. -func (suite *KeeperTestSuite) setupAddr(addrNum int, prefix string, balance sdk.Coins) sdk.AccAddress { - if prefix == "" { - prefixBz := make([]byte, 8) - _, _ = rand.Read(prefixBz) - prefix = string(prefixBz) - } - - addr := sdk.AccAddress([]byte(fmt.Sprintf("addr%s%8d", prefix, addrNum))) - suite.FundAcc(addr, balance) - return addr -} - -// SetupUserLocks takes an array of user locks, creates locks based on this array, then returns the respective array of accounts. -func (suite *KeeperTestSuite) SetupUserLocks(users []userLocks) (accs []sdk.AccAddress) { - accs = make([]sdk.AccAddress, len(users)) - for i, user := range users { - suite.Assert().Equal(len(user.lockDurations), len(user.lockAmounts)) - totalLockAmt := user.lockAmounts[0] - for j := 1; j < len(user.lockAmounts); j++ { - totalLockAmt = totalLockAmt.Add(user.lockAmounts[j]...) - } - accs[i] = suite.setupAddr(i, "", totalLockAmt) - for j := 0; j < len(user.lockAmounts); j++ { - _, err := suite.App.LockupKeeper.CreateLock( - suite.Ctx, accs[i], user.lockAmounts[j], user.lockDurations[j]) - suite.Require().NoError(err) - } - } - return -} - -// SetupGauges takes an array of perpGaugeDesc structs. Then returns the corresponding array of Gauge structs. -func (suite *KeeperTestSuite) SetupGauges(gaugeDescriptors []perpGaugeDesc, denom string) []types.Gauge { - gauges := make([]types.Gauge, len(gaugeDescriptors)) - perpetual := true - for i, desc := range gaugeDescriptors { - _, gaugePtr, _, _ := suite.setupNewGaugeWithDuration(perpetual, desc.rewardAmount, desc.lockDuration, denom) - gauges[i] = *gaugePtr - } - return gauges -} - -// CreateGauge creates a gauge struct given the required params. -func (suite *KeeperTestSuite) CreateGauge(isPerpetual bool, addr sdk.AccAddress, coins sdk.Coins, distrTo lockuptypes.QueryCondition, startTime time.Time, numEpoch uint64) (uint64, *types.Gauge) { - suite.FundAcc(addr, coins) - gaugeID, err := suite.App.IncentivesKeeper.CreateGauge(suite.Ctx, isPerpetual, addr, coins, distrTo, startTime, numEpoch) - suite.Require().NoError(err) - gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, gaugeID) - suite.Require().NoError(err) - return gaugeID, gauge -} - -// AddToGauge adds coins to the specified gauge. -func (suite *KeeperTestSuite) AddToGauge(coins sdk.Coins, gaugeID uint64) uint64 { - gauge, err := suite.App.IncentivesKeeper.GetGaugeByID(suite.Ctx, gaugeID) - suite.Require().NoError(err) - addr := sdk.AccAddress([]byte("addrx---------------")) - suite.FundAcc(addr, coins) - err = suite.App.IncentivesKeeper.AddToGaugeRewards(suite.Ctx, addr, coins, gauge) - suite.Require().NoError(err) - return gaugeID -} - -// LockTokens locks tokens for the specified duration -func (suite *KeeperTestSuite) LockTokens(addr sdk.AccAddress, coins sdk.Coins, duration time.Duration) { - suite.FundAcc(addr, coins) - _, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, addr, coins, duration) - suite.Require().NoError(err) -} - -// setupNewGaugeWithDuration creates a gauge with the specified duration. -func (suite *KeeperTestSuite) setupNewGaugeWithDuration(isPerpetual bool, coins sdk.Coins, duration time.Duration, denom string) ( - uint64, *types.Gauge, sdk.Coins, time.Time, -) { - addr := sdk.AccAddress([]byte("Gauge_Creation_Addr_")) - startTime2 := time.Now() - distrTo := lockuptypes.QueryCondition{ - LockQueryType: lockuptypes.ByDuration, - Denom: denom, - Duration: duration, - } - - // mints coins so supply exists on chain - mintCoins := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)} - suite.FundAcc(addr, mintCoins) - - numEpochsPaidOver := uint64(2) - if isPerpetual { - numEpochsPaidOver = uint64(1) - } - gaugeID, gauge := suite.CreateGauge(isPerpetual, addr, coins, distrTo, startTime2, numEpochsPaidOver) - return gaugeID, gauge, coins, startTime2 -} - -// SetupNewGauge creates a gauge with the default lock duration. -func (suite *KeeperTestSuite) SetupNewGauge(isPerpetual bool, coins sdk.Coins) (uint64, *types.Gauge, sdk.Coins, time.Time) { - return suite.setupNewGaugeWithDuration(isPerpetual, coins, defaultLockDuration, "lptoken") -} - -// setupNewGaugeWithDenom creates a gauge with the specified duration and denom. -func (suite *KeeperTestSuite) setupNewGaugeWithDenom(isPerpetual bool, coins sdk.Coins, duration time.Duration, denom string) ( - uint64, *types.Gauge, sdk.Coins, time.Time, -) { - addr := sdk.AccAddress([]byte("Gauge_Creation_Addr_")) - startTime2 := time.Now() - distrTo := lockuptypes.QueryCondition{ - LockQueryType: lockuptypes.ByDuration, - Denom: denom, - Duration: duration, - } - - // mints coins so supply exists on chain - mintCoins := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)} - suite.FundAcc(addr, mintCoins) - - numEpochsPaidOver := uint64(2) - if isPerpetual { - numEpochsPaidOver = uint64(1) - } - gaugeID, gauge := suite.CreateGauge(isPerpetual, addr, coins, distrTo, startTime2, numEpochsPaidOver) - return gaugeID, gauge, coins, startTime2 -} - -// SetupNewGaugeWithDenom creates a gauge with the specified duration and denom. -func (suite *KeeperTestSuite) SetupNewGaugeWithDenom(isPerpetual bool, coins sdk.Coins, denom string) (uint64, *types.Gauge, sdk.Coins, time.Time) { - return suite.setupNewGaugeWithDenom(isPerpetual, coins, defaultLockDuration, denom) -} - -// SetupManyLocks creates as many locks as the user defines. -func (suite *KeeperTestSuite) SetupManyLocks(numLocks int, liquidBalance sdk.Coins, coinsPerLock sdk.Coins, - lockDuration time.Duration, -) []sdk.AccAddress { - addrs := make([]sdk.AccAddress, 0, numLocks) - randPrefix := make([]byte, 8) - _, _ = rand.Read(randPrefix) - - bal := liquidBalance.Add(coinsPerLock...) - for i := 0; i < numLocks; i++ { - addr := suite.setupAddr(i, string(randPrefix), bal) - _, err := suite.App.LockupKeeper.CreateLock(suite.Ctx, addr, coinsPerLock, lockDuration) - suite.Require().NoError(err) - addrs = append(addrs, addr) - } - return addrs -} - -// SetupLockAndGauge creates both a lock and a gauge. -func (suite *KeeperTestSuite) SetupLockAndGauge(isPerpetual bool) (sdk.AccAddress, uint64, sdk.Coins, time.Time) { - // create a gauge and locks - lockOwner := sdk.AccAddress([]byte("addr1---------------")) - suite.LockTokens(lockOwner, sdk.Coins{sdk.NewInt64Coin("lptoken", 10)}, time.Second) - - // create gauge - gaugeID, _, gaugeCoins, startTime := suite.SetupNewGauge(isPerpetual, sdk.Coins{sdk.NewInt64Coin("stake", 10)}) - - return lockOwner, gaugeID, gaugeCoins, startTime -} - -// SetupLockAndGauge creates both a lock and a gauge. -func (suite *KeeperTestSuite) CreateDefaultRollapp(addr sdk.AccAddress) string { - msgCreateRollapp := rollapptypes.MsgCreateRollapp{ - Creator: addr.String(), - RollappId: urand.RollappID(), - InitialSequencer: addr.String(), - MinSequencerBond: rollapptypes.DefaultMinSequencerBondGlobalCoin, - - Alias: strings.ToLower(tmrand.Str(7)), - VmType: rollapptypes.Rollapp_EVM, - GenesisInfo: &rollapptypes.GenesisInfo{ - Bech32Prefix: strings.ToLower(tmrand.Str(3)), - GenesisChecksum: "checksum", - NativeDenom: rollapptypes.DenomMetadata{ - Display: "DEN", - Base: "aden", - Exponent: 18, - }, - InitialSupply: sdk.NewInt(1000), - }, - } - - suite.FundForAliasRegistration(msgCreateRollapp) - - msgServer := rollapp.NewMsgServerImpl(suite.App.RollappKeeper) - _, err := msgServer.CreateRollapp(suite.Ctx, &msgCreateRollapp) - suite.Require().NoError(err) - return msgCreateRollapp.RollappId -} - -func (suite *KeeperTestSuite) TransferRollappOwnership(currentOwner, newOwner sdk.AccAddress, rollappID string) { - rollappMsgServer := rollapp.NewMsgServerImpl(suite.App.RollappKeeper) - resp, err := rollappMsgServer.TransferOwnership(suite.Ctx, &rollapptypes.MsgTransferOwnership{ - CurrentOwner: currentOwner.String(), - NewOwner: newOwner.String(), - RollappId: rollappID, - }) - suite.Require().NoError(err) - suite.Require().NotNil(resp) -} diff --git a/x/dividends/module.go b/x/dividends/module.go new file mode 100644 index 00000000..855226fd --- /dev/null +++ b/x/dividends/module.go @@ -0,0 +1,177 @@ +package dividends + +import ( + "context" + "encoding/json" + "fmt" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/dymensionxyz/dymension-rdk/x/dividends/client/cli" + "github.com/dymensionxyz/dymension-rdk/x/dividends/keeper" + "github.com/dymensionxyz/dymension-rdk/x/dividends/types" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the module. +type AppModuleBasic struct{} + +// NewAppModuleBasic creates a new AppModuleBasic struct. +func NewAppModuleBasic() AppModuleBasic { + return AppModuleBasic{} +} + +// Name returns the module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// Route returns the capability module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// NewHandler returns a handler for epochs module messages +func NewHandler(k keeper.Keeper) sdk.Handler { + return func(_ sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + } +} + +// QuerierRoute returns the capability module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return nil +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types. +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + return + } +} + +// GetTxCmd returns the module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +// NewAppModule creates a new AppModule struct. +func NewAppModule( + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(), + keeper: keeper, + } +} + +// Name returns the module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// RegisterServices registers the module's services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper)) +} + +// RegisterInvariants registers the module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. +// Returns an empty ValidatorUpdate array. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // initialize global index to index in genesis state. + cdc.MustUnmarshalJSON(gs, &genState) + + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(am.keeper.ExportGenesis(ctx)) +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the module. +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the module. +// Returns a nil validatorUpdate struct array. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } diff --git a/x/dividends/types/codec.go b/x/dividends/types/codec.go new file mode 100644 index 00000000..83568acc --- /dev/null +++ b/x/dividends/types/codec.go @@ -0,0 +1,41 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" +) + +// RegisterCodec registers the necessary x/sponsorship interfaces and concrete types on the provided +// LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgCreateGauge{}, "dividends/CreateGauge", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "dividends/UpdateParams", nil) +} + +// RegisterInterfaces registers interfaces types with the interface registry. +func RegisterInterfaces(reg types.InterfaceRegistry) { + reg.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgCreateGauge{}, + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(reg, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(Amino) +) + +func init() { + RegisterCodec(Amino) + // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be + // used to properly serialize MsgGrant and MsgExec instances + sdk.RegisterLegacyAminoCodec(Amino) + RegisterCodec(authzcodec.Amino) + + Amino.Seal() +} diff --git a/x/dividends/types/events.pb.go b/x/dividends/types/events.pb.go new file mode 100644 index 00000000..b4010755 --- /dev/null +++ b/x/dividends/types/events.pb.go @@ -0,0 +1,752 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dividends/events.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type EventUpdateParams struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + NewParams Params `protobuf:"bytes,2,opt,name=new_params,json=newParams,proto3" json:"new_params"` + OldParams Params `protobuf:"bytes,3,opt,name=old_params,json=oldParams,proto3" json:"old_params"` +} + +func (m *EventUpdateParams) Reset() { *m = EventUpdateParams{} } +func (m *EventUpdateParams) String() string { return proto.CompactTextString(m) } +func (*EventUpdateParams) ProtoMessage() {} +func (*EventUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_7a463702b1028004, []int{0} +} +func (m *EventUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventUpdateParams.Merge(m, src) +} +func (m *EventUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *EventUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_EventUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_EventUpdateParams proto.InternalMessageInfo + +func (m *EventUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *EventUpdateParams) GetNewParams() Params { + if m != nil { + return m.NewParams + } + return Params{} +} + +func (m *EventUpdateParams) GetOldParams() Params { + if m != nil { + return m.OldParams + } + return Params{} +} + +type EventCreateGauge struct { + // Authority is the address that controls the module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // query_condition is *where* the gauge rewards are distributed to + QueryCondition QueryCondition `protobuf:"bytes,2,opt,name=query_condition,json=queryCondition,proto3" json:"query_condition"` + // vesting_condition is *how long* the gauge rewards are distributed to + VestingCondition VestingCondition `protobuf:"bytes,3,opt,name=vesting_condition,json=vestingCondition,proto3" json:"vesting_condition"` + // vesting_condition is *how frequent* the gauge rewards are distributed to + VestingFrequency VestingFrequency `protobuf:"varint,4,opt,name=vesting_frequency,json=vestingFrequency,proto3,enum=rollapp.dividends.VestingFrequency" json:"vesting_frequency,omitempty"` +} + +func (m *EventCreateGauge) Reset() { *m = EventCreateGauge{} } +func (m *EventCreateGauge) String() string { return proto.CompactTextString(m) } +func (*EventCreateGauge) ProtoMessage() {} +func (*EventCreateGauge) Descriptor() ([]byte, []int) { + return fileDescriptor_7a463702b1028004, []int{1} +} +func (m *EventCreateGauge) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventCreateGauge) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventCreateGauge.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventCreateGauge) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventCreateGauge.Merge(m, src) +} +func (m *EventCreateGauge) XXX_Size() int { + return m.Size() +} +func (m *EventCreateGauge) XXX_DiscardUnknown() { + xxx_messageInfo_EventCreateGauge.DiscardUnknown(m) +} + +var xxx_messageInfo_EventCreateGauge proto.InternalMessageInfo + +func (m *EventCreateGauge) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *EventCreateGauge) GetQueryCondition() QueryCondition { + if m != nil { + return m.QueryCondition + } + return QueryCondition{} +} + +func (m *EventCreateGauge) GetVestingCondition() VestingCondition { + if m != nil { + return m.VestingCondition + } + return VestingCondition{} +} + +func (m *EventCreateGauge) GetVestingFrequency() VestingFrequency { + if m != nil { + return m.VestingFrequency + } + return VestingFrequency_VESTING_FREQUENCY_UNSPECIFIED +} + +func init() { + proto.RegisterType((*EventUpdateParams)(nil), "rollapp.dividends.EventUpdateParams") + proto.RegisterType((*EventCreateGauge)(nil), "rollapp.dividends.EventCreateGauge") +} + +func init() { proto.RegisterFile("dividends/events.proto", fileDescriptor_7a463702b1028004) } + +var fileDescriptor_7a463702b1028004 = []byte{ + // 395 bytes of a gzipped FileDescriptorProto + 0x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xfa, 0x82, 0xbc, 0x77, + 0x37, 0x6e, 0xf5, 0xdf, 0x54, 0x16, 0x83, 0x5c, 0xdc, 0x2e, 0x3e, 0xdc, 0x93, 0x9f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x65, 0xea, 0xaa, 0x85, 0xe5, 0x02, 0x00, 0x00, +} + +func (m *EventUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.OldParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.NewParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *EventCreateGauge) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventCreateGauge) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventCreateGauge) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.VestingFrequency != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.VestingFrequency)) + i-- + dAtA[i] = 0x20 + } + { + size, err := m.VestingCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.QueryCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { + offset -= sovEvents(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = m.NewParams.Size() + n += 1 + l + sovEvents(uint64(l)) + l = m.OldParams.Size() + n += 1 + l + sovEvents(uint64(l)) + return n +} + +func (m *EventCreateGauge) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = m.QueryCondition.Size() + n += 1 + l + sovEvents(uint64(l)) + l = m.VestingCondition.Size() + n += 1 + l + sovEvents(uint64(l)) + if m.VestingFrequency != 0 { + n += 1 + sovEvents(uint64(m.VestingFrequency)) + } + return n +} + +func sovEvents(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvents(x uint64) (n int) { + return sovEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NewParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OldParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.OldParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EventCreateGauge) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventCreateGauge: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventCreateGauge: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryCondition", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.QueryCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VestingCondition", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VestingCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VestingFrequency", wireType) + } + m.VestingFrequency = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VestingFrequency |= VestingFrequency(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvents(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvents + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvents + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEvents + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthEvents + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvents + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvents + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvents = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvents = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvents = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/dividends/types/expected_keepers.go b/x/dividends/types/expected_keepers.go index aaca26f7..79ff1219 100644 --- a/x/dividends/types/expected_keepers.go +++ b/x/dividends/types/expected_keepers.go @@ -3,6 +3,7 @@ package types import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -22,3 +23,11 @@ type DistributionKeeper interface { AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI + GetModuleAddress(moduleName string) sdk.AccAddress + NewAccount(ctx sdk.Context, acc authtypes.AccountI) authtypes.AccountI + SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI) +} diff --git a/x/dividends/types/gauge.go b/x/dividends/types/gauge.go index 8d33cb46..a09e2bfc 100644 --- a/x/dividends/types/gauge.go +++ b/x/dividends/types/gauge.go @@ -1,15 +1,71 @@ package types +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + func NewGauge( id uint64, address string, - queryCondition *QueryCondition, - vestingCondition *VestingCondition, + queryCondition QueryCondition, + vestingCondition VestingCondition, + vestingFrequency VestingFrequency, ) Gauge { return Gauge{ Id: id, Address: address, QueryCondition: queryCondition, VestingCondition: vestingCondition, + VestingFrequency: vestingFrequency, + } +} + +// ValidateBasic performs basic validation of the Gauge fields. +func (g Gauge) ValidateBasic() error { + if g.Id == 0 { + return fmt.Errorf("gauge id cannot be zero") + } + if _, err := sdk.AccAddressFromBech32(g.Address); err != nil { + return fmt.Errorf("invalid address: %w", err) + } + if err := g.QueryCondition.ValidateBasic(); err != nil { + return fmt.Errorf("invalid query condition: %w", err) + } + if err := g.VestingCondition.ValidateBasic(); err != nil { + return fmt.Errorf("invalid vesting condition: %w", err) + } + if g.VestingFrequency == VestingFrequency_VESTING_FREQUENCY_UNSPECIFIED { + return fmt.Errorf("vesting frequency cannot be unspecified") + } + return nil +} + +// ValidateBasic performs basic validation of the QueryCondition fields. +func (qc QueryCondition) ValidateBasic() error { + switch qc.Condition.(type) { + case *QueryCondition_Stakers: + return nil + default: + return fmt.Errorf("invalid query condition type") + } +} + +// ValidateBasic performs basic validation of the VestingCondition fields. +func (vc VestingCondition) ValidateBasic() error { + switch c := vc.Condition.(type) { + case *VestingCondition_Perpetual: + return nil + case *VestingCondition_Limited: + if c.Limited.NumUnits < 0 { + return fmt.Errorf("num_units cannot be negative") + } + if c.Limited.FilledUnits <= 0 { + return fmt.Errorf("filled_units must be greater than zero") + } + return nil + default: + return fmt.Errorf("invalid vesting condition type") } } diff --git a/x/dividends/types/gauge.pb.go b/x/dividends/types/gauge.pb.go index 70f7cdce..b3801eb3 100644 --- a/x/dividends/types/gauge.pb.go +++ b/x/dividends/types/gauge.pb.go @@ -5,10 +5,8 @@ package types import ( fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" io "io" math "math" math_bits "math/bits" @@ -53,6 +51,63 @@ func (VestingFrequency) EnumDescriptor() ([]byte, []int) { return fileDescriptor_904d8195b7413b1f, []int{0} } +// Params holds parameters for the incentives module +type Params struct { + // distr_epoch_identifier is what epoch type distribution will be triggered by + // (day, week, etc.) + DistrEpochIdentifier string `protobuf:"bytes,1,opt,name=distr_epoch_identifier,json=distrEpochIdentifier,proto3" json:"distr_epoch_identifier,omitempty"` + // approved_denoms is a list of allowed tokens: only gov can approve tokens + // that can be used for dividends + ApprovedDenoms []string `protobuf:"bytes,2,rep,name=approved_denoms,json=approvedDenoms,proto3" json:"approved_denoms,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_904d8195b7413b1f, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetDistrEpochIdentifier() string { + if m != nil { + return m.DistrEpochIdentifier + } + return "" +} + +func (m *Params) GetApprovedDenoms() []string { + if m != nil { + return m.ApprovedDenoms + } + return nil +} + // Gauge is an object that stores and distributes yields to recipients who // satisfy certain conditions. type Gauge struct { @@ -61,9 +116,9 @@ type Gauge struct { // address is a bech32-formatted address that holds the tokens to allocate Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` // query_condition is *where* the gauge rewards are distributed to - QueryCondition *QueryCondition `protobuf:"bytes,3,opt,name=query_condition,json=queryCondition,proto3" json:"query_condition,omitempty"` + QueryCondition QueryCondition `protobuf:"bytes,3,opt,name=query_condition,json=queryCondition,proto3" json:"query_condition"` // vesting_condition is *how long* the gauge rewards are distributed to - VestingCondition *VestingCondition `protobuf:"bytes,4,opt,name=vesting_condition,json=vestingCondition,proto3" json:"vesting_condition,omitempty"` + VestingCondition VestingCondition `protobuf:"bytes,4,opt,name=vesting_condition,json=vestingCondition,proto3" json:"vesting_condition"` // vesting_condition is *how frequent* the gauge rewards are distributed to VestingFrequency VestingFrequency `protobuf:"varint,5,opt,name=vesting_frequency,json=vestingFrequency,proto3,enum=rollapp.dividends.VestingFrequency" json:"vesting_frequency,omitempty"` } @@ -72,7 +127,7 @@ func (m *Gauge) Reset() { *m = Gauge{} } func (m *Gauge) String() string { return proto.CompactTextString(m) } func (*Gauge) ProtoMessage() {} func (*Gauge) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{0} + return fileDescriptor_904d8195b7413b1f, []int{1} } func (m *Gauge) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -115,18 +170,18 @@ func (m *Gauge) GetAddress() string { return "" } -func (m *Gauge) GetQueryCondition() *QueryCondition { +func (m *Gauge) GetQueryCondition() QueryCondition { if m != nil { return m.QueryCondition } - return nil + return QueryCondition{} } -func (m *Gauge) GetVestingCondition() *VestingCondition { +func (m *Gauge) GetVestingCondition() VestingCondition { if m != nil { return m.VestingCondition } - return nil + return VestingCondition{} } func (m *Gauge) GetVestingFrequency() VestingFrequency { @@ -146,7 +201,7 @@ func (m *QueryCondition) Reset() { *m = QueryCondition{} } func (m *QueryCondition) String() string { return proto.CompactTextString(m) } func (*QueryCondition) ProtoMessage() {} func (*QueryCondition) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{1} + return fileDescriptor_904d8195b7413b1f, []int{2} } func (m *QueryCondition) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -211,7 +266,7 @@ func (*QueryCondition) XXX_OneofWrappers() []interface{} { type VestingCondition struct { // Types that are valid to be assigned to Condition: // *VestingCondition_Perpetual - // *VestingCondition_Epoch + // *VestingCondition_Limited Condition isVestingCondition_Condition `protobuf_oneof:"condition"` } @@ -219,7 +274,7 @@ func (m *VestingCondition) Reset() { *m = VestingCondition{} } func (m *VestingCondition) String() string { return proto.CompactTextString(m) } func (*VestingCondition) ProtoMessage() {} func (*VestingCondition) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{2} + return fileDescriptor_904d8195b7413b1f, []int{3} } func (m *VestingCondition) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -257,12 +312,12 @@ type isVestingCondition_Condition interface { type VestingCondition_Perpetual struct { Perpetual *VestingConditionPerpetual `protobuf:"bytes,1,opt,name=perpetual,proto3,oneof" json:"perpetual,omitempty"` } -type VestingCondition_Epoch struct { - Epoch *VestingConditionLimited `protobuf:"bytes,2,opt,name=epoch,proto3,oneof" json:"epoch,omitempty"` +type VestingCondition_Limited struct { + Limited *VestingConditionLimited `protobuf:"bytes,2,opt,name=limited,proto3,oneof" json:"limited,omitempty"` } func (*VestingCondition_Perpetual) isVestingCondition_Condition() {} -func (*VestingCondition_Epoch) isVestingCondition_Condition() {} +func (*VestingCondition_Limited) isVestingCondition_Condition() {} func (m *VestingCondition) GetCondition() isVestingCondition_Condition { if m != nil { @@ -278,9 +333,9 @@ func (m *VestingCondition) GetPerpetual() *VestingConditionPerpetual { return nil } -func (m *VestingCondition) GetEpoch() *VestingConditionLimited { - if x, ok := m.GetCondition().(*VestingCondition_Epoch); ok { - return x.Epoch +func (m *VestingCondition) GetLimited() *VestingConditionLimited { + if x, ok := m.GetCondition().(*VestingCondition_Limited); ok { + return x.Limited } return nil } @@ -289,7 +344,7 @@ func (m *VestingCondition) GetEpoch() *VestingConditionLimited { func (*VestingCondition) XXX_OneofWrappers() []interface{} { return []interface{}{ (*VestingCondition_Perpetual)(nil), - (*VestingCondition_Epoch)(nil), + (*VestingCondition_Limited)(nil), } } @@ -301,7 +356,7 @@ func (m *QueryConditionStakers) Reset() { *m = QueryConditionStakers{} } func (m *QueryConditionStakers) String() string { return proto.CompactTextString(m) } func (*QueryConditionStakers) ProtoMessage() {} func (*QueryConditionStakers) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{3} + return fileDescriptor_904d8195b7413b1f, []int{4} } func (m *QueryConditionStakers) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -345,7 +400,7 @@ func (m *VestingConditionPerpetual) Reset() { *m = VestingConditionPerpe func (m *VestingConditionPerpetual) String() string { return proto.CompactTextString(m) } func (*VestingConditionPerpetual) ProtoMessage() {} func (*VestingConditionPerpetual) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{4} + return fileDescriptor_904d8195b7413b1f, []int{5} } func (m *VestingConditionPerpetual) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -380,17 +435,17 @@ var xxx_messageInfo_VestingConditionPerpetual proto.InternalMessageInfo type VestingConditionLimited struct { // num_units is the number of total epochs/blocks distribution will be // completed over - NumUnits uint64 `protobuf:"varint,1,opt,name=num_units,json=numUnits,proto3" json:"num_units,omitempty"` + NumUnits int64 `protobuf:"varint,1,opt,name=num_units,json=numUnits,proto3" json:"num_units,omitempty"` // filled_epochs is the number of epochs/blocks distribution has been // completed on already - FilledUnits uint64 `protobuf:"varint,2,opt,name=filled_units,json=filledUnits,proto3" json:"filled_units,omitempty"` + FilledUnits int64 `protobuf:"varint,2,opt,name=filled_units,json=filledUnits,proto3" json:"filled_units,omitempty"` } func (m *VestingConditionLimited) Reset() { *m = VestingConditionLimited{} } func (m *VestingConditionLimited) String() string { return proto.CompactTextString(m) } func (*VestingConditionLimited) ProtoMessage() {} func (*VestingConditionLimited) Descriptor() ([]byte, []int) { - return fileDescriptor_904d8195b7413b1f, []int{5} + return fileDescriptor_904d8195b7413b1f, []int{6} } func (m *VestingConditionLimited) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -419,14 +474,14 @@ func (m *VestingConditionLimited) XXX_DiscardUnknown() { var xxx_messageInfo_VestingConditionLimited proto.InternalMessageInfo -func (m *VestingConditionLimited) GetNumUnits() uint64 { +func (m *VestingConditionLimited) GetNumUnits() int64 { if m != nil { return m.NumUnits } return 0 } -func (m *VestingConditionLimited) GetFilledUnits() uint64 { +func (m *VestingConditionLimited) GetFilledUnits() int64 { if m != nil { return m.FilledUnits } @@ -435,6 +490,7 @@ func (m *VestingConditionLimited) GetFilledUnits() uint64 { func init() { proto.RegisterEnum("rollapp.dividends.VestingFrequency", VestingFrequency_name, VestingFrequency_value) + proto.RegisterType((*Params)(nil), "rollapp.dividends.Params") proto.RegisterType((*Gauge)(nil), "rollapp.dividends.Gauge") proto.RegisterType((*QueryCondition)(nil), "rollapp.dividends.QueryCondition") proto.RegisterType((*VestingCondition)(nil), "rollapp.dividends.VestingCondition") @@ -446,42 +502,82 @@ func init() { func init() { proto.RegisterFile("dividends/gauge.proto", fileDescriptor_904d8195b7413b1f) } var fileDescriptor_904d8195b7413b1f = []byte{ - // 552 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xc1, 0x72, 0xd2, 0x40, - 0x18, 0xc7, 0x93, 0x58, 0xac, 0x2c, 0x0e, 0xd2, 0x1d, 0x3b, 0x60, 0x19, 0x23, 0xe0, 0x85, 0xe9, - 0x28, 0x99, 0xe2, 0xc1, 0x3b, 0x34, 0x14, 0x94, 0xa1, 0x10, 0xa4, 0x33, 0xf5, 0xc2, 0x84, 0xec, - 0x92, 0xee, 0x34, 0xc9, 0x86, 0xec, 0x86, 0x29, 0x3e, 0x85, 0xaf, 0xe0, 0x23, 0xf8, 0x16, 0x1e, - 0x7b, 0xf4, 0xe8, 0xc0, 0x8b, 0x38, 0x84, 0x24, 0x14, 0x4a, 0xb5, 0xb7, 0x7c, 0xfb, 0xff, 0xef, - 0x6f, 0xbf, 0xff, 0xb7, 0x49, 0xc0, 0x21, 0x22, 0x53, 0x82, 0xb0, 0x83, 0x98, 0x62, 0xea, 0xbe, - 0x89, 0x2b, 0xae, 0x47, 0x39, 0x85, 0x07, 0x1e, 0xb5, 0x2c, 0xdd, 0x75, 0x2b, 0xb1, 0x7c, 0xf4, - 0xd2, 0xa4, 0x26, 0x0d, 0x54, 0x65, 0xf9, 0xb4, 0x32, 0x1e, 0xc9, 0x26, 0xa5, 0xa6, 0x85, 0x95, -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0xb8, 0x5d, 0xc8, 0xc2, 0xef, - 0x85, 0x2c, 0x7c, 0xfd, 0x68, 0x12, 0x7e, 0xe5, 0x8f, 0x2a, 0x06, 0xb5, 0x15, 0x34, 0xb3, 0xb1, - 0xc3, 0x08, 0x75, 0x6e, 0x66, 0xdf, 0xd6, 0xc5, 0x7b, 0x0f, 0x5d, 0x2b, 0x37, 0xca, 0xfa, 0x0f, - 0xc1, 0x67, 0x2e, 0x66, 0xa3, 0xa7, 0xc1, 0x87, 0xf9, 0xe1, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x0d, 0x79, 0x88, 0x25, 0x3b, 0x04, 0x00, 0x00, + // 566 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xdd, 0x6e, 0xd2, 0x50, + 0x1c, 0x6f, 0xbb, 0x2f, 0x39, 0x18, 0xc6, 0x4e, 0x36, 0x87, 0x2e, 0x56, 0xa8, 0x17, 0x92, 0x45, + 0x21, 0x41, 0x13, 0xef, 0x81, 0x32, 0x88, 0x84, 0x95, 0x22, 0x24, 0xf3, 0xa6, 0xe9, 0x38, 0x87, + 0xee, 0x64, 0x6d, 0x4f, 0x39, 0x6d, 0xc9, 0xf0, 0x29, 0x7c, 0x11, 0x2f, 0x7d, 0x87, 0x5d, 0xee, + 0xd2, 0x2b, 0x63, 0xe0, 0x45, 0x4c, 0x5b, 0x5a, 0x84, 0x31, 0xdd, 0x5d, 0xff, 0xbf, 0xaf, 0xff, + 0x47, 0x93, 0x03, 0x8e, 0x10, 0x99, 0x10, 0x84, 0x6d, 0xe4, 0x96, 0x0d, 0xdd, 0x37, 0x70, 0xc9, + 0x61, 0xd4, 0xa3, 0xf0, 0x80, 0x51, 0xd3, 0xd4, 0x1d, 0xa7, 0x94, 0xd0, 0x2f, 0x0e, 0x0d, 0x6a, + 0xd0, 0x90, 0x2d, 0x07, 0x5f, 0x91, 0x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 0xf9, 0xcd, 0xa4, 0xac, 0x9c, 0xd7, 0x9a, 0x59, 0xa1, 0xda, 0xbd, 0x9d, 0x89, 0xfc, 0xdd, + 0x4c, 0xe4, 0x7f, 0xcf, 0x44, 0xfe, 0xdb, 0x5c, 0xe4, 0xee, 0xe6, 0x22, 0xf7, 0x73, 0x2e, 0x72, + 0x5f, 0x3e, 0x1a, 0xc4, 0xbb, 0xf2, 0x2f, 0x4b, 0x43, 0x6a, 0x95, 0xd1, 0xd4, 0xc2, 0xb6, 0x4b, + 0xa8, 0x7d, 0x33, 0xfd, 0xba, 0x2c, 0xde, 0x31, 0x74, 0x5d, 0xbe, 0x29, 0x2f, 0x5f, 0x0e, 0x6f, + 0xea, 0x60, 0xf7, 0x72, 0x37, 0x7c, 0x11, 0xde, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, 0x73, 0x69, + 0xdc, 0xd9, 0x53, 0x04, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ApprovedDenoms) > 0 { + for iNdEx := len(m.ApprovedDenoms) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ApprovedDenoms[iNdEx]) + copy(dAtA[i:], m.ApprovedDenoms[iNdEx]) + i = encodeVarintGauge(dAtA, i, uint64(len(m.ApprovedDenoms[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.DistrEpochIdentifier) > 0 { + i -= len(m.DistrEpochIdentifier) + copy(dAtA[i:], m.DistrEpochIdentifier) + i = encodeVarintGauge(dAtA, i, uint64(len(m.DistrEpochIdentifier))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *Gauge) Marshal() (dAtA []byte, err error) { @@ -509,30 +605,26 @@ func (m *Gauge) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x28 } - if m.VestingCondition != nil { - { - size, err := m.VestingCondition.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGauge(dAtA, i, uint64(size)) + { + size, err := m.VestingCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x22 + i -= size + i = encodeVarintGauge(dAtA, i, uint64(size)) } - if m.QueryCondition != nil { - { - size, err := m.QueryCondition.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGauge(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x22 + { + size, err := m.QueryCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x1a + i -= size + i = encodeVarintGauge(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x1a if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -654,16 +746,16 @@ func (m *VestingCondition_Perpetual) MarshalToSizedBuffer(dAtA []byte) (int, err } return len(dAtA) - i, nil } -func (m *VestingCondition_Epoch) MarshalTo(dAtA []byte) (int, error) { +func (m *VestingCondition_Limited) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *VestingCondition_Epoch) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *VestingCondition_Limited) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) - if m.Epoch != nil { + if m.Limited != nil { { - size, err := m.Epoch.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Limited.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -765,6 +857,25 @@ func encodeVarintGauge(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DistrEpochIdentifier) + if l > 0 { + n += 1 + l + sovGauge(uint64(l)) + } + if len(m.ApprovedDenoms) > 0 { + for _, s := range m.ApprovedDenoms { + l = len(s) + n += 1 + l + sovGauge(uint64(l)) + } + } + return n +} + func (m *Gauge) Size() (n int) { if m == nil { return 0 @@ -778,14 +889,10 @@ func (m *Gauge) Size() (n int) { if l > 0 { n += 1 + l + sovGauge(uint64(l)) } - if m.QueryCondition != nil { - l = m.QueryCondition.Size() - n += 1 + l + sovGauge(uint64(l)) - } - if m.VestingCondition != nil { - l = m.VestingCondition.Size() - n += 1 + l + sovGauge(uint64(l)) - } + l = m.QueryCondition.Size() + n += 1 + l + sovGauge(uint64(l)) + l = m.VestingCondition.Size() + n += 1 + l + sovGauge(uint64(l)) if m.VestingFrequency != 0 { n += 1 + sovGauge(uint64(m.VestingFrequency)) } @@ -840,14 +947,14 @@ func (m *VestingCondition_Perpetual) Size() (n int) { } return n } -func (m *VestingCondition_Epoch) Size() (n int) { +func (m *VestingCondition_Limited) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Epoch != nil { - l = m.Epoch.Size() + if m.Limited != nil { + l = m.Limited.Size() n += 1 + l + sovGauge(uint64(l)) } return n @@ -891,6 +998,120 @@ func sovGauge(x uint64) (n int) { func sozGauge(x uint64) (n int) { return sovGauge(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGauge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DistrEpochIdentifier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGauge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGauge + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGauge + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DistrEpochIdentifier = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ApprovedDenoms", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGauge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGauge + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGauge + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ApprovedDenoms = append(m.ApprovedDenoms, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGauge(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGauge + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Gauge) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1000,9 +1221,6 @@ func (m *Gauge) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.QueryCondition == nil { - m.QueryCondition = &QueryCondition{} - } if err := m.QueryCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1036,9 +1254,6 @@ func (m *Gauge) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.VestingCondition == nil { - m.VestingCondition = &VestingCondition{} - } if err := m.VestingCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1234,7 +1449,7 @@ func (m *VestingCondition) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Limited", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1265,7 +1480,7 @@ func (m *VestingCondition) Unmarshal(dAtA []byte) error { if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Condition = &VestingCondition_Epoch{v} + m.Condition = &VestingCondition_Limited{v} iNdEx = postIndex default: iNdEx = preIndex @@ -1431,7 +1646,7 @@ func (m *VestingConditionLimited) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.NumUnits |= uint64(b&0x7F) << shift + m.NumUnits |= int64(b&0x7F) << shift if b < 0x80 { break } @@ -1450,7 +1665,7 @@ func (m *VestingConditionLimited) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.FilledUnits |= uint64(b&0x7F) << shift + m.FilledUnits |= int64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/dividends/types/genesis.go b/x/dividends/types/genesis.go new file mode 100644 index 00000000..e3e600be --- /dev/null +++ b/x/dividends/types/genesis.go @@ -0,0 +1,27 @@ +package types + +import "fmt" + +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + Gauges: nil, + LastGaugeId: 0, + } +} + +func (g GenesisState) Validate() error { + err := g.Params.Validate() + if err != nil { + return fmt.Errorf("validate params: %w", err) + } + + for _, gauge := range g.Gauges { + err = gauge.ValidateBasic() + if err != nil { + return fmt.Errorf("validate gauge: %w", err) + } + } + + return nil +} diff --git a/x/dividends/types/genesis.pb.go b/x/dividends/types/genesis.pb.go index c3addb17..5c407677 100644 --- a/x/dividends/types/genesis.pb.go +++ b/x/dividends/types/genesis.pb.go @@ -7,7 +7,6 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" io "io" math "math" math_bits "math/bits" @@ -97,25 +96,24 @@ func init() { func init() { proto.RegisterFile("dividends/genesis.proto", fileDescriptor_ce2ce326dbc73ce4) } var fileDescriptor_ce2ce326dbc73ce4 = []byte{ - // 288 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x8f, 0xbd, 0x4e, 0xc3, 0x30, - 0x14, 0x85, 0x63, 0x5a, 0x65, 0x48, 0x60, 0x20, 0xe2, 0x27, 0x64, 0x30, 0x51, 0xa7, 0x2c, 0xc4, - 0x52, 0x91, 0xe8, 0xde, 0xa5, 0x62, 0x83, 0xb2, 0xb1, 0x54, 0x0e, 0x36, 0xc6, 0x22, 0x89, 0xa3, - 0xd8, 0x41, 0x0d, 0x4f, 0xc1, 0x3b, 0xf0, 0x32, 0x1d, 0x3b, 0x32, 0x21, 0x94, 0xbc, 0x08, 0x8a, - 0x1d, 0x08, 0x12, 0xdd, 0x7c, 0xee, 0xfd, 0x8e, 0xcf, 0x3d, 0xce, 0x29, 0xe1, 0x2f, 0x9c, 0xd0, - 0x9c, 0x48, 0xc4, 0x68, 0x4e, 0x25, 0x97, 0x71, 0x51, 0x0a, 0x25, 0xbc, 0xc3, 0x52, 0xa4, 0x29, - 0x2e, 0x8a, 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, 0xc5, 0xfd, 0x1d, 0x92, 0x01, 0x00, 0x00, + // 257 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4f, 0xc9, 0x2c, 0xcb, + 0x4c, 0x49, 0xcd, 0x4b, 0x29, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2c, 0xca, 0xcf, 0xc9, 0x49, 0x2c, 0x28, 0xd0, 0x83, 0x2b, 0x90, + 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xea, 0x83, 0x58, 0x10, 0x85, 0x52, 0xa2, 0x48, 0x26, + 0x24, 0x96, 0xa6, 0xa7, 0x42, 0x84, 0x95, 0x16, 0x33, 0x72, 0xf1, 0xb8, 0x43, 0x4c, 0x0c, 0x2e, + 0x49, 0x2c, 0x49, 0x15, 0x32, 0xe7, 0x62, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0x96, 0x60, 0x54, + 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd4, 0xc3, 0xb0, 0x41, 0x2f, 0x00, 0xac, 0xc0, 0x89, 0xe5, 0xc4, + 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x72, 0x21, 0x33, 0x2e, 0x36, 0xb0, 0xc1, 0xc5, 0x12, 0x4c, 0x0a, + 0xcc, 0x1a, 0xdc, 0x46, 0x12, 0x58, 0x34, 0xba, 0x83, 0x14, 0xc0, 0xf4, 0x41, 0x54, 0x0b, 0x29, + 0x71, 0xf1, 0xe6, 0x24, 0x16, 0x97, 0xc4, 0x83, 0xb9, 0xf1, 0x99, 0x29, 0x12, 0xcc, 0x0a, 0x8c, + 0x1a, 0x2c, 0x41, 0xdc, 0x20, 0x41, 0xb0, 0x7a, 0xcf, 0x14, 0xa7, 0xc0, 0x13, 0x8f, 0xe4, 0x18, + 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, + 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4f, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, + 0xcf, 0xd5, 0x4f, 0xa9, 0xcc, 0x4d, 0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0xab, 0xa8, 0xac, 0x42, 0x70, + 0x74, 0x8b, 0x52, 0xb2, 0xf5, 0x2b, 0xf4, 0x11, 0xde, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, + 0x03, 0xfb, 0xdf, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x2d, 0xe6, 0xc7, 0xa4, 0x5a, 0x01, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/dividends/types/keys.go b/x/dividends/types/keys.go index b9783439..236ee6a7 100644 --- a/x/dividends/types/keys.go +++ b/x/dividends/types/keys.go @@ -3,14 +3,17 @@ package types import "cosmossdk.io/collections" const ( - // ModuleName defines the module name. + // ModuleName defines the module name ModuleName = "dividends" - // StoreKey defines the primary module store key. + // StoreKey defines the primary module store key StoreKey = ModuleName - // RouterKey is the message route for slashing. + // RouterKey is the message route for slashing RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName ) const ( diff --git a/x/dividends/types/msgs.go b/x/dividends/types/msgs.go new file mode 100644 index 00000000..116d92c9 --- /dev/null +++ b/x/dividends/types/msgs.go @@ -0,0 +1,32 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (msg MsgCreateGauge) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + if err := msg.QueryCondition.ValidateBasic(); err != nil { + return err + } + if err := msg.VestingCondition.ValidateBasic(); err != nil { + return err + } + if msg.VestingFrequency == VestingFrequency_VESTING_FREQUENCY_UNSPECIFIED { + return sdkerrors.ErrInvalidRequest.Wrap("vesting frequency cannot be zero") + } + return nil +} + +func (msg MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + if err := msg.NewParams.Validate(); err != nil { + return err + } + return nil +} diff --git a/x/dividends/types/params.go b/x/dividends/types/params.go new file mode 100644 index 00000000..6b8bb906 --- /dev/null +++ b/x/dividends/types/params.go @@ -0,0 +1,30 @@ +package types + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + epochtypes "github.com/dymensionxyz/dymension-rdk/x/epochs/types" +) + +func DefaultParams() Params { + return Params{ + DistrEpochIdentifier: "day", + ApprovedDenoms: []string{sdk.DefaultBondDenom}, + } +} + +func (p Params) Validate() error { + err := epochtypes.ValidateEpochIdentifierString(p.DistrEpochIdentifier) + if err != nil { + return fmt.Errorf("validate distribution epoch identifier: %w", err) + } + + for _, denom := range p.ApprovedDenoms { + if err := sdk.ValidateDenom(denom); err != nil { + return fmt.Errorf("validate approved denom: %w", err) + } + } + + return nil +} diff --git a/x/dividends/types/query.pb.go b/x/dividends/types/query.pb.go index 4cec24e6..db9a142b 100644 --- a/x/dividends/types/query.pb.go +++ b/x/dividends/types/query.pb.go @@ -6,12 +6,10 @@ package types import ( context "context" fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types" query "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -77,7 +75,7 @@ func (m *GaugeByIDRequest) GetId() uint64 { } type GaugeByIDResponse struct { - Gauge *Gauge `protobuf:"bytes,1,opt,name=gauge,proto3" json:"gauge,omitempty"` + Gauge Gauge `protobuf:"bytes,1,opt,name=gauge,proto3" json:"gauge"` } func (m *GaugeByIDResponse) Reset() { *m = GaugeByIDResponse{} } @@ -113,11 +111,11 @@ func (m *GaugeByIDResponse) XXX_DiscardUnknown() { var xxx_messageInfo_GaugeByIDResponse proto.InternalMessageInfo -func (m *GaugeByIDResponse) GetGauge() *Gauge { +func (m *GaugeByIDResponse) GetGauge() Gauge { if m != nil { return m.Gauge } - return nil + return Gauge{} } type GaugesRequest struct { @@ -253,7 +251,7 @@ func (m *ParamsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ParamsRequest proto.InternalMessageInfo type ParamsResponse struct { - Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } func (m *ParamsResponse) Reset() { *m = ParamsResponse{} } @@ -289,11 +287,11 @@ func (m *ParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ParamsResponse proto.InternalMessageInfo -func (m *ParamsResponse) GetParams() *Params { +func (m *ParamsResponse) GetParams() Params { if m != nil { return m.Params } - return nil + return Params{} } func init() { @@ -308,40 +306,38 @@ func init() { func init() { proto.RegisterFile("dividends/query.proto", fileDescriptor_6ae227fd43ef89d3) } var fileDescriptor_6ae227fd43ef89d3 = []byte{ - // 514 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0x9b, 0xd2, 0x55, 0xc2, 0x68, 0x85, 0x59, 0x80, 0xba, 0x82, 0x42, 0x97, 0xf1, 0x4f, - 0x20, 0x6c, 0xb5, 0x1c, 0xb8, 0x77, 0x88, 0x89, 0xdb, 0x96, 0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55, 0xf3, 0x32, 0x80, 0xce, 0xce, 0x1a, 0x85, 0xf3, 0xde, - 0x31, 0xde, 0xb7, 0xe0, 0xf6, 0x2a, 0x6f, 0x5d, 0x38, 0xda, 0x4c, 0x96, 0x3a, 0x2e, 0x44, 0xbe, - 0xd4, 0x71, 0x71, 0x07, 0x6b, 0x1d, 0x6d, 0xe6, 0x83, 0xc3, 0xb3, 0x89, 0xef, 0x9d, 0x4f, 0x7c, - 0xef, 0xd7, 0xc4, 0xf7, 0xbe, 0x4e, 0xfd, 0xda, 0xf9, 0xd4, 0xaf, 0xfd, 0x98, 0xfa, 0xb5, 0xd7, - 0xcf, 0xb8, 0x48, 0xdf, 0x66, 0x11, 0x1a, 0xca, 0x31, 0xa6, 0xf9, 0x98, 0xc5, 0x5a, 0xc8, 0xf8, - 0x34, 0x7f, 0x3f, 0x3f, 0x3c, 0x49, 0xe8, 0x3b, 0x7c, 0x5a, 0xe9, 0x99, 0xe6, 0x8a, 0xe9, 0xa8, - 0x69, 0xbe, 0xba, 0xa7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x85, 0x56, 0xed, 0xb6, 0x70, 0x04, - 0x00, 0x00, + // 490 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0xb3, 0x6b, 0x1a, 0x70, 0xa4, 0xd1, 0x0e, 0x0a, 0x69, 0x94, 0x35, 0xdd, 0xfa, 0x0f, + 0xc5, 0x19, 0x1a, 0x85, 0xde, 0x8b, 0x58, 0x72, 0x6b, 0x73, 0x11, 0xbc, 0x94, 0xd9, 0xce, 0x30, + 0x0e, 0x26, 0x3b, 0xd3, 0x9d, 0x49, 0xe9, 0x2a, 0x5e, 0xf4, 0x2c, 0x08, 0x7e, 0xa9, 0x1e, 0x0b, + 0x5e, 0x3c, 0x89, 0x24, 0x7e, 0x01, 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xed, + 0x62, 0x12, 0xd5, 0xbe, 0x4f, 0xa2, 0xda, 0xeb, 0x5d, 0x2e, 0xcc, 0x9b, 0x51, 0x82, 0x8e, 0xe5, + 0x10, 0xd3, 0x7c, 0xc8, 0x52, 0x2d, 0x64, 0x7a, 0x96, 0xbf, 0x9b, 0x1d, 0x9e, 0x66, 0xf4, 0x2d, + 0x3e, 0x9b, 0x9b, 0x69, 0x72, 0xc5, 0x74, 0xd2, 0xb0, 0x5f, 0xe0, 0xb3, 0x3f, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x21, 0xd1, 0x1f, 0x19, 0x24, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -544,18 +540,16 @@ func (m *GaugeByIDResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Gauge != nil { - { - size, err := m.Gauge.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + { + size, err := m.Gauge.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -686,18 +680,16 @@ func (m *ParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Params != nil { - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -730,10 +722,8 @@ func (m *GaugeByIDResponse) Size() (n int) { } var l int _ = l - if m.Gauge != nil { - l = m.Gauge.Size() - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Gauge.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -784,10 +774,8 @@ func (m *ParamsResponse) Size() (n int) { } var l int _ = l - if m.Params != nil { - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -924,9 +912,6 @@ func (m *GaugeByIDResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Gauge == nil { - m.Gauge = &Gauge{} - } if err := m.Gauge.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1266,9 +1251,6 @@ func (m *ParamsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Params == nil { - m.Params = &Params{} - } if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/dividends/types/tx.pb.go b/x/dividends/types/tx.pb.go index 42537855..69afa2c5 100644 --- a/x/dividends/types/tx.pb.go +++ b/x/dividends/types/tx.pb.go @@ -6,11 +6,12 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" - _ "github.com/gogo/protobuf/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -32,16 +33,14 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgCreateGauge creates a gague to distribute rewards to users type MsgCreateGauge struct { - // id is the unique ID of a gauge - Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // address is a bech32-formatted address that holds the tokens to allocate - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + // Authority is the address that controls the module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` // query_condition is *where* the gauge rewards are distributed to - QueryCondition *QueryCondition `protobuf:"bytes,3,opt,name=query_condition,json=queryCondition,proto3" json:"query_condition,omitempty"` + QueryCondition QueryCondition `protobuf:"bytes,2,opt,name=query_condition,json=queryCondition,proto3" json:"query_condition"` // vesting_condition is *how long* the gauge rewards are distributed to - VestingCondition *VestingCondition `protobuf:"bytes,4,opt,name=vesting_condition,json=vestingCondition,proto3" json:"vesting_condition,omitempty"` + VestingCondition VestingCondition `protobuf:"bytes,3,opt,name=vesting_condition,json=vestingCondition,proto3" json:"vesting_condition"` // vesting_condition is *how frequent* the gauge rewards are distributed to - VestingFrequency VestingFrequency `protobuf:"varint,5,opt,name=vesting_frequency,json=vestingFrequency,proto3,enum=rollapp.dividends.VestingFrequency" json:"vesting_frequency,omitempty"` + VestingFrequency VestingFrequency `protobuf:"varint,4,opt,name=vesting_frequency,json=vestingFrequency,proto3,enum=rollapp.dividends.VestingFrequency" json:"vesting_frequency,omitempty"` } func (m *MsgCreateGauge) Reset() { *m = MsgCreateGauge{} } @@ -77,32 +76,25 @@ func (m *MsgCreateGauge) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreateGauge proto.InternalMessageInfo -func (m *MsgCreateGauge) GetId() uint64 { +func (m *MsgCreateGauge) GetAuthority() string { if m != nil { - return m.Id - } - return 0 -} - -func (m *MsgCreateGauge) GetAddress() string { - if m != nil { - return m.Address + return m.Authority } return "" } -func (m *MsgCreateGauge) GetQueryCondition() *QueryCondition { +func (m *MsgCreateGauge) GetQueryCondition() QueryCondition { if m != nil { return m.QueryCondition } - return nil + return QueryCondition{} } -func (m *MsgCreateGauge) GetVestingCondition() *VestingCondition { +func (m *MsgCreateGauge) GetVestingCondition() VestingCondition { if m != nil { return m.VestingCondition } - return nil + return VestingCondition{} } func (m *MsgCreateGauge) GetVestingFrequency() VestingFrequency { @@ -148,39 +140,139 @@ func (m *MsgCreateGaugeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreateGaugeResponse proto.InternalMessageInfo +// MsgUpdateParams allows to update module params. +type MsgUpdateParams struct { + // Authority is the address that controls the module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // NewParams should be fully populated. + NewParams Params `protobuf:"bytes,2,opt,name=new_params,json=newParams,proto3" json:"new_params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_957086822ec1c0b6, []int{2} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetNewParams() Params { + if m != nil { + return m.NewParams + } + return Params{} +} + +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_957086822ec1c0b6, []int{3} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreateGauge)(nil), "rollapp.dividends.MsgCreateGauge") proto.RegisterType((*MsgCreateGaugeResponse)(nil), "rollapp.dividends.MsgCreateGaugeResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "rollapp.dividends.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "rollapp.dividends.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("dividends/tx.proto", fileDescriptor_957086822ec1c0b6) } var fileDescriptor_957086822ec1c0b6 = []byte{ - // 382 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x8e, 0xd2, 0x40, - 0x18, 0xc7, 0x99, 0x82, 0x1a, 0x87, 0xa4, 0x4a, 0xa3, 0xa6, 0xe1, 0x50, 0x2b, 0x5e, 0xea, 0xc1, - 0x4e, 0xc0, 0x83, 0x77, 0x49, 0x34, 0x31, 0x21, 0x91, 0x1e, 0x3c, 0xe8, 0xc1, 0xb4, 0x9d, 0x8f, - 0x71, 0x22, 0x9d, 0x29, 0x9d, 0x69, 0x43, 0x7d, 0x8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0x4a, 0x73, - 0xc1, 0x1a, 0xb6, 0x4e, 0x65, 0x7b, 0x7f, 0xc6, 0xf6, 0x73, 0xc7, 0x1e, 0x7d, 0x2f, 0x8b, 0x3b, - 0x93, 0xa6, 0x71, 0x96, 0xc1, 0x22, 0x07, 0x11, 0x97, 0xf6, 0x13, 0x17, 0x79, 0xe6, 0x43, 0xc6, - 0xaf, 0x35, 0x7a, 0x30, 0x1e, 0x26, 0x03, 0x1b, 0xbf, 0x39, 0xdd, 0x55, 0x00, 0x2a, 0x95, 0x42, - 0xc1, 0x28, 0xc2, 0xed, 0x89, 0x62, 0xd6, 0x6f, 0xdc, 0x6d, 0x6e, 0xf2, 0xdc, 0x1a, 0x4e, 0x05, - 0xfd, 0x0f, 0x8f, 0x22, 0xf5, 0x1b, 0x5f, 0xa6, 0x57, 0x6b, 0x07, 0xad, 0xd6, 0x0e, 0xba, 0x59, - 0x3b, 0xe8, 0x62, 0xe3, 0xb4, 0x56, 0x1b, 0xa7, 0x75, 0xbd, 0x71, 0x5a, 0xbf, 0x3e, 0x33, 0xae, - 0xff, 0xe6, 0x91, 0x1f, 0xcb, 0x84, 0xd0, 0x32, 0x01, 0xa1, 0xb8, 0x14, 0xcb, 0xf2, 0xff, 0x31, - 0x7c, 0xcc, 0xe8, 0x3f, 0xb2, 0x24, 0x8d, 0x0b, 0x2c, 0x53, 0x50, 0xd1, 0xd3, 0xea, 0x08, 0x3e, - 0xdd, 0x06, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x02, 0x00, 0xd7, 0x9b, 0x02, 0x00, 0x00, + // 490 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xc7, 0xb3, 0x6d, 0x11, 0x32, 0x95, 0xd4, 0x2e, 0xd5, 0x26, 0x39, 0xac, 0x69, 0xbc, 0xc4, + 0x42, 0x77, 0x48, 0x05, 0x05, 0x0f, 0x82, 0x29, 0xe8, 0x29, 0x90, 0x46, 0xec, 0x41, 0xc1, 0x30, + 0xd9, 0x79, 0x4e, 0x07, 0xbb, 0x33, 0x9b, 0x99, 0xd9, 0x6d, 0xd6, 0xa3, 0x9f, 0xc0, 0xab, 0xdf, + 0xc2, 0x83, 0x9f, 0xc0, 0x53, 0x8f, 0x45, 0x3c, 0x78, 0x12, 0x49, 0x0e, 0x7e, 0x0d, 0x49, 0x76, + 0x37, 0x9b, 0xa4, 0xc1, 0x42, 0x4f, 0xbb, 0xef, 0xfd, 0xff, 0xfb, 0x7b, 0xff, 0x79, 0xec, 0x20, + 0x9b, 0xf2, 0x88, 0x53, 0x10, 0x54, 0x63, 0x33, 0x74, 0x03, 0x25, 0x8d, 0xb4, 0xb7, 0x95, 0x3c, + 0x3b, 0x23, 0x41, 0xe0, 0xce, 0xb4, 0xea, 0x0e, 0x93, 0x4c, 0x4e, 0x55, 0x3c, 0x79, 0x4b, 0x8c, + 0xd5, 0x8a, 0x27, 0xb5, 0x2f, 0x75, 0x2f, 0x11, 0x92, 0x22, 0x95, 0x76, 0x93, 0x0a, 0xfb, 0x9a, + 0xe1, 0xa8, 0x39, 0x79, 0xa4, 0x82, 0x93, 0x0a, 0x7d, 0xa2, 0x01, 0x47, 0xcd, 0x3e, 0x18, 0xd2, + 0xc4, 0x9e, 0xe4, 0x22, 0xd5, 0xef, 0xe6, 0x81, 0x18, 0x09, 0x19, 0x24, 0xed, 0xfa, 0xcf, 0x35, + 0x54, 0x6a, 0x6b, 0x76, 0xa4, 0x80, 0x18, 0x78, 0x39, 0x11, 0xec, 0xc7, 0xa8, 0x48, 0x42, 0x73, + 0x2a, 0x15, 0x37, 0x71, 0xd9, 0xaa, 0x59, 0x8d, 0x62, 0xab, 0xfc, 0xe3, 0xdb, 0xc1, 0x4e, 0x9a, + 0xe3, 0x39, 0xa5, 0x0a, 0xb4, 0x7e, 0x65, 0x14, 0x17, 0xac, 0x9b, 0x5b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73, 0xfe, 0x5f, 0xdc, 0x5b, 0xfd, 0xe9, 0x9c, 0xa5, 0xfa, 0xf0, 0x5a, 0x4b, 0x06, + 0x6f, 0x1d, 0x5f, 0x8c, 0x1c, 0xeb, 0x72, 0xe4, 0x58, 0x7f, 0x46, 0x8e, 0xf5, 0x79, 0xec, 0x14, + 0x2e, 0xc7, 0x4e, 0xe1, 0xd7, 0xd8, 0x29, 0xbc, 0x79, 0xc2, 0xb8, 0x39, 0x0d, 0xfb, 0xae, 0x27, + 0x7d, 0x4c, 0x63, 0x1f, 0x84, 0xe6, 0x52, 0x0c, 0xe3, 0x8f, 0x79, 0x71, 0xa0, 0xe8, 0x07, 0x3c, + 0xc4, 0x73, 0xd7, 0x3a, 0x0e, 0x40, 0xf7, 0x6f, 0x4d, 0xaf, 0xd1, 0xa3, 0x7f, 0x01, 0x00, 0x00, + 0xff, 0xff, 0xd0, 0x3c, 0x35, 0xc2, 0xf0, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -195,6 +287,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) CreateGauge(ctx context.Context, in *MsgCreateGauge, opts ...grpc.CallOption) (*MsgCreateGaugeResponse, error) } @@ -206,6 +299,15 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/rollapp.dividends.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) CreateGauge(ctx context.Context, in *MsgCreateGauge, opts ...grpc.CallOption) (*MsgCreateGaugeResponse, error) { out := new(MsgCreateGaugeResponse) err := c.cc.Invoke(ctx, "/rollapp.dividends.Msg/CreateGauge", in, out, opts...) @@ -217,6 +319,7 @@ func (c *msgClient) CreateGauge(ctx context.Context, in *MsgCreateGauge, opts .. // MsgServer is the server API for Msg service. type MsgServer interface { + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) CreateGauge(context.Context, *MsgCreateGauge) (*MsgCreateGaugeResponse, error) } @@ -224,6 +327,9 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func (*UnimplementedMsgServer) CreateGauge(ctx context.Context, req *MsgCreateGauge) (*MsgCreateGaugeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateGauge not implemented") } @@ -232,6 +338,24 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollapp.dividends.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_CreateGauge_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgCreateGauge) if err := dec(in); err != nil { @@ -254,6 +378,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "rollapp.dividends.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, { MethodName: "CreateGauge", Handler: _Msg_CreateGauge_Handler, @@ -286,43 +414,34 @@ func (m *MsgCreateGauge) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.VestingFrequency != 0 { i = encodeVarintTx(dAtA, i, uint64(m.VestingFrequency)) i-- - dAtA[i] = 0x28 + dAtA[i] = 0x20 } - if m.VestingCondition != nil { - { - size, err := m.VestingCondition.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + { + size, err := m.VestingCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x22 + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - if m.QueryCondition != nil { - { - size, err := m.QueryCondition.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a + { + size, err := m.QueryCondition.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x1a - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - if m.Id != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -350,6 +469,69 @@ func (m *MsgCreateGaugeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.NewParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -367,21 +549,14 @@ func (m *MsgCreateGauge) Size() (n int) { } var l int _ = l - if m.Id != 0 { - n += 1 + sovTx(uint64(m.Id)) - } - l = len(m.Address) + l = len(m.Authority) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.QueryCondition != nil { - l = m.QueryCondition.Size() - n += 1 + l + sovTx(uint64(l)) - } - if m.VestingCondition != nil { - l = m.VestingCondition.Size() - n += 1 + l + sovTx(uint64(l)) - } + l = m.QueryCondition.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.VestingCondition.Size() + n += 1 + l + sovTx(uint64(l)) if m.VestingFrequency != 0 { n += 1 + sovTx(uint64(m.VestingFrequency)) } @@ -397,6 +572,30 @@ func (m *MsgCreateGaugeResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.NewParams.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -433,27 +632,8 @@ func (m *MsgCreateGauge) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -481,9 +661,9 @@ func (m *MsgCreateGauge) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Authority = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field QueryCondition", wireType) } @@ -512,14 +692,11 @@ func (m *MsgCreateGauge) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.QueryCondition == nil { - m.QueryCondition = &QueryCondition{} - } if err := m.QueryCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 4: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field VestingCondition", wireType) } @@ -548,14 +725,11 @@ func (m *MsgCreateGauge) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.VestingCondition == nil { - m.VestingCondition = &VestingCondition{} - } if err := m.VestingCondition.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 5: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field VestingFrequency", wireType) } @@ -645,6 +819,171 @@ func (m *MsgCreateGaugeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NewParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0