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.
Parameters:
_name
string
ERC20 ticket token name.
_symbol
string
ERC20 ticket token symbol.
_decimals
uint8
ERC20 ticket token decimals.
_controller
address
ERC20 ticket controller address (ie. PrizePool address).
approve()
Standard ERC20 approve of the ticket token. Sets _amount
as the allowance of _spender
over the caller's tokens.
Return:
_approved
bool
true
if the operation was successful.
controllerBurn()
Allows the controller to burn tokens from a user account. May be overridden to provide more granular control over burning.
Parameters:
_user
address
Address of the holder account to burn tokens from.
_amount
uint256
Amount of tokens to burn.
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:
_operator
address
Address of the operator performing the burn action via the controller contract.
_user
address
Address of the holder account to burn tokens from.
_amount
uint256
Amount of tokens to burn.
controllerMint()
Allows the controller to mint tokens for a user account. May be overridden to provide more granular control over minting.
Parameters:
_user
address
Address of the receiver of the minted tokens.
_amount
uint256
Amount of tokens to mint.
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:
_spender
address
Address from where to subtract the allowance.
_subtractedValue
uint256
The amount to subtract.
Return:
_success
bool
true
if operation was successful.
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:
_to
address
Recipient of delegated TWAB.
delegateWithSignature()
Allows a user to delegate via signature.
Parameters:
_user
address
The user who is delegating.
_delegate
address
The new delegate.
_deadline
uint256
The timestamp by which this must be submitted.
_v
uint8
The v
portion of the ECDSA sig.
_r
bytes32
The r
portion of the ECDSA sig.
_s
bytes32
The s
portion of the ECDSA sig.
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:
_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:
_user
address
The user for whom to fetch the TWAB context.
getAverageBalanceBetween()
Retrieves the average balance held by a user for a given time frame.
Parameters:
_user
address
The user whose balance is checked.
_startTime
uint64
The start time of the time frame.
_endTime
uint64
The end time of the time frame.
Return:
_balance
uint256
The average balance that the user held during the time frame.
getAverageBalancesBetween()
Retrieves the average balances held by a user for a given time frames.
Parameters:
_user
address
The user whose balances are checked.
_startTimes
uint64[]
The start time of the time frames.
_endTimes
uint64[]
The end time of the time frames.
Return:
_balances
uint256[]
The average balances that the user held during the time frame.
getAverageTotalSuppliesBetween()
Retrieves the average total supply balances for a set of given time frames.
Parameters:
_startTimes
uint64[]
Array of start times.
_endTimes
uint64[]
Array of end times.
Return:
_totalSupplies
uint256[]
The average total supplies held during the time frame.
getBalanceAt()
Retrieves the user's TWAB balance.
Parameters:
_user
address
Address of the user whose TWAB is being fetched.
_timestamp
uint64
Timestamp at which we want to retrieve the TWAB balance.
Return:
_balance
uint256
The TWAB balance at the given timestamp.
getBalancesAt()
Retrieves the userβs TWAB balances.
Parameters:
_user
address
Address of the user whose TWABs are being fetched.
_timestamps
uint64[]
Timestamps range at which we want to retrieve the TWAB balances.
Return:
_balances
uint256[]
The userβs TWAB balances.
getTotalSuppliesAt()
Retrieves the total supply TWAB balances between the given timestamps range.
Parameters:
_timestamps
uint64[]
Timestamps range at which we want to retrieve the total supply TWAB balances.
Return:
_balances
uint256[]
Total supply TWAB balances.
getTotalSupplyAt()
Retrieves the total supply TWAB balance at the given timestamp.
Parameters:
_timestamp
uint64
Timestamp at which we want to retrieve the total supply TWAB balance.
Return:
_balance
uint256
The total supply TWAB balance at the given timestamp.
getTwab()
Gets the TWAB at a specific index for a user.
Parameters:
_user
address
The user for whom to fetch the TWAB.
_index
uint16
The index of the TWAB to fetch.
Return:
_twab
TWAB
The TWAB, which includes the TWAB amount and the timestamp.
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.
Last updated