Skip to content

Commit 9ea51db

Browse files
authored
Merge pull request #6 from ajna-finance/40-subgraph-failure
40: Optionally abort run on subgraph failure
2 parents 98bd68c + aeafc65 commit 9ea51db

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ MIN_TIME_SINCE_BANKRUPTCY=259200
3535
# Defaults to 72 hours (in seconds).
3636
MAX_AUCTION_AGE=259200
3737

38+
# Optional: this value determines whether the entire run exits if the subgraph query fails during the check for bad debt in the pool.
39+
# Defaults to false.
40+
EXIT_ON_SUBGRAPH_FAILURE=false
41+
3842
# A CoinGecko API key is not strictly required for the rate of queries made by this keeper.
3943
#
4044
# If a key is defined, the tier is also required, since the header is different for each request (demo or pro).

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ Due to LUP and HTP shifting dynamically with pool activity, the in-range boundar
4343
| `MIN_MOVE_AMOUNT` | Skip moves if bucket's quote token balance is below this amount (dust limit) - enforced by vault. | Integer (WAD units) | Optional | 1,000,000 |
4444
| `MIN_TIME_SINCE_BANKRUPTCY` | Minimum time since bucket bankruptcy to be considered valid. Abort keeper run if timestamp is between this value and current time. | Integer (seconds) | Optional | 259,200 (72h) |
4545
| `MAX_AUCTION_AGE` | Only consider auctions with bad debt if they are older than this value. | Integer (seconds) | Optional | 259,200 (72h) |
46+
| `EXIT_ON_SUBGRAPH_FAILURE` | Abort run if the subgraph query fails during the check for bad debt in the pool. | String (`true`/`false`) | Optional | `false`
4647
| `ORACLE_API_KEY` | CoinGecko API key. | String | Optional | None |
4748
| `ORACLE_KEY_TIER` | CoinGecko tier (`demo`, `pro`). | String | Conditional (if `ORACLE_API_KEY` set) | None |
4849
| `ONCHAIN_ORACLE_ADDRESS` | Address of Chronicle on-chain oracle. | Ethereum address (`0x…`) | Conditional (if `ONCHAIN_ORACLE_PRIMARY=true`) | None |
49-
| `ONCHAIN_ORACLE_PRIMARY` | Use on-chain oracle as primary instead of CoinGecko. | Boolean (`true/false`) | Optional | false |
50+
| `ONCHAIN_ORACLE_PRIMARY` | Use on-chain oracle as primary instead of CoinGecko. | String (`true`/`false`) | Optional | false |
5051
| `ONCHAIN_ORACLE_MAX_STALENESS` | Max allowed age of on-chain price data. | Integer (seconds) | Conditional (if `ONCHAIN_ORACLE_PRIMARY=true`) | 43,200 (12h) |
5152

5253

src/subgraph/poolHealth.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type LiquidationAuction = {
1616

1717
export async function poolHasBadDebt(): Promise<boolean> {
1818
const unfilteredAuctions = await _getUnsettledAuctions();
19-
const auctionsBeforeCutoff = _filterAuctions(unfilteredAuctions);
19+
if (unfilteredAuctions === 'error') return true;
20+
const auctionsBeforeCutoff = _filterAuctions(unfilteredAuctions as GetUnsettledAuctionsResponse);
2021

2122
for (let i = 0; i < auctionsBeforeCutoff.length; i++) {
2223
const [kickTime, collateralRemaining, debtRemaining] = await getAuctionStatus(
@@ -29,7 +30,7 @@ export async function poolHasBadDebt(): Promise<boolean> {
2930
return false;
3031
}
3132

32-
export async function _getUnsettledAuctions(): Promise<GetUnsettledAuctionsResponse> {
33+
export async function _getUnsettledAuctions(): Promise<GetUnsettledAuctionsResponse | string> {
3334
try {
3435
const poolAddress = (await getPoolAddress()).toLowerCase();
3536
const subgraphUrl = env.SUBGRAPH_URL;
@@ -51,10 +52,10 @@ export async function _getUnsettledAuctions(): Promise<GetUnsettledAuctionsRespo
5152
} catch (err) {
5253
log.error(
5354
{ event: 'subgraph_query_failed', url: env.SUBGRAPH_URL, err },
54-
'subgraph query failed, continuing with keeper run optimistically',
55+
'subgraph query failed',
5556
);
5657

57-
return { liquidationAuctions: [] };
58+
return env.EXIT_ON_SUBGRAPH_FAILURE ? 'error' : { liquidationAuctions: [] };
5859
}
5960
}
6061

src/utils/env.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ const minTimeSinceBankruptcy = process.env.MIN_TIME_SINCE_BANKRUPTCY ?? 259200;
3636
// Defaults to 72 hours (seconds)
3737
const maxAuctionAge = process.env.MAX_AUCTION_AGE ?? 259200;
3838

39+
let exitOnSubgraphFailure;
40+
if (process.env.EXIT_ON_SUBGRAPH_FAILURE) {
41+
exitOnSubgraphFailure = process.env.EXIT_ON_SUBGRAPH_FAILURE === 'true' ? true : false;
42+
} else {
43+
exitOnSubgraphFailure = false;
44+
}
45+
3946
export const env = {
4047
KEEPER_INTERVAL_MS: Number(process.env.KEEPER_INTERVAL_MS),
4148
VAULT_ADDRESS: process.env.VAULT_ADDRESS,
@@ -58,4 +65,5 @@ export const env = {
5865
SUBGRAPH_URL: process.env.SUBGRAPH_URL,
5966
MIN_TIME_SINCE_BANKRUPTCY: BigInt(minTimeSinceBankruptcy),
6067
MAX_AUCTION_AGE: Number(maxAuctionAge),
68+
EXIT_ON_SUBGRAPH_FAILURE: exitOnSubgraphFailure,
6169
};

test/subgraph/poolHealth.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { describe, it, expect, expectTypeOf } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import { _getUnsettledAuctions, _filterAuctions } from '../../src/subgraph/poolHealth';
33

44
describe('subgraph query', () => {
55
it('can query subgraph for unsettled auctions', async () => {
66
const result = await _getUnsettledAuctions();
77

88
expect(result).toHaveProperty('liquidationAuctions');
9-
expectTypeOf(result.liquidationAuctions).toBeArray();
109
});
1110

1211
it('can filter out auctions newer than the minAge', () => {

0 commit comments

Comments
 (0)