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

# Error Codes

> Every error emitted by Kimia programs, grouped by category.

Each table mirrors the Rust `#[error_code]` enum exactly. For `kimia-perp`,
codes are explicitly pinned at the start of each bucket; Anchor auto-increments
within a bucket, so a code number not listed here is not used.

## kimia-perp

Defined in `Perp-engine/programs/kimia-perp/src/errors.rs`.

### Oracle

| Code | Name                    | Meaning                                        |
| ---- | ----------------------- | ---------------------------------------------- |
| 6000 | StaleOracle             | Price older than `oracle_staleness_threshold`  |
| 6001 | OracleConfidenceTooWide | Confidence exceeds `oracle_confidence_max_bps` |
| 6002 | InvalidOraclePrice      | Price ≤ 0 or account misowned                  |

### Market

| Code | Name                |
| ---- | ------------------- |
| 6010 | MarketNotActive     |
| 6011 | MarketNotPaused     |
| 6012 | MarketAlreadyExists |

### Margin

| Code | Name                    |
| ---- | ----------------------- |
| 6020 | InsufficientMargin      |
| 6021 | WithdrawalExceedsMargin |
| 6022 | ExceedsMaxLeverage      |

### Position

| Code | Name                 |
| ---- | -------------------- |
| 6030 | NoPosition           |
| 6031 | CloseExceedsPosition |
| 6032 | ZeroSize             |
| 6033 | InvalidDirection     |

### Funding

| Code | Name                  |
| ---- | --------------------- |
| 6040 | FundingTooEarly       |
| 6041 | FundingAlreadySettled |

### Liquidation

| Code | Name                |
| ---- | ------------------- |
| 6050 | NotLiquidatable     |
| 6051 | LiquidationTooLarge |

### Deposit / Withdraw

| Code | Name                   |
| ---- | ---------------------- |
| 6060 | ZeroDeposit            |
| 6061 | InsufficientCollateral |

### Math / Auth

| Code | Name            |
| ---- | --------------- |
| 6070 | MathOverflow    |
| 6080 | Unauthorized    |
| 6081 | InvalidDelegate |

### Slippage / Insurance

| Code | Name                  |
| ---- | --------------------- |
| 6090 | SlippageExceeded      |
| 6100 | InsuranceInsufficient |

### Orderbook

| Code | Name                       |
| ---- | -------------------------- |
| 6110 | OrderbookFull              |
| 6111 | OrderNotFound              |
| 6112 | OrderWouldCross            |
| 6113 | OrderPriceOutOfRange       |
| 6114 | MissingCounterparty        |
| 6115 | InvalidTickSize            |
| 6116 | InsufficientFreeCollateral |
| 6117 | MarketOrderSlippage        |

### Spot pool

| Code | Name                          |
| ---- | ----------------------------- |
| 6130 | SpotPoolPaused                |
| 6131 | SpotPoolInsufficientLiquidity |
| 6132 | SpotSwapSlippageExceeded      |
| 6133 | SpotSwapZeroAmount            |

## delta-vault

Defined in `Programs/programs/delta-vault/src/errors.rs`. Codes auto-increment
from 6000 in the order shown.

