# Yield Accrual Example

#### PT Redemption Example

Let's see how PT redemption works, both before and at expiry. Assume:

* User holds: 1,000 PT tokens
* PY index when market created: 1.0
* Current PY index: 1.05 (5% yield accrued so far)

**Scenario 1: Early Redemption (Before Expiry)**

To redeem PT before expiry, you must combine it with YT:

```
PT to redeem: 1,000 PT
YT needed: 1,000 YT (must match PT amount)
Current PY index: 1.05

SY redeemable = asset_to_sy(py_index, pt_redemption_amount)
SY redeemable = pt_redemption_amount / py_index
SY redeemable = 1,000 / 1.05 ≈ 952.38 SY
```

**Result:**

* User redeems: 1,000 PT + 1,000 YT
* User receives: \~952.38 SY
* This is less than the original 1,000 SY because the PY index has increased
* User can claim (1,000 - 952.38) = 47.62 SY, which came from holding 1,000 YT before the sale

**Why less than original amount?**

* When you minted at py\_index 1.0: 1,000 SY → 1,000 PT + 1,000 YT
* PT represents a fixed number of "asset units" (1,000 assets at index 1.0)
* When you redeem at py\_index 1.05: Those 1,000 asset units convert to SY using the new index
* Since SY has grown in value (index increased), 1,000 assets = 1,000/1.05 = 952.38 SY
* **Important:** When redeeming PT + YT together, you're not claiming YT yield separately - the YT is just burned. To get the full value, you should claim YT yield first, then redeem PT + remaining YT.

**Scenario 2: Redemption at Expiry**

At expiry, the PY index is frozen at `first_post_expiry_py_index`. Let's say:

```
Market expired
PY index frozen at: 1.10 (10% total yield over the year)
User redeems: 1,000 PT

SY redeemable = asset_to_sy(first_post_expiry_py_index, pt_redemption_amount)
SY redeemable = 1,000 / 1.10 ≈ 909.09 SY
```

**Understanding the "1 PT = 1 SY at expiry" guarantee:**

The guarantee means PT is always redeemable for SY at expiry, but the amount depends on the PY index:

* If PY index at expiry = 1.0 (no yield accrued): 1,000 PT → 1,000 SY
* If PY index at expiry = 1.10 (10% yield accrued): 1,000 PT → 1,000/1.10 ≈ 909.09 SY

**Why this makes sense:**

* PT represents a fixed number of asset units
* As yield accrues, the PY index increases
* At redemption, asset units are converted to SY using the current index
* If you bought PT at a discount (e.g., 105 PT for 100 SY), and index stays at 1.0, you'd get 105 SY back
* If index grows to 1.05, you'd get 105/1.05 ≈100 SY back

**Key Insight:** PT redemption converts asset units to SY using the current PY index. The index represents how much the underlying has grown, so redemption accounts for that growth. The "1:1" guarantee refers to redeemability, not a fixed exchange rate.

#### YT Interest Accrual Example

Now let's see how YT holders accrue and claim yield. Assume:

* User mints YT when: py\_index = 1.0 (market just created)
* User receives: 1,000 YT tokens
* Time passes: 6 months later
* Current py\_index: 1.05 (5% yield accrued)
* User wants to claim accrued yield

**Step 1: Initial State**

```
When YT was minted:
- User deposited SY and split into PT + YT
- Received 1,000 YT tokens
- PY index at mint: 1.0
- User's YT represents: 1,000 / 1.0 = 1,000 SY worth of yield exposure
```

**Step 2: Yield Accrual Over Time**

```
After 6 months:
- PY index increased: 1.0 → 1.05
- This represents 5% yield on the underlying assets
- User's YT: 1,000 YT tokens
- YT now represents: 1,000 / 1.0 * 1.05 = 1,050 assets worth of yield exposure
```

**Step 3: Calculate Claimable Yield**

```
Formula: interest_from_yt = principal * (current_index - prev_index) / (prev_index * current_index)

User's YT balance: 1,000 YT
Previous index (when last interacted): 1.0
Current index: 1.05

interest_from_yt = 1,000 * (1.05 - 1.0) / (1.0 * 1.05)
interest_from_yt = 1,000 * 0.05 / 1.05
interest_from_yt = 50 / 1.05
interest_from_yt ≈ 47.62 SY
```

**Step 4: Apply Interest Fee (if any)**

```
Protocol interest fee: 0% (assume no fee for this example)
User receives: 47.62 SY
```

**Step 5: Update User's Index**

```
After claiming:
- User's index updated to: 1.05
- User still holds: 1,000 YT tokens
- Next time they claim, calculation will use 1.05 as prev_index
```

**Result:**

* User claimed: 47.62 SY
* User still holds: 1,000 YT tokens
* User's index updated to: 1.05

**Continuing the Example:** If user waits another 6 months and PY index reaches 1.10:

```
Previous index: 1.05
Current index: 1.10
YT balance: 1,000 YT

interest_from_yt = 1,000 * (1.10 - 1.05) / (1.05 * 1.10)
interest_from_yt = 1,000 * 0.05 / 1.155
interest_from_yt ≈ 43.29 SY
```

**Key Insights:**

1. Yield accrues continuously as PY index increases
2. Users can claim anytime - the protocol tracks their last index
3. Each claim uses the difference between current and previous index
4. The formula accounts for the fact that YT value changes with index
5. More frequent claims = smaller amounts per claim, but same total over time

**At Expiry:** When the market expires, YT becomes worthless (all yield has been distributed).
