relevant tag icon
NFT with Vote checkpointing
copy icon
Nouns-DAO
• version 1.0.0
ERC721
Extension
Voting

NFT with Vote checkpointing

ERC721 extension that allows a DAO or governer contract to lock in ownership details at a specific point in time. This snapshot allows the DAO to securely tally votes on proposals

*Visit desktop site to download or deploy

Version

1.0.0

Creator

Nouns-DAO

Recent Use

🍞 0x7b4e downloaded
🥐 0x77CA downloaded
🥖 0x77CA saved

Last Publish

10/17/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
votesToDelegate(address) :
This function allows a delegator to convert their ERC721 tokens into a vote for a delegate. It works by taking the delegator's address as an input and returning a uint96 value representing the number of votes they have. The function also uses a safe96 function to ensure that the amount of votes does not exceed 96 bits. (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)
_beforeTokenTransfer(address,address,uint256) :
This function is an internal override of the _beforeTokenTransfer function in the ERC721 contract. It is used to update the delegates associated with a token when it is transferred 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 first calls the _beforeTokenTransfer function in the parent contract, and then updates the delegates associated with the token by calling the _moveDelegates function. This function takes the delegates associated with the sender and the recipient, and moves the appropriate number of delegates from the sender to the recipient. (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,uint256,uint256,uint8,bytes32,bytes32) :
This function allows a user to delegate their rights to another user by providing a signature. The function first verifies the signature by using the ecrecover function to recover the signatory address from the provided v, r, and s parameters. It then checks that the nonce provided is valid and that the signature has not expired. If all of these checks pass, the function calls the _delegate function to delegate the rights to the delegatee. (autogenerated documentation)
getCurrentVotes(address) :
This function is used to retrieve the current number of votes for a given account. It does this by first retrieving the number of checkpoints associated with the account from the numCheckpoints mapping. If the number of checkpoints is greater than 0, it then retrieves the votes from the last checkpoint in the checkpoints mapping associated with the account. If the number of checkpoints is 0, it returns 0. (autogenerated documentation)
getPriorVotes(address,uint256) :
This function is used to get the prior votes of an account at a given block number. It requires that the block number is less than the current block number. It first checks if the account has any checkpoints, and if not, it returns 0. It then checks if the last checkpoint is before the given block number, and if so, it returns the votes of that checkpoint. If the first checkpoint is after the given block number, it returns 0. Otherwise, it uses binary search to find the checkpoint with the closest block number before the given block number, and returns the votes of that checkpoint. (autogenerated documentation)
_delegate(address,address) :
This function allows a delegator to delegate their voting power to a delegatee. It first stores the current delegate of the delegator in a variable, then updates the mapping of delegates to the new delegatee. It then emits an event to signal that the delegate has changed. Finally, it calculates the amount of votes to be delegated and calls the _moveDelegates function to transfer the voting power from the current delegate to the new delegatee. (autogenerated documentation)
_moveDelegates(address,address,uint96) :
This function is used to move a specified amount of votes from one representative (srcRep) to another (dstRep). It first checks that the source and destination representatives are not the same and that the amount of votes to be moved is greater than 0. If the source representative is not address 0, it then calculates the new vote total for the source representative by subtracting the specified amount from the previous vote total. If the destination representative is not address 0, it then calculates the new vote total for the destination representative by adding the specified amount to the previous vote total. Finally, it writes the new vote totals to the checkpoints mapping. (autogenerated documentation)
_writeCheckpoint(address,uint32,uint96,uint96) :
This function is used to write a checkpoint for a given delegatee. It takes in the address of the delegatee, the number of checkpoints, the old votes, and the new votes. It then stores the checkpoint in the checkpoints mapping, and updates the number of checkpoints for the delegatee. Finally, it emits an event to indicate that the delegatee's votes have changed. (autogenerated documentation)
safe32(uint256,string) :
This function is an internal pure function that takes in a uint256 number and a string error message as parameters. It checks to make sure that the number is less than 2^32 and if it is, it returns the number as a uint32. If the number is not less than 2^32, it will throw an error with the provided error message. (autogenerated documentation)
safe96(uint256,string) :
This function is an internal pure function that takes in a uint256 number and a string error message as parameters. It checks to make sure that the number is less than 2^96 and if it is, it returns a uint96 number. If the number is not less than 2^96, it will throw an error with the provided error message. (autogenerated documentation)
add96(uint96,uint96,string) :
This function adds two uint96 values together and returns the result. It also checks to make sure that the result of the addition is greater than or equal to the first value, and if not, it will throw an error with the provided error message. (autogenerated documentation)
sub96(uint96,uint96,string) :
This function is an internal pure function that subtracts two uint96 values and returns the result. It requires that the second argument (b) is less than or equal to the first argument (a). If this requirement is not met, an error message is thrown. The function then returns the result of subtracting b from a. (autogenerated documentation)
getChainId() :
This function is used to retrieve the chain ID of the current Ethereum network. It does this by using the chainid() assembly instruction, which returns the chain ID of the current network. The function then returns the chain ID as a uint256. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i nft-vote-extension
copy icon

Recent Use

🍞 0x7b4e downloaded
🥐 0x77CA downloaded
🥖 0x77CA saved

Last Publish

10/17/2022

Version

1.0.0

Creator

Nouns-DAO

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