Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created March 10, 2022 15:00
Show Gist options
  • Save PaulRBerg/5eeed367b91dc8b121e9f386d36c3e8e to your computer and use it in GitHub Desktop.
Save PaulRBerg/5eeed367b91dc8b121e9f386d36c3e8e to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;
/// @title Create2Utility
/// @author Paul Razvan Berg
/// @dev Forked from OpenZeppelin
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/utils/Create2.sol
contract Create2Utility {
/// @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
/// `bytecodeHash` or `salt` will result in a new destination address.
function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address) {
bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, bytecodeHash));
return address(uint160(uint256(_data)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment