Skip to content

Commit 86fa37f

Browse files
committed
feat: configurable debt policy
1 parent 7c1f223 commit 86fa37f

File tree

4 files changed

+287
-260
lines changed

4 files changed

+287
-260
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"pino-pretty": "^13.1.3"
2222
},
2323
"devDependencies": {
24-
"@aws-sdk/client-s3": "^3.956.0",
24+
"@aws-sdk/client-s3": "^3.957.0",
2525
"@biomejs/biome": "^2.3.10",
2626
"@commander-js/extra-typings": "^14.0.0",
2727
"@commitlint/cli": "^20.2.0",

src/config/full-liquidator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ export const FullLiquidatorSchema = z.object({
1212
description: "Liquidator mode (full/partial/batch/deleverage)",
1313
env: "LIQUIDATION_MODE",
1414
}),
15+
/**
16+
* Debt policy
17+
* full - liquidate fully
18+
* debt-only - try to liquidate only debt
19+
* debt-expired - try to liquidate only debt for expired accounts
20+
*/
21+
debtPolicy: z
22+
.enum(["full", "debt-only", "debt-expired"])
23+
.default("full")
24+
.register(zommandRegistry, {
25+
flags: "--debt-policy <policy>",
26+
description: "Liquidate fully/debt only/debt only for expired accounts",
27+
env: "DEBT_POLICY",
28+
}),
1529
/**
1630
* Whether we should apply loss policy on full liquidation of accounts with bad debt
1731
*/

src/services/liquidate/LiquidationStrategyFull.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export default class LiquidationStrategyFull
169169
const isV310 = this.checkAccountVersion(ca, VERSION_RANGE_310);
170170
const ignoreReservePrices = !this.config.updateReservePrices && isV310;
171171
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
172+
const debtOnly =
173+
this.config.debtPolicy === "debt-only" ||
174+
(this.config.debtPolicy === "debt-expired" && cm.isExpired);
172175
const { tx, routerCloseResult, calls } =
173176
await this.creditAccountService.fullyLiquidate({
174177
account: ca,
@@ -177,8 +180,7 @@ export default class LiquidationStrategyFull
177180
keepAssets: this.config.keepAssets,
178181
ignoreReservePrices,
179182
applyLossPolicy: this.#applyLossPolicy,
180-
// TODO: try to liquidate with debt only, then normally as a fallback
181-
debtOnly: cm.isExpired,
183+
debtOnly,
182184
});
183185
return { ...routerCloseResult, calls, rawTx: tx };
184186
} catch (e) {

0 commit comments

Comments
 (0)