@@ -27,6 +27,7 @@ import {
27
27
import { AccountAPI } from "./lib/account" ;
28
28
import { AddressZero } from "@account-abstraction/utils" ;
29
29
import { TransactionDetailsForUserOp } from "./lib/transaction-details" ;
30
+ import { BatchData } from "./lib/base-api" ;
30
31
31
32
export class SmartWalletConnector extends Connector < SmartWalletConnectionArgs > {
32
33
protected config : SmartWalletConfig ;
@@ -203,14 +204,14 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
203
204
throw new Error ( "Personal wallet not connected" ) ;
204
205
}
205
206
const signer = await this . getSigner ( ) ;
206
- const batchData = await this . prepareBatchTx ( transactions ) ;
207
+ const { tx , batchData } = await this . prepareBatchTx ( transactions ) ;
207
208
return await signer . sendTransaction (
208
209
{
209
210
to : await signer . getAddress ( ) ,
210
- data : batchData . encode ( ) ,
211
+ data : tx . encode ( ) ,
211
212
value : 0 ,
212
213
} ,
213
- true , // batched tx flag
214
+ batchData ,
214
215
) ;
215
216
}
216
217
@@ -258,14 +259,14 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
258
259
throw new Error ( "Personal wallet not connected" ) ;
259
260
}
260
261
const signer = await this . getSigner ( ) ;
261
- const batchData = await this . prepareBatchRaw ( transactions ) ;
262
+ const batch = await this . prepareBatchRaw ( transactions ) ;
262
263
return signer . sendTransaction (
263
264
{
264
265
to : await signer . getAddress ( ) ,
265
- data : batchData . encode ( ) ,
266
+ data : batch . tx . encode ( ) ,
266
267
value : 0 ,
267
268
} ,
268
- true , // batched tx flag
269
+ batch . batchData , // batched tx flag
269
270
) ;
270
271
}
271
272
@@ -285,15 +286,11 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
285
286
if ( ! this . accountApi ) {
286
287
throw new Error ( "Personal wallet not connected" ) ;
287
288
}
288
- console . log ( "single" , transaction . getTarget ( ) , transaction . encode ( ) . length ) ;
289
- return this . estimateTx (
290
- {
291
- target : transaction . getTarget ( ) ,
292
- data : transaction . encode ( ) ,
293
- value : await transaction . getValue ( ) ,
294
- } ,
295
- false ,
296
- ) ;
289
+ return this . estimateTx ( {
290
+ target : transaction . getTarget ( ) ,
291
+ data : transaction . encode ( ) ,
292
+ value : await transaction . getValue ( ) ,
293
+ } ) ;
297
294
}
298
295
299
296
async estimateRaw (
@@ -303,29 +300,25 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
303
300
throw new Error ( "Personal wallet not connected" ) ;
304
301
}
305
302
const tx = await ethers . utils . resolveProperties ( transaction ) ;
306
- return this . estimateTx (
307
- {
308
- target : tx . to || AddressZero ,
309
- data : tx . data ?. toString ( ) || "" ,
310
- value : tx . value || BigNumber . from ( 0 ) ,
311
- } ,
312
- false ,
313
- ) ;
303
+ return this . estimateTx ( {
304
+ target : tx . to || AddressZero ,
305
+ data : tx . data ?. toString ( ) || "" ,
306
+ value : tx . value || BigNumber . from ( 0 ) ,
307
+ } ) ;
314
308
}
315
309
316
310
async estimateBatch ( transactions : Transaction < any > [ ] ) {
317
311
if ( ! this . accountApi ) {
318
312
throw new Error ( "Personal wallet not connected" ) ;
319
313
}
320
- const batch = await this . prepareBatchTx ( transactions ) ;
321
- console . log ( "batch" , batch . getTarget ( ) , batch . encode ( ) . length ) ;
314
+ const { tx, batchData } = await this . prepareBatchTx ( transactions ) ;
322
315
return this . estimateTx (
323
316
{
324
- target : batch . getTarget ( ) ,
325
- data : batch . encode ( ) ,
326
- value : await batch . getValue ( ) ,
317
+ target : tx . getTarget ( ) ,
318
+ data : tx . encode ( ) ,
319
+ value : await tx . getValue ( ) ,
327
320
} ,
328
- true ,
321
+ batchData ,
329
322
) ;
330
323
}
331
324
@@ -335,14 +328,14 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
335
328
if ( ! this . accountApi ) {
336
329
throw new Error ( "Personal wallet not connected" ) ;
337
330
}
338
- const batch = await this . prepareBatchRaw ( transactions ) ;
331
+ const { tx , batchData } = await this . prepareBatchRaw ( transactions ) ;
339
332
return this . estimateTx (
340
333
{
341
- target : batch . getTarget ( ) ,
342
- data : batch . encode ( ) ,
343
- value : await batch . getValue ( ) ,
334
+ target : tx . getTarget ( ) ,
335
+ data : tx . encode ( ) ,
336
+ value : await tx . getValue ( ) ,
344
337
} ,
345
- true ,
338
+ batchData ,
346
339
) ;
347
340
}
348
341
@@ -357,16 +350,16 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
357
350
if ( ! this . accountApi ) {
358
351
throw new Error ( "Personal wallet not connected" ) ;
359
352
}
360
- if ( await this . accountApi . isAcountDeployed ( ) ) {
361
- throw new Error ( "Smart wallet already deployed" ) ;
362
- }
363
353
const signer = await this . getSigner ( ) ;
364
354
const tx = await signer . sendTransaction (
365
355
{
366
356
to : await signer . getAddress ( ) ,
367
357
data : "0x" ,
368
358
} ,
369
- true , // batched tx flag to avoid hitting the Router fallback method
359
+ {
360
+ targets : [ ] ,
361
+ data : [ ] ,
362
+ } , // batched tx flag to avoid hitting the Router fallback method
370
363
) ;
371
364
const receipt = await tx . wait ( ) ;
372
365
return { receipt } ;
@@ -533,7 +526,10 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
533
526
534
527
/// PRIVATE METHODS
535
528
536
- private async estimateTx ( tx : TransactionDetailsForUserOp , batched : boolean ) {
529
+ private async estimateTx (
530
+ tx : TransactionDetailsForUserOp ,
531
+ batchData ?: BatchData ,
532
+ ) {
537
533
if ( ! this . accountApi ) {
538
534
throw new Error ( "Personal wallet not connected" ) ;
539
535
}
@@ -547,7 +543,7 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
547
543
}
548
544
const [ { callGasLimit : transactionGasLimit } , gasPrice ] = await Promise . all (
549
545
[
550
- await this . accountApi . encodeUserOpCallDataAndGasLimit ( tx , batched ) ,
546
+ this . accountApi . encodeUserOpCallDataAndGasLimit ( tx , batchData ) ,
551
547
getGasPrice ( provider ) ,
552
548
] ,
553
549
) ;
@@ -595,7 +591,13 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
595
591
const targets = resolvedTxs . map ( ( tx ) => tx . to || AddressZero ) ;
596
592
const data = resolvedTxs . map ( ( tx ) => tx . data || "0x" ) ;
597
593
const values = resolvedTxs . map ( ( tx ) => tx . value || BigNumber . from ( 0 ) ) ;
598
- return this . accountApi . prepareExecuteBatch ( targets , values , data ) ;
594
+ return {
595
+ tx : await this . accountApi . prepareExecuteBatch ( targets , values , data ) ,
596
+ batchData : {
597
+ targets,
598
+ data,
599
+ } ,
600
+ } ;
599
601
}
600
602
601
603
private async prepareBatchTx ( transactions : Transaction < any > [ ] ) {
@@ -605,6 +607,12 @@ export class SmartWalletConnector extends Connector<SmartWalletConnectionArgs> {
605
607
const targets = transactions . map ( ( tx ) => tx . getTarget ( ) ) ;
606
608
const data = transactions . map ( ( tx ) => tx . encode ( ) ) ;
607
609
const values = await Promise . all ( transactions . map ( ( tx ) => tx . getValue ( ) ) ) ;
608
- return this . accountApi . prepareExecuteBatch ( targets , values , data ) ;
610
+ return {
611
+ tx : await this . accountApi . prepareExecuteBatch ( targets , values , data ) ,
612
+ batchData : {
613
+ targets,
614
+ data,
615
+ } ,
616
+ } ;
609
617
}
610
618
}
0 commit comments