§ 09 — API reference
JSON over REST, events over /ws, a guide at /llms.txt.
The Fastify API is the single backend for the web app and for agents. The contract is typed in packages/shared/src/api.ts, ws.ts and custody.ts.
§ 9.1Conventions
- Base URL: your API host (local
http://localhost:4000). REST under/api. - Amounts are UI units (JS numbers already divided by decimals); on-chain code uses bigint atoms. Prices are quote per whole token; tokens have 6 decimals.
- Timestamps are unix seconds. Use
serverTimeTsto correct your clock before computing countdowns. - Errors:
{ "error": string, "details"?: unknown }with a 4xx/5xx status. Unknown routes return 404route not found. - CORS from
CORS_ORIGIN; body limit 256 KB (32 KB on the privacy proxy).
§ 9.2Public endpoints
| Method | Path | Returns |
|---|---|---|
| GET | /api/health | HealthResponse — network, isDemo, db, cache, redacted rpc, programId, uptime, version. Also /health. |
| GET | /api/stats | ProtocolStats — volume, fees, credit deployed/repaid, solvency, burns, payouts, counts. |
| GET | /api/launches?status="e=&limit= | LaunchListResponse. status: a LaunchStatus or auctions | vaults | graduated; quote: a symbol, stocks or all; limit 1–200 (50). |
| GET | /api/launches/:idOrMint | LaunchSummary, 404 if unknown. |
| GET | /api/launches/:idOrMint/trades?limit= | { trades: Trade[] } |
| GET | /api/launches/:idOrMint/chart?interval=1m|5m|1h | { points: PricePoint[] } |
| POST | /api/launches | Demo: creates an in-memory launch (200). Non-demo: 501 "sign client-side" with create_launch args in atoms. 400 on invalid input (e.g. > 200 bps). |
| GET | /api/auctions/:idOrMint | { launch, serverTimeTs } — public aggregates only. |
| POST | /api/auctions/:idOrMint/demo-bid | Demo only (403 otherwise). { commitment, deposit, wallet? }; 409 if the commit window is closed. |
| GET | /api/vaults/:mint | { launch, recentBuybacks (30), serverTimeTs } |
| GET | /api/rewards/:mint/:wallet | HolderReward — staked, claimable, claimed, eligible (false for snipers). |
| GET | /api/revenue | { stats, recentBuybacks, ledger, daily (14 days) } |
| GET | /api/relayer/pubkey | { pubkey (base64 x25519), relayerAddress } |
| POST | /api/relayer/reveals | SealedRevealEnvelope → { accepted, id }. 400 malformed / wrong key / bad payload, 401 bad signature, 404, 409 window closed. |
| GET | /api/privacy/status | PrivacyStatusResponse — available, simulated, ringId, escrowFunding, reason. |
| POST | /api/privacy/rpc | { method, params } → raw Helius JSON-RPC (8 whitelisted methods, 120/min/IP). |
| GET | /llms.txt | text/plain agent guide, generated from live config and shared constants. |
Example: health
{
"ok": true,
"network": "devnet",
"isDemo": true,
"db": "memory",
"cache": "memory",
"rpc": "https://devnet.helius-rpc.com/?api-key=***",
"programId": "71geDPZMKfjJnKE4an15QyyH5TyFG1w7XEL5tUkp5Tpy",
"uptimeSec": 221,
"version": "0.1.0"
}Example: a launch in reveal
{
"launches": [{
"id": "Ccrm8zMN6fJFrHGnm9dHHKAquAPTJdJsX2xj7LgGKZXw",
"mint": "EH5Z1R2MGW2iXAMX9yudQm39xxFZQ8ittkUgNwU4HLty",
"name": "Solstice", "ticker": "SOLST",
"creatorAllocationBps": 50, "totalSupply": 1000000000,
"quoteAsset": "SOL", "creditTier": "plus", "status": "reveal",
"auction": {
"commitStartTs": 1795691227, "commitEndTs": 1795692427, "revealEndTs": 1795692547,
"bidCount": 120, "revealedCount": 43, "escrowedWallets": 100, "totalEscrowed": 354.135,
"floorPrice": 3.1846375e-7, "tickSize": 1.59231875e-8, "tokensForSale": 400000000,
"targetRaise": 231.61, "clearingCap": 347.415, "clearingPrice": null, "totalRaised": null
},
"market": null, "vault": null, "credit": null,
"network": "devnet", "isDemo": true
}],
"total": 5
}After graduation market, vault (creditLine, balance, dripAmount, nextDripTs, dripsExecuted, tokensBurned…) and credit (repaid, repaidPct, phase, feesCollected, holderPayouts…) are populated. No per-bid field is ever exposed before clearing.
Example: create a launch (demo)
curl -s -X POST http://localhost:4000/api/launches \
-H 'content-type: application/json' \
-d '{"name":"Quiet Money","ticker":"QUIET","quoteAsset":"USDC","creditTier":"standard",
"creatorAllocationBps":150,"auctionSupplyBps":4000,"commitDurationSec":1200,
"revealDurationSec":120,"floorPrice":0.0001,"tickSize":0.000005,
"targetRaise":50000,"clearingCap":75000}'§ 9.3Custody and trading endpoints
Defined in CUSTODY_ROUTES. Everything except /api/custody/info and the two auth calls requires Authorization: Bearer <token> from SIWS sign-in. The server implementation is in development; shapes are fixed by the shared contract.
| Method | Path | Body → response | Auth |
|---|---|---|---|
| GET | /api/custody/info | CustodyInfoResponse — companyWallet, network, mode, payoutsEnabled, proofOfReserves[] | — |
| POST | /api/auth/nonce | { wallet } → { nonce, message, expiresTs } | — |
| POST | /api/auth/verify | { wallet, nonce, signature (base58) } → { token, wallet, expiresTs } | — |
| GET | /api/account | AccountResponse — balances (available / locked), depositRef, companyWallet, sniperFlags | bearer |
| GET | /api/account/deposit/:asset | DepositInstructions — companyWallet, memo, mint, minConfirmations, note | bearer |
| GET · POST | /api/account/deposits | GET → { deposits }; POST { signature } nudges detection → DepositRecord | bearer |
| GET · POST | /api/account/withdrawals | GET → { withdrawals }; POST { asset, amount, destination } → WithdrawalRecord | bearer |
| POST | /api/trade/commit | { launchId, commitment, deposit, sealedReveal? } → { bidId, bidCount } | bearer |
| POST | /api/trade/reveal | { launchId, maxPrice, bidAmount, salt } → { revealed: true } | bearer |
| POST | /api/trade/swap | { launchId, side, amountIn, minAmountOut } → { tradeId, amountIn, amountOut, fee, price, isSniper } | bearer |
| POST | /api/trade/claim/:launchId | after clearing → { tokens, refund } | bearer |
| POST | /api/trade/stake | { launchId, amount } — negative amount unstakes | bearer |
| POST | /api/trade/rewards/:launchId | → { amount } | bearer |
| GET · POST | /api/admin/withdrawals | operator queue: list, approve, reject — requires the ADMIN_TOKEN header | bearer |
import bs58 from "bs58";
const api = "http://localhost:4000";
const { nonce, message } = await fetch(`${api}/api/auth/nonce`, {
method: "POST", headers: { "content-type": "application/json" },
body: JSON.stringify({ wallet: wallet.publicKey.toBase58() }),
}).then((r) => r.json());
const signature = bs58.encode(await wallet.signMessage(new TextEncoder().encode(message)));
const { token } = await fetch(`${api}/api/auth/verify`, {
method: "POST", headers: { "content-type": "application/json" },
body: JSON.stringify({ wallet: wallet.publicKey.toBase58(), nonce, signature }),
}).then((r) => r.json());
const account = await fetch(`${api}/api/account`, { headers: { authorization: `Bearer ${token}` } }).then((r) => r.json());
// account.depositRef → send funds to account.companyWallet with memo "sealed:" + depositRef§ 9.4WebSocket
Connect to /ws. Subscribing sends an immediate snapshot (stats.updated for global, launch.updated for a launch). The server pings to detect dead sockets; clients may send {"op":"ping"} and receive {"type":"pong","ts":…}.
{ "op": "subscribe", "channels": ["global", "launch:<launchId>"] }
{ "op": "unsubscribe", "channels": ["launch:<launchId>"] }
{ "op": "ping" }{ "type": "vault.drip", "channel": "global", "ts": 1795692450,
"data": { "launchId": "…", "ticker": "LANE", "quoteSpent": 0.52, "tokensBurned": 20123.4,
"dripIndex": 16, "nextDripTs": 1795692630, "vaultBalance": 11.9, "…": "…" } }| Event | Data |
|---|---|
launch.created · launch.updated | LaunchSummary |
auction.bid_committed | launchId, bidCount, escrowedWallets, totalEscrowed |
auction.bid_revealed | launchId, revealedCount, bidCount |
auction.phase_changed | launchId, from, to |
auction.cleared | launchId, clearingPrice, totalRaised, winners |
trade | Trade (launch channel) |
vault.drip | BuybackEvent + nextDripTs + vaultBalance |
credit.ledger | CreditLedgerEntry + repaidPct |
credit.flywheel_activated | launchId, ts |
stats.updated | ProtocolStats, every ~3 s on global |
§ 9.5/llms.txt for AI agents
GET /llms.txt returns a plain-text guide rendered from the running config: mode (demo or live), network, program id, REST and WS URLs, the mechanics with numbers pulled from shared constants, every endpoint with example JSON, the WS protocol, a step-by-step “how an agent participates” recipe (discover → bid → auto-reveal → settle → trade and earn) and the Privacy Ring status. Point an agent at it first.
curl -s http://localhost:4000/llms.txt | head -40