Skip to content

Latest commit

 

History

History
656 lines (433 loc) · 14.5 KB

File metadata and controls

656 lines (433 loc) · 14.5 KB

Solidity API

VotingEscrow

_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) -

token

contract IERC20 token

The token being locked

supply

uint256 supply

Total locked supply

DELEGATION_TYPEHASH

bytes32 DELEGATION_TYPEHASH

The EIP-712 typehash for the delegation struct used by the contract

nonces

mapping(address => uint256) nonces

A record of states for signing / validating signatures

VotesExpiredSignature

error VotesExpiredSignature(uint256 expiry)

OpenZeppelin v5 IVotes error

constructor

constructor(string _name, string _symbol, string version, contract IERC20 mainToken) public

Initializes the contract by setting a name, symbol, version and mainToken.

checkAuthorized

modifier checkAuthorized(uint256 _tokenId)

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool supported)

See {IERC165-supportsInterface}.

_beforeTokenTransfer

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.

lockDetails

mapping(uint256 => struct IVotingEscrow.LockDetails) lockDetails

maps the vesting data with tokenIds

totalNftsMinted

uint256 totalNftsMinted

tracker of current NFT id

_createLock

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

Parameters

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

createLock

function createLock(uint256 _value, uint256 _lockDuration, bool _permanent) external returns (uint256)

Creates a lock for the sender

Parameters

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

Return Values

Name Type Description
[0] uint256 The id of the newly created token

createLockFor

function createLockFor(uint256 _value, uint256 _lockDuration, address _to, bool _permanent) external returns (uint256)

Creates a lock for a specified address

Parameters

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

Return Values

Name Type Description
[0] uint256 The id of the newly created token

createDelegatedLockFor

function createDelegatedLockFor(uint256 _value, uint256 _lockDuration, address _to, address _delegatee, bool _permanent) external returns (uint256)

Creates a lock for a specified address

Parameters

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

Return Values

Name Type Description
[0] uint256 The id of the newly created token

globalCheckpoint

function globalCheckpoint() external

Updates the global checkpoint

checkpointDelegatee

function checkpointDelegatee(address _delegateeAddress) external

Updates the checkpoint for a delegatee

Parameters

Name Type Description
_delegateeAddress address The address of the delegatee

_updateLock

function _updateLock(uint256 _tokenId, uint256 _increasedValue, uint256 _unlockTime, struct IVotingEscrow.LockDetails _oldLocked, bool isPermanent) internal

Deposit & update lock tokens for a user

_The supply is increased by the value amount

Parameters

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

_checkpointLock

function _checkpointLock(uint256 _tokenId, struct IVotingEscrow.LockDetails _oldLocked, struct IVotingEscrow.LockDetails _newLocked) internal

Record global and per-user data to checkpoints. Used by VotingEscrow system.

Parameters

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

increaseAmount

function increaseAmount(uint256 _tokenId, uint256 _value) external

Deposit _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

Parameters

Name Type Description
_tokenId uint256 lock NFT
_value uint256 Amount to add to user's lock

increaseUnlockTime

function increaseUnlockTime(uint256 _tokenId, uint256 _lockDuration, bool _permanent) external

Increases the unlock time of a lock

Parameters

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

unlockPermanent

function unlockPermanent(uint256 _tokenId) external

Unlocks a permanent lock

Parameters

Name Type Description
_tokenId uint256 The id of the token to unlock

_claim

function _claim(uint256 _tokenId) internal

Claims the payout for a token

Parameters

Name Type Description
_tokenId uint256 The id of the token to claim the payout for

claim

function claim(uint256 _tokenId) external

Claims the payout for a token

Parameters

Name Type Description
_tokenId uint256 The id of the token to claim the payout for

merge

function merge(uint256 _from, uint256 _to) external

Merges two tokens together

Parameters

Name Type Description
_from uint256 The id of the token to merge from
_to uint256 The id of the token to merge to

split

function split(uint256[] _weights, uint256 _tokenId) external

