Skip to main content

Indexer API

The indexer tails Soroban events with a persisted cursor, writes them to Postgres, and serves a small REST surface for the stats page, historical charts, and at-risk-position monitoring.

Endpoints

MethodPathReturns
GET/health{ ok: true }
GET/metricslatest TVL, utility ratio, cap utilization, borrow liquidity
GET/vaults/:id/historyshare_price series for charting
GET/positions/at-riskpositions with health_factor near/below 1

Poller

  • Persisted cursor — resumes exactly where it stopped; survives restarts.
  • FiltergetEvents({ filters: [{ type: "contract", contractIds: […] }] }) across all Leontief contracts (no topic filter, so no event is missed).
  • Risk math is purecomputeAtRisk / healthFactor are pure functions with their own unit tests, independent of I/O.

Run it

# migrate + serve
DATABASE_URL=postgres://… pnpm --filter @leontief/indexer migrate
DATABASE_URL=postgres://… pnpm --filter @leontief/indexer start

The indexer is optional for the dApp (which reads chain state directly); it powers aggregate history and the public stats view. A separate services/monitor watches the live contracts directly and alerts on share-price steps, oracle staleness/halts, cap utilization, and pauses.