TokenTimelock

Git Source

Inherits: Patchable, StateAware, VotesDelegator, AdminControlled, MezzERC721Upgradeable, ITokenTimelock

Author: Daniel Yamagata & Naveen Ailawadi

This contract is used to vest a company's shares for a period of time. It is used by a company's Common Shares and Preferred Shares. The voting power of vesting shares can be delegated and used in governance

*Invariants:

  • _erc20Vesting[token] is always greater than or equal to _erc20Released[token]

  • _vestingScheduleByTokenId[tokenId].amount is always greater than or equal to _erc20ReleasedByTokenId[tokenId][shares]. This is inclusive of when the token's data is deleted upon vesting completion or when the vesting is canceled*

State Variables

TokenTimelockStorageLocation

bytes32 private constant TokenTimelockStorageLocation =
    0x35f985dfceb352faec794b4221331a49707dbeacf0ce328e288c0a3b67d6cb00;

Functions

_getTokenTimelockStorage

function _getTokenTimelockStorage() internal pure returns (TokenTimelockStorage storage $);

constructor

receive

The Token Timelock should not receive the native token used to pay for gas All native tokens transferred to this contract will be locked forever and effectively burned

init

Initializes the token timelock contract

Parameters

Name
Type
Description

initTreasury

address

The address of the treasury contract

__TokenTimelock_Init

treasury

Returns the address of the treasury, whose signers are the company's board of directors

vestShares

Vest shares for a recipient according to a vesting schedule. Vesting is cancellable by the board or a set of admins determined by the board depending on if it is obligatory

'data.shares' must be tracked by the treasury, otherwise the function call will revert. This function uses an ERC721 safe transfer, which is susceptible to reentrancy. It follows the CEI pattern accordingly. There is no validation of 'data.startDate' being in the past. It is the responsibility of the caller to ensure its validity. If the start date is in the past farther than 'data.duration', the shares will be instantly vested. The max start date is two years into the future, at which point the shares will begin to vest

Parameters

Name
Type
Description

data

DataTypes.VestingData

The vesting data as a DataTypes.VestingData struct

Returns

Name
Type
Description

<none>

uint256

The token ID for the vesting shares

release

Releases vested tokens to the owner of an ERC721. Can be called by anyone

This function is not access controlled. Any account can release vested shares for any token ID Vested shares are transferred to the owner of the token

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token to release vested shares for

Returns

Name
Type
Description

<none>

uint256

The amount of shares that were released

cancelVestingAtTimepoint

Cache and Validate

This function is primarily used by the Payroll Manager when an employee resigns at a timepoint

Returns

Name
Type
Description

<none>

uint256

The amount of canceled shares

cancelVesting

Cancels the vesting for a given token. Releases any vested shares and burns the remaining amount allocated to the token.

This function will revert if the caller is not the token owner nor an admin. If the caller is an admin, this function will revert if the token is obligatory

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token to cancel the vesting for

Returns

Name
Type
Description

<none>

uint256

Returns two arguments. The first is the amount of shares that were released. The second is the amount of shares that were cancelled and burned

<none>

uint256

_cancelVesting

_handleCanceledShares

If the owner is the payroll manager, transfer the vesting shares back to the treasury Otherwise, burn the shares. This is done to prevent the treasury from having to re-authorize and re-issue shares that were allocated to employees but subsequently canceled

extendVestingDuration

Extends the vesting duration for the given 'tokenId'. Only callable by the token owner

This function will revert if the token does not exist

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token to extend the vesting duration for

durationExtension

uint256

The amount of time to extend the vesting duration by

Returns

Name
Type
Description

<none>

uint32

The new vesting duration

extendVestingAmount

Increases the vesting amount for 'tokenId' by 'equityExtension'

This function is not access controlled. It is callable by anyone This function will revert if the token does not exist

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token to increase the vesting amount for

equityExtension

uint256

The amount to increase the vesting amount by

Returns

Name
Type
Description

<none>

uint256

The new vesting amount

updateDelegate

Updates the delegate of 'delegator' from 'fromDelegate' to 'toDelegate'. Only callable by the Delegate Registry

isObligatory

Returns whether or not a given token is obligatory

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token

Returns

Name
Type
Description

<none>

bool

Whether or not the token is obligatory

wasCanceled

Returns true if the token was canceled, false otherwise

hasCompleted

Returns true if the token has completed its vesting, false otherwise

exists

Returns true if the token exists, false otherwise

getVestingSchedule

Returns the vesting schedule for the given token

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token

Returns

Name
Type
Description

<none>

DataTypes.VestingSchedule

The vesting schedule as a DataTypes.VestingSchedule struct

