Skip to content

Commit fa3ed8c

Browse files
committed
fix: batch liquidator in optimistic mode
1 parent 873c4c6 commit fa3ed8c

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

src/services/liquidate/BatchLiquidator.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,40 @@ export default class BatchLiquidator
8484
`processing batch of ${batch.length} for ${batch[0]?.cmName}: ${batch.map(ca => ca.addr)}`,
8585
);
8686
const snapshotId = await this.client.anvil.snapshot();
87-
const { results, receipt } = await this.#liquidateBatch(
88-
batch,
89-
cms,
90-
i,
91-
batches.length,
92-
);
93-
const hasErrors = results.some(r => !!r.isError);
94-
let traceId: string | undefined;
95-
if (hasErrors && !!receipt) {
96-
traceId = await this.errorHandler.saveTransactionTrace(
97-
receipt.transactionHash,
87+
try {
88+
const { results, receipt } = await this.#liquidateBatch(
89+
batch,
90+
cms,
91+
i,
92+
batches.length,
9893
);
94+
const hasErrors = results.some(r => !!r.isError);
95+
let traceId: string | undefined;
96+
if (hasErrors && !!receipt) {
97+
traceId = await this.errorHandler.saveTransactionTrace(
98+
receipt.transactionHash,
99+
);
100+
}
101+
for (const r of results) {
102+
this.optimistic.push({ ...r, traceFile: traceId });
103+
}
104+
} catch (e) {
105+
const decoded = await this.errorHandler.explain(e);
106+
this.logger.error(decoded, "cant liquidate");
107+
for (const a of batch) {
108+
this.optimistic.push({
109+
...this.newOptimisticResult(a),
110+
isError: true,
111+
error: `cannot liquidate: ${decoded.longMessage}`.replaceAll(
112+
"\n",
113+
"\\n",
114+
),
115+
traceFile: decoded.traceFile,
116+
});
117+
}
118+
} finally {
119+
await this.client.anvil.revert({ id: snapshotId });
99120
}
100-
for (const r of results) {
101-
this.optimistic.push({ ...r, traceFile: traceId });
102-
}
103-
await this.client.anvil.revert({ id: snapshotId });
104121
}
105122
const success = this.optimistic.get().filter(r => !r.isError).length;
106123
this.logger.info(

0 commit comments

Comments
 (0)