Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Compound-like voting extension for ERC1155
copy icon
z0r0z
• version 1.0.0
ERC1155
Voting
Compound
Library
Abstract

Compound-like voting extension for ERC1155

An abstract extension for Compound-like ERC1155 voting. Uses gas-optimized dependencies by Solbase.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

z0r0z

Last Publish

11/14/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
delegates(address,uint256) :
This function is used to retrieve the address of a delegate associated with a given account and ID. It takes in two parameters, an address account and a uint256 id, and returns an address. It first looks up the address associated with the account and ID in the _delegates mapping, and if it finds one, it returns that address. If it does not find one, it returns the account address that was passed in. (autogenerated documentation)
getCurrentVotes(address,uint256) :
This function retrieves the total number of votes for a given account and ID. It does this by first checking the numCheckpoints mapping to get the total number of checkpoints associated with the account and ID. If the number of checkpoints is not 0, it then retrieves the votes from the last checkpoint in the checkpoints mapping. If the number of checkpoints is 0, it returns 0. (autogenerated documentation)
getPriorVotes(address,uint256,uint256) :
This function is used to retrieve the number of votes a given account had at a given timestamp. It does this by using a binary search algorithm to look through the checkpoints array for the account and id provided. The checkpoints array stores the number of votes the account had at a given timestamp. The function returns the number of votes the account had at the given timestamp, or 0 if the timestamp is before the first checkpoint. (autogenerated documentation)
delegate(address,uint256) :
This function allows a user to delegate their balance of a particular token (identified by the id parameter) to another user (the delegatee parameter). The function first stores the current delegate in a variable, then updates the _delegates mapping to reflect the new delegate. It then emits an event to notify of the change, and finally calls the _moveDelegates function to transfer the balance from the current delegate to the new delegate. (autogenerated documentation)
_moveDelegates(address,address,uint256,uint256) :
This function is used to move a certain amount of votes from one representative (srcRep) to another (dstRep). It first checks if the source and destination representatives are different and if the amount of votes to be moved is not 0. If these conditions are met, it subtracts the amount of votes from the source representative's total and adds it to the destination representative's total. It does this by writing a new checkpoint for each representative, which stores the new total amount of votes. (autogenerated documentation)
_writeCheckpoint(address,uint256,uint256,uint256,uint256) :
This function is used to write a checkpoint for a delegatee's vote count. It takes in the address of the delegatee, the ID of the vote, the number of checkpoints, the old vote count, and the new vote count. It then stores the timestamp, the new vote count, and increments the number of checkpoints for the delegatee. Finally, it emits an event to indicate that the delegatee's vote count has changed. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i z0r0z-erc1155votes
copy icon

Last Publish

11/14/2022

Version

1.0.0

Creator

z0r0z

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