@@ -222,7 +222,7 @@ export const calculateHFAfterRepay = ({
222222 fromAssetData . priceInUSD
223223 ) ,
224224 borrowBalanceMarketReferenceCurrency : debtLeftInMarketReference . toString ( 10 ) ,
225- currentLiquidationThreshold : fromAssetData . formattedReserveLiquidationThreshold ,
225+ currentLiquidationThreshold : reserveLiquidationThreshold ,
226226 } ) . toString ( )
227227 : '0' ;
228228
@@ -292,14 +292,33 @@ export const calculateHFAfterSupply = (
292292) => {
293293 let healthFactorAfterDeposit = user ? valueToBigNumber ( user . healthFactor ) : '-1' ;
294294
295+ const userEmode = user
296+ ? poolReserve . eModes . find ( ( e ) => e . id === user . userEmodeCategoryId )
297+ : undefined ;
298+
299+ // Mirrors validateUseAsCollateral on-chain: asset is only auto-enabled as collateral
300+ // when effective LTV > 0. Base LTV covers the non-emode path; emode collateral without
301+ // ltvzero covers the boosted path (ltvzero assets have 0 LTV and won't be enabled).
302+ const hasEffectiveLtv =
303+ poolReserve . baseLTVasCollateral !== '0' ||
304+ ( user ?. isInEmode && userEmode ?. collateralEnabled && ! userEmode . ltvzeroEnabled ) ;
305+
306+ const additionalCollateral = hasEffectiveLtv ? supplyAmountInEth : valueToBigNumber ( 0 ) ;
307+
308+ // Use emode-boosted LT when user is in emode and asset is in that category's collateral bitmap.
309+ const reserveLiquidationThreshold =
310+ user ?. isInEmode && userEmode ?. collateralEnabled
311+ ? userEmode . eMode . formattedLiquidationThreshold
312+ : poolReserve . formattedReserveLiquidationThreshold ;
313+
295314 const totalCollateralMarketReferenceCurrencyAfter = user
296- ? valueToBigNumber ( user . totalCollateralMarketReferenceCurrency ) . plus ( supplyAmountInEth )
315+ ? valueToBigNumber ( user . totalCollateralMarketReferenceCurrency ) . plus ( additionalCollateral )
297316 : '-1' ;
298317
299318 const liquidationThresholdAfter = user
300319 ? valueToBigNumber ( user . totalCollateralMarketReferenceCurrency )
301320 . multipliedBy ( user . currentLiquidationThreshold )
302- . plus ( supplyAmountInEth . multipliedBy ( poolReserve . formattedReserveLiquidationThreshold ) )
321+ . plus ( additionalCollateral . multipliedBy ( reserveLiquidationThreshold ) )
303322 . dividedBy ( totalCollateralMarketReferenceCurrencyAfter )
304323 : '-1' ;
305324
0 commit comments