ERC20Votes Smart Contract Module in Bunzz

ERC20Votes is an extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound’s, and supports token supply up to 2²²⁴^ — 1, while ERC20VotesComp is limited to 2^96^ – 1.

You can access this Module and the code here: https://bit.ly/40ircwI

How to Use

This extension keeps a history checkpoints of each account’s vote power. Vote power can be delegated either by calling the delegate function directly, or by providing a signature to be used with delegateBySig.

Voting power can be queried through the public accessors getVotes and getPastVotes.

By default, token balance does not account for voting power. This makes transfers cheaper.

The downside is that it requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.

[Methods]

checkpoints(address account, uint32 pos) → struct ERC20Votes.Checkpoint => Get the pos-th checkpoint for account.

delegate(address delegatee) => Get the address account is currently delegating to.

= delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) => Delegates votes from signer to delegatee.

getVotes(address account) → uint256 => Gets the current votes balance for account.

= getPastVotes(address account, uint256 blockNumber) → uint256 => Retrieve the number of votes for account at the end of blockNumberblockNumber must have been already mined.

Functions

#WRITE

  • delegate
  • approve
  • increaseAllowance
  • transfer
  • permit
  • transferFrom
  • decreaseAllowance
  • delegateBySig

#READ

  • name
  • numCheckpoints
  • balanceOf
  • symbol
  • totalSupply
  • decimals
  • delegates
  • getPastVotes
  • getVotes
  • checkpoints
  • DOMAIN_SEPARATOR
  • getPastTotalSupply
  • allowance
  • nonces

You can access this Module and the code here: https://bit.ly/40ircwI

If you still haven’t signed up to Bunzz, what are you waiting for?

Sign up here https://app.bunzz.dev/signup and get your smart contracts deployed in 5 minutes through our great GUI.

Share this article:

Leave a Comment

Your email address will not be published. Required fields are marked *