Skip to content

Commit 6715717

Browse files
committed
refactor: remove redundant factory check and correct return type for SMA
1 parent 4324a3e commit 6715717

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/account/AccountFactory.sol

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ contract AccountFactory is Ownable {
2020
IEntryPoint public immutable ENTRY_POINT;
2121
address public immutable SINGLE_SIGNER_VALIDATION_MODULE;
2222

23+
error SemiModularAccountAddressMismatch(address expected, address returned);
24+
2325
constructor(
2426
IEntryPoint _entryPoint,
2527
UpgradeableModularAccount _accountImpl,
@@ -66,21 +68,23 @@ contract AccountFactory is Ownable {
6668
return UpgradeableModularAccount(payable(addr));
6769
}
6870

69-
function createSemiModularAccount(address owner, uint256 salt) external returns (UpgradeableModularAccount) {
71+
function createSemiModularAccount(address owner, uint256 salt) external returns (SemiModularAccount) {
7072
// both module address and entityId for fallback validations are hardcoded at the maximum value.
7173
bytes32 fullSalt = getSalt(owner, salt, type(uint32).max);
7274

7375
bytes memory immutables = _getImmutableArgs(owner);
7476

7577
address addr = _getAddressFallbackSigner(immutables, fullSalt);
7678

77-
// short circuit if exists
78-
if (addr.code.length == 0) {
79-
// not necessary to check return addr since next call will fail if so
79+
// LibClone short-circuits if it's already deployed.
80+
(, address instance) =
8081
LibClone.createDeterministicERC1967(address(SEMI_MODULAR_ACCOUNT_IMPL), immutables, fullSalt);
82+
83+
if (instance != addr) {
84+
revert SemiModularAccountAddressMismatch(addr, instance);
8185
}
8286

83-
return UpgradeableModularAccount(payable(addr));
87+
return SemiModularAccount(payable(addr));
8488
}
8589

8690
function addStake(uint32 unstakeDelay) external payable onlyOwner {

test/mocks/SingleSignerFactoryFixture.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ contract SingleSignerFactoryFixture is OptimizedTest {
2525

2626
address public self;
2727

28+
error SemiModularAccountAddressMismatch(address expected, address returned);
29+
2830
constructor(IEntryPoint _entryPoint, SingleSignerValidationModule _singleSignerValidationModule) {
2931
entryPoint = _entryPoint;
3032

@@ -81,12 +83,12 @@ contract SingleSignerFactoryFixture is OptimizedTest {
8183

8284
address addr = _getAddressFallbackSigner(immutables, fullSalt);
8385

84-
// short circuit if exists
85-
if (addr.code.length == 0) {
86-
// not necessary to check return addr since next call will fail if so
87-
// new ERC1967Proxy{salt: getSalt(owner, salt, type(uint32).max)}(address(ACCOUNT_IMPL), "");
88-
// UpgradeableModularAccount(payable(addr)).initialize(owner);
86+
// LibClone short-circuits if it's already deployed.
87+
(, address instance) =
8988
LibClone.createDeterministicERC1967(address(accountImplementation), immutables, fullSalt);
89+
90+
if (instance != addr) {
91+
revert SemiModularAccountAddressMismatch(addr, instance);
9092
}
9193

9294
return UpgradeableModularAccount(payable(addr));

0 commit comments

Comments
 (0)