IVotingEscrow

Git Source

Inherits: IVotes, IERC4906, IERC6372, IERC721Metadata

Functions

token

Address of token (RED) 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

NameTypeDescription
<none>IInfraredUpgradeableIInfrared 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

NameTypeDescription
_mTokenIduint256managed 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

NameTypeDescription
_tokenIduint256tokenId of NFT being deposited
_mTokenIduint256tokenId 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

NameTypeDescription
_tokenIduint256tokenId 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

NameTypeDescription
_mTokenIduint256managed nft state to set
_statebooltrue => 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

A distinct Uniform Resource Identifier (URI) for a given asset.

Throws if _tokenId is not a valid NFT. URIs are defined in RFC 3986. The URI may point to a JSON file that conforms to the "ERC721 Metadata JSON Schema".

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

Find the owner of an NFT

NFTs assigned to zero address are considered invalid, and queries about them do throw.

function ownerOf(uint256 tokenId) external view returns (address owner);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
owneraddressThe address of the owner of the NFT

balanceOf

Count all NFTs assigned to an owner

NFTs assigned to the zero address are considered invalid, and this function throws for queries about the zero address.

function balanceOf(address owner) external view returns (uint256 balance);

Parameters

NameTypeDescription
owneraddress

Returns

NameTypeDescription
balanceuint256The number of NFTs owned by _owner, possibly zero

getApproved

Get the approved address for a single NFT

Throws if _tokenId is not a valid NFT.

function getApproved(uint256 _tokenId)
    external
    view
    returns (address operator);

Parameters

NameTypeDescription
_tokenIduint256The NFT to find the approved address for

Returns

NameTypeDescription
operatoraddressThe approved address for this NFT, or the zero address if there is none

isApprovedForAll

Query if an address is an authorized operator for another address

function isApprovedForAll(address owner, address operator)
    external
    view
    returns (bool);

Parameters

NameTypeDescription
owneraddress
operatoraddress

Returns

NameTypeDescription
<none>boolTrue if _operator is an approved operator for _owner, false otherwise

isApprovedOrOwner

Check whether spender is owner or an approved user for a given veNFT

function isApprovedOrOwner(address _spender, uint256 _tokenId)
    external
    returns (bool);

Parameters

NameTypeDescription
_spenderaddress.
_tokenIduint256.

approve

Change or reaffirm the approved address for an NFT

The zero address indicates there is no approved address. Throws unless msg.sender is the current NFT owner, or an authorized operator of the current owner.

function approve(address to, uint256 tokenId) external;

Parameters

NameTypeDescription
toaddress
tokenIduint256

setApprovalForAll

Enable or disable approval for a third party ("operator") to manage all of msg.sender's assets

Emits the ApprovalForAll event. The contract MUST allow multiple operators per owner.

function setApprovalForAll(address operator, bool approved) external;

Parameters

NameTypeDescription
operatoraddress
approvedbool

transferFrom

Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE TO CONFIRM THAT _to IS CAPABLE OF RECEIVING NFTS OR ELSE THEY MAY BE PERMANENTLY LOST

Throws unless msg.sender is the current owner, an authorized operator, or the approved address for this NFT. Throws if _from is not the current owner. Throws if _to is the zero address. Throws if _tokenId is not a valid NFT.

function transferFrom(address from, address to, uint256 tokenId) external;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256

safeTransferFrom

Transfers the ownership of an NFT from one address to another address

Throws unless msg.sender is the current owner, an authorized operator, or the approved address for this NFT. Throws if _from is not the current owner. Throws if _to is the zero address. Throws if _tokenId is not a valid NFT. When transfer is complete, this function checks if _to is a smart contract (code size > 0). If so, it calls onERC721Received on _to and throws if the return value is not bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).

function safeTransferFrom(address from, address to, uint256 tokenId) external;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256

safeTransferFrom

Transfers the ownership of an NFT from one address to another address

Throws unless msg.sender is the current owner, an authorized operator, or the approved address for this NFT. Throws if _from is not the current owner. Throws if _to is the zero address. Throws if _tokenId is not a valid NFT. When transfer is complete, this function checks if _to is a smart contract (code size > 0). If so, it calls onERC721Received on _to and throws if the return value is not bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).

function safeTransferFrom(
    address from,
    address to,
    uint256 tokenId,
    bytes calldata data
) external;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256
databytesAdditional data with no specified format, sent in call to _to

supportsInterface

Query if a contract implements an interface

