> ## 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.

# delta-vault

> USDC vault that opens a hedged SOL-PERP short and distributes funding yield.

`delta-vault` holds user deposits, maintains a delta-neutral hedge via
`kimia-perp`, and distributes accrued funding to vault share holders.

## Accounts

### Vault

`["vault", perps_market]`.

| Field                        | Type         | Notes                                          |
| ---------------------------- | ------------ | ---------------------------------------------- |
| `authority`                  | `Pubkey`     | Admin                                          |
| `perps_market`               | `Pubkey`     | `kimia-perp::Market` this vault hedges on      |
| `perps_market_index`         | `u16`        |                                                |
| `perps_user_account`         | `Pubkey`     | Vault's user account inside `kimia-perp`       |
| `share_mint`                 | `Pubkey`     | SPL mint for vault shares                      |
| `usdc_vault`                 | `Pubkey`     | USDC token account (vault PDA authority)       |
| `wsol_vault`                 | `Pubkey`     | wSOL token account (spot leg)                  |
| `spot_pool`                  | `Pubkey`     | `kimia-perp::SpotPool` the vault swaps against |
| `nav`                        | `u64`        | Net asset value, USDC 6-decimal                |
| `total_shares`               | `u64`        |                                                |
| `insurance_fund`             | `u64`        |                                                |
| `insurance_skim_bps`         | `u16`        | configurable per vault (e.g. 3000 = 30%)       |
| `rebalance_threshold_bps`    | `u16`        | triggers rebalance()                           |
| `state`                      | `VaultState` | `Active`, `Paused`, `Closed`                   |
| `last_realized_pnl_snapshot` | `i64`        | used by `claim_funding`                        |
| `last_wsol_balance`          | `u64`        | for rebalance diffs                            |

`share_price() = nav × ONE / total_shares` (9-decimal fixed point).

## Instructions

| Instruction               | Who          | Purpose                                              |
| ------------------------- | ------------ | ---------------------------------------------------- |
| `initialize_vault`        | admin        | Create Vault PDA, share mint, USDC vault             |
| `admin_seed_insurance`    | admin        | Bootstrap the insurance fund                         |
| `init_perps_user_account` | admin        | One-time CPI to create vault's perp user             |
| `admin_setup_spot_leg`    | admin        | Configure wSOL vault + spot pool                     |
| `deposit`                 | user         | Mint shares; optionally open hedge                   |
| `withdraw`                | user         | Burn shares; optionally close hedge                  |
| `rebalance`               | **anyone**   | Close delta gap if > `rebalance_threshold_bps`       |
| `claim_funding`           | **anyone**   | CPI `settle_funding`, route yield to NAV + insurance |
| `admin_resync_nav`        | admin        | Emergency NAV reconciliation                         |
| `admin_unwind_vault`      | admin        | Force close all positions (requires `Paused`)        |
| `admin_simulate_funding`  | admin (demo) | Inject synthetic yield for testing                   |
| `admin_force_pause`       | admin (demo) | Pause vault manually                                 |

## Deposit flow

```
user USDC
    │
    ▼
vault.usdc_vault  ── mints shares = amount × total_shares / NAV ──► user
    │
    │ if open_perp=true and size_amount>0:
    │
    ├── spot_swap(half USDC → wSOL)                  [CPI → kimia-perp]
    ├── deposit_collateral(half USDC → perp)         [CPI → kimia-perp]
    └── place_order(direction=SHORT, size_amount,
                    is_market=true, max_slippage_bps) [CPI → kimia-perp]
```

Remaining accounts passed to `deposit` are orderbook counterparty accounts used
by `place_order`.

## claim\_funding flow

```
pre_snapshot  = perps_user_account.realized_pnl
settle_funding(keeper=vault_pda)    [CPI → kimia-perp]
post_snapshot = perps_user_account.realized_pnl

delta = post_snapshot - pre_snapshot

if delta > 0:
    skim      = delta × insurance_skim_bps / 10_000
    to_nav    = delta - skim
    insurance_fund += skim
    nav       += to_nav
else:
    abs_delta = -delta
    drawn     = min(abs_delta, insurance_fund)
    insurance_fund -= drawn
    nav       -= abs_delta - drawn

    if insurance_fund == 0 and sustained 24h loss:
        state = Paused
```

## Withdraw flow

```
shares = amount
if close_perp=true:
    place_order(direction=LONG buy-to-close, base_amount=share_ratio × position)
    spot_swap(wSOL → USDC proportionally)

burn shares → transfer USDC to user
nav -= amount_out
```

## Errors

`VaultNotActive`, `VaultNotPaused`, `MathOverflow`, `StaleOracle`,
`PerpsUserAccountNotInit`, `NavCorrupted`, `InsufficientInsuranceFund`,
`RebalanceGapTooSmall`.

## Read next

<CardGroup cols={2}>
  <Card title="Delta-neutral concept" icon="shield" href="/concepts/delta-neutral-vault">
    The math and motivation.
  </Card>

  <Card title="split-engine" icon="scissors" href="/programs/split-engine">
    Wrap vault shares into PT/YT.
  </Card>
</CardGroup>
