Skip to content

Commit

Permalink
fix: changes how batches are sorted and sliced
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Aug 9, 2024
1 parent 8681322 commit ca17315
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/services/liquidate/BatchLiquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,34 @@ export default class BatchLiquidator
}

#sliceBatches(accounts: CreditAccountData[]): CreditAccountData[][] {
const batches: CreditAccountData[][] = [];
const byCM: Record<string, CreditAccountData[]> = {};

for (const account of accounts) {
if (!byCM[account.creditManager]) {
byCM[account.creditManager] = [];
// sort by healthFactor bin ASC, debt DESC
const sortedAccounts = accounts.sort((a, b) => {
if (a.healthFactor !== b.healthFactor) {
return healthFactorBin(a) - healthFactorBin(b);
}
byCM[account.creditManager].push(account);
}

// eslint-disable-next-line guard-for-in
for (const cm in byCM) {
const cmAccs = byCM[cm];
for (let i = 0; i < cmAccs.length; i += this.config.batchSize) {
batches.push(cmAccs.slice(i, i + this.config.batchSize));
if (b.totalDebtUSD > a.totalDebtUSD) {
return 1;
} else if (b.totalDebtUSD === a.totalDebtUSD) {
return 0;
} else {
return -1;
}
}
});

const batches: CreditAccountData[][] = [];
for (let i = 0; i < sortedAccounts.length; i += this.config.batchSize) {
batches.push(sortedAccounts.slice(i, i + this.config.batchSize));
}
return batches;
}
}

function healthFactorBin({ healthFactor }: CreditAccountData): number {
if (healthFactor < 9300) {
return 0;
} else if (healthFactor < 9600) {
return 1;
} else {
return 2;
}
}

0 comments on commit ca17315

Please sign in to comment.