@@ -8,62 +8,56 @@ import {StdConstants} from "forge-std/StdConstants.sol";
88import {ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol " ;
99import {ICreateX} from "@createx/contracts/ICreateX.sol " ;
1010
11- /// @notice Utility library for deploying UUPS proxy contracts and their implementations using the CreateX Factory
11+ /**
12+ * @notice Utility library for deploying UUPS proxy contracts and their implementations
13+ * using the CreateX Factory.
14+ */
1215library UUPSProxyDeployer {
1316 /// @dev Reference to the VM cheat codes from forge-std
1417 Vm private constant vm = StdConstants.VM;
1518
16- /// @notice Deploys a UUPS proxy contract and its implementation using the CreateX Factory
17- /// @param contractName The name of the contract to deploy (used to fetch creation code)
18- /// @param constructorData The constructor arguments for the implementation contract
19- /// @param initializeData The initialization data for the proxy contract
20- /// @param createXFactory The address of the CreateX factory
21- /// @param salt The salt for deterministic deployment
22- /// @return The address of the deployed proxy
19+ /**
20+ * Deploys a UUPS proxy contract and its implementation using the CreateX Factory
21+ * @param contractName The name of the contract to deploy (used to fetch creation code)
22+ * @param constructorData The constructor arguments for the implementation contract
23+ * @param initializeData The initialization data for the proxy contract
24+ * @param createXFactory The address of the CreateX factory
25+ * @param salt The salt for deterministic deployment
26+ * @return The address of the deployed proxy
27+ */
2328 function deployUUPSProxyWithCreateX (
2429 string memory contractName ,
2530 bytes memory constructorData ,
2631 bytes memory initializeData ,
2732 address createXFactory ,
2833 bytes32 salt
2934 ) internal returns (address ) {
30- // CreateX Factory instance
31- // TODO read factory address here.
32- // address createxFactory = vm.envAddress("CREATE_X_FACTORY_ADDRESS");
3335 ICreateX createX = ICreateX (createXFactory);
34- address implementation = deployImplementationWithCreateX (contractName, constructorData, createX, salt);
35-
36- // Deploy the proxy contract using CreateX Factory
36+ address implementation = deployImplementation (contractName, constructorData, createX);
3737 address proxy = createX.deployCreate2AndInit (
38- salt, // salt
38+ salt,
3939 abi.encodePacked (type (ERC1967Proxy ).creationCode, abi.encode (implementation, "" )), // initCode
40- initializeData, // data for initialize
40+ initializeData,
4141 ICreateX.Values ({constructorAmount: 0 , initCallAmount: 0 }) // values for CreateX
4242 );
4343 console.log ("UUPS Proxy deployed at: " , proxy);
44-
4544 return proxy;
4645 }
4746
48- // TODO remove and deploy implementation without create2.
49-
50- /// @notice Deploys the implementation contract using the CreateX Factory
51- /// @param contractName The name of the contract to deploy (used to fetch creation code)
52- /// @param constructorData The constructor arguments for the implementation contract
53- /// @param createXFactory The address of the CreateX factory
54- /// @param salt The salt for deterministic deployment
55- /// @return The address of the deployed implementation contract
56- function deployImplementationWithCreateX (
57- string memory contractName ,
58- bytes memory constructorData ,
59- ICreateX createXFactory ,
60- bytes32 salt
61- ) internal returns (address ) {
62- // Deploy the implementation contract using CreateX Factory
47+ /**
48+ * Deploys the implementation contract using tradition `create`.
49+ * @param contractName The name of the contract to deploy (used to fetch creation code)
50+ * @param constructorData The constructor arguments for the implementation contract
51+ * @param createxFactory The address of the CreateX factory
52+ * @return The address of the deployed implementation contract
53+ */
54+ function deployImplementation (string memory contractName , bytes memory constructorData , ICreateX createxFactory )
55+ internal
56+ returns (address )
57+ {
6358 bytes memory creationCode = vm.getCode (contractName);
64- address implementation = createXFactory. deployCreate2 (salt, abi.encodePacked (creationCode, constructorData));
59+ address implementation = createxFactory. deployCreate ( abi.encodePacked (creationCode, constructorData));
6560 console.log ("Implementation deployed at: " , implementation);
66-
6761 return implementation;
6862 }
6963}
0 commit comments