AccountFactory
Inherits: IAccountFactory
Title: AccountFactory
Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)
Deterministic factory for EIP-2535 Diamond smart accounts, suitable for ERC-4337 counterfactual
initCode onboarding. Holds a fixed facet blueprint + initializer; each createAccount CREATE2-
deploys a AccountDiamond proxy and initializes it with the blueprint and the owner.
The proxy has no constructor args, so its initcode hash is constant and the CREATE2 address depends
only on (factory, keccak256(owner, salt)). Deploy this factory itself deterministically (e.g. via
CreateX) and the same (owner, salt) lands at the SAME account address on every chain. Folding the
owner into the salt binds each counterfactual address to its owner, so no third party can occupy it
under a different owner. Not a Diamond facet — a standalone singleton with its own storage.
Constants
accountInit
The initializer contract delegatecalled during each account's diamondCut initialization.
address public immutable accountInit;Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
_proxyInitCodeHash
keccak256(type(AccountDiamond).creationCode) — the CREATE2 initcode hash, fixed at construction.
bytes32 private immutable _proxyInitCodeHash;State Variables
_blueprint
The facet cuts applied to every account. Fixed at construction; a different blueprint ⇒ a different factory ⇒ a different address set, preserving the counterfactual guarantee.
FacetCut[] private _blueprint;Functions
constructor
constructor(FacetCut[] memory __blueprint, address _accountInit);Parameters
| Name | Type | Description |
|---|---|---|
| __blueprint | FacetCut[] | The facet cuts (Add) wiring a complete account. |
| _accountInit | address | Initializer delegatecalled during diamondCut; MUST expose init(address owner). |
createAccount
Deploys (or returns the existing) Diamond account for (owner, salt) and initializes it
with the factory's fixed facet blueprint and the owner.
function createAccount(address owner, bytes32 salt) external returns (address account);Parameters
| Name | Type | Description |
|---|---|---|
| owner | address | The initial signing owner of the account. |
| salt | bytes32 | Caller-chosen salt; distinct salts yield distinct accounts for the same owner. |
Returns
| Name | Type | Description |
|---|---|---|
| account | address | The deterministic account address (equals getAddress). |
getAddress
The counterfactual address createAccount(owner, salt) will deploy to.
function getAddress(address owner, bytes32 salt) external view returns (address account);Parameters
| Name | Type | Description |
|---|---|---|
| owner | address | The prospective owner. |
| salt | bytes32 | The prospective salt. |
Returns
| Name | Type | Description |
|---|---|---|
| account | address | The deterministic CREATE2 address. |
_saltFor
Binds the account address to its owner: keccak256(owner, salt).
function _saltFor(address owner, bytes32 salt) private pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| owner | address | |
| salt | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
_predict
Standard CREATE2 address derivation for the AccountDiamond proxy.
function _predict(bytes32 s) private view returns (address);Parameters
| Name | Type | Description |
|---|---|---|
| s | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |