Skip to content

Commit 0369447

Browse files
committed
fix: block e-mode exit when LTV=0 collateral assets have outstanding borrows
1 parent d6c4858 commit 0369447

6 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/components/transactions/Emode/EmodeModalContent.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { EmodeActions } from './EmodeActions';
5151
export enum ErrorType {
5252
EMODE_DISABLED_LIQUIDATION,
5353
CLOSE_POSITIONS_BEFORE_SWITCHING,
54+
ZERO_LTV_COLLATERAL_BLOCKING,
5455
}
5556

5657
export type EModeCategoryDisplay = EmodeCategory & {
@@ -138,17 +139,48 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
138139
marketReferencePriceInUsd,
139140
});
140141

142+
// Check for collateral assets with LTV=0 outside of e-mode that would block exit
143+
const zeroLtvCollateralSymbols = user.userReservesData
144+
.filter(
145+
(userReserve) =>
146+
Number(userReserve.scaledATokenBalance) > 0 &&
147+
userReserve.reserve.baseLTVasCollateral === '0' &&
148+
userReserve.usageAsCollateralEnabledOnUser &&
149+
userReserve.reserve.reserveLiquidationThreshold !== '0'
150+
)
151+
.map((r) => r.reserve.symbol);
152+
153+
const hasBorrows = Number(user.totalBorrowsUSD) > 0;
154+
141155
// error handling
142156
let blockingError: ErrorType | undefined = undefined;
143157
// if user is disabling eMode
144158
if (user.isInEmode && disableEmode) {
145-
if (Number(newSummary.healthFactor) < 1.01 && newSummary.healthFactor !== '-1') {
146-
blockingError = ErrorType.EMODE_DISABLED_LIQUIDATION; // intl.formatMessage(messages.eModeDisabledLiquidation);
159+
if (hasBorrows && zeroLtvCollateralSymbols.length > 0) {
160+
blockingError = ErrorType.ZERO_LTV_COLLATERAL_BLOCKING;
161+
} else if (Number(newSummary.healthFactor) < 1.01 && newSummary.healthFactor !== '-1') {
162+
blockingError = ErrorType.EMODE_DISABLED_LIQUIDATION;
147163
}
148164
}
149165

150166
const Blocked: React.FC = () => {
151167
switch (blockingError) {
168+
case ErrorType.ZERO_LTV_COLLATERAL_BLOCKING:
169+
return (
170+
<Warning severity="info" sx={{ mt: 6, alignItems: 'center' }}>
171+
<Typography variant="subheader1">
172+
<Trans>Cannot disable E-Mode</Trans>
173+
</Typography>
174+
<Typography variant="caption">
175+
<Trans>
176+
You must repay your borrow positions before exiting E-Mode.{' '}
177+
{zeroLtvCollateralSymbols.join(', ')}{' '}
178+
{zeroLtvCollateralSymbols.length === 1 ? 'has' : 'have'} 0 LTV outside of E-Mode and
179+
cannot remain as collateral.
180+
</Trans>
181+
</Typography>
182+
</Warning>
183+
);
152184
case ErrorType.EMODE_DISABLED_LIQUIDATION:
153185
return (
154186
<Warning severity="error" sx={{ mt: 6, alignItems: 'center' }}>
@@ -233,7 +265,7 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
233265
</Trans>
234266
</Typography>
235267

236-
{blockingError === ErrorType.EMODE_DISABLED_LIQUIDATION && <Blocked />}
268+
{blockingError !== undefined && <Blocked />}
237269
{showLiquidationRiskWarning && (
238270
<Warning severity="error" sx={{ mt: 6, alignItems: 'center' }}>
239271
<Typography variant="subheader1" color="#4F1919">

src/locales/el/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,7 @@ msgstr "supply"
24482448
msgid "Supply"
24492449
msgstr "Supply"
24502450

2451+
#: src/components/transactions/Emode/EmodeModalContent.tsx
24512452
#: src/components/transactions/Emode/EmodeModalContent.tsx
24522453
msgid "Cannot disable E-Mode"
24532454
msgstr "Cannot disable E-Mode"
@@ -3638,6 +3639,10 @@ msgstr "Exchange rate"
36383639
msgid "You unstake here"
36393640
msgstr "You unstake here"
36403641

3642+
#: src/components/transactions/Emode/EmodeModalContent.tsx
3643+
msgid "You must repay your borrow positions before exiting E-Mode. {0} {1} 0 LTV outside of E-Mode and cannot remain as collateral."
3644+
msgstr "You must repay your borrow positions before exiting E-Mode. {0} {1} 0 LTV outside of E-Mode and cannot remain as collateral."
3645+
36413646
#: src/components/caps/CapsHint.tsx
36423647
#: src/modules/dashboard/lists/BorrowAssetsList/BorrowAssetsListMobileItem.tsx
36433648
#: src/modules/reserve-overview/ReserveActions.tsx

src/locales/es/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/fr/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)