GovernanceWrappedERC20
Contract · src/erc20/GovernanceWrappedERC20.sol
Explained in: Governance tokens
Author: Aragon X
Inherits: IGovernanceWrappedERC20, Initializable, ERC165Upgradeable, ERC20VotesUpgradeable, ERC20WrapperUpgradeable
Wraps an existing ERC-20 token by inheriting from ERC20WrapperUpgradeable and allows using it for voting by inheriting from ERC20VotesUpgradeable. The latter is compatible with OpenZeppelin's Votes interface. The contract supports meta transactions. To use an amount of underlying tokens for voting, the token owner must:
- call
approvefor the tokens to be used by this contract - call
depositForto wrap them, which safely transfers the underlying ERC-20 tokens to the contract and mints wrapped ERC-20 tokens. To get the ERC-20 tokens back, the owner of the wrapped tokens can callwithdrawFor, which burns the wrapped ERC-20 tokens and safely transfers the underlying tokens back to the owner.
Dev: This contract intentionally has no public mint functionality because this is the responsibility of the underlying ERC-20 token contract.
security-contact: sirt@aragon.org
Constructor
constructor
constructor(IERC20Upgradeable _token, string _name, string _symbol)Calls the initialize function.
| Parameter | Type | Description |
|---|---|---|
_token | IERC20Upgradeable | The underlying ERC-20 token. |
_name | string | The name of the wrapped token. |
_symbol | string | The symbol of the wrapped token. |
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
decimals
function decimals() external view returns (uint8)Selector: 0x313ce567
Dev: Uses the
decimalsof the underlying ERC-20 token.
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.
depositFor
function depositFor(address account, uint256 amount) external returns (bool)Selector: 0x2f4f21e2
Deposits an amount of underlying token and mints the corresponding number of wrapped tokens for a receiving address.
| Parameter | Type | Description |
|---|---|---|
account | address | The address receiving the minted, wrapped tokens. |
amount | uint256 | The amount of tokens to deposit. |
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.
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(IERC20Upgradeable _token, string _name, string _symbol) externalSelector: 0x90657147
Initializes the contract.
| Parameter | Type | Description |
|---|---|---|
_token | IERC20Upgradeable | The underlying ERC-20 token. |
_name | string | The name of the wrapped token. |
_symbol | string | The symbol of the wrapped token. |
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.
underlying
function underlying() external view returns (IERC20Upgradeable)Selector: 0x6f307dc3
Dev: Returns the address of the underlying ERC-20 token that is being wrapped.
withdrawTo
function withdrawTo(address account, uint256 amount) external returns (bool)Selector: 0x205c2878
Withdraws an amount of underlying tokens to a receiving address and burns the corresponding number of wrapped tokens.
| Parameter | Type | Description |
|---|---|---|
account | address | The address receiving the withdrawn, underlying tokens. |
amount | uint256 | The amount of underlying tokens to withdraw. |
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.
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.
Structs
Checkpoint
Inherited from ERC20VotesUpgradeable.
struct Checkpoint {
uint32 fromBlock;
uint224 votes;
}