# Risk Filters & Emergency Evacuation

In isolated DeFi lending markets, the highest headline APY is frequently a warning sign rather than an opportunity. When utilization climbs toward `100%`, `AdaptiveCurveIRM` spikes the borrow rate sharply, attracting naive depositors into markets where withdrawal liquidity is nearly exhausted. Morfa is engineered to reject "toxic APY" traps and evacuate positions automatically when conditions deteriorate.

***

## Multi-Layer Risk Guardrails

Every allocation decision must pass both **hard on-chain smart contract invariants** (which cannot be bypassed even by the keeper) and **off-chain risk screening** inside `morfa-worker`.

### Immutable On-Chain Invariants

| Guardrail | Exact On-Chain Rule | Where Enforced |
| --- | --- | --- |
| **USDC-only loan asset** | `loanToken` must equal Circle Ethereum USDC (`0xA0b8...eB48`). | `MorfaVaultV2` (asset immutable) & `MorfaRebalancer.sol` |
| **Curated / whitelisted markets only** | Vault V2 allocates only within Curator-approved adapters and caps; `MorfaRebalancer` accepts only whitelisted `Active` targets (added behind a `48h` timelock). | `Morpho Vault V2` & `MorfaRebalancer.sol` |
| **Minimum market TVL** | Target Morpho Blue market must have `totalSupplyAssets ≥ 100,000 USDC` (`MIN_MARKET_SUPPLY`). | `MorfaRebalancer.sol` (also screened off-chain for Mode B) |
| **Maximum post-deposit utilization** | Target market utilization after deposit must satisfy `utilization ≤ 95.00%` (`MAX_TARGET_UTILIZATION_WAD`). | `MorfaRebalancer.sol` (also enforced in Vault Allocator) |
| **Rounding & share-price protection** | Mode A enforces `minSharesOut` and `≤ 2 wei` rounding loss (`MAX_ROUNDING_LOSS`); Mode B UI applies `0.03%` `maxSharePrice` tolerance. | `MorfaRebalancer.sol` & `@morpho-org/morpho-sdk` |
| **Zero-custody balance conservation** | Every Mode A rebalance asserts `USDC.balanceOf(rebalancer) == usdcBefore + res.fee` before completing. | `MorfaRebalancer.sol` |

### Off-Chain Screening Criteria (`morfa-worker`)

Before proposing any rebalance, the worker evaluates additional market-health filters:

* **Free liquidity depth:** Target markets must carry healthy available liquidity both in absolute USDC terms and as a multiple of the capital being deployed, preventing allocations into thin markets that would immediately trap withdrawals.
* **`AdaptiveCurveIRM` requirement:** Only markets using Morpho's official immutable `AdaptiveCurveIRM` (`0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC`) are eligible for automated allocation.
* **Live positive oracle verification:** Market oracles are verified to return a live, strictly positive price; markets with missing, zero, or broken oracle responses are rejected.
* **Fail-closed data integrity:** If Morpho Core REST, Merkl v4, or single-block Ethereum RPC verification data is incomplete or unavailable for a market, Morfa **fails closed** and never proceeds on partial or stale data.

All monitored Ethereum USDC markets (including markets currently filtered out and their exact rejection reasons) are visible transparently inside the **Advanced** drawer on [`morfa.finance/portfolio`](https://morfa.finance/portfolio).

***

## Smart Emergency Evacuation

If a market already holding Mode B vault liquidity or Mode A user positions degrades after funds were supplied, Morfa switches from yield optimization into **Smart Emergency Evacuation** mode.

### What Triggers Emergency Evacuation?

Emergency evacuation activates automatically when **any** of the following occurs:

1. **Governance / Sentinel signal:**
   * **Mode A:** Admin or Sentinel calls `disableMarketDeposits(marketId)`, immediately flipping the market from `Active` to **`WithdrawOnly`**.
   * **Mode B:** Curator or Sentinel lowers a market's cap to `0` on Morpho Vault V2.
2. **Broken or zero oracle:** The market's oracle price becomes missing or non-positive.
3. **Sustained extreme utilization:** Market utilization remains at critically high illiquidity levels across consecutive worker cycles (tracked persistently in PostgreSQL so restarts do not reset the streak).

### How Emergency Evacuation Executes

Emergency evacuations prioritize **capital exit and liquidity recovery** over normal yield thresholds:

* **Bypasses normal profit gates & standard gas budgets:** Standard net-gain hurdles and routine keeper gas-subsidy caps are bypassed, and the worker permits an elevated emergency gas-price ceiling so evacuations are not delayed during Ethereum network congestion.
* **Full or partial exit under tight liquidity:** If the degraded market has enough free liquidity to exit 100% of shares, Morfa exits completely in one move. If free liquidity is partially constrained by borrowers, Morfa performs a **partial evacuation** of whatever free liquidity is currently available and retries on subsequent cycles as borrowers repay.
* **Safest liquid destination:** Evacuated USDC is routed to the safest eligible liquid market (prioritizing ample free liquidity and comfortable utilization headroom rather than chasing peak APY).
* **Fee-free `WithdrawOnly` evacuations (Mode A):** On-chain in `MorfaRebalancer.sol`, whenever the source market's status is `WithdrawOnly`, the protocol rebalance fee is automatically overridden to **`0 bps` (`0%`)**. Users are never charged a rebalance fee to leave a market that Admin or Sentinel flagged for exit.

:::warning[Liquidity Limits Still Apply During Extreme Stress]
Automated evacuation can only withdraw USDC that is currently **unborrowed (free liquidity)** in the source Morpho Blue market. If a market reaches `100%` utilization before evacuation completes, remaining liquidity becomes withdrawable progressively as borrowers repay or are liquidated.
:::
