# PrizeDistributionBuffer

The PrizeDistributionBuffer contract provides historical lookups of PrizeDistribution struct parameters (linked with a Draw ID) via a circular ring buffer. Historical PrizeDistribution parameters can be accessed on-chain using a draw ID to calculate ring buffer storage slots. The PrizeDistribution parameters can be created by manager/owner and existing PrizeDistribution parameters can only be updated by the owner. When adding a new PrizeDistribution basic sanity checks will be used to validate the incoming parameters.

## Write methods description

### initialize()

Allows to initialize the contract during the deployment. Initialize for PrizeDistributionBuffer.

Parameters:

<table><thead><tr><th width="170.33333333333331">Name</th><th width="118">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_owner</strong></td><td>address</td><td>Address of the PrizeDistributionBuffer owner.</td></tr><tr><td><strong>_cardinality</strong></td><td>uint8</td><td>Cardinality of the <code>bufferMetadata</code>.</td></tr></tbody></table>

### pushPrizeDistribution()

Adds new PrizeDistribution record to ring buffer storage. Only callable by the owner or manager.

Parameters:

<table><thead><tr><th width="189.33333333333331">Name</th><th width="172">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID linked to PrizeDistribution parameters.</td></tr><tr><td><strong>_prizeDistribution</strong></td><td>PrizeDistribution</td><td>Parameters struct.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="202.33333333333331">Name</th><th width="169">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_pushed</strong></td><td>bool</td><td><code>true</code> if operation is successful.</td></tr></tbody></table>

### setPrizeDistribution()

Sets existing PrizeDistribution with new PrizeDistribution parameters in ring buffer storage. Retroactively updates an existing PrizeDistribution and should be thought of as a "safety" fallback. If the manager is setting invalid PrizeDistribution parameters the owner can update the invalid parameters with correct parameters.

Parameters:

<table><thead><tr><th width="200">Name</th><th width="183.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID to be set.</td></tr><tr><td><strong>_prizeDistribution</strong></td><td>PrizeDistribution</td><td>Information to set on the drawId.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="198.33333333333331">Name</th><th width="191">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID that was set.</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="150.33333333333331">Name</th><th width="128">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

### getBufferCardinality()

Read a ring buffer cardinality.

### getNewestPrizeDistribution()

Read newest PrizeDistribution from prize distributions ring buffer. Uses nextDrawIndex to calculate the most recently added PrizeDistribution.

Return:

<table><thead><tr><th width="197.33333333333331">Name</th><th width="169">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_prizeDistribution</strong></td><td>PrizeDistribution</td><td>Prize distribution.</td></tr><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID.</td></tr></tbody></table>

### getOldestPrizeDistribution()

Read oldest PrizeDistribution from prize distributions ring buffer. Finds the oldest Draw by `buffer.nextIndex` and `buffer.lastDrawId`.

Return:

<table><thead><tr><th width="196.33333333333331">Name</th><th width="179">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_prizeDistribution</strong></td><td>PrizeDistribution</td><td>Prize distribution.</td></tr><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID.</td></tr></tbody></table>

### getPrizeDistribution()

Gets the PrizeDistributionBuffer for a `_drawId`.

Return:

<table><thead><tr><th width="198.33333333333331">Name</th><th width="193">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_prizeDistribution</strong></td><td>PrizeDistribution</td><td>Prize distribution.</td></tr><tr><td><strong>_drawId</strong></td><td>uint32</td><td>Draw ID.</td></tr></tbody></table>

### getPrizeDistributionCount()

Gets the number of PrizeDistributions stored in the prize distributions 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 NewestPrizeDistribution index + 1.

Return:

<table><thead><tr><th width="124.33333333333331">Name</th><th width="86">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_number</strong></td><td>uint32</td><td>Number of PrizeDistributions stored in the prize distributions ring buffer.</td></tr></tbody></table>

### getPrizeDistributions()

Gets PrizeDistribution list from array of `_drawIds`.

Parameters:

<table><thead><tr><th width="125">Name</th><th width="121.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_drawIds</strong></td><td>uint32[]</td><td><code>_drawIds</code> to get PrizeDistribution for.</td></tr></tbody></table>

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