ERC20VotesLib
Title: ERC20VotesLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Votes.sol)
Library adding checkpoint-based voting power to ERC-20 tokens.
No own storage — uses ERC20 and Votes slots already present in Diamond storage. No init and no ERC-165 registration either: IERC20Votes declares only errors, so its interfaceId is the meaningless 0x00000000 (the voting surface is advertised as IVotes by VotesLib). Max token supply is capped at type(uint208).max so checkpoint values never overflow.
Functions
_maxSupply
Returns the maximum supply that can be checkpointed safely (type(uint208).max).
function _maxSupply() internal pure returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
numCheckpoints
Returns the number of checkpoints stored for account.
Matches OZ ERC20Votes.numCheckpoints — used by governance frameworks and indexers.
function numCheckpoints(address account) internal view returns (uint32);Parameters
| Name | Type | Description |
|---|---|---|
| account | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint32 |
checkpoints
Returns the checkpoint at position pos for account (0-indexed).
Matches OZ ERC20Votes.checkpoints — used by governance frameworks and indexers.
function checkpoints(address account, uint32 pos) internal view returns (Checkpoints.Checkpoint208 memory);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| pos | uint32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | Checkpoints.Checkpoint208 |
transfer
ERC-20 transfer with vote-checkpoint update.
Uses msg.sender for Diamond-compatible caller resolution.
function transfer(address to, uint256 value) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| to | address | |
| value | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
transferFrom
ERC-20 transferFrom with vote-checkpoint update.
function transferFrom(address from, address to, uint256 value) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| value | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
_mint
Mints value tokens to to, enforcing the uint208 supply cap.
Follows OZ v5 order: update balances first, then check post-mint supply against cap. This matches OZ ERC20Votes._update which calls super._update before reading totalSupply().
function _mint(address to, uint256 value) internal;Parameters
| Name | Type | Description |
|---|---|---|
| to | address | |
| value | uint256 |
_burn
Burns value tokens from from.
function _burn(address from, uint256 value) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| value | uint256 |
delegate
Delegates votes from the caller to delegatee.
Reads caller's ERC-20 balance as voting units before delegating.
function delegate(address delegatee) internal;Parameters
| Name | Type | Description |
|---|---|---|
| delegatee | address |
delegateBySig
Delegates votes via an EIP-712 signature, using the signer's ERC-20 balance.
Two-step: recover the signer first (VotesLib._recoverDelegationSigner, which also checks expiry)
to read their balance, then consume the nonce with NoncesLib.useCheckedNonce and delegate.
Both ERC20Votes and the standalone Votes facet route delegateBySig here.
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) internal;Parameters
| Name | Type | Description |
|---|---|---|
| delegatee | address | |
| nonce | uint256 | |
| expiry | uint256 | |
| v | uint8 | |
| r | bytes32 | |
| s | bytes32 |