thirdweb 5.48.2 → 5.48.3-nightly-b661ce7b2fd58e7ff01faf47cf8fb3bb232841ec-20240827000337
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 +4 -2
- package/dist/cjs/exports/wallets/smart.js.map +1 -1
- package/dist/cjs/extensions/erc1155/drops/write/claimTo.js.map +1 -1
- package/dist/cjs/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.js +32 -0
- package/dist/cjs/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.js.map +1 -0
- package/dist/cjs/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.js +153 -0
- package/dist/cjs/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.js.map +1 -0
- package/dist/cjs/extensions/prebuilts/__generated__/VoteERC20/write/initialize.js +184 -0
- package/dist/cjs/extensions/prebuilts/__generated__/VoteERC20/write/initialize.js.map +1 -0
- package/dist/cjs/extensions/prebuilts/deploy-vote.js +122 -0
- package/dist/cjs/extensions/prebuilts/deploy-vote.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +13 -2
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/bundler.js +11 -2
- package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/constants.js +27 -13
- package/dist/cjs/wallets/smart/lib/constants.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/packUserOp.js +75 -0
- package/dist/cjs/wallets/smart/lib/packUserOp.js.map +1 -0
- package/dist/cjs/wallets/smart/lib/paymaster.js +11 -1
- package/dist/cjs/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/userop.js +201 -66
- package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/utils.js +1 -1
- package/dist/cjs/wallets/smart/lib/utils.js.map +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js +2 -1
- package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/cjs/wallets/smart/types.js.map +1 -1
- package/dist/esm/exports/wallets/smart.js +1 -1
- package/dist/esm/exports/wallets/smart.js.map +1 -1
- package/dist/esm/extensions/erc1155/drops/write/claimTo.js.map +1 -1
- package/dist/esm/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.js +29 -0
- package/dist/esm/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.js.map +1 -0
- package/dist/esm/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.js +145 -0
- package/dist/esm/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.js.map +1 -0
- package/dist/esm/extensions/prebuilts/__generated__/VoteERC20/write/initialize.js +177 -0
- package/dist/esm/extensions/prebuilts/__generated__/VoteERC20/write/initialize.js.map +1 -0
- package/dist/esm/extensions/prebuilts/deploy-vote.js +119 -0
- package/dist/esm/extensions/prebuilts/deploy-vote.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +14 -3
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/bundler.js +12 -3
- package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/esm/wallets/smart/lib/constants.js +23 -10
- package/dist/esm/wallets/smart/lib/constants.js.map +1 -1
- package/dist/esm/wallets/smart/lib/packUserOp.js +65 -0
- package/dist/esm/wallets/smart/lib/packUserOp.js.map +1 -0
- package/dist/esm/wallets/smart/lib/paymaster.js +12 -2
- package/dist/esm/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/esm/wallets/smart/lib/userop.js +202 -67
- package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
- package/dist/esm/wallets/smart/lib/utils.js +1 -1
- package/dist/esm/wallets/smart/lib/utils.js.map +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js +3 -2
- package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/esm/wallets/smart/types.js.map +1 -1
- package/dist/types/exports/wallets/smart.d.ts +2 -2
- package/dist/types/exports/wallets/smart.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts +2 -3
- package/dist/types/extensions/erc1155/drops/write/claimTo.d.ts.map +1 -1
- package/dist/types/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.d.ts +57 -0
- package/dist/types/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.d.ts.map +1 -0
- package/dist/types/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.d.ts +123 -0
- package/dist/types/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.d.ts.map +1 -0
- package/dist/types/extensions/prebuilts/__generated__/VoteERC20/write/initialize.d.ts +129 -0
- package/dist/types/extensions/prebuilts/__generated__/VoteERC20/write/initialize.d.ts.map +1 -0
- package/dist/types/extensions/prebuilts/deploy-vote.d.ts +82 -0
- package/dist/types/extensions/prebuilts/deploy-vote.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/bundler.d.ts +3 -3
- package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/constants.d.ts +6 -6
- package/dist/types/wallets/smart/lib/constants.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/packUserOp.d.ts +16 -0
- package/dist/types/wallets/smart/lib/packUserOp.d.ts.map +1 -0
- package/dist/types/wallets/smart/lib/paymaster.d.ts +3 -3
- package/dist/types/wallets/smart/lib/paymaster.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/userop.d.ts +6 -4
- package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/utils.d.ts +2 -2
- package/dist/types/wallets/smart/lib/utils.d.ts.map +1 -1
- package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -1
- package/dist/types/wallets/smart/types.d.ts +62 -9
- package/dist/types/wallets/smart/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/wallets/smart.ts +4 -2
- package/src/extensions/erc1155/drops/write/claimTo.ts +2 -3
- package/src/extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.ts +49 -0
- package/src/extensions/erc4337/__generated__/IEntryPoint_v07/read/getUserOpHash.ts +181 -0
- package/src/extensions/prebuilts/__generated__/VoteERC20/write/initialize.ts +230 -0
- package/src/extensions/prebuilts/deploy-vote.test.ts +73 -0
- package/src/extensions/prebuilts/deploy-vote.ts +213 -0
- package/src/extensions/vote/read/proposalExists.test.ts +123 -0
- package/src/version.ts +1 -1
- package/src/wallets/smart/index.ts +21 -5
- package/src/wallets/smart/lib/bundler.ts +21 -5
- package/src/wallets/smart/lib/constants.ts +29 -10
- package/src/wallets/smart/lib/packUserOp.ts +79 -0
- package/src/wallets/smart/lib/paymaster.ts +22 -5
- package/src/wallets/smart/lib/userop.ts +292 -85
- package/src/wallets/smart/lib/utils.ts +11 -4
- package/src/wallets/smart/smart-wallet-integration-v07.test.ts +206 -0
- package/src/wallets/smart/smart-wallet-integration.test.ts +1 -1
- package/src/wallets/smart/smart-wallet-zksync.test.ts +1 -2
- package/src/wallets/smart/smart-wallet.ts +4 -2
- package/src/wallets/smart/types.ts +73 -9
@@ -42,7 +42,7 @@ import {
|
|
42
42
|
prepareBatchExecute,
|
43
43
|
prepareExecute,
|
44
44
|
} from "./lib/calls.js";
|
45
|
-
import {
|
45
|
+
import { getDefaultAccountFactory } from "./lib/constants.js";
|
46
46
|
import {
|
47
47
|
createUnsignedUserOp,
|
48
48
|
signUserOp,
|
@@ -50,11 +50,13 @@ import {
|
|
50
50
|
} from "./lib/userop.js";
|
51
51
|
import { isNativeAAChain } from "./lib/utils.js";
|
52
52
|
import type {
|
53
|
+
BundlerOptions,
|
53
54
|
PaymasterResult,
|
54
55
|
SmartAccountOptions,
|
55
56
|
SmartWalletConnectionOptions,
|
56
57
|
SmartWalletOptions,
|
57
|
-
|
58
|
+
UserOperationV06,
|
59
|
+
UserOperationV07,
|
58
60
|
} from "./types.js";
|
59
61
|
|
60
62
|
/**
|
@@ -95,7 +97,9 @@ export async function connectSmartWallet(
|
|
95
97
|
}
|
96
98
|
|
97
99
|
const options = creationOptions;
|
98
|
-
const factoryAddress =
|
100
|
+
const factoryAddress =
|
101
|
+
options.factoryAddress ??
|
102
|
+
getDefaultAccountFactory(creationOptions.overrides?.entrypointAddress);
|
99
103
|
const chain = connectChain ?? options.chain;
|
100
104
|
const sponsorGas =
|
101
105
|
"gasless" in options ? options.gasless : options.sponsorGas;
|
@@ -182,7 +186,9 @@ async function createSmartAccount(
|
|
182
186
|
const erc20Paymaster = options.overrides?.erc20Paymaster;
|
183
187
|
let paymasterOverride:
|
184
188
|
| undefined
|
185
|
-
| ((
|
189
|
+
| ((
|
190
|
+
userOp: UserOperationV06 | UserOperationV07,
|
191
|
+
) => Promise<PaymasterResult>) = undefined;
|
186
192
|
if (erc20Paymaster) {
|
187
193
|
await approveERC20({
|
188
194
|
accountContract,
|
@@ -195,6 +201,9 @@ async function createSmartAccount(
|
|
195
201
|
erc20Paymaster.address as Hex,
|
196
202
|
erc20Paymaster?.token as Hex,
|
197
203
|
]),
|
204
|
+
// for 0.7 compatibility
|
205
|
+
paymaster: erc20Paymaster.address as Hex,
|
206
|
+
paymasterData: "0x",
|
198
207
|
};
|
199
208
|
};
|
200
209
|
paymasterOverride = options.overrides?.paymaster || paymasterCallback;
|
@@ -567,13 +576,20 @@ async function _sendUserOp(args: {
|
|
567
576
|
overrides: options.overrides,
|
568
577
|
});
|
569
578
|
const signedUserOp = await signUserOp({
|
579
|
+
client: options.client,
|
570
580
|
chain: options.chain,
|
571
581
|
adminAccount: options.personalAccount,
|
572
582
|
entrypointAddress: options.overrides?.entrypointAddress,
|
573
583
|
userOp: unsignedUserOp,
|
574
584
|
});
|
585
|
+
const bundlerOptions: BundlerOptions = {
|
586
|
+
chain: options.chain,
|
587
|
+
client: options.client,
|
588
|
+
bundlerUrl: options.overrides?.bundlerUrl,
|
589
|
+
entrypointAddress: options.overrides?.entrypointAddress,
|
590
|
+
};
|
575
591
|
const userOpHash = await bundleUserOp({
|
576
|
-
options,
|
592
|
+
options: bundlerOptions,
|
577
593
|
userOp: signedUserOp,
|
578
594
|
});
|
579
595
|
// wait for tx receipt rather than return the userOp hash
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { type TransactionSerializable, decodeErrorResult } from "viem";
|
2
2
|
import { parseEventLogs } from "../../../event/actions/parse-logs.js";
|
3
3
|
import { userOperationRevertReasonEvent } from "../../../extensions/erc4337/__generated__/IEntryPoint/events/UserOperationRevertReason.js";
|
4
|
+
import { postOpRevertReasonEvent } from "../../../extensions/erc4337/__generated__/IEntryPoint_v07/events/PostOpRevertReason.js";
|
4
5
|
import type { TransactionReceipt } from "../../../transaction/types.js";
|
5
6
|
import { type Hex, hexToBigInt } from "../../../utils/encoding/hex.js";
|
6
7
|
import { getClientFetch } from "../../../utils/fetch.js";
|
@@ -10,8 +11,9 @@ import {
|
|
10
11
|
type EstimationResult,
|
11
12
|
type GasPriceResult,
|
12
13
|
type PmTransactionData,
|
13
|
-
type UserOperation,
|
14
14
|
type UserOperationReceipt,
|
15
|
+
type UserOperationV06,
|
16
|
+
type UserOperationV07,
|
15
17
|
formatUserOperationReceipt,
|
16
18
|
} from "../types.js";
|
17
19
|
import {
|
@@ -19,6 +21,7 @@ import {
|
|
19
21
|
ENTRYPOINT_ADDRESS_v0_6,
|
20
22
|
MANAGED_ACCOUNT_GAS_BUFFER,
|
21
23
|
getDefaultBundlerUrl,
|
24
|
+
getEntryPointVersion,
|
22
25
|
} from "./constants.js";
|
23
26
|
import { hexlifyUserOp } from "./utils.js";
|
24
27
|
|
@@ -38,7 +41,7 @@ import { hexlifyUserOp } from "./utils.js";
|
|
38
41
|
* @walletUtils
|
39
42
|
*/
|
40
43
|
export async function bundleUserOp(args: {
|
41
|
-
userOp:
|
44
|
+
userOp: UserOperationV06 | UserOperationV07;
|
42
45
|
options: BundlerOptions;
|
43
46
|
}): Promise<Hex> {
|
44
47
|
return sendBundlerRequest({
|
@@ -67,7 +70,7 @@ export async function bundleUserOp(args: {
|
|
67
70
|
* @walletUtils
|
68
71
|
*/
|
69
72
|
export async function estimateUserOpGas(args: {
|
70
|
-
userOp:
|
73
|
+
userOp: UserOperationV06 | UserOperationV07;
|
71
74
|
options: BundlerOptions;
|
72
75
|
}): Promise<EstimationResult> {
|
73
76
|
const res = await sendBundlerRequest({
|
@@ -85,6 +88,14 @@ export async function estimateUserOpGas(args: {
|
|
85
88
|
verificationGas: hexToBigInt(res.verificationGas),
|
86
89
|
verificationGasLimit: hexToBigInt(res.verificationGasLimit),
|
87
90
|
callGasLimit: hexToBigInt(res.callGasLimit) + MANAGED_ACCOUNT_GAS_BUFFER,
|
91
|
+
paymasterVerificationGasLimit:
|
92
|
+
res.paymasterVerificationGasLimit !== undefined
|
93
|
+
? hexToBigInt(res.paymasterVerificationGasLimit)
|
94
|
+
: undefined,
|
95
|
+
paymasterPostOpGasLimit:
|
96
|
+
res.paymasterPostOpGasLimit !== undefined
|
97
|
+
? hexToBigInt(res.paymasterPostOpGasLimit)
|
98
|
+
: undefined,
|
88
99
|
};
|
89
100
|
}
|
90
101
|
|
@@ -147,7 +158,7 @@ export async function getUserOpReceipt(
|
|
147
158
|
if (res.success === false) {
|
148
159
|
// parse revert reason
|
149
160
|
const logs = parseEventLogs({
|
150
|
-
events: [userOperationRevertReasonEvent()],
|
161
|
+
events: [userOperationRevertReasonEvent(), postOpRevertReasonEvent()],
|
151
162
|
logs: res.logs,
|
152
163
|
});
|
153
164
|
const revertReason = logs[0]?.args?.revertReason;
|
@@ -258,7 +269,12 @@ async function sendBundlerRequest(args: {
|
|
258
269
|
console.debug(`>>> sending ${operation} with payload:`, params);
|
259
270
|
}
|
260
271
|
|
261
|
-
const
|
272
|
+
const entryPointVersion = getEntryPointVersion(
|
273
|
+
options.entrypointAddress || ENTRYPOINT_ADDRESS_v0_6,
|
274
|
+
);
|
275
|
+
const bundlerVersion = entryPointVersion === "v0.6" ? "v1" : "v2";
|
276
|
+
const bundlerUrl =
|
277
|
+
options.bundlerUrl ?? getDefaultBundlerUrl(options.chain, bundlerVersion);
|
262
278
|
const fetchWithHeaders = getClientFetch(options.client);
|
263
279
|
const response = await fetchWithHeaders(bundlerUrl, {
|
264
280
|
method: "POST",
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Chain } from "../../../chains/types.js";
|
2
|
+
import { getAddress } from "../../../utils/address.js";
|
2
3
|
import { getThirdwebDomains } from "../../../utils/domains.js";
|
3
4
|
|
4
5
|
// dev only
|
@@ -7,31 +8,49 @@ export const DEBUG = false;
|
|
7
8
|
export const DUMMY_SIGNATURE =
|
8
9
|
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
9
10
|
|
10
|
-
export const
|
11
|
+
export const DEFAULT_ACCOUNT_FACTORY_V0_6 =
|
11
12
|
"0x85e23b94e7F5E9cC1fF78BCe78cfb15B81f0DF00";
|
13
|
+
export const DEFAULT_ACCOUNT_FACTORY_V0_7 =
|
14
|
+
"0x4be0ddfebca9a5a4a617dee4dece99e7c862dceb";
|
12
15
|
|
13
16
|
export const ENTRYPOINT_ADDRESS_v0_6 =
|
14
17
|
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"; // v0.6
|
18
|
+
export const ENTRYPOINT_ADDRESS_v0_7 =
|
19
|
+
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"; // v0.7
|
20
|
+
|
15
21
|
export const MANAGED_ACCOUNT_GAS_BUFFER = 50000n;
|
16
22
|
|
17
|
-
|
23
|
+
/*
|
18
24
|
* @internal
|
19
25
|
*/
|
20
|
-
export const
|
21
|
-
const
|
22
|
-
|
23
|
-
|
26
|
+
export const getDefaultAccountFactory = (entryPointAddress?: string) => {
|
27
|
+
const version = getEntryPointVersion(
|
28
|
+
entryPointAddress || ENTRYPOINT_ADDRESS_v0_6,
|
29
|
+
);
|
30
|
+
if (version === "v0.7") {
|
31
|
+
return DEFAULT_ACCOUNT_FACTORY_V0_7;
|
24
32
|
}
|
25
|
-
return
|
33
|
+
return DEFAULT_ACCOUNT_FACTORY_V0_6;
|
26
34
|
};
|
27
35
|
|
28
36
|
/**
|
29
37
|
* @internal
|
30
38
|
*/
|
31
|
-
export const
|
39
|
+
export const getDefaultBundlerUrl = (chain: Chain, version: "v1" | "v2") => {
|
32
40
|
const domain = getThirdwebDomains().bundler;
|
33
41
|
if (domain.startsWith("localhost:")) {
|
34
|
-
return `http://${domain}?chain=${chain.id}`;
|
42
|
+
return `http://${domain}/${version ?? "v1"}?chain=${chain.id}`;
|
43
|
+
}
|
44
|
+
return `https://${chain.id}.${domain}/${version ?? "v1"}`;
|
45
|
+
};
|
46
|
+
|
47
|
+
export const getEntryPointVersion = (address: string): "v0.6" | "v0.7" => {
|
48
|
+
const checksummedAddress = getAddress(address);
|
49
|
+
if (checksummedAddress === ENTRYPOINT_ADDRESS_v0_6) {
|
50
|
+
return "v0.6";
|
51
|
+
}
|
52
|
+
if (checksummedAddress === ENTRYPOINT_ADDRESS_v0_7) {
|
53
|
+
return "v0.7";
|
35
54
|
}
|
36
|
-
|
55
|
+
throw new Error("Unknown paymaster version");
|
37
56
|
};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { type Hex, concat, pad, slice, toHex } from "viem";
|
2
|
+
import type { PackedUserOperation, UserOperationV07 } from "../types.js";
|
3
|
+
|
4
|
+
export function getInitCode(unpackedUserOperation: UserOperationV07) {
|
5
|
+
return unpackedUserOperation.factory
|
6
|
+
? concat([
|
7
|
+
unpackedUserOperation.factory as Hex,
|
8
|
+
unpackedUserOperation.factoryData || ("0x" as Hex),
|
9
|
+
])
|
10
|
+
: "0x";
|
11
|
+
}
|
12
|
+
|
13
|
+
export function getAccountGasLimits(unpackedUserOperation: UserOperationV07) {
|
14
|
+
return concat([
|
15
|
+
pad(toHex(unpackedUserOperation.verificationGasLimit), {
|
16
|
+
size: 16,
|
17
|
+
}),
|
18
|
+
pad(toHex(unpackedUserOperation.callGasLimit), { size: 16 }),
|
19
|
+
]) as Hex;
|
20
|
+
}
|
21
|
+
|
22
|
+
export function unpackAccountGasLimits(accountGasLimits: Hex) {
|
23
|
+
return {
|
24
|
+
verificationGasLimit: BigInt(slice(accountGasLimits, 0, 16)),
|
25
|
+
callGasLimit: BigInt(slice(accountGasLimits, 16)),
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
export function getGasLimits(unpackedUserOperation: UserOperationV07) {
|
30
|
+
return concat([
|
31
|
+
pad(toHex(unpackedUserOperation.maxPriorityFeePerGas), {
|
32
|
+
size: 16,
|
33
|
+
}),
|
34
|
+
pad(toHex(unpackedUserOperation.maxFeePerGas), { size: 16 }),
|
35
|
+
]) as Hex;
|
36
|
+
}
|
37
|
+
|
38
|
+
export function unpackGasLimits(gasLimits: Hex) {
|
39
|
+
return {
|
40
|
+
maxPriorityFeePerGas: BigInt(slice(gasLimits, 0, 16)),
|
41
|
+
maxFeePerGas: BigInt(slice(gasLimits, 16)),
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
export function getPaymasterAndData(unpackedUserOperation: UserOperationV07) {
|
46
|
+
return unpackedUserOperation.paymaster
|
47
|
+
? concat([
|
48
|
+
unpackedUserOperation.paymaster as Hex,
|
49
|
+
pad(
|
50
|
+
toHex(
|
51
|
+
unpackedUserOperation.paymasterVerificationGasLimit || BigInt(0),
|
52
|
+
),
|
53
|
+
{
|
54
|
+
size: 16,
|
55
|
+
},
|
56
|
+
),
|
57
|
+
pad(toHex(unpackedUserOperation.paymasterPostOpGasLimit || BigInt(0)), {
|
58
|
+
size: 16,
|
59
|
+
}),
|
60
|
+
unpackedUserOperation.paymasterData || ("0x" as Hex),
|
61
|
+
])
|
62
|
+
: "0x";
|
63
|
+
}
|
64
|
+
|
65
|
+
export const getPackedUserOperation = (
|
66
|
+
userOperation: UserOperationV07,
|
67
|
+
): PackedUserOperation => {
|
68
|
+
return {
|
69
|
+
sender: userOperation.sender,
|
70
|
+
nonce: userOperation.nonce,
|
71
|
+
initCode: getInitCode(userOperation),
|
72
|
+
callData: userOperation.callData,
|
73
|
+
accountGasLimits: getAccountGasLimits(userOperation),
|
74
|
+
preVerificationGas: userOperation.preVerificationGas,
|
75
|
+
gasFees: getGasLimits(userOperation),
|
76
|
+
paymasterAndData: getPaymasterAndData(userOperation),
|
77
|
+
signature: userOperation.signature,
|
78
|
+
};
|
79
|
+
};
|
@@ -2,11 +2,16 @@ import type { Chain } from "../../../chains/types.js";
|
|
2
2
|
import type { ThirdwebClient } from "../../../client/client.js";
|
3
3
|
import { hexToBigInt } from "../../../utils/encoding/hex.js";
|
4
4
|
import { getClientFetch } from "../../../utils/fetch.js";
|
5
|
-
import type {
|
5
|
+
import type {
|
6
|
+
PaymasterResult,
|
7
|
+
UserOperationV06,
|
8
|
+
UserOperationV07,
|
9
|
+
} from "../types.js";
|
6
10
|
import {
|
7
11
|
DEBUG,
|
8
12
|
ENTRYPOINT_ADDRESS_v0_6,
|
9
|
-
|
13
|
+
getDefaultBundlerUrl,
|
14
|
+
getEntryPointVersion,
|
10
15
|
} from "./constants.js";
|
11
16
|
import { hexlifyUserOp } from "./utils.js";
|
12
17
|
|
@@ -29,11 +34,13 @@ import { hexlifyUserOp } from "./utils.js";
|
|
29
34
|
* @walletUtils
|
30
35
|
*/
|
31
36
|
export async function getPaymasterAndData(args: {
|
32
|
-
userOp:
|
37
|
+
userOp: UserOperationV06 | UserOperationV07;
|
33
38
|
client: ThirdwebClient;
|
34
39
|
chain: Chain;
|
35
40
|
entrypointAddress?: string;
|
36
|
-
paymasterOverride?: (
|
41
|
+
paymasterOverride?: (
|
42
|
+
userOp: UserOperationV06 | UserOperationV07,
|
43
|
+
) => Promise<PaymasterResult>;
|
37
44
|
}): Promise<PaymasterResult> {
|
38
45
|
const { userOp, paymasterOverride, client, chain, entrypointAddress } = args;
|
39
46
|
|
@@ -45,8 +52,10 @@ export async function getPaymasterAndData(args: {
|
|
45
52
|
"Content-Type": "application/json",
|
46
53
|
};
|
47
54
|
|
48
|
-
const paymasterUrl = getDefaultPaymasterUrl(chain);
|
49
55
|
const entrypoint = entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6;
|
56
|
+
const entrypointVersion = getEntryPointVersion(entrypoint);
|
57
|
+
const paymasterVersion = entrypointVersion === "v0.6" ? "v1" : "v2";
|
58
|
+
const paymasterUrl = getDefaultBundlerUrl(chain, paymasterVersion);
|
50
59
|
|
51
60
|
// Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
|
52
61
|
const fetchWithHeaders = getClientFetch(client);
|
@@ -95,6 +104,14 @@ Code: ${code}`,
|
|
95
104
|
callGasLimit: res.result.callGasLimit
|
96
105
|
? hexToBigInt(res.result.callGasLimit)
|
97
106
|
: undefined,
|
107
|
+
paymaster: res.result.paymaster,
|
108
|
+
paymasterData: res.result.paymasterData,
|
109
|
+
paymasterVerificationGasLimit: res.result.paymasterVerificationGasLimit
|
110
|
+
? hexToBigInt(res.result.paymasterVerificationGasLimit)
|
111
|
+
: undefined,
|
112
|
+
paymasterPostOpGasLimit: res.result.paymasterPostOpGasLimit
|
113
|
+
? hexToBigInt(res.result.paymasterPostOpGasLimit)
|
114
|
+
: undefined,
|
98
115
|
};
|
99
116
|
}
|
100
117
|
const error =
|