-
Notifications
You must be signed in to change notification settings - Fork 25
/
KnownSelectorsLib.sol
61 lines (56 loc) · 3.54 KB
/
KnownSelectorsLib.sol
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
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
import {IAccount} from "@eth-infinitism/account-abstraction/interfaces/IAccount.sol";
import {IAggregator} from "@eth-infinitism/account-abstraction/interfaces/IAggregator.sol";
import {IPaymaster} from "@eth-infinitism/account-abstraction/interfaces/IPaymaster.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IExecutionHookModule} from "../interfaces/IExecutionHookModule.sol";
import {IExecutionModule} from "../interfaces/IExecutionModule.sol";
import {IModularAccount} from "../interfaces/IModularAccount.sol";
import {IModularAccountView} from "../interfaces/IModularAccountView.sol";
import {IModule} from "../interfaces/IModule.sol";
import {IValidationHookModule} from "../interfaces/IValidationHookModule.sol";
import {IValidationModule} from "../interfaces/IValidationModule.sol";
/// @dev Library to help to check if a selector is a know function selector of the modular account or ERC-4337
/// contract.
library KnownSelectorsLib {
function isNativeFunction(bytes4 selector) internal pure returns (bool) {
return
// check against IAccount methods
selector == IAccount.validateUserOp.selector
// check against IModularAccount methods
|| selector == IModularAccount.installExecution.selector
|| selector == IModularAccount.uninstallExecution.selector
|| selector == IModularAccount.installValidation.selector
|| selector == IModularAccount.uninstallValidation.selector || selector == IModularAccount.execute.selector
|| selector == IModularAccount.executeBatch.selector
|| selector == IModularAccount.executeWithRuntimeValidation.selector
|| selector == IModularAccount.accountId.selector
// check against IERC165 methods
|| selector == IERC165.supportsInterface.selector
// check against UUPSUpgradeable methods
|| selector == UUPSUpgradeable.proxiableUUID.selector
|| selector == UUPSUpgradeable.upgradeToAndCall.selector
// check against IModularAccountView methods
|| selector == IModularAccountView.getExecutionData.selector
|| selector == IModularAccountView.getValidationData.selector;
}
function isErc4337Function(bytes4 selector) internal pure returns (bool) {
return selector == IAggregator.validateSignatures.selector
|| selector == IAggregator.validateUserOpSignature.selector
|| selector == IAggregator.aggregateSignatures.selector
|| selector == IPaymaster.validatePaymasterUserOp.selector || selector == IPaymaster.postOp.selector;
}
function isIModuleFunction(bytes4 selector) internal pure returns (bool) {
return selector == IModule.onInstall.selector || selector == IModule.onUninstall.selector
|| selector == IModule.moduleId.selector || selector == IExecutionModule.executionManifest.selector
|| selector == IExecutionHookModule.preExecutionHook.selector
|| selector == IExecutionHookModule.postExecutionHook.selector
|| selector == IValidationModule.validateUserOp.selector
|| selector == IValidationModule.validateRuntime.selector
|| selector == IValidationModule.validateSignature.selector
|| selector == IValidationHookModule.preUserOpValidationHook.selector
|| selector == IValidationHookModule.preRuntimeValidationHook.selector;
}
}