-
Notifications
You must be signed in to change notification settings - Fork 588
Expand file tree
/
Copy pathManagedAccountFactory.sol
More file actions
68 lines (56 loc) · 3.01 KB
/
ManagedAccountFactory.sol
File metadata and controls
68 lines (56 loc) · 3.01 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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
// Utils
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouter.sol";
import "../utils/BaseAccountFactory.sol";
// Extensions
import "../../../extension/upgradeable//PermissionsEnumerable.sol";
import "../../../extension/upgradeable//ContractMetadata.sol";
// Smart wallet implementation
import { ManagedAccount, IEntryPoint } from "./ManagedAccount.sol";
// $$\ $$\ $$\ $$\ $$\
// $$ | $$ | \__| $$ | $$ |
// $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\
// \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\
// $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
// $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable, BaseRouter {
/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/
constructor(
address _defaultAdmin,
IEntryPoint _entrypoint,
Extension[] memory _defaultExtensions
)
BaseRouter(_defaultExtensions)
BaseAccountFactory(payable(address(new ManagedAccount(_entrypoint, address(this)))), address(_entrypoint))
{
__BaseRouter_init();
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
bytes32 _extensionRole = keccak256("EXTENSION_ROLE");
_setupRole(_extensionRole, _defaultAdmin);
_setRoleAdmin(_extensionRole, _extensionRole);
}
/*///////////////////////////////////////////////////////////////
Internal functions
//////////////////////////////////////////////////////////////*/
/// @dev Called in `createAccount`. Initializes the account contract created in `createAccount`.
function _initializeAccount(address _account, address _admin, bytes calldata _data) internal override {
ManagedAccount(payable(_account)).initialize(_admin, _data);
}
/// @dev Returns whether all relevant permission and other checks are met before any upgrade.
function _isAuthorizedCallToUpgrade() internal view virtual override returns (bool) {
return hasRole(keccak256("EXTENSION_ROLE"), msg.sender);
}
/// @dev Returns whether contract metadata can be set in the given execution context.
function _canSetContractURI() internal view virtual override returns (bool) {
return hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
/// @notice Returns the sender in the given execution context.
function _msgSender() internal view virtual override(Multicall, Permissions) returns (address) {
return msg.sender;
}
}