ERC20Votes
Hashgraph
ERC20 Votes Facet
Provides vote delegation and historical voting power queries for an ERC20 asset.
Delegates storage and vote accounting to ERC20VotesStorageWrapper. Initialisation is restricted to the default admin and may only occur before the facet is registered as ready.
Methods
CLOCK_MODE
function CLOCK_MODE() external view returns (string)
Description of the clock
Returns
| Name | Type | Description |
|---|---|---|
| _0 | string | undefined |
checkpoints
function checkpoints(address _account, uint256 _pos) external view returns (struct Checkpoints.Checkpoint)
Returns the checkpoint at a given position for an account's vote history.
Parameters
| Name | Type | Description |
|---|---|---|
| _account | address | Address whose checkpoint history is queried. |
| _pos | uint256 | Zero-based index into the account's checkpoint array. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | Checkpoints.Checkpoint | The checkpoint struct at the given position. |
clock
function clock() external view returns (uint48)
Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint48 | undefined |
delegate
function delegate(address _delegatee) external nonpayable
Delegates the caller's voting power to delegatee.
Requires the system to be operational, activated, and not paused.
Parameters
| Name | Type | Description |
|---|---|---|
| _delegatee | address | Address that will receive the caller's voting power. |
delegates
function delegates(address _account) external view returns (address)
Returns the delegate address that account has chosen.
Returns the delegate that account has chosen.
Parameters
| Name | Type | Description |
|---|---|---|
| _account | address | Address whose chosen delegate is queried. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | address | Address of the delegate chosen by account. |
getPastTotalSupply
function getPastTotalSupply(uint256 _timepoint) external view returns (uint256)
Returns the total vote supply available at a past timepoint.
Returns the total supply of votes available at a specific moment in the past. If the clock() is configured to use block numbers, this will return the value at the end of the corresponding block. NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes. Votes that have not been delegated are still part of total supply, even though they would not participate in a vote.
Parameters
| Name | Type | Description |
|---|---|---|
| _timepoint | uint256 | Block number or timestamp at which the total supply is resolved. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | Total vote supply at timepoint. |
getPastVotes
function getPastVotes(address _account, uint256 _timepoint) external view returns (uint256)
Returns the vote weight of account at a past timepoint.
Returns the amount of votes that account had at a specific moment in the past. If the clock() is configured to use block numbers, this will return the value at the end of the corresponding block.
Parameters
| Name | Type | Description |
|---|---|---|
| _account | address | Address whose historical vote weight is queried. |
| _timepoint | uint256 | Block number or timestamp at which the weight is resolved. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | Vote weight of account at timepoint. |
getVotes
function getVotes(address _account) external view returns (uint256)
Returns the current vote weight of account.
Returns the current amount of votes that account has.
Parameters
| Name | Type | Description |
|---|---|---|
| _account | address | Address whose current vote weight is queried. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | Current vote weight of account. |
initializeERC20Votes
function initializeERC20Votes(bool _activated) external nonpayable
Initialises the ERC-20Votes capability on the token.
Requires DEFAULT_ADMIN_ROLE and rejects repeated facet registration.
Parameters
| Name | Type | Description |
|---|---|---|
| _activated | bool | Whether the voting feature should be active after initialisation. |
isActivated
function isActivated() external view returns (bool)
Returns whether vote delegation functionality is active.
Reads the activation flag from ERC20VotesStorageWrapper without mutating state.
Returns
| Name | Type | Description |
|---|---|---|
| _0 | bool | True if ERC20Votes functionality is activated, false otherwise. |
numCheckpoints
function numCheckpoints(address _account) external view returns (uint256)
Returns the total number of vote checkpoints recorded for an account.
Parameters
| Name | Type | Description |
|---|---|---|
| _account | address | Address whose checkpoint count is queried. |
Returns
| Name | Type | Description |
|---|---|---|
| _0 | uint256 | The number of checkpoints stored for the account. |
Events
DelegateChanged
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate)
Emitted when an account changes their delegate
Parameters
| Name | Type | Description |
|---|---|---|
delegator indexed | address | The account that changed their delegation |
fromDelegate indexed | address | The previous delegate address |
toDelegate indexed | address | The new delegate address |
DelegateVotesChanged
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance)
Emitted when delegate votes change due to balance changes
Parameters
| Name | Type | Description |
|---|---|---|
delegate indexed | address | The delegate whose votes changed |
| previousBalance | uint256 | The previous vote balance |
| newBalance | uint256 | The new vote balance |
ERC20VotesInitialized
event ERC20VotesInitialized(bool activated)
Emitted once when the ERC-20Votes capability is initialised on a token.
Fires exclusively from initializeERC20Votes after the storage write succeeds.
Parameters
| Name | Type | Description |
|---|---|---|
| activated | bool | Whether the ERC-20Votes feature is active after initialisation. |
Errors
AbafChangeForBlockForbidden
error AbafChangeForBlockForbidden(uint256 blockNumber)
Raised when attempting to change ABAF for a block that is forbidden
Parameters
| Name | Type | Description |
|---|---|---|
| blockNumber | uint256 | The block number that is forbidden |
AccountHasNoRole
error AccountHasNoRole(address account, bytes32 role)
Thrown when an account does not hold a required role.
Parameters
| Name | Type | Description |
|---|---|---|
| account | address | The account that lacks the role. |
| role | bytes32 | The role that is not held. |
AssetNotOperational
error AssetNotOperational(bytes32 configId, uint256 versionId)
Raised by InitializerStorageWrapper.checkOperational (and the related isConfigVersionOperational helper) when an operation is attempted on a configuration version that has not yet been marked operational.
Parameters
| Name | Type | Description |
|---|---|---|
| configId | bytes32 | Resolver-proxy configuration whose operational status was checked. |
| versionId | uint256 | Configuration version whose operational status was checked. |
BrokenClockMode
error BrokenClockMode()
Raised when the clock mode is broken
Deactivated
error Deactivated()
Thrown when an operation guarded by onlyActivated is attempted on a token whose deactivation flag has already been set.
FacetAlreadyRegistered
error FacetAlreadyRegistered(bytes32 facetId, uint256 lastVersion)
Raised when an initialiser tries to register a facet that already has a non-zero last registered version (i.e. the facet is being re-initialised on a fresh install).
Parameters
| Name | Type | Description |
|---|---|---|
| facetId | bytes32 | Identifier of the offending facet. |
| lastVersion | uint256 | Last version recorded for that facet at the time of the check. |
FutureLookup
error FutureLookup(uint256 timepoint, uint256 currentClock)
Raised when querying past votes or supply with a future timepoint
Parameters
| Name | Type | Description |
|---|---|---|
| timepoint | uint256 | The requested future timepoint |
| currentClock | uint256 | The current clock value |
IsPaused
error IsPaused()
Thrown when an operation that requires the token to be unpaused is attempted while the token is paused (own flag or any external pause contract).
UnexpectedError
error UnexpectedError(bytes4 _errorId)
Reverts when an unreachable validation state is detected.
Replaces assertions for defensive handling of logically impossible states.
Parameters
| Name | Type | Description |
|---|---|---|
| _errorId | bytes4 | Identifier of the unexpected validation condition. |
UnrecognizedResolverProxyVersion
error UnrecognizedResolverProxyVersion(bytes8 _resolverProxyVersion)
Thrown when the provided proxy version does not match any BLR compatible standard.
Parameters
| Name | Type | Description |
|---|---|---|
| _resolverProxyVersion | bytes8 | proxy version that is not compatible with the BLR. |
WalletRecovered
error WalletRecovered()
Thrown when attempting to recover a wallet that has already been recovered.