Skip to content
Lattice

VotesLib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
<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

NameTypeDescription
<none>string

getVotes

Returns the current voting power of account.

function getVotes(address account) internal view returns (uint256);

Parameters

NameTypeDescription
accountaddress

Returns

NameTypeDescription
<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

NameTypeDescription
accountaddress
timepointuint256

Returns

NameTypeDescription
<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

NameTypeDescription
timepointuint256

Returns

NameTypeDescription
<none>uint256

delegates

Returns the current delegate of account.

function delegates(address account) internal view returns (address);

Parameters

NameTypeDescription
accountaddress

Returns

NameTypeDescription
<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

NameTypeDescription
delegateeaddress
votingUnitsuint256

_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

NameTypeDescription
delegateeaddress
nonceuint256
expiryuint256
vuint8
rbytes32
sbytes32

Returns

NameTypeDescription
signeraddress

_delegate

Changes the delegate of account to delegatee and moves votingUnits accordingly.

function _delegate(address account, address delegatee, uint256 votingUnits) internal;

Parameters

NameTypeDescription
accountaddress
delegateeaddress
votingUnitsuint256

_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

NameTypeDescription
fromaddress
toaddress
amountuint256

_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

NameTypeDescription
fromaddress
toaddress
amountuint256

_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

NameTypeDescription
valueuint256

Returns

NameTypeDescription
<none>uint208

_add

function _add(uint208 a, uint208 b) private pure returns (uint208);

Parameters

NameTypeDescription
auint208
buint208

Returns

NameTypeDescription
<none>uint208

_subtract

function _subtract(uint208 a, uint208 b) private pure returns (uint208);

Parameters

NameTypeDescription
auint208
buint208

Returns

NameTypeDescription
<none>uint208