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

add main bond denom #141

Merged
merged 3 commits into from
Jul 16, 2024
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
9 changes: 9 additions & 0 deletions proto/multistaking/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package multistaking.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/realiotech/multi-staking/x/multi-staking/types";

// Params defines the incentives module params
message Params { string main_bond_denom = 1; }
28 changes: 28 additions & 0 deletions proto/multistaking/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package multistaking.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "multistaking/v1/params.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/realiotech/multi-staking/x/multi-staking/types";

service Msg {
rpc UpdateMultiStakingParams(MsgUpdateMultiStakingParams)
returns (MsgUpdateMultiStakingParamsResponse);
}

message MsgUpdateMultiStakingParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/evm parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
}

message MsgUpdateMultiStakingParamsResponse {}
1 change: 1 addition & 0 deletions test/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func NewSimApp(
app.StakingKeeper,
app.BankKeeper,
keys[multistakingtypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper)
Expand Down
12 changes: 12 additions & 0 deletions x/multi-staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Keeper struct {
accountKeeper types.AccountKeeper
stakingKeeper *stakingkeeper.Keeper
bankKeeper types.BankKeeper
authority string
}

func NewKeeper(
Expand All @@ -31,13 +32,15 @@ func NewKeeper(
stakingKeeper *stakingkeeper.Keeper,
bankKeeper types.BankKeeper,
key storetypes.StoreKey,
authority string,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: key,
accountKeeper: accountKeeper,
stakingKeeper: stakingKeeper,
bankKeeper: bankKeeper,
authority: authority,
}
}

Expand Down Expand Up @@ -161,3 +164,12 @@ func (k Keeper) AdjustCancelUnbondingAmount(ctx sdk.Context, delAcc sdk.AccAddre

return math.MinInt(totalUnbondingAmount, amount), nil
}

func (k Keeper) BondDenom(ctx sdk.Context) string {
bondDenom := k.GetParams(ctx).MainBondDenom
return bondDenom
}

func (k Keeper) IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress, fn func(index int64, delegation stakingtypes.DelegationI) (stop bool)) {
k.stakingKeeper.IterateDelegations(ctx, delegator, fn)
}
29 changes: 25 additions & 4 deletions x/multi-staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,35 @@
type msgServer struct {
keeper Keeper
stakingMsgServer stakingtypes.MsgServer
authority string
}

var _ stakingtypes.MsgServer = msgServer{}

Check failure on line 19 in x/multi-staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
var _ types.MsgServer = msgServer{}

func NewMultiStakingMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{
keeper: keeper,
}
}

func (k msgServer) UpdateMultiStakingParams(goCtx context.Context, msg *types.MsgUpdateMultiStakingParams) (*types.MsgUpdateMultiStakingParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.keeper.authority != msg.Authority {
return nil, fmt.Errorf("invalid authority; expected %s, got %s", k.keeper.authority, msg.Authority)
}

// store params
if err := k.keeper.SetParams(ctx, msg.Params); err != nil {
return nil, err
}

return &types.MsgUpdateMultiStakingParamsResponse{}, nil
}

// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) stakingtypes.MsgServer {
func NewMsgServerImpl(keeper Keeper) *msgServer {
return &msgServer{
keeper: keeper,
stakingMsgServer: stakingkeeper.NewMsgServerImpl(keeper.stakingKeeper),
Expand All @@ -32,8 +53,8 @@
func (k msgServer) UpdateParams(goCtx context.Context, msg *stakingtypes.MsgUpdateParams) (*stakingtypes.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.authority != msg.Authority {
return nil, fmt.Errorf("invalid authority; expected %s, got %s", k.authority, msg.Authority)
if k.keeper.authority != msg.Authority {
return nil, fmt.Errorf("invalid authority; expected %s, got %s", k.keeper.authority, msg.Authority)
}

// store params
Expand Down
30 changes: 30 additions & 0 deletions x/multi-staking/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 4 in x/multi-staking/keeper/params.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
"github.com/realio-tech/multi-staking-module/x/multi-staking/types"

Check failure on line 5 in x/multi-staking/keeper/params.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
)

// SetParams sets the x/staking module parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)

return nil
}

// GetParams sets the x/staking module parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}

k.cdc.MustUnmarshal(bz, &params)
return params
}
3 changes: 2 additions & 1 deletion x/multi-staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ func (AppModule) QuerierRoute() string {
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
stakingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
multistakingtypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
multistakingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))

multistakingtypes.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
querier := stakingkeeper.Querier{Keeper: am.sk}
stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier)

Expand Down
19 changes: 19 additions & 0 deletions x/multi-staking/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
v1beta1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

Check failure on line 10 in x/multi-staking/types/codec.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"

Check failure on line 13 in x/multi-staking/types/codec.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
)

var (
Expand All @@ -21,21 +27,34 @@
)

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgUpdateMultiStakingParams{}, "multistaking/MsgUpdateMSParams")

cdc.RegisterConcrete(&AddMultiStakingCoinProposal{}, "multistaking/AddMultiStakingCoinProposal", nil)
cdc.RegisterConcrete(&UpdateBondWeightProposal{}, "multistaking/UpdateBondWeightProposal", nil)
// this line is used by starport scaffolding # 2
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateMultiStakingParams{},
)
registry.RegisterImplementations(
(*v1beta1types.Content)(nil),
&AddMultiStakingCoinProposal{},
&UpdateBondWeightProposal{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

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)
}
2 changes: 2 additions & 0 deletions x/multi-staking/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var (
MultiStakingLockPrefix = []byte{0x02}

MultiStakingUnlockPrefix = []byte{0x11} // key for an unbonding-delegation

ParamsKey = []byte{0x03} // prefix for parameters for module x/multistaking
)

func KeyPrefix(key string) []byte {
Expand Down
36 changes: 36 additions & 0 deletions x/multi-staking/types/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package types

import (
sdkerrors "cosmossdk.io/errors"

Check failure on line 4 in x/multi-staking/types/msg.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
sdk "github.com/cosmos/cosmos-sdk/types"
)

// staking message types
const (
TypeMsgUpdateMultiStakingParams = "update_multistaking_params"
)

var (

Check failure on line 13 in x/multi-staking/types/msg.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
_ sdk.Msg = &MsgUpdateMultiStakingParams{}
)

// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
// the expected signer needs to sign.
func (m *MsgUpdateMultiStakingParams) GetSignBytes() []byte {
bz := AminoCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

// ValidateBasic executes sanity validation on the provided data
func (m *MsgUpdateMultiStakingParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return sdkerrors.Wrap(err, "invalid authority address")
}
return nil
}

// GetSigners returns the expected signers for a MsgUpdateParams message
func (m *MsgUpdateMultiStakingParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}
Loading
Loading