From 065b98cd3d68ee4f0a7a111e9fd52077009e81c3 Mon Sep 17 00:00:00 2001 From: zer0dot Date: Mon, 9 Dec 2024 19:54:39 -0500 Subject: [PATCH] feat: Add factory address to script prediction --- script/DeployFactory.s.sol | 2 +- ...ctModules.s.sol => PredictAddresses.s.sol} | 44 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) rename script/{PredictModules.s.sol => PredictAddresses.s.sol} (61%) diff --git a/script/DeployFactory.s.sol b/script/DeployFactory.s.sol index 880f6b58..ac5f9710 100644 --- a/script/DeployFactory.s.sol +++ b/script/DeployFactory.s.sol @@ -46,7 +46,7 @@ contract DeployFactoryScript is ScriptBase, Artifacts { } function run() public onlyProfile("optimized-build") { - console.log("******** Deploying Modules *********"); + console.log("******** Deploying Factory *********"); vm.startBroadcast(); diff --git a/script/PredictModules.s.sol b/script/PredictAddresses.s.sol similarity index 61% rename from script/PredictModules.s.sol rename to script/PredictAddresses.s.sol index 196f11ea..63617e9c 100644 --- a/script/PredictModules.s.sol +++ b/script/PredictAddresses.s.sol @@ -3,8 +3,11 @@ 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"; import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; // Predicts addresses for all standalone modules with salts taken from the environment. @@ -14,7 +17,7 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; // - SingleSignerValidationModule // - TimeRangeModule // - WebAuthnValidationModule -contract PredictModulesScript is ScriptBase, Artifacts { +contract PredictAddressScript is ScriptBase, Artifacts { // State vars for salts. uint256 public allowlistModuleSalt; @@ -23,6 +26,14 @@ contract PredictModulesScript is ScriptBase, Artifacts { uint256 public singleSignerValidationModuleSalt; uint256 public timeRangeModuleSalt; uint256 public webAuthnValidationModuleSalt; + uint256 public factorySalt; + + IEntryPoint public entryPoint; + ModularAccount public modularAccountImpl; + SemiModularAccountBytecode public semiModularAccountBytecodeImpl; + address public singleSignerValidationModule; + address public webAuthnValidationModule; + address public factoryOwner; function setUp() public { // Load the salts from env vars. @@ -33,10 +44,19 @@ contract PredictModulesScript is ScriptBase, Artifacts { singleSignerValidationModuleSalt = vm.envOr("SINGLE_SIGNER_VALIDATION_MODULE_SALT", uint256(0)); timeRangeModuleSalt = vm.envOr("TIME_RANGE_MODULE_SALT", uint256(0)); webAuthnValidationModuleSalt = vm.envOr("WEBAUTHN_VALIDATION_MODULE_SALT", uint256(0)); + factorySalt = vm.envOr("FACTORY_SALT", uint256(0)); + + // Load the env vars for the factory. + entryPoint = _getEntryPoint(); + modularAccountImpl = _getModularAccountImpl(); + semiModularAccountBytecodeImpl = _getSemiModularAccountBytecodeImpl(); + singleSignerValidationModule = _getSingleSignerValidationModule(); + webAuthnValidationModule = _getWebAuthnValidationModule(); + factoryOwner = _getFactoryOwner(); } function run() public view onlyProfile("optimized-build") { - console.log("******** Logging Expected Module Addresses With Env Salts *********"); + console.log("******** Logging Expected Addresses With Env Salts *********"); console.log( "ALLOWLIST_MODULE=", @@ -85,5 +105,25 @@ contract PredictModulesScript is ScriptBase, Artifacts { CREATE2_FACTORY ) ); + + console.log(""); + console.log("******** Logging Expected Factory Address With Env Salt And Env Addresses *********"); + console.log( + "FACTORY=", + Create2.computeAddress( + bytes32(factorySalt), + keccak256( + _getAccountFactoryInitcode( + entryPoint, + modularAccountImpl, + semiModularAccountBytecodeImpl, + singleSignerValidationModule, + webAuthnValidationModule, + factoryOwner + ) + ), + CREATE2_FACTORY + ) + ); } }