@@ -93,22 +93,39 @@ export default class BatchLiquidator
9393 `processing batch of ${ batch . length } for ${ batch [ 0 ] ?. creditManager } : ${ batch . map ( ca => ca . creditAccount ) } ` ,
9494 ) ;
9595 const snapshotId = await this . client . anvil . snapshot ( ) ;
96- const { results, receipt } = await this . #liquidateBatch(
97- batch ,
98- i ,
99- batches . length ,
100- ) ;
101- const hasErrors = results . some ( r => ! ! r . isError ) ;
102- let traceId : string | undefined ;
103- if ( hasErrors && ! ! receipt ) {
104- traceId = await this . errorHandler . saveTransactionTrace (
105- receipt . transactionHash ,
96+ try {
97+ const { results, receipt } = await this . #liquidateBatch(
98+ batch ,
99+ i ,
100+ batches . length ,
106101 ) ;
102+ const hasErrors = results . some ( r => ! ! r . isError ) ;
103+ let traceId : string | undefined ;
104+ if ( hasErrors && ! ! receipt ) {
105+ traceId = await this . errorHandler . saveTransactionTrace (
106+ receipt . transactionHash ,
107+ ) ;
108+ }
109+ for ( const r of results ) {
110+ this . optimistic . push ( { ...r , traceFile : traceId } ) ;
111+ }
112+ } catch ( e ) {
113+ const decoded = await this . errorHandler . explain ( e ) ;
114+ this . logger . error ( decoded , "cant liquidate" ) ;
115+ for ( const a of batch ) {
116+ this . optimistic . push ( {
117+ ...this . newOptimisticResult ( a ) ,
118+ isError : true ,
119+ error : `cannot liquidate: ${ decoded . longMessage } ` . replaceAll (
120+ "\n" ,
121+ "\\n" ,
122+ ) ,
123+ traceFile : decoded . traceFile ,
124+ } ) ;
125+ }
126+ } finally {
127+ await this . client . anvil . revert ( { id : snapshotId } ) ;
107128 }
108- for ( const r of results ) {
109- this . optimistic . push ( { ...r , traceFile : traceId } ) ;
110- }
111- await this . client . anvil . revert ( { id : snapshotId } ) ;
112129 }
113130 const success = this . optimistic . get ( ) . filter ( r => ! r . isError ) . length ;
114131 this . logger . info (
0 commit comments