|
1 | 1 | // SPDX-License-Identifier: MIT |
2 | 2 | pragma solidity ^0.8.28; |
3 | 3 |
|
4 | | -// Generic Account Factory which can deploy SA with more modules (multiple validation schemes, executors, hooks etc upon deployment itself) |
| 4 | +import {IStartaleAccountFactory} from '../interfaces/IStartaleAccountFactory.sol'; |
| 5 | +import {ProxyLib} from '../lib/ProxyLib.sol'; |
| 6 | +import {Stakeable} from '../utils/Stakeable.sol'; |
| 7 | + |
| 8 | +/// @title Startale Account Factory |
| 9 | +/// @dev Generic Account Factory which can deploy SA with more modules (multiple validation schemes, executors, hooks etc upon deployment itself) |
| 10 | +/// @notice Manages the creation of Modular Smart Accounts compliant with ERC-7579 and ERC-4337 using a factory pattern. |
| 11 | +/// @author Startale labs |
| 12 | +contract StartaleAccountFactory is Stakeable, IStartaleAccountFactory { |
| 13 | + /// @notice Address of the implementation contract used to create new Startale Account instances. |
| 14 | + /// @dev This address is immutable and set upon deployment, ensuring the implementation cannot be changed. |
| 15 | + address public immutable ACCOUNT_IMPLEMENTATION; |
| 16 | + |
| 17 | + /// @notice Constructor to set the smart account implementation address and the factory owner. |
| 18 | + /// @param implementation_ The address of the Startale Account implementation to be used for all deployments. |
| 19 | + /// @param owner_ The address of the owner of the factory. |
| 20 | + constructor(address implementation_, address owner_) Stakeable(owner_) { |
| 21 | + require(implementation_ != address(0), ImplementationAddressCanNotBeZero()); |
| 22 | + require(owner_ != address(0), ZeroAddressNotAllowed()); |
| 23 | + ACCOUNT_IMPLEMENTATION = implementation_; |
| 24 | + } |
| 25 | + |
| 26 | + /// @notice Creates a new Startale Account with the provided initialization data. |
| 27 | + /// @param initData Initialization data to be called on the new Smart Account. |
| 28 | + /// @param salt Unique salt for the Smart Account creation. |
| 29 | + /// @return The address of the newly created Startale Account. |
| 30 | + function createAccount(bytes calldata initData, bytes32 salt) external payable override returns (address payable) { |
| 31 | + // Deploy the Startale Account using the ProxyLib |
| 32 | + (bool alreadyDeployed, address payable account) = ProxyLib.deployProxy(ACCOUNT_IMPLEMENTATION, salt, initData); |
| 33 | + if (!alreadyDeployed) { |
| 34 | + emit AccountCreated(account, initData, salt); |
| 35 | + } |
| 36 | + return account; |
| 37 | + } |
| 38 | + |
| 39 | + /// @notice Computes the expected address of a Startale Account using the factory's deterministic deployment algorithm. |
| 40 | + /// @param initData - Initialization data to be called on the new Smart Account. |
| 41 | + /// @param salt - Unique salt for the Smart Account creation. |
| 42 | + /// @return expectedAddress The expected address at which the Startale Account will be deployed if the provided parameters are used. |
| 43 | + function computeAccountAddress( |
| 44 | + bytes calldata initData, |
| 45 | + bytes32 salt |
| 46 | + ) external view override returns (address payable expectedAddress) { |
| 47 | + // Return the expected address of the Startale Account using the provided initialization data and salt |
| 48 | + return ProxyLib.predictProxyAddress(ACCOUNT_IMPLEMENTATION, salt, initData); |
| 49 | + } |
| 50 | +} |
0 commit comments