> ## Documentation Index
> Fetch the complete documentation index at: https://docs.denar.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# How Denar works

> The architecture in five minutes: isolated markets, the USDG vault, equity-aware oracles, and how a loan flows through the system.

Denar is three layers stacked on top of each other. Each layer does one job, and each can be understood on its own.

```mermaid theme={"system"}
flowchart TB
    subgraph Lenders
        direction TB
        L1[USDG depositors]
    end
    subgraph Vault["Denar USDG Vault (dnUSDG)"]
        direction TB
        V1[One deposit, allocated across markets<br/>behind per-market caps]
    end
    subgraph Markets["Isolated lending markets — Morpho Blue"]
        direction LR
        M1[NVDA / USDG]
        M2[AAPL / USDG]
        M3[… / USDG]
    end
    subgraph Oracles["Denar oracles"]
        direction TB
        O1[Chainlink feed per stock<br/>+ USDG/USD feed<br/>+ market-hours & corporate-action guards]
    end
    B[Borrowers<br/>post stock tokens, draw USDG]
    L1 --> Vault --> Markets
    B --> Markets
    Oracles --> Markets
```

## Layer 1 — Isolated markets

The foundation is **Morpho Blue**: a minimal, immutable lending engine. Each Denar market is a sealed five-part tuple — collateral asset, loan asset, oracle, interest model, and liquidation threshold — **fixed forever at creation**. Nobody, including the Denar team, can change the rules of a market after it exists.

Isolation is the point. Tokenized equities each carry their own event risk: trading halts, corporate actions, thin liquidity. In a shared-pool design (the Aave model), one bad asset can poison the entire protocol. In Denar, the blast radius of any single stock is its own market — never its neighbors.

The trade-off is that **liquidity is per-market too**: USDG lent to the NVDA market can only be borrowed by NVDA-collateral borrowers. That's what the vault layer solves.

## Layer 2 — The USDG vault

Most lenders don't want to study six markets, split funds across them, and rebalance as conditions change. The **Denar USDG Vault (dnUSDG)** does it for them: one ERC-4626 deposit, allocated across the stock markets according to a supply queue and **per-market caps** set by the curator.

* Deposits fill markets in queue order, each up to its cap, then overflow to the next.
* Caps bound the vault's worst-case exposure to any single stock. Raising a cap goes through a **1-day timelock**; lowering one is instant.
* Yield from every market flows back into the vault's share price.
* Withdrawals draw on unborrowed liquidity at any time — the vault never takes custody in any meaningful sense.

Advanced lenders can skip the vault entirely and [lend directly to a single market](/use/lend-direct).

## Layer 3 — Equity-aware oracles

Every market prices its collateral through a dedicated **Denar oracle** that wraps Chainlink feeds with the guards equities require:

* **Two feeds, not one.** Collateral is priced by its stock feed *and* converted through an independent USDG/USD feed — Denar never assumes the stablecoin is worth exactly \$1.
* **Market-hours awareness.** Stock feeds update 24/5. Overnight and on weekends the oracle serves the last traded price; only when a feed exceeds a staleness bound sized for the longest normal market closure does the market pause.
* **Corporate-action pauses.** During splits and dividends, the token issuer flags the oracle; Denar honors the flag and pauses the market instead of trading on a half-updated price.

The full logic — including exactly what pauses and what never does — is on the [Oracles & market hours](/protocol/oracles) page.

## What a borrow looks like end to end

<Steps>
  <Step title="A lender seeds liquidity">
    USDG is deposited into the vault and allocated to the NVDA market, up to its cap.
  </Step>

  <Step title="A borrower opens a position">
    They deposit NVDA tokens as collateral and borrow USDG — up to 62.5% of the collateral's oracle value, though prudent positions stay well below that.
  </Step>

  <Step title="Interest accrues">
    The adaptive rate model charges the borrower continuously; 10% of that interest goes to the protocol, the rest to lenders.
  </Step>

  <Step title="The position closes — one way or another">
    The borrower repays and reclaims collateral (possible in **every** protocol state), or — if the position's health factor falls below 1 — anyone liquidates it, repaying the debt in exchange for collateral at a bonus.
  </Step>
</Steps>

<Check>
  There is no configuration of failures that traps user funds forever: repaying debt and recovering collateral works even with a permanently dead oracle.
</Check>
