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

integrate staking middleware module into cosmos chain #301

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
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
custombankmodule "github.com/notional-labs/composable/v6/custom/bank"

"github.com/notional-labs/composable/v6/app/ante"
"github.com/notional-labs/composable/v6/x/stakingmiddleware"
transfermiddleware "github.com/notional-labs/composable/v6/x/transfermiddleware"
transfermiddlewaretypes "github.com/notional-labs/composable/v6/x/transfermiddleware/types"

Expand All @@ -125,6 +126,7 @@
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

upgrades "github.com/notional-labs/composable/v6/app/upgrades"
stakingmiddlewaretypes "github.com/notional-labs/composable/v6/x/stakingmiddleware/types"
)

const (
Expand Down Expand Up @@ -219,6 +221,7 @@
txBoundary.AppModuleBasic{},
ratelimitmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
stakingmiddleware.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -358,7 +361,8 @@
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
customstaking.NewAppModule(appCodec, *&app.CustomStakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),

Check failure on line 364 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

SA4001: *&x will be simplified to x. It will not copy x. (staticcheck)
stakingmiddleware.NewAppModule(appCodec, app.StakingMiddlewareKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down Expand Up @@ -412,6 +416,7 @@
wasm08types.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
stakingmiddlewaretypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -445,6 +450,7 @@
wasm08types.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
stakingmiddlewaretypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -482,6 +488,7 @@
wasm08types.ModuleName,
icatypes.ModuleName,
wasm.ModuleName,
stakingmiddlewaretypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down
5 changes: 5 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ import (
ibc_hooks "github.com/notional-labs/composable/v6/x/ibc-hooks"
ibchookskeeper "github.com/notional-labs/composable/v6/x/ibc-hooks/keeper"
ibchookstypes "github.com/notional-labs/composable/v6/x/ibc-hooks/types"
stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper"
stakingmiddlewaretypes "github.com/notional-labs/composable/v6/x/stakingmiddleware/types"
)

const (
Expand Down Expand Up @@ -150,6 +152,7 @@ type AppKeepers struct {
TxBoundaryKeepper txBoundaryKeeper.Keeper
RouterKeeper *routerkeeper.Keeper
RatelimitKeeper ratelimitmodulekeeper.Keeper
StakingMiddlewareKeeper stakingmiddleware.Keeper
}

// InitNormalKeepers initializes all 'normal' keepers.
Expand Down Expand Up @@ -194,6 +197,8 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, 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
4 changes: 3 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasm08types "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"

// customstakingtypes "github.com/notional-labs/composable/v6/custom/staking/types"
stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/types"
)

// GenerateKeys generates new keys (KV Store, Transient store, and memory store).
Expand All @@ -53,7 +55,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icqtypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, wasm08types.StoreKey,
crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey, txBoundaryTypes.StoreKey,
authzkeeper.StoreKey, /*customstakingtypes.StoreKey,*/
authzkeeper.StoreKey, stakingmiddleware.StoreKey, /*customstakingtypes.StoreKey,*/
)

// Define transient store keys
Expand Down
1 change: 1 addition & 0 deletions proto/centauri/stakingmiddleware/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ service Msg {
//
// Since: cosmos-sdk 0.47
message MsgSetPower {
string from_address = 1;
}

// MsgSetPowerResponse defines the response structure for executing a
Expand Down
27 changes: 25 additions & 2 deletions x/stakingmiddleware/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

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

// GetTxCmd returns the tx commands for mint
Expand All @@ -17,7 +19,28 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

txCmd.AddCommand()
txCmd.AddCommand(
GetCmdSetPower(),
)

return txCmd
}

func GetCmdSetPower() *cobra.Command {
cmd := &cobra.Command{
Use: "fund [amount]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgSetPower(clientCtx.GetFromAddress())
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}
11 changes: 6 additions & 5 deletions x/stakingmiddleware/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stakingmiddleware

import (
"context"
"encoding/json"
"fmt"

Expand All @@ -18,8 +19,8 @@
"github.com/notional-labs/composable/v6/x/mint/simulation"
"github.com/notional-labs/composable/v6/x/stakingmiddleware/client/cli"
"github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper"
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types"

Check failure on line 22 in x/stakingmiddleware/module.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" is being imported more than once (stylecheck)
middlewarestaking "github.com/notional-labs/composable/v6/x/stakingmiddleware/types"

Check failure on line 23 in x/stakingmiddleware/module.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" (stylecheck)
)

var (
Expand All @@ -42,12 +43,12 @@

// RegisterLegacyAminoCodec registers the mint module's types on the given LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// types.RegisterLegacyAminoCodec(cdc)
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers the module interface
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
// types.RegisterInterfaces(reg)
types.RegisterInterfaces(reg)
}

// DefaultGenesis returns default genesis state as raw bytes for the mint
Expand All @@ -68,9 +69,9 @@

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
// if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
// panic(err)
// }
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns no root tx command for the mint module.
Expand Down
45 changes: 45 additions & 0 deletions x/stakingmiddleware/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// RegisterLegacyAminoCodec registers the account interfaces and concrete types on the
// provided LegacyAmino codec. These types are used for Amino JSON serialization
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgSetPower{}, "composable/MsgSetPower")
}

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgSetPower{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)

// Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}
5 changes: 3 additions & 2 deletions x/stakingmiddleware/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ var (

const (
// module name
ModuleName = "customstaking"
ModuleName = "stakingmiddleware"

// StoreKey is the default store key for mint
StoreKey = ModuleName

StoreKey = "customstmiddleware" // not using the module name because of collisions with key "ibc"
)

// GetDelegationKey creates the key for delegator bond with validator
Expand Down
44 changes: 44 additions & 0 deletions x/stakingmiddleware/types/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package types

import (
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ sdk.Msg = &MsgSetPower{}

// Route Implements Msg.
func (m MsgSetPower) Route() string { return sdk.MsgTypeURL(&m) }

// Type Implements Msg.
func (m MsgSetPower) Type() string { return sdk.MsgTypeURL(&m) }

// GetSigners returns the expected signers for a MsgMintAndAllocateExp .
func (m MsgSetPower) GetSigners() []sdk.AccAddress {
daoAccount, err := sdk.AccAddressFromBech32(m.FromAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{daoAccount}
}

// GetSignBytes Implements Msg.
func (m MsgSetPower) GetSignBytes() []byte {
return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m MsgSetPower) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.FromAddress)
if err != nil {
return errorsmod.Wrap(err, "from address must be valid address")
}
return nil
}

func NewMsgSetPower(fromAddr sdk.AccAddress) *MsgSetPower {
return &MsgSetPower{
FromAddress: fromAddr.String(),
}
}
Loading
Loading