Skip to content

Commit

Permalink
refactor: use safe singleton deployer in BaseDeployScript and revert …
Browse files Browse the repository at this point in the history
…DeployRecoveryController to original state
  • Loading branch information
zkfriendly committed Dec 18, 2024
1 parent 49a9a6b commit b84939b
Showing 1 changed file with 129 additions and 52 deletions.
181 changes: 129 additions & 52 deletions packages/contracts/script/BaseDeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {Groth16Verifier} from "../src/utils/Groth16Verifier.sol";
import {ECDSAOwnedDKIMRegistry} from "../src/utils/ECDSAOwnedDKIMRegistry.sol";
import {EmailAuth} from "../src/EmailAuth.sol";

import {SafeSingletonDeployer} from "safe-singleton-deployer/SafeSingletonDeployer.sol";

contract BaseDeployScript is Script {
address initialOwner;
uint256 deployerPrivateKey;
Expand All @@ -40,19 +42,32 @@ contract BaseDeployScript is Script {
address dkimSigner,
uint256 timeDelay
) public returns (address) {
address dkimProxyAddress;
UserOverrideableDKIMRegistry dkimImpl = new UserOverrideableDKIMRegistry();
dkimProxyAddress = address(
new ERC1967Proxy(
address(dkimImpl),
abi.encodeCall(
UserOverrideableDKIMRegistry.initialize,
(owner, dkimSigner, timeDelay)
)
)
// Deploy implementation
address dkimImpl = SafeSingletonDeployer.deploy(
type(UserOverrideableDKIMRegistry).creationCode,
"",
keccak256("DKIM_REGISTRY_IMPL")
);

console.log(
"UserOverrideableDKIMRegistry implementation deployed at: %s",
dkimImpl
);

// Deploy proxy
bytes memory initData = abi.encodeCall(
UserOverrideableDKIMRegistry.initialize,
(owner, dkimSigner, timeDelay)
);

address dkimProxyAddress = SafeSingletonDeployer.deploy(
type(ERC1967Proxy).creationCode,
abi.encode(dkimImpl, initData),
keccak256("DKIM_REGISTRY_PROXY")
);

console.log(
"UseroverrideableDKIMRegistry proxy deployed at: %s",
"UserOverrideableDKIMRegistry deployed at: %s",
dkimProxyAddress
);
return dkimProxyAddress;
Expand All @@ -63,14 +78,30 @@ contract BaseDeployScript is Script {
address owner,
address dkimSigner
) public returns (address) {
address ecdsaDkimProxyAddress;
ECDSAOwnedDKIMRegistry ecdsaDkimImpl = new ECDSAOwnedDKIMRegistry();
ecdsaDkimProxyAddress = address(
new ERC1967Proxy(
address(ecdsaDkimImpl),
abi.encodeCall(ecdsaDkimImpl.initialize, (owner, dkimSigner))
)
// Deploy implementation
address ecdsaDkimImpl = SafeSingletonDeployer.deploy(
type(ECDSAOwnedDKIMRegistry).creationCode,
"",
keccak256("ECDSA_DKIM_IMPL")
);

console.log(
"ECDSAOwnedDKIMRegistry implementation deployed at: %s",
ecdsaDkimImpl
);

// Deploy proxy
bytes memory initData = abi.encodeCall(
ECDSAOwnedDKIMRegistry.initialize,
(owner, dkimSigner)
);

address ecdsaDkimProxyAddress = SafeSingletonDeployer.deploy(
type(ERC1967Proxy).creationCode,
abi.encode(ecdsaDkimImpl, initData),
keccak256("ECDSA_DKIM_PROXY")
);

console.log(
"ECDSAOwnedDKIMRegistry proxy deployed at: %s",
ecdsaDkimProxyAddress
Expand All @@ -80,27 +111,47 @@ contract BaseDeployScript is Script {

/// @notice Deploys a Verifier contract with a specified owner and Groth16 verifier
function deployVerifier(address owner) public returns (address) {
address verifierProxyAddress;
Verifier verifierImpl = new Verifier();
Groth16Verifier groth16Verifier = new Groth16Verifier();
console.log("Groth16Verifier deployed at: %s", address(groth16Verifier));
verifierProxyAddress = address(
new ERC1967Proxy(
address(verifierImpl),
abi.encodeCall(
verifierImpl.initialize,
(owner, address(groth16Verifier))
)
)
// Deploy implementation
address verifierImpl = SafeSingletonDeployer.deploy(
type(Verifier).creationCode,
"",
keccak256("VERIFIER_IMPL")
);

console.log("Verifier implementation deployed at: %s", verifierImpl);

address groth16Verifier = SafeSingletonDeployer.deploy(
type(Groth16Verifier).creationCode,
"",
keccak256("GROTH16_VERIFIER")
);

console.log("Groth16Verifier deployed at: %s", groth16Verifier);

// Deploy proxy
bytes memory initData = abi.encodeCall(
Verifier.initialize,
(owner, address(groth16Verifier))
);

address verifierProxyAddress = SafeSingletonDeployer.deploy(
type(ERC1967Proxy).creationCode,
abi.encode(verifierImpl, initData),
keccak256("VERIFIER_PROXY")
);

console.log("Verifier deployed at: %s", verifierProxyAddress);
return verifierProxyAddress;
}

/// @notice Deploys an EmailAuth implementation contract
function deployEmailAuthImplementation() public returns (address) {
address emailAuthImplAddress;
emailAuthImplAddress = address(new EmailAuth());
address emailAuthImplAddress = SafeSingletonDeployer.deploy(
type(EmailAuth).creationCode,
"",
keccak256("EMAIL_AUTH_IMPL")
);

console.log(
"EmailAuth implementation deployed at: %s",
emailAuthImplAddress
Expand All @@ -115,17 +166,30 @@ contract BaseDeployScript is Script {
address dkim,
address emailAuthImpl
) public returns (address) {
address recoveryControllerProxyAddress;
RecoveryController recoveryControllerImpl = new RecoveryController();
recoveryControllerProxyAddress = address(
new ERC1967Proxy(
address(recoveryControllerImpl),
abi.encodeCall(
RecoveryController.initialize,
(owner, verifier, dkim, emailAuthImpl)
)
)
// Deploy implementation
address recoveryControllerImpl = SafeSingletonDeployer.deploy(
type(RecoveryController).creationCode,
"",
keccak256("RECOVERY_CONTROLLER_IMPL")
);

console.log(
"RecoveryController implementation deployed at: %s",
recoveryControllerImpl
);

// Deploy proxy
bytes memory initData = abi.encodeCall(
RecoveryController.initialize,
(owner, verifier, dkim, emailAuthImpl)
);

address recoveryControllerProxyAddress = SafeSingletonDeployer.deploy(
type(ERC1967Proxy).creationCode,
abi.encode(recoveryControllerImpl, initData),
keccak256("RECOVERY_CONTROLLER_PROXY")
);

console.log(
"RecoveryController deployed at: %s",
recoveryControllerProxyAddress
Expand Down Expand Up @@ -180,17 +244,30 @@ contract BaseDeployScript is Script {
address owner,
address recoveryController
) public returns (address) {
address simpleWalletProxyAddress;
SimpleWallet simpleWalletImpl = new SimpleWallet();
simpleWalletProxyAddress = address(
new ERC1967Proxy(
address(simpleWalletImpl),
abi.encodeCall(
simpleWalletImpl.initialize,
(owner, address(recoveryController))
)
)
// Deploy implementation
address simpleWalletImpl = SafeSingletonDeployer.deploy(
type(SimpleWallet).creationCode,
"",
keccak256("SIMPLE_WALLET_IMPL")
);

console.log(
"SimpleWallet implementation deployed at: %s",
simpleWalletImpl
);

// Deploy proxy
bytes memory initData = abi.encodeCall(
SimpleWallet.initialize,
(owner, address(recoveryController))
);

address simpleWalletProxyAddress = SafeSingletonDeployer.deploy(
type(ERC1967Proxy).creationCode,
abi.encode(simpleWalletImpl, initData),
keccak256("SIMPLE_WALLET_PROXY")
);

console.log("SimpleWallet deployed at: %s", simpleWalletProxyAddress);
return simpleWalletProxyAddress;
}
Expand Down

0 comments on commit b84939b

Please sign in to comment.