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 inner bounds #938

Merged
merged 14 commits into from
Sep 18, 2023
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
}
}
sampocs marked this conversation as resolved.
Show resolved Hide resolved

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