0
# Account Abstraction
1
2
Draft ERC-7579 account abstraction implementations enabling modular smart contract accounts with validator, executor, and hook support.
3
4
## Capabilities
5
6
### ERC-7579 Account
7
8
Modular smart contract account supporting validators, executors, fallbacks, and hooks.
9
10
```solidity { .api }
11
/**
12
* @dev Implementation of ERC-7579 account abstraction
13
*/
14
abstract contract AccountERC7579Upgradeable {
15
function __AccountERC7579_init(
16
bytes[] calldata validators,
17
bytes[] calldata executors
18
) internal onlyInitializing;
19
20
/**
21
* @dev Install a module on the account
22
*/
23
function installModule(
24
uint256 moduleTypeId,
25
address module,
26
bytes calldata initData
27
) external;
28
29
/**
30
* @dev Uninstall a module from the account
31
*/
32
function uninstallModule(
33
uint256 moduleTypeId,
34
address module,
35
bytes calldata deinitData
36
) external;
37
38
/**
39
* @dev Check if a module is installed
40
*/
41
function isModuleInstalled(
42
uint256 moduleTypeId,
43
address module,
44
bytes calldata additionalContext
45
) external view returns (bool);
46
47
/**
48
* @dev Returns true if this contract implements the interface
49
*/
50
function supportsExecutionMode(bytes32 encodedMode) external pure returns (bool);
51
52
/**
53
* @dev Returns true if the module is supported
54
*/
55
function supportsModule(uint256 moduleTypeId) external pure returns (bool);
56
57
/**
58
* @dev Execute a single call
59
*/
60
function execute(
61
bytes32 mode,
62
bytes calldata executionCalldata
63
) external;
64
65
/**
66
* @dev Execute from an executor module
67
*/
68
function executeFromExecutor(
69
bytes32 mode,
70
bytes calldata executionCalldata
71
) external returns (bytes[] memory returnData);
72
}
73
74
// Module type constants
75
uint256 constant MODULE_TYPE_VALIDATOR = 1;
76
uint256 constant MODULE_TYPE_EXECUTOR = 2;
77
uint256 constant MODULE_TYPE_FALLBACK = 3;
78
uint256 constant MODULE_TYPE_HOOK = 4;
79
```
80
81
### ERC-7579 Account with Hooks
82
83
Extended account abstraction implementation with hook support for transaction lifecycle management.
84
85
```solidity { .api }
86
/**
87
* @dev Extension with hooks support
88
*/
89
abstract contract AccountERC7579HookedUpgradeable {
90
function __AccountERC7579Hooked_init(
91
bytes[] calldata validators,
92
bytes[] calldata executors,
93
bytes[] calldata hooks
94
) internal onlyInitializing;
95
96
/**
97
* @dev Install a hook module
98
*/
99
function installHook(
100
address hook,
101
bytes calldata initData
102
) external;
103
104
/**
105
* @dev Uninstall a hook module
106
*/
107
function uninstallHook(
108
address hook,
109
bytes calldata deinitData
110
) external;
111
112
// Inherits all AccountERC7579Upgradeable functions
113
}
114
```
115
116
## Usage Examples
117
118
### Basic Smart Account
119
120
```solidity
121
import {AccountERC7579Upgradeable} from "@openzeppelin/contracts-upgradeable/account/extensions/draft-AccountERC7579Upgradeable.sol";
122
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
123
124
contract MySmartAccount is AccountERC7579Upgradeable, OwnableUpgradeable {
125
function initialize(
126
address initialOwner,
127
bytes[] calldata validators,
128
bytes[] calldata executors
129
) initializer public {
130
__AccountERC7579_init(validators, executors);
131
__Ownable_init(initialOwner);
132
}
133
134
function executeTransaction(
135
address to,
136
uint256 value,
137
bytes calldata data
138
) external onlyOwner {
139
bytes32 mode = bytes32(0); // Single execution mode
140
bytes memory executionCalldata = abi.encode(to, value, data);
141
execute(mode, executionCalldata);
142
}
143
}
144
```
145
146
### Account with Hooks
147
148
```solidity
149
import {AccountERC7579HookedUpgradeable} from "@openzeppelin/contracts-upgradeable/account/extensions/draft-AccountERC7579HookedUpgradeable.sol";
150
151
contract HookedSmartAccount is AccountERC7579HookedUpgradeable {
152
function initialize(
153
bytes[] calldata validators,
154
bytes[] calldata executors,
155
bytes[] calldata hooks
156
) initializer public {
157
__AccountERC7579Hooked_init(validators, executors, hooks);
158
}
159
160
function addSecurityHook(address hook, bytes calldata initData) external {
161
installHook(hook, initData);
162
}
163
}
164
```