This release introduces our latest work on governance contracts. ERC20Votes
and ERC20VotesComp
, extensions for our ERC20 token, include vote delegation mechanisms essential for voting in governance systems like Compound’s GovernorAlpha and GovernorBravo. Additionally, this release introduces gas cost reductions, new helper functions, and the ERC20Wrapper extension. In the future, we plan to release major governance features that will further enhance this update. Read on to learn more!
Get Started
Use Contracts Wizard to leverage OpenZeppelin Contracts and bootstrap your code in minutes.
Install from npm for local development:
npm install @openzeppelin/contracts
npm install @openzeppelin/contracts-upgradeable
for upgradeable contracts
Finally, if you’re looking for an easy way to manage and automate operations for the contracts you deploy, check out OpenZeppelin Defender and sign up for a free account.
Build a voting token with ERC20Votes and ERC20VotesComp
On-chain governance, as implemented by Compound’s governor contracts and used by many prominent projects (Compound, Uniswap, Gitcoin and more), gives voting power to token holders. While the tokens are ERC20, their latest balance is not used when querying voting power. A separate mechanism is required to ensure that the same tokens cannot be used to vote multiple times if they are transferred during the voting windows. This mechanism also includes delegation logic, allowing a user to delegate his or her votes to a trusted party.
With the increased adoption of governance systems based on Compound’s COMP token, we decided to provide a compatible extension that can be added to any OpenZeppelin based ERC20 contract, turning it into a governance-compatible token.
This extension comes in two variants:
ERC20Votes
, an extension that provides all the features of the Comp token, with support for a total supply of up to 2224 but with interfaces that are not compatible with GovernorAlpha & GovernorBravo. It will, however, be compatible with our own governor system, as part of the 4.3 release.ERC20VotesComp
, an extension that provides all the features of the COMP token, with the COMP interface, but is limited to a total supply of 296 (like COMP). It will be compatible with GovernorAlpha and GovernorBravo as well as with our own governor system.
Both versions are mostly compatible with COMP token – specifically the following identical aspects:
- Both versions include the functions
delegate
,delegateBySig
anddelegates
making them compatible with delegation management UIs. - Both versions emit the events
DelegateChanged
andDelegateVotesChanged
making them compatible with existing indexing logic. - Both versions include similar checkpointing logic.
The interface difference between the two modules only concerns the functions that query the vote count, getPastVotes
returns uint256
while COMP’s getPriorVotes
returns uint96
, which may be restrictive under some conditions. The governor system we plan to release in 4.3 will be compatible with both modules.
How to choose between the two?
You should use ERC20Votes
if:
- You need to support supply above 296
- You don’t plan to use GovernorAlpha or GovernorBravo with your token
- You want to reduce your deployment cost
You should use ERC20VotesComp
if:
- Your total supply will never go over 296
- You want to use your token in conjunction with GovernorAlpha or GovernorBravo
Wrap a token with ERC20Wrapper
Token instances deployed using the OpenZeppelin upgrades plugin can easily benefit from the new ERC20Votes module through an upgrade. However, for tokens that are not upgradeable, another option is to wrap them into a new ERC20 token with additional features.
The new ERC20Wrapper
extension allows for easy implementation of such a wrapped token. It includes both a deposit and a withdrawal mechanism enabling the wrapping and unwrapping of tokens. While the wrapping mechanism mints wrapped tokens when taking ownership of underlying tokens, the unwrapping mechanism requires burning wrapped tokens in order to unlock underlying tokens.
Tracking supply of ERC1155 tokens
A new extension for the ERC1155 token standard allows you to keep track of the total supply for each token id. This will help distinguish between fungible and non-fungible tokens. This is an optional module that, when enabled, will slightly increase the cost of minting and burning ERC1155 tokens. It adds no additional costs to transfers and approvals.
More
- Code optimizations result in slight gas cost reductions for
ERC20
,EnumerableSet
andEnumerableMap
. - New
Math.ceilDiv
function returning the rounded-up result of an integer division. - A new
Counter.reset
function resets the Counter to 0.
Get Started
Use Contracts Wizard to leverage OpenZeppelin Contracts and bootstrap your code in minutes.
Install from npm for local development:
npm install @openzeppelin/contracts
npm install @openzeppelin/contracts-upgradeable
for upgradeable contracts
Learn more
Finally, if you’re looking for an easy way to manage and automate operations for the contracts you deploy, you can learn more about OpenZeppelin Defender and sign up for a free account.
Be part of the community
- Continue the discussion on our forum 📖
- Join our Discord ⚡
- Follow us on Twitter 🐥
- Even better, join the team 🚀