Skip to content

fix(markets): add missing columns to stats endpoints per OpenAPI schema#173

Open
6figpsolseeker wants to merge 1 commit intodcccrypto:mainfrom
6figpsolseeker:fix/markets-stats-missing-columns
Open

fix(markets): add missing columns to stats endpoints per OpenAPI schema#173
6figpsolseeker wants to merge 1 commit intodcccrypto:mainfrom
6figpsolseeker:fix/markets-stats-missing-columns

Conversation

@6figpsolseeker
Copy link
Copy Markdown

@6figpsolseeker 6figpsolseeker commented Apr 9, 2026

Summary

  • Both /markets/stats and /markets/:slab/stats selected only 10 columns, but the OpenAPI MarketStats schema documents 14 fields.
  • Missing columns: lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, volume_24h — all present in the DB (queried successfully by other routes like insurance.ts, open-interest.ts, stats.ts, trades.ts) but 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.

Test plan

  • npx vitest run tests/routes/markets.test.ts — 10/10 passing
  • Full suite: 188/189 passing (the 1 failure is a pre-existing tests/routes/prices.test.ts issue on main, unrelated)
  • npx tsc --noEmit — clean

Summary by CodeRabbit

  • New Features
    • Market statistics endpoints now return additional data fields including LP position metrics, insurance information, and 24-hour trading volume.

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

The /markets/stats and /markets/:slab/stats endpoints in the Supabase query handlers were updated to retrieve additional database columns: lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, and volume_24h, alongside the existing fields.

Changes

Cohort / File(s) Summary
Market Stats Column Expansion
src/routes/markets.ts
Expanded Supabase column selections for both /markets/stats (using markets_with_stats view) and /markets/:slab/stats (using market_stats table) endpoints to include five additional fields: lp_sum_abs, lp_max_abs, insurance_balance, insurance_fee_revenue, and volume_24h.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 Hop, hop, new columns bloom,
Database fields dispel the gloom,
Insurance, LP, volume so bright,
Market stats now complete and tight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding missing columns to market stats endpoints to align with the OpenAPI schema.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2c339e5-3985-4827-93b9-e005f41f97ef

📥 Commits

Reviewing files that changed from the base of the PR and between 9abea9f and 5ccbd32.

📒 Files selected for processing (1)
  • src/routes/markets.ts

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