# Reserve

The Reserve contract provides historical lookups of a token balance increase during a target time range. As the Reserve contract transfers OUT tokens, the withdrawal accumulator is increased. When tokens are transferred IN new checkpoint *can* be created if `checkpoint()` is called after transferring tokens. By using the reserve and withdrawal accumulators to create a new checkpoint, any contract or account can look up the balance increase of the reserve for a target time range. By calculating the total held tokens in a specific time range, contracts that require knowledge of captured interest during a draw period, can easily call into the Reserve and deterministically determine the newly acquired tokens for that time range.

## Write methods description

### initialize()

Allows to initialize the contract during the deployment. Constructs Reserve with passed parameters.

Parameters:

<table><thead><tr><th width="140.33333333333331">Name</th><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_owner</strong></td><td>address</td><td>Address that will become the new owner of the contract.</td></tr><tr><td><strong>_token</strong></td><td>address</td><td>ERC20 address that will be used in the reserve.</td></tr></tbody></table>

### checkpoint()

Create observation checkpoint in ring buffer. Calculates total deposited tokens since last checkpoint and creates a new accumulator checkpoint.

### withdrawTo()

Transfer Reserve token balance to recipient address. Creates checkpoint before token transfer. Increments `withdrawAccumulator` with amount.

Parameters:

<table><thead><tr><th width="220">Name</th><th width="195.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_recipient</strong></td><td>address</td><td>Account address.</td></tr><tr><td><strong>_amount</strong></td><td>uint256</td><td>Transfer amount.</td></tr></tbody></table>

### claimOwnership()

Allows the `pendingOwner` address to claim the owner role. This function is only callable by the `pendingOwner`.

### renounceOwnership()

Leaves the contract without owner. It will not be possible to call the owner's functions anymore. Can only be called by the current owner. The method does not take any parameters. Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

### transferOwnership()

Transfers ownership of the contract to a `_pendingOwner`. Can only be called by the current owner.

Parameters:

<table><thead><tr><th width="177.33333333333331">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_newOwner</strong></td><td>address</td><td>An account that will become the <code>_pendingOwner</code>.</td></tr></tbody></table>

### setManager()

Allows the owner to give the manager role to an address. The manager role has access to the functions with the modified `onlyManager` or `onlyManagerOrOwner`.

Parameters:

<table><thead><tr><th width="193.33333333333331">Name</th><th width="138">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_newManager</strong></td><td>address</td><td>An account that will become the new manager.</td></tr></tbody></table>

## Read methods description

### getReserveAccumulatedBetween()

Calculate token accumulation between timestamp range. Search the ring buffer for two checkpoint observations and diffs accumulator amount.

Parameters:

| Name                 | Type   | Description      |
| -------------------- | ------ | ---------------- |
| **\_startTimestamp** | uint32 | Start timestamp. |
| **\_endTimestamp**   | uint32 | End timestamp.   |

Return:

<table><thead><tr><th width="224.33333333333331">Name</th><th width="149">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_amount</strong></td><td>uint224</td><td>Accumulated between input timestamps.</td></tr></tbody></table>

### getToken()

Read global token value. It is the token that the reserve will accept.

### withdrawAccumulator()

Total withdrawal amount from reserve.

### owner()

An account that is the owner of the contract. It has access to the functions that use the modified `onlyOwner`.

### pendingOwner()

Address that can claim the owner role. It is used to transfer the owner.

### manager()

Manager role that can be granted exclusive access to specific functions with the modifier `onlyManager` or `onlyManagerOrOwner`.


---

# Agent Instructions: 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:

```
GET https://docs.asymetrix.io/resources/developers-docs/reserve.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
