Skip to main content

TWABDelegator

This contract allows accounts to easily delegate a portion of their tickets to multiple delegatees. The delegatees chance of winning prizes is increased by the delegated amount. If a delegator doesn't want to actively manage the delegations, then they can stake on the contract and appoint representatives.

Structs

Signature

  • uint256 deadline
  • uint8 v
  • bytes32 r
  • bytes32 s

Functions

constructor

  function constructor(
string name_,
string symbol_,
contract ITicket _ticket
) public

Creates a new TWAB Delegator that is bound to the given ticket contract.

Parameters:

NameTypeDescription
name_stringThe name for the staked ticket token
symbol_stringThe symbol for the staked ticket token
_ticketcontract ITicketAddress of the ticket contract

stake

  function stake(
address _to,
uint256 _amount
) external

Stake _amount of tickets in this contract.

Tickets can be staked on behalf of a _to user.

Parameters:

NameTypeDescription
_toaddressAddress to which the stake will be attributed
_amountuint256Amount of tickets to stake

unstake

  function unstake(
address _to,
uint256 _amount
) external

Unstake _amount of tickets from this contract. Transfers ticket to the passed _to address.

If delegator has delegated his whole stake, he will first have to withdraw from a delegation to be able to unstake.

Parameters:

NameTypeDescription
_toaddressAddress of the recipient that will receive the tickets
_amountuint256Amount of tickets to unstake

createDelegation

  function createDelegation(
address _delegator,
uint256 _slot,
address _delegatee,
uint96 _lockDuration
) external returns (contract Delegation)

Creates a new delegation. This will create a new Delegation contract for the given slot and have it delegate its tickets to the given delegatee. If a non-zero lock duration is passed, then the delegatee cannot be changed, nor funding withdrawn, until the lock has expired.

The _delegator and _slot params are used to compute the salt of the delegation

Parameters:

NameTypeDescription
_delegatoraddressAddress of the delegator that will be able to handle the delegation
_slotuint256Slot of the delegation
_delegateeaddressAddress of the delegatee
_lockDurationuint96Duration of time for which the delegation is locked. Must be less than the max duration.

Return Values:

TypeDescription
contract DelegationReturns the address of the Delegation contract that will hold the tickets

updateDelegatee

  function updateDelegatee(
address _delegator,
uint256 _slot,
address _delegatee,
uint96 _lockDuration
) external returns (contract Delegation)

Updates the delegatee and lock duration for a delegation slot.

Only callable by the _delegator or their representative. Will revert if delegation is still locked.

Parameters:

NameTypeDescription
_delegatoraddressAddress of the delegator
_slotuint256Slot of the delegation
_delegateeaddressAddress of the delegatee
_lockDurationuint96Duration of time during which the delegatee cannot be changed nor withdrawn

Return Values:

TypeDescription
contract DelegationThe address of the Delegation

fundDelegation

  function fundDelegation(
address _delegator,
uint256 _slot,
uint256 _amount
) external returns (contract Delegation)

Fund a delegation by transferring tickets from the caller to the delegation.

Callable by anyone. Will revert if delegation does not exist.

Parameters:

NameTypeDescription
_delegatoraddressAddress of the delegator
_slotuint256Slot of the delegation
_amountuint256Amount of tickets to transfer

Return Values:

TypeDescription
contract DelegationThe address of the Delegation

fundDelegationFromStake

  function fundDelegationFromStake(
address _delegator,
uint256 _slot,
uint256 _amount
) external returns (contract Delegation)

Fund a delegation using the _delegator stake.

Callable only by the _delegator or a representative. Will revert if delegation does not exist. Will revert if _amount is greater than the staked amount.

Parameters:

NameTypeDescription
_delegatoraddressAddress of the delegator
_slotuint256Slot of the delegation
_amountuint256Amount of tickets to send to the delegation from the staked amount

Return Values:

TypeDescription
contract DelegationThe address of the Delegation

withdrawDelegationToStake

  function withdrawDelegationToStake(
address _delegator,
uint256 _slot,
uint256 _amount
) external returns (contract Delegation)

Withdraw tickets from a delegation. The tickets will be held by this contract and the delegator's stake will increase.

