thirdweb 5.34.0-nightly-325416ea19905901f30e795cbf93cb8a085be02f-20240708203622 → 5.34.0-nightly-3f0291def5ac8b5006a75e8c1212d4f287647d05-20240709000342
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/wallets/smart.js +10 -1
- package/dist/cjs/exports/wallets/smart.js.map +1 -1
- package/dist/cjs/react/core/hooks/others/useChainQuery.js +44 -0
- package/dist/cjs/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/NetworkSelector.js +20 -4
- package/dist/cjs/react/web/ui/ConnectWallet/NetworkSelector.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/smart/index.js +19 -9
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/bundler.js +57 -9
- package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/calls.js +31 -21
- package/dist/cjs/wallets/smart/lib/calls.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/paymaster.js +5 -6
- package/dist/cjs/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/userop.js +45 -21
- package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
- package/dist/esm/exports/wallets/smart.js +3 -1
- package/dist/esm/exports/wallets/smart.js.map +1 -1
- package/dist/esm/react/core/hooks/others/useChainQuery.js +43 -1
- package/dist/esm/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/NetworkSelector.js +21 -5
- package/dist/esm/react/web/ui/ConnectWallet/NetworkSelector.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/smart/index.js +19 -9
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/bundler.js +56 -8
- package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/esm/wallets/smart/lib/calls.js +31 -21
- package/dist/esm/wallets/smart/lib/calls.js.map +1 -1
- package/dist/esm/wallets/smart/lib/paymaster.js +5 -6
- package/dist/esm/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/esm/wallets/smart/lib/userop.js +46 -22
- package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
- package/dist/types/exports/wallets/smart.d.ts +3 -1
- package/dist/types/exports/wallets/smart.d.ts.map +1 -1
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts +10 -0
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/NetworkSelector.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/bundler.d.ts +53 -5
- package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/calls.d.ts +25 -7
- package/dist/types/wallets/smart/lib/calls.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/paymaster.d.ts +7 -2
- package/dist/types/wallets/smart/lib/paymaster.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/userop.d.ts +15 -4
- package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
- package/dist/types/wallets/smart/types.d.ts +4 -2
- package/dist/types/wallets/smart/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/wallets/smart.ts +14 -1
- package/src/react/core/hooks/others/useChainQuery.ts +47 -1
- package/src/react/web/ui/ConnectWallet/NetworkSelector.tsx +27 -4
- package/src/version.ts +1 -1
- package/src/wallets/smart/index.ts +19 -9
- package/src/wallets/smart/lib/bundler.ts +56 -9
- package/src/wallets/smart/lib/calls.ts +67 -28
- package/src/wallets/smart/lib/paymaster.ts +12 -13
- package/src/wallets/smart/lib/userop.ts +74 -30
- package/src/wallets/smart/types.ts +6 -6
@@ -4,28 +4,51 @@ import type { PreparedTransaction } from "../../../transaction/prepare-transacti
|
|
4
4
|
import { readContract } from "../../../transaction/read-contract.js";
|
5
5
|
import { stringToHex } from "../../../utils/encoding/hex.js";
|
6
6
|
import type { SendTransactionOption } from "../../interfaces/wallet.js";
|
7
|
-
import type { SmartAccountOptions, SmartWalletOptions } from "../types.ts";
|
8
7
|
|
9
8
|
/**
|
10
|
-
*
|
9
|
+
* Predict the address of a smart account.
|
10
|
+
* @param args - The options for predicting the address of a smart account.
|
11
|
+
* @returns The predicted address of the smart account.
|
12
|
+
* @example
|
13
|
+
* ```ts
|
14
|
+
* import { predictAddress } from "thirdweb/wallets/smart";
|
15
|
+
*
|
16
|
+
* const predictedAddress = await predictAddress({
|
17
|
+
* factoryContract,
|
18
|
+
* adminAddress,
|
19
|
+
* accountSalt,
|
20
|
+
* });
|
21
|
+
* ```
|
22
|
+
* @walletUtils
|
11
23
|
*/
|
12
|
-
export async function predictAddress(
|
13
|
-
factoryContract: ThirdwebContract
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
24
|
+
export async function predictAddress(args: {
|
25
|
+
factoryContract: ThirdwebContract;
|
26
|
+
predictAddressOverride?: (
|
27
|
+
factoryContract: ThirdwebContract,
|
28
|
+
) => Promise<string>;
|
29
|
+
adminAddress: string;
|
30
|
+
accountSalt?: string;
|
31
|
+
accountAddress?: string;
|
32
|
+
}): Promise<string> {
|
33
|
+
const {
|
34
|
+
factoryContract,
|
35
|
+
predictAddressOverride: predictAddress,
|
36
|
+
adminAddress,
|
37
|
+
accountSalt,
|
38
|
+
accountAddress,
|
39
|
+
} = args;
|
40
|
+
if (predictAddress) {
|
41
|
+
return predictAddress(factoryContract);
|
18
42
|
}
|
19
|
-
if (
|
20
|
-
return
|
43
|
+
if (accountAddress) {
|
44
|
+
return accountAddress;
|
21
45
|
}
|
22
|
-
const adminAddress = options.personalAccountAddress;
|
23
46
|
if (!adminAddress) {
|
24
47
|
throw new Error(
|
25
48
|
"Account address is required to predict the smart wallet address.",
|
26
49
|
);
|
27
50
|
}
|
28
|
-
const extraData = stringToHex(
|
51
|
+
const extraData = stringToHex(accountSalt ?? "");
|
29
52
|
return readContract({
|
30
53
|
contract: factoryContract,
|
31
54
|
method: "function getAddress(address, bytes) returns (address)",
|
@@ -38,19 +61,25 @@ export async function predictAddress(
|
|
38
61
|
*/
|
39
62
|
export function prepareCreateAccount(args: {
|
40
63
|
factoryContract: ThirdwebContract;
|
41
|
-
|
64
|
+
adminAddress: string;
|
65
|
+
accountSalt?: string;
|
66
|
+
createAccountOverride?: (
|
67
|
+
factoryContract: ThirdwebContract,
|
68
|
+
) => PreparedTransaction;
|
42
69
|
}): PreparedTransaction {
|
43
|
-
const {
|
44
|
-
|
45
|
-
|
70
|
+
const {
|
71
|
+
adminAddress,
|
72
|
+
factoryContract,
|
73
|
+
createAccountOverride: createAccount,
|
74
|
+
accountSalt,
|
75
|
+
} = args;
|
76
|
+
if (createAccount) {
|
77
|
+
return createAccount(factoryContract);
|
46
78
|
}
|
47
79
|
return prepareContractCall({
|
48
80
|
contract: factoryContract,
|
49
81
|
method: "function createAccount(address, bytes) returns (address)",
|
50
|
-
params: [
|
51
|
-
options.personalAccount.address,
|
52
|
-
stringToHex(options.overrides?.accountSalt ?? ""),
|
53
|
-
],
|
82
|
+
params: [adminAddress, stringToHex(accountSalt ?? "")],
|
54
83
|
});
|
55
84
|
}
|
56
85
|
|
@@ -59,12 +88,15 @@ export function prepareCreateAccount(args: {
|
|
59
88
|
*/
|
60
89
|
export function prepareExecute(args: {
|
61
90
|
accountContract: ThirdwebContract;
|
62
|
-
options: SmartAccountOptions;
|
63
91
|
transaction: SendTransactionOption;
|
92
|
+
executeOverride?: (
|
93
|
+
accountContract: ThirdwebContract,
|
94
|
+
transaction: SendTransactionOption,
|
95
|
+
) => PreparedTransaction;
|
64
96
|
}): PreparedTransaction {
|
65
|
-
const { accountContract,
|
66
|
-
if (
|
67
|
-
return
|
97
|
+
const { accountContract, transaction, executeOverride: execute } = args;
|
98
|
+
if (execute) {
|
99
|
+
return execute(accountContract, transaction);
|
68
100
|
}
|
69
101
|
return prepareContractCall({
|
70
102
|
contract: accountContract,
|
@@ -82,12 +114,19 @@ export function prepareExecute(args: {
|
|
82
114
|
*/
|
83
115
|
export function prepareBatchExecute(args: {
|
84
116
|
accountContract: ThirdwebContract;
|
85
|
-
options: SmartAccountOptions;
|
86
117
|
transactions: SendTransactionOption[];
|
118
|
+
executeBatchOverride?: (
|
119
|
+
accountContract: ThirdwebContract,
|
120
|
+
transactions: SendTransactionOption[],
|
121
|
+
) => PreparedTransaction;
|
87
122
|
}): PreparedTransaction {
|
88
|
-
const {
|
89
|
-
|
90
|
-
|
123
|
+
const {
|
124
|
+
accountContract,
|
125
|
+
transactions,
|
126
|
+
executeBatchOverride: executeBatch,
|
127
|
+
} = args;
|
128
|
+
if (executeBatch) {
|
129
|
+
return executeBatch(accountContract, transactions);
|
91
130
|
}
|
92
131
|
return prepareContractCall({
|
93
132
|
contract: accountContract,
|
@@ -1,10 +1,8 @@
|
|
1
|
+
import type { Chain } from "../../../chains/types.js";
|
2
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
1
3
|
import { hexToBigInt } from "../../../utils/encoding/hex.js";
|
2
4
|
import { getClientFetch } from "../../../utils/fetch.js";
|
3
|
-
import type {
|
4
|
-
PaymasterResult,
|
5
|
-
SmartAccountOptions,
|
6
|
-
UserOperation,
|
7
|
-
} from "../types.js";
|
5
|
+
import type { PaymasterResult, UserOperation } from "../types.js";
|
8
6
|
import {
|
9
7
|
DEBUG,
|
10
8
|
ENTRYPOINT_ADDRESS_v0_6,
|
@@ -18,22 +16,23 @@ import { hexlifyUserOp } from "./utils.js";
|
|
18
16
|
*/
|
19
17
|
export async function getPaymasterAndData(args: {
|
20
18
|
userOp: UserOperation;
|
21
|
-
|
19
|
+
client: ThirdwebClient;
|
20
|
+
chain: Chain;
|
21
|
+
entrypointAddress?: string;
|
22
|
+
paymasterOverride?: (userOp: UserOperation) => Promise<PaymasterResult>;
|
22
23
|
}): Promise<PaymasterResult> {
|
23
|
-
const { userOp,
|
24
|
+
const { userOp, paymasterOverride, client, chain, entrypointAddress } = args;
|
24
25
|
|
25
|
-
if (
|
26
|
-
return
|
26
|
+
if (paymasterOverride) {
|
27
|
+
return paymasterOverride(userOp);
|
27
28
|
}
|
28
29
|
|
29
30
|
const headers: Record<string, string> = {
|
30
31
|
"Content-Type": "application/json",
|
31
32
|
};
|
32
33
|
|
33
|
-
const
|
34
|
-
const
|
35
|
-
const entrypoint =
|
36
|
-
options.overrides?.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6;
|
34
|
+
const paymasterUrl = getDefaultPaymasterUrl(chain);
|
35
|
+
const entrypoint = entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6;
|
37
36
|
|
38
37
|
// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
|
39
38
|
const fetchWithHeaders = getClientFetch(client);
|
@@ -1,4 +1,6 @@
|
|
1
1
|
import { concat } from "viem";
|
2
|
+
import type { Chain } from "../../../chains/types.js";
|
3
|
+
import type { ThirdwebContract } from "../../../contract/contract.js";
|
2
4
|
import { getDefaultGasOverrides } from "../../../gas/fee-data.js";
|
3
5
|
import { encode } from "../../../transaction/actions/encode.js";
|
4
6
|
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
|
@@ -10,14 +12,15 @@ import { hexToBytes } from "../../../utils/encoding/to-bytes.js";
|
|
10
12
|
import { isThirdwebUrl } from "../../../utils/fetch.js";
|
11
13
|
import { keccak256 } from "../../../utils/hashing/keccak256.js";
|
12
14
|
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
|
15
|
+
import type { Account } from "../../interfaces/wallet.js";
|
13
16
|
import type {
|
14
17
|
BundlerOptions,
|
15
|
-
|
18
|
+
SmartWalletOptions,
|
16
19
|
UserOperation,
|
17
20
|
} from "../types.js";
|
18
21
|
import {
|
19
22
|
estimateUserOpGas,
|
20
|
-
|
23
|
+
getUserOpGasFees,
|
21
24
|
getUserOpReceipt,
|
22
25
|
} from "./bundler.js";
|
23
26
|
import { prepareCreateAccount } from "./calls.js";
|
@@ -78,27 +81,53 @@ export async function waitForUserOpReceipt(
|
|
78
81
|
*
|
79
82
|
* const userOp = await createUnsignedUserOp({
|
80
83
|
* transaction,
|
81
|
-
*
|
84
|
+
* accountContract,
|
85
|
+
* sponsorGas,
|
86
|
+
* overrides,
|
82
87
|
* });
|
83
88
|
* ```
|
84
89
|
* @walletUtils
|
85
90
|
*/
|
86
91
|
export async function createUnsignedUserOp(args: {
|
87
92
|
transaction: PreparedTransaction;
|
88
|
-
|
93
|
+
factoryContract: ThirdwebContract;
|
94
|
+
accountContract: ThirdwebContract;
|
95
|
+
adminAddress: string;
|
96
|
+
sponsorGas: boolean;
|
97
|
+
overrides?: SmartWalletOptions["overrides"];
|
89
98
|
}): Promise<UserOperation> {
|
90
|
-
const {
|
91
|
-
|
92
|
-
|
99
|
+
const {
|
100
|
+
transaction: executeTx,
|
101
|
+
accountContract,
|
102
|
+
factoryContract,
|
103
|
+
adminAddress,
|
104
|
+
overrides,
|
105
|
+
sponsorGas,
|
106
|
+
} = args;
|
107
|
+
const chain = executeTx.chain;
|
108
|
+
const client = executeTx.client;
|
109
|
+
const isDeployed = await isContractDeployed(accountContract);
|
110
|
+
const initCode = isDeployed
|
111
|
+
? "0x"
|
112
|
+
: await getAccountInitCode({
|
113
|
+
factoryContract: factoryContract,
|
114
|
+
adminAddress,
|
115
|
+
accountSalt: overrides?.accountSalt,
|
116
|
+
createAccountOverride: overrides?.createAccount,
|
117
|
+
});
|
93
118
|
const callData = await encode(executeTx);
|
119
|
+
const bundlerOptions = {
|
120
|
+
client,
|
121
|
+
chain,
|
122
|
+
entrypointAddress: overrides?.entrypointAddress,
|
123
|
+
};
|
94
124
|
|
95
125
|
let { maxFeePerGas, maxPriorityFeePerGas } = executeTx;
|
96
|
-
const bundlerUrl =
|
97
|
-
options.overrides?.bundlerUrl ?? getDefaultBundlerUrl(options.chain);
|
126
|
+
const bundlerUrl = overrides?.bundlerUrl ?? getDefaultBundlerUrl(chain);
|
98
127
|
if (isThirdwebUrl(bundlerUrl)) {
|
99
128
|
// get gas prices from bundler
|
100
|
-
const bundlerGasPrice = await
|
101
|
-
options,
|
129
|
+
const bundlerGasPrice = await getUserOpGasFees({
|
130
|
+
options: bundlerOptions,
|
102
131
|
});
|
103
132
|
maxFeePerGas = bundlerGasPrice.maxFeePerGas;
|
104
133
|
maxPriorityFeePerGas = bundlerGasPrice.maxPriorityFeePerGas;
|
@@ -116,10 +145,7 @@ export async function createUnsignedUserOp(args: {
|
|
116
145
|
maxPriorityFeePerGas = resolvedMaxPriorityFeePerGas;
|
117
146
|
} else {
|
118
147
|
// Fallback to RPC gas prices if no explicit values provided
|
119
|
-
const feeData = await getDefaultGasOverrides(
|
120
|
-
options.client,
|
121
|
-
options.chain,
|
122
|
-
);
|
148
|
+
const feeData = await getDefaultGasOverrides(client, chain);
|
123
149
|
|
124
150
|
// Still check for explicit values in case one is provided and not the other
|
125
151
|
maxPriorityFeePerGas =
|
@@ -132,7 +158,7 @@ export async function createUnsignedUserOp(args: {
|
|
132
158
|
const nonce = randomNonce(); // FIXME getNonce should be overrideable by the wallet
|
133
159
|
|
134
160
|
const partialOp: UserOperation = {
|
135
|
-
sender:
|
161
|
+
sender: accountContract.address,
|
136
162
|
nonce,
|
137
163
|
initCode,
|
138
164
|
callData,
|
@@ -145,10 +171,13 @@ export async function createUnsignedUserOp(args: {
|
|
145
171
|
signature: DUMMY_SIGNATURE,
|
146
172
|
};
|
147
173
|
|
148
|
-
if (
|
174
|
+
if (sponsorGas) {
|
149
175
|
const paymasterResult = await getPaymasterAndData({
|
150
176
|
userOp: partialOp,
|
151
|
-
|
177
|
+
chain,
|
178
|
+
client,
|
179
|
+
entrypointAddress: overrides?.entrypointAddress,
|
180
|
+
paymasterOverride: overrides?.paymaster,
|
152
181
|
});
|
153
182
|
const paymasterAndData = paymasterResult.paymasterAndData;
|
154
183
|
if (paymasterAndData && paymasterAndData !== "0x") {
|
@@ -167,7 +196,7 @@ export async function createUnsignedUserOp(args: {
|
|
167
196
|
// otherwise fallback to bundler for gas limits
|
168
197
|
const estimates = await estimateUserOpGas({
|
169
198
|
userOp: partialOp,
|
170
|
-
options,
|
199
|
+
options: bundlerOptions,
|
171
200
|
});
|
172
201
|
partialOp.callGasLimit = estimates.callGasLimit;
|
173
202
|
partialOp.verificationGasLimit = estimates.verificationGasLimit;
|
@@ -176,7 +205,10 @@ export async function createUnsignedUserOp(args: {
|
|
176
205
|
if (paymasterAndData && paymasterAndData !== "0x") {
|
177
206
|
const paymasterResult2 = await getPaymasterAndData({
|
178
207
|
userOp: partialOp,
|
179
|
-
|
208
|
+
chain,
|
209
|
+
client,
|
210
|
+
entrypointAddress: overrides?.entrypointAddress,
|
211
|
+
paymasterOverride: overrides?.paymaster,
|
180
212
|
});
|
181
213
|
if (
|
182
214
|
paymasterResult2.paymasterAndData &&
|
@@ -190,7 +222,7 @@ export async function createUnsignedUserOp(args: {
|
|
190
222
|
// not gasless, so we just need to estimate gas limits
|
191
223
|
const estimates = await estimateUserOpGas({
|
192
224
|
userOp: partialOp,
|
193
|
-
options,
|
225
|
+
options: bundlerOptions,
|
194
226
|
});
|
195
227
|
partialOp.callGasLimit = estimates.callGasLimit;
|
196
228
|
partialOp.verificationGasLimit = estimates.verificationGasLimit;
|
@@ -221,16 +253,18 @@ export async function createUnsignedUserOp(args: {
|
|
221
253
|
*/
|
222
254
|
export async function signUserOp(args: {
|
223
255
|
userOp: UserOperation;
|
224
|
-
|
256
|
+
chain: Chain;
|
257
|
+
entrypointAddress?: string;
|
258
|
+
adminAccount: Account;
|
225
259
|
}): Promise<UserOperation> {
|
226
|
-
const { userOp,
|
260
|
+
const { userOp, chain, entrypointAddress, adminAccount } = args;
|
227
261
|
const userOpHash = getUserOpHash({
|
228
262
|
userOp,
|
229
|
-
entryPoint:
|
230
|
-
chainId:
|
263
|
+
entryPoint: entrypointAddress || ENTRYPOINT_ADDRESS_v0_6,
|
264
|
+
chainId: chain.id,
|
231
265
|
});
|
232
|
-
if (
|
233
|
-
const signature = await
|
266
|
+
if (adminAccount.signMessage) {
|
267
|
+
const signature = await adminAccount.signMessage({
|
234
268
|
message: {
|
235
269
|
raw: hexToBytes(userOpHash),
|
236
270
|
},
|
@@ -243,11 +277,21 @@ export async function signUserOp(args: {
|
|
243
277
|
throw new Error("signMessage not implemented in signingAccount");
|
244
278
|
}
|
245
279
|
|
246
|
-
async function getAccountInitCode(options:
|
247
|
-
|
280
|
+
async function getAccountInitCode(options: {
|
281
|
+
factoryContract: ThirdwebContract;
|
282
|
+
adminAddress: string;
|
283
|
+
accountSalt?: string;
|
284
|
+
createAccountOverride?: (
|
285
|
+
factoryContract: ThirdwebContract,
|
286
|
+
) => PreparedTransaction;
|
287
|
+
}): Promise<Hex> {
|
288
|
+
const { factoryContract, adminAddress, accountSalt, createAccountOverride } =
|
289
|
+
options;
|
248
290
|
const deployTx = prepareCreateAccount({
|
249
291
|
factoryContract,
|
250
|
-
|
292
|
+
adminAddress,
|
293
|
+
accountSalt,
|
294
|
+
createAccountOverride,
|
251
295
|
});
|
252
296
|
return concat([factoryContract.address as Hex, await encode(deployTx)]);
|
253
297
|
}
|
@@ -55,12 +55,12 @@ export type SmartAccountOptions = Prettify<
|
|
55
55
|
}
|
56
56
|
>;
|
57
57
|
|
58
|
-
export type BundlerOptions =
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
export type BundlerOptions = {
|
59
|
+
bundlerUrl?: string;
|
60
|
+
entrypointAddress?: string;
|
61
|
+
chain: Chain;
|
62
|
+
client: ThirdwebClient;
|
63
|
+
};
|
64
64
|
|
65
65
|
export type SmartWalletConnectionOptions = {
|
66
66
|
personalAccount: Account;
|