From 1d894a4586ba0a8386cb01efff8cac72e3fb9554 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Sun, 12 Nov 2023 21:10:03 -0700 Subject: [PATCH] fix comments, confirm safety of 1.0 assumed borrow factor for unused collateral when under limit --- x/leverage/types/position.go | 1 - x/leverage/types/position_test.go | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/leverage/types/position.go b/x/leverage/types/position.go index 6f10f0933a..771b85ec12 100644 --- a/x/leverage/types/position.go +++ b/x/leverage/types/position.go @@ -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)) diff --git a/x/leverage/types/position_test.go b/x/leverage/types/position_test.go index f7a9b6c2a1..a44992e1e4 100644 --- a/x/leverage/types/position_test.go +++ b/x/leverage/types/position_test.go @@ -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"), ), @@ -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",