Skip to content

Commit 00bf330

Browse files
committed
fix: correctly get state after strategy
1 parent c34a700 commit 00bf330

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/services/liquidate/SingularLiquidator.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import {
33
filterDustUSD,
44
type MultiCall,
55
} from "@gearbox-protocol/sdk";
6-
import type {
7-
OptimisticResult,
8-
PartialLiquidationCondition,
9-
} from "@gearbox-protocol/types/optimist";
6+
import type { OptimisticResult } from "@gearbox-protocol/types/optimist";
107
import type { Hex, TransactionReceipt } from "viem";
118
import type {
129
CommonSchema,
@@ -32,7 +29,10 @@ import type {
3229
type OptimisticStrategyResult = {
3330
preview?: LiquidationPreview;
3431
receipt?: TransactionReceipt;
35-
} & ({ success: true } | { success: false; error: Error });
32+
} & (
33+
| { success: true; state: CreditAccountData }
34+
| { success: false; error: Error }
35+
);
3636

3737
export default class SingularLiquidator
3838
extends AbstractLiquidator<CommonSchema>
@@ -234,14 +234,14 @@ export default class SingularLiquidator
234234
result.callsHuman = this.creditAccountService.sdk.parseMultiCall([
235235
...(strategyResult.preview?.calls ?? []),
236236
]);
237-
const ca = await this.creditAccountService.getCreditAccountData(
238-
acc.creditAccount,
239-
);
240-
if (!ca) {
241-
throw new Error(`account ${acc.creditAccount} not found`);
237+
238+
if (strategyResult.success) {
239+
result.balancesAfter = filterDustUSD({
240+
account: strategyResult.state,
241+
sdk: this.sdk,
242+
});
243+
result.hfAfter = strategyResult.state.healthFactor;
242244
}
243-
result.balancesAfter = filterDustUSD({ account: ca, sdk: this.sdk });
244-
result.hfAfter = ca.healthFactor;
245245
result.gasUsed = strategyResult.receipt?.gasUsed ?? 0n;
246246
result.isError = !strategyResult.success;
247247

@@ -291,7 +291,7 @@ export default class SingularLiquidator
291291
): Promise<OptimisticStrategyResult> {
292292
let snapshotId = snapshotId_;
293293
const logger = this.logger.child({ strategy: strategy.name });
294-
let result: OptimisticStrategyResult = { success: true };
294+
let result: OptimisticStrategyResult = { success: true, state: acc };
295295
try {
296296
logger.debug({ snapshotId, strategy: strategy.name }, "previewing...");
297297
result.preview = await strategy.preview(acc);
@@ -313,6 +313,15 @@ export default class SingularLiquidator
313313
if (result.receipt.status !== "success") {
314314
throw new TransactionRevertedError(result.receipt);
315315
}
316+
const ca = await this.creditAccountService.getCreditAccountData(
317+
acc.creditAccount,
318+
);
319+
if (!ca) {
320+
throw new Error(
321+
`account ${acc.creditAccount} not found after liquidation`,
322+
);
323+
}
324+
result.state = ca;
316325
} catch (e) {
317326
logger.error(e, "strategy failed");
318327
result = { ...result, success: false, error: e as Error };

0 commit comments

Comments
 (0)