This repo is the application API used by the frontend. It exposes the HTTP surface area for articles, claims, staking, and the market maker. It calls OpenAI for article generation and sentence cleanup.
cd app
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8070OPENAI_API_KEY— required for article generation and sentence cleanup.DATABASE_URL— PostgreSQL connection string.RPC_URL— Avalanche Fuji RPC endpoint.MM_PRIVATE_KEY— market maker wallet private key (for relay signing).CHAIN_ID— defaults to43113(Fuji).
See ops/compose/.env.example for the full list.
Schema is managed via SQL files in ops/compose/migrations/. Run them with:
python -m migrate # apply all migrations
python -m migrate reset # DROP + recreate schema (dev only)GET /healthz— returns{"ok":"true"}when the service is up.
GET /api/article/{topic}— get or auto-generate article for a topic.POST /api/article/{topic}/generate— generate (or regenerate) an article.POST /api/article/sentence/insert— add a sentence to a section.POST /api/article/sentence/{id}/edit— replace a sentence (creates new + marks old replaced).POST /api/article/sentence/{id}/link_post— link a sentence to its on-chain post_id.POST /api/article/sentence/cleanup— AI grammar/pronoun cleanup.GET /api/disambiguate?q=...— typeahead search across articles and claims.
GET /api/claims/fast/all— all on-chain claims with metrics (indexed DB, fast).GET /api/claims/search?q=...— search claims by text.GET /api/claims/{post_id}/summary— full claim summary from ProtocolViews.GET /api/claims/{post_id}/edges— incoming and outgoing evidence links.GET /api/claims/{post_id}/stakes?user=0x...— stake totals and user positions.GET /api/claim-status/{claim_text}— full claim state including on-chain data.
POST /relay— submit a signed meta-transaction for gasless execution.GET /relay/nonce/{address}— get the user's forwarder nonce.
GET /api/mm/quote?side=buy&qty=10— get a price quote.POST /api/mm/trade— execute a trade.GET /api/mm/floor— liquidation floor price.
GET /api/portfolio/{address}— user's staked positions with APR estimates.
GET /api/contracts— deployed contract addresses.
Two indexers run at startup:
chain/indexer.py(async) — pollsnextPostId()and syncs new claims into theclaimandclaim_embeddingtables for semantic search.chain_indexer.py(thread) — polls contract events and syncs full on-chain state intochain_post,chain_user_stake,chain_link, etc. for fast API reads.
Both are necessary: the first feeds the semantic/dedup system, the second feeds the indexed read model.