# How Morfa Works

Morfa automates USDC allocation across curated **Morpho Blue** markets on Ethereum Mainnet without taking custody of your assets. Understanding the full closed loop (from deposit to allocation to withdrawal) makes it clear where yield comes from and where your USDC lives at every step.

## Where Yield Comes From

All yield earned through Morfa originates from two distinct, variable sources:

1. **Native USDC Yield (`Variable APY · 6h average`):** Paid continuously by overcollateralized borrowers on Morpho Blue who deposit collateral (such as `WBTC`, `cbBTC`, `stUSDS`, or other curated collateral assets) to borrow USDC. Interest accrues automatically every second into your vault share price (Mode B) or your Morpho Blue supply shares (Mode A).
2. **Merkl Token Incentives (`Variable APR · 6h average`):** Optional third-party reward campaigns funded by external protocols or curators and distributed via **Merkl**. These incentives are not interest, can change or end without notice, and are claimed separately through the Merkl Distributor.

## Why Morpho Blue Markets Need Active Rebalancing

Morpho Blue organizes lending into **isolated markets**, each defined by a specific collateral asset, loan asset (`USDC`), oracle, liquidation loan-to-value (`LLTV`), and interest rate model (`AdaptiveCurveIRM`). Because liquidity is isolated per market:

* Supply APY shifts continuously as borrowers open or repay positions and as other lenders enter or exit.
* External Merkl campaigns start, rotate, or expire on independent schedules.
* Sudden APY spikes often signal **high utilization (near 100%)**, where headline yield looks attractive on paper but lenders may face temporary withdrawal delays until borrowers repay or new liquidity arrives.

Morfa continuously evaluates curated USDC markets, accounts for how a deposit moves the interest rate curve, filters out unhealthy or illiquid markets, and reallocates only when expected net gains exceed transaction and fee costs.

***

## Follow 1 USDC: Mode B (Morfa Vault / `mfUSDC`)

Mode B is the **default** way to use Morfa. It uses an official ERC-4626 **Morpho Vault V2** smart contract (`0xfde07Bd3A0e514e7216239Ecd31c51a2400B99c9`) paired with `MorphoMarketV1AdapterV2`.

> Diagram (Mode B Closed-Loop Vault Flow): User Wallet (USDC) -> Morfa Vault V2 (0xfde0...99c9, mints ERC-4626 mfUSDC) -> MorphoMarketV1AdapterV2 (0xA6dD...eD41) -> Curated Morpho Blue Markets (overcollateralized AdaptiveCurveIRM markets earning native USDC APY + external Merkl incentives). The Morfa Allocator worker calls VaultV2.multicall strictly inside Curator caps and never takes custody. Withdrawals and redemptions return USDC directly to the user wallet.

1. **Deposit:** You deposit `1 USDC` into the Morfa Vault V2 smart contract (using a gasless EIP-2612 permit for standard EOA wallets or an ERC-20 `approve` for Smart Accounts). No `Morpho.setAuthorization` is needed.
2. **Receipt tokens minted:** The vault mints **ERC-4626 `mfUSDC` receipt tokens** directly to your wallet. Your `mfUSDC` balance represents your proportional claim on the vault's underlying USDC plus accrued native yield.
3. **Curator caps define the boundary:** The Vault Curator sets per-market, per-collateral, and adapter caps under Morpho Vault V2 timelocks. The automated allocator cannot deploy funds outside those approved markets or caps.
4. **Multi-market allocation:** Morfa's allocator evaluates curated markets and calls `VaultV2.multicall` atomically to balance vault liquidity across eligible markets while keeping a healthy **Liquidity Adapter** designated for ordinary withdrawals.
5. **Continuous accrual:** Borrower-paid USDC interest compounds automatically inside the vault's on-chain share price (`realAssets()`). Any external Merkl incentives forwarded to depositors accumulate separately for claiming.
6. **Emergency protection:** If a curated market becomes illiquid, suffers an oracle failure, or has its cap lowered, the allocator evacuates available liquidity into safer liquid markets.
7. **Exit directly to your wallet:** When you withdraw USDC or redeem `mfUSDC`, the vault burns your receipt tokens and transfers USDC straight to your wallet from idle vault liquidity and the active Liquidity Adapter (subject to available liquidity).

***

## Follow 1 USDC: Mode A (Direct Wallet / Morpho Blue + `MorfaRebalancer`)

Mode A is built for users who prefer to hold **native Morpho Blue `supplyShares` directly on their own wallet address** instead of holding a pooled vault receipt token.

> Diagram (Mode A Direct Wallet Atomic Rebalance): User Wallet owns native Morpho Blue supplyShares directly and sets on-chain guardrails (maxFeeBps, cooldown, 30-day periodFeeCap). When rebalancing, MorfaRebalancer.sol atomically verifies guardrails, withdraws 100% of shares from Market A, retains the accrued fee (5 bps standard, 0 bps for WithdrawOnly markets), and supplies netAssets to active Market B on behalf of the user, enforcing USDC.balanceOf(this) == usdcBefore + res.fee and \<= 2 wei rounding loss.

1. **Direct supply on Morpho Blue:** You supply USDC directly into an eligible Morpho Blue market (or keep an existing Morpho Blue USDC supply position you already hold; Morfa auto-detects it).
2. **Opt in with personal on-chain guardrails:** You configure three hard limits enforced by `MorfaRebalancer.sol`: your maximum rebalance fee (`maxFeeBps`), minimum time between rebalances (`cooldown`), and rolling 30-day fee ceiling (`periodFeeCap`). You authorize `MorfaRebalancer` on Morpho Blue (single EIP-712 signature + 1 transaction for EOAs via `enableWithSig`, or 2 transactions for Smart Accounts).
3. **Off-chain monitoring:** Morfa's keeper monitors your opted-in position against whitelisted active USDC markets and evaluates whether moving to the best active market yields a meaningful net improvement after rate impact and fees.
4. **Atomic rebalance:** When conditions are met, the keeper triggers `MorfaRebalancer`, which verifies every user guardrail and on-chain safety invariant, withdraws 100% of your supply shares from Market A, retains only the exact protocol fee (`5 bps` standard; `0 bps` on `WithdrawOnly` evacuations), and supplies `netAssets` directly to Market B **on behalf of your wallet** in a single atomic transaction.
5. **Zero custody between transactions:** `MorfaRebalancer` enforces exact balance conservation on-chain (`USDC.balanceOf(this) == usdcBefore + res.fee`). It never holds user principal between transactions and cannot call `borrow` or `withdrawCollateral`.
6. **Direct exit or instant off-switch:** At any time, you can withdraw directly from Morpho Blue, call `MorfaRebalancer.disable()`, or revoke `Morpho.setAuthorization(rebalancer, false)` directly on Morpho Blue.

## Next Steps

* Compare both modes side by side in [Choosing a Mode: Vault vs Direct](/getting-started/modes).
* Ready to make your first deposit? Follow the [Quickstart](/getting-started/quickstart).
