Skip to content

feat: indexer api - #182

Merged
pradel merged 1 commit into
mainfrom
feat/indexer-api
Oct 21, 2026
Merged

pradel merged 1 commit into
mainfrom
feat/indexer-api

Conversation

@pradel

@pradel pradel commented Oct 21, 2026

Copy link
Copy Markdown
Owner

New HTTP API for the frontend, built with Effect HttpApi, served by the indexer process. It replaces apps/server, which reads a Stacks node database we no longer run. Not backward compatible.

Why in the indexer process

PGlite allows one process per database, so the API reads the indexer database through indexer.Db in the same process. index.ts now runs app.live (historical sync, then new blocks) alongside the HTTP server; if either fails, both stop. NodeRuntime.runMain replaces the hand-written signal handling.

Routes

Interactive docs at /docs. CORS allows any origin for GET, as before.

Route Returns
GET /stackingdao/stats Per token: deposits, unique stakers, deposited / withdrawn (STX or sBTC), minted / burned
GET /stackingdao/flows?token&interval Deposited, withdrawn, minted, burned per period and token
GET /stackingdao/stakers?token&interval Depositors per period, and how many were new
GET /stackingdao/yield?token=ststx|stbtc&interval STX per stSTX / sBTC per stBTC over time, and APY over the last 30 days
GET /stackingdao/withdrawals?token&interval Instant (withdraw-idle) vs standard (withdraw) counts, amounts and fees
GET /stackingdao/swaps?interval stSTX ⇄ stSTXbtc swaps per period and direction
GET /stackingdao/activity?kind&token&since&sort&limit&cursor Feed of deposits, withdrawals and swaps with cursor paging
GET /status Indexer phase, checkpoint and chain tip
GET /tokens/holders, /tokens/markets, /tokens/resolve Ported from apps/server (Hiro API, CoinGecko), same response shapes
  • Amounts are integer strings in base units (STX 6 decimals, sBTC 8). Periods are UTC start dates; weeks start on Monday. Defaults: interval=month, day for yield.
  • StackingDAO responses carry asOfBlock, the block through which every event is indexed.
  • deposited excludes core-v1 stSTX deposits, which print no STX amount; minted includes them.
  • sort=amount needs token and kind=deposit|withdraw, since amounts of different tokens are not comparable; otherwise 400 InvalidQuery.
  • External responses are cached in memory (holders 15 min, markets 24 h, resolve 3 days); failures are not cached. Database routes are not cached.

Configuration

PORT (default 3001), optional HIRO_API_KEY and COINGECKO_API_KEY. The holders route and the indexer share the Hiro quota: set HIRO_API_KEY in production, or holders answers 502 while the backfill runs.

Dependencies

Adds @effect/platform-node@4.0.2 and pins @effect/platform-node-shared to 4.0.2 in pnpm-workspace.yaml: the caret range resolved 4.0.5, which requires effect 4.0.5, while stacksindex pins effect 4.0.2.

Verification

  • vp check, tsc, vp test (25 tests). The 12 API tests serve the real API on an ephemeral port over an in-memory database and call it through the client derived from Api: UTC month and Monday week grouping, totals, new vs returning stakers, yield weighting and APY, instant vs standard withdrawals, swaps, cursor paging (every event exactly once), amount sorting and 400 errors.
  • Mainnet run on a fresh database: StackingDAO routes and /status answer during the backfill, CORS header and /docs served, markets from CoinGecko (cached second call in 1 ms), resolve returns stSTX's contract and 404 for an unknown coin, holders returns real stSTX holders.

Not in this PR

Switching apps/web to these routes, removing the pages without data, and deleting apps/server.

@pradel
pradel merged commit 65ee64d into main Oct 21, 2026
1 of 3 checks passed
@pradel
pradel deleted the feat/indexer-api branch October 21, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant