VotesExtended
Inherits: Votes
*Extension of {Votes} that adds checkpoints for delegations and balances. WARNING: While this contract extends {Votes}, valid uses of {Votes} may not be compatible with {VotesExtended} without additional considerations. This implementation of {_transferVotingUnits} must run AFTER the voting weight movement is registered, such that it is reflected on {_getVotingUnits}. Said differently, {VotesExtended} MUST be integrated in a way that calls {_transferVotingUnits} AFTER the asset transfer is registered and balances are updated:
contract VotingToken is Token, VotesExtended {
function transfer(address from, address to, uint256 tokenId) public override {
super.transfer(from, to, tokenId); // <- Perform the transfer first ...
_transferVotingUnits(from, to, 1); // <- ... then call _transferVotingUnits.
}
function _getVotingUnits(address account) internal view override returns (uint256) {
return balanceOf(account);
}
}
{ERC20Votes} and {ERC721Votes} follow this pattern and are thus safe to use with {VotesExtended}.*
State Variables
_userDelegationCheckpoints
mapping(address delegator => Checkpoints.Trace160) private _userDelegationCheckpoints;
_userVotingUnitsCheckpoints
mapping(address account => Checkpoints.Trace208) private _userVotingUnitsCheckpoints;
Functions
getPastDelegate
*Returns the delegate of an account 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.
Requirements:
timepointmust be in the past. If operating using block numbers, the block must be already mined.*
function getPastDelegate(address account, uint256 timepoint) public view virtual returns (address);
getPastBalanceOf
*Returns the balanceOf of an account 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.
Requirements:
timepointmust be in the past. If operating using block numbers, the block must be already mined.*
function getPastBalanceOf(address account, uint256 timepoint) public view virtual returns (uint256);
_delegate
Delegate all of account's voting units to delegatee.
Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
function _delegate(address account, address delegatee) internal virtual override;
_transferVotingUnits
Transfers, mints, or burns voting units. To register a mint, from should be zero. To register a burn, to
should be zero. Total supply of voting units will be adjusted with mints and burns.
function _transferVotingUnits(address from, address to, uint256 amount) internal virtual override;