@@ -5,10 +5,8 @@ import {Ownable} from "@solady/auth/Ownable.sol";
5
5
import {Multicallable} from "@solady/utils/Multicallable.sol " ;
6
6
import {ERC1155 } from "@solady/tokens/ERC1155.sol " ;
7
7
8
- import {HookFlagsDirectory} from "../../hook/HookFlagsDirectory.sol " ;
9
- import {HookInstaller} from "../HookInstaller.sol " ;
8
+ import {CoreContract} from "../CoreContract.sol " ;
10
9
11
- import {IERC1155HookInstaller } from "../../interface/IERC1155HookInstaller.sol " ;
12
10
import {BeforeMintHookERC1155} from "../../hook/BeforeMintHookERC1155.sol " ;
13
11
import {BeforeTransferHookERC1155} from "../../hook/BeforeTransferHookERC1155.sol " ;
14
12
import {BeforeBatchTransferHookERC1155} from "../../hook/BeforeBatchTransferHookERC1155.sol " ;
@@ -17,7 +15,7 @@ import {BeforeApproveForAllHook} from "../../hook/BeforeApproveForAllHook.sol";
17
15
import {OnTokenURIHook} from "../../hook/OnTokenURIHook.sol " ;
18
16
import {OnRoyaltyInfoHook} from "../../hook/OnRoyaltyInfoHook.sol " ;
19
17
20
- contract ERC1155Core is ERC1155 , HookInstaller , Ownable , Multicallable , IERC1155HookInstaller , HookFlagsDirectory {
18
+ contract ERC1155Core is ERC1155 , CoreContract , Ownable , Multicallable {
21
19
/*//////////////////////////////////////////////////////////////
22
20
STORAGE
23
21
//////////////////////////////////////////////////////////////*/
@@ -39,16 +37,10 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
39
37
//////////////////////////////////////////////////////////////*/
40
38
41
39
/// @notice Emitted when the on initialize call fails.
42
- error ERC1155CoreOnInitializeCallFailed ();
43
-
44
- /// @notice Emitted when a hook initialization call fails.
45
- error ERC1155CoreHookInitializeCallFailed ();
40
+ error ERC1155CoreInitCallFailed ();
46
41
47
42
/// @notice Emitted when a hook call fails.
48
- error ERC1155CoreHookCallFailed ();
49
-
50
- /// @notice Emitted when insufficient value is sent in the constructor.
51
- error ERC1155CoreInsufficientValueInConstructor ();
43
+ error ERC1155CoreCallbackFailed ();
52
44
53
45
/// @notice Emitted on an attempt to mint tokens when no beforeMint hook is installed.
54
46
error ERC1155CoreMintDisabled ();
@@ -60,23 +52,14 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
60
52
/// @notice Emitted when the contract URI is updated.
61
53
event ContractURIUpdated ();
62
54
63
- /**
64
- * @notice Initializes the ERC1155 NFT collection.
65
- *
66
- * @param _name The name of the NFT collection.
67
- * @param _symbol The symbol of the NFT collection.
68
- * @param _contractURI The contract URI of the NFT collection.
69
- * @param _owner The owner of the contract.
70
- * @param _onInitializeCall Any external call to make on contract initialization.
71
- * @param _hooksToInstall Any hooks to install and initialize on contract initialization.
72
- */
73
55
constructor (
74
56
string memory _name ,
75
57
string memory _symbol ,
76
58
string memory _contractURI ,
77
59
address _owner ,
78
- OnInitializeParams memory _onInitializeCall ,
79
- InstallHookParams[] memory _hooksToInstall
60
+ address [] memory _extensionsToInstall ,
61
+ address _initCallTarget ,
62
+ bytes memory _initCalldata
80
63
) payable {
81
64
// Set contract metadata
82
65
name_ = _name;
@@ -86,26 +69,15 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
86
69
// Set contract owner
87
70
_setOwner (_owner);
88
71
89
- // Track native token value sent to the constructor
90
- uint256 constructorValue = msg .value ;
91
-
92
- // Initialize the core NFT collection
93
- if (_onInitializeCall.target != address (0 )) {
94
- if (constructorValue < _onInitializeCall.value) revert ERC1155CoreInsufficientValueInConstructor ();
95
- constructorValue -= _onInitializeCall.value;
96
-
97
- (bool success , bytes memory returndata ) =
98
- _onInitializeCall.target.call {value: _onInitializeCall.value}(_onInitializeCall.data);
99
-
100
- if (! success) _revert (returndata, ERC1155CoreOnInitializeCallFailed .selector );
72
+ // External call upon core core contract initialization.
73
+ if (_initCallTarget != address (0 ) && _initCalldata.length > 0 ) {
74
+ (bool success , bytes memory returndata ) = _initCallTarget.call {value: msg .value }(_initCalldata);
75
+ if (! success) _revert (returndata, ERC1155CoreInitCallFailed .selector );
101
76
}
102
77
103
78
// Install and initialize hooks
104
- for (uint256 i = 0 ; i < _hooksToInstall.length ; i++ ) {
105
- if (constructorValue < _hooksToInstall[i].initValue) revert ERC1155CoreInsufficientValueInConstructor ();
106
- constructorValue -= _hooksToInstall[i].initValue;
107
-
108
- _installHook (_hooksToInstall[i]);
79
+ for (uint256 i = 0 ; i < _extensionsToInstall.length ; i++ ) {
80
+ _installExtension (_extensionsToInstall[i]);
109
81
}
110
82
}
111
83
@@ -171,17 +143,19 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
171
143
|| _interfaceId == 0x2a55205a ; // ERC165 Interface ID for ERC-2981
172
144
}
173
145
174
- /// @notice Returns all of the contract's hooks and their implementations.
175
- function getAllHooks () external view returns (ERC1155Hooks memory hooks ) {
176
- hooks = ERC1155Hooks ({
177
- beforeMint: getHookImplementation (BEFORE_MINT_ERC1155_FLAG),
178
- beforeTransfer: getHookImplementation (BEFORE_TRANSFER_ERC1155_FLAG),
179
- beforeBatchTransfer: getHookImplementation (BEFORE_BATCH_TRANSFER_ERC1155_FLAG),
180
- beforeBurn: getHookImplementation (BEFORE_BURN_ERC1155_FLAG),
181
- beforeApproveForAll: getHookImplementation (BEFORE_APPROVE_FOR_ALL_FLAG),
182
- uri: getHookImplementation (ON_TOKEN_URI_FLAG),
183
- royaltyInfo: getHookImplementation (ON_ROYALTY_INFO_FLAG)
184
- });
146
+ function getSupportedCallbackFunctions ()
147
+ public
148
+ pure
149
+ override
150
+ returns (bytes4 [] memory supportedCallbackFunctions )
151
+ {
152
+ supportedCallbackFunctions = new bytes4 [](6 );
153
+ supportedCallbackFunctions[0 ] = BeforeMintHookERC1155.beforeMintERC1155.selector ;
154
+ supportedCallbackFunctions[1 ] = BeforeTransferHookERC1155.beforeTransferERC1155.selector ;
155
+ supportedCallbackFunctions[2 ] = BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector ;
156
+ supportedCallbackFunctions[3 ] = BeforeBurnHookERC1155.beforeBurnERC1155.selector ;
157
+ supportedCallbackFunctions[4 ] = BeforeApproveForAllHook.beforeApproveForAll.selector ;
158
+ supportedCallbackFunctions[5 ] = OnTokenURIHook.onTokenURI.selector ;
185
159
}
186
160
187
161
/*//////////////////////////////////////////////////////////////
@@ -275,20 +249,12 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
275
249
INTERNAL FUNCTIONS
276
250
//////////////////////////////////////////////////////////////*/
277
251
278
- /// @dev Returns whether the given caller can update hooks.
279
- function _canUpdateHooks (address _caller ) internal view override returns (bool ) {
280
- return _caller == owner ();
281
- }
282
-
283
- /// @dev Returns whether the caller can write to hooks.
284
- function _isAuthorizedToCallHookFallbackFunction (address _caller ) internal view override returns (bool ) {
285
- return _caller == owner ();
252
+ function _isAuthorizedToInstallExtensions (address _target ) internal view override returns (bool ) {
253
+ return _target == owner ();
286
254
}
287
255
288
- /// @dev Should return the supported hook flags.
289
- function _supportedHookFlags () internal view virtual override returns (uint256 ) {
290
- return BEFORE_MINT_ERC1155_FLAG | BEFORE_TRANSFER_ERC1155_FLAG | BEFORE_BATCH_TRANSFER_ERC1155_FLAG
291
- | BEFORE_BURN_ERC1155_FLAG | BEFORE_APPROVE_FOR_ALL_FLAG | ON_TOKEN_URI_FLAG | ON_ROYALTY_INFO_FLAG;
256
+ function _isAuthorizedToCallExtensionFunctions (address _target ) internal view override returns (bool ) {
257
+ return _target == owner ();
292
258
}
293
259
294
260
/// @dev Sets contract URI
@@ -303,29 +269,30 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
303
269
304
270
/// @dev Calls the beforeMint hook.
305
271
function _beforeMint (address _to , uint256 _tokenId , uint256 _value , bytes memory _data ) internal virtual {
306
- address hook = getHookImplementation (BEFORE_MINT_ERC1155_FLAG );
272
+ address hook = getCallbackFunctionImplementation (BeforeMintHookERC1155.beforeMintERC1155. selector );
307
273
308
274
if (hook != address (0 )) {
309
275
(bool success , bytes memory returndata ) = hook.call {value: msg .value }(
310
276
abi.encodeWithSelector (BeforeMintHookERC1155.beforeMintERC1155.selector , _to, _tokenId, _value, _data)
311
277
);
312
- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
278
+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
313
279
} else {
314
280
revert ERC1155CoreMintDisabled ();
315
281
}
316
282
}
317
283
318
284
/// @dev Calls the beforeTransfer hook, if installed.
319
285
function _beforeTransfer (address _from , address _to , uint256 _tokenId , uint256 _value ) internal virtual {
320
- address hook = getHookImplementation (BEFORE_TRANSFER_ERC1155_FLAG);
286
+ address hook =
287
+ getCallbackFunctionImplementation (BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector );
321
288
322
289
if (hook != address (0 )) {
323
290
(bool success , bytes memory returndata ) = hook.call {value: msg .value }(
324
291
abi.encodeWithSelector (
325
292
BeforeTransferHookERC1155.beforeTransferERC1155.selector , _from, _to, _tokenId, _value
326
293
)
327
294
);
328
- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
295
+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
329
296
}
330
297
}
331
298
@@ -334,47 +301,48 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
334
301
internal
335
302
virtual
336
303
{
337
- address hook = getHookImplementation (BEFORE_BATCH_TRANSFER_ERC1155_FLAG);
304
+ address hook =
305
+ getCallbackFunctionImplementation (BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector );
338
306
339
307
if (hook != address (0 )) {
340
308
(bool success , bytes memory returndata ) = hook.call {value: msg .value }(
341
309
abi.encodeWithSelector (
342
310
BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector , _from, _to, _tokenIds, _values
343
311
)
344
312
);
345
- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
313
+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
346
314
}
347
315
}
348
316
349
317
/// @dev Calls the beforeBurn hook, if installed.
350
318
function _beforeBurn (address _operator , uint256 _tokenId , uint256 _value , bytes memory _data ) internal virtual {
351
- address hook = getHookImplementation (BEFORE_BURN_ERC1155_FLAG );
319
+ address hook = getCallbackFunctionImplementation (BeforeBurnHookERC1155.beforeBurnERC1155. selector );
352
320
353
321
if (hook != address (0 )) {
354
322
(bool success , bytes memory returndata ) = hook.call {value: msg .value }(
355
323
abi.encodeWithSelector (
356
324
BeforeBurnHookERC1155.beforeBurnERC1155.selector , _operator, _tokenId, _value, _data
357
325
)
358
326
);
359
- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
327
+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
360
328
}
361
329
}
362
330
363
331
/// @dev Calls the beforeApprove hook, if installed.
364
332
function _beforeApproveForAll (address _from , address _to , bool _approved ) internal virtual {
365
- address hook = getHookImplementation (BEFORE_APPROVE_FOR_ALL_FLAG );
333
+ address hook = getCallbackFunctionImplementation (BeforeApproveForAllHook.beforeApproveForAll. selector );
366
334
367
335
if (hook != address (0 )) {
368
336
(bool success , bytes memory returndata ) = hook.call {value: msg .value }(
369
337
abi.encodeWithSelector (BeforeApproveForAllHook.beforeApproveForAll.selector , _from, _to, _approved)
370
338
);
371
- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
339
+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
372
340
}
373
341
}
374
342
375
343
/// @dev Fetches token URI from the token metadata hook.
376
344
function _getTokenURI (uint256 _tokenId ) internal view virtual returns (string memory _uri ) {
377
- address hook = getHookImplementation (ON_TOKEN_URI_FLAG );
345
+ address hook = getCallbackFunctionImplementation (OnTokenURIHook.onTokenURI. selector );
378
346
379
347
if (hook != address (0 )) {
380
348
_uri = OnTokenURIHook (hook).onTokenURI (_tokenId);
@@ -388,7 +356,7 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
388
356
virtual
389
357
returns (address receiver , uint256 royaltyAmount )
390
358
{
391
- address hook = getHookImplementation (ON_ROYALTY_INFO_FLAG );
359
+ address hook = getCallbackFunctionImplementation (OnRoyaltyInfoHook.onRoyaltyInfo. selector );
392
360
393
361
if (hook != address (0 )) {
394
362
(receiver, royaltyAmount) = OnRoyaltyInfoHook (hook).onRoyaltyInfo (_tokenId, _salePrice);
0 commit comments