Skip to content

Commit

Permalink
fix: update partial liquidation case
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Dec 5, 2024
1 parent e54b5c5 commit d64d0a8
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/services/scanner/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,13 @@ export class Scanner {

async #getAccountsFromManagers(
cms: Address[],
{ liquidatableOnly, priceUpdates, blockNumber }: AccountSelection,
selection: AccountSelection,
): Promise<CreditAccountDataRaw[]> {
const { liquidatableOnly, blockNumber } = selection;
const all = await Promise.all(
cms.map(cm =>
this.dataCompressor.simulate.getCreditAccountsByCreditManager(
[cm, priceUpdates],
{ blockNumber },
),
),
cms.map(cm => this.#getAccountsFromManager(cm, selection)),
);
const accs = all.map(r => r.result).flat();
const accs = all.flat();
this.log.debug(
`loaded ${accs.length} credit accounts from ${cms.length} credit managers`,
);
Expand All @@ -335,6 +331,33 @@ export class Scanner {
: this.#filterZeroDebt(accs);
}

async #getAccountsFromManager(
cm: Address,
{ priceUpdates, blockNumber }: AccountSelection,
): Promise<CreditAccountDataRaw[]> {
const resp = await simulateMulticall(this.client.pub, {
contracts: [
...priceUpdates.map(p => ({
address: p.address,
abi: iUpdatablePriceFeedAbi,
functionName: "updatePrice",
args: [p.callData],
})),
{
address: this.dataCompressor.address,
abi: iDataCompressorV3Abi,
functionName: "getCreditAccountsByCreditManager",
args: [cm, []],
},
],
blockNumber,
allowFailure: false,
gas: 550_000_000n,
});
const result = resp.pop() as readonly CreditAccountDataRaw[];
return [...result];
}

#filterZeroDebt(accs: CreditAccountDataRaw[]): CreditAccountDataRaw[] {
return accs.filter(acc => acc.debt > 0n);
}
Expand Down

0 comments on commit d64d0a8

Please sign in to comment.