@@ -3,7 +3,7 @@ import * as zksync from 'zksync-ethers';
33import * as ethers from 'ethers' ;
44import * as hre from 'hardhat' ;
55import { ZkSyncArtifact } from '@matterlabs/hardhat-zksync-solc/dist/src/types' ;
6- import { TimeoutError } from 'ethers/src.ts/utils/errors ' ;
6+ import { TransactionReceipt } from 'ethers' ;
77
88export const SYSTEM_CONTEXT_ADDRESS = '0x000000000000000000000000000000000000800b' ;
99
@@ -75,7 +75,7 @@ export async function waitForNewL1Batch(wallet: zksync.Wallet): Promise<zksync.t
7575 const MAX_ATTEMPTS = 3 ;
7676
7777 let txResponse = null ;
78- let txReceipt = null ;
78+ let txReceipt : TransactionReceipt | null = null ;
7979 let nonce = Number ( await wallet . getNonce ( ) ) ;
8080 for ( let i = 0 ; i < MAX_ATTEMPTS ; i ++ ) {
8181 // Send a dummy transaction and wait for it to execute. We override `maxFeePerGas` as the default ethers behavior
@@ -91,12 +91,25 @@ export async function waitForNewL1Batch(wallet: zksync.Wallet): Promise<zksync.t
9191 } else {
9292 console . log ( 'Gas price has not gone up, waiting longer' ) ;
9393 }
94- txReceipt = await wallet . provider . waitForTransaction ( txResponse . hash , 1 , 3000 ) . catch ( ( _ : TimeoutError ) => null ) ;
94+ txReceipt = await wallet . provider . waitForTransaction ( txResponse . hash , 1 , 3000 ) . catch ( ( e ) => {
95+ if ( ethers . isError ( e , 'TIMEOUT' ) ) {
96+ console . log ( `Transaction timed out, potentially gas price went up (attempt ${ i + 1 } /${ MAX_ATTEMPTS } )` ) ;
97+ return null ;
98+ } else if (
99+ ethers . isError ( e , 'UNKNOWN_ERROR' ) &&
100+ e . message . match ( / N o t e n o u g h g a s f o r t r a n s a c t i o n v a l i d a t i o n / )
101+ ) {
102+ console . log (
103+ `Transaction did not have enough gas, likely gas price went up (attempt ${ i + 1 } /${ MAX_ATTEMPTS } )`
104+ ) ;
105+ return null ;
106+ } else {
107+ return Promise . reject ( e ) ;
108+ }
109+ } ) ;
95110 if ( txReceipt ) {
96111 // Transaction got executed, so we can safely assume it will be sealed in the next batch
97112 break ;
98- } else {
99- console . log ( `Transaction timed out (attempt ${ i + 1 } /${ MAX_ATTEMPTS } )` ) ;
100113 }
101114 }
102115 if ( ! txReceipt ) {
0 commit comments