Skip to content

feat: add admin metrics endpoints with scheduled aggregation (#156)#188

Open
kalbliz wants to merge 1 commit into
BETAIL-BOYS:mainfrom
kalbliz:feat/admin-metrics-156
Open

feat: add admin metrics endpoints with scheduled aggregation (#156)#188
kalbliz wants to merge 1 commit into
BETAIL-BOYS:mainfrom
kalbliz:feat/admin-metrics-156

Conversation

@kalbliz

@kalbliz kalbliz commented Jun 24, 2026

Copy link
Copy Markdown

Summary

  • Adds admin-protected GET /api/v1/admin/metrics/tvl, /revenue, and /active-users endpoints returning { success, data, timestamp } envelopes
  • Introduces MetricsModule with a 5-minute MetricsScheduler that aggregates TVL, cumulative protocol fees, and 24h/7d/30d active traders, caching results in Redis and persisting ProtocolMetricsSnapshot rows
  • Adds AdminGuard (JWT + role: admin), Prisma schema extensions/migrations, and fixes the Soroban event indexer to upsert pools and use Pool.id for trade FKs
  • Includes local dev improvements: Redis service in Docker Compose, express-rate-limit dependency, and small build fixes (logger types, Horizon fee lookup, compression import, etc.)

Test plan

  • npx jest src/metrics/metrics.service.spec.ts src/auth/guards/admin.guard.spec.ts (9/9 passing)
  • POST /api/v1/admin/login with ADMIN_PASSWORD returns JWT
  • Unauthenticated GET /api/v1/admin/metrics/tvl returns 401
  • Authenticated calls to all three metrics endpoints return success: true
  • Verified Redis cache keys and protocol_metrics_snapshots rows are written by scheduler
  • Run docker compose up -d db redis + npm run prisma:migrate on a fresh checkout
  • Seed pools/trades and confirm non-zero TVL/revenue/active-user values after aggregation

Notes

  • TVL depends on Pool.reserveA/B being populated; returns honest 0 until reserve sync lands
  • Protocol revenue is derived from indexed swaps × pool fee bps, not on-chain treasury balance
  • Active users count distinct swapper addresses in trades

Closes #156

…BOYS#156)

Introduce /api/v1/admin/metrics for global TVL, protocol revenue, and active trader counts. Metrics are computed every 5 minutes, cached in Redis, and persisted to ProtocolMetricsSnapshot. Includes AdminGuard, Prisma schema/migrations, indexer pool FK fix, and build/infra fixes to unblock local development.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

[Feature] Global TVL and Protocol Revenue Aggregation Endpoints

1 participant