Skip to content

Commit

Permalink
add safety param to assertBorrowHealth
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Jun 22, 2023
1 parent 39d6f64 commit ec064aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion x/leverage/keeper/borrows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
// unless the remaining collateral is enough to cover all borrows.
// This should be checked in msg_server.go at the end of any transaction which is restricted
// by borrow limits, i.e. Borrow, Decollateralize, Withdraw, MaxWithdraw.
func (k Keeper) assertBorrowerHealth(ctx sdk.Context, borrowerAddr sdk.AccAddress) error {
// MaxUsage sets the maximum percent of a user's borrow limit that can be in use: set to 1
// to allow up to 100% borrow limit, or a lower value (e.g. 0.9) if a transaction should fail
// if a safety margin is desired (e.g. <90% borrow limit).
func (k Keeper) assertBorrowerHealth(ctx sdk.Context, borrowerAddr sdk.AccAddress, maxUsage sdk.Dec) error {

Check failure on line 20 in x/leverage/keeper/borrows.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

unused-parameter: parameter 'maxUsage' seems to be unused, consider removing or renaming it as _ (revive)
borrowed := k.GetBorrowerBorrows(ctx, borrowerAddr)
collateral := k.GetBorrowerCollateral(ctx, borrowerAddr)

Expand Down
12 changes: 6 additions & 6 deletions x/leverage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s msgServer) Withdraw(
// Fail here if supplier ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the borrower's collateral can cover all borrows
if isFromCollateral {
err = s.keeper.assertBorrowerHealth(ctx, supplierAddr)
err = s.keeper.assertBorrowerHealth(ctx, supplierAddr, sdk.OneDec())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func (s msgServer) MaxWithdraw(
// Fail here if supplier ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the borrower's collateral can cover all borrows
if isFromCollateral {
err = s.keeper.assertBorrowerHealth(ctx, supplierAddr)
err = s.keeper.assertBorrowerHealth(ctx, supplierAddr, sdk.OneDec())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (s msgServer) Decollateralize(

// Fail here if borrower ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the borrower's collateral can cover all borrows
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr)
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr, sdk.OneDec())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func (s msgServer) Borrow(

// Fail here if borrower ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the borrower's collateral can cover all borrows
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr)
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr, sdk.OneDec())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -390,7 +390,7 @@ func (s msgServer) MaxBorrow(

// Fail here if borrower ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the borrower's collateral can cover all borrows
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr)
err = s.keeper.assertBorrowerHealth(ctx, borrowerAddr, sdk.OneDec())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func (s msgServer) FastLiquidate(

// Fail here if liquidator ends up over their borrow limit under current or historic prices
// Tolerates missing collateral prices if the rest of the liquidator's collateral can cover all borrows
err = s.keeper.assertBorrowerHealth(ctx, liquidator)
err = s.keeper.assertBorrowerHealth(ctx, liquidator, sdk.MustNewDecFromStr("0.9"))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ec064aa

Please sign in to comment.