ERC20Upgradeable
Inherits: Initializable ↗, IERC20Permit ↗, IERC20 ↗, IERC20Metadata ↗
Modern and gas efficient ERC20 ↗ + EIP-2612 ↗ implementation.
State Variables
name
Returns the name of the token.
string public override name
symbol
Returns the symbol of the token.
string public override symbol
decimals
Returns the decimals places of the token.
uint8 public constant override decimals = 18
allowance
Returns the remaining number of tokens that spender is allowed
to spend on behalf of owner
mapping(address => mapping(address => uint256)) public override allowance
nonces
Returns the current nonce for owner. This value must be
included whenever a signature is generated for permit.
Every successful call to permit increases owner's nonce by one. This
prevents a signature from being used multiple times.
mapping(address => uint256) public override nonces
Functions
approve
Sets amount as the allowance of spender over the caller's tokens.
Front-Running Risk
Be aware of potential front-running attacks. See EIP-20 Discussion ↗ for details.
function approve(address spender, uint256 amount) public override returns (bool);
transfer
Moves amount tokens from the caller's account to to.
function transfer(address to, uint256 amount) public virtual override returns (bool);
transferFrom
Moves amount tokens from from to to using the allowance mechanism.
amount is then deducted from the caller's allowance.
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool);
permit
Sets value as the allowance of spender over owner's tokens using a signed approval.
Security Considerations
- The same front-running issues that affect
IERC20-approvealso apply here - Always verify signatures are using the latest nonce
- Be cautious of signature replay attacks
Emits an Approval event.
Requirements:
spendercannot be the zero addressdeadlinemust be a timestamp in the futurev,randsmust be a validsecp256k1signature fromownerover the EIP712-formatted function arguments- The signature must use
owner's current nonce (seenonces)
For more information, see EIP-2612 Specification ↗.
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
public
override;
DOMAIN_SEPARATOR
Returns the domain separator used in the encoding of the signature for permit, as defined by EIP712.
function DOMAIN_SEPARATOR() public view override returns (bytes32);