Skip to content

Commit

Permalink
fix comments, confirm safety of 1.0 assumed borrow factor for unused …
Browse files Browse the repository at this point in the history
…collateral when under limit
  • Loading branch information
toteki committed Nov 13, 2023
1 parent 2fec4d4 commit 1d894a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion x/leverage/types/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ func (ap *AccountPosition) Limit() sdk.Dec {
// borrow limit logic. Borrow factor considers the maximum possible borrow factor,
// which if we are not specifying a borrow denom, is 1.0.
avgWeight = sdk.OneDec()
// TODO: this is an overestimate, which is dangerous when computing liquidation threshold.
}
borrowFactorLimit := ap.BorrowedValue().Add(unusedCollateralValue.Mul(avgWeight))

Expand Down
5 changes: 3 additions & 2 deletions x/leverage/types/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestBorrowLimit(t *testing.T) {
"F loop",
},
{
// single asset with unused special pair (borrowFactor reducing weight, minimumBorrowFactor active)
// single asset with unused special pair (borrowFactor LT, minimumBorrowFactor active)
sdk.NewDecCoins(
coin.Dec("FFFF", "100"),
),
Expand All @@ -245,7 +245,8 @@ func TestBorrowLimit(t *testing.T) {
),
// 40 A consumes 80 F collateral (weight 0.5 due to MinimumBorrowFactor), leaving 20 F collateral unused.
// Total borrow limit and liquidation thresholds are 40 + 20 * 1.0 since borrow limit assumes unused
// Collateral can be borrowed by the most efficient possible asset. Actual max borrow will be lower.
// collateral can be borrowed by the most efficient possible asset. Actual max borrow will be lower.
// Liquidation threshold is capped by borrow factor here, otherwise it would be $65.
// The F <-> H special pair has no effect
"60.00",
"60.00",
Expand Down

0 comments on commit 1d894a4

Please sign in to comment.