@@ -5,10 +5,8 @@ import {Ownable} from "@solady/auth/Ownable.sol";
55import {Multicallable} from "@solady/utils/Multicallable.sol " ;
66import {ERC1155 } from "@solady/tokens/ERC1155.sol " ;
77
8- import {HookFlagsDirectory} from "../../hook/HookFlagsDirectory.sol " ;
9- import {HookInstaller} from "../HookInstaller.sol " ;
8+ import {CoreContract} from "../CoreContract.sol " ;
109
11- import {IERC1155HookInstaller } from "../../interface/IERC1155HookInstaller.sol " ;
1210import {BeforeMintHookERC1155} from "../../hook/BeforeMintHookERC1155.sol " ;
1311import {BeforeTransferHookERC1155} from "../../hook/BeforeTransferHookERC1155.sol " ;
1412import {BeforeBatchTransferHookERC1155} from "../../hook/BeforeBatchTransferHookERC1155.sol " ;
@@ -17,7 +15,7 @@ import {BeforeApproveForAllHook} from "../../hook/BeforeApproveForAllHook.sol";
1715import {OnTokenURIHook} from "../../hook/OnTokenURIHook.sol " ;
1816import {OnRoyaltyInfoHook} from "../../hook/OnRoyaltyInfoHook.sol " ;
1917
20- contract ERC1155Core is ERC1155 , HookInstaller , Ownable , Multicallable , IERC1155HookInstaller , HookFlagsDirectory {
18+ contract ERC1155Core is ERC1155 , CoreContract , Ownable , Multicallable {
2119 /*//////////////////////////////////////////////////////////////
2220 STORAGE
2321 //////////////////////////////////////////////////////////////*/
@@ -39,16 +37,10 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
3937 //////////////////////////////////////////////////////////////*/
4038
4139 /// @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 ();
4641
4742 /// @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 ();
5244
5345 /// @notice Emitted on an attempt to mint tokens when no beforeMint hook is installed.
5446 error ERC1155CoreMintDisabled ();
@@ -60,23 +52,14 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
6052 /// @notice Emitted when the contract URI is updated.
6153 event ContractURIUpdated ();
6254
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- */
7355 constructor (
7456 string memory _name ,
7557 string memory _symbol ,
7658 string memory _contractURI ,
7759 address _owner ,
78- OnInitializeParams memory _onInitializeCall ,
79- InstallHookParams[] memory _hooksToInstall
60+ address [] memory _extensionsToInstall ,
61+ address _initCallTarget ,
62+ bytes memory _initCalldata
8063 ) payable {
8164 // Set contract metadata
8265 name_ = _name;
@@ -86,26 +69,15 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
8669 // Set contract owner
8770 _setOwner (_owner);
8871
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 );
10176 }
10277
10378 // 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]);
10981 }
11082 }
11183
@@ -171,17 +143,19 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
171143 || _interfaceId == 0x2a55205a ; // ERC165 Interface ID for ERC-2981
172144 }
173145
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 ;
185159 }
186160
187161 /*//////////////////////////////////////////////////////////////
@@ -275,20 +249,12 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
275249 INTERNAL FUNCTIONS
276250 //////////////////////////////////////////////////////////////*/
277251
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 ();
286254 }
287255
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 ();
292258 }
293259
294260 /// @dev Sets contract URI
@@ -303,29 +269,30 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
303269
304270 /// @dev Calls the beforeMint hook.
305271 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 );
307273
308274 if (hook != address (0 )) {
309275 (bool success , bytes memory returndata ) = hook.call {value: msg .value }(
310276 abi.encodeWithSelector (BeforeMintHookERC1155.beforeMintERC1155.selector , _to, _tokenId, _value, _data)
311277 );
312- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
278+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
313279 } else {
314280 revert ERC1155CoreMintDisabled ();
315281 }
316282 }
317283
318284 /// @dev Calls the beforeTransfer hook, if installed.
319285 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 );
321288
322289 if (hook != address (0 )) {
323290 (bool success , bytes memory returndata ) = hook.call {value: msg .value }(
324291 abi.encodeWithSelector (
325292 BeforeTransferHookERC1155.beforeTransferERC1155.selector , _from, _to, _tokenId, _value
326293 )
327294 );
328- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
295+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
329296 }
330297 }
331298
@@ -334,47 +301,48 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
334301 internal
335302 virtual
336303 {
337- address hook = getHookImplementation (BEFORE_BATCH_TRANSFER_ERC1155_FLAG);
304+ address hook =
305+ getCallbackFunctionImplementation (BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector );
338306
339307 if (hook != address (0 )) {
340308 (bool success , bytes memory returndata ) = hook.call {value: msg .value }(
341309 abi.encodeWithSelector (
342310 BeforeBatchTransferHookERC1155.beforeBatchTransferERC1155.selector , _from, _to, _tokenIds, _values
343311 )
344312 );
345- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
313+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
346314 }
347315 }
348316
349317 /// @dev Calls the beforeBurn hook, if installed.
350318 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 );
352320
353321 if (hook != address (0 )) {
354322 (bool success , bytes memory returndata ) = hook.call {value: msg .value }(
355323 abi.encodeWithSelector (
356324 BeforeBurnHookERC1155.beforeBurnERC1155.selector , _operator, _tokenId, _value, _data
357325 )
358326 );
359- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
327+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
360328 }
361329 }
362330
363331 /// @dev Calls the beforeApprove hook, if installed.
364332 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 );
366334
367335 if (hook != address (0 )) {
368336 (bool success , bytes memory returndata ) = hook.call {value: msg .value }(
369337 abi.encodeWithSelector (BeforeApproveForAllHook.beforeApproveForAll.selector , _from, _to, _approved)
370338 );
371- if (! success) _revert (returndata, ERC1155CoreHookCallFailed .selector );
339+ if (! success) _revert (returndata, ERC1155CoreCallbackFailed .selector );
372340 }
373341 }
374342
375343 /// @dev Fetches token URI from the token metadata hook.
376344 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 );
378346
379347 if (hook != address (0 )) {
380348 _uri = OnTokenURIHook (hook).onTokenURI (_tokenId);
@@ -388,7 +356,7 @@ contract ERC1155Core is ERC1155, HookInstaller, Ownable, Multicallable, IERC1155
388356 virtual
389357 returns (address receiver , uint256 royaltyAmount )
390358 {
391- address hook = getHookImplementation (ON_ROYALTY_INFO_FLAG );
359+ address hook = getCallbackFunctionImplementation (OnRoyaltyInfoHook.onRoyaltyInfo. selector );
392360
393361 if (hook != address (0 )) {
394362 (receiver, royaltyAmount) = OnRoyaltyInfoHook (hook).onRoyaltyInfo (_tokenId, _salePrice);
0 commit comments