@1llet.xyz/erc4337-gasless-sdk 0.1.2 → 0.1.4

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/index.mjs DELETED
@@ -1,583 +0,0 @@
1
- // src/AccountAbstraction.ts
2
- import {
3
- createPublicClient,
4
- http,
5
- encodeFunctionData,
6
- encodeAbiParameters,
7
- keccak256
8
- } from "viem";
9
-
10
- // src/constants.ts
11
- var DEFAULT_ENTRYPOINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
12
- var DEFAULT_FACTORY = "0x9406Cc6185a346906296840746125a0E44976454";
13
- var factoryAbi = [
14
- {
15
- inputs: [
16
- { name: "owner", type: "address" },
17
- { name: "salt", type: "uint256" }
18
- ],
19
- name: "getAccountAddress",
20
- outputs: [{ name: "", type: "address" }],
21
- stateMutability: "view",
22
- type: "function"
23
- },
24
- {
25
- inputs: [
26
- { name: "owner", type: "address" },
27
- { name: "salt", type: "uint256" }
28
- ],
29
- name: "isAccountDeployed",
30
- outputs: [{ name: "", type: "bool" }],
31
- stateMutability: "view",
32
- type: "function"
33
- },
34
- {
35
- inputs: [
36
- { name: "owner", type: "address" },
37
- { name: "salt", type: "uint256" }
38
- ],
39
- name: "createAccount",
40
- outputs: [{ name: "account", type: "address" }],
41
- stateMutability: "nonpayable",
42
- type: "function"
43
- }
44
- ];
45
- var entryPointAbi = [
46
- {
47
- inputs: [
48
- { name: "sender", type: "address" },
49
- { name: "key", type: "uint192" }
50
- ],
51
- name: "getNonce",
52
- outputs: [{ name: "nonce", type: "uint256" }],
53
- stateMutability: "view",
54
- type: "function"
55
- }
56
- ];
57
- var smartAccountAbi = [
58
- {
59
- inputs: [
60
- { name: "target", type: "address" },
61
- { name: "value", type: "uint256" },
62
- { name: "data", type: "bytes" }
63
- ],
64
- name: "execute",
65
- outputs: [],
66
- stateMutability: "nonpayable",
67
- type: "function"
68
- },
69
- {
70
- inputs: [
71
- { name: "targets", type: "address[]" },
72
- { name: "values", type: "uint256[]" },
73
- { name: "datas", type: "bytes[]" }
74
- ],
75
- name: "executeBatch",
76
- outputs: [],
77
- stateMutability: "nonpayable",
78
- type: "function"
79
- }
80
- ];
81
- var erc20Abi = [
82
- {
83
- inputs: [{ name: "account", type: "address" }],
84
- name: "balanceOf",
85
- outputs: [{ name: "", type: "uint256" }],
86
- stateMutability: "view",
87
- type: "function"
88
- },
89
- {
90
- inputs: [
91
- { name: "to", type: "address" },
92
- { name: "amount", type: "uint256" }
93
- ],
94
- name: "transfer",
95
- outputs: [{ name: "", type: "bool" }],
96
- stateMutability: "nonpayable",
97
- type: "function"
98
- },
99
- {
100
- inputs: [
101
- { name: "spender", type: "address" },
102
- { name: "amount", type: "uint256" }
103
- ],
104
- name: "approve",
105
- outputs: [{ name: "", type: "bool" }],
106
- stateMutability: "nonpayable",
107
- type: "function"
108
- },
109
- {
110
- inputs: [
111
- { name: "owner", type: "address" },
112
- { name: "spender", type: "address" }
113
- ],
114
- name: "allowance",
115
- outputs: [{ name: "", type: "uint256" }],
116
- stateMutability: "view",
117
- type: "function"
118
- },
119
- {
120
- inputs: [
121
- { name: "from", type: "address" },
122
- { name: "to", type: "address" },
123
- { name: "amount", type: "uint256" }
124
- ],
125
- name: "transferFrom",
126
- outputs: [{ name: "", type: "bool" }],
127
- stateMutability: "nonpayable",
128
- type: "function"
129
- },
130
- {
131
- inputs: [],
132
- name: "decimals",
133
- outputs: [{ name: "", type: "uint8" }],
134
- stateMutability: "view",
135
- type: "function"
136
- }
137
- ];
138
-
139
- // src/deployments.ts
140
- var DEPLOYMENTS = {
141
- // Base Mainnet
142
- 8453: {
143
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
144
- factory: "0xe2584152891E4769025807DEa0cD611F135aDC68",
145
- paymaster: "0x1e13Eb16C565E3f3FDe49A011755e50410bb1F95",
146
- usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
147
- },
148
- // Base Sepolia
149
- 84532: {
150
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
151
- factory: "0x9406Cc6185a346906296840746125a0E44976454",
152
- usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
153
- }
154
- };
155
-
156
- // src/AccountAbstraction.ts
157
- var AccountAbstraction = class {
158
- constructor(chainConfig) {
159
- this.owner = null;
160
- this.smartAccountAddress = null;
161
- this.chainConfig = chainConfig;
162
- const chainId = chainConfig.chain.id;
163
- const defaults = DEPLOYMENTS[chainId];
164
- const entryPoint = chainConfig.entryPointAddress || defaults?.entryPoint;
165
- if (!entryPoint) throw new Error(`EntryPoint address not found for chain ${chainId}`);
166
- this.entryPointAddress = entryPoint;
167
- const factory = chainConfig.factoryAddress || defaults?.factory;
168
- if (!factory) throw new Error(`Factory address not found for chain ${chainId}`);
169
- this.factoryAddress = factory;
170
- const usdc = chainConfig.usdcAddress || defaults?.usdc;
171
- if (!usdc) throw new Error(`USDC address not found for chain ${chainId}`);
172
- this.usdcAddress = usdc;
173
- this.paymasterAddress = chainConfig.paymasterAddress || defaults?.paymaster;
174
- const rpcUrl = chainConfig.rpcUrl || chainConfig.chain.rpcUrls.default.http[0];
175
- this.publicClient = createPublicClient({
176
- chain: chainConfig.chain,
177
- transport: http(rpcUrl)
178
- });
179
- }
180
- /**
181
- * Connect to MetaMask and get the owner address
182
- */
183
- async connect() {
184
- if (typeof window === "undefined" || !window.ethereum) {
185
- throw new Error("MetaMask is not installed");
186
- }
187
- const accounts = await window.ethereum.request({
188
- method: "eth_requestAccounts"
189
- });
190
- if (!accounts || accounts.length === 0) {
191
- throw new Error("No accounts found");
192
- }
193
- const chainId = await window.ethereum.request({
194
- method: "eth_chainId"
195
- });
196
- const targetChainId = this.chainConfig.chain.id;
197
- if (parseInt(chainId, 16) !== targetChainId) {
198
- try {
199
- await window.ethereum.request({
200
- method: "wallet_switchEthereumChain",
201
- params: [{ chainId: "0x" + targetChainId.toString(16) }]
202
- });
203
- } catch (switchError) {
204
- const error = switchError;
205
- if (error.code === 4902) {
206
- await window.ethereum.request({
207
- method: "wallet_addEthereumChain",
208
- params: [
209
- {
210
- chainId: "0x" + targetChainId.toString(16),
211
- chainName: this.chainConfig.chain.name,
212
- nativeCurrency: this.chainConfig.chain.nativeCurrency,
213
- rpcUrls: [this.chainConfig.rpcUrl],
214
- blockExplorerUrls: this.chainConfig.chain.blockExplorers?.default?.url ? [this.chainConfig.chain.blockExplorers.default.url] : []
215
- }
216
- ]
217
- });
218
- } else {
219
- throw switchError;
220
- }
221
- }
222
- }
223
- this.owner = accounts[0];
224
- this.smartAccountAddress = await this.getSmartAccountAddress(this.owner);
225
- return {
226
- owner: this.owner,
227
- smartAccount: this.smartAccountAddress
228
- };
229
- }
230
- /**
231
- * Get the Smart Account address for an owner (counterfactual)
232
- */
233
- async getSmartAccountAddress(owner) {
234
- const address = await this.publicClient.readContract({
235
- address: this.factoryAddress,
236
- abi: factoryAbi,
237
- functionName: "getAccountAddress",
238
- args: [owner, 0n]
239
- // salt = 0
240
- });
241
- return address;
242
- }
243
- /**
244
- * Check if the Smart Account is deployed
245
- */
246
- async isAccountDeployed() {
247
- if (!this.smartAccountAddress) {
248
- throw new Error("Not connected");
249
- }
250
- const code = await this.publicClient.getCode({
251
- address: this.smartAccountAddress
252
- });
253
- return code !== void 0 && code !== "0x";
254
- }
255
- /**
256
- * Get the USDC balance of the Smart Account
257
- */
258
- async getUsdcBalance() {
259
- if (!this.smartAccountAddress) {
260
- throw new Error("Not connected");
261
- }
262
- return await this.publicClient.readContract({
263
- address: this.usdcAddress,
264
- abi: erc20Abi,
265
- functionName: "balanceOf",
266
- args: [this.smartAccountAddress]
267
- });
268
- }
269
- /**
270
- * Get the EOA's USDC balance
271
- */
272
- async getEoaUsdcBalance() {
273
- if (!this.owner) {
274
- throw new Error("Not connected");
275
- }
276
- return await this.publicClient.readContract({
277
- address: this.usdcAddress,
278
- abi: erc20Abi,
279
- functionName: "balanceOf",
280
- args: [this.owner]
281
- });
282
- }
283
- /**
284
- * Get the allowance of the Smart Account to spend the EOA's USDC
285
- */
286
- async getAllowance() {
287
- if (!this.owner || !this.smartAccountAddress) {
288
- throw new Error("Not connected");
289
- }
290
- return await this.publicClient.readContract({
291
- address: this.usdcAddress,
292
- abi: erc20Abi,
293
- functionName: "allowance",
294
- args: [this.owner, this.smartAccountAddress]
295
- });
296
- }
297
- /**
298
- * Get the nonce for the Smart Account
299
- */
300
- async getNonce() {
301
- if (!this.smartAccountAddress) {
302
- throw new Error("Not connected");
303
- }
304
- return await this.publicClient.readContract({
305
- address: this.entryPointAddress,
306
- abi: entryPointAbi,
307
- functionName: "getNonce",
308
- args: [this.smartAccountAddress, 0n]
309
- });
310
- }
311
- /**
312
- * Build initCode for account deployment
313
- */
314
- buildInitCode() {
315
- if (!this.owner) {
316
- throw new Error("Not connected");
317
- }
318
- const createAccountData = encodeFunctionData({
319
- abi: factoryAbi,
320
- functionName: "createAccount",
321
- args: [this.owner, 0n]
322
- });
323
- return `${this.factoryAddress}${createAccountData.slice(2)}`;
324
- }
325
- /**
326
- * Estimate gas for a UserOperation
327
- */
328
- async estimateGas(userOp) {
329
- const response = await fetch(this.chainConfig.bundlerUrl, {
330
- method: "POST",
331
- headers: { "Content-Type": "application/json" },
332
- body: JSON.stringify({
333
- jsonrpc: "2.0",
334
- id: 1,
335
- method: "eth_estimateUserOperationGas",
336
- params: [
337
- {
338
- sender: userOp.sender,
339
- nonce: userOp.nonce ? "0x" + userOp.nonce.toString(16) : "0x0",
340
- initCode: userOp.initCode || "0x",
341
- callData: userOp.callData || "0x",
342
- paymasterAndData: userOp.paymasterAndData || "0x",
343
- signature: "0x"
344
- },
345
- this.entryPointAddress
346
- ]
347
- })
348
- });
349
- const result = await response.json();
350
- if (result.error) {
351
- throw new Error(result.error.message);
352
- }
353
- return result.result;
354
- }
355
- /**
356
- * Build a UserOperation for Batched Execution (e.g. USDC Transfer + Fee)
357
- */
358
- async buildUserOperationBatch(transactions) {
359
- if (!this.owner || !this.smartAccountAddress) {
360
- throw new Error("Not connected");
361
- }
362
- const isDeployed = await this.isAccountDeployed();
363
- const initCode = isDeployed ? "0x" : this.buildInitCode();
364
- const targets = transactions.map((tx) => tx.target);
365
- const values = transactions.map((tx) => tx.value);
366
- const datas = transactions.map((tx) => tx.data);
367
- const callData = encodeFunctionData({
368
- abi: smartAccountAbi,
369
- functionName: "executeBatch",
370
- args: [targets, values, datas]
371
- });
372
- const nonce = await this.getNonce();
373
- const gasEstimate = await this.estimateGas({
374
- sender: this.smartAccountAddress,
375
- nonce,
376
- initCode,
377
- callData,
378
- paymasterAndData: this.paymasterAddress
379
- });
380
- return {
381
- sender: this.smartAccountAddress,
382
- nonce,
383
- initCode,
384
- callData,
385
- callGasLimit: BigInt(gasEstimate.callGasLimit),
386
- verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),
387
- preVerificationGas: BigInt(gasEstimate.preVerificationGas),
388
- maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),
389
- maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),
390
- paymasterAndData: this.paymasterAddress,
391
- signature: "0x"
392
- };
393
- }
394
- /**
395
- * Build a UserOperation to ONLY deploy the account (empty callData)
396
- */
397
- async buildDeployUserOperation() {
398
- if (!this.owner || !this.smartAccountAddress) {
399
- throw new Error("Not connected");
400
- }
401
- const isDeployed = await this.isAccountDeployed();
402
- if (isDeployed) {
403
- throw new Error("Account is already deployed");
404
- }
405
- const initCode = this.buildInitCode();
406
- const callData = "0x";
407
- const nonce = await this.getNonce();
408
- const gasEstimate = await this.estimateGas({
409
- sender: this.smartAccountAddress,
410
- nonce,
411
- initCode,
412
- callData,
413
- paymasterAndData: this.paymasterAddress
414
- });
415
- return {
416
- sender: this.smartAccountAddress,
417
- nonce,
418
- initCode,
419
- callData,
420
- callGasLimit: BigInt(gasEstimate.callGasLimit),
421
- verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),
422
- preVerificationGas: BigInt(gasEstimate.preVerificationGas),
423
- maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),
424
- maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),
425
- paymasterAndData: this.paymasterAddress,
426
- signature: "0x"
427
- };
428
- }
429
- /**
430
- * Calculate the UserOperation hash
431
- */
432
- getUserOpHash(userOp) {
433
- const packed = encodeAbiParameters(
434
- [
435
- { type: "address" },
436
- { type: "uint256" },
437
- { type: "bytes32" },
438
- { type: "bytes32" },
439
- { type: "uint256" },
440
- { type: "uint256" },
441
- { type: "uint256" },
442
- { type: "uint256" },
443
- { type: "uint256" },
444
- { type: "bytes32" }
445
- ],
446
- [
447
- userOp.sender,
448
- userOp.nonce,
449
- keccak256(userOp.initCode),
450
- keccak256(userOp.callData),
451
- userOp.callGasLimit,
452
- userOp.verificationGasLimit,
453
- userOp.preVerificationGas,
454
- userOp.maxFeePerGas,
455
- userOp.maxPriorityFeePerGas,
456
- keccak256(userOp.paymasterAndData)
457
- ]
458
- );
459
- const packedHash = keccak256(packed);
460
- return keccak256(
461
- encodeAbiParameters(
462
- [{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
463
- [packedHash, this.entryPointAddress, BigInt(this.chainConfig.chain.id)]
464
- )
465
- );
466
- }
467
- /**
468
- * Sign a UserOperation with MetaMask
469
- */
470
- async signUserOperation(userOp) {
471
- if (!this.owner) {
472
- throw new Error("Not connected");
473
- }
474
- const userOpHash = this.getUserOpHash(userOp);
475
- const signature = await window.ethereum.request({
476
- method: "personal_sign",
477
- params: [userOpHash, this.owner]
478
- });
479
- return {
480
- ...userOp,
481
- signature
482
- };
483
- }
484
- /**
485
- * Send a signed UserOperation to the bundler
486
- */
487
- async sendUserOperation(userOp) {
488
- const response = await fetch(this.chainConfig.bundlerUrl, {
489
- method: "POST",
490
- headers: { "Content-Type": "application/json" },
491
- body: JSON.stringify({
492
- jsonrpc: "2.0",
493
- id: 1,
494
- method: "eth_sendUserOperation",
495
- params: [
496
- {
497
- sender: userOp.sender,
498
- nonce: "0x" + userOp.nonce.toString(16),
499
- initCode: userOp.initCode,
500
- callData: userOp.callData,
501
- callGasLimit: "0x" + userOp.callGasLimit.toString(16),
502
- verificationGasLimit: "0x" + userOp.verificationGasLimit.toString(16),
503
- preVerificationGas: "0x" + userOp.preVerificationGas.toString(16),
504
- maxFeePerGas: "0x" + userOp.maxFeePerGas.toString(16),
505
- maxPriorityFeePerGas: "0x" + userOp.maxPriorityFeePerGas.toString(16),
506
- paymasterAndData: userOp.paymasterAndData,
507
- signature: userOp.signature
508
- },
509
- this.entryPointAddress
510
- ]
511
- })
512
- });
513
- const result = await response.json();
514
- if (result.error) {
515
- throw new Error(result.error.message);
516
- }
517
- return result.result;
518
- }
519
- /**
520
- * Wait for a UserOperation to be confirmed
521
- */
522
- async waitForUserOperation(userOpHash, timeout = 6e4) {
523
- const startTime = Date.now();
524
- while (Date.now() - startTime < timeout) {
525
- const response = await fetch(this.chainConfig.bundlerUrl, {
526
- method: "POST",
527
- headers: { "Content-Type": "application/json" },
528
- body: JSON.stringify({
529
- jsonrpc: "2.0",
530
- id: 1,
531
- method: "eth_getUserOperationReceipt",
532
- params: [userOpHash]
533
- })
534
- });
535
- const result = await response.json();
536
- if (result.result) {
537
- return result.result;
538
- }
539
- await new Promise((resolve) => setTimeout(resolve, 2e3));
540
- }
541
- throw new Error("Timeout waiting for UserOperation");
542
- }
543
- /**
544
- * Request support for token approval (fund if needed)
545
- */
546
- async requestApprovalSupport(token, spender, amount) {
547
- if (!this.owner) {
548
- throw new Error("Not connected");
549
- }
550
- const response = await fetch(this.chainConfig.bundlerUrl, {
551
- method: "POST",
552
- headers: { "Content-Type": "application/json" },
553
- body: JSON.stringify({
554
- jsonrpc: "2.0",
555
- id: 1,
556
- method: "pm_requestApprovalSupport",
557
- params: [token, this.owner, spender, amount.toString()]
558
- })
559
- });
560
- const result = await response.json();
561
- if (result.error) {
562
- throw new Error(result.error.message);
563
- }
564
- return result.result;
565
- }
566
- // Getters
567
- getOwner() {
568
- return this.owner;
569
- }
570
- getSmartAccount() {
571
- return this.smartAccountAddress;
572
- }
573
- };
574
- export {
575
- AccountAbstraction,
576
- DEFAULT_ENTRYPOINT,
577
- DEFAULT_FACTORY,
578
- entryPointAbi,
579
- erc20Abi,
580
- factoryAbi,
581
- smartAccountAbi
582
- };
583
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/AccountAbstraction.ts","../src/constants.ts","../src/deployments.ts"],"sourcesContent":["import {\n createPublicClient,\n http,\n encodeFunctionData,\n encodeAbiParameters,\n keccak256,\n type Address,\n type Hash,\n type Hex,\n type PublicClient\n} from \"viem\";\nimport {\n factoryAbi,\n entryPointAbi,\n smartAccountAbi,\n erc20Abi,\n} from \"./constants\";\nimport {\n type ChainConfig,\n type UserOperation,\n type GasEstimate,\n type UserOpReceipt,\n type ApprovalSupportResult\n} from \"./types\";\nimport { DEPLOYMENTS } from \"./deployments\";\n\n/**\n * ERC-4337 Account Abstraction Client\n */\nexport class AccountAbstraction {\n private owner: Address | null = null;\n private smartAccountAddress: Address | null = null;\n private chainConfig: ChainConfig;\n private publicClient: PublicClient;\n\n // Resolved addresses\n private entryPointAddress: Address;\n private factoryAddress: Address;\n private paymasterAddress?: Address;\n private usdcAddress: Address;\n\n constructor(chainConfig: ChainConfig) {\n this.chainConfig = chainConfig;\n const chainId = chainConfig.chain.id;\n const defaults = DEPLOYMENTS[chainId];\n\n // Resolve addresses (Config > Defaults > Error)\n const entryPoint = chainConfig.entryPointAddress || defaults?.entryPoint;\n if (!entryPoint) throw new Error(`EntryPoint address not found for chain ${chainId}`);\n this.entryPointAddress = entryPoint;\n\n const factory = chainConfig.factoryAddress || defaults?.factory;\n if (!factory) throw new Error(`Factory address not found for chain ${chainId}`);\n this.factoryAddress = factory;\n\n const usdc = chainConfig.usdcAddress || defaults?.usdc;\n if (!usdc) throw new Error(`USDC address not found for chain ${chainId}`);\n this.usdcAddress = usdc;\n\n this.paymasterAddress = chainConfig.paymasterAddress || defaults?.paymaster;\n\n // Use provided RPC or default from chain\n const rpcUrl = chainConfig.rpcUrl || chainConfig.chain.rpcUrls.default.http[0];\n\n this.publicClient = createPublicClient({\n chain: chainConfig.chain,\n transport: http(rpcUrl),\n });\n }\n\n /**\n * Connect to MetaMask and get the owner address\n */\n async connect(): Promise<{ owner: Address; smartAccount: Address }> {\n if (typeof window === \"undefined\" || !window.ethereum) {\n throw new Error(\"MetaMask is not installed\");\n }\n\n // Request account access\n const accounts = (await window.ethereum.request({\n method: \"eth_requestAccounts\",\n })) as string[];\n\n if (!accounts || accounts.length === 0) {\n throw new Error(\"No accounts found\");\n }\n\n // Check network\n const chainId = (await window.ethereum.request({\n method: \"eth_chainId\",\n })) as string;\n\n const targetChainId = this.chainConfig.chain.id;\n\n if (parseInt(chainId, 16) !== targetChainId) {\n // Switch to configured chain\n try {\n await window.ethereum.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: \"0x\" + targetChainId.toString(16) }],\n });\n } catch (switchError: unknown) {\n const error = switchError as { code?: number };\n // Chain not added, add it\n if (error.code === 4902) {\n await window.ethereum.request({\n method: \"wallet_addEthereumChain\",\n params: [\n {\n chainId: \"0x\" + targetChainId.toString(16),\n chainName: this.chainConfig.chain.name,\n nativeCurrency: this.chainConfig.chain.nativeCurrency,\n rpcUrls: [this.chainConfig.rpcUrl],\n blockExplorerUrls: this.chainConfig.chain.blockExplorers?.default?.url\n ? [this.chainConfig.chain.blockExplorers.default.url]\n : [],\n },\n ],\n });\n } else {\n throw switchError;\n }\n }\n }\n\n this.owner = accounts[0] as Address;\n this.smartAccountAddress = await this.getSmartAccountAddress(this.owner);\n\n return {\n owner: this.owner,\n smartAccount: this.smartAccountAddress,\n };\n }\n\n /**\n * Get the Smart Account address for an owner (counterfactual)\n */\n async getSmartAccountAddress(owner: Address): Promise<Address> {\n const address = await this.publicClient.readContract({\n address: this.factoryAddress,\n abi: factoryAbi,\n functionName: \"getAccountAddress\",\n args: [owner, 0n], // salt = 0\n }) as Address;\n return address;\n }\n\n /**\n * Check if the Smart Account is deployed\n */\n async isAccountDeployed(): Promise<boolean> {\n if (!this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n const code = await this.publicClient.getCode({\n address: this.smartAccountAddress,\n });\n return code !== undefined && code !== \"0x\";\n }\n\n\n /**\n * Get the USDC balance of the Smart Account\n */\n async getUsdcBalance(): Promise<bigint> {\n if (!this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n return await this.publicClient.readContract({\n address: this.usdcAddress,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [this.smartAccountAddress],\n }) as bigint;\n }\n\n\n /**\n * Get the EOA's USDC balance\n */\n async getEoaUsdcBalance(): Promise<bigint> {\n if (!this.owner) {\n throw new Error(\"Not connected\");\n }\n\n return await this.publicClient.readContract({\n address: this.usdcAddress,\n abi: erc20Abi,\n functionName: \"balanceOf\",\n args: [this.owner],\n }) as bigint;\n }\n\n /**\n * Get the allowance of the Smart Account to spend the EOA's USDC\n */\n async getAllowance(): Promise<bigint> {\n if (!this.owner || !this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n return await this.publicClient.readContract({\n address: this.usdcAddress,\n abi: erc20Abi,\n functionName: \"allowance\",\n args: [this.owner, this.smartAccountAddress],\n }) as bigint;\n }\n\n /**\n * Get the nonce for the Smart Account\n */\n async getNonce(): Promise<bigint> {\n if (!this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n return await this.publicClient.readContract({\n address: this.entryPointAddress,\n abi: entryPointAbi,\n functionName: \"getNonce\",\n args: [this.smartAccountAddress, 0n],\n }) as bigint;\n }\n\n /**\n * Build initCode for account deployment\n */\n buildInitCode(): Hex {\n if (!this.owner) {\n throw new Error(\"Not connected\");\n }\n\n const createAccountData = encodeFunctionData({\n abi: factoryAbi,\n functionName: \"createAccount\",\n args: [this.owner, 0n],\n });\n\n return `${this.factoryAddress}${createAccountData.slice(2)}` as Hex;\n }\n\n\n /**\n * Estimate gas for a UserOperation\n */\n async estimateGas(userOp: Partial<UserOperation>): Promise<GasEstimate> {\n const response = await fetch(this.chainConfig.bundlerUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_estimateUserOperationGas\",\n params: [\n {\n sender: userOp.sender,\n nonce: userOp.nonce ? \"0x\" + userOp.nonce.toString(16) : \"0x0\",\n initCode: userOp.initCode || \"0x\",\n callData: userOp.callData || \"0x\",\n paymasterAndData: userOp.paymasterAndData || \"0x\",\n signature: \"0x\",\n },\n this.entryPointAddress,\n ],\n }),\n });\n\n const result = await response.json();\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n return result.result;\n }\n\n\n /**\n * Build a UserOperation for Batched Execution (e.g. USDC Transfer + Fee)\n */\n async buildUserOperationBatch(\n transactions: { target: Address; value: bigint; data: Hex }[]\n ): Promise<UserOperation> {\n if (!this.owner || !this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n const isDeployed = await this.isAccountDeployed();\n const initCode = isDeployed ? \"0x\" : this.buildInitCode();\n\n // Prepare arrays for executeBatch\n const targets = transactions.map((tx) => tx.target);\n const values = transactions.map((tx) => tx.value);\n const datas = transactions.map((tx) => tx.data);\n\n // Encode callData for executeBatch\n const callData = encodeFunctionData({\n abi: smartAccountAbi,\n functionName: \"executeBatch\",\n args: [targets, values, datas],\n });\n\n const nonce = await this.getNonce();\n\n // Estimate gas\n const gasEstimate = await this.estimateGas({\n sender: this.smartAccountAddress,\n nonce,\n initCode: initCode as Hex,\n callData,\n paymasterAndData: this.paymasterAddress as Hex,\n });\n\n return {\n sender: this.smartAccountAddress,\n nonce,\n initCode: initCode as Hex,\n callData,\n callGasLimit: BigInt(gasEstimate.callGasLimit),\n verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),\n preVerificationGas: BigInt(gasEstimate.preVerificationGas),\n maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),\n maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),\n paymasterAndData: this.paymasterAddress as Hex,\n signature: \"0x\",\n };\n }\n\n /**\n * Build a UserOperation to ONLY deploy the account (empty callData)\n */\n async buildDeployUserOperation(): Promise<UserOperation> {\n if (!this.owner || !this.smartAccountAddress) {\n throw new Error(\"Not connected\");\n }\n\n const isDeployed = await this.isAccountDeployed();\n if (isDeployed) {\n throw new Error(\"Account is already deployed\");\n }\n\n const initCode = this.buildInitCode();\n const callData = \"0x\"; // Empty callData for deployment only\n const nonce = await this.getNonce();\n\n // Estimate gas\n const gasEstimate = await this.estimateGas({\n sender: this.smartAccountAddress,\n nonce,\n initCode: initCode as Hex,\n callData,\n paymasterAndData: this.paymasterAddress as Hex,\n });\n\n return {\n sender: this.smartAccountAddress,\n nonce,\n initCode: initCode as Hex,\n callData,\n callGasLimit: BigInt(gasEstimate.callGasLimit),\n verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),\n preVerificationGas: BigInt(gasEstimate.preVerificationGas),\n maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),\n maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),\n paymasterAndData: this.paymasterAddress as Hex,\n signature: \"0x\",\n };\n }\n\n /**\n * Calculate the UserOperation hash\n */\n getUserOpHash(userOp: UserOperation): Hex {\n const packed = encodeAbiParameters(\n [\n { type: \"address\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n ],\n [\n userOp.sender,\n userOp.nonce,\n keccak256(userOp.initCode),\n keccak256(userOp.callData),\n userOp.callGasLimit,\n userOp.verificationGasLimit,\n userOp.preVerificationGas,\n userOp.maxFeePerGas,\n userOp.maxPriorityFeePerGas,\n keccak256(userOp.paymasterAndData),\n ]\n );\n\n const packedHash = keccak256(packed);\n\n return keccak256(\n encodeAbiParameters(\n [{ type: \"bytes32\" }, { type: \"address\" }, { type: \"uint256\" }],\n [packedHash, this.entryPointAddress, BigInt(this.chainConfig.chain.id)]\n )\n );\n }\n\n /**\n * Sign a UserOperation with MetaMask\n */\n async signUserOperation(userOp: UserOperation): Promise<UserOperation> {\n if (!this.owner) {\n throw new Error(\"Not connected\");\n }\n\n const userOpHash = this.getUserOpHash(userOp);\n\n // Sign with MetaMask using personal_sign (EIP-191)\n const signature = (await window.ethereum!.request({\n method: \"personal_sign\",\n params: [userOpHash, this.owner],\n })) as Hex;\n\n return {\n ...userOp,\n signature,\n };\n }\n\n /**\n * Send a signed UserOperation to the bundler\n */\n async sendUserOperation(userOp: UserOperation): Promise<Hash> {\n const response = await fetch(this.chainConfig.bundlerUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_sendUserOperation\",\n params: [\n {\n sender: userOp.sender,\n nonce: \"0x\" + userOp.nonce.toString(16),\n initCode: userOp.initCode,\n callData: userOp.callData,\n callGasLimit: \"0x\" + userOp.callGasLimit.toString(16),\n verificationGasLimit: \"0x\" + userOp.verificationGasLimit.toString(16),\n preVerificationGas: \"0x\" + userOp.preVerificationGas.toString(16),\n maxFeePerGas: \"0x\" + userOp.maxFeePerGas.toString(16),\n maxPriorityFeePerGas: \"0x\" + userOp.maxPriorityFeePerGas.toString(16),\n paymasterAndData: userOp.paymasterAndData,\n signature: userOp.signature,\n },\n this.entryPointAddress,\n ],\n }),\n });\n\n const result = await response.json();\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n return result.result as Hash;\n }\n\n /**\n * Wait for a UserOperation to be confirmed\n */\n async waitForUserOperation(\n userOpHash: Hash,\n timeout = 60000\n ): Promise<UserOpReceipt> {\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n const response = await fetch(this.chainConfig.bundlerUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"eth_getUserOperationReceipt\",\n params: [userOpHash],\n }),\n });\n\n const result = await response.json();\n if (result.result) {\n return result.result as UserOpReceipt;\n }\n\n // Wait 2 seconds before polling again\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n\n throw new Error(\"Timeout waiting for UserOperation\");\n }\n\n\n /**\n * Request support for token approval (fund if needed)\n */\n async requestApprovalSupport(\n token: Address,\n spender: Address,\n amount: bigint\n ): Promise<ApprovalSupportResult> {\n if (!this.owner) {\n throw new Error(\"Not connected\");\n }\n\n const response = await fetch(this.chainConfig.bundlerUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: 1,\n method: \"pm_requestApprovalSupport\",\n params: [token, this.owner, spender, amount.toString()],\n }),\n });\n\n const result = await response.json();\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n return result.result;\n }\n\n // Getters\n getOwner(): Address | null {\n return this.owner;\n }\n\n getSmartAccount(): Address | null {\n return this.smartAccountAddress;\n }\n}\n\n// Global window types for MetaMask\ndeclare global {\n interface Window {\n ethereum?: {\n request: (args: { method: string; params?: unknown[] }) => Promise<unknown>;\n on: (event: string, callback: (args: unknown) => void) => void;\n removeListener: (event: string, callback: (args: unknown) => void) => void;\n };\n }\n}\n","export const DEFAULT_ENTRYPOINT = \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\";\nexport const DEFAULT_FACTORY = \"0x9406Cc6185a346906296840746125a0E44976454\"; // SimpleAccountFactory v0.6\n\nexport const factoryAbi = [\n {\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"salt\", type: \"uint256\" },\n ],\n name: \"getAccountAddress\",\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"salt\", type: \"uint256\" },\n ],\n name: \"isAccountDeployed\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"salt\", type: \"uint256\" },\n ],\n name: \"createAccount\",\n outputs: [{ name: \"account\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n\nexport const entryPointAbi = [\n {\n inputs: [\n { name: \"sender\", type: \"address\" },\n { name: \"key\", type: \"uint192\" },\n ],\n name: \"getNonce\",\n outputs: [{ name: \"nonce\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n\nexport const smartAccountAbi = [\n {\n inputs: [\n { name: \"target\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"data\", type: \"bytes\" },\n ],\n name: \"execute\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"targets\", type: \"address[]\" },\n { name: \"values\", type: \"uint256[]\" },\n { name: \"datas\", type: \"bytes[]\" },\n ],\n name: \"executeBatch\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n\nexport const erc20Abi = [\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"transfer\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"spender\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"approve\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"owner\", type: \"address\" },\n { name: \"spender\", type: \"address\" },\n ],\n name: \"allowance\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"transferFrom\",\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"decimals\",\n outputs: [{ name: \"\", type: \"uint8\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n","import { type Address } from \"viem\";\n\nexport const DEPLOYMENTS: Record<number, {\n entryPoint: Address;\n factory: Address;\n paymaster?: Address;\n usdc: Address;\n}> = {\n // Base Mainnet\n 8453: {\n entryPoint: \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\",\n factory: \"0xe2584152891E4769025807DEa0cD611F135aDC68\",\n paymaster: \"0x1e13Eb16C565E3f3FDe49A011755e50410bb1F95\",\n usdc: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\"\n },\n // Base Sepolia\n 84532: {\n entryPoint: \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\",\n factory: \"0x9406Cc6185a346906296840746125a0E44976454\",\n usdc: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\"\n }\n};\n"],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKG;;;ACVA,IAAM,qBAAqB;AAC3B,IAAM,kBAAkB;AAExB,IAAM,aAAa;AAAA,EACtB;AAAA,IACI,QAAQ;AAAA,MACJ,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,MACjC,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IACpC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,IAAI,MAAM,UAAU,CAAC;AAAA,IACvC,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACV;AAAA,EACA;AAAA,IACI,QAAQ;AAAA,MACJ,EAAE,M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