Only callable by the _delegator or a representative. Will send the tickets to this contract and increase the _delegator staked amount. Will revert if delegation is still locked.

Parameters:

NameTypeDescription
_delegatoraddressAddress of the delegator
_slotuint256Slot of the delegation
_amountuint256Amount of tickets to withdraw

Return Values:

TypeDescription
contract DelegationThe address of the Delegation

transferDelegationTo

  function transferDelegationTo(
uint256 _slot,
uint256 _amount,
address _to
) external returns (contract Delegation)

Withdraw an _amount of tickets from a delegation. The delegator is assumed to be the caller.

Tickets are sent directly to the passed _to address. Will revert if delegation is still locked.

Parameters:

NameTypeDescription
_slotuint256Slot of the delegation
_amountuint256Amount to withdraw
_toaddressAccount to transfer the withdrawn tickets to

Return Values:

TypeDescription
contract DelegationThe address of the Delegation

setRepresentative

  function setRepresentative(
address _representative,
bool _set
) external

Allow an account to set or unset a _representative to handle delegation.

If _set is true, _representative will be set as representative of msg.sender. If _set is false, _representative will be unset as representative of msg.sender.

Parameters:

NameTypeDescription
_representativeaddressAddress of the representative
_setboolSet or unset the representative

isRepresentativeOf

  function isRepresentativeOf(
address _delegator,
address _representative
) external returns (bool)

Returns whether or not the given rep is a representative of the delegator.

Parameters:

NameTypeDescription
_delegatoraddressThe delegator
_representativeaddressThe representative to check for

Return Values:

TypeDescription
boolTrue if the rep is a rep, false otherwise

multicall

  function multicall(
bytes[] _data
) external returns (bytes[])

Allows a user to call multiple functions on the same contract. Useful for EOA who wants to batch transactions.

Parameters:

NameTypeDescription
_databytes[]An array of encoded function calls. The calls must be abi-encoded calls to this contract.

Return Values:

TypeDescription
bytes[]The results from each function call

permitAndMulticall

  function permitAndMulticall(
uint256 _amount,
struct PermitAndMulticall.Signature _permitSignature,
bytes[] _data
) external

Alow a user to approve ticket and run various calls in one transaction.

Parameters:

NameTypeDescription
_amountuint256Amount of tickets to approve
_permitSignaturestruct PermitAndMulticall.SignaturePermit signature
_databytes[]Datas to call with functionDelegateCall

getDelegation

  function getDelegation(
address _delegator,
uint256 _slot
) external returns (contract Delegation delegation, address delegatee, uint256 balance, uint256 lockUntil, bool wasCreated)

Allows the caller to easily get the details for a delegation.

Parameters:

NameTypeDescription
_delegatoraddressThe delegator address
_slotuint256The delegation slot they are using

Return Values:

TypeDescription
contract Delegationdelegation The address that holds tickets for the delegation
addressdelegatee The address that tickets are being delegated to
uint256balance The balance of tickets in the delegation
uint256lockUntil The timestamp at which the delegation unlocks
boolwasCreated Whether or not the delegation has been created

computeDelegationAddress

  function computeDelegationAddress(
address _delegator,
uint256 _slot
) external returns (address)

Computes the address of the delegation for the delegator + slot combination.

Parameters:

NameTypeDescription
_delegatoraddressThe user who is delegating tickets
_slotuint256The delegation slot

Return Values:

TypeDescription
addressThe address of the delegation. This is the address that holds the balance of tickets.

decimals

  function decimals(
) public returns (uint8)

Returns the ERC20 token decimals.

This value is equal to the decimals of the ticket being delegated.

Return Values:

TypeDescription
uint8ERC20 token decimals

name

  function name(
) public returns (string)

Returns the name of the token.

symbol

  function symbol(
) public returns (string)

Returns the symbol of the token, usually a shorter version of the name.

totalSupply

  function totalSupply(
) public returns (uint256)

See {IERC20-totalSupply}.

balanceOf

  function balanceOf(
) public returns (uint256)

See {IERC20-balanceOf}.

transfer

  function transfer(
) public returns (bool)

See {IERC20-transfer}. Requirements:

  • to cannot be the zero address.
  • the caller must have a balance of at least amount.

