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

# How Hearth works

> On-chain XFG/HEAT market: constant-product AMM + tx-extra-backed limit orders, 1% taker fee → CD yield; LP income is pool P&L.

**Hearth** is Fuego’s native **XFG/HEAT** exchange: a constant-product AMM with a limit-order overlay. It is the price surface for minting HEAT and for on-chain XFG↔HEAT swaps.

## What Hearth is not

* Not a centralized order book hosted by a company
* Not the same as **swapXFG** (cross-chain atomic swaps)
* Not DIGM

## Orderbook model (v12+)

The original in-band CLOB matcher (gossiped, unbacked orders matched once per block at a VWAP clearing price) is **retired**. The live model:

1. **Orders are transactions.** A limit order is created by a `TransactionExtraLimitDeposit` (SELL\_XFG deposits XFG, BUY\_XFG deposits HEAT into the pending buckets). Nothing exists in a gossip mempool — every resting order is backed by committed funds.
2. **Execution at block time, against the pool, at the live spot price.** Each block the protocol fills resting orders whose limit is crossed by the current pool spot price (`ammGetSpotPrice` = HEAT/XFG × COIN):
   * SELL\_XFG fills if `target ≤ spot`; the pool buys the XFG and credits HEAT proceeds.
   * BUY\_XFG fills if `target ≥ spot`; the pool sells XFG and debits the HEAT budget.
3. **Partial fills and proceeds.** Fills consume part of the deposit; the proceeds (`proceedsXfg` / `proceedsHeat`) are claimable later with the remaining deposit via a `TransactionExtraLimitWithdraw` (also the auto-return path for expired orders).
4. **Expiry is height-based** (`expiration` blocks). Expired orders keep their deposit + proceeds claimable.
5. **Taker pays the 1% fee** by receiving the fee-adjusted output; the fee value leaves LP reserves into the HEAT-denominated CD accumulator.
6. **No unbacked orders, no gossip, no user-vs-user matching.** The pool is the sole counterparty — this removes the wash-trade / unbacked-order manipulation classes entirely.

`P_clear` remains the header metric (clearing-price statistic), seeded from the pool ratio in bootstrap; at v12 the volatility feed used for the adaptive spread is the **pool spot price** itself.

## Fee (live code)

| Constant                  | Value                                                    |
| ------------------------- | -------------------------------------------------------- |
| `HEARTH_FEE_BPS`          | **100** = **1.0%** of trade notional, paid by the taker  |
| `HEARTH_CD_SHARE_BPS`     | **70** — 70% of the fee → CD yield                       |
| `HEARTH_MAKER_REBATE_BPS` | **30** — 30% of the fee → maker rebate                   |
| `HEARTH_BACKSTOP_MAX_BPS` | **500** — backstop fills ≤ 5× the block's auction volume |

```
gross = user_notional
paid  = gross × (10000 − 100) / 10000      // taker receives fee-adjusted output
fee   = gross − paid                        // 70% → CD accumulator, 30% → maker rebate
```

On auction fills the taker is the rationed side; the maker side receives the rebate pool pro-rata. On pool-intermediated fills (backstop/AMM) the pool is the maker, so 30% stays in LP reserves. The 70% accrues in a HEAT-denominated accumulator (`cdHearthFeeAccumulator`) and is minted into the CD yield vault (`CD_APY_POOL`) at each epoch boundary; the consumed XFG side is burned 50/50 (Eternal Flame / SWF).

## Roles

| Role                | Action                                                                                                                                                                                         |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Trader              | Swaps XFG↔HEAT (AMM) or places a limit order; pays the 1% flat fee                                                                                                                             |
| LP                  | Provides a **balanced** XFG+HEAT deposit (single-sided deposits are rejected); earns the pool’s trading P\&L and appreciation, realized on withdrawal via share redemption — not the flat fee  |
| Minter              | Uses Hearth TWAP when burning XFG to mint HEAT (canonical price = HEAT/XFG × COIN)                                                                                                             |
| CD holder           | Receives the 1% Hearth flat fee via the CD yield vault                                                                                                                                         |
| Protocol / Treasury | The **Treasury LP Manager** maintains the protocol’s own ratio-paired LP position (from the 20% treasury fee share + mint premiums + donations) which compounds and drives bootstrap repayment |

## Privacy

LP and commitment-style positions use the chain’s commitment / privacy primitives. Exact share sizes are not meant to be public account balances like a CEX.

## Related

* [Provide liquidity](/features/hearth/providing-liquidity)
* [Fee earning](/features/hearth/fee-earning)
* [Mint HEAT](/features/heat/mint-heat)
* [swapXFG](/features/atomic-swaps/how-swaps-work)
