> For the complete documentation index, see [llms.txt](https://docs.fira.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fira.money/developers/protocol-contracts/core.md).

# Core

The core directory contains the AMM trading infrastructure and yield tokenization system — the two pillars of the Fira protocol.

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.fira.money/developers/protocol-contracts/core.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
