Skip to content

fix(routes): scope single-market queries by network - #204

Open
Bayyan16 wants to merge 1 commit into
dcccrypto:mainfrom
Bayyan16:fix/network-scope-single-market-routes
Open

fix(routes): scope single-market queries by network#204
Bayyan16 wants to merge 1 commit into
dcccrypto:mainfrom
Bayyan16:fix/network-scope-single-market-routes

Conversation

@Bayyan16

Copy link
Copy Markdown
Contributor

Summary

Fixes #192.

This PR scopes single-market DB-backed route queries by the active configured network to prevent cross-network slab collisions.

Previously, several single-market endpoints queried market_stats by slab_address only. If the same slab address exists across networks, for example devnet and mainnet, the API could resolve the wrong row or return an incorrect 404 depending on which database row was matched first.

This PR adds network = getNetwork() filtering to the affected single-market lookups so each route resolves market data only for the active deployment network.

Fixed routes

This PR updates the following single-market route lookups:

  • GET /funding/:slab
  • GET /open-interest/:slab
  • GET /insurance/:slab
  • single-market stats lookup in markets routes

The route queries now scope market_stats lookups with both:

.eq("slab_address", slab)
.eq("network", getNetwork())

Why this is needed

Single-market endpoints should be deterministic for the currently configured network.

Querying only by slab_address is not sufficient when the same slab address can exist on multiple networks. In a shared database containing rows from more than one network, a slab-only query can cause:

  • wrong network data to be returned for a valid market
  • false 404s when the current-network row exists but another network row is matched first
  • incorrect funding, open-interest, insurance, or market stats responses

Adding the network filter ensures the API only returns data from the active configured network.

Test updates

The affected tests were updated to match the new query chain:

select(...).eq("slab_address", slab).eq("network", getNetwork()).single()

Test mocks now include:

getNetwork: vi.fn(() => "devnet")

The Supabase mocks were also cleaned up so they support chained .eq() calls consistently.

Validation

Ran the affected route test suite:

pnpm exec vitest run tests/routes/funding.test.ts tests/routes/open-interest.test.ts tests/routes/insurance.test.ts tests/routes/markets.test.ts

Result:

Test Files 4 passed
Tests 75 passed

Also verified the PR only changes the intended route and test files.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

@Bayyan16 is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Bayyan16, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 59 minutes and 18 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90ad1b9a-4865-4bf7-a3fe-2a3d6166b517

📥 Commits

Reviewing files that changed from the base of the PR and between b2751f4 and d056249.

📒 Files selected for processing (6)
  • src/routes/funding.ts
  • src/routes/insurance.ts
  • src/routes/markets.ts
  • src/routes/open-interest.ts
  • tests/routes/insurance.test.ts
  • tests/routes/open-interest.test.ts
✨ 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.

@Bayyan16

Copy link
Copy Markdown
Contributor Author

CI note: the current build-and-test failure happens during pnpm install --frozen-lockfile, before pnpm build or pnpm test runs.

The error is:

ENOENT: no such file or directory, scandir '/home/runner/work/percolator-sdk'

This appears to be caused by the existing local SDK dependency:

"@percolatorct/sdk": "file:../../percolator-sdk"

The GitHub Actions workflow checks out only percolator-api, so the sibling ../../percolator-sdk directory is not present in the runner when pnpm install --frozen-lockfile runs.

The route fix itself was validated locally with:

pnpm exec vitest run tests/routes/funding.test.ts tests/routes/open-interest.test.ts tests/routes/insurance.test.ts tests/routes/markets.test.ts

Result:

Test Files 4 passed
Tests 75 passed

So this PR’s code changes are scoped to #192, while the current CI install failure appears to be a pre-existing workflow/dependency resolution issue unrelated to the route changes.

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.

[HIGH] Single-market DB routes lack network isolation, causing cross-network data collision / false 404s

1 participant