22// SPDX-License-Identifier: Apache 2.0
33pragma solidity 0.8.19 ;
44
5- import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol " ;
6- import "@openzeppelin/contracts/utils/cryptography/EIP712.sol " ;
7- import "@openzeppelin/contracts/interfaces/IERC1271.sol " ;
8- import "solidity-bytes-utils/contracts/BytesLib.sol " ;
9- import "./IERC1155Permit.sol " ;
5+ import { ERC1155Burnable , ERC1155 } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol " ;
6+ import {EIP712, ECDSA} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol " ;
7+ import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol " ;
8+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol " ;
9+ import { IERC1155Permit } from "./IERC1155Permit.sol " ;
1010import {IImmutableERC1155Errors} from "../../../errors/Errors.sol " ;
1111
1212abstract contract ERC1155Permit is ERC1155Burnable , EIP712 , IERC1155Permit , IImmutableERC1155Errors {
13-
1413 bytes32 private immutable _PERMIT_TYPEHASH =
1514 keccak256 ("Permit(address owner,address spender,bool approved,uint256 nonce,uint256 deadline) " );
1615
17- mapping (address => uint256 ) private _nonces;
16+ mapping (address account = > uint256 nonce ) private _nonces;
1817
19- constructor (string memory name , string memory uri )
20- ERC1155 (uri)
21- EIP712 (name, "1 " )
22- {}
18+ constructor (string memory name , string memory uri ) ERC1155 (uri) EIP712 (name, "1 " ) {}
2319
2420 function permit (address owner , address spender , bool approved , uint256 deadline , bytes memory sig ) external {
21+ // solhint-disable-next-line not-rely-on-time
2522 if (deadline < block .timestamp ) {
2623 revert PermitExpired ();
2724 }
@@ -30,7 +27,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
3027
3128 // smart contract signature validation
3229 if (_isValidERC1271Signature (owner, digest, sig)) {
33- _setApprovalForAll (owner, spender, approved);
30+ _setApprovalForAll (owner, spender, approved);
3431 return ;
3532 }
3633
@@ -63,16 +60,15 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
6360 * @param owner The address for which to retrieve the nonce.
6461 * @return Current nonce of the given token.
6562 */
66- function nonces (
67- address owner
68- ) external view returns (uint256 ) {
63+ function nonces (address owner ) external view returns (uint256 ) {
6964 return _nonces[owner];
7065 }
7166
7267 /**
7368 * @notice Returns the domain separator used in the encoding of the signature for permits, as defined by EIP-712
7469 * @return the bytes32 domain separator
7570 */
71+ // solhint-disable-next-line func-name-mixedcase
7672 function DOMAIN_SEPARATOR () external view override returns (bytes32 ) {
7773 return _domainSeparatorV4 ();
7874 }
@@ -82,16 +78,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
8278 * @param interfaceId The interface identifier, which is a 4-byte selector.
8379 * @return True if the contract implements `interfaceId` and the call doesn't revert, otherwise false.
8480 */
85- function supportsInterface (bytes4 interfaceId )
86- public
87- view
88- virtual
89- override (ERC1155 )
90- returns (bool )
91- {
92- return
93- interfaceId == type (IERC1155Permit ).interfaceId || // 0x9e3ae8e4
94- super .supportsInterface (interfaceId);
81+ function supportsInterface (bytes4 interfaceId ) public view virtual override (ERC1155 ) returns (bool ) {
82+ return
83+ interfaceId == type (IERC1155Permit ).interfaceId || // 0x9e3ae8e4
84+ super .supportsInterface (interfaceId);
9585 }
9686
9787 /**
@@ -107,18 +97,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
10797 bool approved ,
10898 uint256 deadline
10999 ) internal returns (bytes32 ) {
110- return _hashTypedDataV4 (
111- keccak256 (
112- abi.encode (
113- _PERMIT_TYPEHASH,
114- owner,
115- spender,
116- approved,
117- _nonces[owner]++ ,
118- deadline
119- )
120- )
121- );
100+ return
101+ _hashTypedDataV4 (
102+ keccak256 (abi.encode (_PERMIT_TYPEHASH, owner, spender, approved, _nonces[owner]++ , deadline))
103+ );
122104 }
123105
124106 /**
@@ -128,14 +110,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
128110 * @param sig The actual signature bytes.
129111 * @return True if the signature is valid according to EIP-1271, otherwise false.
130112 */
131- function _isValidERC1271Signature (address spender , bytes32 digest , bytes memory sig ) private view returns (bool ) {
113+ function _isValidERC1271Signature (address spender , bytes32 digest , bytes memory sig ) private view returns (bool ) {
132114 // slither-disable-next-line low-level-calls
133115 (bool success , bytes memory res ) = spender.staticcall (
134- abi.encodeWithSelector (
135- IERC1271 .isValidSignature.selector ,
136- digest,
137- sig
138- )
116+ abi.encodeWithSelector (IERC1271 .isValidSignature.selector , digest, sig)
139117 );
140118
141119 if (success && res.length == 32 ) {
@@ -154,8 +132,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
154132 * @param owner The owner of the tokens.
155133 * @return True if the signature is from an approved operator or owner, otherwise false.
156134 */
157- function _isValidEOASignature (address recoveredSigner , address owner ) private pure returns (bool ) {
135+ function _isValidEOASignature (address recoveredSigner , address owner ) private pure returns (bool ) {
158136 return recoveredSigner != address (0 ) && recoveredSigner == owner;
159137 }
160-
161138}
0 commit comments