@1llet.xyz/erc4337-gasless-sdk 0.2.0 → 0.4.1

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 ADDED
@@ -0,0 +1,714 @@
1
+ // src/AccountAbstraction.ts
2
+ import {
3
+ createPublicClient,
4
+ http,
5
+ decodeErrorResult
6
+ } from "viem";
7
+
8
+ // src/constants.ts
9
+ var factoryAbi = [
10
+ {
11
+ inputs: [
12
+ { name: "owner", type: "address" },
13
+ { name: "salt", type: "uint256" }
14
+ ],
15
+ name: "getAccountAddress",
16
+ outputs: [{ name: "", type: "address" }],
17
+ stateMutability: "view",
18
+ type: "function"
19
+ },
20
+ {
21
+ inputs: [
22
+ { name: "owner", type: "address" },
23
+ { name: "salt", type: "uint256" }
24
+ ],
25
+ name: "isAccountDeployed",
26
+ outputs: [{ name: "", type: "bool" }],
27
+ stateMutability: "view",
28
+ type: "function"
29
+ },
30
+ {
31
+ inputs: [
32
+ { name: "owner", type: "address" },
33
+ { name: "salt", type: "uint256" }
34
+ ],
35
+ name: "createAccount",
36
+ outputs: [{ name: "account", type: "address" }],
37
+ stateMutability: "nonpayable",
38
+ type: "function"
39
+ }
40
+ ];
41
+ var entryPointAbi = [
42
+ {
43
+ inputs: [
44
+ { name: "sender", type: "address" },
45
+ { name: "key", type: "uint192" }
46
+ ],
47
+ name: "getNonce",
48
+ outputs: [{ name: "nonce", type: "uint256" }],
49
+ stateMutability: "view",
50
+ type: "function"
51
+ }
52
+ ];
53
+ var smartAccountAbi = [
54
+ {
55
+ inputs: [
56
+ { name: "target", type: "address" },
57
+ { name: "value", type: "uint256" },
58
+ { name: "data", type: "bytes" }
59
+ ],
60
+ name: "execute",
61
+ outputs: [],
62
+ stateMutability: "nonpayable",
63
+ type: "function"
64
+ },
65
+ {
66
+ inputs: [
67
+ { name: "targets", type: "address[]" },
68
+ { name: "values", type: "uint256[]" },
69
+ { name: "datas", type: "bytes[]" }
70
+ ],
71
+ name: "executeBatch",
72
+ outputs: [],
73
+ stateMutability: "nonpayable",
74
+ type: "function"
75
+ }
76
+ ];
77
+ var erc20Abi = [
78
+ {
79
+ inputs: [{ name: "account", type: "address" }],
80
+ name: "balanceOf",
81
+ outputs: [{ name: "", type: "uint256" }],
82
+ stateMutability: "view",
83
+ type: "function"
84
+ },
85
+ {
86
+ inputs: [
87
+ { name: "to", type: "address" },
88
+ { name: "amount", type: "uint256" }
89
+ ],
90
+ name: "transfer",
91
+ outputs: [{ name: "", type: "bool" }],
92
+ stateMutability: "nonpayable",
93
+ type: "function"
94
+ },
95
+ {
96
+ inputs: [
97
+ { name: "spender", type: "address" },
98
+ { name: "amount", type: "uint256" }
99
+ ],
100
+ name: "approve",
101
+ outputs: [{ name: "", type: "bool" }],
102
+ stateMutability: "nonpayable",
103
+ type: "function"
104
+ },
105
+ {
106
+ inputs: [
107
+ { name: "owner", type: "address" },
108
+ { name: "spender", type: "address" }
109
+ ],
110
+ name: "allowance",
111
+ outputs: [{ name: "", type: "uint256" }],
112
+ stateMutability: "view",
113
+ type: "function"
114
+ },
115
+ {
116
+ inputs: [
117
+ { name: "from", type: "address" },
118
+ { name: "to", type: "address" },
119
+ { name: "amount", type: "uint256" }
120
+ ],
121
+ name: "transferFrom",
122
+ outputs: [{ name: "", type: "bool" }],
123
+ stateMutability: "nonpayable",
124
+ type: "function"
125
+ },
126
+ {
127
+ inputs: [],
128
+ name: "decimals",
129
+ outputs: [{ name: "", type: "uint8" }],
130
+ stateMutability: "view",
131
+ type: "function"
132
+ }
133
+ ];
134
+
135
+ // src/BundlerClient.ts
136
+ var BundlerClient = class {
137
+ constructor(config, entryPointAddress) {
138
+ this.bundlerUrl = config.bundlerUrl;
139
+ this.chainId = config.chain.id;
140
+ this.entryPointAddress = entryPointAddress;
141
+ }
142
+ async call(method, params) {
143
+ const response = await fetch(this.bundlerUrl, {
144
+ method: "POST",
145
+ headers: { "Content-Type": "application/json" },
146
+ body: JSON.stringify({
147
+ jsonrpc: "2.0",
148
+ id: 1,
149
+ method,
150
+ params
151
+ })
152
+ });
153
+ const result = await response.json();
154
+ if (result.error) {
155
+ throw new Error(result.error.message);
156
+ }
157
+ return result.result;
158
+ }
159
+ async estimateGas(userOp) {
160
+ return await this.call("eth_estimateUserOperationGas", [
161
+ {
162
+ sender: userOp.sender,
163
+ nonce: userOp.nonce ? "0x" + userOp.nonce.toString(16) : "0x0",
164
+ initCode: userOp.initCode || "0x",
165
+ callData: userOp.callData || "0x",
166
+ paymasterAndData: userOp.paymasterAndData || "0x",
167
+ signature: "0x"
168
+ },
169
+ this.entryPointAddress
170
+ ]);
171
+ }
172
+ async sendUserOperation(userOp) {
173
+ return await this.call("eth_sendUserOperation", [
174
+ {
175
+ sender: userOp.sender,
176
+ nonce: "0x" + userOp.nonce.toString(16),
177
+ initCode: userOp.initCode,
178
+ callData: userOp.callData,
179
+ callGasLimit: "0x" + userOp.callGasLimit.toString(16),
180
+ verificationGasLimit: "0x" + userOp.verificationGasLimit.toString(16),
181
+ preVerificationGas: "0x" + userOp.preVerificationGas.toString(16),
182
+ maxFeePerGas: "0x" + userOp.maxFeePerGas.toString(16),
183
+ maxPriorityFeePerGas: "0x" + userOp.maxPriorityFeePerGas.toString(16),
184
+ paymasterAndData: userOp.paymasterAndData,
185
+ signature: userOp.signature
186
+ },
187
+ this.entryPointAddress
188
+ ]);
189
+ }
190
+ async waitForUserOperation(userOpHash, timeout = 6e4) {
191
+ const startTime = Date.now();
192
+ while (Date.now() - startTime < timeout) {
193
+ const result = await this.call("eth_getUserOperationReceipt", [userOpHash]);
194
+ if (result) {
195
+ return result;
196
+ }
197
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
198
+ }
199
+ throw new Error("Timeout waiting for UserOperation");
200
+ }
201
+ async requestApprovalSupport(token, owner, spender, amount) {
202
+ return await this.call("pm_requestApprovalSupport", [
203
+ token,
204
+ owner,
205
+ spender,
206
+ amount.toString()
207
+ ]);
208
+ }
209
+ };
210
+
211
+ // src/TokenService.ts
212
+ import { encodeFunctionData } from "viem";
213
+ var TokenService = class {
214
+ constructor(chainConfig, publicClient) {
215
+ this.tokens = /* @__PURE__ */ new Map();
216
+ this.publicClient = publicClient;
217
+ chainConfig.tokens.forEach((token) => {
218
+ this.tokens.set(token.symbol.toUpperCase(), token);
219
+ });
220
+ }
221
+ /**
222
+ * Resolve token address from symbol or return address if provided
223
+ */
224
+ getTokenAddress(token) {
225
+ if (token === "ETH") {
226
+ return "0x0000000000000000000000000000000000000000";
227
+ }
228
+ if (token.startsWith("0x")) return token;
229
+ const info = this.tokens.get(token.toUpperCase());
230
+ if (!info) throw new Error(`Token ${token} not found in chain config`);
231
+ return info.address;
232
+ }
233
+ /**
234
+ * Get balance of a token for an account
235
+ */
236
+ async getBalance(token, account) {
237
+ const address = this.getTokenAddress(token);
238
+ if (address === "0x0000000000000000000000000000000000000000") {
239
+ return await this.publicClient.getBalance({ address: account });
240
+ }
241
+ return await this.publicClient.readContract({
242
+ address,
243
+ abi: erc20Abi,
244
+ functionName: "balanceOf",
245
+ args: [account]
246
+ });
247
+ }
248
+ /**
249
+ * Get allowance (ERC-20 only)
250
+ */
251
+ async getAllowance(token, owner, spender) {
252
+ const address = this.getTokenAddress(token);
253
+ if (address === "0x0000000000000000000000000000000000000000") {
254
+ return 0n;
255
+ }
256
+ return await this.publicClient.readContract({
257
+ address,
258
+ abi: erc20Abi,
259
+ functionName: "allowance",
260
+ args: [owner, spender]
261
+ });
262
+ }
263
+ /**
264
+ * Encode transfer data
265
+ */
266
+ encodeTransfer(recipient, amount) {
267
+ return encodeFunctionData({
268
+ abi: erc20Abi,
269
+ functionName: "transfer",
270
+ args: [recipient, amount]
271
+ });
272
+ }
273
+ /**
274
+ * Encode approve data
275
+ */
276
+ encodeApprove(spender, amount) {
277
+ return encodeFunctionData({
278
+ abi: erc20Abi,
279
+ functionName: "approve",
280
+ args: [spender, amount]
281
+ });
282
+ }
283
+ };
284
+
285
+ // src/UserOpBuilder.ts
286
+ import {
287
+ encodeFunctionData as encodeFunctionData2,
288
+ encodeAbiParameters,
289
+ keccak256
290
+ } from "viem";
291
+ var UserOpBuilder = class {
292
+ constructor(chainConfig, bundlerClient, publicClient) {
293
+ this.chainConfig = chainConfig;
294
+ this.bundlerClient = bundlerClient;
295
+ this.publicClient = publicClient;
296
+ this.entryPointAddress = chainConfig.entryPointAddress;
297
+ this.factoryAddress = chainConfig.factoryAddress;
298
+ }
299
+ async getNonce(smartAccountAddress) {
300
+ return await this.publicClient.readContract({
301
+ address: this.entryPointAddress,
302
+ abi: entryPointAbi,
303
+ functionName: "getNonce",
304
+ args: [smartAccountAddress, 0n]
305
+ });
306
+ }
307
+ buildInitCode(owner) {
308
+ const createAccountData = encodeFunctionData2({
309
+ abi: factoryAbi,
310
+ functionName: "createAccount",
311
+ args: [owner, 0n]
312
+ });
313
+ return `${this.factoryAddress}${createAccountData.slice(2)}`;
314
+ }
315
+ async isAccountDeployed(smartAccountAddress) {
316
+ const code = await this.publicClient.getCode({
317
+ address: smartAccountAddress
318
+ });
319
+ return code !== void 0 && code !== "0x";
320
+ }
321
+ async buildUserOperationBatch(owner, smartAccountAddress, transactions) {
322
+ const isDeployed = await this.isAccountDeployed(smartAccountAddress);
323
+ const initCode = isDeployed ? "0x" : this.buildInitCode(owner);
324
+ const targets = transactions.map((tx) => tx.target);
325
+ const values = transactions.map((tx) => tx.value);
326
+ const datas = transactions.map((tx) => tx.data);
327
+ const callData = encodeFunctionData2({
328
+ abi: smartAccountAbi,
329
+ functionName: "executeBatch",
330
+ args: [targets, values, datas]
331
+ });
332
+ const nonce = await this.getNonce(smartAccountAddress);
333
+ const partialOp = {
334
+ sender: smartAccountAddress,
335
+ nonce,
336
+ initCode,
337
+ callData,
338
+ paymasterAndData: this.chainConfig.paymasterAddress || "0x"
339
+ };
340
+ const gasEstimate = await this.bundlerClient.estimateGas(partialOp);
341
+ return {
342
+ ...partialOp,
343
+ callGasLimit: BigInt(gasEstimate.callGasLimit),
344
+ verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),
345
+ preVerificationGas: BigInt(gasEstimate.preVerificationGas),
346
+ maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),
347
+ maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),
348
+ signature: "0x"
349
+ };
350
+ }
351
+ async buildDeployUserOp(owner, smartAccountAddress) {
352
+ const isDeployed = await this.isAccountDeployed(smartAccountAddress);
353
+ if (isDeployed) throw new Error("Account already deployed");
354
+ const initCode = this.buildInitCode(owner);
355
+ const callData = "0x";
356
+ const nonce = await this.getNonce(smartAccountAddress);
357
+ const partialOp = {
358
+ sender: smartAccountAddress,
359
+ nonce,
360
+ initCode,
361
+ callData,
362
+ paymasterAndData: this.chainConfig.paymasterAddress || "0x"
363
+ };
364
+ const gasEstimate = await this.bundlerClient.estimateGas(partialOp);
365
+ return {
366
+ ...partialOp,
367
+ callGasLimit: BigInt(gasEstimate.callGasLimit),
368
+ verificationGasLimit: BigInt(gasEstimate.verificationGasLimit),
369
+ preVerificationGas: BigInt(gasEstimate.preVerificationGas),
370
+ maxFeePerGas: BigInt(gasEstimate.maxFeePerGas),
371
+ maxPriorityFeePerGas: BigInt(gasEstimate.maxPriorityFeePerGas),
372
+ signature: "0x"
373
+ };
374
+ }
375
+ getUserOpHash(userOp) {
376
+ const packed = encodeAbiParameters(
377
+ [
378
+ { type: "address" },
379
+ { type: "uint256" },
380
+ { type: "bytes32" },
381
+ { type: "bytes32" },
382
+ { type: "uint256" },
383
+ { type: "uint256" },
384
+ { type: "uint256" },
385
+ { type: "uint256" },
386
+ { type: "uint256" },
387
+ { type: "bytes32" }
388
+ ],
389
+ [
390
+ userOp.sender,
391
+ userOp.nonce,
392
+ keccak256(userOp.initCode),
393
+ keccak256(userOp.callData),
394
+ userOp.callGasLimit,
395
+ userOp.verificationGasLimit,
396
+ userOp.preVerificationGas,
397
+ userOp.maxFeePerGas,
398
+ userOp.maxPriorityFeePerGas,
399
+ keccak256(userOp.paymasterAndData)
400
+ ]
401
+ );
402
+ const packedHash = keccak256(packed);
403
+ return keccak256(
404
+ encodeAbiParameters(
405
+ [{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
406
+ [packedHash, this.entryPointAddress, BigInt(this.chainConfig.chain.id)]
407
+ )
408
+ );
409
+ }
410
+ };
411
+
412
+ // src/AccountAbstraction.ts
413
+ var AccountAbstraction = class {
414
+ constructor(chainConfig) {
415
+ this.owner = null;
416
+ this.smartAccountAddress = null;
417
+ this.chainConfig = chainConfig;
418
+ if (!chainConfig.entryPointAddress) throw new Error("EntryPoint address required");
419
+ this.entryPointAddress = chainConfig.entryPointAddress;
420
+ if (!chainConfig.factoryAddress) throw new Error("Factory address required");
421
+ this.factoryAddress = chainConfig.factoryAddress;
422
+ const rpcUrl = chainConfig.rpcUrl || chainConfig.chain.rpcUrls.default.http[0];
423
+ this.publicClient = createPublicClient({
424
+ chain: chainConfig.chain,
425
+ transport: http(rpcUrl)
426
+ });
427
+ this.bundlerClient = new BundlerClient(chainConfig, this.entryPointAddress);
428
+ this.tokenService = new TokenService(chainConfig, this.publicClient);
429
+ this.userOpBuilder = new UserOpBuilder(chainConfig, this.bundlerClient, this.publicClient);
430
+ }
431
+ /**
432
+ * Connect to MetaMask and get the owner address
433
+ */
434
+ async connect() {
435
+ if (typeof window === "undefined" || !window.ethereum) {
436
+ throw new Error("MetaMask is not installed");
437
+ }
438
+ const accounts = await window.ethereum.request({
439
+ method: "eth_requestAccounts"
440
+ });
441
+ if (!accounts || accounts.length === 0) throw new Error("No accounts found");
442
+ const chainId = await window.ethereum.request({
443
+ method: "eth_chainId"
444
+ });
445
+ const targetChainId = this.chainConfig.chain.id;
446
+ if (parseInt(chainId, 16) !== targetChainId) {
447
+ try {
448
+ await window.ethereum.request({
449
+ method: "wallet_switchEthereumChain",
450
+ params: [{ chainId: "0x" + targetChainId.toString(16) }]
451
+ });
452
+ } catch (switchError) {
453
+ const error = switchError;
454
+ if (error.code === 4902) {
455
+ await window.ethereum.request({
456
+ method: "wallet_addEthereumChain",
457
+ params: [
458
+ {
459
+ chainId: "0x" + targetChainId.toString(16),
460
+ chainName: this.chainConfig.chain.name,
461
+ nativeCurrency: this.chainConfig.chain.nativeCurrency,
462
+ rpcUrls: [this.chainConfig.rpcUrl || this.chainConfig.chain.rpcUrls.default.http[0]],
463
+ blockExplorerUrls: this.chainConfig.chain.blockExplorers?.default?.url ? [this.chainConfig.chain.blockExplorers.default.url] : []
464
+ }
465
+ ]
466
+ });
467
+ } else {
468
+ throw switchError;
469
+ }
470
+ }
471
+ }
472
+ this.owner = accounts[0];
473
+ this.smartAccountAddress = await this.getSmartAccountAddress(this.owner);
474
+ return {
475
+ owner: this.owner,
476
+ smartAccount: this.smartAccountAddress
477
+ };
478
+ }
479
+ /**
480
+ * Get the Smart Account address for an owner
481
+ */
482
+ async getSmartAccountAddress(owner) {
483
+ const address = await this.publicClient.readContract({
484
+ address: this.factoryAddress,
485
+ abi: factoryAbi,
486
+ functionName: "getAccountAddress",
487
+ args: [owner, 0n]
488
+ });
489
+ return address;
490
+ }
491
+ /**
492
+ * Check if the Smart Account is deployed
493
+ */
494
+ async isAccountDeployed() {
495
+ if (!this.smartAccountAddress) throw new Error("Not connected");
496
+ return this.userOpBuilder.isAccountDeployed(this.smartAccountAddress);
497
+ }
498
+ // --- Token Methods (Delegated) ---
499
+ getTokenAddress(token) {
500
+ return this.tokenService.getTokenAddress(token);
501
+ }
502
+ async getUsdcBalance() {
503
+ if (!this.smartAccountAddress) throw new Error("Not connected");
504
+ return this.tokenService.getBalance("USDC", this.smartAccountAddress);
505
+ }
506
+ async getEoaUsdcBalance() {
507
+ if (!this.owner) throw new Error("Not connected");
508
+ return this.tokenService.getBalance("USDC", this.owner);
509
+ }
510
+ async getAllowance() {
511
+ if (!this.owner || !this.smartAccountAddress) throw new Error("Not connected");
512
+ return this.tokenService.getAllowance("USDC", this.owner, this.smartAccountAddress);
513
+ }
514
+ // --- Transactions ---
515
+ async deployAccount() {
516
+ if (!this.owner || !this.smartAccountAddress) throw new Error("Not connected");
517
+ try {
518
+ const userOp = await this.userOpBuilder.buildDeployUserOp(this.owner, this.smartAccountAddress);
519
+ const signed = await this.signUserOperation(userOp);
520
+ const hash = await this.sendUserOperation(signed);
521
+ return await this.waitForUserOperation(hash);
522
+ } catch (error) {
523
+ throw this.decodeError(error);
524
+ }
525
+ }
526
+ async sendTransaction(tx) {
527
+ return this.sendBatchTransaction([tx]);
528
+ }
529
+ async sendBatchTransaction(txs) {
530
+ if (!this.owner || !this.smartAccountAddress) throw new Error("Not connected");
531
+ const transactions = txs.map((tx) => ({
532
+ target: tx.target,
533
+ value: tx.value ?? 0n,
534
+ data: tx.data ?? "0x"
535
+ }));
536
+ try {
537
+ const userOp = await this.userOpBuilder.buildUserOperationBatch(
538
+ this.owner,
539
+ this.smartAccountAddress,
540
+ transactions
541
+ );
542
+ const signed = await this.signUserOperation(userOp);
543
+ const hash = await this.sendUserOperation(signed);
544
+ return await this.waitForUserOperation(hash);
545
+ } catch (error) {
546
+ throw this.decodeError(error);
547
+ }
548
+ }
549
+ async deposit(amount) {
550
+ if (!this.owner || !this.smartAccountAddress) throw new Error("Not connected");
551
+ const txHash = await window.ethereum.request({
552
+ method: "eth_sendTransaction",
553
+ params: [{
554
+ from: this.owner,
555
+ to: this.smartAccountAddress,
556
+ value: "0x" + amount.toString(16)
557
+ }]
558
+ });
559
+ return txHash;
560
+ }
561
+ async transfer(token, recipient, amount) {
562
+ const tokenAddress = this.getTokenAddress(token);
563
+ if (tokenAddress === "0x0000000000000000000000000000000000000000") {
564
+ return this.sendTransaction({
565
+ target: recipient,
566
+ value: amount,
567
+ data: "0x"
568
+ });
569
+ }
570
+ const data = this.tokenService.encodeTransfer(recipient, amount);
571
+ return this.sendTransaction({
572
+ target: tokenAddress,
573
+ value: 0n,
574
+ data
575
+ });
576
+ }
577
+ /**
578
+ * Approve a token for the Smart Account
579
+ */
580
+ async approveToken(token, spender, amount = 115792089237316195423570985008687907853269984665640564039457584007913129639935n) {
581
+ if (!this.owner) throw new Error("Not connected");
582
+ const support = await this.requestApprovalSupport(token, spender, amount);
583
+ if (support.type === "approve") {
584
+ const data = this.tokenService.encodeApprove(spender, amount);
585
+ const txHash = await window.ethereum.request({
586
+ method: "eth_sendTransaction",
587
+ params: [{
588
+ from: this.owner,
589
+ to: token,
590
+ data
591
+ }]
592
+ });
593
+ return txHash;
594
+ }
595
+ if (support.type === "permit") throw new Error("Permit not yet supported");
596
+ return "NOT_NEEDED";
597
+ }
598
+ // --- Core Bridge to Bundler/UserOp ---
599
+ // Deprecated/Legacy but kept for compatibility or advanced usage?
600
+ // buildUserOperationBatch moved to internal usage mostly, but maybe exposed?
601
+ // If I remove them from public API, that is a BREAKING change if user used them.
602
+ // User requested "modularize", but usually expects same public API.
603
+ // I will expose them as simple delegates if needed, or assume they primarily use sendBatchTransaction.
604
+ // The previous implementation exposed `buildUserOperationBatch`.
605
+ async buildUserOperationBatch(transactions) {
606
+ if (!this.owner || !this.smartAccountAddress) throw new Error("Not connected");
607
+ return this.userOpBuilder.buildUserOperationBatch(this.owner, this.smartAccountAddress, transactions);
608
+ }
609
+ async signUserOperation(userOp) {
610
+ if (!this.owner) throw new Error("Not connected");
611
+ const userOpHash = this.userOpBuilder.getUserOpHash(userOp);
612
+ const signature = await window.ethereum.request({
613
+ method: "personal_sign",
614
+ params: [userOpHash, this.owner]
615
+ });
616
+ return { ...userOp, signature };
617
+ }
618
+ async sendUserOperation(userOp) {
619
+ return this.bundlerClient.sendUserOperation(userOp);
620
+ }
621
+ async waitForUserOperation(hash, timeout = 6e4) {
622
+ return this.bundlerClient.waitForUserOperation(hash, timeout);
623
+ }
624
+ // Internal but exposed via BundlerClient originally
625
+ async requestApprovalSupport(token, spender, amount) {
626
+ if (!this.owner) throw new Error("Not connected");
627
+ return this.bundlerClient.requestApprovalSupport(token, this.owner, spender, amount);
628
+ }
629
+ // Error Decoding (Private)
630
+ decodeError(error) {
631
+ const msg = error?.message || "";
632
+ const hexMatch = msg.match(/(0x[0-9a-fA-F]+)/);
633
+ if (hexMatch) {
634
+ try {
635
+ const decoded = decodeErrorResult({
636
+ abi: [{ inputs: [{ name: "message", type: "string" }], name: "Error", type: "error" }],
637
+ data: hexMatch[0]
638
+ });
639
+ if (decoded.errorName === "Error") return new Error(`Smart Account Error: ${decoded.args[0]}`);
640
+ } catch (e) {
641
+ }
642
+ }
643
+ if (msg.includes("AA21")) return new Error("Smart Account: Native transfer failed (ETH missing?)");
644
+ if (msg.includes("AA25")) return new Error("Smart Account: Invalid account nonce");
645
+ return error instanceof Error ? error : new Error(String(error));
646
+ }
647
+ // Getters
648
+ getOwner() {
649
+ return this.owner;
650
+ }
651
+ getSmartAccount() {
652
+ return this.smartAccountAddress;
653
+ }
654
+ };
655
+
656
+ // src/chains.ts
657
+ import { base, baseSepolia } from "viem/chains";
658
+ var BASE_MAINNET = {
659
+ chain: base,
660
+ bundlerUrl: "http://localhost:3000/rpc?chain=base",
661
+ // Default to local bundler pattern
662
+ // Addresses
663
+ entryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
664
+ factoryAddress: "0xe2584152891E4769025807DEa0cD611F135aDC68",
665
+ paymasterAddress: "0x1e13Eb16C565E3f3FDe49A011755e50410bb1F95",
666
+ tokens: [
667
+ {
668
+ symbol: "USDC",
669
+ decimals: 6,
670
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
671
+ },
672
+ {
673
+ symbol: "ETH",
674
+ decimals: 18,
675
+ address: "0x0000000000000000000000000000000000000000"
676
+ }
677
+ ]
678
+ };
679
+ var BASE_SEPOLIA = {
680
+ chain: baseSepolia,
681
+ bundlerUrl: "http://localhost:3000/rpc?chain=baseSepolia",
682
+ // Default to local bundler pattern
683
+ // Addresses
684
+ entryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
685
+ factoryAddress: "0x9406Cc6185a346906296840746125a0E44976454",
686
+ // Paymaster not configured in deployments.ts for Sepolia?
687
+ tokens: [
688
+ {
689
+ symbol: "USDC",
690
+ decimals: 6,
691
+ address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
692
+ },
693
+ {
694
+ symbol: "ETH",
695
+ decimals: 18,
696
+ address: "0x0000000000000000000000000000000000000000"
697
+ }
698
+ ]
699
+ };
700
+ var CHAIN_CONFIGS = {
701
+ [base.id]: BASE_MAINNET,
702
+ [baseSepolia.id]: BASE_SEPOLIA
703
+ };
704
+ export {
705
+ AccountAbstraction,
706
+ BASE_MAINNET,
707
+ BASE_SEPOLIA,
708
+ BundlerClient,
709
+ CHAIN_CONFIGS,
710
+ entryPointAbi,
711
+ erc20Abi,
712
+ smartAccountAbi
713
+ };
714
+ //# sourceMappingURL=index.mjs.map