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

# Architecture overview

> How perps.ordr's on-chain program is put together

perps.ordr is a single Solana program written in C with
[caravel](https://github.com/joeymeere/caravel), a lightweight framework with
almost no overhead. Several of the hottest instructions, the ones a market
maker calls most often while quoting, are hand written in low level assembly
instead of normal C, so they cost as little compute as possible.

The two ideas that shape everything else in the program are:

1. **One book per leverage tier, shared by every approved maker.** There is
   no single order book for an asset. Instead, each leverage tier an asset
   offers, for example SOL at 1x, 2x, and 5x, is its own market with its own
   book, and up to four approved makers quote into that same book together.
   This is explained in full on the
   [Pools and Markets](https://docs.devnet.perp.ordr.trade/architecture/pools-and-markets.md) and
   [Shared Book](https://docs.devnet.perp.ordr.trade/architecture/shared-book.md) pages.
2. **Nothing matches until a batch clears.** A trader's order does not fill
   the moment it lands. It queues, and a permissionless crank clears every
   queued order against every maker's quotes at one price, once per slot.
   This is explained on the
   [Batching and Liquidations](https://docs.devnet.perp.ordr.trade/architecture/batching-and-liquidations.md) page.

## Core accounts

| Account | Belongs to | What it holds |
| - | - | - |
| **Pool** | One admin, one asset | Up to 8 leverage markets and up to 4 approved makers for that asset, plus the one shared token account their capital lives in |
| **Market** | One pool, one leverage tier | That tier's leverage, margin requirements, OI cap, oracle config, and whether cross margin is enabled |
| **Book** | One market | The two sides (bids, asks) that every approved maker's resting orders live in together |
| **Mid** | One maker, one pool | That maker's reference price, repriced in a single cheap instruction, and the sequence number that keeps a stale reprice from being used |
| **Auction** | One market | The queued taker orders waiting to clear, this market's liquidation heaps, and its running funding and solvency state |
| **Margin account & vault** | One trader | Free and locked USDC balance, and the token account it actually sits in |
| **Cross book** | Every trader, shared | One account holding every trader's cross-margin collateral and positions, across every market that allows cross |
| **Insurance fund** | One market | USDC set aside from liquidations to cover a shortfall before a trader is owed an IOU |

From there:

* Admins create [pools and markets](https://docs.devnet.perp.ordr.trade/architecture/pools-and-markets.md), and
  approve the makers who are allowed to quote into them.
* Makers quote into the [shared book](https://docs.devnet.perp.ordr.trade/architecture/shared-book.md), pricing
  every order as an offset from one mid they control.
* Traders submit orders that queue up and clear through
  [batching, and get liquidated through the same process if they go
  underwater](https://docs.devnet.perp.ordr.trade/architecture/batching-and-liquidations.md).
* Trader collateral and maker capital are tracked differently, covered on the
  [Margin and Vaults](https://docs.devnet.perp.ordr.trade/architecture/margin-and-vaults.md) page.

> [!NOTE]
>
> Looking for the exact formulas behind any of this, like the liquidation key
> or the funding accrual? [The Math](https://docs.devnet.perp.ordr.trade/architecture/math.md) page has every
> equation; these pages explain the ideas, not re-derive them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.