diff --git a/.gitmodules b/.gitmodules index acd01fd4..071da355 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "packages/contracts/lib/forge-std"] path = packages/contracts/lib/forge-std url = https://github.com/foundry-rs/forge-std +[submodule "packages/contracts/lib/safe-singleton-deployer-sol"] + path = packages/contracts/lib/safe-singleton-deployer-sol + url = https://github.com/wilsoncusack/safe-singleton-deployer-sol diff --git a/packages/contracts/lib/safe-singleton-deployer-sol b/packages/contracts/lib/safe-singleton-deployer-sol new file mode 160000 index 00000000..cf2b89c3 --- /dev/null +++ b/packages/contracts/lib/safe-singleton-deployer-sol @@ -0,0 +1 @@ +Subproject commit cf2b89c33fed536c4dd6fef2fb84f39053068868 diff --git a/packages/contracts/remappings.txt b/packages/contracts/remappings.txt index c22d4aa9..335e802b 100644 --- a/packages/contracts/remappings.txt +++ b/packages/contracts/remappings.txt @@ -8,4 +8,5 @@ ds-test/=../../node_modules/ds-test/src solady/=../../node_modules/solady/src/ accountabstraction/=../../node_modules/accountabstraction/ solidity-stringutils/=../../node_modules/solidity-stringutils/ -openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/ \ No newline at end of file +openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/ +safe-singleton-deployer/=lib/safe-singleton-deployer-sol/src/ \ No newline at end of file diff --git a/packages/contracts/script/DeployRecoveryController.s.sol b/packages/contracts/script/DeployRecoveryController.s.sol index 40a47b31..6243da87 100644 --- a/packages/contracts/script/DeployRecoveryController.s.sol +++ b/packages/contracts/script/DeployRecoveryController.s.sol @@ -6,12 +6,10 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {SimpleWallet} from "../test/helpers/SimpleWallet.sol"; import {RecoveryController} from "../test/helpers/RecoveryController.sol"; import {Verifier} from "../src/utils/Verifier.sol"; -import {Groth16Verifier} from "../src/utils/Groth16Verifier.sol"; -import {ECDSAOwnedDKIMRegistry} from "../src/utils/ECDSAOwnedDKIMRegistry.sol"; import {EmailAuth} from "../src/EmailAuth.sol"; -import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol"; import {BaseDeployScript} from "./BaseDeployScript.sol"; +import {SafeSingletonDeployer} from "safe-singleton-deployer/SafeSingletonDeployer.sol"; contract Deploy is BaseDeployScript { using ECDSA for *; @@ -22,54 +20,82 @@ contract Deploy is BaseDeployScript { address simpleWallet; address recoveryController; + function deploySingleton( + uint256 deployerPrivateKey, + bytes memory creationCode, + bytes memory initData, + bytes32 salt + ) private returns (address) { + return + SafeSingletonDeployer.broadcastDeploy( + deployerPrivateKey, + creationCode, + initData, + salt + ); + } + function run() public override { super.run(); - vm.startBroadcast(deployerPrivateKey); + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + address initialOwner = vm.envOr("INITIAL_OWNER", address(0)); // Deploy User-overrideable DKIM registry dkim = vm.envOr("DKIM", address(0)); - if (address(dkim) == address(0)) { + if (dkim == address(0)) { address dkimSigner = vm.envAddress("DKIM_SIGNER"); - if (dkimSigner == address(0)) { - console.log("DKIM_SIGNER env var not set"); - return; - } + require(dkimSigner != address(0), "DKIM_SIGNER env var not set"); uint256 timeDelay = vm.envOr("DKIM_DELAY", uint256(0)); - console.log("DKIM_DELAY: %s", timeDelay); - dkim = deployUserOverrideableDKIMRegistry( - initialOwner, - dkimSigner, - timeDelay + dkim = deploySingleton( + deployerPrivateKey, + type(UserOverrideableDKIMRegistry).creationCode, + abi.encode(initialOwner, dkimSigner, timeDelay), + keccak256("DKIM_REGISTRY") ); } + console.log("UserOverrideableDKIMRegistry: %s", dkim); // Deploy Verifier verifier = vm.envOr("VERIFIER", address(0)); - if (address(verifier) == address(0)) { - verifier = deployVerifier(initialOwner); + if (verifier == address(0)) { + verifier = deploySingleton( + deployerPrivateKey, + type(Verifier).creationCode, + abi.encode(initialOwner), + keccak256("VERIFIER") + ); } + console.log("Verifier: %s", verifier); // Deploy EmailAuth Implementation emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0)); if (emailAuthImpl == address(0)) { - emailAuthImpl = deployEmailAuthImplementation(); + emailAuthImpl = deploySingleton( + deployerPrivateKey, + type(EmailAuth).creationCode, + "", + keccak256("EMAIL_AUTH_IMPL") + ); } + console.log("EmailAuth: %s", emailAuthImpl); - // Create RecoveryController as EmailAccountRecovery implementation - recoveryController = deployRecoveryController( - initialOwner, - address(verifier), - address(dkim), - address(emailAuthImpl) + // Create RecoveryController + recoveryController = deploySingleton( + deployerPrivateKey, + type(RecoveryController).creationCode, + abi.encode(initialOwner, verifier, dkim, emailAuthImpl), + keccak256("RECOVERY_CONTROLLER") ); + console.log("RecoveryController: %s", recoveryController); // Deploy SimpleWallet Implementation - simpleWallet = deploySimpleWallet( - initialOwner, - address(recoveryController) + simpleWallet = deploySingleton( + deployerPrivateKey, + type(SimpleWallet).creationCode, + abi.encode(initialOwner, recoveryController), + keccak256("SIMPLE_WALLET") ); - - vm.stopBroadcast(); + console.log("SimpleWallet: %s", simpleWallet); } }