Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 15caf06

Browse files
Smart Wallet Changes (#899)
* add Krishang's table * add tables to how it works * add signers page * add info on factory contracts & initializing accounts with an personal wallet key * add account, key & wallet terms * remove unused file
1 parent 6e1d2b0 commit 15caf06

File tree

3 files changed

+160
-2
lines changed

3 files changed

+160
-2
lines changed

docs/onboarding/1 Solidity SDK/Base Contracts/Smart Account/0 Overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ thirdweb’s smart wallets have the following features by default:
1818

1919
Choose the right smart wallet setup for your app. thirdweb offers the following three different kinds of smart wallets:
2020

21-
| | [`Account`](/solidity/base-contracts/account) setup | [`DynamicAccount`](/solidity/base-contracts/dynamic-account) setup | [`ManagedAccount`](/solidity/base-contracts/managed-account) setup |
21+
| | [`Simple`](/solidity/base-contracts/account) | [`Dynamic`](/solidity/base-contracts/dynamic-account) | [`Managed`](/solidity/base-contracts/managed-account) |
2222
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23-
| **Upgradeability** | Non-upgradeable | Account upgrades controlled locally by account admin. | Account upgrades controlled centrally by account factory admin. |
23+
| **Upgradeability** | Non-upgradeable | Account upgrades controlled locally by account admin. | Account upgrades controlled centrally by the parent account factory admin. |
2424
| **User persona** | Developer wants to issue simple smart wallets to their users. They do not anticipate that users wallets will need any feature upgrades. | Developer wants to issue smart wallets to their users. They do anticipate feature upgrades to user wallets but do not want to push upgrades to user wallets without consent. | Developer wants to issue smart wallets to their users. They do anticipate feature upgrades to user wallets, and want to push upgrades to user wallets for seamless/invisible UX for upgrades. |
2525

2626
## Simple smart wallets

docs/onboarding/23 Smart Wallet/1 How it Works.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,85 @@ To learn more about how smart wallets work, read our [smart contract deep dive](
4141

4242
![Smart Wallet Flow](/assets/smart-wallet-architecture.png)
4343

44+
## Account Factories
45+
46+
In order to issue smart wallet account contracts for users, an account factory contract must be deployed.
47+
A factory contract is a contract which clones an implementation contract which defines the functions and logic on the clone.
48+
49+
To create accounts with the factory contract, the `createAccount` function is called. This function calls `_initializeAccount`
50+
which initializes the account and sets the default admin on the account.
51+
52+
## One Account Per Personal Wallet
53+
54+
The thirdweb Account Factories are designed so that only one account can be created per personal wallet key.
55+
This means that any one personal wallet can only be a default admin on one account per factory.
56+
57+
This is because, when the account contract is cloned by the factory, the account is craeted deterministically
58+
via the `cloneDeterministic` function. This function takes a `salt` as a parameter to predict the deployment address. The `salt` is calculated using the
59+
default admin address. Since the deployment address will be the same if the default admin is the same, if an account
60+
already exists at that address, the transaction will revert.
61+
62+
```solidity
63+
/// @notice Deploys a new Account for admin.
64+
function createAccount(address _admin, bytes calldata _data) external virtual override returns (address) {
65+
address impl = accountImplementation;
66+
bytes32 salt = _generateSalt(_admin, _data);
67+
address account = Clones.predictDeterministicAddress(impl, salt);
68+
69+
if (account.code.length > 0) {
70+
return account;
71+
}
72+
73+
account = Clones.cloneDeterministic(impl, salt);
74+
75+
if (msg.sender != entrypoint) {
76+
require(allAccounts.add(account), "AccountFactory: account already registered");
77+
}
78+
79+
_initializeAccount(account, _admin, _data);
80+
81+
emit AccountCreated(account, _admin);
82+
83+
return account;
84+
}
85+
```
86+
87+
## Types of Account and Account Factory
88+
89+
| | [`Simple`](https://thirdweb.com/thirdweb.eth/AccountFactory) | [`Dynamic`](https://thirdweb.com/thirdweb.eth/DynamicAccountFactory) | [`Managed`](https://thirdweb.com/thirdweb.eth/ManagedAccountFactory) |
90+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91+
| **Upgradeability** | Non-upgradeable | Account upgrades controlled locally by account admin. | Account upgrades controlled centrally by the parent account factory admin. |
92+
| **Expected Usage** | Developer wants to issue simple smart wallets to their users. They do not anticipate that users wallets will need any feature upgrades. | Developer wants to issue smart wallets to their users. They do anticipate feature upgrades to user wallets but do not want to push upgrades to user wallets without consent. | Developer wants to issue smart wallets to their users. They do anticipate feature upgrades to user wallets, and want to push upgrades to user wallets for seamless/invisible UX for upgrades. |
93+
94+
### Account Type Feature Comparison
95+
96+
| | Simple | Dynamic | Managed |
97+
| --------------------------------------------------- | -------------------------- | ---------------------------------------- | ---------------------------------------------- |
98+
| Contracts | `AccountFactory` `Account` | `DynamicAccountFactory` `DynamicAccount` | `ManagedAccountFactory` `ManagedAccount` |
99+
| ERC-4337 Compatible ||||
100+
| Can hold native ERC-20, ERC-721 and ERC-1155 Tokens ||||
101+
| Multi-signer ||||
102+
| Execute transactions in Batches ||||
103+
| Is the Account Upgradeable ||||
104+
| Who controls upgrades (?) | n/a | Admin of the account. | Admin of the account’s parent account factory. |
105+
44106
## Terminology
45107

108+
### Personal Wallet/Key
109+
110+
This is the default admin on an account or the "key" to an account. It can be any wallet and is used to initialize the account.
111+
Any one wallet can only be the "key" to one account per factory contract.
112+
113+
This wallet is the primary way to access and interact with the account.
114+
115+
### Account
116+
117+
In the context of smart wallets, the account is the ERC-4337 compatible smart contract which holds all of the assets.
118+
119+
### Smart Wallet
120+
121+
The smart wallet is the combination of your personal wallet "key" plus the account smart contract with all of it's assets.
122+
46123
### UserOperations
47124

48125
This is the data structure for the transaction that the user wants to perform. It contains the following fields:
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
slug: /smart-wallet/permissions
3+
title: Permissions & Signers
4+
---
5+
6+
All of the account contracts [[Simple](https://thirdweb.com/thirdweb.eth/AccountFactory), [Dynamic](https://thirdweb.com/thirdweb.eth/DynamicAccountFactory) and [Managed](https://thirdweb.com/thirdweb.eth/ManagedAccountFactory)] share the same permission model. In this section, we'll describe this permission model in detail.
7+
8+
## Account Permissions
9+
10+
An account recognizes only two types of actors:
11+
12+
### [1] Admins
13+
14+
Admins have **unrestricted access** to the account; call any functions on the contract, use the contract without going through the ERC-4337 infrastructure (bundlers, EntryPoint, etc.), withdraw the account's native token balance, and so on.
15+
16+
### Assigning Admin Permissions
17+
18+
Existing admins on the account can add new admins, remove existing admins or renounce their own admin status.
19+
20+
This is done by simply calling the `setAdmin` function:
21+
22+
```solidity
23+
/// @notice Adds / removes an account as an admin.
24+
function setAdmin(address account, bool isAdmin) external;
25+
```
26+
27+
### [2] Non-admins with permissions (Signers)
28+
29+
Signers must go through ERC-4337 infrastructure (bundlers, EntryPoint, etc.) to use an account to execute transactions. Signers can use an account under certain restrictions.
30+
31+
### Assigning Signer Permissions
32+
33+
Each individual signer has their own permissions to use the account. Admins set the permissions for signers.
34+
35+
A signers on an account are managed by the account admin and signers can be restricted to:
36+
37+
- Only call specific wallets with the account.
38+
- Transfer a specific native token amount out of account.
39+
- Only use the account in a specific time window.
40+
41+
These restrictions are set in the `SignerPermissionsRequest` struct.
42+
To set the permissions for a given signer, the `setPermissionsForSigner` function is called.
43+
44+
```Solidity
45+
struct SignerPermissionRequest {
46+
address signer;
47+
address[] approvedTargets;
48+
uint256 nativeTokenLimitPerTransaction;
49+
uint128 permissionStartTimestamp;
50+
uint128 permissionEndTimestamp;
51+
uint128 reqValidityStartTimestamp;
52+
uint128 reqValidityEndTimestamp;
53+
bytes32 uid;
54+
}
55+
56+
/// @notice Sets the permissions for a given signer.
57+
function setPermissionsForSigner(SignerPermissionRequest calldata req, bytes calldata signature) external;
58+
```
59+
60+
The function uses [EIP-712](https://eips.ethereum.org/EIPS/eip-712?ref=portal.thirdweb.com) typed data signatures. That means an admin must fill and sign the `SignerPermissionRequest` payload and pass the payload and produced signature to the function.
61+
This is so that a bundler can be used to send the transaction while still being able to perform a permissions check.
62+
63+
#### Security note:
64+
65+
A signer cannot have 'catch-all' permissions where they can call any target contract, or transfer any amount of native tokens. This is an important security consideration, since it is common (unfortunately) for private keys to get lost or leaked. In this way, the account encourages usage through purposeful signer keys.
66+
67+
Even though an account may have 'recovery', having your admin keys leaked means whoever has your admin keys has unrestricted control over the smart wallet.
68+
69+
## Account Factory Permissions
70+
71+
For all three types of account factory (simple, dynamic and managed), the following role exists:
72+
73+
- `DEFAULT_ADMIN_ROLE`: Only a holder of this role is eligible to set the contract metadata of the account factory (i.e. name, description, image and any other metadata to associate with the contract).
74+
75+
**For Simple & Dynamic accounts, there is no permission control on the factory contract.**
76+
77+
For Managed Account Factories, an extra role exists:
78+
79+
- `EXTENSION_ROLE`: Only a holder of this role can perform upgrades to the children account contracts created by the managed account factory.
80+
81+
## SDK Usage

0 commit comments

Comments
 (0)