diff --git a/.gitmodules b/.gitmodules index 31f95bf224..49bafc0c9f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,6 +11,6 @@ [submodule "services/cctp-relayer/external/synapse-contracts"] path = services/cctp-relayer/external/synapse-contracts url = https://github.com/synapsecns/synapse-contracts -[submodule "packages/contracts-core/lib/create3-factory"] - path = packages/contracts-core/lib/create3-factory - url = https://github.com/zeframlou/create3-factory +[submodule "packages/contracts-core/lib/solmate"] + path = packages/contracts-core/lib/solmate + url = https://github.com/transmissions11/solmate diff --git a/packages/contracts-core/contracts/create3/CREATE3Factory.sol b/packages/contracts-core/contracts/create3/CREATE3Factory.sol new file mode 100644 index 0000000000..70d13e8b2a --- /dev/null +++ b/packages/contracts-core/contracts/create3/CREATE3Factory.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity ^0.8.13; + +import {CREATE3} from "solmate/utils/CREATE3.sol"; + +import {ICREATE3Factory} from "./ICREATE3Factory.sol"; + +/// @title Factory for deploying contracts to deterministic addresses via CREATE3 +/// @author zefram.eth +/// @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has +/// its own namespace for deployed addresses. +contract CREATE3Factory is ICREATE3Factory { + /// @inheritdoc ICREATE3Factory + function deploy(bytes32 salt, bytes memory creationCode) external payable override returns (address deployed) { + // hash salt with the deployer address to give each deployer its own namespace + salt = keccak256(abi.encodePacked(msg.sender, salt)); + return CREATE3.deploy(salt, creationCode, msg.value); + } + + /// @inheritdoc ICREATE3Factory + function getDeployed(address deployer, bytes32 salt) external view override returns (address deployed) { + // hash salt with the deployer address to give each deployer its own namespace + salt = keccak256(abi.encodePacked(deployer, salt)); + return CREATE3.getDeployed(salt); + } +} diff --git a/packages/contracts-core/contracts/create3/ICREATE3Factory.sol b/packages/contracts-core/contracts/create3/ICREATE3Factory.sol new file mode 100644 index 0000000000..223c4f9958 --- /dev/null +++ b/packages/contracts-core/contracts/create3/ICREATE3Factory.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: AGPL-3.0 +pragma solidity >=0.6.0; + +/// @title Factory for deploying contracts to deterministic addresses via CREATE3 +/// @author zefram.eth +/// @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has +/// its own namespace for deployed addresses. +interface ICREATE3Factory { + /// @notice Deploys a contract using CREATE3 + /// @dev The provided salt is hashed together with msg.sender to generate the final salt + /// @param salt The deployer-specific salt for determining the deployed contract's address + /// @param creationCode The creation code of the contract to deploy + /// @return deployed The address of the deployed contract + function deploy(bytes32 salt, bytes memory creationCode) external payable returns (address deployed); + + /// @notice Predicts the address of a deployed contract + /// @dev The provided salt is hashed together with the deployer address to generate the final salt + /// @param deployer The deployer account that will call deploy() + /// @param salt The deployer-specific salt for determining the deployed contract's address + /// @return deployed The address of the contract that will be deployed + function getDeployed(address deployer, bytes32 salt) external view returns (address deployed); +} diff --git a/packages/contracts-core/lib/create3-factory b/packages/contracts-core/lib/create3-factory deleted file mode 160000 index 06ec0ff36d..0000000000 --- a/packages/contracts-core/lib/create3-factory +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 06ec0ff36d41853dcd4399fbe2127aef801c4077 diff --git a/packages/contracts-core/lib/solmate b/packages/contracts-core/lib/solmate new file mode 160000 index 0000000000..fadb2e2778 --- /dev/null +++ b/packages/contracts-core/lib/solmate @@ -0,0 +1 @@ +Subproject commit fadb2e2778adbf01c80275bfb99e5c14969d964b diff --git a/packages/contracts-core/remappings.txt b/packages/contracts-core/remappings.txt index 9d6fc62b2c..907d6d3d0e 100644 --- a/packages/contracts-core/remappings.txt +++ b/packages/contracts-core/remappings.txt @@ -1,3 +1,2 @@ forge-std=lib/forge-std/src -ds-test=lib/forge-std/lib/ds-test/src -create3=lib/create3-factory/src +ds-test=lib/forge-std/lib/ds-test/src \ No newline at end of file diff --git a/packages/contracts-core/script/DeployCREATE3Factory.sol b/packages/contracts-core/script/DeployCREATE3.sol similarity index 77% rename from packages/contracts-core/script/DeployCREATE3Factory.sol rename to packages/contracts-core/script/DeployCREATE3.sol index dc28d11154..92428f2db2 100644 --- a/packages/contracts-core/script/DeployCREATE3Factory.sol +++ b/packages/contracts-core/script/DeployCREATE3.sol @@ -7,10 +7,10 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; // ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════ import {DeployerUtils} from "./utils/DeployerUtils.sol"; -import {CREATE3Factory} from "create3/CREATE3Factory.sol"; +import {CREATE3Factory} from "../contracts/create3/CREATE3Factory.sol"; -// TODO: move this to a common deployer-utils package, as this is not specific to SIN -contract DeployCREATE3Factory is DeployerUtils { +// TODO: remove this script, I don't think we need it since we handle the devnet create3 deploy in setupDevnetIfEnabled(); +contract DeployCREATE3 is DeployerUtils { using stdJson for string; using Strings for uint256; diff --git a/packages/contracts-core/script/utils/DeployerUtils.sol b/packages/contracts-core/script/utils/DeployerUtils.sol index 46e8c06edf..682c73ad99 100644 --- a/packages/contracts-core/script/utils/DeployerUtils.sol +++ b/packages/contracts-core/script/utils/DeployerUtils.sol @@ -5,7 +5,7 @@ import {console, Script, stdJson} from "forge-std/Script.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; -import {CREATE3Factory} from "create3/CREATE3Factory.sol"; +import {CREATE3Factory} from "../../contracts/create3/CREATE3Factory.sol"; interface ICreate3Factory { function deploy(bytes32 salt, bytes memory creationCode) external payable returns (address deployed);