-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathModularAccountView.sol
More file actions
65 lines (58 loc) · 3.13 KB
/
ModularAccountView.sol
File metadata and controls
65 lines (58 loc) · 3.13 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
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {HookConfig, IERC6900Account, ModuleEntity} from "../interfaces/IERC6900Account.sol";
import {ExecutionDataView, IERC6900AccountView, ValidationDataView} from "../interfaces/IERC6900AccountView.sol";
import {HookConfigLib} from "../libraries/HookConfigLib.sol";
import {ExecutionStorage, ValidationStorage, getAccountStorage, toHookConfig} from "./AccountStorage.sol";
abstract contract ModularAccountView is IERC6900AccountView {
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableMap for EnumerableMap.AddressToUintMap;
using HookConfigLib for HookConfig;
/// @inheritdoc IERC6900AccountView
function getExecutionData(bytes4 selector) external view override returns (ExecutionDataView memory data) {
ExecutionStorage storage executionStorage = getAccountStorage().executionStorage[selector];
if (
selector == IERC6900Account.execute.selector || selector == IERC6900Account.executeBatch.selector
|| selector == UUPSUpgradeable.upgradeToAndCall.selector
|| selector == IERC6900Account.installExecution.selector
|| selector == IERC6900Account.uninstallExecution.selector
) {
data.module = address(this);
data.allowGlobalValidation = true;
} else {
data.module = executionStorage.module;
data.skipRuntimeValidation = executionStorage.skipRuntimeValidation;
data.allowGlobalValidation = executionStorage.allowGlobalValidation;
}
uint256 executionHooksLen = executionStorage.executionHooks.length();
data.executionHooks = new HookConfig[](executionHooksLen);
for (uint256 i = 0; i < executionHooksLen; ++i) {
data.executionHooks[i] = toHookConfig(executionStorage.executionHooks.at(i));
}
}
/// @inheritdoc IERC6900AccountView
function getValidationData(ModuleEntity validationFunction)
external
view
override
returns (ValidationDataView memory data)
{
ValidationStorage storage validationStorage = getAccountStorage().validationStorage[validationFunction];
data.validationFlags = validationStorage.validationFlags;
data.validationHooks = validationStorage.validationHooks;
uint256 execHooksLen = validationStorage.executionHooks.length();
data.executionHooks = new HookConfig[](execHooksLen);
for (uint256 i = 0; i < execHooksLen; ++i) {
data.executionHooks[i] = toHookConfig(validationStorage.executionHooks.at(i));
}
bytes32[] memory selectors = validationStorage.selectors.values();
uint256 selectorsLen = selectors.length;
data.selectors = new bytes4[](selectorsLen);
for (uint256 j = 0; j < selectorsLen; ++j) {
data.selectors[j] = bytes4(selectors[j]);
}
}
}