-
Notifications
You must be signed in to change notification settings - Fork 4
/
AccountFactory.sol
59 lines (52 loc) · 1.98 KB
/
AccountFactory.sol
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
pragma solidity ^0.8.0;
import "zksync-contracts/Constants.sol";
import "zksync-contracts/libraries/SystemContractsCaller.sol";
import "./interfaces/IAccountRegistry.sol";
/**
@title Factory Contract that deploys Account contract
@author Porco Rosso<porcorossoj89@gmail.com>
@notice This is a factory contract that deploys Account contract, which also passes deployed addresses to AccountRegistry contract.
*/
contract AccountFactory {
bytes32 public accountBytecodeHash;
address public moduleManager;
address public accountRegistry;
constructor(
bytes32 _accountBytecodeHash,
address _moduleManager,
address _accountRegistry
) {
accountBytecodeHash = _accountBytecodeHash;
moduleManager = _moduleManager;
accountRegistry = _accountRegistry;
}
/**
@notice this function deploys an Account contract and passes deployed address to AccountRegistry.
@param salt arbitrary hash to pass create2Account metho
@param owner signer address of the deployed account
@return accountAddress deployed Account contract address
*/
function deployAccount(bytes32 salt, address owner)
external
returns (address accountAddress)
{
(bool success, bytes memory returnData) = SystemContractsCaller
.systemCallWithReturndata(
uint32(gasleft()),
address(DEPLOYER_SYSTEM_CONTRACT),
uint128(0),
abi.encodeCall(
DEPLOYER_SYSTEM_CONTRACT.create2Account,
(
salt,
accountBytecodeHash,
abi.encode(owner, moduleManager),
IContractDeployer.AccountAbstractionVersion.Version1
)
)
);
require(success, "Deployment Failed");
accountAddress = abi.decode(returnData, (address));
IAccountRegistry(accountRegistry)._storeAccount(accountAddress);
}
}