Skip to content

Commit

Permalink
feat(evm): skip deployment if already deployed to address
Browse files Browse the repository at this point in the history
  • Loading branch information
Quazia committed Sep 24, 2024
1 parent 6ece9ce commit 4b402b9
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions packages/evm/script/solidity/Util.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,29 @@ contract ScriptUtils is Script {

function _deploy2(bytes memory deployCode, bytes memory args) internal {
bytes32 salt = keccak256(bytes(vm.envString("BOOST_DEPLOYMENT_SALT")));
bytes memory payload = abi.encodePacked(salt, deployCode, args);
// deploy using address configured at the CLI level
vm.broadcast();
(bool success,) = CREATE2_FACTORY.call(payload);
if (!success) revert("create2 failed");
bytes32 bytecodeHash = keccak256(abi.encodePacked(deployCode, args));
address computedAddress = address(uint160(uint256(keccak256(abi.encodePacked(
bytes1(0xff),
CREATE2_FACTORY,
salt,
bytecodeHash
)))));

// Check if the address already has code deployed
uint256 codeSize;
assembly {
codeSize := extcodesize(computedAddress)
}

if (codeSize == 0) {
bytes memory payload = abi.encodePacked(salt, deployCode, args);
// deploy using address configured at the CLI level
vm.broadcast();
(bool success,) = CREATE2_FACTORY.call(payload);
if (!success) revert("create2 failed");
} else {
console.log("Address already deployed at: ", computedAddress);
}
}

function _buildJsonDeployPath() internal virtual view returns (string memory) {
Expand Down

0 comments on commit 4b402b9

Please sign in to comment.