Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use staking middleware in custom staking module to batch delegation. #302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,7 +29,7 @@
}

func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) {

Check failure on line 32 in custom/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
ctx := sdk.UnwrapSDKContext(goCtx)

// bondDenom := k.BondDenom(ctx)
Expand All @@ -45,6 +45,7 @@
// 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,25 +21,28 @@
}

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{}
res, err := queryClient.Power(cmd.Context(), params)
Expand Down
Loading