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

# yield-amm

> AMM for PT / underlying with a yield-space invariant that decays into par at maturity.

`yield-amm` is an AMM purpose-built for trading a principal token (PT) against
its underlying. The invariant $x \cdot y^t = k$ makes prices converge to 1:1 as
time-to-maturity $t$ approaches 0.

## Accounts

### Pool

`["pool", market]`.

| Field                                | Type     | Notes                         |
| ------------------------------------ | -------- | ----------------------------- |
| `market`                             | `Pubkey` | Paired split-engine market    |
| `underlying_mint`                    | `Pubkey` | Vault share mint              |
| `pt_mint`                            | `Pubkey` | PT mint                       |
| `lp_mint`                            | `Pubkey` | LP share mint                 |
| `underlying_reserve_account`         | `Pubkey` | Vault share token account     |
| `pt_reserve_account`                 | `Pubkey` | PT token account              |
| `underlying_reserves`, `pt_reserves` | `u64`    | Mirrors token accounts        |
| `total_lp`                           | `u64`    | LP supply                     |
| `maturity`                           | `i64`    | unix                          |
| `total_duration`                     | `i64`    | seconds (maturity − creation) |

### Pool methods

* `time_factor(now) = clamp((maturity - now) / total_duration, 0, 1)`.
* `compute_k(t) = underlying_reserves × pt_reserves^t`.
* `get_pt_out(underlying_in, t)`, solve `k / (x + amount_in)` for the exponent $t$.
* `get_underlying_out(pt_in, t)`, inverse.

## Instructions

| Instruction        | Purpose                                             |
| ------------------ | --------------------------------------------------- |
| `create_pool`      | Seed reserves, set maturity and total\_duration     |
| `swap`             | Underlying ↔ PT with 30 bps fee, slippage-protected |
| `add_liquidity`    | Balanced add, mint LP                               |
| `remove_liquidity` | Burn LP, withdraw proportional reserves             |

Swap is disabled within `t < 0.001` of maturity to avoid exponent blow-up. At
that point PT is essentially at par, just call `redeem_pt` on the split engine.

## Math helpers (kimia-math)

* `pow_frac(base, exponent)`, `exp(exponent × ln(base))` via range-reduced
  Taylor series. Error \< 0.05%.
* `mul_fp`, `div_fp`, u128-intermediate fixed-point ops, always rounds down.

## Errors

`SwapDisabledNearMaturity`, `SlippageExceeded`, `InsufficientLiquidity`,
`MathOverflow`, `AlreadyMatured`.

## Read next

<CardGroup cols={2}>
  <Card title="Yield-AMM concept" icon="arrow-right-arrow-left" href="/concepts/yield-amm">
    Full derivation of the invariant and fees.
  </Card>

  <Card title="Math reference" icon="function" href="/build/math">
    pow\_frac, ln, exp.
  </Card>
</CardGroup>
