Skip to content

Commit 7ac029e

Browse files
committed
feat: updates to script utils
1 parent 8cade27 commit 7ac029e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

script/utils/CreateXWrapper.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pragma solidity ^0.8.0;
33

44
import {ICreateX} from "./interfaces/ICreateX.sol";
55

6+
import {Hashes} from "@openzeppelin/contracts/utils/cryptography/Hashes.sol";
7+
68
/**
79
* @title CreateXWrapper
810
* @notice Contract providing convenient wrapper functions for deployments via CreateX factory
@@ -45,6 +47,16 @@ contract CreateXWrapper {
4547
return ICreateX(CREATEX_FACTORY).deployCreate2(initCode);
4648
}
4749

50+
/**
51+
* @notice Deploys a contract using CREATE2 with a salt
52+
* @param salt An 11-byte salt value for deterministic address generation
53+
* @param initCode The contract bytecode to deploy
54+
* @return The address of the deployed contract
55+
*/
56+
function deployCreate2WithSalt(bytes32 salt, bytes memory initCode) public returns (address) {
57+
return ICreateX(CREATEX_FACTORY).deployCreate2(salt, initCode);
58+
}
59+
4860
/**
4961
* @notice Deploys a contract using CREATE2 and calls an initialization function
5062
* @param salt An 32-byte salt value for deterministic address generation
@@ -110,6 +122,17 @@ contract CreateXWrapper {
110122
);
111123
}
112124

125+
/**
126+
* @notice Computes the deterministic address for a CREATE deployment
127+
* @dev Useful for predicting contract addresses before deployment
128+
* @param deployer The address of the deployer
129+
* @param nonce The nonce value for the deployment
130+
* @return The computed address where the contract would be deployed
131+
*/
132+
function computeCreateAddress(address deployer, uint256 nonce) public view returns (address) {
133+
return ICreateX(CREATEX_FACTORY).computeCreateAddress(deployer, nonce);
134+
}
135+
113136
/**
114137
* @notice Computes the deterministic address for a CREATE3 deployment
115138
* @dev Useful for predicting contract addresses before deployment
@@ -143,4 +166,15 @@ contract CreateXWrapper {
143166
function getSaltForCreate3(bytes11 salt, address deployer) public pure returns (bytes32) {
144167
return bytes32(uint256(uint160(deployer)) << 96 | uint256(0x00) << 88 | uint256(uint88(salt)));
145168
}
169+
170+
/**
171+
* @notice Generates a guarded salt for CREATE3 deployment by combining deployer address and salt
172+
* @dev The salt format is: [160-bit deployer address][8-bit zero padding][88-bit salt]
173+
* @param deployer The deployer's address (160-bit)
174+
* @param salt An 32-byte salt value
175+
* @return A 32-byte salt suitable for CREATE3 deployment
176+
*/
177+
function getGuardedSalt(address deployer, bytes32 salt) public pure returns (bytes32) {
178+
return Hashes.efficientKeccak256({a: bytes32(uint256(uint160(deployer))), b: salt});
179+
}
146180
}

script/utils/Logs.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ library Logs {
1313
string memory data
1414
) public {
1515
console2.log(data);
16-
vm.writeFile(LOG_FILE, string.concat(vm.readFile(LOG_FILE), data, "\n"));
16+
vm.writeLine(LOG_FILE, string.concat(data, "\n"));
1717
}
1818
}

0 commit comments

Comments
 (0)