Skip to content

Commit

Permalink
Adding validation in params
Browse files Browse the repository at this point in the history
  • Loading branch information
avkr003 committed Aug 23, 2024
1 parent 69b652f commit c7e82a2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion x/leveragelp/keeper/hooks_amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (k Keeper) CheckAmmPoolUsdcBalance(ctx sdk.Context, ammPool ammtypes.Pool) error {
leveragelpPool, found := k.GetPool(ctx, ammPool.PoolId)
if !found {
return nil
return types.ErrPoolDoesNotExist
}

tvl, err := ammPool.TVL(ctx, k.oracleKeeper)
Expand Down
18 changes: 0 additions & 18 deletions x/leveragelp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,6 @@ func (k Keeper) GetAllWhitelistedAddress(ctx sdk.Context) []sdk.AccAddress {
return list
}

// remove after migration
func (k Keeper) GetAllLegacyWhitelistedAddress(ctx sdk.Context) []string {
var list []string
iterator := k.GetWhitelistAddressIterator(ctx)
defer func(iterator sdk.Iterator) {
err := iterator.Close()
if err != nil {
panic(err)
}
}(iterator)

for ; iterator.Valid(); iterator.Next() {
list = append(list, (string)(iterator.Value()))
}

return list
}

func (k Keeper) GetWhitelistedAddress(ctx sdk.Context, pagination *query.PageRequest) ([]sdk.AccAddress, *query.PageResponse, error) {
var list []sdk.AccAddress
store := ctx.KVStore(k.storeKey)
Expand Down
16 changes: 16 additions & 0 deletions x/leveragelp/keeper/msg_server_remove_pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ func (suite *KeeperTestSuite) TestRemove_Pool() {
prerequisiteFunction: func() {
},
},
{name: "non zero pool leveraged amount",
input: &types.MsgRemovePool{
Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Id: 1,
},
expectErr: true,
expectErrMsg: "pool leverage amount is greater than zero",
prerequisiteFunction: func() {
pool := types.NewPool(1)
pool.LeveragedLpAmount = sdk.OneInt()
suite.app.LeveragelpKeeper.SetPool(suite.ctx, pool)
},
},
{name: "success",
input: &types.MsgRemovePool{
Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Expand All @@ -61,6 +74,9 @@ func (suite *KeeperTestSuite) TestRemove_Pool() {
expectErr: false,
expectErrMsg: "",
prerequisiteFunction: func() {
pool := types.NewPool(1)
pool.LeveragedLpAmount = sdk.ZeroInt()
suite.app.LeveragelpKeeper.SetPool(suite.ctx, pool)
},
},
}
Expand Down
17 changes: 6 additions & 11 deletions x/leveragelp/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func validateLeverageMax(i interface{}) error {
if v.IsNil() {
return fmt.Errorf("leverage max must be not nil")
}
if v.IsNegative() {
return fmt.Errorf("leverage max must be positive: %s", v)
if !v.GT(sdk.OneDec()) {
return fmt.Errorf("leverage max must be greater than 1: %s", v)
}
if v.GT(sdk.NewDec(10)) {
return fmt.Errorf("leverage max too large: %s", v)
Expand Down Expand Up @@ -152,15 +152,6 @@ func validateSafetyFactor(i interface{}) error {
return nil
}

func validateIncrementalInterestPaymentEnabled(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

return nil
}

func validateWhitelistingEnabled(i interface{}) error {
_, ok := i.(bool)
if !ok {
Expand Down Expand Up @@ -192,6 +183,10 @@ func validateNumberOfBlocks(i interface{}) error {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v < 0 {
return fmt.Errorf("number of positions per block must be positive: %s", v)
}

if v > MaxPageLimit {
return fmt.Errorf("number of positions per block should not exceed page limit: %d, number of positions: %d", MaxPageLimit, v)
}
Expand Down

0 comments on commit c7e82a2

Please sign in to comment.