Skip to content

Commit 2529cb9

Browse files
authored
Remove state from account factories (#368)
1 parent c26afb0 commit 2529cb9

File tree

3 files changed

+0
-129
lines changed

3 files changed

+0
-129
lines changed

contracts/smart-wallet/TWAccountFactory.sol

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@ import "./TWAccount.sol";
2121
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
2222
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
2323

24-
/*///////////////////////////////////////////////////////////////
25-
Storage layout
26-
//////////////////////////////////////////////////////////////*/
27-
28-
library TWAccountFactoryStorage {
29-
bytes32 internal constant TWACCOUNT_FACTORY_STORAGE_POSITION = keccak256("twaccount.factory.storage");
30-
31-
struct Data {
32-
TWStringSet.Set allAccounts;
33-
mapping(address => TWStringSet.Set) accountsOfSigner;
34-
}
35-
36-
function factoryStorage() internal pure returns (Data storage twaccountFactoryData) {
37-
bytes32 position = TWACCOUNT_FACTORY_STORAGE_POSITION;
38-
assembly {
39-
twaccountFactoryData.slot := position
40-
}
41-
}
42-
}
43-
4424
contract TWAccountFactory is ITWAccountFactory, Multicall {
4525
using TWStringSet for TWStringSet.Set;
4626

@@ -76,8 +56,6 @@ contract TWAccountFactory is ITWAccountFactory, Multicall {
7656

7757
TWAccount(payable(account)).initialize(_admin);
7858

79-
_setupAccount(_admin, _accountId);
80-
8159
emit AccountCreated(account, _admin, _accountId);
8260

8361
return account;
@@ -97,38 +75,4 @@ contract TWAccountFactory is ITWAccountFactory, Multicall {
9775
bytes32 salt = keccak256(abi.encode(_accountId));
9876
return Clones.predictDeterministicAddress(address(_accountImplementation), salt);
9977
}
100-
101-
/// @notice Returns the list of accounts created by a signer.
102-
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory) {
103-
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
104-
return _formatAccounts(data.accountsOfSigner[_signer].values());
105-
}
106-
107-
/// @notice Returns the list of all accounts.
108-
function getAllAccounts() external view returns (AccountInfo[] memory accounts) {
109-
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
110-
return _formatAccounts(data.allAccounts.values());
111-
}
112-
113-
/*///////////////////////////////////////////////////////////////
114-
Internal functions
115-
//////////////////////////////////////////////////////////////*/
116-
117-
/// @dev Formats a list of accountIds to a list of `AccountInfo` (account id + account address).
118-
function _formatAccounts(string[] memory _accountIds) internal view returns (AccountInfo[] memory accounts) {
119-
uint256 len = _accountIds.length;
120-
accounts = new AccountInfo[](len);
121-
for (uint256 i = 0; i < len; i += 1) {
122-
string memory accountId = _accountIds[i];
123-
address account = getAddress(accountId);
124-
accounts[i] = AccountInfo(accountId, account);
125-
}
126-
}
127-
128-
/// @dev Adds an account to the list of accounts created by a signer.
129-
function _setupAccount(address _signer, string memory _accountId) internal {
130-
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
131-
data.allAccounts.add(_accountId);
132-
data.accountsOfSigner[_signer].add(_accountId);
133-
}
13478
}

contracts/smart-wallet/TWDynamicAccountFactory.sol

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ import "./TWDynamicAccount.sol";
2121
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
2222
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
2323

24-
/*///////////////////////////////////////////////////////////////
25-
Storage layout
26-
//////////////////////////////////////////////////////////////*/
27-
28-
library TWDynamicAccountFactoryStorage {
29-
bytes32 internal constant DYNAMIC_ACCOUNT_FACTORY_STORAGE_POSITION =
30-
keccak256("tw.dynamic.account.factory.storage");
31-
32-
struct Data {
33-
TWStringSet.Set allAccounts;
34-
mapping(address => TWStringSet.Set) accountsOfSigner;
35-
}
36-
37-
function factoryStorage() internal pure returns (Data storage dynamicAccountFactoryData) {
38-
bytes32 position = DYNAMIC_ACCOUNT_FACTORY_STORAGE_POSITION;
39-
assembly {
40-
dynamicAccountFactoryData.slot := position
41-
}
42-
}
43-
}
44-
4524
contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {
4625
using TWStringSet for TWStringSet.Set;
4726

@@ -77,8 +56,6 @@ contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {
7756

7857
TWAccount(payable(account)).initialize(_admin);
7958

80-
_setupAccount(_admin, _accountId);
81-
8259
emit AccountCreated(account, _admin, _accountId);
8360

8461
return account;
@@ -98,38 +75,4 @@ contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {
9875
bytes32 salt = keccak256(abi.encode(_accountId));
9976
return Clones.predictDeterministicAddress(address(_accountImplementation), salt);
10077
}
101-
102-
/// @notice Returns the list of accounts created by a signer.
103-
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory) {
104-
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
105-
return _formatAccounts(data.accountsOfSigner[_signer].values());
106-
}
107-
108-
/// @notice Returns the list of all accounts.
109-
function getAllAccounts() external view returns (AccountInfo[] memory accounts) {
110-
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
111-
return _formatAccounts(data.allAccounts.values());
112-
}
113-
114-
/*///////////////////////////////////////////////////////////////
115-
Internal functions
116-
//////////////////////////////////////////////////////////////*/
117-
118-
/// @dev Formats a list of accountIds to a list of `AccountInfo` (account id + account address).
119-
function _formatAccounts(string[] memory _accountIds) internal view returns (AccountInfo[] memory accounts) {
120-
uint256 len = _accountIds.length;
121-
accounts = new AccountInfo[](len);
122-
for (uint256 i = 0; i < len; i += 1) {
123-
string memory accountId = _accountIds[i];
124-
address account = getAddress(accountId);
125-
accounts[i] = AccountInfo(accountId, account);
126-
}
127-
}
128-
129-
/// @dev Adds an account to the list of accounts created by a signer.
130-
function _setupAccount(address _signer, string memory _accountId) internal {
131-
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
132-
data.allAccounts.add(_accountId);
133-
data.accountsOfSigner[_signer].add(_accountId);
134-
}
13578
}

contracts/smart-wallet/interfaces/ITWAccountFactory.sol

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
pragma solidity ^0.8.12;
33

44
interface ITWAccountFactory {
5-
/*///////////////////////////////////////////////////////////////
6-
Structs
7-
//////////////////////////////////////////////////////////////*/
8-
9-
/// @notice Smart account details: address and ID (used as salt).
10-
struct AccountInfo {
11-
string id;
12-
address account;
13-
}
14-
155
/*///////////////////////////////////////////////////////////////
166
Events
177
//////////////////////////////////////////////////////////////*/
@@ -35,10 +25,4 @@ interface ITWAccountFactory {
3525

3626
/// @notice Returns the address of an Account that would be deployed with the given accountId as salt.
3727
function getAddress(string memory accountId) external view returns (address);
38-
39-
/// @notice Returns the list of accounts created by a signer.
40-
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory);
41-
42-
/// @notice Returns the list of all accounts.
43-
function getAllAccounts() external view returns (AccountInfo[] memory);
4428
}

0 commit comments

Comments
 (0)