Skip to main content
Version: V5

TwabDelegator

Git Source

This contract allows accounts to easily delegate a portion of their Vault shares 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.

Events

TwabControllerSet

event TwabControllerSet(contract TwabController twabController)

Emitted when TwabController associated with this contract has been set.

Parameters

NameTypeDescription
twabControllercontract TwabControllerAddress of the TwabController

VaultSet

event VaultSet(contract Vault vault)

Emitted when Vault associated with this contract has been set.

Parameters

NameTypeDescription
vaultcontract VaultAddress of the Vault

VaultSharesStaked

event VaultSharesStaked(address delegator, uint256 amount)

Emitted when Vault shares have been staked.

Parameters

NameTypeDescription
delegatoraddressAddress of the delegator
amountuint256Amount of Vault shares shares staked

VaultSharesUnstaked

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

Emitted when Vault shares have been unstaked.

Parameters

NameTypeDescription
delegatoraddressAddress of the delegator
recipientaddressAddress of the recipient that will receive the Vault shares
amountuint256Amount of Vault shares 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 Vault shares 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 Vault shares 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 Vault shares has been withdrawn from a delegation.

The Vault shares are held by this contract and the delegator stake is increased.

Parameters

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

TransferredDelegation

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

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

Parameters

NameTypeDescription
delegatoraddressAddress of the delegator
slotuint256Slot of the delegation
amountuint256Amount of Vault shares withdrawn
toaddressRecipient address of withdrawn Vault shares

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

Variables

MAX_LOCK

uint256 MAX_LOCK

Max lock time during which a delegation cannot be updated.

Functions

constructor

constructor(string name_, string symbol_, contract TwabController twabController_, contract Vault vault_) public

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

Parameters

NameTypeDescription
name_stringThe name for the staked vault token
symbol_stringThe symbol for the staked vault token
twabController_contract TwabControllerAddress of the TwabController contract
vault_contract VaultAddress of the Vault contract

stake

function stake(address _to, uint256 _amount) external

Stake _amount of Vault shares in this contract.

Vault Shares can be staked on behalf of a _to user.

Parameters

NameTypeDescription
_toaddressAddress to which the stake will be attributed
_amountuint256Amount of Vault shares to stake

unstake

function unstake(address _to, uint256 _amount) external

Unstake _amount of Vault shares from this contract. Transfers Vault shares 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 Vault shares
_amountuint256Amount of Vault shares 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 Vault shares 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

NameTypeDescription
[0]contract DelegationReturns the address of the Delegation contract that will hold the Vault shares

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

NameTypeDescription
[0]contract DelegationThe address of the Delegation

fundDelegation

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

Fund a delegation by transferring Vault shares 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 Vault shares to transfer

Return Values

NameTypeDescription
[0]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 Vault shares to send to the delegation from the staked amount

Return Values

NameTypeDescription
[0]contract DelegationThe address of the Delegation

withdrawDelegationToStake

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

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

Only callable by the _delegator or a representative. Will send the Vault shares 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 Vault shares to withdraw

Return Values

NameTypeDescription
[0]contract DelegationThe address of the Delegation

transferDelegationTo

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

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

Vault Shares 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 Vault shares to

Return Values

NameTypeDescription
[0]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 view 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

NameTypeDescription
[0]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

NameTypeDescription
[0]bytes[]The results from each function call

permitAndMulticall

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

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

Parameters

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

getDelegation

function getDelegation(address _delegator, uint256 _slot) external view 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

NameTypeDescription
delegationcontract DelegationThe address that holds Vault shares for the delegation
delegateeaddressThe address that Vault shares are being delegated to
balanceuint256The balance of Vault shares in the delegation
lockUntiluint256The timestamp at which the delegation unlocks
wasCreatedboolWhether or not the delegation has been created

computeDelegationAddress

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

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

Parameters

NameTypeDescription
_delegatoraddressThe user who is delegating Vault shares
_slotuint256The delegation slot

Return Values

NameTypeDescription
[0]addressThe address of the delegation. This is the address that holds the balance of Vault shares.

decimals

function decimals() public view virtual returns (uint8)

Returns the ERC20 token decimals.

This value is equal to the decimals of the Vault shares being delegated.

Return Values

NameTypeDescription
[0]uint8ERC20 token decimals

twabController

function twabController() external view returns (address)

Returns the TwabController address.

Return Values

NameTypeDescription
[0]addressTwabController address

vault

function vault() external view returns (address)

Returns the Vault address.

Return Values

NameTypeDescription
[0]addressVault address

Structs

Errors