VotesLib
Title: VotesLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/governance/utils/Votes.sol)
Library implementing delegation + checkpoint tracking for ERC-5805 / ERC-6372 voting.
Abstract building block: _getVotingUnits must be overridden by submodules (e.g. ERC20VotesLib).
Functions
votesStorage
function votesStorage() internal pure returns (VotesStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | VotesStorage |
__Votes_init
Initializes the Votes module and registers the IVotes interface.
Must be called inside a pre/postInitializer block.
function __Votes_init() internal;registerInterface
Registers support for the IVotes interface via ERC-165.
function registerInterface() internal;clock
Returns the current timepoint (block.timestamp cast to uint48).
function clock() internal view returns (uint48);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint48 |
CLOCK_MODE
Returns the ERC-6372 clock mode string.
Declared as view (not pure) to allow future overrides to add a consistency check (e.g., assert clock() == expected_mode) without mutability narrowing. Timestamp mode is an intentional deviation from OZ's default block-number mode.
function CLOCK_MODE() internal view returns (string memory);Returns
| Name | Type | Description |
|---|---|---|
| <none> | string |
getVotes
Returns the current voting power of account.
function getVotes(address account) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| account | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getPastVotes
Returns the voting power of account at a past timepoint.
Reverts with ERC5805FutureLookup if timepoint >= clock().
function getPastVotes(address account, uint256 timepoint) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| timepoint | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getPastTotalSupply
Returns the total token supply checkpointed at a past timepoint.
Reverts with ERC5805FutureLookup if timepoint >= clock().
function getPastTotalSupply(uint256 timepoint) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| timepoint | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
delegates
Returns the current delegate of account.
function delegates(address account) internal view returns (address);Parameters
| Name | Type | Description |
|---|---|---|
| account | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
delegate
Delegates votes from the caller to delegatee, using the provided voting units.
Submodules pass their token balance as votingUnits.
function delegate(address delegatee, uint256 votingUnits) internal;Parameters
| Name | Type | Description |
|---|---|---|
| delegatee | address | |
| votingUnits | uint256 |
_recoverDelegationSigner
Recovers the signer of a delegation EIP-712 signature and validates expiry. Does NOT consume the nonce or delegate. Useful for callers needing the signer address before deciding on voting units (e.g. ERC20VotesLib).
function _recoverDelegationSigner(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)
internal
view
returns (address signer);Parameters
| Name | Type | Description |
|---|---|---|
| delegatee | address | |
| nonce | uint256 | |
| expiry | uint256 | |
| v | uint8 | |
| r | bytes32 | |
| s | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| signer | address |
_delegate
Changes the delegate of account to delegatee and moves votingUnits accordingly.
function _delegate(address account, address delegatee, uint256 votingUnits) internal;Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| delegatee | address | |
| votingUnits | uint256 |
_moveDelegateVotes
Moves amount voting units from delegate from to delegate to.
Pushes new checkpoints and emits DelegateVotesChanged for any non-zero, non-self moves.
function _moveDelegateVotes(address from, address to, uint256 amount) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| amount | uint256 |
_transferVotingUnits
Called by submodules on token transfers to update total supply and delegated vote checkpoints.
If from == address(0), increases total supply checkpoint.
If to == address(0), decreases total supply checkpoint.
Always moves delegated votes between the delegates of from and to.
function _transferVotingUnits(address from, address to, uint256 amount) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| amount | uint256 |
_toUint208
Casts value to uint208, reverting with IVotes.VotesOverflowedVotingUnits on overflow.
Voting-unit checkpoints are uint208; silently truncating would corrupt vote accounting.
function _toUint208(uint256 value) private pure returns (uint208);Parameters
| Name | Type | Description |
|---|---|---|
| value | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint208 |
_add
function _add(uint208 a, uint208 b) private pure returns (uint208);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint208 | |
| b | uint208 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint208 |
_subtract
function _subtract(uint208 a, uint208 b) private pure returns (uint208);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint208 | |
| b | uint208 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint208 |