Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixed available debt in isolated reserve in case that debt > ma… #532

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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