-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOV-3390: reimplement increasing debt without adding collateral (#703)
* feat: allow borrowing more money * fix: review comments * chore: add changeset --------- Co-authored-by: soulBit <[email protected]>
- Loading branch information
1 parent
f9c3795
commit cb660fb
Showing
9 changed files
with
182 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"frontend": patch | ||
--- | ||
|
||
SOV-3390: Fixed Rate Borrow - add ability to increase debt without adding collateral |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/frontend/src/app/5_pages/BorrowPage/components/AdjustLoanForm/AdjustLoanForm.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export enum DebtTabAction { | ||
None = -1, | ||
Borrow, | ||
Repay, | ||
Close, | ||
Borrow, | ||
} | ||
|
||
export enum CollateralTabAction { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/frontend/src/app/5_pages/BorrowPage/components/AdjustLoanForm/hooks/useDrawdown.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { Decimal } from '@sovryn/utils'; | ||
|
||
import { decimalic } from '../../../../../../utils/math'; | ||
import { LoanItem } from '../../OpenLoansTable/OpenLoansTable.types'; | ||
import { getBorrowAmount, getMaxDrawdown } from '../AdjustLoanForm.utils'; | ||
|
||
export const useDrawdown = ( | ||
loan: LoanItem, | ||
collateralSize: Decimal, | ||
isAddCollateralTab: boolean, | ||
) => { | ||
const [drawDown, setDrawDown] = useState(Decimal.ZERO); | ||
const [maxBorrow, setMaxBorrow] = useState(Decimal.ZERO); | ||
|
||
useEffect(() => { | ||
getMaxDrawdown( | ||
loan.debtAsset, | ||
loan.collateralAsset, | ||
decimalic(loan.debt), | ||
decimalic(loan.collateral), | ||
loan.startMargin, | ||
).then(setDrawDown); | ||
}, [ | ||
loan.collateral, | ||
loan.collateralAsset, | ||
loan.debt, | ||
loan.debtAsset, | ||
loan.startMargin, | ||
]); | ||
|
||
useEffect(() => { | ||
getBorrowAmount( | ||
loan.debtAsset, | ||
drawDown.add(collateralSize.mul(isAddCollateralTab ? 1 : -1)), | ||
loan.collateralAsset, | ||
Math.max(Math.floor(loan.rolloverDate - Date.now() / 1000), 0), | ||
// 28 * 86400, | ||
).then(setMaxBorrow); | ||
}, [ | ||
collateralSize, | ||
drawDown, | ||
isAddCollateralTab, | ||
loan.collateralAsset, | ||
loan.debtAsset, | ||
loan.rolloverDate, | ||
]); | ||
|
||
return { drawDown, maxBorrow }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters