Skip to content

Commit

Permalink
fix: deploy implementation and proxy instead of direct deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
zkfriendly committed Dec 18, 2024
1 parent 93fa613 commit 49a9a6b
Showing 1 changed file with 28 additions and 54 deletions.
82 changes: 28 additions & 54 deletions packages/contracts/script/DeployRecoveryController.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ 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 *;
Expand All @@ -20,82 +22,54 @@ 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();
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address initialOwner = vm.envOr("INITIAL_OWNER", address(0));
vm.startBroadcast(deployerPrivateKey);

// Deploy User-overrideable DKIM registry
dkim = vm.envOr("DKIM", address(0));
if (dkim == address(0)) {
if (address(dkim) == address(0)) {
address dkimSigner = vm.envAddress("DKIM_SIGNER");
require(dkimSigner != address(0), "DKIM_SIGNER env var not set");
if (dkimSigner == address(0)) {
console.log("DKIM_SIGNER env var not set");
return;
}
uint256 timeDelay = vm.envOr("DKIM_DELAY", uint256(0));
console.log("DKIM_DELAY: %s", timeDelay);

dkim = deploySingleton(
deployerPrivateKey,
type(UserOverrideableDKIMRegistry).creationCode,
abi.encode(initialOwner, dkimSigner, timeDelay),
keccak256("DKIM_REGISTRY")
dkim = deployUserOverrideableDKIMRegistry(
initialOwner,
dkimSigner,
timeDelay
);
}
console.log("UserOverrideableDKIMRegistry: %s", dkim);

// Deploy Verifier
verifier = vm.envOr("VERIFIER", address(0));
if (verifier == address(0)) {
verifier = deploySingleton(
deployerPrivateKey,
type(Verifier).creationCode,
abi.encode(initialOwner),
keccak256("VERIFIER")
);
if (address(verifier) == address(0)) {
verifier = deployVerifier(initialOwner);
}
console.log("Verifier: %s", verifier);

// Deploy EmailAuth Implementation
emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0));
if (emailAuthImpl == address(0)) {
emailAuthImpl = deploySingleton(
deployerPrivateKey,
type(EmailAuth).creationCode,
"",
keccak256("EMAIL_AUTH_IMPL")
);
emailAuthImpl = deployEmailAuthImplementation();
}
console.log("EmailAuth: %s", emailAuthImpl);

// Create RecoveryController
recoveryController = deploySingleton(
deployerPrivateKey,
type(RecoveryController).creationCode,
abi.encode(initialOwner, verifier, dkim, emailAuthImpl),
keccak256("RECOVERY_CONTROLLER")
// Create RecoveryController as EmailAccountRecovery implementation
recoveryController = deployRecoveryController(
initialOwner,
address(verifier),
address(dkim),
address(emailAuthImpl)
);
console.log("RecoveryController: %s", recoveryController);

// Deploy SimpleWallet Implementation
simpleWallet = deploySingleton(
deployerPrivateKey,
type(SimpleWallet).creationCode,
abi.encode(initialOwner, recoveryController),
keccak256("SIMPLE_WALLET")
simpleWallet = deploySimpleWallet(
initialOwner,
address(recoveryController)
);
console.log("SimpleWallet: %s", simpleWallet);

vm.stopBroadcast();
}
}

0 comments on commit 49a9a6b

Please sign in to comment.