From cb37d34273238545e9d96d77a4fb55696ebbc135 Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Tue, 23 Jan 2024 16:50:28 +0530 Subject: [PATCH] MaxFee cap is 0.5. --- x/liquidstakeibc/types/keys.go | 4 +++ x/liquidstakeibc/types/liquidstakeibc.go | 16 +++++----- x/liquidstakeibc/types/liquidstakeibc_test.go | 18 +++++++---- x/liquidstakeibc/types/msgs.go | 32 +++++++++---------- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/x/liquidstakeibc/types/keys.go b/x/liquidstakeibc/types/keys.go index 451640dba..2162f5ae7 100644 --- a/x/liquidstakeibc/types/keys.go +++ b/x/liquidstakeibc/types/keys.go @@ -1,6 +1,7 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" "strconv" "time" @@ -92,6 +93,9 @@ var ( RedelegationsKey = []byte{0x08} RedelegationTxKey = []byte{0x09} ) +var ( + MaxFee = sdk.MustNewDecFromStr("0.5") +) func GetUnbondingStoreKey(chainID string, epochNumber int64) []byte { return append([]byte(chainID), []byte(strconv.FormatInt(epochNumber, 10))...) diff --git a/x/liquidstakeibc/types/liquidstakeibc.go b/x/liquidstakeibc/types/liquidstakeibc.go index 7f99fa394..21cdbb409 100644 --- a/x/liquidstakeibc/types/liquidstakeibc.go +++ b/x/liquidstakeibc/types/liquidstakeibc.go @@ -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") diff --git a/x/liquidstakeibc/types/liquidstakeibc_test.go b/x/liquidstakeibc/types/liquidstakeibc_test.go index fbfa36bc2..c24be445e 100644 --- a/x/liquidstakeibc/types/liquidstakeibc_test.go +++ b/x/liquidstakeibc/types/liquidstakeibc_test.go @@ -318,7 +318,8 @@ func TestHostChain_Validate(t *testing.T) { return newfields }, wantErr: true, - }, { + }, + { name: "invalid too long chain-id", fields: func() fields { newfields := validFields() @@ -326,7 +327,8 @@ func TestHostChain_Validate(t *testing.T) { return newfields }, wantErr: true, - }, { + }, + { name: "invalid connection", fields: func() fields { newfields := validFields() @@ -334,7 +336,8 @@ func TestHostChain_Validate(t *testing.T) { return newfields }, wantErr: true, - }, { + }, + { name: "invalid port", fields: func() fields { newfields := validFields() @@ -342,7 +345,8 @@ func TestHostChain_Validate(t *testing.T) { return newfields }, wantErr: true, - }, { + }, + { name: "invalid channel", fields: func() fields { newfields := validFields() @@ -378,7 +382,8 @@ func TestHostChain_Validate(t *testing.T) { return newfields }, wantErr: true, - }, { + }, + { name: "invalid rewards autocompound param", fields: func() fields { newfields := validFields() @@ -897,7 +902,8 @@ func TestICAAccount_Validate(t *testing.T) { ChannelState: 1, }, wantErr: true, - }, { + }, + { name: "Invalid coin", fields: fields{ Address: authtypes.NewModuleAddress("test").String(), diff --git a/x/liquidstakeibc/types/msgs.go b/x/liquidstakeibc/types/msgs.go index 3c9783044..188ed1fb6 100644 --- a/x/liquidstakeibc/types/msgs.go +++ b/x/liquidstakeibc/types/msgs.go @@ -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, ) } @@ -253,8 +253,8 @@ 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) @@ -262,8 +262,8 @@ 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 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) @@ -271,8 +271,8 @@ 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 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) @@ -280,8 +280,8 @@ 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 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)