Skip to content

Commit

Permalink
Merge pull request #1260 from ProjectOpenSea/horsefacts/add-initcode-…
Browse files Browse the repository at this point in the history
…to-deploy-script

Add salts + initcode to deploy script
  • Loading branch information
0age authored Jun 16, 2023
2 parents 9d4f697 + d43e792 commit 4a719dc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 38 deletions.
2 changes: 1 addition & 1 deletion contracts/helpers/navigator/lib/ExecutionsHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract ExecutionsHelper is HelperInterface {

function prepare(
NavigatorContext memory context
) public view returns (NavigatorContext memory) {
) public pure returns (NavigatorContext memory) {
return context.withExecutions();
}
}
2 changes: 1 addition & 1 deletion lib/seaport-sol
95 changes: 59 additions & 36 deletions script/NavigatorDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.4;
import "forge-std/Script.sol";
import "forge-std/console.sol";

import { LibString } from "solady/src/utils/LibString.sol";

import {
ReadOnlyOrderValidator
} from "../contracts/helpers/order-validator/lib/ReadOnlyOrderValidator.sol";
Expand Down Expand Up @@ -61,45 +63,20 @@ contract NavigatorDeployer is Script {
address private constant CONDUIT_CONTROLLER =
0x00000000F9490004C11Cef243f5400493c00Ad63;

bytes32 private constant SALT = bytes32(uint256(0x1));
bytes32 private constant DEFAULT_SALT = bytes32(uint256(0x1));
bytes32 private constant SEAPORT_VALIDATOR_SALT =
bytes32(uint256(0x459b42ee5b5e5000d96491ce));
bytes32 private constant SEAPORT_NAVIGATOR_SALT =
bytes32(uint256(0x9237ec96f90d12013e58e484));

function deploy(
string memory name,
bytes memory initCode
) internal returns (address) {
address deploymentAddress = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
address(IMMUTABLE_CREATE2_FACTORY),
SALT,
keccak256(initCode)
)
)
)
)
);
bool deployed;
if (!IMMUTABLE_CREATE2_FACTORY.hasBeenDeployed(deploymentAddress)) {
deploymentAddress = IMMUTABLE_CREATE2_FACTORY.safeCreate2(
SALT,
initCode
);
deployed = true;
}
function run() public {
console.log(
_pad(deployed ? "Deploying" : "Found", 10),
_pad(name, 23),
deploymentAddress
pad("State", 10),
pad("Name", 23),
pad("Address", 43),
"Initcode hash"
);
return deploymentAddress;
}

function run() public {
vm.startBroadcast();

address seaportValidatorHelper = deploy(
"SeaportValidatorHelper",
type(SeaportValidatorHelper).creationCode
Expand All @@ -110,6 +87,7 @@ contract NavigatorDeployer is Script {
);
deploy(
"SeaportValidator",
SEAPORT_VALIDATOR_SALT,
bytes.concat(
type(SeaportValidator).creationCode,
abi.encode(
Expand Down Expand Up @@ -151,6 +129,7 @@ contract NavigatorDeployer is Script {

deploy(
"SeaportNavigator",
SEAPORT_NAVIGATOR_SALT,
bytes.concat(
type(SeaportNavigator).creationCode,
abi.encode(
Expand All @@ -166,7 +145,51 @@ contract NavigatorDeployer is Script {
);
}

function _pad(
function deploy(
string memory name,
bytes memory initCode
) internal returns (address) {
return deploy(name, DEFAULT_SALT, initCode);
}

function deploy(
string memory name,
bytes32 salt,
bytes memory initCode
) internal returns (address) {
bytes32 initCodeHash = keccak256(initCode);
address deploymentAddress = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
address(IMMUTABLE_CREATE2_FACTORY),
salt,
initCodeHash
)
)
)
)
);
bool deploying;
if (!IMMUTABLE_CREATE2_FACTORY.hasBeenDeployed(deploymentAddress)) {
deploymentAddress = IMMUTABLE_CREATE2_FACTORY.safeCreate2(
salt,
initCode
);
deploying = true;
}
console.log(
pad(deploying ? "Deploying" : "Found", 10),
pad(name, 23),
pad(LibString.toHexString(deploymentAddress), 43),
LibString.toHexString(uint256(initCodeHash))
);
return deploymentAddress;
}

function pad(
string memory name,
uint256 n
) internal pure returns (string memory) {
Expand Down

0 comments on commit 4a719dc

Please sign in to comment.