# Core

The core module houses the contracts users interact with (through the router) to trade, provide liquidity, and split yield into fixed and floating components.

## How Market and YieldContracts interact

The two subsystems are tightly coupled. A `FiraMarket` is parameterized by a BT address, and every swap queries the associated CT contract for the current BC index (via `CT.newIndex()`). The BC index determines how BT (denominated in asset units) should price against FW.

When the BC index rises (because the underlying vault earns yield), BT becomes cheaper in FW terms. The AMM incorporates this automatically: `getMarketPreCompute` converts FW reserves to asset terms before computing the exchange rate, so the pricing curve always reflects the current yield environment.

At expiry, the market freezes: swaps and new deposits revert. Burns still work, letting LPs exit. Post-expiry exits go through `CT.redeemBC()` rather than AMM swaps.

## State management pattern

Both the market and yield contracts use a **read-modify-write pattern** with in-memory structs. The market loads `MarketState` into memory via `readState`, mutates it through `MarketMathCore` library calls, and persists it through `_writeState`. This avoids repeated SLOAD/SSTORE operations and keeps the math library pure.

## Contracts

* [FiraMarket](https://docs.fira.money/developers/protocol-contracts/core/fira-market) — BT/FW AMM with LP tokens
* [FiraMarketFactory](https://docs.fira.money/developers/protocol-contracts/core/fira-market-factory) — Split-code CREATE2 market deployment
* [MarketMathCore](https://docs.fira.money/developers/protocol-contracts/core/market-math-core) — Pricing curve and trade execution math
