EpochBasedVoteToken
Inherits: IEpochBasedVoteToken, ERC5805, ERC20Extended
Author: M^0 Labs
State Variables
_totalSupplies
Store the total supply per epoch.
_balances
Store the balance per epoch per account.
_delegatees
Store the delegatee per epoch per account.
_votingPowers
Store the voting power per epoch per delegatee.
Functions
constructor
Constructs a new EpochBasedVoteToken contract.
Parameters
name_
string
The name of the token.
symbol_
string
The symbol of the token.
decimals_
uint8
The decimals of the token.
delegateBySig
Changes the voting power delegation for account
to delegatee
.
Parameters
account_
address
delegatee_
address
nonce_
uint256
expiry_
uint256
signature_
bytes
balanceOf
Returns the amount of tokens owned by account
.
getDelegationDigest
Returns the digest to be signed, via EIP-712, given an internal digest (i.e. hash struct).
Parameters
delegatee_
address
nonce_
uint256
expiry_
uint256
Returns
<none>
bytes32
The digest to be signed.
pastBalanceOf
Returns the token balance of account
at a past clock value epoch
.
Parameters
account_
address
epoch_
uint256
Returns
<none>
uint256
The token balance account
at epoch
.
clock
Returns the current timepoint according to the mode the contract is operating on.
delegates
Returns the delegatee the voting power of account
is delegated to.
Parameters
account_
address
Returns
<none>
address
The address of the account the voting power of account
will be delegated to.
pastDelegates
Returns the delegatee of account
at a past clock value epoch
.
Parameters
account_
address
epoch_
uint256
Returns
<none>
address
The delegatee of the voting power of account
at epoch
.
getVotes
Returns the total voting power of account
.
Parameters
account_
address
Returns
<none>
uint256
The total voting power of account
.
getPastVotes
Returns the total voting power of account
at a past clock value timepoint
.
Parameters
account_
address
epoch_
uint256
Returns
<none>
uint256
The total voting power of account
at clock value timepoint
.
totalSupply
Returns the amount of tokens in existence.
pastTotalSupply
Returns the total token supply at a past clock value epoch
.
Parameters
epoch_
uint256
Returns
<none>
uint256
The total token supply at epoch
.
CLOCK_MODE
Returns a machine-readable string description of the clock the contract is operating on.
_addBalance
Add amount_
to the balance of account_
, using unchecked math.
Parameters
account_
address
The address of the account to add the balance to.
amount_
uint240
The amount to add to the balance.
_addTotalSupply
Add amount_
to the total supply, using checked math.
Parameters
amount_
uint240
The amount to add to the total supply.
_addVotingPower
Add amount_
to the voting power of account_
, using unchecked math.
Parameters
account_
address
The address of the account to add the voting power to.
amount_
uint240
The amount to add to the voting power.
_delegate
Set a new delegatee for delegator_
.
Parameters
delegator_
address
The address of the account delegating voting power.
newDelegatee_
address
The address of the account receiving voting power.
_mint
Mint amount_
tokens to recipient_
.
Parameters
recipient_
address
The address of the account to mint tokens to.
amount_
uint256
The amount of tokens to mint.
_removeBalance
Subtract amount_
from the balance of account_
, using checked math.
Parameters
account_
address
The address of the account to subtract the balance from.
amount_
uint240
The amount to subtract from the balance.
_removeVotingPower
Subtract amount_
of voting power from the balance of account_
, using checked math.
Parameters
account_
address
The address of the account to subtract the voting power from.
amount_
uint240
The amount of voting power to subtract.
_setDelegatee
Set a new delegatee for delegator_
.
Parameters
delegator_
address
The address of the account delegating voting power.
delegatee_
address
The address of the account receiving voting power.
Returns
oldDelegatee_
address
The address of the previous delegatee of delegator_
.
_transfer
Transfer amount_
tokens from sender_
to recipient_
.
Parameters
sender_
address
The address of the account to transfer tokens from.
recipient_
address
The address of the account to transfer tokens to.
amount_
uint256
The amount of tokens to transfer.
_update
Update a storage AmountSnap by amount_
given operation_
.
Parameters
amountSnaps_
AmountSnap[]
The storage pointer to an AmountSnap array to update.
operation_
function (uint240, uint240) internal pure returns (uint240)
The operation to perform on the old and new amounts.
amount_
uint240
The amount to update the Snap by.
Returns
oldAmount_
uint240
The previous latest amount of the Snap array.
newAmount_
uint240
The new latest amount of the Snap array.
_updateBalance
Update the balance of account_
by amount_
given operation_
.
Parameters
account_
address
The address of the account to update the balance of.
operation_
function (uint240, uint240) internal pure returns (uint240)
The operation to perform on the old and new amounts.
amount_
uint240
The amount to update the balance by.
_updateVotingPower
Update the voting power of delegatee_
by amount_
given operation_
.
Parameters
delegatee_
address
The address of the account to update the voting power of.
operation_
function (uint240, uint240) internal pure returns (uint240)
The operation to perform on the old and new amounts.
amount_
uint240
The amount to update the voting power by.
_clock
Returns the current timepoint according to the mode the contract is operating on.
Returns
<none>
uint16
Current timepoint.
_getBalance
Get the balance of account_
at epoch_
.
Parameters
account_
address
The address of the account to get the balance of.
epoch_
uint16
The epoch to get the balance at.
Returns
<none>
uint240
The balance of account_
at epoch_
.
_getDelegatee
Get the delegatee of account_
at epoch_
.
The delegatee is the account itself (the default) if no retrieved delegatee was found.
Parameters
account_
address
The address of the account to get the delegatee of.
epoch_
uint256
The epoch to get the delegatee at.
Returns
<none>
address
The delegatee of account_
at epoch_
.
_getTotalSupply
Get the total supply at epoch_
.
Parameters
epoch_
uint16
The epoch to get the total supply at.
Returns
<none>
uint240
The total supply at epoch_
.
_getValueAt
Get the value of an AmountSnap array at a given epoch.
Parameters
amountSnaps_
AmountSnap[]
The array of AmountSnaps to get the value of.
epoch_
uint16
The epoch to get the value at.
Returns
<none>
uint240
The value of the AmountSnap array at epoch_
.
_getVotes
The votes of account_
at epoch_
.
Parameters
account_
address
The address of the account to get the votes of.
epoch_
uint16
The epoch to get the votes at.
Returns
<none>
uint240
The votes of account_
at epoch_
.
_revertIfNotPastTimepoint
Revert if epoch_
is not in the past.
Parameters
epoch_
uint16
The epoch to check.
_revertIfInvalidRecipient
Reverts if the recipient of a mint
or transfer
is address(0).
Parameters
recipient_
address
Address of the recipient to check.
_add
Add b_
to a_
, using checked math.
Parameters
a_
uint240
The amount to add to.
b_
uint240
The amount to add.
Returns
<none>
uint240
The sum of a_
and b_
.
_addUnchecked
Add b_
to a_
, using unchecked math.
Parameters
a_
uint240
The amount to add to.
b_
uint240
The amount to add.
Returns
<none>
uint240
The sum of a_
and b_
.
_getDefaultIfZero
Return default_
if input_
is equal to address(0), else return input_
.
Parameters
input_
address
The input address.
default_
address
The default address.
Returns
<none>
address
The input address if not equal to the zero address, else the default address.
_sub
Subtract b_
from a_
, using checked math.
Parameters
a_
uint240
The amount to subtract from.
b_
uint240
The amount to subtract.
Returns
<none>
uint240
The difference of a_
and b_
.
_unsafeAccess
Returns the AmountSnap in an array at a given index without doing bounds checking.
Parameters
amountSnaps_
AmountSnap[]
The array of AmountSnaps to parse.
index_
uint256
The index of the AmountSnap to return.
Returns
amountSnap_
AmountSnap
The AmountSnap at index_
.
_unsafeAccess
Returns the AccountSnap in an array at a given index without doing bounds checking.
Parameters
accountSnaps_
AccountSnap[]
The array of AccountSnaps to parse.
index_
uint256
The index of the AccountSnap to return.
Returns
accountSnap_
AccountSnap
The AccountSnap at index_
.
Structs
AccountSnap
A 32-byte struct containing a starting epoch and an address that is valid until the next AccountSnap.
AmountSnap
A 32-byte struct containing a starting epoch and an amount that is valid until the next AmountSnap.