Skip to content

Commit

Permalink
fix: filter accounts without reserve price feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Apr 15, 2024
1 parent 2c8237a commit 9ad5ac7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/services/OracleServiceV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
RedstonePriceFeed,
} from "@gearbox-protocol/sdk";
import {
ADDRESS_0X0,
IPriceOracleV3__factory,
RedstonePriceFeed__factory,
safeMulticall,
Expand All @@ -30,6 +31,7 @@ interface PriceFeedEntry {
* Is set for redstone feeds, null for non-redstone feeds, undefined if unknown
*/
dataFeedId?: string | null;
trusted?: boolean;
}

interface RedstoneFeed {
Expand Down Expand Up @@ -111,6 +113,25 @@ export default class OracleServiceV3 {
);
}

public checkReserveFeeds(tokens: string[], underlying: string): boolean {
for (const t of tokens) {
if (t.toLowerCase() === underlying.toLowerCase()) {
continue;
}
const entry = this.#feeds[t.toLowerCase()];
if (!entry) {
return false;
}
if (
!entry.main.trusted &&
(!entry.reserve || entry.reserve.address === ADDRESS_0X0)
) {
return false;
}
}
return true;
}

/**
* Returns currenly used redstone feeds
*/
Expand Down Expand Up @@ -169,7 +190,13 @@ export default class OracleServiceV3 {
`cannot add reserve price feed ${priceFeed} for token ${token} because main price feed is not added yet`,
);
}
entry = { active: "main", main: { address: priceFeed } };
entry = {
active: "main",
main: {
address: priceFeed,
trusted: (e as SetPriceFeedEvent).args.trusted,
},
};
}
entry[kind] = { address: priceFeed };
this.#feeds[token] = entry;
Expand Down
5 changes: 5 additions & 0 deletions src/services/liquidate/LiquidationStrategyV3Partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ export default class LiquidationStrategyV3Partial
if (ca.borrowedAmount === 0n) {
throw new Error("zero-debt account");
}
if (
!this.oracle.checkReserveFeeds(Object.keys(balances), ca.underlyingToken)
) {
throw new Error("account has tokens without reserve price feeds");
}
// const snapshotId = await (
// this.executor.provider as providers.JsonRpcProvider
// ).send("evm_snapshot", []);
Expand Down

0 comments on commit 9ad5ac7

Please sign in to comment.