Skip to content

Commit

Permalink
boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
asalzmann committed Sep 17, 2023
1 parent 52581d2 commit 6158058
Show file tree
Hide file tree
Showing 9 changed files with 747 additions and 109 deletions.
2 changes: 1 addition & 1 deletion deps/gaia
Submodule gaia updated 220 files
19 changes: 19 additions & 0 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,27 @@ service Msg {
rpc UpdateValidatorSharesExchRate(MsgUpdateValidatorSharesExchRate)
returns (MsgUpdateValidatorSharesExchRateResponse);
rpc ClearBalance(MsgClearBalance) returns (MsgClearBalanceResponse);
rpc UpdateTightBounds(MsgUpdateTightBounds)
returns (MsgUpdateTightBoundsResponse);
}

message MsgUpdateTightBounds {
string creator = 1;
string chain_id = 2;
string min_tight_redemption_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string max_tight_redemption_rate = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MsgUpdateTightBoundsResponse {}

message MsgLiquidStake {
string creator = 1;
string amount = 2 [
Expand Down
1 change: 1 addition & 0 deletions x/stakeibc/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdRestoreInterchainAccount())
cmd.AddCommand(CmdUpdateValidatorSharesExchRate())
cmd.AddCommand(CmdClearBalance())
cmd.AddCommand(CmdUpdateTightBounds())

return cmd
}
59 changes: 59 additions & 0 deletions x/stakeibc/client/cli/tx_update_tight_bounds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cli

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

"github.com/Stride-Labs/stride/v14/x/stakeibc/types"
)

func CmdUpdateTightBounds() *cobra.Command {
cmd := &cobra.Command{
Use: "update-tight-bounds [chainid] [min-bound] [max-bound]",
Short: "Broadcast message update-tight-bounds",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argChainId := args[0]
minRedemptionRateStr := args[1]
maxRedemptionRateStr := args[2]

minTightRedemptionRate := sdk.ZeroDec()
if minRedemptionRateStr != "" {
minTightRedemptionRate, err = sdk.NewDecFromStr(minRedemptionRateStr)
if err != nil {
return err
}
}
maxTightRedemptionRate := sdk.ZeroDec()
if maxRedemptionRateStr != "" {
maxTightRedemptionRate, err = sdk.NewDecFromStr(maxRedemptionRateStr)
if err != nil {
return err
}
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgUpdateTightBounds(
clientCtx.GetFromAddress().String(),
argChainId,
minTightRedemptionRate,
maxTightRedemptionRate,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
3 changes: 3 additions & 0 deletions x/stakeibc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func NewMessageHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgUpdateValidatorSharesExchRate:
res, err := msgServer.UpdateValidatorSharesExchRate(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgUpdateTightBounds:
res, err := msgServer.UpdateTightBounds(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
Expand Down
25 changes: 25 additions & 0 deletions x/stakeibc/keeper/msg_server_update_tight_bounds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"context"
"fmt"

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

"github.com/Stride-Labs/stride/v14/x/stakeibc/types"
)

func (k msgServer) UpdateTightBounds(goCtx context.Context, msg *types.MsgUpdateTightBounds) (*types.MsgUpdateTightBoundsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// Confirm host zone exists
_, found := k.GetHostZone(ctx, msg.ChainId)
if !found {
k.Logger(ctx).Error(fmt.Sprintf("Host Zone not found: %s", msg.ChainId))
return nil, types.ErrInvalidHostZone
}

// TODO: set the bounds

return &types.MsgUpdateTightBoundsResponse{}, nil
}
2 changes: 2 additions & 0 deletions x/stakeibc/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&ToggleLSMProposal{}, "stakeibc/ToggleLSMProposal", nil)
cdc.RegisterConcrete(&MsgRestoreInterchainAccount{}, "stakeibc/RestoreInterchainAccount", nil)
cdc.RegisterConcrete(&MsgUpdateValidatorSharesExchRate{}, "stakeibc/UpdateValidatorSharesExchRate", nil)
cdc.RegisterConcrete(&MsgUpdateTightBounds{}, "stakeibc/UpdateTightBounds", nil)
// this line is used by starport scaffolding # 2
}

Expand All @@ -39,6 +40,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgDeleteValidator{},
&MsgRestoreInterchainAccount{},
&MsgUpdateValidatorSharesExchRate{},
&MsgUpdateTightBounds{},
)

registry.RegisterImplementations((*govtypes.Content)(nil),
Expand Down
54 changes: 54 additions & 0 deletions x/stakeibc/types/message_update_tight_bounds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/Stride-Labs/stride/v14/utils"
)

const TypeMsgUpdateTightBounds = "update_tight_bounds"

var _ sdk.Msg = &MsgUpdateTightBounds{}

func NewMsgUpdateTightBounds(creator string, chainId string, minTightRedemptionRate sdk.Dec, maxTightRedemptionRate sdk.Dec) *MsgUpdateTightBounds {
return &MsgUpdateTightBounds{
Creator: creator,
ChainId: chainId,
MinTightRedemptionRate: minTightRedemptionRate,
MaxTightRedemptionRate: maxTightRedemptionRate,
}
}

func (msg *MsgUpdateTightBounds) Route() string {
return RouterKey
}

func (msg *MsgUpdateTightBounds) Type() string {
return TypeMsgUpdateTightBounds
}

func (msg *MsgUpdateTightBounds) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}

func (msg *MsgUpdateTightBounds) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgUpdateTightBounds) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if err := utils.ValidateAdminAddress(msg.Creator); err != nil {
return err
}
return nil
}
Loading

0 comments on commit 6158058

Please sign in to comment.