ERC20PermitFacet
EIP-2612 permit functionality for ERC-20 tokens
- Implements EIP-2612
permitfunction for off-chain approvals. - Exposes
noncesandDOMAIN_SEPARATORfor signature verification. - Integrates with Compose diamond storage pattern.
Overview
This facet implements EIP-2612 permit functionality, enabling off-chain approvals for ERC-20 token transfers within a Compose diamond. It exposes the permit function to set allowances via signatures and provides nonces and DOMAIN_SEPARATOR for signature validation. Developers integrate this facet to allow users to grant token spending permissions without direct on-chain transactions.
Storage
ERC20Storage
ERC20PermitStorage
State Variables
| Property | Type | Description |
|---|---|---|
ERC20_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.erc20")) |
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.erc20.permit")) |
Functions
nonces
Returns the current nonce for an owner. This value changes each time a permit is used.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The address of the owner. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The current nonce. |
DOMAIN_SEPARATOR
Returns the domain separator used in the encoding of the signature for permit. This value is unique to a contract and chain ID combination to prevent replay attacks.
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes32 | The domain separator. |
permit
Sets the allowance for a spender via a signature. This function implements EIP-2612 permit functionality.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | The address of the token owner. |
_spender | address | The address of the spender. |
_value | uint256 | The amount of tokens to approve. |
_deadline | uint256 | The deadline for the permit (timestamp). |
_v | uint8 | The recovery byte of the signature. |
_r | bytes32 | The r value of the signature. |
_s | bytes32 | The s value of the signature. |
Events
Errors
Best Practices
- Integrate the
ERC20PermitFacetduring diamond initialization. - Ensure
DOMAIN_SEPARATORis correctly configured for the specific chain and diamond. - Validate signature parameters (
_v,_r,_s) before relaying them to thepermitfunction.
Security Considerations
The permit function allows setting allowances via signatures. Ensure correct implementation of signature verification logic by consumers of this facet. Reentrancy is not applicable as permit only modifies storage. Input validation for spender and value is handled internally. Follow standard Solidity security practices.