Interface identification is specified in ERC-165. This function uses less than 30,000 gas.

function supportsInterface(bytes4 _interfaceID) external view returns (bool);

Parameters

NameTypeDescription
_interfaceIDbytes4

Returns

NameTypeDescription
<none>booltrue if the contract implements interfaceID and interfaceID is not 0xffffffff, false otherwise

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

NameTypeDescription
_tokenIduint256.

Returns

NameTypeDescription
<none>LockedBalanceLockedBalance 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

NameTypeDescription
_tokenIduint256lock NFT
_valueuint256Amount 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

NameTypeDescription
_valueuint256Amount to deposit
_lockDurationuint256Number of seconds to lock tokens for (rounded down to nearest week)

Returns

NameTypeDescription
<none>uint256TokenId 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

NameTypeDescription
_valueuint256Amount to deposit
_lockDurationuint256Number of seconds to lock tokens for (rounded down to nearest week)
_toaddressAddress to deposit

Returns

NameTypeDescription
<none>uint256TokenId of created veNFT

increaseAmount

Deposit _value additional tokens for _tokenId without modifying the unlock time

function increaseAmount(uint256 _tokenId, uint256 _value) external;

Parameters

NameTypeDescription
_tokenIduint256
_valueuint256Amount 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

NameTypeDescription
_tokenIduint256
_lockDurationuint256New 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

NameTypeDescription
_fromuint256VeNFT to merge from.
_touint256VeNFT 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

NameTypeDescription
_fromuint256VeNFT to split.
_amountuint256Amount to split from veNFT.

Returns

NameTypeDescription
_tokenId1uint256Return tokenId of veNFT with oldLocked.amount - _amount.
_tokenId2uint256Return 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

NameTypeDescription
_accountaddressAddress to toggle split permissions
_boolboolTrue 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

NameTypeDescription
_tokenIduint256tokenId 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

NameTypeDescription
_tokenIduint256tokenId 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

NameTypeDescription
_tokenIduint256.

Returns

NameTypeDescription
<none>uint256Voting power

balanceOfNFTAt

Get the voting power for _tokenId at a given timestamp

function balanceOfNFTAt(uint256 _tokenId, uint256 _t)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription
_tokenIduint256.
_tuint256Timestamp to query voting power

Returns

NameTypeDescription
<none>uint256Voting power

totalSupply

Calculate total voting power at current timestamp

function totalSupply() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256Total voting power at current timestamp

totalSupplyAt

Calculate total voting power at a given timestamp

function totalSupplyAt(uint256 _t) external view returns (uint256);

Parameters

NameTypeDescription
_tuint256Timestamp to query total voting power

Returns

NameTypeDescription
<none>uint256Total voting power at given timestamp

voted

See if a queried _tokenId has actively voted

function voted(uint256 _tokenId) external view returns (bool);

Parameters

NameTypeDescription
_tokenIduint256.

Returns

NameTypeDescription
<none>boolTrue 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

NameTypeDescription
_tokenIduint256.
_votedbool.

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

NameTypeDescription
tokenIduint256.
indexuint48.

Returns

NameTypeDescription
<none>CheckpointCheckpoint

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

NameTypeDescription
amountint128The amount of tokens locked by the user
enduint256The expiration timestamp for the lock
isPermanentboolFlag 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;
    uint256 ts;
    uint256 blk;
    uint256 permanent;
}

Properties

NameTypeDescription
biasint128Voting power, decaying over time
slopeint128Rate of decay of voting power
tsuint256Timestamp of this snapshot
blkuint256Block number of this snapshot
permanentuint256Amount locked permanently without decay

GlobalPoint

Tracks cumulative voting power and its decay across all users

struct GlobalPoint {
    int128 bias;
    int128 slope;
    uint256 ts;
    uint256 blk;
    uint256 permanentLockBalance;
}

Properties

NameTypeDescription
biasint128Total voting power, decaying over time
slopeint128Global decay rate of voting power
tsuint256Timestamp of this global checkpoint
blkuint256Block number of this global checkpoint
permanentLockBalanceuint256Cumulative 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

NameTypeDescription
fromTimestampuint256Timestamp when the delegation was made
owneraddressAddress of the NFT owner
delegatedBalanceuint256Balance that has been delegated
delegateeuint256Address 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
}

EscrowType

Specifies the type of voting escrow NFT (veNFT)

enum EscrowType {
    NORMAL,
    LOCKED,
    MANAGED
}