-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53373ae
commit 6216d9f
Showing
6 changed files
with
369 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// https://github.com/Genesis3800/CREATE2Factory/blob/b202029eadc0299e6e5923dd90db4200c2f7955a/src/Create2.sol | ||
|
||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract Create2 { | ||
|
||
error Create2InsufficientBalance(uint256 received, uint256 minimumNeeded); | ||
|
||
error Create2EmptyBytecode(); | ||
|
||
error Create2FailedDeployment(); | ||
|
||
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) external payable returns (address addr) { | ||
|
||
if (msg.value < amount) { | ||
revert Create2InsufficientBalance(msg.value, amount); | ||
} | ||
|
||
if (bytecode.length == 0) { | ||
revert Create2EmptyBytecode(); | ||
} | ||
|
||
assembly { | ||
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt) | ||
} | ||
|
||
if (addr == address(0)) { | ||
revert Create2FailedDeployment(); | ||
} | ||
} | ||
|
||
function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address addr) { | ||
|
||
address contractAddress = address(this); | ||
|
||
assembly { | ||
let ptr := mload(0x40) | ||
|
||
mstore(add(ptr, 0x40), bytecodeHash) | ||
mstore(add(ptr, 0x20), salt) | ||
mstore(ptr, contractAddress) | ||
let start := add(ptr, 0x0b) | ||
mstore8(start, 0xff) | ||
addr := keccak256(start, 85) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.