Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update factory based off of Rhinestone feedback: #16

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/Compute7579CalldataHash.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions script/Deploy7579Controller.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
68 changes: 40 additions & 28 deletions src/EmailRecoveryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good I guess

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
)
Expand All @@ -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)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ 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
bytes32 subjectHandlerSalt = bytes32(uint256(0));
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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,19 @@ 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
bytes32 subjectHandlerSalt = bytes32(uint256(0));
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/SafeUnitBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion test/unit/UnitBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down