-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathAccountStorage.sol
More file actions
94 lines (84 loc) · 4.18 KB
/
Copy pathAccountStorage.sol
File metadata and controls
94 lines (84 loc) · 4.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// This file is part of Modular Account.
//
// Copyright 2024 Alchemy Insights, Inc.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
// Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with this program. If not, see
// <https://www.gnu.org/licenses/>.
pragma solidity ^0.8.28;
import {HookConfig, ValidationFlags} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {LinkedListSet, SetValue} from "../libraries/LinkedListSetLib.sol";
import {ValidationLookupKey} from "../libraries/ValidationLocatorLib.sol";
// ERC-7201 derived storage slot.
// keccak256(abi.encode(uint256(keccak256("Alchemy.ModularAccount.Storage_V2")) - 1)) & ~bytes32(uint256(0xff))
bytes32 constant _ACCOUNT_STORAGE_SLOT = 0x596912a710dec01bac203cb0ed2c7e56a2ce6b2a68276967fff6dd57561bdd00;
/// @notice Represents data associated with a specific function selector.
struct ExecutionStorage {
// The module that implements this execution function.
// If this is a native function, the address should remain address(0).
address module;
// Whether or not the function needs runtime validation, or can be called without any validation. The function
// can still be state changing if this flag is set to true.
// Note that even if this is set to true, user op validation will still be required, otherwise any caller could
// drain the account of native tokens by wasting gas.
bool skipRuntimeValidation;
// Whether or not a global validation function may be used to validate this function.
bool allowGlobalValidation;
// The execution hooks for this function selector.
LinkedListSet executionHooks;
}
/// @notice Represents data associated with a specific validation function.
struct ValidationStorage {
// The address of the validation module.
address module;
// ValidationFlags layout:
// 0b00000___ // unused
// 0b_____A__ // isGlobal
// 0b______B_ // isSignatureValidation
// 0b_______C // isUserOpValidation
ValidationFlags validationFlags;
// Length of the validation hooks for this validation function. The length is stored here, in the same storage
// slot as the flags, to save an `sload` when putting the hooks into memory.
uint8 validationHookCount;
// Length of execution hooks for this validation function. The length is stored here, in the same storage slot
// as the flags, to save an `sload` when putting the hooks into memory.
uint8 executionHookCount;
// The validation hooks for this validation function.
LinkedListSet validationHooks;
// Execution hooks to run with this validation function.
LinkedListSet executionHooks;
// The set of selectors that may be validated by this validation function.
LinkedListSet selectors;
}
/// @custom:storage-location erc7201:Alchemy.ModularAccount.Storage_V2
struct AccountStorage {
// AccountStorageInitializable variables.
uint64 initialized;
bool initializing;
// Execution functions and their associated functions.
mapping(bytes4 selector => ExecutionStorage) executionStorage;
// Validation functions and their associated functions.
mapping(ValidationLookupKey lookupKey => ValidationStorage) validationStorage;
// Module-defined ERC-165 interfaces installed on the account.
mapping(bytes4 => uint256) supportedIfaces;
}
function getAccountStorage() pure returns (AccountStorage storage _storage) {
assembly ("memory-safe") {
_storage.slot := _ACCOUNT_STORAGE_SLOT
}
}
function toSetValue(HookConfig hookConfig) pure returns (SetValue) {
return SetValue.wrap(bytes31(HookConfig.unwrap(hookConfig)));
}
function toSetValue(bytes4 selector) pure returns (SetValue) {
return SetValue.wrap(bytes31(selector));
}