forked from erc6900/reference-implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseModule.sol
More file actions
54 lines (48 loc) · 2.71 KB
/
BaseModule.sol
File metadata and controls
54 lines (48 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {ERC165, IERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC6900Module} from "../interfaces/IERC6900Module.sol";
/// @title Base contract for modules
/// @dev Implements ERC-165 to support IERC6900Module's interface, which is a requirement
/// for module installation. This also ensures that module interactions cannot
/// happen via the standard execution funtions `execute` and `executeBatch`.
abstract contract BaseModule is ERC165, IERC6900Module {
error NotImplemented();
/// @dev Returns true if this contract implements the interface defined by
/// `interfaceId`. See the corresponding
/// https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
/// to learn more about how these ids are created.
///
/// This function call must use less than 30 000 gas.
///
/// Supporting the IERC6900Module interface is a requirement for module installation. This is also used
/// by the modular account to prevent standard execution functions `execute` and `executeBatch` from
/// making calls to modules.
/// @param interfaceId The interface ID to check for support.
/// @return True if the contract supports `interfaceId`.
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC6900Module).interfaceId || super.supportsInterface(interfaceId);
}
function _getSelectorAndCalldata(bytes calldata data) internal pure returns (bytes4, bytes memory) {
if (bytes4(data[:4]) == IAccountExecute.executeUserOp.selector) {
(PackedUserOperation memory uo,) = abi.decode(data[4:], (PackedUserOperation, bytes32));
bytes4 selector;
bytes memory callData = uo.callData;
// Bytes arr representation: [bytes32(len), bytes4(executeUserOp.selector), bytes4(actualSelector),
// bytes(actualCallData)]
// 1. Copy actualSelector into a new var
// 2. Shorten bytes arry by 8 by: store length - 8 into the new pointer location
// 3. Move the callData pointer by 8
assembly {
selector := mload(add(callData, 36))
let len := mload(callData)
mstore(add(callData, 8), sub(len, 8))
callData := add(callData, 8)
}
return (selector, callData);
}
return (bytes4(data[:4]), data[4:]);
}
}