Skip to content

Commit

Permalink
Use the address from deployerPrivateKey if no initialOwner is provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Nov 1, 2024
1 parent e60d1de commit 06e2187
Showing 1 changed file with 113 additions and 32 deletions.
145 changes: 113 additions & 32 deletions packages/contracts/script/BaseDeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,70 +61,103 @@ contract BaseDeployScript is Script {

initialOwner = vm.envAddress("INITIAL_OWNER");
if (initialOwner == address(0)) {
console.log("INITIAL_OWNER env var not set");
return;
initialOwner = vm.addr(deployerPrivateKey);
}
}
}

/// @notice Deploys a UserOverrideableDKIMRegistry contract with a specified owner, dkim signer and time delay
function deployUserOverrideableDKIMRegistry(address owner, address dkimSigner, uint256 timeDelay)
public
returns (address)
{
function deployUserOverrideableDKIMRegistry(
address owner,
address dkimSigner,
uint256 timeDelay
) public returns (address) {
address dkimProxyAddress;
if (useDefender()) {
dkimProxyAddress = Upgrades.deployUUPSProxy(
"UserOverrideableDKIMRegistry.sol",
abi.encodeCall(UserOverrideableDKIMRegistry.initialize, (owner, dkimSigner, timeDelay)),
abi.encodeCall(
UserOverrideableDKIMRegistry.initialize,
(owner, dkimSigner, timeDelay)
),
opts
);
} else {
UserOverrideableDKIMRegistry dkimImpl = new UserOverrideableDKIMRegistry();
dkimProxyAddress = address(
new ERC1967Proxy(
address(dkimImpl),
abi.encodeCall(UserOverrideableDKIMRegistry.initialize, (owner, dkimSigner, timeDelay))
abi.encodeCall(
UserOverrideableDKIMRegistry.initialize,
(owner, dkimSigner, timeDelay)
)
)
);
}
console.log("UseroverrideableDKIMRegistry proxy deployed at: %s", dkimProxyAddress);
console.log(
"UseroverrideableDKIMRegistry proxy deployed at: %s",
dkimProxyAddress
);
return dkimProxyAddress;
}

/// @notice Deploys an ECDSAOwnedDKIMRegistry contract with a specified owner and dkim signer
function deployECDSAOwnedDKIMRegistry(address owner, address dkimSigner) public returns (address) {
function deployECDSAOwnedDKIMRegistry(
address owner,
address dkimSigner
) public returns (address) {
address ecdsaDkimProxyAddress;
if (useDefender()) {
ecdsaDkimProxyAddress = Upgrades.deployUUPSProxy(
"ECDSAOwnedDKIMRegistry.sol",
abi.encodeCall(ECDSAOwnedDKIMRegistry.initialize, (owner, dkimSigner)),
abi.encodeCall(
ECDSAOwnedDKIMRegistry.initialize,
(owner, dkimSigner)
),
opts
);
} else {
ECDSAOwnedDKIMRegistry ecdsaDkimImpl = new ECDSAOwnedDKIMRegistry();
ecdsaDkimProxyAddress = address(
new ERC1967Proxy(address(ecdsaDkimImpl), abi.encodeCall(ecdsaDkimImpl.initialize, (owner, dkimSigner)))
new ERC1967Proxy(
address(ecdsaDkimImpl),
abi.encodeCall(
ecdsaDkimImpl.initialize,
(owner, dkimSigner)
)
)
);
}
console.log("ECDSAOwnedDKIMRegistry proxy deployed at: %s", ecdsaDkimProxyAddress);
console.log(
"ECDSAOwnedDKIMRegistry proxy deployed at: %s",
ecdsaDkimProxyAddress
);
return ecdsaDkimProxyAddress;
}

/// @notice Deploys a Verifier contract with a specified owner and Groth16 verifier
function deployVerifier(address owner) public returns (address) {
address verifierProxyAddress;
if (useDefender()) {
address groth16Verifier = Defender.deployContract("Groth16Verifier.sol", opts.defender);
address groth16Verifier = Defender.deployContract(
"Groth16Verifier.sol",
opts.defender
);
verifierProxyAddress = Upgrades.deployUUPSProxy(
"Verifier.sol", abi.encodeCall(Verifier.initialize, (owner, groth16Verifier)), opts
"Verifier.sol",
abi.encodeCall(Verifier.initialize, (owner, groth16Verifier)),
opts
);
} else {
Verifier verifierImpl = new Verifier();
Groth16Verifier groth16Verifier = new Groth16Verifier();
verifierProxyAddress = address(
new ERC1967Proxy(
address(verifierImpl), abi.encodeCall(verifierImpl.initialize, (owner, address(groth16Verifier)))
address(verifierImpl),
abi.encodeCall(
verifierImpl.initialize,
(owner, address(groth16Verifier))
)
)
);
}
Expand All @@ -136,36 +169,53 @@ contract BaseDeployScript is Script {
function deployEmailAuthImplementation() public returns (address) {
address emailAuthImplAddress;
if (useDefender()) {
emailAuthImplAddress = Upgrades.deployImplementation("EmailAuth.sol", opts);
emailAuthImplAddress = Upgrades.deployImplementation(
"EmailAuth.sol",
opts
);
} else {
emailAuthImplAddress = address(new EmailAuth());
}
console.log("EmailAuth implementation deployed at: %s", emailAuthImplAddress);
console.log(
"EmailAuth implementation deployed at: %s",
emailAuthImplAddress
);
return emailAuthImplAddress;
}

/// @notice Deploys a RecoveryController contract with specified owner, verifier, DKIM registry and EmailAuth implementation
function deployRecoveryController(address owner, address verifier, address dkim, address emailAuthImpl)
public
returns (address)
{
function deployRecoveryController(
address owner,
address verifier,
address dkim,
address emailAuthImpl
) public returns (address) {
address recoveryControllerProxyAddress;
if (useDefender()) {
recoveryControllerProxyAddress = Upgrades.deployUUPSProxy(
"RecoveryController.sol",
abi.encodeCall(RecoveryController.initialize, (owner, verifier, dkim, emailAuthImpl)),
abi.encodeCall(
RecoveryController.initialize,
(owner, verifier, dkim, emailAuthImpl)
),
opts
);
} else {
RecoveryController recoveryControllerImpl = new RecoveryController();
recoveryControllerProxyAddress = address(
new ERC1967Proxy(
address(recoveryControllerImpl),
abi.encodeCall(RecoveryController.initialize, (owner, verifier, dkim, emailAuthImpl))
abi.encodeCall(
RecoveryController.initialize,
(owner, verifier, dkim, emailAuthImpl)
)
)
);
}
console.log("RecoveryController deployed at: %s", recoveryControllerProxyAddress);
console.log(
"RecoveryController deployed at: %s",
recoveryControllerProxyAddress
);
return recoveryControllerProxyAddress;
}

Expand All @@ -184,7 +234,14 @@ contract BaseDeployScript is Script {
"RecoveryControllerZKSync.sol",
abi.encodeCall(
RecoveryControllerZKSync.initialize,
(owner, verifier, dkim, emailAuthImpl, factoryImpl, proxyBytecodeHash)
(
owner,
verifier,
dkim,
emailAuthImpl,
factoryImpl,
proxyBytecodeHash
)
),
opts
);
Expand All @@ -195,20 +252,33 @@ contract BaseDeployScript is Script {
address(recoveryControllerZKSyncImpl),
abi.encodeCall(
recoveryControllerZKSyncImpl.initialize,
(owner, verifier, dkim, emailAuthImpl, factoryImpl, proxyBytecodeHash)
(
owner,
verifier,
dkim,
emailAuthImpl,
factoryImpl,
proxyBytecodeHash
)
)
)
);
}
console.log("RecoveryControllerZKSync deployed at: %s", recoveryControllerProxyAddress);
console.log(
"RecoveryControllerZKSync deployed at: %s",
recoveryControllerProxyAddress
);
return recoveryControllerProxyAddress;
}

/// @notice Deploys a ZK Sync Create2 factory contract
function deployZKSyncCreate2Factory() public returns (address) {
address factoryImplAddress;
if (useDefender()) {
factoryImplAddress = Defender.deployContract("ZKSyncCreate2Factory.sol", opts.defender);
factoryImplAddress = Defender.deployContract(
"ZKSyncCreate2Factory.sol",
opts.defender
);
} else {
factoryImplAddress = address(new ZKSyncCreate2Factory());
}
Expand All @@ -217,18 +287,29 @@ contract BaseDeployScript is Script {
}

/// @notice Deploys a SimpleWallet contract with a specified owner and recovery controller
function deploySimpleWallet(address owner, address recoveryController) public returns (address) {
function deploySimpleWallet(
address owner,
address recoveryController
) public returns (address) {
address simpleWalletProxyAddress;
if (useDefender()) {
simpleWalletProxyAddress = Upgrades.deployUUPSProxy(
"SimpleWallet.sol", abi.encodeCall(SimpleWallet.initialize, (owner, recoveryController)), opts
"SimpleWallet.sol",
abi.encodeCall(
SimpleWallet.initialize,
(owner, recoveryController)
),
opts
);
} else {
SimpleWallet simpleWalletImpl = new SimpleWallet();
simpleWalletProxyAddress = address(
new ERC1967Proxy(
address(simpleWalletImpl),
abi.encodeCall(simpleWalletImpl.initialize, (owner, address(recoveryController)))
abi.encodeCall(
simpleWalletImpl.initialize,
(owner, address(recoveryController))
)
)
);
}
Expand Down

0 comments on commit 06e2187

Please sign in to comment.