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

# Contract Map

> What each piece of Perpetra is responsible for

Perpetra is built from a set of focused pieces rather than one large contract, each one responsible for a single job. Here's what each one does and roughly how they connect. For live addresses, see [Contract Addresses](/contract-addresses).

## How the pieces connect

```mermaid theme={null}
flowchart TD
    Vault[Custody: holds\nall deposited funds]
    Signing[Order signing check]
    Matching[Off-chain matching]
    Settlement[Settlement]
    Risk[Risk limits &\nposition health]
    Prices[Price feeds]
    Funding[Funding payments]
    Fees[Fee collection]
    Liquidation[Liquidation]
    Points[Points & referrals]
    Insurance[Insurance backstop]
    Keepers[Approved bot whitelist]

    Signing --> Matching
    Matching --> Settlement
    Settlement --> Vault
    Settlement --> Risk
    Risk --> Prices
    Funding --> Prices
    Funding --> Vault
    Liquidation --> Risk
    Liquidation --> Vault
    Liquidation --> Insurance
    Settlement --> Fees
    Liquidation --> Fees
    Fees --> Vault
    Vault --> Points
    Settlement --> Points
    Keepers -.authorizes.-> Matching
    Keepers -.authorizes.-> Funding
    Keepers -.authorizes.-> Liquidation
    Keepers -.authorizes.-> Prices
```

## What each piece does

**Custody** holds every deposited token and is the only place funds actually move in or out of. Everything else, fees, liquidation payouts, funding, moves value by instructing this piece, never by holding funds itself. See [Deposits & Withdrawals](/deposit-and-withdrawal).

**Order signing** checks that a submitted order was genuinely authorized by the trader who claims to have placed it. See [Order Signing](/order-signing-eip712).

**Off-chain matching** pairs up compatible orders before anything reaches the chain. See [Off-Chain Matching Engine](/off-chain-matching-engine).

**Settlement** is where a matched trade actually becomes a position, or closes an existing one, on-chain.

**Risk limits & position health** decides whether a trade is currently allowed, and whether an open position is still healthy or needs to be liquidated. See [Risk Engine](/risk-engine).

**Price feeds** supply the reference and mark prices everything else depends on. See [Mark Price & Index Price](/trading/mark-price-and-index-price).

**Funding payments** move value between longs and shorts on a schedule, keeping Perpetra's price aligned with the broader market. See [Funding Rate](/funding-rate).

**Fee collection** takes trading and liquidation fees and routes them onward to their destinations. See [Fees](/fees).

**Liquidation** is the dedicated system for closing out unhealthy positions. See [Liquidation Engine](/liquidation-engine).

**Points & referrals** tracks trading and deposit activity, plus referral relationships, for future rewards. See [Points & Referrals](/funding-mechanism-tokenomics).

**Insurance backstop** covers the gap on liquidations where a position's own collateral wasn't enough to cover what was owed.

**Approved bot whitelist** decides which off-chain bots are allowed to trigger any of the automated pieces above. See [Keeper System](/keeper-system).
