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

# split-engine

> Splits yield-bearing vault shares into PT (principal) and YT (yield).

`split-engine` takes any yield-bearing vault share and mints two tradable SPL
tokens: **PT** (redeems 1:1 at maturity) and **YT** (receives all yield accrued
before maturity).

## Accounts

### Market

`["market", vault, maturity]`.

| Field                    | Type     | Notes                                         |
| ------------------------ | -------- | --------------------------------------------- |
| `vault`                  | `Pubkey` | Underlying vault (e.g. delta-vault)           |
| `vault_share_mint`       | `Pubkey` | Vault share SPL mint                          |
| `pt_mint`                | `Pubkey` | Principal token mint (authority = market PDA) |
| `yt_mint`                | `Pubkey` | Yield token mint (authority = market PDA)     |
| `vault_share_escrow`     | `Pubkey` | Holds deposited shares                        |
| `maturity`               | `i64`    | unix timestamp                                |
| `total_deposits`         | `u64`    | PT supply                                     |
| `total_yt_supply`        | `u64`    | should equal total\_deposits                  |
| `reward_per_share`       | `u128`   | MasterChef accumulator (9-decimal)            |
| `last_vault_share_price` | `u64`    | for delta computation                         |
| `accumulated_yield`      | `u64`    | total yield held in escrow                    |

### UserPosition

`["position", market, owner]`.

| Field         | Type     | Notes                                               |
| ------------- | -------- | --------------------------------------------------- |
| `owner`       | `Pubkey` |                                                     |
| `market`      | `Pubkey` |                                                     |
| `yt_balance`  | `u64`    |                                                     |
| `reward_debt` | `u128`   | `yt_balance × reward_per_share` at last interaction |

## Instructions

| Instruction         | Who        | Purpose                                                |
| ------------------- | ---------- | ------------------------------------------------------ |
| `initialize_market` | admin      | Create market with maturity and mints                  |
| `deposit`           | user       | Auto-claim pending → escrow shares → mint PT+YT 1:1    |
| `claim_yield`       | user       | Transfer pending yield (vault shares) from escrow      |
| `redeem_pt`         | user       | At maturity: burn PT → receive vault shares 1:1        |
| `early_exit`        | user       | Burn matched PT+YT → shares minus 0.3% fee             |
| `update_rewards`    | **anyone** | Sync `reward_per_share` with current vault share price |

## MasterChef flow

```
// On any join/leave:
pending        = user.yt_balance × market.reward_per_share - user.reward_debt
auto_claim(user, pending)
user.yt_balance = new_balance
user.reward_debt = user.yt_balance × market.reward_per_share
```

This guarantees every YT holder earns exactly the yield accrued **while they
held**, regardless of when others join or leave.

## update\_rewards

Anyone can crank:

1. Read `vault.share_price()`.
2. `delta = share_price - last_vault_share_price`.
3. If `delta > 0`:
   `reward_per_share += delta × PRECISION / total_yt_supply` (clamped at 1 if supply=0).
4. `last_vault_share_price = share_price`.

Negative share-price movement does not decrement `reward_per_share`, losses are
already absorbed at the vault layer (insurance fund + NAV).

## Errors

`NotMatured`, `AlreadyMatured`, `SupplyInvariantViolated`, `NoYieldToClaim`,
`MathOverflow`.

## Read next

<CardGroup cols={2}>
  <Card title="PT / YT concept" icon="scissors" href="/concepts/pt-yt-tokenization">
    Why split, worked example.
  </Card>

  <Card title="yield-amm" icon="arrow-right-arrow-left" href="/programs/yield-amm">
    Where PT and underlying trade.
  </Card>
</CardGroup>
