-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deploy and address prediction scripts (#321)
Co-authored-by: Zer0dot <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,028 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import {console} from "forge-std/console.sol"; | ||
|
||
import {ExecutionInstallDelegate} from "../src/helpers/ExecutionInstallDelegate.sol"; | ||
import {Artifacts} from "./Artifacts.sol"; | ||
import {ScriptBase} from "./ScriptBase.sol"; | ||
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; | ||
|
||
// Deploys the three account implementations and an execution install delegate. This requires the following env | ||
// vars to be set: | ||
// - ENTRY_POINT (optional) | ||
contract DeployAccountsScript is ScriptBase, Artifacts { | ||
// State vars for expected addresses and salts. | ||
|
||
IEntryPoint public entryPoint; | ||
|
||
address public expectedExecutionInstallDelegate; | ||
uint256 public executionInstallDelegateSalt; | ||
|
||
address public expectedModularAccountImpl; | ||
uint256 public modularAccountImplSalt; | ||
|
||
address public expectedSemiModularAccountBytecodeImpl; | ||
uint256 public semiModularAccountBytecodeImplSalt; | ||
|
||
address public expectedSemiModularAccountStorageOnlyImpl; | ||
uint256 public semiModularAccountStorageOnlyImplSalt; | ||
|
||
function setUp() public { | ||
// Load the required addresses for the deployment from env vars. | ||
entryPoint = _getEntryPoint(); | ||
|
||
expectedExecutionInstallDelegate = _getExecutionInstallDelegate(); | ||
executionInstallDelegateSalt = _getSaltOrZero("EXECUTION_INSTALL_DELEGATE"); | ||
|
||
expectedModularAccountImpl = _getModularAccountImpl(); | ||
modularAccountImplSalt = _getSaltOrZero("MODULAR_ACCOUNT_IMPL"); | ||
|
||
expectedSemiModularAccountBytecodeImpl = _getSemiModularAccountBytecodeImpl(); | ||
semiModularAccountBytecodeImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL"); | ||
|
||
expectedSemiModularAccountStorageOnlyImpl = address(_getSemiModularAccountStorageOnlyImpl()); | ||
semiModularAccountStorageOnlyImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL"); | ||
} | ||
|
||
function run() public onlyProfile("optimized-build") { | ||
console.log("******** Deploying Account Implementations and Execution Install Delegate *********"); | ||
|
||
vm.startBroadcast(); | ||
|
||
_safeDeploy( | ||
"Execution Install Delegate", | ||
expectedExecutionInstallDelegate, | ||
executionInstallDelegateSalt, | ||
_getExecutionInstallDelegateInitcode(), | ||
_deployExecutionInstallDelegate | ||
); | ||
|
||
// At this point, the delegate and entrypoint are valid, so we can safely proceed with | ||
// using them as parameters and accessing them in wrapped functions. | ||
|
||
_safeDeploy( | ||
"Modular Account Impl", | ||
expectedModularAccountImpl, | ||
modularAccountImplSalt, | ||
_getModularAccountInitcode(entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)), | ||
_wrappedDeployModularAccount | ||
); | ||
|
||
_safeDeploy( | ||
"Semi Modular Account Bytecode Impl", | ||
expectedSemiModularAccountBytecodeImpl, | ||
semiModularAccountBytecodeImplSalt, | ||
_getSemiModularAccountBytecodeInitcode( | ||
entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate) | ||
), | ||
_wrappedDeploySemiModularAccountBytecode | ||
); | ||
|
||
_safeDeploy( | ||
"Semi Modular Account Storage Only Impl", | ||
expectedSemiModularAccountStorageOnlyImpl, | ||
semiModularAccountStorageOnlyImplSalt, | ||
_getSemiModularAccountStorageOnlyInitcode( | ||
entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate) | ||
), | ||
_wrappedDeploySemiModularAccountStorageOnly | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
console.log("******** Account Implementations and Execution Install Delegate Deployed *********"); | ||
} | ||
|
||
// These functions wrap the internal deployment functions to provide access to the needed state variables | ||
// without affecting the expected signature from _safeDeploy. | ||
|
||
function _wrappedDeployModularAccount(bytes32 salt) internal returns (address) { | ||
return _deployModularAccount(salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)); | ||
} | ||
|
||
function _wrappedDeploySemiModularAccountBytecode(bytes32 salt) internal returns (address) { | ||
return _deploySemiModularAccountBytecode( | ||
salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate) | ||
); | ||
} | ||
|
||
function _wrappedDeploySemiModularAccountStorageOnly(bytes32 salt) internal returns (address) { | ||
return _deploySemiModularAccountStorageOnly( | ||
salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import {console} from "forge-std/console.sol"; | ||
|
||
import {ModularAccount} from "../src/account/ModularAccount.sol"; | ||
import {SemiModularAccountBytecode} from "../src/account/SemiModularAccountBytecode.sol"; | ||
import {Artifacts} from "./Artifacts.sol"; | ||
import {ScriptBase} from "./ScriptBase.sol"; | ||
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; | ||
|
||
// Deploys the Account Factory. This requires the following env vars to be set: | ||
// - ENTRY_POINT | ||
// - MODULAR_ACCOUNT_IMPL | ||
// - SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL | ||
// - SINGLE_SIGNER_VALIDATION_MODULE | ||
// - WEBAUTHN_VALIDATION_MODULE | ||
// - FACTORY_OWNER | ||
contract DeployFactoryScript is ScriptBase, Artifacts { | ||
// State vars for expected addresses and salts. | ||
|
||
address public expectedFactoryAddr; | ||
uint256 public factorySalt; | ||
|
||
// State vars for factory dependencies | ||
|
||
IEntryPoint public entryPoint; | ||
ModularAccount public modularAccountImpl; | ||
SemiModularAccountBytecode public semiModularAccountBytecodeImpl; | ||
address public singleSignerValidationModule; | ||
address public webAuthnValidationModule; | ||
address public factoryOwner; | ||
|
||
function setUp() public { | ||
// Load the required addresses for the factory deployment from env vars. | ||
entryPoint = _getEntryPoint(); | ||
modularAccountImpl = ModularAccount(payable(_getModularAccountImpl())); | ||
semiModularAccountBytecodeImpl = SemiModularAccountBytecode(payable(_getSemiModularAccountBytecodeImpl())); | ||
singleSignerValidationModule = _getSingleSignerValidationModule(); | ||
webAuthnValidationModule = _getWebAuthnValidationModule(); | ||
factoryOwner = _getFactoryOwner(); | ||
|
||
// Load the expected address and salt from env vars. | ||
expectedFactoryAddr = vm.envOr("ACCOUNT_FACTORY", address(0)); | ||
factorySalt = _getSaltOrZero("ACCOUNT_FACTORY"); | ||
} | ||
|
||
function run() public onlyProfile("optimized-build") { | ||
console.log("******** Deploying Factory *********"); | ||
|
||
vm.startBroadcast(); | ||
|
||
_safeDeploy( | ||
"Account Factory", | ||
expectedFactoryAddr, | ||
factorySalt, | ||
_getAccountFactoryInitcode( | ||
entryPoint, | ||
modularAccountImpl, | ||
semiModularAccountBytecodeImpl, | ||
singleSignerValidationModule, | ||
webAuthnValidationModule, | ||
factoryOwner | ||
), | ||
_wrappedDeployAccountFactory | ||
); | ||
|
||
vm.stopBroadcast(); | ||
|
||
console.log("******** Factory Deployed *********"); | ||
} | ||
|
||
// Wrapper function to be called within _safeDeploy using the context in this contract. | ||
function _wrappedDeployAccountFactory(bytes32 salt) internal returns (address) { | ||
_ensureNonzeroFactoryArgs(); | ||
return _deployAccountFactory( | ||
salt, | ||
entryPoint, | ||
modularAccountImpl, | ||
semiModularAccountBytecodeImpl, | ||
singleSignerValidationModule, | ||
webAuthnValidationModule, | ||
factoryOwner | ||
); | ||
} | ||
|
||
function _ensureNonzeroFactoryArgs() internal view { | ||
bool shouldRevert; | ||
if (address(modularAccountImpl) == address(0)) { | ||
console.log("Env Variable 'MODULAR_ACCOUNT_IMPL' not found or invalid during factory deployment"); | ||
shouldRevert = true; | ||
} else { | ||
console.log("Using user-defined ModularAccount at: %x", address(modularAccountImpl)); | ||
} | ||
|
||
if (address(semiModularAccountBytecodeImpl) == address(0)) { | ||
console.log( | ||
"Env Variable 'SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL' not found or invalid during factory deployment" | ||
); | ||
shouldRevert = true; | ||
} else { | ||
console.log( | ||
"Using user-defined SemiModularAccountBytecode at: %x", address(semiModularAccountBytecodeImpl) | ||
); | ||
} | ||
|
||
if (singleSignerValidationModule == address(0)) { | ||
console.log( | ||
"Env Variable 'SINGLE_SIGNER_VALIDATION_MODULE' not found or invalid during factory deployment" | ||
); | ||
shouldRevert = true; | ||
} else { | ||
console.log("Using user-defined SingleSignerValidationModule at: %x", singleSignerValidationModule); | ||
} | ||
|
||
if (webAuthnValidationModule == address(0)) { | ||
console.log("Env Variable 'WEBAUTHN_VALIDATION_MODULE' not found or invalid during factory deployment"); | ||
shouldRevert = true; | ||
} else { | ||
console.log("Using user-defined WebAuthnValidationModule at: %x", webAuthnValidationModule); | ||
} | ||
|
||
if (factoryOwner == address(0)) { | ||
console.log("Env Variable 'ACCOUNT_FACTORY_OWNER' not found or invalid during factory deployment"); | ||
shouldRevert = true; | ||
} else { | ||
console.log("Using user-defined factory owner at: %x", factoryOwner); | ||
} | ||
|
||
if (shouldRevert) { | ||
revert("Missing or invalid env variables during factory deployment"); | ||
} | ||
} | ||
} |
Oops, something went wrong.