Skip to content

Commit

Permalink
fix: add batch id to output
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Aug 8, 2024
1 parent 6b42a29 commit bd4b196
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@gearbox-protocol/liquidator-v2-contracts": "^2.1.0-next.18",
"@gearbox-protocol/prettier-config": "2.0.0-next.0",
"@gearbox-protocol/sdk-gov": "^2.14.1",
"@gearbox-protocol/types": "^1.10.2",
"@gearbox-protocol/types": "^1.11.0",
"@redstone-finance/evm-connector": "^0.6.1",
"@types/node": "^22.1.0",
"@uniswap/sdk-core": "^5.3.1",
Expand Down
23 changes: 19 additions & 4 deletions src/services/liquidate/BatchLiquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ export default class BatchLiquidator
const cms = await this.getCreditManagersV3List();
const batches = this.#sliceBatches(accounts);

for (const batch of batches) {
for (let i = 0; i < batches.length; i++) {
const batch = batches[i];
this.logger.debug(
`processing batch of ${batch.length} for ${batch[0]?.cmName}: ${batch.map(ca => ca.addr)}`,
);
try {
const { receipt, results } = await this.#liquidateBatch(batch, cms);
const { receipt, results } = await this.#liquidateBatch(
batch,
cms,
i,
batches.length,
);
this.notifier.notify(
new BatchLiquidationFinishedMessage(receipt, results),
);
Expand All @@ -72,11 +78,17 @@ export default class BatchLiquidator
const total = accounts.length;
this.logger.info(`optimistic batch-liquidation for ${total} accounts`);
const batches = this.#sliceBatches(accounts);
for (const batch of batches) {
for (let i = 0; i < batches.length; i++) {
const batch = batches[i];
this.logger.debug(
`processing batch of ${batch.length} for ${batch[0]?.cmName}: ${batch.map(ca => ca.addr)}`,
);
const { results } = await this.#liquidateBatch(batch, cms);
const { results } = await this.#liquidateBatch(
batch,
cms,
i,
batches.length,
);
for (const r of results) {
this.optimistic.push(r);
}
Expand All @@ -90,6 +102,8 @@ export default class BatchLiquidator
async #liquidateBatch(
accounts: CreditAccountData[],
cms: CreditManagerData[],
index: number,
total: number,
): Promise<BatchLiquidationOutput> {
const inputs: EstimateBatchInput[] = [];
for (const ca of accounts) {
Expand Down Expand Up @@ -207,6 +221,7 @@ export default class BatchLiquidator
liquidatorProfit: "0", // cannot compute for single account
isError: !liquidated.has(a.addr),
error: getError(a),
batchId: `${index + 1}/${total}`,
}),
);
return {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,10 @@
humanize-duration-ts "^2.1.1"
zod "^3.22.2"

"@gearbox-protocol/types@^1.10.2":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@gearbox-protocol/types/-/types-1.10.2.tgz#98098a9c837fa91caf11093a9002505eda644dd3"
integrity sha512-1Nn78pHfsbo+z4VpuLGDeBu4GcfjHZbHlkMFJigGsiBbATBnZE9XnYaNUFFWXqs/PK+vce3yrnetOn6LDu1/wA==
"@gearbox-protocol/types@^1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@gearbox-protocol/types/-/types-1.11.0.tgz#0d4192f7fb70b994822a6dde95a091fb69ce581e"
integrity sha512-f5FI99X8nxC05l3HzGjahTWs4P3/sAvwWrX+V4c3U63dCk56nBNlyLMHs6dGGj/QiXFIxpE40v7p4LaRkPVXMQ==

"@humanwhocodes/config-array@^0.11.14":
version "0.11.14"
Expand Down

0 comments on commit bd4b196

Please sign in to comment.