Skip to content

Commit

Permalink
module basic, validation, scaffolding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch committed Feb 5, 2025
1 parent 6b9867e commit a27d903
Show file tree
Hide file tree
Showing 30 changed files with 2,305 additions and 1,125 deletions.
25 changes: 25 additions & 0 deletions proto/dividends/events.proto
Original file line number Diff line number Diff line change
@@ -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;
}
23 changes: 15 additions & 8 deletions proto/dividends/gauge.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -32,7 +39,7 @@ message QueryCondition {
message VestingCondition {
oneof condition {
VestingConditionPerpetual perpetual = 1;
VestingConditionLimited epoch = 2;
VestingConditionLimited limited = 2;
}
}

Expand Down Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions proto/dividends/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
16 changes: 0 additions & 16 deletions proto/dividends/params.proto

This file was deleted.

9 changes: 3 additions & 6 deletions proto/dividends/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -31,20 +28,20 @@ message GaugeByIDRequest {
}

message GaugeByIDResponse {
Gauge gauge = 1;
Gauge gauge = 1 [ (gogoproto.nullable) = false ];
}

message GaugesRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

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 ];
}
30 changes: 22 additions & 8 deletions proto/dividends/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
22 changes: 22 additions & 0 deletions testutil/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -198,6 +203,7 @@ var (
wasm.AppModuleBasic{},
tokenfactory.NewAppModuleBasic(),
rollappparams.AppModuleBasic{},
dividends.AppModuleBasic{},
)

// module account permissions
Expand All @@ -214,6 +220,7 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
rollappparamstypes.ModuleName: nil,
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
dividendstypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -639,6 +658,7 @@ func NewRollapp(
tokenfactorytypes.ModuleName,
gaslesstypes.ModuleName,
rollappparamstypes.ModuleName,
dividendstypes.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -663,6 +683,7 @@ func NewRollapp(
tokenfactorytypes.ModuleName,
gaslesstypes.ModuleName,
rollappparamstypes.ModuleName,
dividendstypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -693,6 +714,7 @@ func NewRollapp(
tokenfactorytypes.ModuleName,
gaslesstypes.ModuleName,
rollappparamstypes.ModuleName,
dividendstypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down
2 changes: 1 addition & 1 deletion testutil/app/apptesting/apptesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})

Check warning

Code scanning / CodeQL

Calling the system time Warning test

Calling the system time may be a possible source of non-determinism
s.QueryHelper = &baseapp.QueryServiceTestHelper{
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
Expand Down
Loading

0 comments on commit a27d903

Please sign in to comment.