# Ticket

The Ticket extends the standard ERC20 and ControlledToken interfaces with time-weighted average balance functionality. The average balance held by a user between two timestamps can be calculated, as well as the historic balance. The historic total supply is available as well as the average total supply between two timestamps. A user may `delegate` their balance increasing another user's historic balance while retaining their tokens.

## Write methods description

### initialize()

Allows to initialize the contract during the deployment. Constructs Ticket with passed parameters.&#x20;

Parameters:

<table><thead><tr><th width="149.33333333333331">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_name</strong></td><td>string</td><td>ERC20 ticket token name.</td></tr><tr><td><strong>_symbol</strong></td><td>string</td><td>ERC20 ticket token symbol.</td></tr><tr><td><strong>_decimals</strong></td><td>uint8</td><td>ERC20 ticket token decimals.</td></tr><tr><td><strong>_controller</strong></td><td>address</td><td>ERC20 ticket controller address (ie. PrizePool address).</td></tr></tbody></table>

### approve()

Standard ERC20 approve of the ticket token. Sets `_amount` as the allowance of `_spender` over the caller's tokens.

Return:

<table><thead><tr><th width="196.33333333333331">Name</th><th width="181">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_approved</strong></td><td>bool</td><td><code>true</code> if the operation was successful.</td></tr></tbody></table>

### controllerBurn()

Allows the controller to burn tokens from a user account. May be overridden to provide more granular control over burning.

Parameters:

<table><thead><tr><th width="163.33333333333331">Name</th><th width="158">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>Address of the holder account to burn tokens from.</td></tr><tr><td><strong>_amount</strong></td><td>uint256</td><td>Amount of tokens to burn.</td></tr></tbody></table>

### controllerBurnFrom()

Allows an operator via the controller to burn tokens on behalf of a user account. May be overridden to provide more granular control over operator-burning.

Parameters:

<table><thead><tr><th width="142.33333333333331">Name</th><th width="118">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_operator</strong></td><td>address</td><td>Address of the operator performing the burn action via the controller contract.</td></tr><tr><td><strong>_user</strong></td><td>address</td><td>Address of the holder account to burn tokens from.</td></tr><tr><td><strong>_amount</strong></td><td>uint256</td><td>Amount of tokens to burn.</td></tr></tbody></table>

### controllerMint()

Allows the controller to mint tokens for a user account. May be overridden to provide more granular control over minting.

Parameters:

<table><thead><tr><th width="164.33333333333331">Name</th><th width="190">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>Address of the receiver of the minted tokens.</td></tr><tr><td><strong>_amount</strong></td><td>uint256</td><td>Amount of tokens to mint.</td></tr></tbody></table>

### decreaseAllowance()

Standard ERC20 `decreaseAllowance` function, atomically decreases the allowance granted to `_spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}.

Parameters:

<table><thead><tr><th width="207">Name</th><th width="146.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_spender</strong></td><td>address</td><td>Address from where to subtract the allowance.</td></tr><tr><td><strong>_subtractedValue</strong></td><td>uint256</td><td>The amount to subtract.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="193.33333333333331">Name</th><th width="196">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_success</strong></td><td>bool</td><td><code>true</code> if operation was successful.</td></tr></tbody></table>

### delegate()

Delegate time-weighted average balances to an alternative address. Transfers (including mints) trigger the storage of a TWAB in the delegate(s) account, instead of the targeted sender and/or recipient address(s). To reset the delegate, pass the zero address (0x000) as `_to` parameter. The current delegate address should be different from the new delegate address `_to`.

Parameters:

<table><thead><tr><th width="182">Name</th><th width="168.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_to</strong></td><td>address</td><td>Recipient of delegated TWAB.</td></tr></tbody></table>

### delegateWithSignature()

Allows a user to delegate via signature.

Parameters:

<table><thead><tr><th width="156.33333333333331">Name</th><th width="163">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>The user who is delegating.</td></tr><tr><td><strong>_delegate</strong></td><td>address</td><td>The new delegate.</td></tr><tr><td><strong>_deadline</strong></td><td>uint256</td><td>The timestamp by which this must be submitted.</td></tr><tr><td><strong>_v</strong></td><td>uint8</td><td>The <code>v</code> portion of the ECDSA sig.</td></tr><tr><td><strong>_r</strong></td><td>bytes32</td><td>The <code>r</code> portion of the ECDSA sig.</td></tr><tr><td><strong>_s</strong></td><td>bytes32</td><td>The <code>s</code> portion of the ECDSA sig.</td></tr></tbody></table>

### increaseAllowance()

Standard ERC20 `increaseAllowance` function, atomically increases the allowance granted to `_spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}.

### permit()

Sets `_value` as the allowance of `_spender` over `_owner`'s tokens, given `_owner`'s signed approval.

### transfer()

Standard ERC20 `transfer` function, moves `_amount` tokens from the caller's account to `_to`. Returns a boolean value indicating whether the operation succeeded.

### transferFrom()

Standard ERC20 `transferFrom` function, moves `_amount` tokens from `_from` to `_to` using the allowance mechanism. `_amount` is then deducted from the caller's allowance.

## Read methods description

### DOMAIN\_SEPARATOR()

Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.

### allowance()

Returns the remaining number of tokens that `_spender` will be allowed to spend on behalf of `_owner` through {transferFrom}. This is zero by default. This value changes when {approve} or {transferFrom} are called.

