ERC20PermitMod
ERC-2612 permit and domain separator logic
- Provides internal functions for ERC-2612 permit logic.
- Includes
DOMAIN_SEPARATOR()for signature validation. - Leverages diamond storage pattern for state management.
- Functions are internal, intended for use by other facets.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for managing ERC-2612 permit logic and domain separators within a diamond. Facets can import this module to handle permit validation and signature encoding, leveraging shared diamond storage. The domain separator ensures signature uniqueness per contract and chain ID, preventing replay attacks.
Storage
ERC20PermitStorage
storage-location: erc8042:compose.erc20.permit
ERC20Storage
storage-location: erc8042:compose.erc20
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
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. |
getERC20Storage
getPermitStorage
permit
Validates a permit signature and sets allowance. Emits Approval event; must be emitted by the calling facet/contract.
Parameters:
| Property | Type | Description |
|---|---|---|
_owner | address | Token owner. |
_spender | address | Token spender. |
_value | uint256 | Allowance value. |
_deadline | uint256 | Permit's time deadline. |
Events
Errors
Best Practices
- Use the
permitfunction within a facet that manages ERC-20 allowances. - Call
DOMAIN_SEPARATOR()to obtain the correct domain separator for signature generation. - Ensure the calling facet emits the
Approvalevent after a successful permit validation.
Integration Notes
This module interacts with diamond storage via the ERC20_STORAGE_POSITION slot, identified by keccak256("compose.erc20"). The ERC20PermitStorage and ERC20Storage structs are utilized. Changes to state, such as allowance updates after permit validation, are managed by the calling facet, ensuring composability within the diamond storage pattern.