Skip to content

GET /api/markets/:id/predictions/aggregate for outcome pool sizes #94

Description

@greatest0fallt1me

Description

Markets pages need at-a-glance pool totals per outcome. Add an aggregate endpoint backed by a small materialized view refreshed by the predictions confirmer worker, so reads are O(rows-in-result) and never scan predictions.

Requirements and Context

  • MV market_outcome_totals with (market_id, outcome, total_amount, prediction_count)
  • Refreshed at the end of every confirmer tick
  • GET /api/markets/:id/predictions/aggregate returns the rows
  • Caches Cache-Control: max-age=5 for browser clients
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b feature/market-aggregate-endpoint
  2. Implement changes
    • SQL migration creating MV
    • Hook refresh into src/workers/predictionsConfirmer.ts
    • src/routes/markets.ts aggregate handler
  3. Test and commit
    • Seed predictions, run confirmer, assert totals
    • Cover edge cases
    • Include test output and notes in the PR

Example commit message

feat: market outcome aggregates endpoint

Acceptance Criteria

  • Endpoint p95 < 20ms at 1M predictions
  • Aggregates always equal sum of confirmed predictions
  • Cache header present and respected by supertest repeat call

Guidelines

  • Use numeric(78,0) for total_amount
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GRANTFOX OSSGrantFox open-source campaign taskOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service workperformancePerformance/efficiency
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions