|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.23; |
| 3 | + |
| 4 | +import {IERC7579Account} from '../../../src/interfaces/IERC7579Account.sol'; |
| 5 | +import {IModule} from '../../../src/interfaces/IERC7579Module.sol'; |
| 6 | +import {ExecutionLib} from '../../../src/lib/ExecutionLib.sol'; |
| 7 | +import {ModeLib} from '../../../src/lib/ModeLib.sol'; |
| 8 | +import {EncodedModuleTypes} from '../../../src/lib/ModuleTypeLib.sol'; |
| 9 | +import '../../../src/types/Constants.sol'; |
| 10 | +import {Execution} from '../../../src/types/Structs.sol'; |
| 11 | +import {MessageHashUtils} from '@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol'; |
| 12 | +import {PackedUserOperation} from 'account-abstraction/interfaces/PackedUserOperation.sol'; |
| 13 | +import {ECDSA} from 'solady/utils/ECDSA.sol'; |
| 14 | +import {SignatureCheckerLib} from 'solady/utils/SignatureCheckerLib.sol'; |
| 15 | + |
| 16 | +contract MockMultiModule is IModule { |
| 17 | + error WrongUninstallData(); |
| 18 | + |
| 19 | + mapping(uint256 moduleTypeId => mapping(address smartAccount => bytes32 initData)) configs; |
| 20 | + |
| 21 | + function validateUserOp( |
| 22 | + PackedUserOperation calldata userOp, |
| 23 | + bytes32 userOpHash |
| 24 | + ) external view returns (uint256 validation) { |
| 25 | + address owner = address(bytes20(configs[MODULE_TYPE_VALIDATOR][msg.sender])); |
| 26 | + return ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(userOpHash), userOp.signature) == owner |
| 27 | + ? VALIDATION_SUCCESS |
| 28 | + : VALIDATION_FAILED; |
| 29 | + } |
| 30 | + |
| 31 | + function someFallbackFunction(Execution calldata execution) external { |
| 32 | + IERC7579Account(msg.sender).executeFromExecutor{value: execution.value}({ |
| 33 | + mode: ModeLib.encodeSimpleSingle(), |
| 34 | + executionCalldata: ExecutionLib.encodeSingle(execution.target, execution.value, execution.callData) |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + function getConfig(address smartAccount, uint256 moduleTypeId) external view returns (bytes32) { |
| 39 | + return configs[moduleTypeId][smartAccount]; |
| 40 | + } |
| 41 | + |
| 42 | + function onInstall(bytes calldata data) external override { |
| 43 | + if (data.length >= 0x21) { |
| 44 | + uint256 moduleTypeId = uint256(uint8(bytes1(data[:1]))); |
| 45 | + configs[moduleTypeId][msg.sender] = bytes32(data[1:33]); |
| 46 | + } else {} |
| 47 | + } |
| 48 | + |
| 49 | + function onUninstall(bytes calldata data) external override { |
| 50 | + if (data.length >= 0x1) { |
| 51 | + uint256 moduleTypeId = uint256(uint8(bytes1(data[:1]))); |
| 52 | + configs[moduleTypeId][msg.sender] = bytes32(0x00); |
| 53 | + } else { |
| 54 | + revert WrongUninstallData(); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + function preCheck(address, uint256, bytes calldata) external returns (bytes memory) {} |
| 59 | + |
| 60 | + function postCheck(bytes calldata hookData) external {} |
| 61 | + |
| 62 | + function isModuleType(uint256 moduleTypeId) external pure returns (bool) { |
| 63 | + return ( |
| 64 | + moduleTypeId == MODULE_TYPE_HOOK || moduleTypeId == MODULE_TYPE_EXECUTOR || moduleTypeId == MODULE_TYPE_VALIDATOR |
| 65 | + || moduleTypeId == MODULE_TYPE_FALLBACK |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + function isInitialized(address smartAccount) external view returns (bool) { |
| 70 | + return ( |
| 71 | + configs[MODULE_TYPE_VALIDATOR][smartAccount] != bytes32(0x00) |
| 72 | + || configs[MODULE_TYPE_EXECUTOR][smartAccount] != bytes32(0x00) |
| 73 | + || configs[MODULE_TYPE_HOOK][smartAccount] != bytes32(0x00) |
| 74 | + || configs[MODULE_TYPE_FALLBACK][smartAccount] != bytes32(0x00) |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments