@@ -4,13 +4,10 @@ pragma solidity ^0.8.12;
44// Utils
55
66import "../utils/BaseRouter.sol " ;
7- import "../../extension/Multicall.sol " ;
8- import "../../openzeppelin-presets/proxy/Clones.sol " ;
97import "../../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 " ;
1411
1512// Smart wallet implementation
1613import "../utils/AccountExtension.sol " ;
@@ -25,98 +22,26 @@ import { ManagedAccount, IEntryPoint } from "./ManagedAccount.sol";
2522// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
2623// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
2724
28- contract ManagedAccountFactory is IAccountFactory , Multicall , PermissionsEnumerable , BaseRouter {
29- using EnumerableSet for EnumerableSet.AddressSet;
30-
25+ contract ManagedAccountFactory is BaseAccountFactory , PermissionsEnumerable , BaseRouter {
3126 /*///////////////////////////////////////////////////////////////
3227 State
3328 //////////////////////////////////////////////////////////////*/
3429
35- ManagedAccount private immutable _accountImplementation;
36-
37- mapping (address => EnumerableSet.AddressSet) private accountsOfSigner;
38- mapping (address => EnumerableSet.AddressSet) private signersOfAccount;
39-
4030 address public immutable defaultExtension;
4131
4232 /*///////////////////////////////////////////////////////////////
4333 Constructor
4434 //////////////////////////////////////////////////////////////*/
4535
46- constructor (IEntryPoint _entrypoint ) {
36+ constructor (IEntryPoint _entrypoint ) BaseAccountFactory ( payable ( address ( new ManagedAccount (_entrypoint)))) {
4737 defaultExtension = address (new AccountExtension (address (_entrypoint), address (this )));
4838 _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);
9339 }
9440
9541 /*///////////////////////////////////////////////////////////////
9642 View functions
9743 //////////////////////////////////////////////////////////////*/
9844
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-
12045 /// @dev Returns the extension implementation address stored in router, for the given function.
12146 function getImplementationForFunction (bytes4 _functionSelector ) public view override returns (address ) {
12247 address impl = getExtensionForFunction (_functionSelector).implementation;
@@ -127,6 +52,16 @@ contract ManagedAccountFactory is IAccountFactory, Multicall, PermissionsEnumera
12752 Internal functions
12853 //////////////////////////////////////////////////////////////*/
12954
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.
13065 function _canSetExtension () internal view virtual override returns (bool ) {
13166 return hasRole (DEFAULT_ADMIN_ROLE, msg .sender );
13267 }
0 commit comments