_This contract is used for locking tokens and voting.
- tokenIds always have a delegatee, with the owner being the default (see createLock)
- On transfers, delegation is reset. (See update) -
contract IERC20 tokenThe token being locked
uint256 supplyTotal locked supply
bytes32 DELEGATION_TYPEHASHThe EIP-712 typehash for the delegation struct used by the contract
mapping(address => uint256) noncesA record of states for signing / validating signatures
error VotesExpiredSignature(uint256 expiry)OpenZeppelin v5 IVotes error
constructor(string _name, string _symbol, string version, contract IERC20 mainToken) publicInitializes the contract by setting a name, symbol, version and mainToken.
modifier checkAuthorized(uint256 _tokenId)function supportsInterface(bytes4 interfaceId) public view virtual returns (bool supported)See {IERC165-supportsInterface}.
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual_See {IERC721-beforeTokenTransfer}.
Clears the approval of a given tokenId when the token is transferred or burned.
mapping(uint256 => struct IVotingEscrow.LockDetails) lockDetailsmaps the vesting data with tokenIds
uint256 totalNftsMintedtracker of current NFT id
function _createLock(uint256 value, uint256 duration, address to, address delegatee, bool permanent) internal virtual returns (uint256)Creates a new vesting NFT and mints it
Token amount should be approved to be transferred by this contract before executing create
| Name | Type | Description |
|---|---|---|
| value | uint256 | The total assets to be locked over time |
| duration | uint256 | Duration in seconds of the lock |
| to | address | The receiver of the lock |
| delegatee | address | |
| permanent | bool |
function createLock(uint256 _value, uint256 _lockDuration, bool _permanent) external returns (uint256)Creates a lock for the sender
| Name | Type | Description |
|---|---|---|
| _value | uint256 | The total assets to be locked over time |
| _lockDuration | uint256 | Duration in seconds of the lock |
| _permanent | bool | Whether the lock is permanent or not |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The id of the newly created token |
function createLockFor(uint256 _value, uint256 _lockDuration, address _to, bool _permanent) external returns (uint256)Creates a lock for a specified address
| Name | Type | Description |
|---|---|---|
| _value | uint256 | The total assets to be locked over time |
| _lockDuration | uint256 | Duration in seconds of the lock |
| _to | address | The receiver of the lock |
| _permanent | bool | Whether the lock is permanent or not |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The id of the newly created token |
function createDelegatedLockFor(uint256 _value, uint256 _lockDuration, address _to, address _delegatee, bool _permanent) external returns (uint256)Creates a lock for a specified address
| Name | Type | Description |
|---|---|---|
| _value | uint256 | The total assets to be locked over time |
| _lockDuration | uint256 | Duration in seconds of the lock |
| _to | address | The receiver of the lock |
| _delegatee | address | The receiver of the lock |
| _permanent | bool | Whether the lock is permanent or not |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The id of the newly created token |
function globalCheckpoint() externalUpdates the global checkpoint
function checkpointDelegatee(address _delegateeAddress) externalUpdates the checkpoint for a delegatee
| Name | Type | Description |
|---|---|---|
| _delegateeAddress | address | The address of the delegatee |
function _updateLock(uint256 _tokenId, uint256 _increasedValue, uint256 _unlockTime, struct IVotingEscrow.LockDetails _oldLocked, bool isPermanent) internalDeposit & update lock tokens for a user
_The supply is increased by the value amount
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | NFT that holds lock |
| _increasedValue | uint256 | Amount to deposit |
| _unlockTime | uint256 | New time when to unlock the tokens, or 0 if unchanged |
| _oldLocked | struct IVotingEscrow.LockDetails | Previous locked amount / timestamp |
| isPermanent | bool |
function _checkpointLock(uint256 _tokenId, struct IVotingEscrow.LockDetails _oldLocked, struct IVotingEscrow.LockDetails _newLocked) internalRecord global and per-user data to checkpoints. Used by VotingEscrow system.
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | NFT token ID. No user checkpoint if 0 |
| _oldLocked | struct IVotingEscrow.LockDetails | Previous locked amount / end lock time for the user |
| _newLocked | struct IVotingEscrow.LockDetails | New locked amount / end lock time for the user |
function increaseAmount(uint256 _tokenId, uint256 _value) externalDeposit _value tokens for _tokenId and add to the lock
Anyone (even a smart contract) can deposit for someone else, but cannot extend their locktime and deposit for a brand new user
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | lock NFT |
| _value | uint256 | Amount to add to user's lock |
function increaseUnlockTime(uint256 _tokenId, uint256 _lockDuration, bool _permanent) externalIncreases the unlock time of a lock
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | The id of the token to increase the unlock time for |
| _lockDuration | uint256 | The new duration of the lock |
| _permanent | bool | Whether the lock is permanent or not |
function unlockPermanent(uint256 _tokenId) externalUnlocks a permanent lock
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | The id of the token to unlock |
function _claim(uint256 _tokenId) internalClaims the payout for a token
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | The id of the token to claim the payout for |
function claim(uint256 _tokenId) externalClaims the payout for a token
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | The id of the token to claim the payout for |
function merge(uint256 _from, uint256 _to) externalMerges two tokens together
| Name | Type | Description |
|---|---|---|
| _from | uint256 | The id of the token to merge from |
| _to | uint256 | The id of the token to merge to |
function split(uint256[] _weights, uint256 _tokenId) externalSplits a token into multiple tokens
| Name | Type | Description |
|---|---|---|
| _weights | uint256[] | The percentages to split the token into |
| _tokenId | uint256 | The id of the token to split |
function balanceOfNFT(uint256 _tokenId) public view returns (uint256)function balanceOfNFTAt(uint256 _tokenId, uint256 _timestamp) external view returns (uint256)function totalSupply() public view returns (uint256)See {IERC721Enumerable-totalSupply}.
function getVotes(address account) external view returns (uint256)Gets the votes for a delegatee
| Name | Type | Description |
|---|---|---|
| account | address | The address of the delegatee |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The number of votes the delegatee has |
function getPastVotes(address account, uint256 timepoint) external view returns (uint256)Gets the past votes for a delegatee at a specific time point
| Name | Type | Description |
|---|---|---|
| account | address | The address of the delegatee |
| timepoint | uint256 | The time point to get the votes at |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The number of votes the delegatee had at the time point |
function getPastTotalSupply(uint256 _timePoint) external view returns (uint256)Gets the total supply at a specific time point
| Name | Type | Description |
|---|---|---|
| _timePoint | uint256 | The time point to get the total supply at |
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The total supply at the time point |
function delegate(address delegatee) externalDelegates votes to a delegatee
| Name | Type | Description |
|---|---|---|
| delegatee | address | The account to delegate votes to |
function delegates(address account) external view returns (address)Gets the delegate of a delegatee
This function implements IVotes interface. An account can have multiple delegates in this contract. If multiple different delegates are found, this function returns address(1) to indicate that there is not a single unique delegate.
| Name | Type | Description |
|---|---|---|
| account | address | The delegatee to get the delegate of |
| Name | Type | Description |
|---|---|---|
| [0] | address | The delegate of the delegatee, or address(1) if multiple different delegates are found |
function delegate(uint256 _tokenId, address delegatee) externalDelegates votes from a specific lock to a delegatee
| Name | Type | Description |
|---|---|---|
| _tokenId | uint256 | The ID of the lock token delegating the votes |
| delegatee | address | The address to which the votes are being delegated |
function getLockDelegatee(uint256 tokenId) external view returns (address)Gets the delegatee of a given lock
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 | The ID of the lock token |
| Name | Type | Description |
|---|---|---|
| [0] | address | The address of the delegatee for the specified token |
function getAccountDelegates(address account) external view returns (address[])Gets all delegates of a delegatee
| Name | Type | Description |
|---|---|---|
| account | address | The delegatee to get the delegates of |
| Name | Type | Description |
|---|---|---|
| [0] | address[] | An array of all delegates of the delegatee |
function getLockDelegateeAtTime(uint256 tokenId, uint48 timestamp) external view returns (address)Public function to get the delegatee of a lock
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 | The ID of the token |
| timestamp | uint48 | The timestamp to get the delegate at |
| Name | Type | Description |
|---|---|---|
| [0] | address | The address of the delegate |
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) externalDelegates votes by signature
| Name | Type | Description |
|---|---|---|
| delegatee | address | The delegatee to delegate votes to |
| nonce | uint256 | The nonce for the signature |
| expiry | uint256 | The expiry time for the signature |
| v | uint8 | The recovery byte of the signature |
| r | bytes32 | Half of the ECDSA signature pair |
| s | bytes32 | Half of the ECDSA signature pair |
function _delegate(address delegator, address delegatee) internalDelegates votes from an owner to an delegatee
| Name | Type | Description |
|---|---|---|
| delegator | address | The owner of the tokenId delegating votes |
| delegatee | address | The account to delegate votes to |
error ERC6372InconsistentClock()The clock was incorrectly modified.
function clock() public view virtual returns (uint48)Clock used for flagging checkpoints.
| Name | Type | Description |
|---|---|---|
| [0] | uint48 | Current timestamp |
function CLOCK_MODE() public view virtual returns (string)Machine-readable description of the clock as specified in EIP-6372.
| Name | Type | Description |
|---|---|---|
| [0] | string | The clock mode |
function vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) public view returns (uint256 payout)See {ERC5725}.
function _payoutToken(uint256) internal view returns (address)See {ERC5725}.
function _payout(uint256 tokenId) internal view returns (uint256)See {ERC5725}.
function _startTime(uint256 tokenId) internal view returns (uint256)See {ERC5725}.
function _endTime(uint256 tokenId) internal view returns (uint256)See {ERC5725}.