Skip to content

Commit

Permalink
Update deployment scripts with more combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Nov 11, 2024
1 parent c866ecb commit 93344c7
Show file tree
Hide file tree
Showing 19 changed files with 449 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,80 @@ import { UserOverrideableDKIMRegistry } from "@zk-email/contracts/UserOverrideab
import { EmailAuth } from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol";
import { EmailRecoveryFactory } from "src/factories/EmailRecoveryFactory.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";
import { BaseDeployScript } from "./BaseDeployScript.s.sol";
import { BaseDeployScript } from "../../BaseDeployScript.s.sol";

contract DeployEmailRecoveryModuleScript is BaseDeployScript {
address public verifier;
address public dkimRegistrySigner;
address public emailAuthImpl;
address public validatorAddr;
uint256 public minimumDelay;
address public killSwitchAuthorizer;
address verifier;
address dkim;
address emailAuthImpl;
address commandHandler;
uint256 minimumDelay;
address killSwitchAuthorizer;
address validatorAddr;

address public initialOwner;
uint256 public salt;

UserOverrideableDKIMRegistry public dkim;
address initialOwner;
address dkimRegistrySigner;
uint256 dkimDelay;
uint256 salt;

function run() public override {
super.run();
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
verifier = vm.envOr("VERIFIER", address(0));
dkimRegistrySigner = vm.envOr("DKIM_SIGNER", address(0));
dkim = vm.envOr("DKIM_REGISTRY", address(0));
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
validatorAddr = vm.envOr("VALIDATOR", address(0));
commandHandler = vm.envOr("COMMAND_HANDLER", address(0));
minimumDelay = vm.envOr("MINIMUM_DELAY", uint256(0));
killSwitchAuthorizer = vm.envAddress("KILL_SWITCH_AUTHORIZER");
validatorAddr = vm.envOr("VALIDATOR", address(0));

initialOwner = vm.addr(vm.envUint("PRIVATE_KEY"));
dkimRegistrySigner = vm.envOr("DKIM_SIGNER", address(0));
dkimDelay = vm.envOr("DKIM_DELAY", uint256(0));
salt = vm.envOr("CREATE2_SALT", uint256(0));

if (verifier == address(0)) {
verifier = deployVerifier(initialOwner, salt);
}

// Deploy Useroverridable DKIM registry
dkim = UserOverrideableDKIMRegistry(vm.envOr("DKIM_REGISTRY", address(0)));
uint256 setTimeDelay = vm.envOr("DKIM_DELAY", uint256(0));
if (address(dkim) == address(0)) {
dkim = UserOverrideableDKIMRegistry(
deployUserOverrideableDKIMRegistry(
initialOwner, dkimRegistrySigner, setTimeDelay, salt
)
if (dkim == address(0)) {
dkim = deployUserOverrideableDKIMRegistry(
initialOwner, dkimRegistrySigner, dkimDelay, salt
);
}

if (emailAuthImpl == address(0)) {
emailAuthImpl = address(new EmailAuth{ salt: bytes32(salt) }());
console.log("Deployed Email Auth at", emailAuthImpl);
console.log("EmailAuth implementation deployed at", emailAuthImpl);
}

if (validatorAddr == address(0)) {
validatorAddr = address(new OwnableValidator{ salt: bytes32(salt) }());
console.log("Deployed Ownable Validator at", validatorAddr);
console.log("OwnableValidator deployed at", validatorAddr);
}

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory =
address(new EmailRecoveryFactory{ salt: bytes32(salt) }(verifier, emailAuthImpl));
console.log("Deployed Email Recovery Factory at", _factory);
console.log("EmailRecoveryFactory deployed at", _factory);
}
{
EmailRecoveryFactory factory = EmailRecoveryFactory(_factory);
(address module, address commandHandler) = factory.deployEmailRecoveryModule(
bytes32(uint256(0)),
bytes32(uint256(0)),
type(EmailRecoveryCommandHandler).creationCode,
minimumDelay,
killSwitchAuthorizer,
address(dkim),
validatorAddr,
bytes4(keccak256(bytes("changeOwner(address)")))
);

console.log("Deployed Email Recovery Module at", vm.toString(module));
console.log("Deployed Email Recovery Handler at", vm.toString(commandHandler));
vm.stopBroadcast();
}
EmailRecoveryFactory factory = EmailRecoveryFactory(_factory);
(address module, address commandHandler) = factory.deployEmailRecoveryModule(
bytes32(uint256(0)),
bytes32(uint256(0)),
type(EmailRecoveryCommandHandler).creationCode,
minimumDelay,
killSwitchAuthorizer,
address(dkim),
validatorAddr,
bytes4(keccak256(bytes("changeOwner(address)")))
);

console.log("EmailRecoveryModule deployed at", vm.toString(module));
console.log("EmailRecoveryCommandHandler deployed at", vm.toString(commandHandler));
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { console } from "forge-std/console.sol";
import { AccountHidingRecoveryCommandHandler } from
"src/handlers/AccountHidingRecoveryCommandHandler.sol";
import { UserOverrideableDKIMRegistry } from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import { EmailAuth } from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol";
import { EmailRecoveryFactory } from "src/factories/EmailRecoveryFactory.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";
import { BaseDeployScript } from "../../BaseDeployScript.s.sol";

contract DeployEmailRecoveryModuleScript is BaseDeployScript {
address verifier;
address dkim;
address emailAuthImpl;
address commandHandler;
uint256 minimumDelay;
address killSwitchAuthorizer;
address validatorAddr;

address initialOwner;
address dkimRegistrySigner;
uint256 dkimDelay;
uint256 salt;

function run() public override {
super.run();
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
verifier = vm.envOr("VERIFIER", address(0));
dkim = vm.envOr("DKIM_REGISTRY", address(0));
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
commandHandler = vm.envOr("COMMAND_HANDLER", address(0));
minimumDelay = vm.envOr("MINIMUM_DELAY", uint256(0));
killSwitchAuthorizer = vm.envAddress("KILL_SWITCH_AUTHORIZER");
validatorAddr = vm.envOr("VALIDATOR", address(0));

initialOwner = vm.addr(vm.envUint("PRIVATE_KEY"));
dkimRegistrySigner = vm.envOr("DKIM_SIGNER", address(0));
dkimDelay = vm.envOr("DKIM_DELAY", uint256(0));
salt = vm.envOr("CREATE2_SALT", uint256(0));

if (verifier == address(0)) {
verifier = deployVerifier(initialOwner, salt);
}

if (dkim == address(0)) {
dkim = deployUserOverrideableDKIMRegistry(
initialOwner, dkimRegistrySigner, dkimDelay, salt
);
}

if (emailAuthImpl == address(0)) {
emailAuthImpl = address(new EmailAuth{ salt: bytes32(salt) }());
console.log("EmailAuth implemenation deployed at", emailAuthImpl);
}

if (validatorAddr == address(0)) {
validatorAddr = address(new OwnableValidator{ salt: bytes32(salt) }());
console.log("OwnableValidator deployed at", validatorAddr);
}

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory =
address(new EmailRecoveryFactory{ salt: bytes32(salt) }(verifier, emailAuthImpl));
console.log("EmailRecoveryFactory deployed at", _factory);
}

EmailRecoveryFactory factory = EmailRecoveryFactory(_factory);
(address module, address commandHandler) = factory.deployEmailRecoveryModule(
bytes32(uint256(0)),
bytes32(uint256(0)),
type(AccountHidingRecoveryCommandHandler).creationCode,
minimumDelay,
killSwitchAuthorizer,
address(dkim),
validatorAddr,
bytes4(keccak256(bytes("changeOwner(address)")))
);

console.log("EmailRecoveryModule deployed at", vm.toString(module));
console.log("AccountHidingRecoveryCommandHandler deployed at", vm.toString(commandHandler));
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { console } from "forge-std/console.sol";
import { EmailRecoveryCommandHandler } from "src/handlers/EmailRecoveryCommandHandler.sol";
import { UserOverrideableDKIMRegistry } from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import { EmailAuth } from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol";
import { EmailRecoveryUniversalFactory } from "src/factories/EmailRecoveryUniversalFactory.sol";
import { BaseDeployScript } from "../../BaseDeployScript.s.sol";

contract DeployUniversalEmailRecoveryModuleScript is BaseDeployScript {
address verifier;
address dkim;
address emailAuthImpl;
address commandHandler;
uint256 minimumDelay;
address killSwitchAuthorizer;

address initialOwner;
address dkimRegistrySigner;
uint256 dkimDelay;
uint256 salt;

function run() public override {
super.run();
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
verifier = vm.envOr("VERIFIER", address(0));
dkim = vm.envOr("DKIM_REGISTRY", address(0));
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
commandHandler = vm.envOr("COMMAND_HANDLER", address(0));
minimumDelay = vm.envOr("MINIMUM_DELAY", uint256(0));
killSwitchAuthorizer = vm.envAddress("KILL_SWITCH_AUTHORIZER");

initialOwner = vm.addr(vm.envUint("PRIVATE_KEY"));
dkimRegistrySigner = vm.envOr("DKIM_SIGNER", address(0));
dkimDelay = vm.envOr("DKIM_DELAY", uint256(0));
salt = vm.envOr("CREATE2_SALT", uint256(0));

if (verifier == address(0)) {
verifier = deployVerifier(initialOwner, salt);
}

if (dkim == address(0)) {
dkim = deployUserOverrideableDKIMRegistry(
initialOwner, dkimRegistrySigner, dkimDelay, salt
);
}

if (emailAuthImpl == address(0)) {
emailAuthImpl = address(new EmailAuth{ salt: bytes32(salt) }());
console.log("EmailAuth implemenation deployed at", emailAuthImpl);
}

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory = address(
new EmailRecoveryUniversalFactory{ salt: bytes32(salt) }(verifier, emailAuthImpl)
);
console.log("EmailRecoveryUniversalFactory deployed at", _factory);
}

EmailRecoveryUniversalFactory factory = EmailRecoveryUniversalFactory(_factory);
(address module, address commandHandler) = factory.deployUniversalEmailRecoveryModule(
bytes32(uint256(0)),
bytes32(uint256(0)),
type(EmailRecoveryCommandHandler).creationCode,
minimumDelay,
killSwitchAuthorizer,
address(dkim)
);

console.log("UniversalEmailRecoveryModule deployed at", vm.toString(module));
console.log("EmailRecoveryCommandHandler deployed at", vm.toString(commandHandler));
vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { console } from "forge-std/console.sol";
import { AccountHidingRecoveryCommandHandler } from
"src/handlers/AccountHidingRecoveryCommandHandler.sol";
import { UserOverrideableDKIMRegistry } from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import { EmailAuth } from "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol";
import { EmailRecoveryUniversalFactory } from "src/factories/EmailRecoveryUniversalFactory.sol";
import { BaseDeployScript } from "../../BaseDeployScript.s.sol";

contract DeployUniversalEmailRecoveryModuleScript is BaseDeployScript {
address verifier;
address dkim;
address emailAuthImpl;
address commandHandler;
uint256 minimumDelay;
address killSwitchAuthorizer;

address initialOwner;
address dkimRegistrySigner;
uint256 dkimDelay;
uint256 salt;

function run() public override {
super.run();
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
verifier = vm.envOr("VERIFIER", address(0));
dkim = vm.envOr("DKIM_REGISTRY", address(0));
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
commandHandler = vm.envOr("COMMAND_HANDLER", address(0));
minimumDelay = vm.envOr("MINIMUM_DELAY", uint256(0));
killSwitchAuthorizer = vm.envAddress("KILL_SWITCH_AUTHORIZER");

initialOwner = vm.addr(vm.envUint("PRIVATE_KEY"));
dkimRegistrySigner = vm.envOr("DKIM_SIGNER", address(0));
dkimDelay = vm.envOr("DKIM_DELAY", uint256(0));
salt = vm.envOr("CREATE2_SALT", uint256(0));

if (verifier == address(0)) {
verifier = deployVerifier(initialOwner, salt);
}

if (dkim == address(0)) {
dkim = deployUserOverrideableDKIMRegistry(
initialOwner, dkimRegistrySigner, dkimDelay, salt
);
}

if (emailAuthImpl == address(0)) {
emailAuthImpl = address(new EmailAuth{ salt: bytes32(salt) }());
console.log("EmailAuth implemenation deployed at", emailAuthImpl);
}

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory = address(
new EmailRecoveryUniversalFactory{ salt: bytes32(salt) }(verifier, emailAuthImpl)
);
console.log("EmailRecoveryUniversalFactory deployed at", _factory);
}

EmailRecoveryUniversalFactory factory = EmailRecoveryUniversalFactory(_factory);
(address module, address commandHandler) = factory.deployUniversalEmailRecoveryModule(
bytes32(uint256(0)),
bytes32(uint256(0)),
type(AccountHidingRecoveryCommandHandler).creationCode,
minimumDelay,
killSwitchAuthorizer,
address(dkim)
);

console.log("UniversalEmailRecoveryModule deployed at", vm.toString(module));
console.log("AccountHidingRecoveryCommandHandler deployed at", vm.toString(commandHandler));
vm.stopBroadcast();
}
}
8 changes: 4 additions & 4 deletions script/BaseDeployScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract BaseDeployScript is Script {
abi.encodeCall(verifierImpl.initialize, (initialOwner, address(groth16Verifier)))
);
address verifier = address(Verifier(address(verifierProxy)));
console.log("Deployed Verifier at", verifier);
console.log("Verifier proxy deployed at", verifier);
return verifier;
}

Expand All @@ -35,7 +35,7 @@ contract BaseDeployScript is Script {
function deployUserOverrideableDKIMRegistry(
address initialOwner,
address dkimRegistrySigner,
uint256 setTimeDelay,
uint256 dkimDelay,
uint256 salt
)
public
Expand All @@ -51,11 +51,11 @@ contract BaseDeployScript is Script {
ERC1967Proxy dkimProxy = new ERC1967Proxy{ salt: bytes32(salt) }(
address(overrideableDkimImpl),
abi.encodeCall(
overrideableDkimImpl.initialize, (initialOwner, dkimRegistrySigner, setTimeDelay)
overrideableDkimImpl.initialize, (initialOwner, dkimRegistrySigner, dkimDelay)
)
);
address dkim = address(dkimProxy);
console.log("UseroverrideableDKIMRegistry proxy deployed at: %s", dkim);
console.log("UserOverrideableDKIMRegistry proxy deployed at: %s", dkim);
return dkim;
}
}
Loading

0 comments on commit 93344c7

Please sign in to comment.