allowance

  function allowance(
) public returns (uint256)

See {IERC20-allowance}.

approve

  function approve(
) public returns (bool)

See {IERC20-approve}. NOTE: If amount is the maximum uint256, the allowance is not updated on transferFrom. This is semantically equivalent to an infinite approval. Requirements:

  • spender cannot be the zero address.

transferFrom

  function transferFrom(
) public returns (bool)

See {IERC20-transferFrom}. Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {ERC20}. NOTE: Does not update the allowance if the current allowance is the maximum uint256. Requirements:

  • from and to cannot be the zero address.
  • from must have a balance of at least amount.
  • the caller must have allowance for from's tokens of at least amount.

increaseAllowance

  function increaseAllowance(
) public returns (bool)

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}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • spender cannot be the zero address.

decreaseAllowance

  function decreaseAllowance(
) public returns (bool)

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}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • spender cannot be the zero address.
  • spender must have allowance for the caller of at least subtractedValue.

Events

TicketSet

  event TicketSet(
contract ITicket ticket
)

Emitted when ticket associated with this contract has been set.

Parameters:

NameTypeDescription
ticketcontract ITicketAddress of the ticket

TicketsStaked

  event TicketsStaked(
address delegator,
uint256 amount
)

Emitted when tickets have been staked.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
amountuint256Amount of tickets staked

TicketsUnstaked

  event TicketsUnstaked(
address delegator,
address recipient,
uint256 amount
)

Emitted when tickets have been unstaked.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
recipientaddressAddress of the recipient that will receive the tickets
amountuint256Amount of tickets unstaked

DelegationCreated

  event DelegationCreated(
address delegator,
uint256 slot,
uint96 lockUntil,
address delegatee,
contract Delegation delegation,
address user
)

Emitted when a new delegation is created.

Parameters:

NameTypeDescription
delegatoraddressDelegator of the delegation
slotuint256Slot of the delegation
lockUntiluint96Timestamp until which the delegation is locked
delegateeaddressAddress of the delegatee
delegationcontract DelegationAddress of the delegation that was created
useraddressAddress of the user who created the delegation

DelegateeUpdated

  event DelegateeUpdated(
address delegator,
uint256 slot,
address delegatee,
uint96 lockUntil,
address user
)

Emitted when a delegatee is updated.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
delegateeaddressAddress of the delegatee
lockUntiluint96Timestamp until which the delegation is locked
useraddressAddress of the user who updated the delegatee

DelegationFunded

  event DelegationFunded(
address delegator,
uint256 slot,
uint256 amount,
address user
)

Emitted when a delegation is funded.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
amountuint256Amount of tickets that were sent to the delegation
useraddressAddress of the user who funded the delegation

DelegationFundedFromStake

  event DelegationFundedFromStake(
address delegator,
uint256 slot,
uint256 amount,
address user
)

Emitted when a delegation is funded from the staked amount.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
amountuint256Amount of tickets that were sent to the delegation
useraddressAddress of the user who pulled funds from the delegator stake to the delegation

WithdrewDelegationToStake

  event WithdrewDelegationToStake(
address delegator,
uint256 slot,
uint256 amount,
address user
)

Emitted when an amount of tickets has been withdrawn from a delegation. The tickets are held by this contract and the delegator stake is increased.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
amountuint256Amount of tickets withdrawn
useraddressAddress of the user who withdrew the tickets

TransferredDelegation

  event TransferredDelegation(
address delegator,
uint256 slot,
uint256 amount,
address to
)

Emitted when a delegator withdraws an amount of tickets from a delegation to a specified wallet.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
amountuint256Amount of tickets withdrawn
toaddressRecipient address of withdrawn tickets

RepresentativeSet

  event RepresentativeSet(
address delegator,
address representative,
bool set
)

Emitted when a representative is set.

Parameters:

NameTypeDescription
delegatoraddressAddress of the delegator
representativeaddressAddress of the representative
setboolBoolean indicating if the representative was set or unset

Transfer

  event Transfer(
)

Emitted when value tokens are moved from one account (from) to another (to). Note that value may be zero.

Approval

  event Approval(
)

Emitted when the allowance of a spender for an owner is set by a call to {approve}. value is the new allowance.