Files
zk-account-abstraction/contracts/bls/BLSAccountFactory.sol
Dror Tirosh 976d3f2758 AA-91 factories (#151)
* fix factories

BLSFactory use same model as SimpleAccount, using immutable wallet and
only user-specific params in initializer
add factory for TestAggregatedAccount sapmle contract
Create2Factory - use arachnid's de-facto standard deployer, instead of of
the nonstandard EIP2470 (specifically, arachnid's deployer revert on errors)

* gnosis account factory
now Gnosis-Safe  based account uses only standard gnosis contracts. The new GnosisSafeAcccountFactory only wraps the standard GnosisSafeProxyFactory to create the proxy (and initialize it with our modules)
2022-12-20 20:35:08 +02:00

55 lines
2.1 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/utils/Create2.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "../interfaces/IEntryPoint.sol";
import "./BLSAccount.sol";
/**
* Based n SimpleAccountFactory
* can't be a subclass, since both constructor and createAccount depend on the
* actual wallet contract constructor and initializer
*/
contract BLSAccountFactory {
BLSAccount public immutable accountImplementation;
constructor(IEntryPoint entryPoint, address aggregator){
accountImplementation = new BLSAccount(entryPoint, aggregator);
}
/**
* create an account, and return its address.
* returns the address even if the account is already deployed.
* Note that during UserOperation execution, this method is called only if the account is not deployed.
* This method returns an existing account address so that entryPoint.getSenderAddress() would work even after account creation
* Also note that out BLSSignatureAggregator requires that the public-key is the last parameter
*/
function createAccount(uint salt, uint256[4] memory aPublicKey) public returns (BLSAccount) {
address addr = getAddress(salt, aPublicKey);
uint codeSize = addr.code.length;
if (codeSize > 0) {
return BLSAccount(payable(addr));
}
return BLSAccount(payable(new ERC1967Proxy{salt : bytes32(salt)}(
address(accountImplementation),
abi.encodeCall(BLSAccount.initialize, aPublicKey)
)));
}
/**
* calculate the counterfactual address of this account as it would be returned by createAccount()
*/
function getAddress(uint salt, uint256[4] memory aPublicKey) public view returns (address) {
return Create2.computeAddress(bytes32(salt), keccak256(abi.encodePacked(
type(ERC1967Proxy).creationCode,
abi.encode(
address(accountImplementation),
abi.encodeCall(BLSAccount.initialize, (aPublicKey))
)
)));
}
}