@@ -4,13 +4,10 @@ pragma solidity ^0.8.12;
4
4
// Utils
5
5
6
6
import "../utils/BaseRouter.sol " ;
7
- import "../../extension/Multicall.sol " ;
8
- import "../../openzeppelin-presets/proxy/Clones.sol " ;
9
7
import "../../dynamic-contracts/extension/PermissionsEnumerable.sol " ;
10
- import "../../openzeppelin-presets/utils/structs/EnumerableSet.sol " ;
11
-
12
- // Interface
13
- import "../interfaces/IAccountFactory.sol " ;
8
+ import "../utils/BaseAccountFactory.sol " ;
9
+ import "../utils/BaseAccount.sol " ;
10
+ import "../../openzeppelin-presets/proxy/Clones.sol " ;
14
11
15
12
// Smart wallet implementation
16
13
import "../utils/AccountExtension.sol " ;
@@ -25,98 +22,26 @@ import { ManagedAccount, IEntryPoint } from "./ManagedAccount.sol";
25
22
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
26
23
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
27
24
28
- contract ManagedAccountFactory is IAccountFactory , Multicall , PermissionsEnumerable , BaseRouter {
29
- using EnumerableSet for EnumerableSet.AddressSet;
30
-
25
+ contract ManagedAccountFactory is BaseAccountFactory , PermissionsEnumerable , BaseRouter {
31
26
/*///////////////////////////////////////////////////////////////
32
27
State
33
28
//////////////////////////////////////////////////////////////*/
34
29
35
- ManagedAccount private immutable _accountImplementation;
36
-
37
- mapping (address => EnumerableSet.AddressSet) private accountsOfSigner;
38
- mapping (address => EnumerableSet.AddressSet) private signersOfAccount;
39
-
40
30
address public immutable defaultExtension;
41
31
42
32
/*///////////////////////////////////////////////////////////////
43
33
Constructor
44
34
//////////////////////////////////////////////////////////////*/
45
35
46
- constructor (IEntryPoint _entrypoint ) {
36
+ constructor (IEntryPoint _entrypoint ) BaseAccountFactory ( payable ( address ( new ManagedAccount (_entrypoint)))) {
47
37
defaultExtension = address (new AccountExtension (address (_entrypoint), address (this )));
48
38
_setupRole (DEFAULT_ADMIN_ROLE, msg .sender );
49
- _accountImplementation = new ManagedAccount (_entrypoint);
50
- }
51
-
52
- /*///////////////////////////////////////////////////////////////
53
- External functions
54
- //////////////////////////////////////////////////////////////*/
55
-
56
- /// @notice Deploys a new Account for admin.
57
- function createAccount (address _admin ) external returns (address ) {
58
- address impl = address (_accountImplementation);
59
- bytes32 salt = keccak256 (abi.encode (_admin));
60
- address account = Clones.predictDeterministicAddress (impl, salt);
61
-
62
- if (account.code.length > 0 ) {
63
- return account;
64
- }
65
-
66
- account = Clones.cloneDeterministic (impl, salt);
67
-
68
- ManagedAccount (payable (account)).initialize (_admin);
69
-
70
- emit AccountCreated (account, _admin);
71
-
72
- return account;
73
- }
74
-
75
- /// @notice Callback function for an Account to register its signers.
76
- function addSigner (address _signer ) external {
77
- address account = msg .sender ;
78
-
79
- accountsOfSigner[_signer].add (account);
80
- signersOfAccount[account].add (_signer);
81
-
82
- emit SignerAdded (account, _signer);
83
- }
84
-
85
- /// @notice Callback function for an Account to un-register its signers.
86
- function removeSigner (address _signer ) external {
87
- address account = msg .sender ;
88
-
89
- accountsOfSigner[_signer].remove (account);
90
- signersOfAccount[account].remove (_signer);
91
-
92
- emit SignerRemoved (account, _signer);
93
39
}
94
40
95
41
/*///////////////////////////////////////////////////////////////
96
42
View functions
97
43
//////////////////////////////////////////////////////////////*/
98
44
99
- /// @notice Returns the implementation of the Account.
100
- function accountImplementation () external view override returns (address ) {
101
- return address (_accountImplementation);
102
- }
103
-
104
- /// @notice Returns the address of an Account that would be deployed with the given admin signer.
105
- function getAddress (address _adminSigner ) public view returns (address ) {
106
- bytes32 salt = keccak256 (abi.encode (_adminSigner));
107
- return Clones.predictDeterministicAddress (address (_accountImplementation), salt);
108
- }
109
-
110
- /// @notice Returns all signers of an account.
111
- function getSignersOfAccount (address account ) external view returns (address [] memory signers ) {
112
- return signersOfAccount[account].values ();
113
- }
114
-
115
- /// @notice Returns all accounts that the given address is a signer of.
116
- function getAccountsOfSigner (address signer ) external view returns (address [] memory accounts ) {
117
- return accountsOfSigner[signer].values ();
118
- }
119
-
120
45
/// @dev Returns the extension implementation address stored in router, for the given function.
121
46
function getImplementationForFunction (bytes4 _functionSelector ) public view override returns (address ) {
122
47
address impl = getExtensionForFunction (_functionSelector).implementation;
@@ -127,6 +52,16 @@ contract ManagedAccountFactory is IAccountFactory, Multicall, PermissionsEnumera
127
52
Internal functions
128
53
//////////////////////////////////////////////////////////////*/
129
54
55
+ /// @dev Called in `createAccount`. Initializes the account contract created in `createAccount`.
56
+ function _initializeAccount (
57
+ address _account ,
58
+ address _admin ,
59
+ bytes calldata _data
60
+ ) internal override {
61
+ ManagedAccount (payable (_account)).initialize (_admin, _data);
62
+ }
63
+
64
+ /// @dev Returns whether an extension can be set in the given execution context.
130
65
function _canSetExtension () internal view virtual override returns (bool ) {
131
66
return hasRole (DEFAULT_ADMIN_ROLE, msg .sender );
132
67
}
0 commit comments