Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4.9 KiB
ERC20Votes
ERC20 with votes based on ERC5805 and ERC6372.
Inherits:
Custom Errors
ERC5805FutureLookup()
error ERC5805FutureLookup()
The timepoint is in the future.
ERC5805DelegateSignatureExpired()
error ERC5805DelegateSignatureExpired()
The ERC5805 signature to set a delegate has expired.
ERC5805DelegateInvalidSignature()
error ERC5805DelegateInvalidSignature()
The ERC5805 signature to set a delegate is invalid.
ERC5805CheckpointIndexOutOfBounds()
error ERC5805CheckpointIndexOutOfBounds()
Out-of-bounds access for the checkpoints.
ERC5805CheckpointValueOverflow()
error ERC5805CheckpointValueOverflow()
Arithmetic overflow when pushing a new checkpoint.
ERC5805CheckpointValueUnderflow()
error ERC5805CheckpointValueUnderflow()
Arithmetic underflow when pushing a new checkpoint.
Events
DelegateChanged(address,address,address)
event DelegateChanged(
address indexed delegator, address indexed from, address indexed to
)
The delegate of delegator is changed from from to to.
DelegateVotesChanged(address,uint256,uint256)
event DelegateVotesChanged(
address indexed delegate, uint256 oldValue, uint256 newValue
)
The votes balance of delegate is changed from oldValue to newValue.
ERC6372
CLOCK_MODE()
function CLOCK_MODE() public view virtual returns (string memory)
Returns the clock mode.
clock()
function clock() public view virtual returns (uint48 result)
Returns the current clock.
ERC5805
getVotes(address)
function getVotes(address account) public view virtual returns (uint256)
Returns the latest amount of voting units for account.
getPastVotes(address,uint256)
function getPastVotes(address account, uint256 timepoint)
public
view
virtual
returns (uint256)
Returns the latest amount of voting units account has before or during timepoint.
delegates(address)
function delegates(address delegator)
public
view
virtual
returns (address result)
Returns the current voting delegate of delegator.
delegate(address)
function delegate(address delegatee) public virtual
Set the voting delegate of the caller to delegatee.
delegateBySig(address,uint256,uint256,uint8,bytes32,bytes32)
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) public virtual
Sets the voting delegate of the signature signer to delegatee.
Other Vote Public View Functions
checkpointCount(address)
function checkpointCount(address account)
public
view
virtual
returns (uint256 result)
Returns the number of checkpoints for account.
checkpointAt(address,uint256)
function checkpointAt(address account, uint256 i)
public
view
virtual
returns (uint48 checkpointClock, uint256 checkpointValue)
Returns the voting checkpoint for account at index i.
getVotesTotalSupply()
function getVotesTotalSupply() public view virtual returns (uint256)
Returns the latest amount of total voting units.
getPastVotesTotalSupply(uint256)
function getPastVotesTotalSupply(uint256 timepoint)
public
view
virtual
returns (uint256)
Returns the latest amount of total voting units before or during timepoint.
Internal Functions
_getVotingUnits(address)
function _getVotingUnits(address delegator)
internal
view
virtual
returns (uint256)
Returns the amount of voting units delegator has control over.
Override if you need a different formula.
_afterTokenTransfer(address,address,uint256)
function _afterTokenTransfer(address from, address to, uint256 amount)
internal
virtual
override
ERC20 after token transfer internal hook.
_transferVotingUnits(address,address,uint256)
function _transferVotingUnits(address from, address to, uint256 amount)
internal
virtual
Used in _afterTokenTransfer(address from, address to, uint256 amount).
_moveDelegateVotes(address,address,uint256)
function _moveDelegateVotes(address from, address to, uint256 amount)
internal
virtual
Transfer amount of delegated votes from from to to.
Emits a DelegateVotesChanged event for each change of delegated votes.
_delegate(address,address)
function _delegate(address account, address delegatee) internal virtual
Delegates all of account's voting units to delegatee.
Emits the DelegateChanged and DelegateVotesChanged events.