Skip to content

Commit

Permalink
Max ltv error morpho (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
piekczyk authored Jan 22, 2024
1 parent b27c022 commit 5a2c7fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/dma-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/dma-library",
"version": "0.6.9",
"version": "0.6.10",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { formatCryptoBalance } from '@dma-common/utils/common'
import { AjnaError, MorphoBluePosition } from '@dma-library/types'
import BigNumber from 'bignumber.js'

import { validateLiquidity } from './validateLiquidity'

export function validateBorrowUndercollateralized(
position: MorphoBluePosition,
targetPosition: MorphoBluePosition,
position: MorphoBluePosition,
borrowAmount: BigNumber,
): AjnaError[] {
if (validateLiquidity(position, borrowAmount).length > 0) {
return []
}

if (targetPosition.riskRatio.loanToValue.gt(targetPosition.maxRiskRatio.loanToValue)) {
const maxDebt = position.debtAvailable(
targetPosition?.collateralAmount || position.collateralAmount,
position.debtAmount,
)

return [
{
name: 'borrow-undercollateralized',
data: {
amount: borrowAmount.toString(),
amount: formatCryptoBalance(maxDebt),
},
},
]
Expand Down

0 comments on commit 5a2c7fe

Please sign in to comment.