IVotingEscrow
Inherits: IVotes, IERC4906, IERC6372, IERC721Metadata
Functions
token
Address of token (IR) used to create a veNFT
function token() external view returns (address);
distributor
Address of RewardsDistributor.sol
function distributor() external view returns (address);
voter
Address of Voter.sol
function voter() external view returns (address);
artProxy
Address of art proxy used for on-chain art generation
function artProxy() external view returns (address);
allowedManager
address which can create managed NFTs
function allowedManager() external view returns (address);
tokenId
Current count of token
function tokenId() external view returns (uint256);
infrared
Address of Infrared contract
function infrared() external view returns (IInfraredUpgradeable);
Returns
| Name | Type | Description |
|---|---|---|
<none> | IInfraredUpgradeable | IInfrared instance of contract address |
escrowType
Mapping of token id to escrow type Takes advantage of the fact default value is EscrowType.NORMAL
function escrowType(uint256 tokenId) external view returns (EscrowType);
idToManaged
Mapping of token id to managed id
function idToManaged(uint256 tokenId)
external
view
returns (uint256 managedTokenId);
weights
Mapping of user token id to managed token id to weight of token id
function weights(uint256 tokenId, uint256 managedTokenId)
external
view
returns (uint256 weight);
deactivated
Mapping of managed id to deactivated state
function deactivated(uint256 tokenId) external view returns (bool inactive);
createManagedLockFor
Create managed NFT (a permanent lock) for use within ecosystem.
Throws if address already owns a managed NFT.
function createManagedLockFor(address _to)
external
returns (uint256 _mTokenId);
Returns
| Name | Type | Description |
|---|---|---|
_mTokenId | uint256 | managed token id. |
depositManaged
Delegates balance to managed nft Note that NFTs deposited into a managed NFT will be re-locked to the maximum lock time on withdrawal. Permanent locks that are deposited will automatically unlock.
Managed nft will remain max-locked as long as there is at least one deposit or withdrawal per week. Throws if deposit nft is managed. Throws if recipient nft is not managed. Throws if deposit nft is already locked. Throws if not called by voter.
function depositManaged(uint256 _tokenId, uint256 _mTokenId) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | tokenId of NFT being deposited |
_mTokenId | uint256 | tokenId of managed NFT that will receive the deposit |
withdrawManaged
Retrieves locked rewards and withdraws balance from managed nft. Note that the NFT withdrawn is re-locked to the maximum lock time.
Throws if NFT not locked. Throws if not called by voter.
function withdrawManaged(uint256 _tokenId) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | tokenId of NFT being deposited. |
setAllowedManager
Permit one address to call createManagedLockFor() that is not Voter.governor()
function setAllowedManager(address _allowedManager) external;
setManagedState
Set Managed NFT state. Inactive NFTs cannot be deposited into.
function setManagedState(uint256 _mTokenId, bool _state) external;
Parameters
| Name | Type | Description |
|---|---|---|
_mTokenId | uint256 | managed nft state to set |
_state | bool | true => inactive, false => active |
name
function name() external view returns (string memory);
symbol
function symbol() external view returns (string memory);
version
function version() external view returns (string memory);
decimals
function decimals() external view returns (uint8);
setArtProxy
function setArtProxy(address _proxy) external;
tokenURI
Returns the Uniform Resource Identifier (URI) for tokenId token.
function tokenURI(uint256 tokenId) external view returns (string memory);
ownerToNFTokenIdList
Mapping from owner address to mapping of index to tokenId
function ownerToNFTokenIdList(address _owner, uint256 _index)
external
view
returns (uint256 _tokenId);
ownerOf
Returns the owner of the tokenId token.
Requirements:
tokenIdmust exist.
function ownerOf(uint256 tokenId) external view returns (address owner);
balanceOf
Returns the number of tokens in owner's account.
function balanceOf(address owner) external view returns (uint256 balance);
getApproved
Returns the account approved for tokenId token.
Requirements:
tokenIdmust exist.
function getApproved(uint256 _tokenId)
external
view
returns (address operator);
isApprovedForAll
Returns if the operator is allowed to manage all of the assets of owner.
See {setApprovalForAll}
function isApprovedForAll(address owner, address operator)
external
view
returns (bool);
isApprovedOrOwner
Check whether spender is owner or an approved user for a given veNFT
function isApprovedOrOwner(address _spender, uint256 _tokenId)
external
returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
_spender | address | . |
_tokenId | uint256 | . |
approve
Gives permission to to to transfer tokenId token to another account.
The approval is cleared when the token is transferred.
Only a single account can be approved at a time, so approving the zero address clears previous approvals.
Requirements:
- The caller must own the token or be an approved operator.
tokenIdmust exist. Emits an {Approval} event.
function approve(address to, uint256 tokenId) external;
setApprovalForAll
Approve or remove operator as an operator for the caller.
Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
Requirements:
- The
operatorcannot be the address zero. Emits an {ApprovalForAll} event.
function setApprovalForAll(address operator, bool approved) external;
transferFrom
Transfers tokenId token from from to to.
WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
understand this adds an external call which potentially creates a reentrancy vulnerability.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must be owned byfrom.- If the caller is not
from, it must be approved to move this token by either {approve} or {setApprovalForAll}. Emits a {Transfer} event.
function transferFrom(address from, address to, uint256 tokenId) external;
safeTransferFrom
Safely transfers tokenId token from from to to, checking first that contract recipients
are aware of the ERC-721 protocol to prevent tokens from being forever locked.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. - If
torefers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event.
function safeTransferFrom(address from, address to, uint256 tokenId)
external;
safeTransferFrom
Safely transfers tokenId token from from to to.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must be approved to move this token by either {approve} or {setApprovalForAll}. - If
torefers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event.
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
supportsInterface
Returns true if this contract implements the interface defined by
interfaceId. See the corresponding
https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
to learn more about how these ids are created.
This function call must use less than 30 000 gas.
function supportsInterface(bytes4 _interfaceID) external view returns (bool);
epoch
Total count of epochs witnessed since contract creation
function epoch() external view returns (uint256);
supply
Total amount of token() deposited
function supply() external view returns (uint256);
permanentLockBalance
Aggregate permanent locked balances
function permanentLockBalance() external view returns (uint256);
userPointEpoch
function userPointEpoch(uint256 _tokenId)
external
view
returns (uint256 _epoch);
slopeChanges
time -> signed slope change
function slopeChanges(uint256 _timestamp) external view returns (int128);
canSplit
account -> can split
function canSplit(address _account) external view returns (bool);
pointHistory
Global point history at a given index
function pointHistory(uint256 _loc)
external
view
returns (GlobalPoint memory);
locked
Get the LockedBalance (amount, end) of a _tokenId
function locked(uint256 _tokenId)
external
view
returns (LockedBalance memory);
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | . |
Returns
| Name | Type | Description |
|---|---|---|
<none> | LockedBalance | LockedBalance of _tokenId |
userPointHistory
User -> UserPoint[userEpoch]
function userPointHistory(uint256 _tokenId, uint256 _loc)
external
view
returns (UserPoint memory);
checkpoint
Record global data to checkpoint
function checkpoint() external;
depositFor
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
function depositFor(uint256 _tokenId, uint256 _value) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | lock NFT |
_value | uint256 | Amount to add to user's lock |
createLock
Deposit _value tokens for msg.sender and lock for _lockDuration
function createLock(uint256 _value, uint256 _lockDuration)
external
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
_value | uint256 | Amount to deposit |
_lockDuration | uint256 | Number of seconds to lock tokens for (rounded down to nearest week) |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | TokenId of created veNFT |
createLockFor
Deposit _value tokens for _to and lock for _lockDuration
function createLockFor(uint256 _value, uint256 _lockDuration, address _to)
external
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
_value | uint256 | Amount to deposit |
_lockDuration | uint256 | Number of seconds to lock tokens for (rounded down to nearest week) |
_to | address | Address to deposit |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | TokenId of created veNFT |
increaseAmount
Deposit _value additional tokens for _tokenId without modifying the unlock time
function increaseAmount(uint256 _tokenId, uint256 _value) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | |
_value | uint256 | Amount of tokens to deposit and add to the lock |
increaseUnlockTime
Extend the unlock time for _tokenId
Cannot extend lock time of permanent locks
function increaseUnlockTime(uint256 _tokenId, uint256 _lockDuration)
external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | |
_lockDuration | uint256 | New number of seconds until tokens unlock |
withdraw
Withdraw all tokens for _tokenId
Only possible if the lock is both expired and not permanent This will burn the veNFT. Any rebases or rewards that are unclaimed will no longer be claimable. Claim all rebases and rewards prior to calling this.
function withdraw(uint256 _tokenId) external;
merge
Merges _from into _to.
Cannot merge _from locks that are permanent or have already voted this epoch.
Cannot merge _to locks that have already expired.
This will burn the veNFT. Any rebases or rewards that are unclaimed
will no longer be claimable. Claim all rebases and rewards prior to calling this.
function merge(uint256 _from, uint256 _to) external;
Parameters
| Name | Type | Description |
|---|---|---|
_from | uint256 | VeNFT to merge from. |
_to | uint256 | VeNFT to merge into. |
split
Splits veNFT into two new veNFTS - one with oldLocked.amount - _amount, and the second with _amount
This burns the tokenId of the target veNFT
Callable by approved or owner
If this is called by approved, approved will not have permissions to manipulate the newly created veNFTs
Returns the two new split veNFTs to owner
If from is permanent, will automatically dedelegate.
This will burn the veNFT. Any rebases or rewards that are unclaimed
will no longer be claimable. Claim all rebases and rewards prior to calling this.
function split(uint256 _from, uint256 _amount)
external
returns (uint256 _tokenId1, uint256 _tokenId2);
Parameters
| Name | Type | Description |
|---|---|---|
_from | uint256 | VeNFT to split. |
_amount | uint256 | Amount to split from veNFT. |
Returns
| Name | Type | Description |
|---|---|---|
_tokenId1 | uint256 | Return tokenId of veNFT with oldLocked.amount - _amount. |
_tokenId2 | uint256 | Return tokenId of veNFT with _amount. |
toggleSplit
Toggle split for a specific address.
Toggle split for address(0) to enable or disable for all.
function toggleSplit(address _account, bool _bool) external;
Parameters
| Name | Type | Description |
|---|---|---|
_account | address | Address to toggle split permissions |
_bool | bool | True to allow, false to disallow |
lockPermanent
Permanently lock a veNFT. Voting power will be equal to
LockedBalance.amount with no decay. Required to delegate.
Only callable by unlocked normal veNFTs.
function lockPermanent(uint256 _tokenId) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | tokenId to lock. |
unlockPermanent
Unlock a permanently locked veNFT. Voting power will decay. Will automatically dedelegate if delegated.
Only callable by permanently locked veNFTs. Cannot unlock if already voted this epoch.
function unlockPermanent(uint256 _tokenId) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | tokenId to unlock. |
balanceOfNFT
Get the voting power for _tokenId at the current timestamp
Returns 0 if called in the same block as a transfer.
function balanceOfNFT(uint256 _tokenId) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | . |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Voting power |
balanceOfNFTAt
Get the voting power for _tokenId at a given timestamp
function balanceOfNFTAt(uint256 _tokenId, uint256 _t)
external
view
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | . |
_t | uint256 | Timestamp to query voting power |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Voting power |
totalSupply
Calculate total voting power at current timestamp
function totalSupply() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Total voting power at current timestamp |
totalSupplyAt
Calculate total voting power at a given timestamp
function totalSupplyAt(uint256 _t) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
_t | uint256 | Timestamp to query total voting power |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Total voting power at given timestamp |
voted
See if a queried _tokenId has actively voted
function voted(uint256 _tokenId) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | . |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | True if voted, else false |
setVoterAndDistributor
Set the global state voter and distributor
This is only called once, at setup
function setVoterAndDistributor(address _voter, address _distributor)
external;
voting
Set voted for _tokenId to true or false
Only callable by voter
function voting(uint256 _tokenId, bool _voted) external;
Parameters
| Name | Type | Description |
|---|---|---|
_tokenId | uint256 | . |
_voted | bool | . |
numCheckpoints
The number of checkpoints for each tokenId
function numCheckpoints(uint256 tokenId) external view returns (uint48);
nonces
A record of states for signing / validating signatures
function nonces(address account) external view returns (uint256);
delegates
Returns the delegate that tokenId has chosen. Can never be equal to the delegator's tokenId.
Returns 0 if not delegated.
function delegates(uint256 delegator) external view returns (uint256);
checkpoints
A record of delegated token checkpoints for each account, by index
function checkpoints(uint256 tokenId, uint48 index)
external
view
returns (Checkpoint memory);
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | . |
index | uint48 | . |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Checkpoint | Checkpoint |
getPastVotes
Returns the amount of votes that tokenId had at a specific moment in the past.
If the account passed in is not the owner, returns 0.
function getPastVotes(address account, uint256 tokenId, uint256 timestamp)
external
view
returns (uint256);
getPastTotalSupply
Returns the total supply of votes available at a specific moment in the past. If the clock() is
configured to use block numbers, this will return the value the end of the corresponding block.
NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
Votes that have not been delegated are still part of total supply, even though they would not participate in a
vote.
function getPastTotalSupply(uint256 timestamp)
external
view
returns (uint256);
delegate
Delegates votes from the sender to delegatee.
function delegate(uint256 delegator, uint256 delegatee) external;
delegateBySig
Delegates votes from delegator to delegatee. Signer must own delegator.
function delegateBySig(
uint256 delegator,
uint256 delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
clock
Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
function clock() external view returns (uint48);
CLOCK_MODE
Description of the clock
function CLOCK_MODE() external view returns (string memory);
Events
Deposit
event Deposit(
address indexed provider,
uint256 indexed tokenId,
DepositType indexed depositType,
uint256 value,
uint256 locktime,
uint256 ts
);
Withdraw
event Withdraw(
address indexed provider,
uint256 indexed tokenId,
uint256 value,
uint256 ts
);
LockPermanent
event LockPermanent(
address indexed _owner,
uint256 indexed _tokenId,
uint256 amount,
uint256 _ts
);
UnlockPermanent
event UnlockPermanent(
address indexed _owner,
uint256 indexed _tokenId,
uint256 amount,
uint256 _ts
);
Supply
event Supply(uint256 prevSupply, uint256 supply);
Merge
event Merge(
address indexed _sender,
uint256 indexed _from,
uint256 indexed _to,
uint256 _amountFrom,
uint256 _amountTo,
uint256 _amountFinal,
uint256 _locktime,
uint256 _ts
);
Split
event Split(
uint256 indexed _from,
uint256 indexed _tokenId1,
uint256 indexed _tokenId2,
address _sender,
uint256 _splitAmount1,
uint256 _splitAmount2,
uint256 _locktime,
uint256 _ts
);
CreateManaged
event CreateManaged(
address indexed _to, uint256 indexed _mTokenId, address indexed _from
);
DepositManaged
event DepositManaged(
address indexed _owner,
uint256 indexed _tokenId,
uint256 indexed _mTokenId,
uint256 _weight,
uint256 _ts
);
WithdrawManaged
event WithdrawManaged(
address indexed _owner,
uint256 indexed _tokenId,
uint256 indexed _mTokenId,
uint256 _weight,
uint256 _ts
);
SetAllowedManager
event SetAllowedManager(address indexed _allowedManager);
ToggleSplit
event ToggleSplit(address indexed account, bool indexed canSplit);
VoterAndDistributorSet
event VoterAndDistributorSet(
address indexed voter, address indexed distributor
);
Errors
AlreadyVoted
error AlreadyVoted();
AmountTooBig
error AmountTooBig();
ERC721ReceiverRejectedTokens
error ERC721ReceiverRejectedTokens();
ERC721TransferToNonERC721ReceiverImplementer
error ERC721TransferToNonERC721ReceiverImplementer();
InvalidNonce
error InvalidNonce();
InvalidSignature
error InvalidSignature();
InvalidSignatureS
error InvalidSignatureS();
InvalidManagedNFTId
error InvalidManagedNFTId();
LockDurationNotInFuture
error LockDurationNotInFuture();
LockDurationTooLong
error LockDurationTooLong();
LockExpired
error LockExpired();
LockNotExpired
error LockNotExpired();
NoLockFound
error NoLockFound();
NonExistentToken
error NonExistentToken();
NotApprovedOrOwner
error NotApprovedOrOwner();
NotDistributor
error NotDistributor();
NotEmergencyCouncilOrGovernor
error NotEmergencyCouncilOrGovernor();
NotGovernor
error NotGovernor();
NotGovernorOrManager
error NotGovernorOrManager();
NotManagedNFT
error NotManagedNFT();
NotManagedOrNormalNFT
error NotManagedOrNormalNFT();
NotLockedNFT
error NotLockedNFT();
NotNormalNFT
error NotNormalNFT();
NotPermanentLock
error NotPermanentLock();
NotOwner
error NotOwner();
NotTeam
error NotTeam();
NotVoter
error NotVoter();
OwnershipChange
error OwnershipChange();
PermanentLock
error PermanentLock();
SameAddress
error SameAddress();
SameNFT
error SameNFT();
SameState
error SameState();
SplitNoOwner
error SplitNoOwner();
SplitNotAllowed
error SplitNotAllowed();
SignatureExpired
error SignatureExpired();
TooManyTokenIDs
error TooManyTokenIDs();
ZeroAddress
error ZeroAddress();
ZeroAmount
error ZeroAmount();
ZeroBalance
error ZeroBalance();
Structs
LockedBalance
Represents a locked token balance in the voting escrow system
struct LockedBalance {
int128 amount;
uint256 end;
bool isPermanent;
}
Properties
| Name | Type | Description |
|---|---|---|
amount | int128 | The amount of tokens locked by the user |
end | uint256 | The expiration timestamp for the lock |
isPermanent | bool | Flag indicating if the lock is permanent |
UserPoint
Represents a snapshot of a user's voting power at a given point
struct UserPoint {
int128 bias;
int128 slope; // # -dweight / dt
uint256 ts;
uint256 blk; // block
uint256 permanent;
}
Properties
| Name | Type | Description |
|---|---|---|
bias | int128 | Voting power, decaying over time |
slope | int128 | Rate of decay of voting power |
ts | uint256 | Timestamp of this snapshot |
blk | uint256 | Block number of this snapshot |
permanent | uint256 | Amount locked permanently without decay |
GlobalPoint
Tracks cumulative voting power and its decay across all users
struct GlobalPoint {
int128 bias;
int128 slope; // # -dweight / dt
uint256 ts;
uint256 blk; // block
uint256 permanentLockBalance;
}
Properties
| Name | Type | Description |
|---|---|---|
bias | int128 | Total voting power, decaying over time |
slope | int128 | Global decay rate of voting power |
ts | uint256 | Timestamp of this global checkpoint |
blk | uint256 | Block number of this global checkpoint |
permanentLockBalance | uint256 | Cumulative balance of permanently locked tokens |
Checkpoint
Snapshot of delegated voting weights at a particular timestamp
struct Checkpoint {
uint256 fromTimestamp;
address owner;
uint256 delegatedBalance;
uint256 delegatee;
}
Properties
| Name | Type | Description |
|---|---|---|
fromTimestamp | uint256 | Timestamp when the delegation was made |
owner | address | Address of the NFT owner |
delegatedBalance | uint256 | Balance that has been delegated |
delegatee | uint256 | Address receiving the delegated voting power |
Enums
DepositType
Types of deposits supported in the voting escrow contract
enum DepositType {
DEPOSIT_FOR_TYPE,
CREATE_LOCK_TYPE,
INCREASE_LOCK_AMOUNT,
INCREASE_UNLOCK_TIME
}
Variants
| Name | Description |
|---|---|
DEPOSIT_FOR_TYPE | Deposit for another address |
CREATE_LOCK_TYPE | Create a new lock |
INCREASE_LOCK_AMOUNT | Increase tokens in an existing lock |
INCREASE_UNLOCK_TIME | Extend the duration of an existing lock |
EscrowType
Specifies the type of voting escrow NFT (veNFT)
enum EscrowType {
NORMAL,
LOCKED,
MANAGED
}
Variants
| Name | Description |
|---|---|
NORMAL | Standard veNFT |
LOCKED | veNFT locked within a managed veNFT |
MANAGED | veNFT capable of accepting deposits from NORMAL veNFTs |