diff --git a/script/Compute7579CalldataHash.s.sol b/script/Compute7579CalldataHash.s.sol index 0d3d0445..f91fde90 100644 --- a/script/Compute7579CalldataHash.s.sol +++ b/script/Compute7579CalldataHash.s.sol @@ -65,7 +65,7 @@ contract Compute7579CalldataHash is Script { // console.log("Deployed Email Recovery Factory at", _factory); // } // EmailRecoveryFactory factory = EmailRecoveryFactory(_factory); - // (address manager, address module) = factory.deployAllWithUniversalModule( + // (address manager, address module) = factory.deployUniversalEmailRecoveryModule( // verifier, // dkimRegistry, // emailAuthImpl, diff --git a/script/Deploy7579Controller.s.sol b/script/Deploy7579Controller.s.sol index df2d1e32..b92e7130 100644 --- a/script/Deploy7579Controller.s.sol +++ b/script/Deploy7579Controller.s.sol @@ -45,21 +45,18 @@ contract Deploy7579ControllerScript is Script { // ); address _factory = vm.envOr("RECOVERY_FACTORY", address(0)); if (_factory == address(0)) { - _factory = address(new EmailRecoveryFactory()); + _factory = address(new EmailRecoveryFactory(verifier, dkimRegistry, emailAuthImpl)); // vm.setEnv("RECOVERY_FACTORY", vm.toString(_factory)); console.log("Deployed Email Recovery Factory at", _factory); } { EmailRecoveryFactory factory = EmailRecoveryFactory(_factory); - (address manager, address module, address subjectHandler) = factory - .deployAllWithUniversalModule( + (address module, address manager, address subjectHandler) = factory + .deployUniversalEmailRecoveryModule( bytes32(uint256(0)), bytes32(uint256(0)), bytes32(uint256(0)), - type(EmailRecoverySubjectHandler).creationCode, - verifier, - dkimRegistry, - emailAuthImpl + type(EmailRecoverySubjectHandler).creationCode ); // vm.setEnv("RECOVERY_MANAGER", vm.toString(manager)); // vm.setEnv("RECOVERY_MODULE", vm.toString(module)); diff --git a/src/EmailRecoveryFactory.sol b/src/EmailRecoveryFactory.sol index dc32a551..c84bbfb2 100644 --- a/src/EmailRecoveryFactory.sol +++ b/src/EmailRecoveryFactory.sol @@ -7,14 +7,25 @@ import { UniversalEmailRecoveryModule } from "./modules/UniversalEmailRecoveryMo import { EmailRecoveryModule } from "./modules/EmailRecoveryModule.sol"; contract EmailRecoveryFactory { - function deployAll( + address public immutable verifier; + address public immutable dkimRegistry; + address public immutable emailAuthImpl; + + event EmailRecoveryModuleDeployed( + address emailRecoveryModule, address emailRecoveryManager, address subjectHandler + ); + + constructor(address _verifier, address _dkimRegistry, address _emailAuthImpl) { + verifier = _verifier; + dkimRegistry = _dkimRegistry; + emailAuthImpl = _emailAuthImpl; + } + + function deployEmailRecoveryModule( bytes32 subjectHandlerSalt, bytes32 recoveryManagerSalt, bytes32 recoveryModuleSalt, bytes memory subjectHandlerBytecode, - address verifier, - address dkimRegistry, - address emailAuthImpl, address validator, bytes4 functionSelector ) @@ -25,31 +36,31 @@ contract EmailRecoveryFactory { address subjectHandler = Create2.deploy(0, subjectHandlerSalt, subjectHandlerBytecode); // Deploy recovery manager - EmailRecoveryManager emailRecoveryManager = new EmailRecoveryManager{ - salt: recoveryManagerSalt - }(verifier, dkimRegistry, emailAuthImpl, subjectHandler); - address emailRecoveryManagerAddress = address(emailRecoveryManager); + address emailRecoveryManager = address( + new EmailRecoveryManager{ salt: recoveryManagerSalt }( + verifier, dkimRegistry, emailAuthImpl, subjectHandler + ) + ); // Deploy recovery module - EmailRecoveryModule emailRecoveryModule = new EmailRecoveryModule{ salt: recoveryModuleSalt }( - emailRecoveryManagerAddress, validator, functionSelector + address emailRecoveryModule = address( + new EmailRecoveryModule{ salt: recoveryModuleSalt }( + emailRecoveryManager, validator, functionSelector + ) ); - address emailRecoveryModuleAddress = address(emailRecoveryModule); // Initialize recovery manager with module address - emailRecoveryManager.initialize(emailRecoveryModuleAddress); + EmailRecoveryManager(emailRecoveryManager).initialize(emailRecoveryModule); + emit EmailRecoveryModuleDeployed(emailRecoveryModule, emailRecoveryManager, subjectHandler); - return (emailRecoveryManagerAddress, emailRecoveryModuleAddress, subjectHandler); + return (emailRecoveryModule, emailRecoveryManager, subjectHandler); } - function deployAllWithUniversalModule( + function deployUniversalEmailRecoveryModule( bytes32 subjectHandlerSalt, bytes32 recoveryManagerSalt, bytes32 recoveryModuleSalt, - bytes memory subjectHandlerBytecode, - address verifier, - address dkimRegistry, - address emailAuthImpl + bytes memory subjectHandlerBytecode ) external returns (address, address, address) @@ -58,20 +69,21 @@ contract EmailRecoveryFactory { address subjectHandler = Create2.deploy(0, subjectHandlerSalt, subjectHandlerBytecode); // Deploy recovery manager - EmailRecoveryManager emailRecoveryManager = new EmailRecoveryManager{ - salt: recoveryManagerSalt - }(verifier, dkimRegistry, emailAuthImpl, subjectHandler); - address emailRecoveryManagerAddress = address(emailRecoveryManager); + address emailRecoveryManager = address( + new EmailRecoveryManager{ salt: recoveryManagerSalt }( + verifier, dkimRegistry, emailAuthImpl, subjectHandler + ) + ); // Deploy recovery module - UniversalEmailRecoveryModule emailRecoveryModule = new UniversalEmailRecoveryModule{ - salt: recoveryModuleSalt - }(emailRecoveryManagerAddress); - address emailRecoveryModuleAddress = address(emailRecoveryModule); + address emailRecoveryModule = address( + new UniversalEmailRecoveryModule{ salt: recoveryModuleSalt }(emailRecoveryManager) + ); // Initialize recovery manager with module address - emailRecoveryManager.initialize(emailRecoveryModuleAddress); + EmailRecoveryManager(emailRecoveryManager).initialize(emailRecoveryModule); + emit EmailRecoveryModuleDeployed(emailRecoveryModule, emailRecoveryManager, subjectHandler); - return (emailRecoveryManagerAddress, emailRecoveryModuleAddress, subjectHandler); + return (emailRecoveryModule, emailRecoveryManager, subjectHandler); } } diff --git a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index c183f7fa..d99ede2b 100644 --- a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -52,7 +52,9 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati isInstalledContext = bytes("0"); functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) + ); emailRecoveryHandler = new EmailRecoverySubjectHandler(); // Deploy EmailRecoveryManager & EmailRecoveryModule @@ -60,14 +62,12 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati bytes32 recoveryManagerSalt = bytes32(uint256(0)); bytes32 recoveryModuleSalt = bytes32(uint256(0)); bytes memory subjectHandlerBytecode = type(EmailRecoverySubjectHandler).creationCode; - (emailRecoveryManagerAddress, recoveryModuleAddress,) = emailRecoveryFactory.deployAll( + (recoveryModuleAddress, emailRecoveryManagerAddress,) = emailRecoveryFactory + .deployEmailRecoveryModule( subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode, - address(verifier), - address(ecdsaOwnedDkimRegistry), - address(emailAuthImpl), validatorAddress, functionSelector ); diff --git a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol index d2d18d5e..2592b9e1 100644 --- a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol @@ -46,7 +46,9 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is function setUp() public virtual override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) + ); emailRecoveryHandler = new EmailRecoverySubjectHandler(); // Deploy EmailRecoveryManager & UniversalEmailRecoveryModule @@ -54,15 +56,9 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is bytes32 recoveryManagerSalt = bytes32(uint256(0)); bytes32 recoveryModuleSalt = bytes32(uint256(0)); bytes memory subjectHandlerBytecode = type(EmailRecoverySubjectHandler).creationCode; - (emailRecoveryManagerAddress, recoveryModuleAddress,) = emailRecoveryFactory - .deployAllWithUniversalModule( - subjectHandlerSalt, - recoveryManagerSalt, - recoveryModuleSalt, - subjectHandlerBytecode, - address(verifier), - address(ecdsaOwnedDkimRegistry), - address(emailAuthImpl) + (recoveryModuleAddress, emailRecoveryManagerAddress,) = emailRecoveryFactory + .deployUniversalEmailRecoveryModule( + subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode ); emailRecoveryManager = EmailRecoveryManager(emailRecoveryManagerAddress); diff --git a/test/unit/EmailRecoveryFactory/deployAll.t.sol b/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol similarity index 86% rename from test/unit/EmailRecoveryFactory/deployAll.t.sol rename to test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol index b222184e..ca63e9bf 100644 --- a/test/unit/EmailRecoveryFactory/deployAll.t.sol +++ b/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol @@ -12,10 +12,12 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; contract EmailRecoveryFactory_deployAll_Test is UnitBase { function setUp() public override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(dkimRegistry), address(emailAuthImpl) + ); } - function test_DeployAll_Succeeds() public { + function test_DeployEmailRecoveryModule_Succeeds() public { bytes32 recoveryManagerSalt = bytes32(uint256(0)); bytes32 recoveryModuleSalt = bytes32(uint256(0)); bytes32 subjectHandlerSalt = bytes32(uint256(0)); @@ -46,15 +48,12 @@ contract EmailRecoveryFactory_deployAll_Test is UnitBase { recoveryModuleSalt, keccak256(recoveryModuleBytecode), address(emailRecoveryFactory) ); - (address emailRecoveryManager, address emailRecoveryModule, address subjectHandler) = - emailRecoveryFactory.deployAll( + (address emailRecoveryModule, address emailRecoveryManager, address subjectHandler) = + emailRecoveryFactory.deployEmailRecoveryModule( subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode, - address(verifier), - address(dkimRegistry), - address(emailAuthImpl), validatorAddress, functionSelector ); diff --git a/test/unit/EmailRecoveryFactory/deployAllWithUniversalModule.t.sol b/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol similarity index 78% rename from test/unit/EmailRecoveryFactory/deployAllWithUniversalModule.t.sol rename to test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol index fe226334..5a96b157 100644 --- a/test/unit/EmailRecoveryFactory/deployAllWithUniversalModule.t.sol +++ b/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol @@ -9,13 +9,15 @@ import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHa import { EmailRecoveryManager } from "src/EmailRecoveryManager.sol"; import { UniversalEmailRecoveryModule } from "src/modules/UniversalEmailRecoveryModule.sol"; -contract EmailRecoveryFactory_deployModuleAndManager_Test is UnitBase { +contract EmailRecoveryFactory_deployUniversalEmailRecoveryModule_Test is UnitBase { function setUp() public override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(dkimRegistry), address(emailAuthImpl) + ); } - function test_DeployModuleAndManager_Succeeds() public { + function test_DeployUniversalEmailRecoveryModule_Succeeds() public { bytes32 recoveryManagerSalt = bytes32(uint256(0)); bytes32 recoveryModuleSalt = bytes32(uint256(0)); bytes32 subjectHandlerSalt = bytes32(uint256(0)); @@ -45,15 +47,9 @@ contract EmailRecoveryFactory_deployModuleAndManager_Test is UnitBase { recoveryModuleSalt, keccak256(recoveryModuleBytecode), address(emailRecoveryFactory) ); - (address emailRecoveryManager, address emailRecoveryModule, address subjectHandler) = - emailRecoveryFactory.deployAllWithUniversalModule( - subjectHandlerSalt, - recoveryManagerSalt, - recoveryModuleSalt, - subjectHandlerBytecode, - address(verifier), - address(dkimRegistry), - address(emailAuthImpl) + (address emailRecoveryModule, address emailRecoveryManager, address subjectHandler) = + emailRecoveryFactory.deployUniversalEmailRecoveryModule( + subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode ); assertEq(emailRecoveryManager, expectedManager); diff --git a/test/unit/SafeUnitBase.t.sol b/test/unit/SafeUnitBase.t.sol index 2b7fb716..a5c93254 100644 --- a/test/unit/SafeUnitBase.t.sol +++ b/test/unit/SafeUnitBase.t.sol @@ -64,7 +64,9 @@ abstract contract SafeUnitBase is IntegrationBase { // Deploy handler, manager and module safeRecoverySubjectHandler = new SafeRecoverySubjectHandlerHarness(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) + ); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), diff --git a/test/unit/UnitBase.t.sol b/test/unit/UnitBase.t.sol index 782e3e78..19c99efa 100644 --- a/test/unit/UnitBase.t.sol +++ b/test/unit/UnitBase.t.sol @@ -109,7 +109,9 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { // Deploy handler, manager and module emailRecoveryHandler = new EmailRecoverySubjectHandler(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(dkimRegistry), address(emailAuthImpl) + ); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), diff --git a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index 58c373a3..ea91b171 100644 --- a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -119,7 +119,9 @@ abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, Test { // Deploy handler, manager and module emailRecoveryHandler = new EmailRecoverySubjectHandler(); - emailRecoveryFactory = new EmailRecoveryFactory(); + emailRecoveryFactory = new EmailRecoveryFactory( + address(verifier), address(dkimRegistry), address(emailAuthImpl) + ); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier),