2
2
// SPDX-License-Identifier: Apache 2.0
3
3
pragma solidity 0.8.19 ;
4
4
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 " ;
10
10
import {IImmutableERC1155Errors} from "../../../errors/Errors.sol " ;
11
11
12
12
abstract contract ERC1155Permit is ERC1155Burnable , EIP712 , IERC1155Permit , IImmutableERC1155Errors {
13
-
14
13
bytes32 private immutable _PERMIT_TYPEHASH =
15
14
keccak256 ("Permit(address owner,address spender,bool approved,uint256 nonce,uint256 deadline) " );
16
15
17
- mapping (address => uint256 ) private _nonces;
16
+ mapping (address account = > uint256 nonce ) private _nonces;
18
17
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 " ) {}
23
19
24
20
function permit (address owner , address spender , bool approved , uint256 deadline , bytes memory sig ) external {
21
+ // solhint-disable-next-line not-rely-on-time
25
22
if (deadline < block .timestamp ) {
26
23
revert PermitExpired ();
27
24
}
@@ -30,7 +27,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
30
27
31
28
// smart contract signature validation
32
29
if (_isValidERC1271Signature (owner, digest, sig)) {
33
- _setApprovalForAll (owner, spender, approved);
30
+ _setApprovalForAll (owner, spender, approved);
34
31
return ;
35
32
}
36
33
@@ -63,16 +60,15 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
63
60
* @param owner The address for which to retrieve the nonce.
64
61
* @return Current nonce of the given token.
65
62
*/
66
- function nonces (
67
- address owner
68
- ) external view returns (uint256 ) {
63
+ function nonces (address owner ) external view returns (uint256 ) {
69
64
return _nonces[owner];
70
65
}
71
66
72
67
/**
73
68
* @notice Returns the domain separator used in the encoding of the signature for permits, as defined by EIP-712
74
69
* @return the bytes32 domain separator
75
70
*/
71
+ // solhint-disable-next-line func-name-mixedcase
76
72
function DOMAIN_SEPARATOR () external view override returns (bytes32 ) {
77
73
return _domainSeparatorV4 ();
78
74
}
@@ -82,16 +78,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
82
78
* @param interfaceId The interface identifier, which is a 4-byte selector.
83
79
* @return True if the contract implements `interfaceId` and the call doesn't revert, otherwise false.
84
80
*/
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);
95
85
}
96
86
97
87
/**
@@ -107,18 +97,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
107
97
bool approved ,
108
98
uint256 deadline
109
99
) 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
+ );
122
104
}
123
105
124
106
/**
@@ -128,14 +110,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
128
110
* @param sig The actual signature bytes.
129
111
* @return True if the signature is valid according to EIP-1271, otherwise false.
130
112
*/
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 ) {
132
114
// slither-disable-next-line low-level-calls
133
115
(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)
139
117
);
140
118
141
119
if (success && res.length == 32 ) {
@@ -154,8 +132,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm
154
132
* @param owner The owner of the tokens.
155
133
* @return True if the signature is from an approved operator or owner, otherwise false.
156
134
*/
157
- function _isValidEOASignature (address recoveredSigner , address owner ) private pure returns (bool ) {
135
+ function _isValidEOASignature (address recoveredSigner , address owner ) private pure returns (bool ) {
158
136
return recoveredSigner != address (0 ) && recoveredSigner == owner;
159
137
}
160
-
161
138
}
0 commit comments