> For the complete documentation index, see [llms.txt](https://piggybank.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://piggybank.gitbook.io/docs/vault-infrastructure/epochs.md).

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://piggybank.gitbook.io/docs/vault-infrastructure/epochs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
