Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Velodrome Voting Escrow
copy icon
velodrome
• version 1.0.0
Voting
Escrow
ERC20
ERC721

Velodrome Voting Escrow

veNFT implementation that escrows ERC-20 tokens in the form of an ERC-721 NFT. Votes have a weight depending on time, so that users are committed to the future of (whatever they are voting for). Vote weight decays linearly over time. Lock time cannot be more than `MAXTIME` (4 years).

*Visit desktop site to download or deploy

Version

1.0.0

Creator

velodrome

Recent Use

🍞 0xF1B3 downloaded

Last Publish

1/20/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
setTeam(address) :
This function sets the team address of the contract. It requires that the message sender is the team address, and then sets the team address to the address passed in as an argument. (autogenerated documentation)
setArtProxy(address) :
This function allows the team to set the address of the artProxy. It requires that the msg.sender is the team, and then sets the artProxy address to the address passed in as an argument. (autogenerated documentation)
tokenURI() :
This function returns a string containing the URI of a given token. It requires that the tokenId is valid, and then retrieves the locked balance associated with the tokenId. It then calls the _tokenURI function of the IVeArtProxy contract, passing in the tokenId, the balance of the token, the end time of the locked balance, and the amount of the locked balance. The _tokenURI function then returns a string containing the URI of the token. (autogenerated documentation)
ownerOf() :
This function is used to retrieve the owner of a given token ID. It takes in a uint _tokenId as an argument and returns the address of the owner. It works by accessing the mapping idToOwner and returning the address associated with the given token ID. (autogenerated documentation)
_balance(address) :
This function is an internal view function that returns the number of NFTokens owned by a given address. It does this by accessing the ownerToNFTokenCount mapping, which stores the number of NFTokens owned by each address. The function takes in an address as an argument and returns the corresponding number of NFTokens owned by that address. (autogenerated documentation)
balanceOf(address) :
This function is used to check the balance of a given address. It takes in an address as an argument and returns the balance associated with that address. It does this by calling the _balance() function, which is a mapping that stores the address and its associated balance. (autogenerated documentation)
getApproved() :
This function is used to retrieve the address of the approved account for a given token ID. It works by taking in a token ID as an argument and then using this to look up the corresponding address in the idToApprovals mapping. The address of the approved account is then returned. (autogenerated documentation)
isApprovedForAll(address,address) :
This function checks if the given address _operator has been approved by the given address _owner to act on their behalf. It does this by checking the ownerToOperators mapping, which stores a mapping of owners to a mapping of operators and their approval status. If the given operator has been approved by the given owner, the function will return true, otherwise it will return false. (autogenerated documentation)
approve(address) :
This function allows the owner of a token to approve another address to transfer the token. The function requires that the approved address is not the same as the owner, and that the sender is either the owner of the token or has been approved by the owner to transfer the token. If these conditions are met, the approved address is stored in the idToApprovals mapping and an Approval event is emitted. (autogenerated documentation)
setApprovalForAll(address,bool) :
This function allows the owner of a contract to set an approval for all operations for a given operator. It takes in an address of the operator and a boolean value to indicate whether the operator is approved or not. The function first checks that the operator is not the same as the sender, then it sets the approval for the operator in the ownerToOperators mapping and emits an event to indicate the approval has been set. (autogenerated documentation)
_clearApproval(address) :
This function clears the approval of a given tokenId owned by the given address. It first checks that the given address is the owner of the tokenId, and then sets the approval address for the tokenId to 0. This effectively removes the approval for the tokenId. (autogenerated documentation)
_isApprovedOrOwner(address) :
This function checks if a given address (the _spender parameter) is approved to transfer a given token (the _tokenId parameter). It does this by checking if the _spender address is the owner of the token, if the _spender address is the approved address for the token, or if the _spender address is approved for all tokens owned by the owner of the token. If any of these conditions are true, the function returns true, otherwise it returns false. (autogenerated documentation)
isApprovedOrOwner(address) :
This function checks if the given address is either the owner of a specific token or has been approved to transfer it. It does this by calling the internal _isApprovedOrOwner() function, which checks if the given address is either the owner of the token or is listed in the approved addresses mapping for that token. If either of these conditions is true, the function returns true, otherwise it returns false. (autogenerated documentation)
_transferFrom(address,address,address) :
This function is used to transfer a token from one address to another. It requires that the token is not already attached and that the sender is either the owner or approved to transfer the token. It then clears the approval, removes the token from the sender's address, moves the token delegates from the sender's address to the recipient's address, adds the token to the recipient's address, and emits a Transfer event. (autogenerated documentation)
transferFrom(address,address) :
This function allows a user to transfer a token from one address to another. It takes three parameters: the address of the sender, the address of the recipient, and the token ID of the token being transferred. The function then calls the _transferFrom() function, passing in the sender, recipient, token ID, and the sender of the message (msg.sender) as parameters. This function will update the token's ownership and transfer the token to the recipient. (autogenerated documentation)
safeTransferFrom(address,address) :
This function is used to transfer a token from one address to another. It takes three parameters: the address of the sender, the address of the recipient, and the token ID of the token being transferred. The function then calls the safeTransferFrom() function, passing in the three parameters and an empty string as the fourth parameter. This function is used to ensure that the token is transferred securely and that the recipient has the correct permissions to receive the token. (autogenerated documentation)
_isContract(address) :
This function is used to check if a given address is a contract or not. It does this by using the extcodesize opcode to check the size of the code stored at the given address. If the size is greater than 0, then the address is a contract and the function returns true. Otherwise, it returns false. (autogenerated documentation)
supportsInterface(bytes4) :
This function checks if a given interface is supported by the contract. It takes in a bytes4 _interfaceID as an argument and returns a boolean value indicating whether the interface is supported or not. The function checks the supportedInterfaces mapping to determine if the given interface is supported. (autogenerated documentation)
tokenOfOwnerByIndex(address) :
This function returns the token ID of a given owner at a given index. It works by accessing the ownerToNFTokenIdList mapping, which is a mapping of addresses to an array of token IDs. The function takes in an address of an owner and an index, and returns the token ID at that index in the array associated with the given owner. (autogenerated documentation)
_addTokenToOwnerList(address) :
This function adds a token to the list of tokens owned by a particular address. It takes two parameters, the address of the owner and the token ID of the token to be added. It first retrieves the current count of tokens owned by the address, then adds the token ID to the ownerToNFTokenIdList mapping at the index of the current count. It also adds the token ID to the tokenToOwnerIndex mapping, with the current count as the value. (autogenerated documentation)
_addTokenTo(address) :
This function adds a token with the given token ID to the given address. It first checks that the token ID is not already owned by anyone, and then sets the token ID to be owned by the given address. It then adds the token ID to the owner's list of tokens, and increments the owner's token count. (autogenerated documentation)
_mint(address) :
This function is used to mint a new token with a given token ID. It first checks that the address provided is not the address 0. It then moves the token delegates from address 0 to the address provided. It then adds the token to the address provided and emits a Transfer event with address 0 as the sender and the address provided as the receiver. Finally, it returns true. (autogenerated documentation)
_removeTokenFromOwnerList(address) :
This function removes a token from the owner's list of tokens. It takes in the address of the owner and the token ID as parameters. It first calculates the current count of tokens owned by the owner and the current index of the token in the owner's list. If the current count is equal to the current index, it sets the owner's token list at the current count to 0 and sets the token's owner index to 0. Otherwise, it sets the owner's token list at the current index to the last token ID in the list, sets the last token's owner index to the current index, sets the owner's token list at the current count to 0, and sets the token's owner index to 0. (autogenerated documentation)
_removeTokenFrom(address) :
This function removes a token from a given address. It first checks that the address is the owner of the token, then sets the owner of the token to address 0. It then removes the token from the owner's list of tokens and decrements the owner's token count. (autogenerated documentation)
_burn() :
This function is used to burn a token. It requires that the caller is either the owner or an approved address of the token. It then sets the approved address of the token to address 0, removes the token from the caller's list of tokens, and emits a Transfer event with the owner, address 0, and the token ID. (autogenerated documentation)
get_last_user_slope() :
This function retrieves the last slope value associated with a given token ID. It does this by first retrieving the epoch associated with the token ID from the user_point_epoch mapping, and then using that epoch to look up the corresponding slope value from the user_point_history mapping. The slope value is then returned as an int128. (autogenerated documentation)
user_point_history__ts() :
This function is used to retrieve the timestamp of a user's point history from the user_point_history mapping. It takes two parameters, a token ID and an index, and returns a uint representing the timestamp. The mapping is structured as a two-dimensional array, with the first parameter representing the token ID and the second parameter representing the index of the point history entry. The function then returns the timestamp associated with the specified entry. (autogenerated documentation)
locked__end() :
This function returns the end time of a locked token. It takes in a token ID as an argument and returns the end time of the locked token associated with that ID. The end time is stored in the locked mapping, which is a mapping of token IDs to locked structs. The locked struct contains the start and end times of the locked token. (autogenerated documentation)
_checkpoint() :
This function is used to update the locked balance of a token. It takes in the token ID, the old locked balance, and the new locked balance as parameters. It then calculates the slope and bias of the old and new locked balances, and updates the slope_changes and point_history variables accordingly. It also updates the user_point_epoch and user_point_history variables for the token ID. Finally, it updates the epoch variable. (autogenerated documentation)
_deposit_for() :
This function is used to deposit a certain amount of tokens into the contract. It takes in the token ID, the value to be deposited, the unlock time, the locked balance, and the deposit type as parameters. It then updates the supply of the contract, adds the value to the locked balance, and checks the checkpoint. It then transfers the tokens from the sender to the contract and emits the Deposit and Supply events. (autogenerated documentation)
block_number() :
This function returns the current block number of the Ethereum blockchain. It works by accessing the block.number variable, which is a global variable that stores the current block number. (autogenerated documentation)
checkpoint() :
This function is used to create a checkpoint in the contract. It sets the locked balances of both the sender and the receiver to 0. This allows the contract to track the amount of funds that have been transferred between the two parties. The function is triggered externally, meaning it can be called by anyone who has access to the contract. (autogenerated documentation)
deposit_for() :
This function allows a user to deposit funds for a specific token ID. It requires that the value of the deposit is greater than 0, that there is an existing lock for the token ID, and that the lock has not expired. It then calls the _deposit_for function, passing in the token ID, the value of the deposit, 0, the locked balance, and the deposit type. This function updates the locked balance with the new deposit, and updates the total locked balance for the token ID. (autogenerated documentation)
_create_lock(address) :
This function creates a lock on a given amount of tokens for a given duration of time. It requires that the value of the tokens is greater than 0, that the unlock time is in the future, and that the unlock time is within the maximum allowed time. It then increments the tokenId, mints the tokens to the specified address, and deposits the tokens into the locked array with the specified unlock time. (autogenerated documentation)
create_lock() :
This function creates a lock on a specified amount of tokens for a specified duration. It takes two parameters, _value and _lock_duration, which represent the amount of tokens to be locked and the duration of the lock, respectively. The function then calls the _create_lock() internal function, passing in the two parameters as well as the address of the sender of the transaction. The _create_lock() function will then create the lock and return the ID of the lock. (autogenerated documentation)
create_lock_for(address) :
This function creates a lock for a specified amount of time for a specified value of tokens to a specified address. It works by calling the _create_lock() function, which takes in the value, lock duration, and address as parameters and returns a unique identifier for the lock. (autogenerated documentation)
increase_amount() :
This function increases the amount of a locked token. It takes two parameters, a token ID and a value. It first checks that the sender is either the owner or an approved address for the token. It then checks that the value is greater than 0 and that the existing lock is still valid. Finally, it calls the _deposit_for function to increase the amount of the locked token. (autogenerated documentation)
increase_unlock_time() :
This function increases the unlock time of a token with a given ID. It first checks that the sender is either the owner or an approved address of the token. It then checks that the lock has not expired, that something is locked, that the new unlock time is greater than the current one, and that the new unlock time is not more than 4 years from the current block timestamp. Finally, it deposits the token with the new unlock time. (autogenerated documentation)
withdraw() :
This function allows a user to withdraw a token from the contract. It first checks that the user is either the owner or has been approved to withdraw the token. It then checks that the token has not been attached to any other contract and that it has not been voted on. It then checks that the lock on the token has expired. It then subtracts the amount of the token from the total supply and transfers the token to the user. Finally, it burns the token and emits two events, one for the withdrawal and one for the change in supply. (autogenerated documentation)
_find_block_epoch() :
This function is used to find the epoch associated with a given block number. It uses a binary search algorithm to search through the point_history array, which stores the block numbers associated with each epoch. The function takes in the block number and the maximum epoch as parameters, and returns the epoch associated with the given block number. The binary search algorithm starts by setting the minimum and maximum epochs to 0 and the maximum epoch respectively. It then iterates through the array, setting the midpoint between the minimum and maximum epochs as the current epoch. If the block number associated with the current epoch is less than or equal to the given block number, the minimum epoch is set to the current epoch. Otherwise, the maximum epoch is set to (autogenerated documentation)
_balanceOfNFT() :
This function is used to calculate the balance of a Non-Fungible Token (NFT) at a given time. It takes in two parameters, the token ID and the time, and returns the balance of the NFT at that time. The function first checks if the token has an epoch associated with it, and if so, it retrieves the last point from the user_point_history array. It then subtracts the slope of the point multiplied by the difference between the given time and the timestamp of the point from the bias of the point. If the result is negative, it is set to 0. Finally, the function returns the resulting balance. (autogenerated documentation)
balanceOfNFT() :
This function is used to check the balance of a given Non-Fungible Token (NFT). It takes in a token ID as an argument and returns the balance of the token. The function first checks if the ownership of the token has changed since the last block, and if so, returns 0. Otherwise, it calls the _balanceOfNFT() function, passing in the token ID and the current block timestamp, and returns the balance of the token. (autogenerated documentation)
balanceOfNFTAt() :
This function returns the balance of a given Non-Fungible Token (NFT) at a given time. It works by taking in two parameters, the token ID of the NFT and the time, and then using the _balanceOfNFT() internal function to retrieve the balance of the NFT at the given time. (autogenerated documentation)
_balanceOfAtNFT() :
This function is used to calculate the balance of a given NFT token at a given block number. It works by first finding the user point epoch associated with the token, and then using binary search to find the user point history associated with the token. It then calculates the block time associated with the given block number, and subtracts the slope and timestamp from the user point history to calculate the balance of the token. (autogenerated documentation)
balanceOfAtNFT() :
This function allows users to check the balance of a specific Non-Fungible Token (NFT) at a given block number. It works by taking in the token ID and the block number as parameters, and then using the _balanceOfAtNFT() internal function to return the balance of the NFT at that block number. (autogenerated documentation)
totalSupplyAt() :
This function calculates the total supply of a token at a given block number. It does this by first finding the epoch associated with the given block number, then finding the Point memory associated with that epoch. It then calculates the difference in time between the given block number and the Point memory's block number, and uses that to calculate the total supply at the given block number. (autogenerated documentation)
_supply_at() :
This function is used to calculate the supply of the token at a given time. It takes in a Point memory point and a uint t as parameters. The Point memory point contains the slope and bias of the supply curve, and the uint t is the time at which the supply is to be calculated. The function first sets the last_point to the point passed in, and sets t_i to the time of the last_point divided by a week, multiplied by a week. It then iterates through a loop 255 times, incrementing t_i by a week each time. It then calculates the change in slope for the current t_i, and subtracts the slope of the last_point multiplied by the (autogenerated documentation)
totalSupply() :
This function returns the total supply of a token at a given timestamp. It works by calling the totalSupplyAtT() function, which takes a timestamp as an argument and returns the total supply of the token at that timestamp. (autogenerated documentation)
totalSupplyAtT() :
This function calculates the total supply of a token at a given time t. It does this by first retrieving the last point in the point history, which is a mapping of epochs to points. A point is a struct containing the total supply of the token at a given time. The function then uses the _supply_at() function to calculate the total supply of the token at the given time t. (autogenerated documentation)
setVoter(address) :
This function allows the owner of the contract to set the address of the voter. It requires that the message sender is the current voter, and then sets the voter address to the address passed in as an argument. (autogenerated documentation)
voting() :
This function allows a voter to cast a vote for a specific token ID. It requires that the sender of the transaction is the voter, and then sets the voted mapping for the token ID to true. (autogenerated documentation)
abstain() :
This function allows a voter to abstain from voting on a particular token. It requires that the sender of the transaction is the voter, and then sets the voted boolean value for the token to false. (autogenerated documentation)
attach() :
This function allows a voter to attach a token to a specific token ID. It requires that the sender of the message is the voter, and then it increments the attachments counter for the specified token ID by 1. (autogenerated documentation)
detach() :
This function allows the voter to detach a token from the contract. It requires that the msg.sender is the voter, and then reduces the number of attachments associated with the tokenId by 1. (autogenerated documentation)
merge() :
This function merges two accounts, transferring the balance of one account to the other. It requires that the sender is the owner or approved for both accounts, and that the two accounts are not the same. It then stores the locked balance of the first account in a memory variable, and sets the locked balance of the first account to 0. It then calls the _checkpoint function to record the change, and the _burn function to burn the balance of the first account. Finally, it calls the _deposit_for function to deposit the balance of the first account into the second account, with the end time of the locked balance being the maximum of the two accounts. (autogenerated documentation)
delegates(address) :
This function is used to retrieve the address of a delegate for a given delegator. It takes in an address of a delegator as an argument and returns the address of the delegate associated with that delegator. The function first checks if the delegator has a delegate associated with it by looking up the address in the _delegates mapping. If the address is 0, then the delegator is returned, otherwise the address of the delegate is returned. (autogenerated documentation)
getVotes(address) :
This function is used to get the total number of votes for a given account. It does this by looping through the tokenIds associated with the account and summing up the balance of each tokenId at the current block timestamp. The result is then returned as the total number of votes for the account. (autogenerated documentation)
getPastVotesIndex(address) :
This function is used to find the index of a past vote in the checkpoints array for a given account. It takes in an address (account) and a timestamp as parameters and returns a uint32 (index). The function first checks if the number of checkpoints for the given account is 0, in which case it returns 0. It then checks if the timestamp is greater than the timestamp of the last checkpoint, in which case it returns the index of the last checkpoint. If the timestamp is less than the timestamp of the first checkpoint, it returns 0. If the timestamp is between the first and last checkpoints, the function uses a binary search algorithm to find the index of the checkpoint with the given timestamp. It sets (autogenerated documentation)
getPastVotes(address) :
This function gets the past votes of a given account at a given timestamp. It does this by first getting the index of the past votes from the getPastVotesIndex function, then looping through the tokenIds stored in the checkpoints mapping for the given account and timestamp. For each tokenId, it adds the balance of the NFT at the given timestamp to the total votes. Finally, it returns the total votes. (autogenerated documentation)
getPastTotalSupply(uint256) :
This function returns the total supply of a token at a given timestamp. It works by using the totalSupplyAtT() function to calculate the total supply of the token at the given timestamp. (autogenerated documentation)
_moveTokenDelegates(address,address) :
This function is used to move a token from one delegate to another. It takes in the address of the source delegate, the address of the destination delegate, and the token ID as parameters. It first checks to make sure that the source and destination delegates are not the same and that the token ID is valid. If the source delegate is not address(0), it finds the last checkpoint for the source delegate and stores the token IDs in an array. It then finds the next checkpoint for the source delegate and stores the token IDs in a new array, excluding the token ID that is being moved. It then increments the number of checkpoints for the source delegate. If the destination delegate is not address(0), it (autogenerated documentation)
_findWhatCheckpointToWrite(address) :
This function is used to find the checkpoint to write for a given account. It takes an address as an argument and returns a uint32. It first gets the current block timestamp and the number of checkpoints for the given account. It then checks if the last checkpoint timestamp is equal to the current block timestamp. If it is, it returns the number of checkpoints minus one, otherwise it returns the number of checkpoints. (autogenerated documentation)
_moveAllDelegates(address,address,address) :
This function is used to move all of the delegates owned by a particular address from one representative to another. It first checks to make sure that the source and destination representatives are not the same. If they are not, it will first write all of the delegates from the source representative to a new checkpoint, excluding any delegates owned by the address specified in the function parameters. It then writes all of the delegates owned by the address specified in the function parameters to a new checkpoint for the destination representative. Finally, it updates the number of checkpoints for both the source and destination representatives. (autogenerated documentation)
_delegate(address,address) :
This function allows a delegator to delegate their voting power to a delegatee. It sets the delegatee as the new delegate for the delegator, and emits an event to notify of the change. It also moves all of the delegator's votes to the delegatee, so that the delegatee can cast votes on their behalf. (autogenerated documentation)
delegate(address) :
This function allows a user to delegate their voting rights to another address. It takes in an address as an argument, and if the address is 0, it sets the delegatee to the sender of the message. It then calls the _delegate function, passing in the sender and the delegatee as arguments. The _delegate function is responsible for actually delegating the voting rights. (autogenerated documentation)
delegateBySig(address,uint8,bytes32,bytes32) :
This function allows a user to delegate their voting rights to another address by providing a signature. The function first calculates the domain separator and the struct hash, which are used to generate the digest. The digest is then used to recover the signatory address from the provided signature. The function then checks that the nonce is valid and that the signature has not expired. Finally, the function calls the _delegate function to delegate the voting rights to the delegatee address. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i velodrome-voting-escrow
copy icon

Recent Use

🍞 0xF1B3 downloaded

Last Publish

1/20/2023

Version

1.0.0

Creator

velodrome

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.