@@ -51,6 +51,7 @@ import { EmodeActions } from './EmodeActions';
5151export enum ErrorType {
5252 EMODE_DISABLED_LIQUIDATION ,
5353 CLOSE_POSITIONS_BEFORE_SWITCHING ,
54+ ZERO_LTV_COLLATERAL_BLOCKING ,
5455}
5556
5657export 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" >
0 commit comments