Skip to content

Commit e45e89d

Browse files
zguesmigfournierProLe-Caignec
authored
refactor: Clean some TODOs (#59)
Co-authored-by: gfournieriExec <[email protected]> Co-authored-by: Robin Le Caignec <[email protected]>
1 parent 21c35a5 commit e45e89d

File tree

6 files changed

+43
-62
lines changed

6 files changed

+43
-62
lines changed

script/lib/UUPSProxyDeployer.sol

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,56 @@ import {StdConstants} from "forge-std/StdConstants.sol";
88
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
99
import {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+
*/
1215
library 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
}

src/mocks/IexecLayerZeroBridgeV2Mock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {IexecLayerZeroBridge} from "../bridges/layerZero/IexecLayerZeroBridge.so
1212
* @custom:oz-upgrades-from src/bridges/layerZero/IexecLayerZeroBridge.sol:IexecLayerZeroBridge
1313
*/
1414
contract IexecLayerZeroBridgeV2 is IexecLayerZeroBridge {
15-
/// NEW STATE VARIABLES FOR V2
15+
// New state variable for v2.
1616
uint256 public newStateVariable;
1717

1818
/// @custom:oz-upgrades-unsafe-allow constructor

src/mocks/RLCLiquidityUnifierV2Mock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {RLCLiquidityUnifier} from "../RLCLiquidityUnifier.sol";
1212
* @custom:oz-upgrades-from src/RLCLiquidityUnifier.sol:RLCLiquidityUnifier
1313
*/
1414
contract RLCLiquidityUnifierV2 is RLCLiquidityUnifier {
15-
/// NEW STATE VARIABLES FOR V2
15+
/// New state variable for v2.
1616
uint256 public newStateVariable;
1717

1818
/// @custom:oz-upgrades-unsafe-allow constructor

test/e2e/IexecLayerZeroBridgeScript.t.sol

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pragma solidity ^0.8.22;
55

66
import {Test} from "forge-std/Test.sol";
7+
import {CreateX} from "@createx/contracts/CreateX.sol";
78
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
89
import {Deploy as IexecLayerZeroBridgeDeploy} from "../../script/bridges/layerZero/IexecLayerZeroBridge.s.sol";
910
import {Deploy as RLCLiquidityUnifierDeployScript} from "../../script/RLCLiquidityUnifier.s.sol";
@@ -65,6 +66,10 @@ contract IexecLayerZeroBridgeScriptTest is Test {
6566
}
6667

6768
function _test_Deployment(bool requireApproval, address bridgeableToken) internal {
69+
// Check that CreateX salt is used to deploy the contract.
70+
vm.expectEmit(false, true, false, false);
71+
// CreateX uses a guarded salt (see CreateX._guard()), so we need to hash it to match the expected event.
72+
emit CreateX.ContractCreation(address(0), keccak256(abi.encode(salt)));
6873
IexecLayerZeroBridge iexecLayerZeroBridge = IexecLayerZeroBridge(
6974
deployer.deploy(
7075
requireApproval,
@@ -96,16 +101,6 @@ contract IexecLayerZeroBridgeScriptTest is Test {
96101
// TODO check that the proxy address is saved.
97102
}
98103

99-
function testFork_RevertWhen_TwoDeploymentsWithTheSameSalt() public {
100-
deployer.deploy(
101-
false, address(rlcCrosschainToken), params.lzEndpoint, admin, upgrader, pauser, params.createxFactory, salt
102-
);
103-
vm.expectRevert(abi.encodeWithSignature("FailedContractCreation(address)", params.createxFactory));
104-
deployer.deploy(
105-
false, address(rlcCrosschainToken), params.lzEndpoint, admin, upgrader, pauser, params.createxFactory, salt
106-
);
107-
}
108-
109104
// TODO: add tests for the configuration script.
110105

111106
function testFork_ConfigureContractCorrectly() public {

test/units/RLCCrosschainTokenScript.t.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ contract RLCCrosschainTokenTest is Test {
2121
function setUp() public {}
2222

2323
function test_Deploy() public {
24+
// Check that CreateX salt is used to deploy the contract.
25+
vm.expectEmit(false, true, false, false);
26+
// CreateX uses a guarded salt (see CreateX._guard()), so we need to hash it to match the expected event.
27+
emit CreateX.ContractCreation(address(0), keccak256(abi.encode(salt)));
2428
address crosschainTokenAddress = deployer.deploy(name, symbol, admin, upgrader, createx, salt);
2529
RLCCrosschainToken rlcCrosschainToken = RLCCrosschainToken(crosschainTokenAddress);
2630
assertEq(rlcCrosschainToken.name(), name);
@@ -38,12 +42,4 @@ contract RLCCrosschainTokenTest is Test {
3842

3943
// TODO check that the proxy address is saved.
4044
}
41-
42-
// Makes sure create2 deployment is well implemented.
43-
function test_RevertWhen_TwoDeploymentsWithTheSameSalt() public {
44-
address random = makeAddr("random");
45-
deployer.deploy(name, symbol, admin, upgrader, createx, salt);
46-
vm.expectRevert(abi.encodeWithSignature("FailedContractCreation(address)", createx));
47-
deployer.deploy("Foo", "BAR", random, random, createx, salt);
48-
}
4945
}

test/units/RLCLiquidityUnifierScript.t.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ contract LiquidityUnifierTest is Test {
2020
function setUp() public {}
2121

2222
function test_Deploy() public {
23+
// Check that CreateX salt is used to deploy the contract.
24+
vm.expectEmit(false, true, false, false);
25+
// CreateX uses a guarded salt (see CreateX._guard()), so we need to hash it to match the expected event.
26+
emit CreateX.ContractCreation(address(0), keccak256(abi.encode(salt)));
2327
address rlcLiquidityUnifierAddress = deployer.deploy(rlcToken, admin, upgrader, createx, salt);
2428
RLCLiquidityUnifier rlcLiquidityUnifier = RLCLiquidityUnifier(rlcLiquidityUnifierAddress);
2529
assertEq(rlcLiquidityUnifier.owner(), admin);
@@ -31,12 +35,4 @@ contract LiquidityUnifierTest is Test {
3135
rlcLiquidityUnifier.initialize(admin, upgrader);
3236
// TODO check that the proxy address is saved.
3337
}
34-
35-
// Makes sure create2 deployment is well implemented.
36-
function test_RevertWhen_TwoDeploymentsWithTheSameSalt() public {
37-
address random = makeAddr("random");
38-
deployer.deploy(rlcToken, admin, upgrader, createx, salt);
39-
vm.expectRevert(abi.encodeWithSignature("FailedContractCreation(address)", createx));
40-
deployer.deploy(rlcToken, random, random, createx, salt);
41-
}
4238
}

0 commit comments

Comments
 (0)