Skip to content

Commit

Permalink
use staking middleware in custom staking module to batch delegation.
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed Dec 18, 2023
1 parent 3e82118 commit 5723863
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())

appKeepers.CustomStakingKeeper = customstaking.NewKeeper(
appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, &appKeepers.StakingMiddlewareKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())

appKeepers.DistrKeeper = distrkeeper.NewKeeper(
appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper,
appKeepers.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down
22 changes: 13 additions & 9 deletions custom/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

mintkeeper "github.com/notional-labs/composable/v6/x/mint/keeper"
stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper"
)

type Keeper struct {
stakingkeeper.Keeper
cdc codec.BinaryCodec
acck accountkeeper.AccountKeeper
mintkeeper *mintkeeper.Keeper
authority string
cdc codec.BinaryCodec
acck accountkeeper.AccountKeeper
mintkeeper *mintkeeper.Keeper
stakingmiddleware *stakingmiddleware.Keeper
authority string
}

// func NewBaseKeeper(
Expand All @@ -36,14 +38,16 @@ func NewKeeper(
staking stakingkeeper.Keeper,
acck accountkeeper.AccountKeeper,
mintkeeper *mintkeeper.Keeper,
stakingmiddleware *stakingmiddleware.Keeper,
authority string,
) Keeper {
keeper := Keeper{
Keeper: staking,
acck: acck,
authority: authority,
mintkeeper: mintkeeper,
cdc: cdc,
Keeper: staking,
acck: acck,
authority: authority,
mintkeeper: mintkeeper,
stakingmiddleware: stakingmiddleware,
cdc: cdc,
}
return keeper
}
Expand Down
1 change: 1 addition & 0 deletions custom/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ
// Shares: msg.Amount.Amount.ToLegacyDec(),
// }
k.mintkeeper.SetLastTotalPower(ctx, math.Int{})
k.stakingmiddleware.SetLastTotalPower(ctx, math.Int{})

return &types.MsgDelegateResponse{}, nil
// return nil, fmt.Errorf("My custom error: Nikita")
Expand Down
11 changes: 7 additions & 4 deletions x/stakingmiddleware/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ func GetQueryCmd() *cobra.Command {
}

mintingQueryCmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryPower(),
)

return mintingQueryCmd
}

// GetCmdQueryParams implements a command to return the current minting
// parameters.
func GetCmdQueryParams() *cobra.Command {
func GetCmdQueryPower() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current minting parameters",
Use: "power",
Short: "Query the current power",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

return clientCtx.PrintString(fmt.Sprintf("%s\n", "hello world"))

queryClient := types.NewQueryClient(clientCtx)

Check failure on line 45 in x/stakingmiddleware/client/cli/query.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)

params := &types.QueryPowerRequest{}
Expand Down

0 comments on commit 5723863

Please sign in to comment.