Repository navigation
feat: indexer api - #182
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New HTTP API for the frontend, built with Effect
HttpApi, served by the indexer process. It replacesapps/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.Dbin the same process.index.tsnow runsapp.live(historical sync, then new blocks) alongside the HTTP server; if either fails, both stop.NodeRuntime.runMainreplaces the hand-written signal handling.Routes
Interactive docs at
/docs. CORS allows any origin forGET, as before.GET /stackingdao/statsGET /stackingdao/flows?token&intervalGET /stackingdao/stakers?token&intervalGET /stackingdao/yield?token=ststx|stbtc&intervalGET /stackingdao/withdrawals?token&intervalwithdraw-idle) vs standard (withdraw) counts, amounts and feesGET /stackingdao/swaps?intervalGET /stackingdao/activity?kind&token&since&sort&limit&cursorGET /statusGET /tokens/holders,/tokens/markets,/tokens/resolveapps/server(Hiro API, CoinGecko), same response shapesinterval=month,dayfor yield.asOfBlock, the block through which every event is indexed.depositedexcludescore-v1stSTX deposits, which print no STX amount;mintedincludes them.sort=amountneedstokenandkind=deposit|withdraw, since amounts of different tokens are not comparable; otherwise400 InvalidQuery.Configuration
PORT(default 3001), optionalHIRO_API_KEYandCOINGECKO_API_KEY. The holders route and the indexer share the Hiro quota: setHIRO_API_KEYin production, or holders answers502while the backfill runs.Dependencies
Adds
@effect/platform-node@4.0.2and pins@effect/platform-node-sharedto 4.0.2 inpnpm-workspace.yaml: the caret range resolved 4.0.5, which requireseffect4.0.5, while stacksindex pinseffect4.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 fromApi: 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 and400errors./statusanswer during the backfill, CORS header and/docsserved, markets from CoinGecko (cached second call in 1 ms), resolve returns stSTX's contract and404for an unknown coin, holders returns real stSTX holders.Not in this PR
Switching
apps/webto these routes, removing the pages without data, and deletingapps/server.