# Epochs

## Epochs System

The epoch system provides orderly batch processing of vault operations. Each epoch represents a discrete management period where deposits and redemptions are processed together.

### Epoch Timeline

<pre><code>Epoch N-2: Performance realized, redemptions claimable
Epoch N-1: Deposits processed, redemptions queued
Epoch N:   Current epoch<a data-footnote-ref href="#user-content-fn-1">,</a> accepting deposits/redemptions
</code></pre>

### State Transitions

When `roll_epoch` is called:

#### Epoch Counter

* Increments by 1
* Triggers state updates

#### Deposit Processing

* `epoch_deposits` withdrawn by admin
* Added to `managed` assets
* Reset to 0 for new epoch

#### Redemption Processing

* `prev_epoch_redemptions` become claimable
* `epoch_redemptions` move to `prev_epoch_redemptions`
* New redemptions start at 0

#### Performance Application

* Applied to epoch N-2 positions
* Updates `managed` assets
* Affects exchange rate

### Exchange Rate Stability

The exchange rate remains constant during an epoch. This ensures:

* Fair treatment of all users
* Predictable deposit amounts
* Known redemption values

Exchange rate only updates when:

* Performance is reported
* Epoch rolls over

### Redemption Delay

The 2-epoch delay for redemptions provides:

* Time for strategy unwinding
* Batch processing efficiency
* Liquidity management

Timeline for redemption:

1. **Epoch N**: User redeems
2. **Epoch N+1**: Admin processes
3. **Epoch N+2**: User claims

### Admin Operations

Admins can perform operations during an epoch:

* `process_deposits`: Withdraw accumulated deposits
* `process_redemptions`: Deposit underlying for claims
* `roll_epoch`: Advance to next epoch

These operations can happen multiple times per epoch or batched at epoch end.

[^1]:
