@@ -246,15 +246,11 @@ const _sendUserOp = async (
246246 waitForDeployment : false ,
247247 } ) ) as UserOperation ; // TODO support entrypoint v0.7 accounts
248248 } catch ( e ) {
249- const erroredTransaction : ErroredTransaction = {
249+ return {
250250 ...queuedTransaction ,
251251 status : "errored" ,
252- errorMessage : prettifyError ( e ) ,
253- } ;
254- job . log (
255- `Failed to populate transaction: ${ erroredTransaction . errorMessage } ` ,
256- ) ;
257- return erroredTransaction ;
252+ errorMessage : prettifyError ( e , "Bundler" ) ,
253+ } satisfies ErroredTransaction ;
258254 }
259255
260256 job . log ( `Populated userOp: ${ stringify ( signedUserOp ) } ` ) ;
@@ -327,15 +323,11 @@ const _sendTransaction = async (
327323 } ,
328324 } ) ;
329325 } catch ( e : unknown ) {
330- const erroredTransaction : ErroredTransaction = {
326+ return {
331327 ...queuedTransaction ,
332328 status : "errored" ,
333- errorMessage : prettifyError ( e ) ,
334- } ;
335- job . log (
336- `Failed to populate transaction: ${ erroredTransaction . errorMessage } ` ,
337- ) ;
338- return erroredTransaction ;
329+ errorMessage : prettifyError ( e , "RPC" ) ,
330+ } satisfies ErroredTransaction ;
339331 }
340332
341333 // Handle if `maxFeePerGas` is overridden.
@@ -371,10 +363,10 @@ const _sendTransaction = async (
371363 const sendTransactionResult =
372364 await account . sendTransaction ( populatedTransaction ) ;
373365 transactionHash = sendTransactionResult . transactionHash ;
374- } catch ( error : unknown ) {
366+ } catch ( e : unknown ) {
375367 // If the nonce is already seen onchain (nonce too low) or in mempool (replacement underpriced),
376368 // correct the DB nonce.
377- if ( isNonceAlreadyUsedError ( error ) || isReplacementGasFeeTooLow ( error ) ) {
369+ if ( isNonceAlreadyUsedError ( e ) || isReplacementGasFeeTooLow ( e ) ) {
378370 const result = await syncLatestNonceFromOnchainIfHigher ( chainId , from ) ;
379371 job . log ( `Re-synced nonce: ${ result } ` ) ;
380372 } else {
@@ -383,18 +375,26 @@ const _sendTransaction = async (
383375 await recycleNonce ( chainId , from , nonce ) ;
384376 }
385377
386- // Prettify "out of funds" error .
387- if ( isInsufficientFundsError ( error ) ) {
378+ // Do not retry errors that are expected to be rejected by RPC again .
379+ if ( isInsufficientFundsError ( e ) ) {
388380 const gasPrice =
389381 populatedTransaction . gasPrice ?? populatedTransaction . maxFeePerGas ;
382+
383+ let errorMessage = prettifyError ( e , "RPC" ) ;
390384 if ( gasPrice ) {
391- const chainMetadata = await getChainMetadata ( chain ) ;
392- const minGasTokens = toTokens ( populatedTransaction . gas * gasPrice , 18 ) ;
393- throw `Insufficient funds in ${ account . address } on ${ chainMetadata . name } . Transaction requires ${ minGasTokens } ${ chainMetadata . nativeCurrency . symbol } .` ;
385+ const { gas, value = 0n } = populatedTransaction ;
386+ const { name, nativeCurrency } = await getChainMetadata ( chain ) ;
387+ const minGasTokens = toTokens ( gas * gasPrice + value , 18 ) ;
388+ errorMessage = `Insufficient funds in ${ account . address } on ${ name } . Transaction requires > ${ minGasTokens } ${ nativeCurrency . symbol } .` ;
394389 }
390+ return {
391+ ...queuedTransaction ,
392+ status : "errored" ,
393+ errorMessage,
394+ } satisfies ErroredTransaction ;
395395 }
396396
397- throw error ;
397+ throw prettifyError ( e , "RPC" ) ;
398398 }
399399
400400 await addSentNonce ( chainId , from , nonce ) ;
0 commit comments