Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions contracts/smart-wallet/TWAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ import "./TWAccount.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

/*///////////////////////////////////////////////////////////////
Storage layout
//////////////////////////////////////////////////////////////*/

library TWAccountFactoryStorage {
bytes32 internal constant TWACCOUNT_FACTORY_STORAGE_POSITION = keccak256("twaccount.factory.storage");

struct Data {
TWStringSet.Set allAccounts;
mapping(address => TWStringSet.Set) accountsOfSigner;
}

function factoryStorage() internal pure returns (Data storage twaccountFactoryData) {
bytes32 position = TWACCOUNT_FACTORY_STORAGE_POSITION;
assembly {
twaccountFactoryData.slot := position
}
}
}

contract TWAccountFactory is ITWAccountFactory, Multicall {
using TWStringSet for TWStringSet.Set;

Expand Down Expand Up @@ -76,8 +56,6 @@ contract TWAccountFactory is ITWAccountFactory, Multicall {

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

_setupAccount(_admin, _accountId);

emit AccountCreated(account, _admin, _accountId);

return account;
Expand All @@ -97,38 +75,4 @@ contract TWAccountFactory is ITWAccountFactory, Multicall {
bytes32 salt = keccak256(abi.encode(_accountId));
return Clones.predictDeterministicAddress(address(_accountImplementation), salt);
}

/// @notice Returns the list of accounts created by a signer.
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory) {
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
return _formatAccounts(data.accountsOfSigner[_signer].values());
}

/// @notice Returns the list of all accounts.
function getAllAccounts() external view returns (AccountInfo[] memory accounts) {
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
return _formatAccounts(data.allAccounts.values());
}

/*///////////////////////////////////////////////////////////////
Internal functions
//////////////////////////////////////////////////////////////*/

/// @dev Formats a list of accountIds to a list of `AccountInfo` (account id + account address).
function _formatAccounts(string[] memory _accountIds) internal view returns (AccountInfo[] memory accounts) {
uint256 len = _accountIds.length;
accounts = new AccountInfo[](len);
for (uint256 i = 0; i < len; i += 1) {
string memory accountId = _accountIds[i];
address account = getAddress(accountId);
accounts[i] = AccountInfo(accountId, account);
}
}

/// @dev Adds an account to the list of accounts created by a signer.
function _setupAccount(address _signer, string memory _accountId) internal {
TWAccountFactoryStorage.Data storage data = TWAccountFactoryStorage.factoryStorage();
data.allAccounts.add(_accountId);
data.accountsOfSigner[_signer].add(_accountId);
}
}
57 changes: 0 additions & 57 deletions contracts/smart-wallet/TWDynamicAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@ import "./TWDynamicAccount.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

/*///////////////////////////////////////////////////////////////
Storage layout
//////////////////////////////////////////////////////////////*/

library TWDynamicAccountFactoryStorage {
bytes32 internal constant DYNAMIC_ACCOUNT_FACTORY_STORAGE_POSITION =
keccak256("tw.dynamic.account.factory.storage");

struct Data {
TWStringSet.Set allAccounts;
mapping(address => TWStringSet.Set) accountsOfSigner;
}

function factoryStorage() internal pure returns (Data storage dynamicAccountFactoryData) {
bytes32 position = DYNAMIC_ACCOUNT_FACTORY_STORAGE_POSITION;
assembly {
dynamicAccountFactoryData.slot := position
}
}
}

contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {
using TWStringSet for TWStringSet.Set;

Expand Down Expand Up @@ -77,8 +56,6 @@ contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {

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

_setupAccount(_admin, _accountId);

emit AccountCreated(account, _admin, _accountId);

return account;
Expand All @@ -98,38 +75,4 @@ contract TWDynamicAccountFactory is ITWAccountFactory, Multicall {
bytes32 salt = keccak256(abi.encode(_accountId));
return Clones.predictDeterministicAddress(address(_accountImplementation), salt);
}

/// @notice Returns the list of accounts created by a signer.
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory) {
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
return _formatAccounts(data.accountsOfSigner[_signer].values());
}

/// @notice Returns the list of all accounts.
function getAllAccounts() external view returns (AccountInfo[] memory accounts) {
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
return _formatAccounts(data.allAccounts.values());
}

/*///////////////////////////////////////////////////////////////
Internal functions
//////////////////////////////////////////////////////////////*/

/// @dev Formats a list of accountIds to a list of `AccountInfo` (account id + account address).
function _formatAccounts(string[] memory _accountIds) internal view returns (AccountInfo[] memory accounts) {
uint256 len = _accountIds.length;
accounts = new AccountInfo[](len);
for (uint256 i = 0; i < len; i += 1) {
string memory accountId = _accountIds[i];
address account = getAddress(accountId);
accounts[i] = AccountInfo(accountId, account);
}
}

/// @dev Adds an account to the list of accounts created by a signer.
function _setupAccount(address _signer, string memory _accountId) internal {
TWDynamicAccountFactoryStorage.Data storage data = TWDynamicAccountFactoryStorage.factoryStorage();
data.allAccounts.add(_accountId);
data.accountsOfSigner[_signer].add(_accountId);
}
}
16 changes: 0 additions & 16 deletions contracts/smart-wallet/interfaces/ITWAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
pragma solidity ^0.8.12;

interface ITWAccountFactory {
/*///////////////////////////////////////////////////////////////
Structs
//////////////////////////////////////////////////////////////*/

/// @notice Smart account details: address and ID (used as salt).
struct AccountInfo {
string id;
address account;
}

/*///////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////*/
Expand All @@ -35,10 +25,4 @@ interface ITWAccountFactory {

/// @notice Returns the address of an Account that would be deployed with the given accountId as salt.
function getAddress(string memory accountId) external view returns (address);

/// @notice Returns the list of accounts created by a signer.
function getAccountsOfSigner(address _signer) external view returns (AccountInfo[] memory);

/// @notice Returns the list of all accounts.
function getAllAccounts() external view returns (AccountInfo[] memory);
}