GovernanceERC20
Contract · src/erc20/GovernanceERC20.sol
Explained in: Governance tokens
Author: Aragon X
Inherits: IERC20MintableUpgradeable, Initializable, ERC165Upgradeable, ERC20VotesUpgradeable, DaoAuthorizableUpgradeable
An OpenZeppelin Votes compatible ERC-20 token, used for voting and managed by a DAO.
security-contact: sirt@aragon.org
Constructor
constructor
constructor(IDAO _dao, string _name, string _symbol, GovernanceERC20.MintSettings _mintSettings)Calls the initialize function.
| Parameter | Type | Description |
|---|---|---|
_dao | IDAO | The managing DAO. |
_name | string | The name of the ERC-20 governance token. |
_symbol | string | The symbol of the ERC-20 governance token. |
_mintSettings | GovernanceERC20.MintSettings | The token mint settings struct containing the receivers, the amounts and ensureDelegationOnMint. |
Functions
allowance
function allowance(address owner, address spender) external view returns (uint256)Selector: 0xdd62ed3e
Dev: See {IERC20-allowance}.
approve
function approve(address spender, uint256 amount) external returns (bool)Selector: 0x095ea7b3
Dev: See {IERC20-approve}.
NOTE: If
amountis the maximumuint256, the allowance is not updated ontransferFrom. This is semantically equivalent to an infinite approval.Requirements:
spendercannot be the zero address.
balanceOf
function balanceOf(address account) external view returns (uint256)Selector: 0x70a08231
Dev: See {IERC20-balanceOf}.
checkpoints
function checkpoints(
address account,
uint32 pos
) external view returns (ERC20VotesUpgradeable.Checkpoint)Selector: 0xf1127ed8
Dev: Get the
pos-th checkpoint foraccount.
| Returns | Type | Description |
|---|---|---|
[0] | ERC20VotesUpgradeable.Checkpoint |
clock
function clock() external view returns (uint48)Selector: 0x91ddadf4
Dev: Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
CLOCK_MODE
function CLOCK_MODE() external view returns (string)Selector: 0x4bf5d7e9
Dev: Description of the clock
dao
function dao() external view returns (IDAO)Selector: 0x4162169f
Returns the DAO contract.
decimals
function decimals() external view returns (uint8)Selector: 0x313ce567
Dev: Returns the number of decimals used to get its user representation. For example, if
decimalsequals2, a balance of505tokens should be displayed to a user as5.05(505 / 10 ** 2).Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the default value returned by this function, unless it's overridden.
NOTE: This information is only used for display purposes: it in no way affects any of the arithmetic of the contract, including {IERC20-balanceOf} and {IERC20-transfer}.
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool)Selector: 0xa457c2d7
Dev: Atomically decreases the allowance granted to
spenderby the caller.This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}.
Emits an {Approval} event indicating the updated allowance.
Requirements:
spendercannot be the zero address.spendermust have allowance for the caller of at leastsubtractedValue.
delegate
function delegate(address delegatee) externalSelector: 0x5c19a95c
Dev: Delegate votes from the sender to
delegatee.
delegateBySig
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) externalSelector: 0xc3cda520
Dev: Delegates votes from signer to
delegatee
delegates
function delegates(address account) external view returns (address)Selector: 0x587cde1e
Dev: Get the address
accountis currently delegating to.
DOMAIN_SEPARATOR
function DOMAIN_SEPARATOR() external view returns (bytes32)Selector: 0x3644e515
Dev: Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
eip712Domain
function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)Selector: 0x84b0196e
Dev: See {EIP-5267}.
Available since v4.9.
freezeMinting
function freezeMinting() externalSelector: 0xc013f30f
Disables the mint() function permanently
getEnsureDelegationOnMint
function getEnsureDelegationOnMint() external view returns (bool)Selector: 0xd9957169
Whether mint() enables self delegation if the receiver has no delegate.
getMintingFrozen
function getMintingFrozen() external view returns (bool)Selector: 0x081f4b8c
Returns true if the ability to mint tokens has been frozen
getPastTotalSupply
function getPastTotalSupply(uint256 timepoint) external view returns (uint256)Selector: 0x8e539e8c
Dev: Retrieve the
totalSupplyat the end oftimepoint. Note, this value is the sum of all balances. It is NOT the sum of all the delegated votes!Requirements:
timepointmust be in the past
getPastVotes
function getPastVotes(address account, uint256 timepoint) external view returns (uint256)Selector: 0x3a46b1a8
Dev: Retrieve the number of votes for
accountat the end oftimepoint.Requirements:
timepointmust be in the past
getVotes
function getVotes(address account) external view returns (uint256)Selector: 0x9ab24eb0
Dev: Gets the current votes balance for
account
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) external returns (bool)Selector: 0x39509351
Dev: Atomically increases the allowance granted to
spenderby the caller.This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}.
Emits an {Approval} event indicating the updated allowance.
Requirements:
spendercannot be the zero address.
initialize
function initialize(
IDAO _dao,
string _name,
string _symbol,
GovernanceERC20.MintSettings _mintSettings
) externalSelector: 0x6273f4dc
Initializes the contract and mints tokens to a list of receivers.
| Parameter | Type | Description |
|---|---|---|
_dao | IDAO | The managing DAO. |
_name | string | The name of the ERC-20 governance token. |
_symbol | string | The symbol of the ERC-20 governance token. |
_mintSettings | GovernanceERC20.MintSettings | The token mint settings struct containing the receivers, the amounts and ensureDelegationOnMint. |
mint
function mint(address to, uint256 amount) externalSelector: 0x40c10f19
Mints tokens to an address.
| Parameter | Type | Description |
|---|---|---|
to | address | The address receiving the tokens. |
amount | uint256 | The amount of tokens to be minted. |
name
function name() external view returns (string)Selector: 0x06fdde03
Dev: Returns the name of the token.
nonces
function nonces(address owner) external view returns (uint256)Selector: 0x7ecebe00
Dev: Returns the current nonce for
owner. This value must be included whenever a signature is generated for {permit}. Every successful call to {permit} increasesowner's nonce by one. This prevents a signature from being used multiple times.
numCheckpoints
function numCheckpoints(address account) external view returns (uint32)Selector: 0x6fcfff45
Dev: Get number of checkpoints for
account.
permit
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) externalSelector: 0xd505accf
Dev: Sets
valueas the allowance ofspenderoverowner's tokens, givenowner's signed approval. IMPORTANT: The same issues {IERC20-approve} has related to transaction ordering also apply here. Emits an {Approval} event. Requirements: -spendercannot be the zero address. -deadlinemust be a timestamp in the future. -v,randsmust be a validsecp256k1signature fromownerover the EIP712-formatted function arguments. - the signature must useowner's current nonce (see {nonces}). For more information on the signature format, see the https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP section]. CAUTION: See Security Considerations above.
supportsInterface
function supportsInterface(bytes4 _interfaceId) external view returns (bool)Selector: 0x01ffc9a7
Checks if this or the parent contract supports an interface by its ID.
| Parameter | Type | Description |
|---|---|---|
_interfaceId | bytes4 | The ID of the interface. |
symbol
function symbol() external view returns (string)Selector: 0x95d89b41
Dev: Returns the symbol of the token, usually a shorter version of the name.
totalSupply
function totalSupply() external view returns (uint256)Selector: 0x18160ddd
Dev: See {IERC20-totalSupply}.
transfer
function transfer(address to, uint256 amount) external returns (bool)Selector: 0xa9059cbb
Dev: See {IERC20-transfer}.
Requirements:
tocannot be the zero address.- the caller must have a balance of at least
amount.
transferFrom
function transferFrom(address from, address to, uint256 amount) external returns (bool)Selector: 0x23b872dd
Dev: See {IERC20-transferFrom}.
Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {ERC20}.
NOTE: Does not update the allowance if the current allowance is the maximum
uint256.Requirements:
fromandtocannot be the zero address.frommust have a balance of at leastamount.- the caller must have allowance for
from's tokens of at leastamount.
Events
Approval
event Approval(address indexed owner, address indexed spender, uint256 value)Dev: Emitted when the allowance of a
spenderfor anowneris set by a call to {approve}.valueis the new allowance.
DelegateChanged
event DelegateChanged(
address indexed delegator,
address indexed fromDelegate,
address indexed toDelegate
)Dev: Emitted when an account changes their delegate.
DelegateVotesChanged
event DelegateVotesChanged(
address indexed delegate,
uint256 previousBalance,
uint256 newBalance
)Dev: Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
EIP712DomainChanged
event EIP712DomainChanged()Dev: MAY be emitted to signal that the domain could have changed.
Initialized
event Initialized(uint8 version)Dev: Triggered when the contract has been initialized or reinitialized.
MintingFrozen
event MintingFrozen()Emitted when minting is frozen permanently
Transfer
event Transfer(address indexed from, address indexed to, uint256 value)Dev: Emitted when
valuetokens are moved from one account (from) to another (to).Note that
valuemay be zero.
Errors
DaoUnauthorized
error DaoUnauthorized(address dao, address where, address who, bytes32 permissionId)Thrown if a call is unauthorized in the associated DAO.
| Parameter | Type | Description |
|---|---|---|
dao | address | The associated DAO. |
where | address | The context in which the authorization reverted. |
who | address | The address (EOA or contract) missing the permission. |
permissionId | bytes32 | The permission identifier. |
MintingIsFrozen
error MintingIsFrozen()Thrown when attempting to mint when minting is permanently disabled
MintSettingsArrayLengthMismatch
error MintSettingsArrayLengthMismatch(uint256 receiversArrayLength, uint256 amountsArrayLength)Thrown if the number of receivers and amounts specified in the mint settings do not match.
| Parameter | Type | Description |
|---|---|---|
receiversArrayLength | uint256 | The length of the receivers array. |
amountsArrayLength | uint256 | The length of the amounts array. |
Constants
Public, so each is also readable through a generated getter.
MINT_PERMISSION_ID
bytes32 public constant MINT_PERMISSION_ID = keccak256("MINT_PERMISSION");Value: 0xb737b436e6cc542520cb79ec04245c720c38eebfa56d9e2d99b043979db20e4c
The permission identifier to mint new tokens
Structs
Checkpoint
Inherited from ERC20VotesUpgradeable.
struct Checkpoint {
uint32 fromBlock;
uint224 votes;
}MintSettings
struct MintSettings {
address[] receivers;
uint256[] amounts;
bool ensureDelegationOnMint;
}The settings for the initial mint of the token.
Dev: The lengths of
receiversandamountsmust match.
| Field | Type | Description |
|---|---|---|
receivers | address[] | The receivers of the tokens. On initialization only. |
amounts | uint256[] | The amounts of tokens to be minted for each receiver. On initialization only. |
ensureDelegationOnMint | bool | Whether mint() calls should self delegate if the receiver doesn't have one. |