-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
747 additions
and
109 deletions.
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
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,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 | ||
} |
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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.