Skip to content

Commit

Permalink
Update deploy script imports to work with pnpm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Jun 25, 2024
1 parent 68b7839 commit 3584a20
Showing 1 changed file with 33 additions and 70 deletions.
103 changes: 33 additions & 70 deletions script/Deploy7579TestAccount.s.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {EmailRecoverySubjectHandler} from "src/handlers/EmailRecoverySubjectHandler.sol";
import {EmailRecoveryManager} from "src/EmailRecoveryManager.sol";
import {EmailRecoveryModule} from "src/modules/EmailRecoveryModule.sol";
import {Verifier} from "ether-email-auth/packages/contracts/src/utils/Verifier.sol";
import {ECDSAOwnedDKIMRegistry} from "ether-email-auth/packages/contracts/src/utils/ECDSAOwnedDKIMRegistry.sol";
import {EmailAuth} from "ether-email-auth/packages/contracts/src/EmailAuth.sol";
import {EmailAccountRecovery} from "ether-email-auth/packages/contracts/src/EmailAccountRecovery.sol";
import {EmailRecoveryFactory} from "src/EmailRecoveryFactory.sol";
import {RhinestoneModuleKit, AccountInstance} from "modulekit/ModuleKit.sol";
import {OwnableValidator} from "src/test/OwnableValidator.sol";
import {SubjectUtils} from "ether-email-auth/packages/contracts/src/libraries/SubjectUtils.sol";
import {MODULE_TYPE_EXECUTOR, MODULE_TYPE_VALIDATOR} from "modulekit/external/ERC7579.sol";
import {ModuleKitHelpers, ModuleKitUserOp} from "modulekit/ModuleKit.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IERC7579Account} from "erc7579-implementation/src/interfaces/IERC7579Account.sol";
import {IEntryPoint, ENTRYPOINT_ADDR} from "erc7579-implementation/test/dependencies/EntryPoint.sol";
import {NonceManager} from "account-abstraction/core/NonceManager.sol";
import {StakeManager} from "account-abstraction/core/StakeManager.sol";
import {PackedUserOperation} from "erc7579-implementation/src/interfaces/IERC4337Account.sol";
import {MSABasic} from "erc7579-implementation/src/MSABasic.sol";
import {MSAFactory} from "erc7579-implementation/src/MSAFactory.sol";
import {Bootstrap, BootstrapConfig} from "erc7579-implementation/src/utils/Bootstrap.sol";
import {MockHook} from "erc7579-implementation/test/mocks/MockHook.sol";
import {MockTarget} from "erc7579-implementation/test/mocks/MockTarget.sol";
import {ModeLib, ModeCode, CallType, ExecType, ModeSelector, ModePayload} from "erc7579-implementation/src/lib/ModeLib.sol";
import {ExecutionLib} from "erc7579-implementation/src/lib/ExecutionLib.sol";
import {ECDSA} from "solady/utils/ECDSA.sol";
import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { EmailAccountRecovery } from
"ether-email-auth/packages/contracts/src/EmailAccountRecovery.sol";
import { RhinestoneModuleKit, AccountInstance } from "modulekit/ModuleKit.sol";
import { OwnableValidator } from "src/test/OwnableValidator.sol";
import { ModuleKitHelpers, ModuleKitUserOp } from "modulekit/ModuleKit.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { IERC7579Account } from "erc7579/interfaces/IERC7579Account.sol";
import { IEntryPoint, ENTRYPOINT_ADDR } from "modulekit/test/predeploy/EntryPoint.sol";
import { PackedUserOperation } from "erc7579-implementation/src/interfaces/IERC4337Account.sol";
import { MSABasic } from "erc7579-implementation/src/MSABasic.sol";
import { MSAFactory } from "erc7579-implementation/src/MSAFactory.sol";
import { Bootstrap, BootstrapConfig } from "erc7579-implementation/src/utils/Bootstrap.sol";
import { MockHook, MockTarget } from "modulekit/Mocks.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { ExecutionLib } from "erc7579-implementation/src/lib/ExecutionLib.sol";
import { ECDSA } from "solady/utils/ECDSA.sol";

contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
using ModuleKitHelpers for *;
Expand Down Expand Up @@ -58,8 +47,7 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
PackedUserOperation userOp;
bytes32 userOpHash;

bytes4 functionSelector =
bytes4(keccak256(bytes("changeOwner(address,address,address)")));
bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)")));

