Skip to content

Commit ce35035

Browse files
committed
t
Signed-off-by: Adam Wolf <wolfynft@gmail.com>
1 parent e6353e4 commit ce35035

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

contracts/factory/MagicDropCloneFactory.sol

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ contract MagicDropCloneFactory is Ownable {
138138
= PUBLIC VIEW METHODS =
139139
==============================================================*/
140140

141+
142+
/// @notice Calculates the address of a deployed contract via create2
143+
/// @param _sender The account that deploys the contract.
144+
/// @param _bytecodeHash The correctly formatted hash of the bytecode.
145+
/// @param _salt The create2 salt.
146+
/// @param _input The constructor data.
147+
/// @return newAddress The derived address of the account.
148+
149+
141150
/// @notice Predicts the deployment address of a proxy contract
142151
/// @param salt The salt used for address generation
143152
/// @return The predicted proxy deployment address
@@ -146,21 +155,26 @@ contract MagicDropCloneFactory is Ownable {
146155
bytes memory constructorArgs = abi.encode(implementation);
147156
bytes memory deploymentBytecode = bytes.concat(bytecode, constructorArgs);
148157

149-
(bool success, bytes memory result) = CONTRACT_DEPLOYER.staticcall(
150-
abi.encodeWithSignature(
151-
"getNewAddressCreate2(address,bytes32,bytes32,bytes)",
152-
address(this),
153-
keccak256(deploymentBytecode),
154-
salt,
155-
constructorArgs
156-
)
157-
);
158-
159-
if (!success) {
160-
revert("Failed to predict deployment address");
161-
}
162-
163-
return abi.decode(result, (address));
158+
// (bool success, bytes memory result) = CONTRACT_DEPLOYER.staticcall(
159+
// abi.encodeWithSignature(
160+
// "getNewAddressCreate2(address,bytes32,bytes32,bytes)",
161+
// address(this),
162+
// keccak256(deploymentBytecode),
163+
// salt,
164+
// constructorArgs
165+
// )
166+
// );
167+
168+
ContractDeployer deployer = ContractDeployer(CONTRACT_DEPLOYER);
169+
address predictedAddress =
170+
deployer.getNewAddressCreate2(address(this), keccak256(deploymentBytecode), salt, deploymentBytecode);
171+
172+
// if (!success) {
173+
// revert("Failed to predict deployment address");
174+
// }
175+
176+
// return abi.decode(result, (address));
177+
return predictedAddress;
164178
}
165179

166180
/*==============================================================

foundry.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ solc_version = "0.8.22"
88
evm_version = "cancun"
99
via_ir = true
1010
optimizer_runs = 777
11+
fallback_oz = true
12+
is_system = true # Note: NonceHolder and the ContractDeployer system contracts can only be called with a special isSystem flag as true
13+
mode = "3"
1114

1215
[etherscan]
1316
apechain = {key = "${VERIFICATION_API_KEY_APECHAIN}", chain = 33139, url = "https://api.apescan.io/api"}

test/factory/MagicDropCloneFactoryTestV2.t.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ contract MagicDropCloneFactoryTestV2 is Test {
4343

4444
function testPredictDeploymentAddress() public {
4545
bytes32 salt = bytes32(uint256(0));
46-
address contractAddress = factory.predictDeploymentAddress(salt);
47-
vm.assertEq(contractAddress, contractAddress);
46+
address expectedAddress = factory.predictDeploymentAddress(salt);
47+
48+
vm.startPrank(user);
49+
address contractAddress = factory.createContractDeterministic("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0, salt);
50+
vm.stopPrank();
51+
52+
vm.assertEq(contractAddress, expectedAddress);
4853
}
4954

5055
function testFailWithdrawToNonOwner() public {

0 commit comments

Comments
 (0)