fix(markets): add missing columns to stats endpoints per OpenAPI schema#173
fix(markets): add missing columns to stats endpoints per OpenAPI schema#1736figpsolseeker wants to merge 1 commit intodcccrypto:mainfrom
Conversation
Both /markets/stats and /markets/:slab/stats selected only 10 columns from market_stats / markets_with_stats, but the OpenAPI MarketStats schema documents 14 fields. The missing columns — lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h — are present in the DB tables (queried successfully by insurance.ts, open-interest.ts, stats.ts, trades.ts) but were omitted from the stats endpoint select clauses. API consumers relying on the documented schema would receive null/missing values for LP statistics, insurance fund data, and 24h volume — breaking risk analytics and dashboard integrations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/routes/markets.ts (1)
86-86: Consider extracting the shared stats column projection into a constant.The select list is duplicated in two routes; centralizing it will reduce future schema drift.
♻️ Suggested refactor
+const MARKET_STATS_SELECT = + "slab_address, total_open_interest, total_accounts, last_crank_slot, last_price, mark_price, index_price, funding_rate, net_lp_pos, lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h, updated_at"; app.get("/markets/stats", async (c) => { try { const { data, error } = await getSupabase() .from("markets_with_stats") - .select("slab_address, total_open_interest, total_accounts, last_crank_slot, last_price, mark_price, index_price, funding_rate, net_lp_pos, lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h, updated_at") + .select(MARKET_STATS_SELECT) .eq("network", getNetwork()) .not("slab_address", "is", null); app.get("/markets/:slab/stats", validateSlab, async (c) => { const slab = c.req.param("slab"); try { const { data, error } = await getSupabase() .from("market_stats") - .select("slab_address, total_open_interest, total_accounts, last_crank_slot, last_price, mark_price, index_price, funding_rate, net_lp_pos, lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h, updated_at") + .select(MARKET_STATS_SELECT) .eq("slab_address", slab) .single();Also applies to: 105-105
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/routes/markets.ts` at line 86, Extract the duplicated select projection string into a shared constant (e.g., MARKET_STATS_COLUMNS) and replace the inline string in both .select(...) calls with that constant; update the two routes that currently call .select("slab_address, total_open_interest, total_accounts, last_crank_slot, last_price, mark_price, index_price, funding_rate, net_lp_pos, lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h, updated_at") to use .select(MARKET_STATS_COLUMNS) so the projection is centralized and reused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/routes/markets.ts`:
- Line 86: Extract the duplicated select projection string into a shared
constant (e.g., MARKET_STATS_COLUMNS) and replace the inline string in both
.select(...) calls with that constant; update the two routes that currently call
.select("slab_address, total_open_interest, total_accounts, last_crank_slot,
last_price, mark_price, index_price, funding_rate, net_lp_pos, lp_sum_abs,
lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h, updated_at")
to use .select(MARKET_STATS_COLUMNS) so the projection is centralized and
reused.
Summary
/markets/statsand/markets/:slab/statsselected only 10 columns, but the OpenAPIMarketStatsschema documents 14 fields.lp_sum_abs,lp_max_abs,insurance_balance,insurance_fee_revenue,volume_24h— all present in the DB (queried successfully by other routes likeinsurance.ts,open-interest.ts,stats.ts,trades.ts) but omitted from the stats endpoint select clauses.Test plan
npx vitest run tests/routes/markets.test.ts— 10/10 passingtests/routes/prices.test.tsissue onmain, unrelated)npx tsc --noEmit— cleanSummary by CodeRabbit