Skip to main content

ERC20Permit

Git Source

Inherits: ERC20, IERC20Permit, EIP712

Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].

Adds the permit method, which can be used to change an account's ERC20 allowance (see IERC20.allowance) by presenting a message signed by the account. By not relying on [IERC20.approve](/main/contracts/docs/src/external/OlympusERC20.sol/interface.IERC20#approve), the token holder account doesn't need to send a transaction, and thus is not required to hold Ether at all.

Available since v3.4.

Constants​

_PERMIT_TYPEHASH​

bytes32 private immutable _PERMIT_TYPEHASH =
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
);

State Variables​

_nonces​

mapping(address => Counters.Counter) private _nonces;

Functions​

constructor​

Initializes the EIP712 domain separator using the name parameter, and setting version to "1".

It's a good idea to use the same name that is defined as the ERC20 token name.

constructor(string memory name) EIP712(name, "1");

Parameters

NameTypeDescription
namestring

permit​

See IERC20Permit.permit.

function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override;

Parameters

NameTypeDescription
owneraddress
spenderaddress
valueuint256
deadlineuint256
vuint8
rbytes32
sbytes32

nonces​

See IERC20Permit.nonces.

function nonces(address owner) public view virtual override returns (uint256);

Parameters

NameTypeDescription
owneraddress

Returns

NameTypeDescription
<none>uint256

DOMAIN_SEPARATOR​

See IERC20Permit.DOMAIN_SEPARATOR.

function DOMAIN_SEPARATOR() external view override returns (bytes32);

Returns

NameTypeDescription
<none>bytes32

_useNonce​

"Consume a nonce": return the current value and increment.

Available since v4.1.

function _useNonce(address owner) internal virtual returns (uint256 current);

Parameters

NameTypeDescription
owneraddress

Returns

NameTypeDescription
currentuint256