Skip to content

Commit

Permalink
chore: MaxFee cap is 0.5. (#739)
Browse files Browse the repository at this point in the history
* MaxFee cap is 0.5.

* lint, fumpt
  • Loading branch information
puneet2019 authored Jan 23, 2024
1 parent 8ff0b1b commit 074739e
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 70 deletions.
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,42 +1027,42 @@ func (app *PstakeApp) RegisterUpgradeHandler() {
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

case "osmosis-1":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.97")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

case "theta-testnet-001":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.9")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

case "osmo-test-5":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

case "dydx-test-4":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

case "gaia-1":
upperLimit, _ := sdk.NewDecFromStr("1.01")
lowerLimit, _ := sdk.NewDecFromStr("0.95")
hc.Params.UpperCValueLimit = upperLimit
hc.Params.LowerCValueLimit = lowerLimit
app.LiquidStakeIBCKeeper.SetHostChain(ctx, hc)

}
}

Expand Down
16 changes: 8 additions & 8 deletions x/liquidstakeibc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func TestGenesis(t *testing.T) {
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
RedelegationAcceptableDelta: sdk.ZeroInt(),
MaxEntries: 7,
},
Expand Down
16 changes: 8 additions & 8 deletions x/liquidstakeibc/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ func ValidGenesis() *types.GenesisState {
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
UpperCValueLimit: upperCValueLimit,
LowerCValueLimit: lowerCValueLimit,
RedelegationAcceptableDelta: sdk.OneInt(),
},
HostDenom: "uatom",
Expand Down
3 changes: 3 additions & 0 deletions x/liquidstakeibc/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)

Expand Down Expand Up @@ -93,6 +94,8 @@ var (
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))...)
}
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 @@ -132,34 +132,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 @@ -265,35 +265,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
54 changes: 36 additions & 18 deletions x/liquidstakeibc/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,62 +207,80 @@ func TestMsgUpdateHostChain(t *testing.T) {
{
Key: types.KeySetWithdrawAddress,
Value: "",
}, {
},
{
Key: types.KeyAddValidator,
Value: "{\"operator_address\":\"cosmosvaloper1hcqg5wj9t42zawqkqucs7la85ffyv08le09ljt\",\"status\":\"BOND_STATUS_UNSPECIFIED\",\"weight\":\"0\",\"delegated_amount\":\"0\",\"exchange_rate\":\"1\"}",
}, {
},
{
Key: types.KeyRemoveValidator,
Value: "cosmosvaloper1hcqg5wj9t42zawqkqucs7la85ffyv08le09ljt",
}, {
},
{
Key: types.KeyValidatorUpdate,
Value: "cosmosvaloper1hcqg5wj9t42zawqkqucs7la85ffyv08le09ljt",
}, {
},
{
Key: types.KeyValidatorWeight,
Value: "cosmosvaloper1hcqg5wj9t42zawqkqucs7la85ffyv08le09ljt,1",
}, {
},
{
Key: types.KeyRedemptionFee,
Value: "0",
}, {
},
{
Key: types.KeyDepositFee,
Value: "0",
}, {
},
{
Key: types.KeyRestakeFee,
Value: "0",
}, {
},
{
Key: types.KeyUnstakeFee,
Value: "0",
},
{
Key: types.KeyUpperCValueLimit,
Value: "1.1",
}, {
},
{
Key: types.KeyLowerCValueLimit,
Value: "0.9",
}, {
},
{
Key: types.KeyMinimumDeposit,
Value: "1",
}, {
},
{
Key: types.KeyLSMValidatorCap,
Value: "0",
}, {
},
{
Key: types.KeyLSMValidatorCap,
Value: "1",
}, {
},
{
Key: types.KeyLSMValidatorCap,
Value: "0.5",
}, {
},
{
Key: types.KeyLSMBondFactor,
Value: "-1",
}, {
},
{
Key: types.KeyLSMBondFactor,
Value: "250",
}, {
},
{
Key: types.KeyLSMBondFactor,
Value: "0",
}, {
},
{
Key: types.KeyActive,
Value: "true",
}, {
},
{
Key: types.KeyAutocompoundFactor,
Value: "2",
},
Expand Down

0 comments on commit 074739e

Please sign in to comment.