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

> The yield-space invariant and how PT/underlying pools converge at maturity.

<style>
  {`
    .katex-display {
      overflow-x: auto;
      overflow-y: hidden;
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    .katex-display::-webkit-scrollbar {
      display: none;
      height: 0;
      width: 0;
    }
    `}
</style>

Kimia's yield-AMM (`yield-amm`) is purpose-built for trading a PT against its
underlying. A classic constant-product AMM wouldn't work here: PT is contractually
worth 1 underlying at maturity, so price must approach par as time runs out.

## The yield-space invariant

Instead of $x \cdot y = k$, Kimia uses:

$$
x \cdot y^{t} = k
$$

where:

* $x$ = reserves of underlying (vault shares),
* $y$ = reserves of PT,
* $t$ = fraction of time remaining to maturity, in `[0, 1]`.

At pool creation, $t = 1$, and the curve behaves like a softened constant-product
curve. At maturity, $t = 0$, so $y^t = 1$ and the invariant becomes $x = k$, PT
trades 1:1 with underlying. The pool's curve literally decays into a fixed peg.

## Time factor

$$
t = \text{clamp}\!\left(\frac{\text{maturity} - \text{now}}{\text{total\_duration}},\; 0,\; 1\right)
$$

* **New pool:** \`now ≈ creation → t ≈ 1 → slippage tolerant\*\*
* **Near maturity:** \`t → 0 → pool behaves like a 1:1 swap\*\*

Swaps with `t < 0.001` are disabled to avoid numerical blow-up in the exponent.

## Swap math

Given `x, y, t`, the pool maintains `k = x · y^t` through any swap.

**Underlying → PT**

$$
k = x \cdot y^{t}, \qquad y_{\text{new}} = \left(\frac{k}{x + \text{amount\_in}}\right)^{1/t}, \qquad \text{pt\_out} = y - y_{\text{new}}
$$

**PT → underlying**

$$
x_{\text{new}} = \frac{k}{y_{\text{new}}^{\,t}}, \qquad \text{under\_out} = x - x_{\text{new}}
$$

The exponentiation uses `kimia-math::pow_frac(base, exponent)`, which implements
`exp(exponent · ln(base))` with range-reduced Taylor series. Precision is
verified at \< 0.05% error across the whole operating range.

## Fees

* **Swap fee:** 30 bps (0.3%) deducted from the input.
* **LP fee share:** All fees stay in the pool, growing `k` for every LP.

## LP mechanics

`add_liquidity` / `remove_liquidity` take **balanced** deposits, the pool won't
accept a single-sided add because that would break the invariant without
compensating the other side.

* First LP: `lp_out = geometric_mean(underlying, pt)`.
* Subsequent LPs: `lp_out = min(underlying_amt / x, pt_amt / y) · total_lp`.

## Pricing intuition

* **PT discount = fixed rate.** If PT trades at 0.98 underlying with 30 days left,
  the annualized rate is `(1/0.98)^(365/30) − 1 ≈ 28%`.
* **YT price = 1 − PT price** (by conservation). YT is cheap early, expensive as
  yield accrues.

## Read next

<CardGroup cols={2}>
  <Card title="yield-amm reference" icon="book" href="/programs/yield-amm">
    Instructions and account layout.
  </Card>

  <Card title="Fixed-rate intents" icon="route" href="/concepts/fixed-rate-intents">
    How the router uses the AMM to prove an achieved APY.
  </Card>

  <Card title="Math library" icon="function" href="/build/math">
    pow\_frac, ln, exp, how we stay precise under 9-decimal fixed point.
  </Card>
</CardGroup>
