Skip to content

Commit

Permalink
MaxFee cap is 0.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Jan 23, 2024
1 parent 633526e commit cb37d34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
4 changes: 4 additions & 0 deletions x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

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

Check failure on line 4 in x/liquidstakeibc/types/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/persistenceOne/pstake-native) --custom-order (gci)
"strconv"
"time"

Check failure on line 6 in x/liquidstakeibc/types/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 7 in x/liquidstakeibc/types/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/persistenceOne/pstake-native) --custom-order (gci)
Expand Down Expand Up @@ -92,6 +93,9 @@ var (
RedelegationsKey = []byte{0x08}
RedelegationTxKey = []byte{0x09}
)
var (

Check failure on line 96 in x/liquidstakeibc/types/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
MaxFee = sdk.MustNewDecFromStr("0.5")
)

func GetUnbondingStoreKey(chainID string, epochNumber int64) []byte {
return append([]byte(chainID), []byte(strconv.FormatInt(epochNumber, 10))...)
Expand Down
16 changes: 8 additions & 8 deletions x/liquidstakeibc/types/liquidstakeibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ func (rewardParams *RewardParams) Validate() error {
}

func (params *HostChainLSParams) Validate() error {
if params.DepositFee.LT(sdk.ZeroDec()) || params.DepositFee.GT(sdk.OneDec()) {
return fmt.Errorf("host chain lsparams has invalid deposit fee, should be 0<=fee<=1")
if params.DepositFee.LT(sdk.ZeroDec()) || params.DepositFee.GT(MaxFee) {
return fmt.Errorf("host chain lsparams has invalid deposit fee, should be 0<=fee<= %s", MaxFee)
}
if params.RestakeFee.LT(sdk.ZeroDec()) || params.RestakeFee.GT(sdk.OneDec()) {
return fmt.Errorf("host chain lsparams has invalid restake fee, should be 0<=fee<=1\"")
if params.RestakeFee.LT(sdk.ZeroDec()) || params.RestakeFee.GT(MaxFee) {
return fmt.Errorf("host chain lsparams has invalid restake fee, should be 0<=fee<= %s", MaxFee)
}
if params.RedemptionFee.LT(sdk.ZeroDec()) || params.RedemptionFee.GT(sdk.OneDec()) {
return fmt.Errorf("host chain lsparams has invalid redemption fee, should be 0<=fee<=1\"")
if params.RedemptionFee.LT(sdk.ZeroDec()) || params.RedemptionFee.GT(MaxFee) {
return fmt.Errorf("host chain lsparams has invalid redemption fee, should be 0<=fee<= %s", MaxFee)
}
if params.UnstakeFee.LT(sdk.ZeroDec()) || params.UnstakeFee.GT(sdk.OneDec()) {
return fmt.Errorf("host chain lsparams has invalid unstake fee, should be 0<=fee<=1\"")
if params.UnstakeFee.LT(sdk.ZeroDec()) || params.UnstakeFee.GT(MaxFee) {
return fmt.Errorf("host chain lsparams has invalid unstake fee, should be 0<=fee<= %s", MaxFee)
}
if params.RedelegationAcceptableDelta.LT(sdk.ZeroInt()) {
return fmt.Errorf("host chain has invalid redelegation acceptable delta expected >= 0")
Expand Down
18 changes: 12 additions & 6 deletions x/liquidstakeibc/types/liquidstakeibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,31 +318,35 @@ func TestHostChain_Validate(t *testing.T) {
return newfields
},
wantErr: true,
}, {
},
{
name: "invalid too long chain-id",
fields: func() fields {
newfields := validFields()
newfields.ChainId = "chainA-11111111111111111111111111111111111111111111111111111111111111111111111"
return newfields
},
wantErr: true,
}, {
},
{
name: "invalid connection",
fields: func() fields {
newfields := validFields()
newfields.ConnectionId = "c"
return newfields
},
wantErr: true,
}, {
},
{
name: "invalid port",
fields: func() fields {
newfields := validFields()
newfields.PortId = ""
return newfields
},
wantErr: true,
}, {
},
{
name: "invalid channel",
fields: func() fields {
newfields := validFields()
Expand Down Expand Up @@ -378,7 +382,8 @@ func TestHostChain_Validate(t *testing.T) {
return newfields
},
wantErr: true,
}, {
},
{
name: "invalid rewards autocompound param",
fields: func() fields {
newfields := validFields()
Expand Down Expand Up @@ -897,7 +902,8 @@ func TestICAAccount_Validate(t *testing.T) {
ChannelState: 1,
},
wantErr: true,
}, {
},
{
name: "Invalid coin",
fields: fields{
Address: authtypes.NewModuleAddress("test").String(),
Expand Down
32 changes: 16 additions & 16 deletions x/liquidstakeibc/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,34 @@ func (m *MsgRegisterHostChain) ValidateBasic() error {
}

// deposit fee must be positive or zero
if m.DepositFee.LT(sdk.ZeroDec()) || m.DepositFee.GT(sdk.OneDec()) {
if m.DepositFee.LT(sdk.ZeroDec()) || m.DepositFee.GT(MaxFee) {
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"deposit fee quantity must be greater or equal than zero and less than equal one",
"deposit fee quantity must be greater or equal than zero and less than equal %s", MaxFee,
)
}

// restake fee must be positive or zero
if m.RestakeFee.LT(sdk.ZeroDec()) || m.RestakeFee.GT(sdk.OneDec()) {
if m.RestakeFee.LT(sdk.ZeroDec()) || m.RestakeFee.GT(MaxFee) {
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"restake fee quantity must be greater or equal than zero and less than equal one",
"restake fee quantity must be greater or equal than zero and less than equal %s", MaxFee,
)
}

// unstake fee must be positive or zero
if m.UnstakeFee.LT(sdk.ZeroDec()) || m.UnstakeFee.GT(sdk.OneDec()) {
if m.UnstakeFee.LT(sdk.ZeroDec()) || m.UnstakeFee.GT(MaxFee) {
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"unstake fee quantity must be greater or equal than zero and less than equal one",
"unstake fee quantity must be greater or equal than zero and less than equal %s", MaxFee,
)
}

// redemption deposit must be positive or zero
if m.RedemptionFee.LT(sdk.ZeroDec()) || m.RedemptionFee.GT(sdk.OneDec()) {
if m.RedemptionFee.LT(sdk.ZeroDec()) || m.RedemptionFee.GT(MaxFee) {
return errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"redemption fee quantity must be greater or equal than zero and less than equal one",
"redemption fee quantity must be greater or equal than zero and less than equal %s", MaxFee,
)
}

Expand Down Expand Up @@ -253,35 +253,35 @@ func (m *MsgUpdateHostChain) ValidateBasic() error {
return fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}

if fee.LT(sdk.ZeroDec()) || fee.GT(sdk.OneDec()) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid deposit fee value should be 0 <= fee <= 1")
if fee.LT(sdk.ZeroDec()) || fee.GT(MaxFee) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid deposit fee value should be 0 <= fee <= %s", MaxFee)
}
case KeyRestakeFee:
fee, err := sdk.NewDecFromStr(update.Value)
if err != nil {
return fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}

if fee.LT(sdk.ZeroDec()) || fee.GT(sdk.OneDec()) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid restake fee value should be 0 <= fee <= 1")
if fee.LT(sdk.ZeroDec()) || fee.GT(MaxFee) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid restake fee value should be 0 <= fee <= %s", MaxFee)
}
case KeyRedemptionFee:
fee, err := sdk.NewDecFromStr(update.Value)
if err != nil {
return fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}

if fee.LT(sdk.ZeroDec()) || fee.GT(sdk.OneDec()) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid redemption fee value should be 0 <= fee <= 1")
if fee.LT(sdk.ZeroDec()) || fee.GT(MaxFee) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid redemption fee value should be 0 <= fee <= %s", MaxFee)
}
case KeyUnstakeFee:
fee, err := sdk.NewDecFromStr(update.Value)
if err != nil {
return fmt.Errorf("unable to parse string to sdk.Dec: %w", err)
}

if fee.LT(sdk.ZeroDec()) || fee.GT(sdk.OneDec()) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid unstake fee value should be 0 <= fee <= 1")
if fee.LT(sdk.ZeroDec()) || fee.GT(MaxFee) {
return sdkerrors.ErrInvalidRequest.Wrapf("invalid unstake fee value should be 0 <= fee <= %s", MaxFee)
}
case KeyLSMValidatorCap:
validatorCap, err := sdk.NewDecFromStr(update.Value)
Expand Down

0 comments on commit cb37d34

Please sign in to comment.