@@ -131,6 +131,7 @@ export async function createUnsignedUserOp(args: {
131
131
accountContract : ThirdwebContract ;
132
132
adminAddress : string ;
133
133
sponsorGas : boolean ;
134
+ waitForDeployment ?: boolean ;
134
135
overrides ?: SmartWalletOptions [ "overrides" ] ;
135
136
} ) : Promise < UserOperationV06 | UserOperationV07 > {
136
137
const {
@@ -140,6 +141,7 @@ export async function createUnsignedUserOp(args: {
140
141
adminAddress,
141
142
overrides,
142
143
sponsorGas,
144
+ waitForDeployment = true ,
143
145
} = args ;
144
146
const chain = executeTx . chain ;
145
147
const client = executeTx . client ;
@@ -154,23 +156,25 @@ export async function createUnsignedUserOp(args: {
154
156
args . overrides ?. entrypointAddress || ENTRYPOINT_ADDRESS_v0_6 ,
155
157
) ;
156
158
157
- const [ isDeployed , callData , gasFees , nonce ] = await Promise . all ( [
158
- isContractDeployed ( accountContract ) ,
159
- encode ( executeTx ) ,
160
- getGasFees ( {
161
- executeTx,
162
- bundlerOptions,
163
- chain,
164
- client,
165
- } ) ,
166
- getAccountNonce ( {
167
- accountContract,
168
- chain,
169
- client,
170
- entrypointAddress : overrides ?. entrypointAddress ,
171
- getNonceOverride : overrides ?. getAccountNonce ,
172
- } ) ,
173
- ] ) ;
159
+ const [ isDeployed , callData , callGasLimit , gasFees , nonce ] =
160
+ await Promise . all ( [
161
+ isContractDeployed ( accountContract ) ,
162
+ encode ( executeTx ) ,
163
+ resolvePromisedValue ( executeTx . gas ) ,
164
+ getGasFees ( {
165
+ executeTx,
166
+ bundlerOptions,
167
+ chain,
168
+ client,
169
+ } ) ,
170
+ getAccountNonce ( {
171
+ accountContract,
172
+ chain,
173
+ client,
174
+ entrypointAddress : overrides ?. entrypointAddress ,
175
+ getNonceOverride : overrides ?. getAccountNonce ,
176
+ } ) ,
177
+ ] ) ;
174
178
175
179
const { maxFeePerGas, maxPriorityFeePerGas } = gasFees ;
176
180
@@ -185,8 +189,10 @@ export async function createUnsignedUserOp(args: {
185
189
isDeployed,
186
190
nonce,
187
191
callData,
192
+ callGasLimit,
188
193
maxFeePerGas,
189
194
maxPriorityFeePerGas,
195
+ waitForDeployment,
190
196
} ) ;
191
197
}
192
198
@@ -201,8 +207,10 @@ export async function createUnsignedUserOp(args: {
201
207
isDeployed,
202
208
nonce,
203
209
callData,
210
+ callGasLimit,
204
211
maxFeePerGas,
205
212
maxPriorityFeePerGas,
213
+ waitForDeployment,
206
214
} ) ;
207
215
}
208
216
@@ -262,8 +270,10 @@ async function populateUserOp_v0_7(args: {
262
270
isDeployed : boolean ;
263
271
nonce : bigint ;
264
272
callData : Hex ;
273
+ callGasLimit ?: bigint ;
265
274
maxFeePerGas : bigint ;
266
275
maxPriorityFeePerGas : bigint ;
276
+ waitForDeployment : boolean ;
267
277
} ) : Promise < UserOperationV07 > {
268
278
const {
269
279
bundlerOptions,
@@ -275,17 +285,21 @@ async function populateUserOp_v0_7(args: {
275
285
overrides,
276
286
nonce,
277
287
callData,
288
+ callGasLimit,
278
289
maxFeePerGas,
279
290
maxPriorityFeePerGas,
291
+ waitForDeployment,
280
292
} = args ;
281
293
const { chain, client } = bundlerOptions ;
282
294
283
295
let factory : string | undefined ;
284
296
let factoryData : Hex ;
285
- // lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
286
297
if ( isDeployed || isAccountDeploying ( accountContract ) ) {
287
298
factoryData = "0x" ;
288
- await waitForAccountDeployed ( accountContract ) ;
299
+ if ( waitForDeployment ) {
300
+ // lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
301
+ await waitForAccountDeployed ( accountContract ) ;
302
+ }
289
303
} else {
290
304
factory = factoryContract . address ;
291
305
factoryData = await encode (
@@ -305,7 +319,7 @@ async function populateUserOp_v0_7(args: {
305
319
callData,
306
320
maxFeePerGas,
307
321
maxPriorityFeePerGas,
308
- callGasLimit : 0n ,
322
+ callGasLimit : callGasLimit ?? 0n ,
309
323
verificationGasLimit : 0n ,
310
324
preVerificationGas : 0n ,
311
325
factory,
@@ -399,8 +413,10 @@ async function populateUserOp_v0_6(args: {
399
413
isDeployed : boolean ;
400
414
nonce : bigint ;
401
415
callData : Hex ;
416
+ callGasLimit ?: bigint ;
402
417
maxFeePerGas : bigint ;
403
418
maxPriorityFeePerGas : bigint ;
419
+ waitForDeployment : boolean ;
404
420
} ) : Promise < UserOperationV06 > {
405
421
const {
406
422
bundlerOptions,
@@ -412,16 +428,20 @@ async function populateUserOp_v0_6(args: {
412
428
overrides,
413
429
nonce,
414
430
callData,
431
+ callGasLimit,
415
432
maxFeePerGas,
416
433
maxPriorityFeePerGas,
434
+ waitForDeployment,
417
435
} = args ;
418
436
const { chain, client } = bundlerOptions ;
419
437
let initCode : Hex ;
420
438
421
- // lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
422
439
if ( isDeployed || isAccountDeploying ( accountContract ) ) {
423
440
initCode = "0x" ;
424
- await waitForAccountDeployed ( accountContract ) ;
441
+ if ( waitForDeployment ) {
442
+ // lock until account is deployed if needed to avoid 'sender already created' errors when sending multiple transactions in parallel
443
+ await waitForAccountDeployed ( accountContract ) ;
444
+ }
425
445
} else {
426
446
initCode = await getAccountInitCode ( {
427
447
factoryContract : factoryContract ,
@@ -439,7 +459,7 @@ async function populateUserOp_v0_6(args: {
439
459
callData,
440
460
maxFeePerGas,
441
461
maxPriorityFeePerGas,
442
- callGasLimit : 0n ,
462
+ callGasLimit : callGasLimit ?? 0n ,
443
463
verificationGasLimit : 0n ,
444
464
preVerificationGas : 0n ,
445
465
paymasterAndData : "0x" ,
@@ -651,6 +671,7 @@ export async function createAndSignUserOp(options: {
651
671
adminAccount : Account ;
652
672
client : ThirdwebClient ;
653
673
smartWalletOptions : SmartWalletOptions ;
674
+ waitForDeployment ?: boolean ;
654
675
} ) {
655
676
const config = options . smartWalletOptions ;
656
677
const factoryContract = getContract ( {
@@ -708,6 +729,7 @@ export async function createAndSignUserOp(options: {
708
729
adminAddress : options . adminAccount . address ,
709
730
sponsorGas : "sponsorGas" in config ? config . sponsorGas : config . gasless ,
710
731
overrides : config . overrides ,
732
+ waitForDeployment : options . waitForDeployment ,
711
733
} ) ;
712
734
const signedUserOp = await signUserOp ( {
713
735
client : options . client ,
@@ -723,6 +745,7 @@ async function waitForAccountDeployed(accountContract: ThirdwebContract) {
723
745
const startTime = Date . now ( ) ;
724
746
while ( isAccountDeploying ( accountContract ) ) {
725
747
if ( Date . now ( ) - startTime > 60000 ) {
748
+ clearAccountDeploying ( accountContract ) ; // clear the flag so it doesnt stay stuck in this state
726
749
throw new Error (
727
750
"Account deployment is taking too long (over 1 minute). Please try again." ,
728
751
) ;
0 commit comments