Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Voting Token (Compound)
copy icon
THORSwap
โ€ข version 1.0.0
Token
ERC20
Governance
Voting
Audited

Voting Token (Compound)

Audited

Token used alongside a DAO for Compound-like voting. Maximum supply so that users know exactly how much voting power they will have. Used by THORSwap for governance.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

THORSwap

Recent Use

๐Ÿž 0xf9e4 downloaded
๐Ÿฅ 0xaE04 downloaded
๐Ÿฅ– 0x70F8 downloaded

Last Publish

9/26/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
checkpoints(address,uint32) :
This function is used to retrieve a specific checkpoint from a given account. It takes two parameters, an address of an account and a uint32 position, and returns a Checkpoint memory. The function works by accessing the _checkpoints mapping, which is a mapping of addresses to an array of Checkpoint memory. The function then returns the Checkpoint memory at the given position for the given account. (autogenerated documentation)
numCheckpoints(address) :
This function returns the number of checkpoints associated with a given account. It works by accessing the _checkpoints mapping, which stores an array of checkpoints associated with each account. The SafeCast.toUint32() function is used to convert the length of the array into a uint32 value, which is then returned. (autogenerated documentation)
delegates(address) :
This function is used to retrieve the address of the delegate associated with a given account. It works by taking in an address as an argument and returning the address of the delegate associated with that account from the _delegates mapping. (autogenerated documentation)
getVotes(address) :
This function retrieves the total number of votes for a given account. It does this by accessing the _checkpoints mapping, which stores an array of structs for each account. The function then looks at the length of the array and returns the votes from the last struct in the array. If the array is empty, it returns 0. (autogenerated documentation)
getPastVotes(address,uint256) :
This function allows users to retrieve the number of votes a given account had at a given block number. It does this by first checking that the block number is lower than the current block number, and then using the _checkpointsLookup() function to look up the number of votes the account had at the given block number in the _checkpoints mapping. (autogenerated documentation)
getPastTotalSupply(uint256) :
This function retrieves the total supply of the ThorToken at a given block number. It does this by using the _checkpointsLookup() function to look up the total supply from the _totalSupplyCheckpoints mapping. The function requires that the given block number is less than the current block number, and returns the total supply at the given block number. (autogenerated documentation)
_checkpointsLookup(uint256) :
This function is used to look up the number of votes associated with a given block number. It uses a binary search algorithm to find the checkpoint with the highest block number that is less than or equal to the given block number. It then returns the number of votes associated with that checkpoint. (autogenerated documentation)
delegate(address) :
This function allows a user to delegate their voting power to another user. It does this by calling the _delegate() function, which takes two parameters: the address of the user delegating their voting power, and the address of the user they are delegating their voting power to. The function then returns the result of the _delegate() function. (autogenerated documentation)
delegateBySig(address,uint256,uint256,uint8,bytes32,bytes32) :
This function allows a user to delegate their token balance to another address. It does this by verifying a signature provided by the user, which is generated using the ECDSA algorithm. The signature is generated using the user's address, a nonce, an expiry timestamp, and a hash of the delegation type. The function then verifies the signature using the ECDSA.recover() function, and if the signature is valid, the user's token balance is delegated to the specified address. (autogenerated documentation)
getCurrentVotes(address) :
This function is used to retrieve the current number of votes that a given account has. It works by calling the getVotes() function, which returns a uint256 value, and then passing that value to the SafeCast.toUint96() function, which converts the uint256 value to a uint96 value. The uint96 value is then returned as the result of the getCurrentVotes() function. (autogenerated documentation)
getPriorVotes(address,uint256) :
This function retrieves the prior votes of a given account at a given block number. It does this by calling the getPastVotes() function, which returns a uint256 value, and then using the SafeCast.toUint96() function to convert the uint256 value into a uint96 value. (autogenerated documentation)
_maxSupply() :
This function is an internal view function that returns the maximum supply of a token. It returns a uint96 value, which is 500 million ether. This function is used to set the maximum supply of the token and is used to ensure that the total supply of the token does not exceed the maximum supply. (autogenerated documentation)
_mint(address,uint256) :
This function is an override of the _mint() function from the ERC20 contract. It is used to mint new tokens and add them to the total supply. It takes in two parameters, an address and an amount, and adds the amount to the total supply. It also checks to make sure that the total supply does not exceed the maximum supply. Finally, it writes a checkpoint to the total supply checkpoints mapping. (autogenerated documentation)
_burn(address,uint256) :
This function is an override of the _burn function from the ERC20 contract. It subtracts the amount of tokens being burned from the total supply of tokens and stores the new total supply in a checkpoint. This allows the total supply to be tracked and updated in a secure and reliable way. (autogenerated documentation)
_afterTokenTransfer(address,address,uint256) :
This function is an override of the _afterTokenTransfer function in the ERC20 contract. It is triggered after a token transfer has been completed. It updates the voting power of the delegates associated with the sender and receiver of the token transfer. It does this by calling the _moveVotingPower function, which updates the voting power of the delegates by subtracting the amount of tokens transferred from the sender's delegate and adding it to the receiver's delegate. (autogenerated documentation)
_delegate(address,address) :
This function allows a user (delegator) to delegate their voting power to another user (delegatee). It first stores the current delegate of the delegator in a variable, then stores the delegator's balance in another variable. It then updates the delegate of the delegator to the delegatee and emits an event to notify of the change. Finally, it moves the delegator's voting power from the current delegate to the delegatee. (autogenerated documentation)
_moveVotingPower(address,address,uint256) :
This function is used to move voting power from one address to another. It takes three parameters: the source address, the destination address, and the amount of voting power to be moved. It first checks that the source and destination addresses are not the same and that the amount is greater than 0. If the source address is not address(0), it subtracts the amount from the source address's voting power and emits an event to indicate that the source address's voting power has changed. If the destination address is not address(0), it adds the amount to the destination address's voting power and emits an event to indicate that the destination address's voting power has changed. (autogenerated documentation)
_writeCheckpoint(uint256) :
This function is used to write a checkpoint to a storage array. It takes in an array of Checkpoint objects, an operation function, and a delta value. It first calculates the old weight and new weight by calling the operation function with the old weight and delta value. It then checks if the last checkpoint in the array has the same block number as the current block. If so, it updates the votes of the last checkpoint to the new weight. Otherwise, it adds a new checkpoint to the array with the current block number and the new weight. (autogenerated documentation)
_add(uint256,uint256) :
This function is a private, pure function that adds two uint256 values together and returns the result. It works by taking two uint256 values as parameters, adding them together, and then returning the result. (autogenerated documentation)
_subtract(uint256,uint256) :
This function is a private, pure function that subtracts two uint256 values (unsigned 256-bit integers) and returns the result. It works by taking two uint256 values as input, subtracting the second value from the first, and then returning the result. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i voting-token-compound
copy icon

Recent Use

๐Ÿž 0xf9e4 downloaded
๐Ÿฅ 0xaE04 downloaded
๐Ÿฅ– 0x70F8 downloaded

Last Publish

9/26/2022

Version

1.0.0

Creator

THORSwap

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