-
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
10 changed files
with
1,015 additions
and
134 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,61 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"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/v19/x/stakeibc/types" | ||
) | ||
|
||
func CmdSetCommunityPoolRebate() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set-rebate [chain-id] [rebate-rate] [liquid-staked-amount]", | ||
Short: "Registers or updates a community pool rebate", | ||
Long: strings.TrimSpace(`Registers a community pool rebate by specifying the rebate percentage (as a decimal) | ||
and the amount liquid staked. | ||
E.g. to specify a 20% rebate, the rebate rate should be 0.2 | ||
If a 0.0 rebate or 0 token liquid stake is specified, the rebate will be deleted. | ||
`), | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
chainId := args[0] | ||
rebatePercentage, err := sdk.NewDecFromStr(args[1]) | ||
if err != nil { | ||
return fmt.Errorf("unable to parse rebate percentage: %s", err.Error()) | ||
} | ||
liquidStakeAmount, ok := sdkmath.NewIntFromString(args[2]) | ||
if !ok { | ||
return errors.New("unable to parse liquid stake amount") | ||
} | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgSetCommunityPoolRebate( | ||
clientCtx.GetFromAddress().String(), | ||
chainId, | ||
rebatePercentage, | ||
liquidStakeAmount, | ||
) | ||
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
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,73 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdkmath "cosmossdk.io/math" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/Stride-Labs/stride/v19/utils" | ||
) | ||
|
||
const TypeMsgSetCommunityPoolRebate = "register_community_pool_rebate" | ||
|
||
var _ sdk.Msg = &MsgSetCommunityPoolRebate{} | ||
|
||
func NewMsgSetCommunityPoolRebate( | ||
creator string, | ||
chainId string, | ||
rebateRate sdk.Dec, | ||
liquidStakedAmount sdkmath.Int, | ||
) *MsgSetCommunityPoolRebate { | ||
return &MsgSetCommunityPoolRebate{ | ||
Creator: creator, | ||
ChainId: chainId, | ||
RebateRate: rebateRate, | ||
LiquidStakedAmount: liquidStakedAmount, | ||
} | ||
} | ||
|
||
func (msg *MsgSetCommunityPoolRebate) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgSetCommunityPoolRebate) Type() string { | ||
return TypeMsgSetCommunityPoolRebate | ||
} | ||
|
||
func (msg *MsgSetCommunityPoolRebate) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgSetCommunityPoolRebate) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgSetCommunityPoolRebate) 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 | ||
} | ||
if msg.ChainId == "" { | ||
return errors.New("chain ID must be specified") | ||
} | ||
if msg.RebateRate.IsNil() || msg.RebateRate.LT(sdk.ZeroDec()) || msg.RebateRate.GT(sdk.OneDec()) { | ||
return errors.New("invalid rebate rate, must be a decimal between 0 and 1 (inclusive)") | ||
} | ||
if msg.LiquidStakedAmount.IsNil() || msg.LiquidStakedAmount.LT(sdkmath.ZeroInt()) { | ||
return errors.New("invalid liquid stake amount, must be greater than or equal to zero") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.