| Name                          | Meaning                                                    |
| ----------------------------- | ---------------------------------------------------------- |
| `VaultNotActive`              | Vault is not in Active state                               |
| `VaultNotPaused`              | Vault is not in Paused state                               |
| `ZeroDeposit`                 | Deposit amount must be greater than zero                   |
| `InsufficientShares`          | Insufficient shares for withdrawal                         |
| `StaleOracle`                 | Oracle price is stale (age > 30 s)                         |
| `OracleConfidenceTooWide`     | Oracle price confidence too wide (> 1%)                    |
| `MathOverflow`                | Math overflow                                              |
| `Unauthorized`                | Not vault authority                                        |
| `ZeroInsuranceSeed`           | Insurance fund seed amount must be greater than zero       |
| `InsufficientLiquidity`       | Insufficient pool liquidity for withdrawal                 |
| `DeltaExceedsThreshold`       | Delta exceeds rebalance threshold                          |
| `InvalidParameter`            | Invalid parameter value                                    |
| `NavCorrupted`                | NAV invariant violated. Call `admin_resync_nav`            |
| `PerpsUserAccountAlreadyInit` | Perps user account already initialized                     |
| `PerpsUserAccountNotInit`     | Call `init_perps_user_account` first                       |
| `PerpsMarketMismatch`         | Provided market does not match `vault.perps_market`        |
| `PerpsMarketIndexMismatch`    | Perps market index mismatch                                |
| `PerpsUserAccountMismatch`    | Perps user account PDA mismatch                            |
| `NoHedgePosition`             | No hedge position open to close                            |
| `SpotPoolMismatch`            | Spot pool does not match `vault.spot_pool`                 |
| `WsolVaultMismatch`           | wSOL vault does not match `vault.wsol_vault`               |
| `InsufficientWsol`            | Insufficient wSOL balance for withdrawal                   |
| `VaultNotMigrated`            | Spot leg not configured; call `admin_setup_spot_leg` first |
| `SpotLegAlreadySetup`         | Spot leg already configured                                |

## split-engine

Defined in `Programs/programs/split-engine/src/errors.rs`.

| Name                      | Meaning                                  |
| ------------------------- | ---------------------------------------- |
| `NotMatured`              | Market has not reached maturity          |
| `AlreadyMatured`          | Market has already matured               |
| `ZeroDeposit`             | Deposit amount must be greater than zero |
| `SupplyInvariantViolated` | PT/YT supply invariant violated          |
| `NoYieldToClaim`          | No yield to claim                        |
| `MathOverflow`            | Math overflow                            |

## yield-amm

Defined in `Programs/programs/yield-amm/src/errors.rs`.

| Name                       | Meaning                            |
| -------------------------- | ---------------------------------- |
| `SwapDisabledNearMaturity` | Pool is near maturity (t \< 0.001) |
| `SlippageExceeded`         | Output less than minimum           |
| `InsufficientLiquidity`    | Insufficient liquidity in pool     |
| `EmptyPool`                | Pool is empty                      |
| `MathOverflow`             | Math overflow                      |
| `InvalidPoolConfig`        | Invalid pool configuration         |
| `ZeroAmount`               | Zero amount                        |
| `MaturityInPast`           | Maturity must be in the future     |
| `InvalidDuration`          | Invalid duration                   |
| `AlreadyMatured`           | Pool already matured               |
| `InvariantViolated`        | Invariant violated after swap      |

## intent-router

Defined in `Programs/programs/intent-router/src/errors.rs`.

| Name                            | Meaning                                                  |
| ------------------------------- | -------------------------------------------------------- |
| `InvalidSessionState`           | Step must follow Created → Step1 → Step2 → Step3         |
| `TargetRateNotAchievable`       | Target rate not achievable at current market prices      |
| `SessionCompleted`              | Session already completed                                |
| `NotSessionOwner`               | Not session owner                                        |
| `MathOverflow`                  | Math overflow                                            |
| `ZeroAmount`                    | Zero amount                                              |
| `NoSharesReceived`              | No vault shares received from deposit                    |
| `NoTokensReceived`              | No PT/YT received from split                             |
| `SlippageExceeded`              | Slippage exceeded on swap                                |
| `PtBalanceMismatch`             | PT balance after swap doesn't match claimed `pt_sold`    |
| `UnderlyingBalanceInsufficient` | User underlying balance \< claimed `underlying_received` |
| `TargetRateNotAchieved`         | Achieved fixed rate below session target                 |
| `NoSwapPerformed`               | Swap reported zero PT sold or zero underlying received   |
| `NegativeDiscount`              | Underlying received exceeds PT face value                |
| `InvalidDuration`               | Session duration must be greater than zero               |