getRemainingVestingAmount

Returns the remaining vesting amount for the given token

The remaining vesting amount refers to the difference between the shares attributed to the vesting schedule and how much has been released

getVestingEndDate

Returns the Unix-timestamp in seconds at which the vesting schedule will complete

released

Returns the amount of shares that have been released for a given token

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token

Returns

Name
Type
Description

<none>

uint256

The amount of shares that have been released for the token

releasable

Returns the amount of shares that are releasable for a given token. 'Releasable' refers to the amount of shares that have vested and have not yet been released

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token

Returns

Name
Type
Description

<none>

uint256

The amount of shares that are releasable for the token

getVotesByShareClass

Returns the current number of voting units for 'account' based on 'shares'

The return value does not adjust for the voting weight of 'shares'

getPastVotesByShareClass

Returns the voting units for 'account' based on 'shares' at the given 'timepoint'

The return value does not adjust for the voting weight of 'shares'. This function will revert if 'timepoint' is in the present or the future

getERC20VestingByAccount

Returns the current amount of 'shares' that are vesting for 'account'

getCumulativeERC20Vesting

Returns the cumlative amount of shares that are vesting or have been vested in the token timelock

Parameters

Name
Type
Description

shares

address

The address of the shares contract

Returns

Name
Type
Description

<none>

uint256

The amount of shares that are vesting or have been vested in the token timelock

getCumulativeERC20Released

Returns the cumlative amount of shares that have been released from the token timelock

Parameters

Name
Type
Description

shares

address

The address of the shares contract

Returns

Name
Type
Description

<none>

uint256

The amount of shares that have been released from the token timelock

name

Returns the name of the token timelock

symbol

Returns the symbol of the token timelock

coreId

Returns the coreId of the implementation as a bytes32

The core ID is the keccak256 hash of the contract name followed by a version under the following syntax: "mezzanine.coreId.ContractName.vX" For example, the core ID of the 2nd version of the Treasury would be the following: keccak256(abi.encodePacked("mezzanine.coreId.Treasury.v2"))

version

Returns the version of the implementation as a uint256

_release

Releases the '_releasableAmount' of vested shares to the owner of the token 'Releasable' refers to the amount vested minus the amount already released

Parameters

Name
Type
Description

tokenId

uint256

The token ID to release tokens for

shares

address

The address of the shares that are being released and correspond to the given token

_releasableAmount

uint256

The amount of tokens that are releasable

_releasable

Returns the amount of tokens that are 'releasable' for a given token 'Releasable' refers to the amount vested minus the amount already released

Parameters

Name
Type
Description

tokenId

uint256

The token ID

Returns

Name
Type
Description

<none>

uint256

The amount of tokens that are releasable

_vestedAmount

Calculates the vested amount of shares for a given vesting schedule. Does not check the released amount of shares Precision loss is possible, but extremely unlikely since shares will always have 18 decimals

Parameters

Name
Type
Description

vestingScheduleCache

DataTypes.VestingSchedule

The vesting schedule to calculate the vested amount for

Returns

Name
Type
Description

<none>

uint256

The vested amount of shares

_burnTokenAndDeleteData

Burn a token with 'tokenId' and deletes it corresponding data in storage

Parameters

Name
Type
Description

tokenId

uint256

The ID of the token to burn

_shares

address

The address of the shares that correspond to the given token

_validateCallerIsOwnerOrAdminAndNonObligatory

*Reverts if:

  • The caller is not the token owner or an admin

  • If the caller is an admin and the token is obligatory*

_checkInvariants

Asserts that the invariants hold true. Panics otherwise

Parameters

Name
Type
Description

tokenId

uint256

The token ID to check the invariants for

_update

Overridden updated from '_ERC721Upgradeable' such that the voting units of a delegate is updated on token transfer, including burning

Returns

Name
Type
Description

<none>

address

The owner of 'tokenId'

_transferVotingUnits

Transfers the voting units of 'shares' from the delegatee of 'from' to the delegatee of 'to'

_moveDelegateVotes

Moves delegated votes of 'shares' from one delegate to another

_push

_add

_subtract

supportsInterface

ERC165 support

upgradeToNewerVersion

Upgrades 'this' to a newer version via the Mezz Migrator. Only callable by the Treasury, whose signers are the board of directors

Will revert if the protocol state is 'Paused' or 'Frozen'

Parameters

Name
Type
Description

newVersion

uint256

The new version to upgrade to

data

bytes

The data to be passed to the new implementation, which likely should be a reinitializer function if used

_authorizePatch

Access control for 'resetToPatchedLatestVersion()'

Structs

TokenTimelockStorage

Last updated