Skip to content

fix: align supply and collateral swap HF with on-chain collateral rules - #3194

Open
grothem wants to merge 7 commits into
samm/zero-ltv-collateral-actionsfrom
fix/hf-supply-existing-collateral
Open

grothem wants to merge 7 commits into
samm/zero-ltv-collateral-actionsfrom
fix/hf-supply-existing-collateral

Conversation

@grothem

@grothem grothem commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3189. Review that first; this PR's diff is only the changes on top of it.

Summary

The health factor "after" numbers in the Supply modal and the collateral swap modal didn't follow the Pool's collateral rules. The reported case: supplying more of a 0 LTV asset that's already enabled as collateral showed the HF staying the same, when on-chain it goes up.

The rule the interface now follows everywhere: the Pool only decides the collateral flag when a position is first created. An existing position keeps its flag. A newly received asset is auto-enabled only if it's supplied and eligible (effective LTV > 0). An aToken transfer never auto-enables collateral for the receiver (v3.4+).

Supply modal

  • Existing position: keeps its current collateral flag. An enabled 0 LTV asset now counts toward HF through its liquidation threshold, and a position the user disabled stays out.
  • E-mode switch path (setUserEMode + supply in one multicall): now uses the same rules, evaluated under the target e-mode, since setUserEMode runs first. Previously it ignored LTV and the user's existing flag.
  • Liquidation threshold: the e-mode threshold is used only when the asset is collateral in that category. A borrow-only entry now keeps the reserve's own threshold.

Shared helpers: supplyCountsAsCollateral and getReserveLiquidationThresholdInEmode in hfUtils.ts.

Collateral swap (CoW and ParaSwap)

How the bought asset arrives depends on the flow, and both providers behave the same way:

Bought asset No flash loan (aToken transfer) Flash-loan adapter (supply)
Held, collateral on counts counts
Held, collateral off doesn't count doesn't count
Not held, effective LTV > 0 doesn't count (#3189 counted it) counts
Not held, effective LTV = 0 doesn't count doesn't count
  • No flash loan: a plain aToken -> aToken swap. On CoW it's the settlement contract that delivers the aTokens. On ParaSwap it's an Augustus route (SwapActionsViaParaswap), where Augustus or its executor is the Pool.supply recipient and then transfers the aTokens to the user. Either way the user receives them by transfer.
  • Flash loan: the adapter supplies the bought asset on the user's behalf (CoW CollateralSwapAaveV3Adapter -> Pool.supply, ParaSwap ParaSwapLiquiditySwapAdapter -> Pool.deposit via flashLoanSimple), then pulls the sold aTokens.
  • calculateHFAfterSwap takes a new toAssetReceivedVia: 'supply' | 'transfer' (default 'supply'). getCollateralSwapReceivedVia(useFlashloan) returns 'transfer' whenever no flash loan is used.
  • useFlowSelector now picks the flow (simple order or flash loan) first, then computes the HF for that flow, so the IS_LIQUIDATABLE block matches what will run. Picking the flow only uses the withdraw side, so there's no loop.
  • In the flash-loan cases where the bought asset doesn't count, the adapter's transferFrom of the sold aTokens runs validateHFAndLtvzero. It reverts only if HF drops below 1 (or the ltvzero rule fires), and the existing IS_LIQUIDATABLE check catches that.
  • Swap from/to liquidation thresholds use the same e-mode rule as supply.

Isolation mode removed from HF

Legacy isolation mode (debt ceilings) is gone in v3.7 and every pool is upgraded, so the isolation checks in calculateHFAfterSupply and calculateHFAfterSwap are removed. Isolated e-mode (v3.7) handling stays.

Testing

  • Unit tests in src/utils/__tests__/hfUtils.test.ts: supply cases, e-mode switch helpers, and the 4 × 2 swap table above. The new swap tests fail on fix: align zero-LTV collateral guards and swap HF with on-chain rules #3189 without this change.
  • tsc is clean and Prettier passes. ESLint shows one existing react-hooks/exhaustive-deps warning in useFlowSelector.ts, on a line this PR doesn't change.
  • Not yet checked on a fork or in the UI.

Not covered

  • The "Collateralization" label in the collateral swap details can still say a newly bought asset will be enabled on a swap without a flash loan (either provider).
  • Product question (separate from this PR): before Collateral Swaps using CoW when available #2581, a ParaSwap collateral swap without a flash loan used the adapter's swapAndDeposit, which supplies, so a newly bought asset with LTV > 0 became collateral. Since Collateral Swaps using CoW when available #2581 it's an Augustus aToken swap, so it arrives disabled, while the flash-loan path still enables it. This PR makes the preview match today's behavior. Bringing back swapAndDeposit would be a product decision.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
interface Ready Ready Preview Nov 19, 2026 4:51pm UTC

Request Review

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

1 similar comment
@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

grothem and others added 5 commits November 19, 2026 10:10
A CoW simple order delivers the bought aTokens by transfer, which never
auto-enables collateral (v3.4+), so a newly bought asset doesn't count.
The flash-loan adapter supplies on the user's behalf, so first-supply
auto-enable applies. An existing position keeps its collateral flag in
both flows. The flow selector now picks the flow before computing HF.

Also use the e-mode liquidation threshold for swap assets only when the
asset is collateral in that category.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@grothem
grothem force-pushed the fix/hf-supply-existing-collateral branch from 557d66a to a650d1e Compare November 19, 2026 16:12
@grothem
grothem changed the base branch from main to samm/zero-ltv-collateral-actions November 19, 2026 16:12
@grothem grothem changed the title fix: count existing 0 LTV collateral in HF after supply fix: align supply and collateral swap HF with on-chain collateral rules Nov 19, 2026
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Without a flash loan, ParaSwap collateral swaps run as aToken -> aToken
Augustus routes (since #2581), not through the adapter's swapAndDeposit.
Augustus or its executor receives the bought aTokens and transfers them
to the user, so a newly bought asset is never auto-enabled as collateral,
same as a CoW simple order. getCollateralSwapReceivedVia now only depends
on whether a flash loan is used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Isolation mode (debt ceilings) is removed in v3.7 and all pools are
upgraded, so the isolation gates in calculateHFAfterSupply and
calculateHFAfterSwap no longer apply. Isolated e-mode handling is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 5179e425 Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant