From 317d1d13158c2433ce30b9ae855ef67aff25f645 Mon Sep 17 00:00:00 2001 From: nktkas Date: Sat, 1 Aug 2026 20:36:01 +0300 Subject: [PATCH] refactor(api/borrowLendUserState): widen `health` and `healthFactor` types Co-authored-by: Claude Opus 5 (1M context) --- src/api/info/_methods/borrowLendUserState.ts | 17 +++++++++-------- tests/api/info/_t.ts | 12 +++++++----- tests/api/info/borrowLendUserState.test.ts | 10 ++++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/api/info/_methods/borrowLendUserState.ts b/src/api/info/_methods/borrowLendUserState.ts index 9af330f22..5e26634d2 100644 --- a/src/api/info/_methods/borrowLendUserState.ts +++ b/src/api/info/_methods/borrowLendUserState.ts @@ -60,17 +60,18 @@ export type BorrowLendUserStateResponse = { }, ][]; /** - * Account health status. - * - * FIXME: other literals may exist (unconfirmed). + * Account health status: + * - `"healthy"`: Collateral covers the debt. + * - `"atRisk"`: Health factor approached the liquidation threshold. + * - `"marketLiquidatable"`: Debt is being liquidated through the order book. + * - `"backstopLiquidatable"`: Debt is taken over by the liquidator vault. */ - health: "healthy"; + health: "healthy" | "atRisk" | "marketLiquidatable" | "backstopLiquidatable"; /** - * Health factor. - * - * FIXME: non-null value not found (unconfirmed). + * Health factor; `null` when the account has no borrow position. + * @pattern ^[0-9]+(\.[0-9]+)?$ */ - healthFactor: null; + healthFactor: string | null; }; // ============================================================ diff --git a/tests/api/info/_t.ts b/tests/api/info/_t.ts index a503b3fe3..5f9761149 100644 --- a/tests/api/info/_t.ts +++ b/tests/api/info/_t.ts @@ -11,8 +11,8 @@ const OFFLINE = Deno.args.includes("--offline"); // Preparation // ============================================================ -const transport = new HttpTransport({ isTestnet: true, timeout: 30_000 }); -const client = new InfoClient({ transport }); +const testnetClient = new InfoClient({ transport: new HttpTransport({ isTestnet: true, timeout: 30_000 }) }); +const mainnetClient = new InfoClient({ transport: new HttpTransport({ timeout: 30_000 }) }); // ============================================================ // Test @@ -24,18 +24,20 @@ const client = new InfoClient({ transport }); * @param options Test options including name and test function * @param options.name Name of the test * @param options.ignore Whether to skip the test + * @param options.isTestnet Uses the testnet API when true; defaults to `true` * @param options.codeTestFn Async function containing the test code, receives Deno.TestContext and shared InfoClient */ export function runTest(options: { name: string; ignore?: boolean; - codeTestFn: (t: Deno.TestContext, client_: typeof client) => Promise; + isTestnet?: boolean; + codeTestFn: (t: Deno.TestContext, client_: typeof testnetClient) => Promise; }): void { - const { name, ignore, codeTestFn } = options; + const { name, ignore, isTestnet = true, codeTestFn } = options; Deno.test(name, { ignore: OFFLINE || ignore }, async (t) => { await new Promise((r) => setTimeout(r, WAIT)); // delay to avoid rate limits - await codeTestFn(t, client); + await codeTestFn(t, isTestnet ? testnetClient : mainnetClient); }); } diff --git a/tests/api/info/borrowLendUserState.test.ts b/tests/api/info/borrowLendUserState.test.ts index 6c97a55ad..f9cb653ef 100644 --- a/tests/api/info/borrowLendUserState.test.ts +++ b/tests/api/info/borrowLendUserState.test.ts @@ -11,14 +11,20 @@ const paramsSchema = valibotToJsonSchema(v.omit(BorrowLendUserStateRequest, ["ty runTest({ name: "borrowLendUserState", + isTestnet: false, codeTestFn: async (_t, client) => { const params: BorrowLendUserStateParameters[] = [ - { user: "0xcb3f0bd249a89e45e86a44bcfc7113e4ffe84cd1" }, + { user: "0x0000000000000000000000000000000000000001" }, // healthFactor: null + { user: "0xf02d16a272a842f8bac1d9a9e773aba1933454c6" }, // "healthy" + { user: "0xe639710e64d7094f7f82ab495915559c2f612953" }, // "atRisk" ]; const data = await Promise.all(params.map((p) => client.borrowLendUserState(p))); schemaCoverage(paramsSchema, params); - schemaCoverage(responseSchema, data); + schemaCoverage(responseSchema, data, [ + "#/properties/health/enum/2", // "marketLiquidatable" + "#/properties/health/enum/3", // "backstopLiquidatable" + ]); }, });