Splits a token into multiple tokens

Parameters

Name Type Description
_weights uint256[] The percentages to split the token into
_tokenId uint256 The id of the token to split

balanceOfNFT

function balanceOfNFT(uint256 _tokenId) public view returns (uint256)

balanceOfNFTAt

function balanceOfNFTAt(uint256 _tokenId, uint256 _timestamp) external view returns (uint256)

totalSupply

function totalSupply() public view returns (uint256)

See {IERC721Enumerable-totalSupply}.

getVotes

function getVotes(address account) external view returns (uint256)

Gets the votes for a delegatee

Parameters

Name Type Description
account address The address of the delegatee

Return Values

Name Type Description
[0] uint256 The number of votes the delegatee has

getPastVotes

function getPastVotes(address account, uint256 timepoint) external view returns (uint256)

Gets the past votes for a delegatee at a specific time point

Parameters

Name Type Description
account address The address of the delegatee
timepoint uint256 The time point to get the votes at

Return Values

Name Type Description
[0] uint256 The number of votes the delegatee had at the time point

getPastTotalSupply

function getPastTotalSupply(uint256 _timePoint) external view returns (uint256)

Gets the total supply at a specific time point

Parameters

Name Type Description
_timePoint uint256 The time point to get the total supply at

Return Values

Name Type Description
[0] uint256 The total supply at the time point

delegate

function delegate(address delegatee) external

Delegates votes to a delegatee

Parameters

Name Type Description
delegatee address The account to delegate votes to

delegates

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.

Parameters

Name Type Description
account address The delegatee to get the delegate of

Return Values

Name Type Description
[0] address The delegate of the delegatee, or address(1) if multiple different delegates are found

delegate

function delegate(uint256 _tokenId, address delegatee) external

Delegates votes from a specific lock to a delegatee

Parameters

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

getLockDelegatee

function getLockDelegatee(uint256 tokenId) external view returns (address)

Gets the delegatee of a given lock

Parameters

Name Type Description
tokenId uint256 The ID of the lock token

Return Values

Name Type Description
[0] address The address of the delegatee for the specified token

getAccountDelegates

function getAccountDelegates(address account) external view returns (address[])

Gets all delegates of a delegatee

Parameters

Name Type Description
account address The delegatee to get the delegates of

Return Values

Name Type Description
[0] address[] An array of all delegates of the delegatee

getLockDelegateeAtTime

function getLockDelegateeAtTime(uint256 tokenId, uint48 timestamp) external view returns (address)

Public function to get the delegatee of a lock

Parameters

Name Type Description
tokenId uint256 The ID of the token
timestamp uint48 The timestamp to get the delegate at

Return Values

Name Type Description
[0] address The address of the delegate

delegateBySig

function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external

Delegates votes by signature

Parameters

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

_delegate

function _delegate(address delegator, address delegatee) internal

Delegates votes from an owner to an delegatee

Parameters

Name Type Description
delegator address The owner of the tokenId delegating votes
delegatee address The account to delegate votes to

ERC6372InconsistentClock

error ERC6372InconsistentClock()

The clock was incorrectly modified.

clock

function clock() public view virtual returns (uint48)

Clock used for flagging checkpoints.

Return Values

Name Type Description
[0] uint48 Current timestamp

CLOCK_MODE

function CLOCK_MODE() public view virtual returns (string)

Machine-readable description of the clock as specified in EIP-6372.

Return Values

Name Type Description
[0] string The clock mode

vestedPayoutAtTime

function vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) public view returns (uint256 payout)

See {ERC5725}.

_payoutToken

function _payoutToken(uint256) internal view returns (address)

See {ERC5725}.

_payout

function _payout(uint256 tokenId) internal view returns (uint256)

See {ERC5725}.

_startTime

function _startTime(uint256 tokenId) internal view returns (uint256)

See {ERC5725}.

_endTime

function _endTime(uint256 tokenId) internal view returns (uint256)

See {ERC5725}.