# DrawBuffer

The DrawBuffer provides historical lookups of Draws via a circular ring buffer. Historical Draws can be accessed on-chain using a Draw ID to calculate ring buffer storage slots. The Draw settings can be created by manager/owner and existing Draws can only be updated by the owner. Once a starting Draw has been added to the ring buffer, all following draws must have a sequential Draw ID.

A DrawBuffer stores a limited number of Draws before beginning to overwrite (managed via the cardinality) previous Draws. Mainnet DrawBuffer is updated directly from a DrawBeacon.

## Write methods description

### initialize()

Allows to initialize the contract during the deployment.&#x20;

Parameters:

<table><thead><tr><th width="176">Name</th><th width="145.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_owner</strong></td><td>address</td><td>Address of the owner of the DrawBuffer.</td></tr><tr><td><strong>_cardinality</strong></td><td>uint8</td><td>Draw ring buffer cardinality.</td></tr></tbody></table>

### markDrawAsPaid()

Mark a draw as paid. It means that the winners of the draw were paid and the draw can not be paid again.

Parameters:

<table><thead><tr><th width="153.33333333333331">Name</th><th width="136">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawId</strong></td><td>uint32</td><td>An ID of a draw that should be marked as paid.</td></tr></tbody></table>

### pushDraw()

Push draw onto draws ring buffer history. Push new draw onto draws history via authorized manager or owner.

Parameters:

<table><thead><tr><th width="164.33333333333331">Name</th><th width="240">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_draw</strong></td><td>IDrawBeacon.Draw</td><td>Draw information that was pushed.</td></tr></tbody></table>

### setDraw()

Set existing draw in draws ring buffer with new parameters. Push new draw onto draws history via authorized manager or owner.

Parameters:

| Name       | Type             | Description  |
| ---------- | ---------------- | ------------ |
| **\_draw** | IDrawBeacon.Draw | Draw to set. |

Return:

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| **\_drawId** | uint32 | Draw ID.    |

### setPrizeDistributor()

Set a new PrizeDistributor contract address.

Parameters:

<table><thead><tr><th width="207">Name</th><th width="156.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_prizeDistributor</strong></td><td>address</td><td>A new PrizeDistributor contract address</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.&#x20;

Parameters:

<table><thead><tr><th width="143.33333333333331">Name</th><th width="139">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

### MAX\_CARDINALITY()

Ring buffer max length.

### getBufferCardinality()

Read a ring buffer cardinality.

### getDraw()

Read a draw from the draws ring buffer. Read a draw using the `draw.drawId` to calculate position in the draws ring buffer.

Parameters:

<table><thead><tr><th width="170.33333333333331">Name</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawId</strong></td><td>uint32</td><td>The draw ID to retrieve the draw data from.</td></tr></tbody></table>

### getDrawCount()

Gets the number of draws held in the draw ring buffer. If no draws have been pushed, it will return 0. If the ring buffer is full, it will return the cardinality. Otherwise, it will return the newest draw index + 1.

Return:

<table><thead><tr><th width="139.33333333333331">Name</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_count</strong></td><td>uint32</td><td>Number of draws held in the draw ring buffer.</td></tr></tbody></table>

### getDraws()

Read multiple draws from the draws ring buffer. Read multiple draws using each `draw.drawId` to calculate position in the draws ring buffer.&#x20;

Parameters:

<table><thead><tr><th width="215.33333333333331">Name</th><th width="196">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawIds</strong></td><td>uint32[]</td><td>Array of draw IDs.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="109.33333333333331">Name</th><th width="195">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_draws</strong></td><td>IDrawBeacon.Draw[]</td><td>Array with the draw information of the requested draw IDs.</td></tr></tbody></table>

### getNewestDraw()

Read newest draw from draws ring buffer. Uses the `nextDrawIndex` to calculate the most recently added draw.

### getOldestDraw()

Read oldest draw from draws ring buffer. Finds the oldest draw by comparing and/or diffing `totalDraws` with the cardinality.

### getPrizeDistributor()

Read a PrizeDistributor contract address.

### owner()

Owner role that can be granted exclusive access to specific functions with the modifier `onlyOwner`.

### manager()

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

### pendingOwner()

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


---

# 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/drawbuffer.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.
