Skip to content

Commit

Permalink
feat: fixed available debt in isolated reserve in case that debt > ma… (
Browse files Browse the repository at this point in the history
#532)

* feat: fixed available debt in isolated reserve in case that debt > max debt

* feat: add isolation mode ceiling exceeded test

* chore: remove comment

---------

Co-authored-by: aschmidt20 <andrew@aave.com>
  • Loading branch information
JoaquinBattilana and defispartan authored Apr 24, 2023
1 parent 54cd8d5 commit 7a2ea1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ describe('generateRawUserSummary', () => {
expect(rawSummary.healthFactor.toFixed()).toEqual('1.2');
});

it('should not allow negative available borrows if debtCeiling is exceeded ', () => {
const rawETHSummaryDebtCeilingExceeded: UserReserveSummaryResponse =
generateUserReserveSummary({
userReserve: {
...ethUserMock.userReserve,
reserve: {
...ethUserMock.reserve,
debtCeiling: '100',
isolationModeTotalDebt: '101',
},
},
marketReferencePriceInUsdNormalized,
marketReferenceCurrencyDecimals: 18,
currentTimestamp,
});

const rawSummaryDebtCeilingExceeded: RawUserSummaryResponse =
generateRawUserSummary({
userReserves: [rawETHSummaryDebtCeilingExceeded],
marketReferencePriceInUsd,
marketReferenceCurrencyDecimals,
userEmodeCategoryId: 0,
});

expect(
normalize(
rawSummaryDebtCeilingExceeded.availableBorrowsMarketReferenceCurrency,
marketReferenceCurrencyDecimals,
),
).toEqual('0');
});

it('should generate the correct user summary for user in stablecoin eMode', () => {
expect(
normalize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ export function generateRawUserSummary({
const availableBorrowsMarketReferenceCurrency =
isInIsolationMode && isolatedReserve
? BigNumber.min(
normalizeBN(
new BigNumber(isolatedReserve.debtCeiling).minus(
isolatedReserve.isolationModeTotalDebt,
BigNumber.max(
0,
normalizeBN(
new BigNumber(isolatedReserve.debtCeiling).minus(
isolatedReserve.isolationModeTotalDebt,
),
isolatedReserve.debtCeilingDecimals -
marketReferenceCurrencyDecimals,
),
isolatedReserve.debtCeilingDecimals -
marketReferenceCurrencyDecimals,
),
_availableBorrowsMarketReferenceCurrency,
)
Expand Down

0 comments on commit 7a2ea1e

Please sign in to comment.