Skip to content

Commit

Permalink
rebate percentage -> rebate rate
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Mar 19, 2024
1 parent 2a7a31e commit 13c9355
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 171 deletions.
4 changes: 2 additions & 2 deletions proto/stride/stakeibc/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ message MsgSetCommunityPoolRebate {
// Chain id of the chain whose community pool has a liquid staking rebate
// arrangement with stride
string chain_id = 2;
// Rebate percentage (e.g. 0.2 for 20%)
string rebate_percentage = 3 [
// Rebate percentage represented as a decimal (e.g. 0.2 for 20%)
string rebate_rate = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down
7 changes: 4 additions & 3 deletions x/stakeibc/client/cli/tx_set_community_pool_rebate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (

func CmdSetCommunityPoolRebate() *cobra.Command {
cmd := &cobra.Command{
Use: "set-rebate [chain-id] [rebate-percentage] [liquid-staked-amount]",
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.
and the amount liquid staked.
E.g. to specify a 20% rebate, the rebate rate should be 0.2
If a 0% rebate or 0 token liquid stake is specified, the rebate will be deleted.
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) {
Expand Down
4 changes: 2 additions & 2 deletions x/stakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,12 +1118,12 @@ func (k msgServer) SetCommunityPoolRebate(

// If a zero rebate is specified, set the rebate to nil
// Otherwise, update the struct
if msg.LiquidStakedAmount.IsZero() || msg.RebatePercentage.IsZero() {
if msg.LiquidStakedAmount.IsZero() || msg.RebateRate.IsZero() {
hostZone.CommunityPoolRebate = nil
} else {
hostZone.CommunityPoolRebate = &types.CommunityPoolRebate{
LiquidStakeAmount: msg.LiquidStakedAmount,
RebatePercentage: msg.RebatePercentage,
RebatePercentage: msg.RebateRate,
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ func (s *KeeperTestSuite) TestSetCommunityPoolRebate() {
// Submit a message to create the rebate
msg := types.MsgSetCommunityPoolRebate{
ChainId: HostChainId,
RebatePercentage: rebateInfo.RebatePercentage,
RebateRate: rebateInfo.RebatePercentage,
LiquidStakedAmount: rebateInfo.LiquidStakeAmount,
}
_, err := s.GetMsgServer().SetCommunityPoolRebate(s.Ctx, &msg)
Expand Down
8 changes: 4 additions & 4 deletions x/stakeibc/types/message_set_community_pool_rebate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ var _ sdk.Msg = &MsgSetCommunityPoolRebate{}
func NewMsgSetCommunityPoolRebate(
creator string,
chainId string,
rebatePercentage sdk.Dec,
rebateRate sdk.Dec,
liquidStakedAmount sdkmath.Int,
) *MsgSetCommunityPoolRebate {
return &MsgSetCommunityPoolRebate{
Creator: creator,
ChainId: chainId,
RebatePercentage: rebatePercentage,
RebateRate: rebateRate,
LiquidStakedAmount: liquidStakedAmount,
}
}
Expand Down Expand Up @@ -62,8 +62,8 @@ func (msg *MsgSetCommunityPoolRebate) ValidateBasic() error {
if msg.ChainId == "" {
return errors.New("chain ID must be specified")
}
if msg.RebatePercentage.IsNil() || msg.RebatePercentage.LT(sdk.ZeroDec()) || msg.RebatePercentage.GT(sdk.OneDec()) {
return errors.New("invalid rebate percentage, must be between 0 and 1 (inclusive)")
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")
Expand Down
28 changes: 14 additions & 14 deletions x/stakeibc/types/message_set_community_pool_rebate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
require.True(t, ok)

validChainId := "chain-0"
validRebatePercentage := sdk.MustNewDecFromStr("0.1")
validRebateRate := sdk.MustNewDecFromStr("0.1")
validLiquidStakedAmount := sdk.NewInt(1000)

tests := []struct {
Expand All @@ -33,7 +33,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: validLiquidStakedAmount,
},
},
Expand All @@ -42,7 +42,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: invalidAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: validLiquidStakedAmount,
},
err: "invalid creator address",
Expand All @@ -52,7 +52,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validNotAdminAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: validLiquidStakedAmount,
},
err: "not an admin",
Expand All @@ -62,7 +62,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: "",
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: validLiquidStakedAmount,
},
err: "chain ID must be specified",
Expand All @@ -81,7 +81,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: sdk.MustNewDecFromStr("0.5").Neg(),
RebateRate: sdk.MustNewDecFromStr("0.5").Neg(),
LiquidStakedAmount: validLiquidStakedAmount,
},
err: "rebate percentage, must be between 0 and 1 (inclusive)",
Expand All @@ -91,7 +91,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: sdk.OneDec(),
RebateRate: sdk.OneDec(),
LiquidStakedAmount: validLiquidStakedAmount,
},
},
Expand All @@ -100,7 +100,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: sdk.MustNewDecFromStr("1.1"),
RebateRate: sdk.MustNewDecFromStr("1.1"),
LiquidStakedAmount: validLiquidStakedAmount,
},
err: "rebate percentage, must be between 0 and 1 (inclusive)",
Expand All @@ -110,16 +110,16 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: sdk.ZeroDec(),
RebateRate: sdk.ZeroDec(),
LiquidStakedAmount: validLiquidStakedAmount,
},
},
{
name: "invalid liquid stake amount - nil",
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
Creator: validAdminAddress,
ChainId: validChainId,
RebateRate: validRebateRate,
},
err: "invalid liquid stake amount, must be greater than or equal to 0",
},
Expand All @@ -128,7 +128,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: sdkmath.NewInt(1).Neg(),
},
err: "invalid liquid stake amount, must be greater than or equal to 0",
Expand All @@ -138,7 +138,7 @@ func TestMsgSetCommunityPoolRebate(t *testing.T) {
msg: types.MsgSetCommunityPoolRebate{
Creator: validAdminAddress,
ChainId: validChainId,
RebatePercentage: validRebatePercentage,
RebateRate: validRebateRate,
LiquidStakedAmount: sdkmath.ZeroInt(),
},
},
Expand Down
Loading

0 comments on commit 13c9355

Please sign in to comment.