-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce staking middleware prototype.
- Loading branch information
Showing
15 changed files
with
1,600 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
package centauri.stakingmiddleware.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "x/stakingmiddleware/types"; | ||
|
||
// Query provides defines the gRPC querier service. | ||
service Query { | ||
// Params returns the total set of minting parameters. | ||
rpc Power(QueryPowerRequest) returns (QueryPowerResponse) { | ||
option (google.api.http).get = "/cosmos/stakingmiddleware/v1beta1/params"; | ||
} | ||
} | ||
|
||
// QueryParamsRequest is the request type for the Query/Params RPC method. | ||
message QueryPowerRequest {} | ||
|
||
// QueryParamsResponse is the response type for the Query/Params RPC method. | ||
message QueryPowerResponse { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto3"; | ||
package centauri.stakingmiddleware.v1beta1; | ||
|
||
import "cosmos/msg/v1/msg.proto"; | ||
import "amino/amino.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
|
||
option go_package = "x/stakingmiddleware/types"; | ||
|
||
// Msg defines the x/stakingmiddleware Msg service. | ||
service Msg { | ||
option (cosmos.msg.v1.service) = true; | ||
|
||
rpc SetPower(MsgSetPower) returns (MsgSetPowerResponse); | ||
} | ||
|
||
// MsgSetPower is the Msg/SetPower request type. | ||
// | ||
// Since: cosmos-sdk 0.47 | ||
message MsgSetPower { | ||
} | ||
|
||
// MsgSetPowerResponse defines the response structure for executing a | ||
// MsgSetPower message. | ||
// | ||
// Since: cosmos-sdk 0.47 | ||
message MsgSetPowerResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for the staking middleware module. | ||
func GetQueryCmd() *cobra.Command { | ||
mintingQueryCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Querying commands for the minting module", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
mintingQueryCmd.AddCommand( | ||
GetCmdQueryParams(), | ||
) | ||
|
||
return mintingQueryCmd | ||
} | ||
|
||
// GetCmdQueryParams implements a command to return the current minting | ||
// parameters. | ||
func GetCmdQueryParams() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "params", | ||
Short: "Query the current minting parameters", | ||
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) | ||
|
||
params := &types.QueryPowerRequest{} | ||
res, err := queryClient.Power(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
_ = res | ||
|
||
// return nil | ||
return clientCtx.PrintString(fmt.Sprintf("%s\n", "hello world")) | ||
// return clientCtx.PrintProto(&res.Power) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/notional-labs/composable/v6/x/mint/types" | ||
) | ||
|
||
// GetTxCmd returns the tx commands for mint | ||
func GetTxCmd() *cobra.Command { | ||
txCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Exp transaction subcommands", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
txCmd.AddCommand() | ||
|
||
return txCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types" | ||
) | ||
|
||
// InitGenesis new mint genesis | ||
func (keeper Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { | ||
keeper.SetLastTotalPower(ctx, data.LastTotalPower) | ||
} | ||
|
||
// ExportGenesis returns a GenesisState for a given context and keeper. | ||
func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
minter := keeper.GetLastTotalPower(ctx) | ||
return types.NewGenesisState(minter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package keeper | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
"github.com/cometbft/cometbft/libs/log" | ||
"github.com/notional-labs/composable/v6/x/mint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
// "github.com/notional-labs/composable/v6/x/mint/types" | ||
) | ||
|
||
// Keeper of the staking middleware store | ||
type Keeper struct { | ||
cdc codec.BinaryCodec | ||
storeKey storetypes.StoreKey | ||
// the address capable of executing a MsgUpdateParams message. Typically, this | ||
// should be the x/gov module account. | ||
authority string | ||
} | ||
|
||
// NewKeeper creates a new middleware Keeper instance | ||
func NewKeeper( | ||
cdc codec.BinaryCodec, | ||
key storetypes.StoreKey, | ||
authority string, | ||
) Keeper { | ||
return Keeper{ | ||
cdc: cdc, | ||
storeKey: key, | ||
authority: authority, | ||
} | ||
} | ||
|
||
// GetAuthority returns the x/mint module's authority. | ||
func (k Keeper) GetAuthority() string { | ||
return k.authority | ||
} | ||
|
||
// Logger returns a module-specific logger. | ||
func (k Keeper) Logger(ctx sdk.Context) log.Logger { | ||
return ctx.Logger().With("module", "x/"+types.ModuleName) | ||
} | ||
|
||
// // SetParams sets the x/mint module parameters. | ||
// func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { | ||
// if err := p.Validate(); err != nil { | ||
// return err | ||
// } | ||
|
||
// store := ctx.KVStore(k.storeKey) | ||
// bz := k.cdc.MustMarshal(&p) | ||
// store.Set(types.ParamsKey, bz) | ||
|
||
// return nil | ||
// } | ||
|
||
// // GetParams returns the current x/mint module parameters. | ||
// func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) { | ||
// store := ctx.KVStore(k.storeKey) | ||
// bz := store.Get(types.ParamsKey) | ||
// if bz == nil { | ||
// return p | ||
// } | ||
|
||
// k.cdc.MustUnmarshal(bz, &p) | ||
// return p | ||
// } | ||
|
||
// func (k Keeper) StoreDelegation(ctx sdk.Context, delegation stakingtypes.Delegation) { | ||
// delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) | ||
// log := k.Logger(ctx) | ||
// log.Info("StoreDelegation", "delegatorAddress", delegatorAddress, "validatorAddress", delegation.GetValidatorAddr()) | ||
// store := ctx.KVStore(k.storeKey) | ||
// b := stakingtypes.MustMarshalDelegation(k.cdc, delegation) | ||
// kkk := types.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr()) | ||
// // log.Info() | ||
// store.Set(kkk, b) | ||
// } | ||
|
||
// SetLastTotalPower Set the last total validator power. | ||
func (k Keeper) SetLastTotalPower(ctx sdk.Context, power math.Int) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power}) | ||
store.Set(types.DelegationKey, bz) | ||
} | ||
|
||
func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.DelegationKey) | ||
|
||
if bz == nil { | ||
return math.ZeroInt() | ||
} | ||
|
||
ip := sdk.IntProto{} | ||
k.cdc.MustUnmarshal(bz, &ip) | ||
|
||
return ip.Int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types" | ||
) | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
// msgServer is a wrapper of Keeper. | ||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the x/mint MsgServer interface. | ||
func NewMsgServerImpl(k Keeper) types.MsgServer { | ||
return &msgServer{ | ||
Keeper: k, | ||
} | ||
} | ||
|
||
// UpdateParams updates the params. | ||
func (ms msgServer) SetPower(goCtx context.Context, req *types.MsgSetPower) (*types.MsgUpdateParamsResponse, error) { | ||
Check failure on line 24 in x/stakingmiddleware/keeper/msg_server.go GitHub Actions / build
Check failure on line 24 in x/stakingmiddleware/keeper/msg_server.go GitHub Actions / lint
Check failure on line 24 in x/stakingmiddleware/keeper/msg_server.go GitHub Actions / lint
Check failure on line 24 in x/stakingmiddleware/keeper/msg_server.go GitHub Actions / test
|
||
|
||
return &types.MsgSetPowerResponse{}, nil | ||
} |
Oops, something went wrong.