### balanceOf()

Returns the amount of tokens owned by `_account`.

### controller()

Interface to the contract responsible for controlling mint/burn.

### decimals()

ERC20 controlled token decimals.

### delegateOf()

Retrieves the address of the delegate to whom `_user` has delegated their tickets. The address of the delegate will be the zero address if `_user` has not delegated their tickets.

Parameters:

| Name       | Type    | Description               |
| ---------- | ------- | ------------------------- |
| **\_user** | address | Address of the delegator. |

### getAccountDetails()

Gets a user's TWAB context. This is a struct with their balance, next TWAB index, and cardinality.

Parameters:

<table><thead><tr><th width="167.33333333333331">Name</th><th width="162">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>The user for whom to fetch the TWAB context.</td></tr></tbody></table>

### getAverageBalanceBetween()

Retrieves the average balance held by a user for a given time frame.

Parameters:

<table><thead><tr><th width="183.33333333333331">Name</th><th width="158">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>The user whose balance is checked.</td></tr><tr><td><strong>_startTime</strong></td><td>uint64</td><td>The start time of the time frame.</td></tr><tr><td><strong>_endTime</strong></td><td>uint64</td><td>The end time of the time frame.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="137.33333333333331">Name</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_balance</strong></td><td>uint256</td><td>The average balance that the user held during the time frame.</td></tr></tbody></table>

### getAverageBalancesBetween()

Retrieves the average balances held by a user for a given time frames.

Parameters:

<table><thead><tr><th width="219.33333333333331">Name</th><th width="154">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>The user whose balances are checked.</td></tr><tr><td><strong>_startTimes</strong></td><td>uint64[]</td><td>The start time of the time frames.</td></tr><tr><td><strong>_endTimes</strong></td><td>uint64[]</td><td>The end time of the time frames.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="131.33333333333331">Name</th><th width="104">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_balances</strong></td><td>uint256[]</td><td>The average balances that the user held during the time frame.</td></tr></tbody></table>

### getAverageTotalSuppliesBetween()

Retrieves the average total supply balances for a set of given time frames.

Parameters:

| Name             | Type      | Description           |
| ---------------- | --------- | --------------------- |
| **\_startTimes** | uint64\[] | Array of start times. |
| **\_endTimes**   | uint64\[] | Array of end times.   |

Return:

<table><thead><tr><th width="173.33333333333331">Name</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_totalSupplies</strong></td><td>uint256[]</td><td>The average total supplies held during the time frame.</td></tr></tbody></table>

### getBalanceAt()

Retrieves the user's TWAB balance.

Parameters:

<table><thead><tr><th width="145.33333333333331">Name</th><th width="112">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>Address of the user whose TWAB is being fetched.</td></tr><tr><td><strong>_timestamp</strong></td><td>uint64</td><td>Timestamp at which we want to retrieve the TWAB balance.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="185.33333333333331">Name</th><th width="176">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_balance</strong></td><td>uint256</td><td>The TWAB balance at the given timestamp.</td></tr></tbody></table>

### getBalancesAt()

Retrieves the user’s TWAB balances.

Parameters:

<table><thead><tr><th width="150.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>Address of the user whose TWABs are being fetched.</td></tr><tr><td><strong>_timestamps</strong></td><td>uint64[]</td><td>Timestamps range at which we want to retrieve the TWAB balances.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="200">Name</th><th width="186.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_balances</strong></td><td>uint256[]</td><td>The user’s TWAB balances.</td></tr></tbody></table>

### getTotalSuppliesAt()

Retrieves the total supply TWAB balances between the given timestamps range.&#x20;

Parameters:

<table><thead><tr><th width="158.33333333333331">Name</th><th width="104">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_timestamps</strong></td><td>uint64[]</td><td>Timestamps range at which we want to retrieve the total supply TWAB balances.</td></tr></tbody></table>

Return:

| Name           | Type       | Description                 |
| -------------- | ---------- | --------------------------- |
| **\_balances** | uint256\[] | Total supply TWAB balances. |

### getTotalSupplyAt()

Retrieves the total supply TWAB balance at the given timestamp.

Parameters:

<table><thead><tr><th width="144.33333333333331">Name</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_timestamp</strong></td><td>uint64</td><td>Timestamp at which we want to retrieve the total supply TWAB balance.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="144.33333333333331">Name</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_balance</strong></td><td>uint256</td><td>The total supply TWAB balance at the given timestamp.</td></tr></tbody></table>

### getTwab()

Gets the TWAB at a specific index for a user.

Parameters:

<table><thead><tr><th width="194.33333333333331">Name</th><th width="165">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_user</strong></td><td>address</td><td>The user for whom to fetch the TWAB.</td></tr><tr><td><strong>_index</strong></td><td>uint16</td><td>The index of the TWAB to fetch.</td></tr></tbody></table>

Return:

<table><thead><tr><th width="130.33333333333331">Name</th><th width="101">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>_twab</strong></td><td>TWAB</td><td>The TWAB, which includes the TWAB amount and the timestamp.</td></tr></tbody></table>

### name()

Ticket token name.

### nonces()

Returns the current nonce for the owner. This value must be included whenever a signature is generated for {permit}. Every successful call to {permit} increases `owner`'s nonce by one. This prevents a signature from being used multiple times.

### symbol()

Ticket token symbol.

### totalSupply()

Returns the amount of tokens in existence.


---

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