function run() public {
privKey = vm.envUint("PRIVATE_KEY");
Expand Down Expand Up @@ -116,10 +104,7 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
BootstrapConfig[] memory validators = new BootstrapConfig[](1);
address accountOwner = vm.envOr("OWNER", deployer);
recoveryModuleAddr = vm.envAddress("RECOVERY_MODULE");
require(
recoveryModuleAddr != address(0),
"RECOVERY_MODULE is required"
);
require(recoveryModuleAddr != address(0), "RECOVERY_MODULE is required");
validators[0] = BootstrapConfig({
module: validatorAddr,
data: abi.encode(accountOwner, recoveryModuleAddr)
Expand All @@ -128,8 +113,8 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
BootstrapConfig[] memory executors = new BootstrapConfig[](1);
managerAddr = vm.envAddress("RECOVERY_MANAGER");
require(managerAddr != address(0), "RECOVERY_MANAGER is required");
address guardianAddr = EmailAccountRecovery(managerAddr)
.computeEmailAuthAddress(account, accountSalt);
address guardianAddr =
EmailAccountRecovery(managerAddr).computeEmailAuthAddress(account, accountSalt);
console.log("Guardian's EmailAuth address", guardianAddr);
guardians[0] = guardianAddr;
guardianWeights[0] = 1;
Expand All @@ -143,40 +128,25 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
vm.envOr("RECOVERY_DELAY", uint256(1 seconds)),
vm.envOr("RECOVERY_EXPIRY", uint256(2 weeks))
);
executors[0] = BootstrapConfig({
module: recoveryModuleAddr,
data: recoveryModuleInstallData
});
BootstrapConfig memory hookConfig = BootstrapConfig({
module: hookAddr,
data: bytes("")
});
executors[0] =
BootstrapConfig({ module: recoveryModuleAddr, data: recoveryModuleInstallData });
BootstrapConfig memory hookConfig = BootstrapConfig({ module: hookAddr, data: bytes("") });
BootstrapConfig[] memory fallbacks = new BootstrapConfig[](0);
bytes memory _initCode = bootstrap._getInitMSACalldata(
validators,
executors,
hookConfig,
fallbacks
);
bytes memory _initCode =
bootstrap._getInitMSACalldata(validators, executors, hookConfig, fallbacks);
account = msaFactory.getAddress(accountSalt, _initCode);
console.log("Account address", account);
console.log("Account code size", account.code.length);
initCode = abi.encodePacked(
address(msaFactory),
abi.encodeWithSelector(
msaFactory.createAccount.selector,
accountSalt,
_initCode
)
abi.encodeWithSelector(msaFactory.createAccount.selector, accountSalt, _initCode)
);
userOpCalldata = abi.encodeCall(
IERC7579Account.execute,
(
ModeLib.encodeSimpleSingle(),
ExecutionLib.encodeSingle(
address(mockTarget),
uint256(0),
abi.encodeCall(MockTarget.setValue, 1)
address(mockTarget), uint256(0), abi.encodeCall(MockTarget.set, 1)
)
)
);
Expand All @@ -186,20 +156,16 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
nonce: getNonce(account, validatorAddr),
initCode: initCode,
callData: userOpCalldata,
accountGasLimits: bytes32(
abi.encodePacked(uint128(1e7), uint128(1e5))
),
accountGasLimits: bytes32(abi.encodePacked(uint128(1e7), uint128(1e5))),
preVerificationGas: 1e7,
gasFees: bytes32(abi.encodePacked(uint128(0), uint128(0))),
paymasterAndData: bytes(""),
signature: bytes("")
});
{
userOpHash = IEntryPoint(ENTRYPOINT_ADDR).getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(
privKey,
ECDSA.toEthSignedMessageHash(userOpHash)
);
(uint8 v, bytes32 r, bytes32 s) =
vm.sign(privKey, ECDSA.toEthSignedMessageHash(userOpHash));
userOp.signature = abi.encodePacked(r, s, v);
}

Expand Down Expand Up @@ -255,10 +221,7 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
vm.stopBroadcast();
}

function getNonce(
address account,
address validator
) internal returns (uint256 nonce) {
function getNonce(address account, address validator) internal returns (uint256 nonce) {
uint192 key = uint192(bytes24(bytes20(address(validator))));
// console.log("shifted key", uint256(key) << 64);
// console.log(
Expand Down

0 comments on commit 3584a20

Please sign in to comment.