VaultClient only ever mirrored vault.py/vault.rs's 2026-10-27 feature set (positions/healthFactor/currentDebt/ltvBps/liquidationThresholdBps) — it never picked up totalAssets/totalReserves/protocolReserves/borrowCap/ reserveFactorBps/totalLenderShares/lenderShares or the severity-scaled liquidationBonusBpsFor the vault contract grew across later 2026-10-28/29 passes. apps/web's own /api/vault-position route already reads every one of these fields to power the live LendCard/VaultCard UI, and scripts/liquidation-bot-demo.mjs reimplements a raw eth_call for the bonus instead of using the published SDK at all — a real third-party integrator building a lending dashboard or liquidation bot off @qie-forge/core had no way to read any of this. - vault.ts: new getLiquidationBonusBps/getLenderShares/getPoolStats on VaultClient, extending VAULT_ABI with the vault's real view functions. - CLI: vault-position now prints liquidationBonusBps and a `pool` block with the same stats, matching apps/web's route shape field-for-field. - Core: 23/23 tests pass (was 20/20). CLI: 28/28 tests pass. - Verified live against the real deployed demo vault behind qie-forge.vercel.app (0xd49a...17be on the self-hosted anvil devnet, addresses pulled via `vercel env pull` then deleted): the CLI's totalAssets/totalDebtPrincipal/liquidationBonusBps exactly match a direct curl against the production app's own /api/vault-position for the same user, and the new fields (totalReserves, protocolReserves, borrowCap=100000000000, reserveFactorBps=1000) are real on-chain reads never exposed through the SDK/CLI before this.
64 lines
2.9 KiB
TypeScript
64 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { isLiquidatable, WAD, VaultClient, type VaultPosition } from "../src/vault.js";
|
|
import { ChainClient } from "../src/chain.js";
|
|
import { QieForgeError } from "../src/errors.js";
|
|
|
|
function position(overrides: Partial<VaultPosition> = {}): VaultPosition {
|
|
return {
|
|
collateral: 0n,
|
|
debtPrincipal: 0n,
|
|
lastAccrual: 0n,
|
|
healthFactor: WAD,
|
|
currentDebt: 0n,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("isLiquidatable (mirrors VaultPosition.is_liquidatable in vault.py / vault.rs)", () => {
|
|
it("is false when there is no debt, regardless of health factor", () => {
|
|
expect(isLiquidatable(position({ debtPrincipal: 0n, healthFactor: 0n }))).toBe(false);
|
|
});
|
|
|
|
it("is false when health factor is at or above WAD", () => {
|
|
expect(isLiquidatable(position({ debtPrincipal: 100n, healthFactor: WAD }))).toBe(false);
|
|
expect(isLiquidatable(position({ debtPrincipal: 100n, healthFactor: WAD + 1n }))).toBe(false);
|
|
});
|
|
|
|
it("is true when there is debt and health factor is below WAD", () => {
|
|
expect(isLiquidatable(position({ debtPrincipal: 100n, healthFactor: WAD - 1n }))).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("VaultClient construction", () => {
|
|
it("rejects an invalid vault address before making any network call", () => {
|
|
const chain = new ChainClient({ network: "testnet" });
|
|
expect(() => new VaultClient(chain, "not-an-address")).toThrowError(QieForgeError);
|
|
});
|
|
|
|
it("rejects an invalid user address before making any network call", async () => {
|
|
const chain = new ChainClient({ network: "testnet" });
|
|
const vault = new VaultClient(chain, "0x0000000000000000000000000000000000000001");
|
|
await expect(vault.getPosition("not-an-address")).rejects.toThrowError(QieForgeError);
|
|
});
|
|
});
|
|
|
|
describe("VaultClient pool-stats/liquidation-bonus surface (2026-10-29 parity gap)", () => {
|
|
it("rejects an invalid user address in getLiquidationBonusBps before any network call", async () => {
|
|
const chain = new ChainClient({ network: "testnet" });
|
|
const vault = new VaultClient(chain, "0x0000000000000000000000000000000000000001");
|
|
await expect(vault.getLiquidationBonusBps("not-an-address")).rejects.toThrowError(QieForgeError);
|
|
});
|
|
|
|
it("rejects an invalid user address in getLenderShares before any network call", async () => {
|
|
const chain = new ChainClient({ network: "testnet" });
|
|
const vault = new VaultClient(chain, "0x0000000000000000000000000000000000000001");
|
|
await expect(vault.getLenderShares("not-an-address")).rejects.toThrowError(QieForgeError);
|
|
});
|
|
|
|
it("rejects an invalid user address in getPoolStats before any network call", async () => {
|
|
const chain = new ChainClient({ network: "testnet" });
|
|
const vault = new VaultClient(chain, "0x0000000000000000000000000000000000000001");
|
|
await expect(vault.getPoolStats("not-an-address")).rejects.toThrowError(QieForgeError);
|
|
});
|
|
});
|