@@ -10,24 +10,26 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
1010import "@openzeppelin/contracts/metatx/ERC2771Context.sol " ;
1111
1212// ========== Internal imports ==========
13- import { IByocFactory } from "./interfaces/IByocFactory .sol " ;
13+ import { IContractDeployer } from "./interfaces/IContractDeployer .sol " ;
1414import { TWRegistry } from "./TWRegistry.sol " ;
15- import "./ThirdwebContract.sol " ;
15+ import { IContractMetadataRegistry } from "./interfaces/IContractMetadataRegistry.sol " ;
16+ import { ThirdwebContract } from "./ThirdwebContract.sol " ;
1617
17- contract ByocFactory is IByocFactory , ERC2771Context , Multicall , AccessControlEnumerable {
18+ contract ContractDeployer is IContractDeployer , ERC2771Context , Multicall , AccessControlEnumerable {
1819 /*///////////////////////////////////////////////////////////////
1920 State variables
2021 //////////////////////////////////////////////////////////////*/
2122
2223 /// @dev The main thirdweb registry.
2324 TWRegistry private immutable registry;
25+ /// @dev The contract metadta registry.
26+ IContractMetadataRegistry private immutable metadataRegistry;
27+ /// @dev contract address deployed through the factory => deployer
28+ mapping (address => address ) public getContractDeployer;
2429
2530 /// @dev Whether the registry is paused.
2631 bool public isPaused;
2732
28- /// @dev contract address deployed through the factory => deployer
29- mapping (address => address ) public getContractDeployer;
30-
3133 /*///////////////////////////////////////////////////////////////
3234 Constructor + modifiers
3335 //////////////////////////////////////////////////////////////*/
@@ -39,8 +41,13 @@ contract ByocFactory is IByocFactory, ERC2771Context, Multicall, AccessControlEn
3941 _;
4042 }
4143
42- constructor (address _twRegistry , address _trustedForwarder ) ERC2771Context (_trustedForwarder) {
44+ constructor (
45+ address _twRegistry ,
46+ address _metadataRegistry ,
47+ address _trustedForwarder
48+ ) ERC2771Context (_trustedForwarder) {
4349 registry = TWRegistry (_twRegistry);
50+ metadataRegistry = IContractMetadataRegistry (_metadataRegistry);
4451 _setupRole (DEFAULT_ADMIN_ROLE, _msgSender ());
4552 }
4653
@@ -66,18 +73,20 @@ contract ByocFactory is IByocFactory, ERC2771Context, Multicall, AccessControlEn
6673 ? keccak256 (abi.encodePacked (caller, block .number , keccak256 (contractBytecode)))
6774 : keccak256 (abi.encodePacked (caller, _salt));
6875
76+ // compute the address of the clone and save it
6977 address computedContractAddress = Create2.computeAddress (salt, keccak256 (contractBytecode), address (this ));
7078 getContractDeployer[computedContractAddress] = caller;
7179
80+ // deploy the contract
7281 deployedAddress = Create2.deploy (_value, salt, contractBytecode);
7382
74- ThirdwebContract (deployedAddress).setPublishMetadataUri (publishMetadataUri);
75- require (
76- keccak256 (bytes (ThirdwebContract (deployedAddress).getPublishMetadataUri ())) ==
77- keccak256 (bytes (publishMetadataUri)),
78- "Not a thirdweb contract "
79- );
83+ // set the owner
84+ ThirdwebContract (deployedAddress).tw_initializeOwner (caller);
8085
86+ // register to metadata registry
87+ metadataRegistry.registerMetadata (deployedAddress, publishMetadataUri);
88+
89+ // register to TWRegistry
8190 registry.add (caller, deployedAddress);
8291
8392 emit ContractDeployed (caller, _publisher, deployedAddress);
@@ -92,24 +101,28 @@ contract ByocFactory is IByocFactory, ERC2771Context, Multicall, AccessControlEn
92101 uint256 _value ,
93102 string memory publishMetadataUri
94103 ) external onlyUnpausedOrAdmin returns (address deployedAddress ) {
104+ require (bytes (publishMetadataUri).length > 0 , "No publish metadata " );
105+
95106 address caller = _msgSender ();
96107
97108 bytes32 salt = _salt == ""
98109 ? keccak256 (abi.encodePacked (caller, block .number , _implementation, _initializeData))
99110 : keccak256 (abi.encodePacked (caller, _salt));
100111
112+ // compute the address of the clone and save it
101113 address computedContractAddress = Clones.predictDeterministicAddress (_implementation, salt, address (this ));
102114 getContractDeployer[computedContractAddress] = caller;
103115
116+ // deploy the clone
104117 deployedAddress = Clones.cloneDeterministic (_implementation, salt);
105118
106- ThirdwebContract (deployedAddress).setPublishMetadataUri (publishMetadataUri);
107- require (
108- keccak256 (bytes (ThirdwebContract (deployedAddress).getPublishMetadataUri ())) ==
109- keccak256 (bytes (publishMetadataUri)),
110- "Not a thirdweb contract "
111- );
119+ // set the owner
120+ ThirdwebContract (deployedAddress).tw_initializeOwner (caller);
121+
122+ // register to metadata registry
123+ metadataRegistry.registerMetadata (deployedAddress, publishMetadataUri);
112124
125+ // register to TWRegistry
113126 registry.add (caller, deployedAddress);
114127
115128 if (_initializeData.length > 0 ) {
0 commit comments