feat: add admin metrics endpoints with scheduled aggregation (#156)#188
Open
kalbliz wants to merge 1 commit into
Open
feat: add admin metrics endpoints with scheduled aggregation (#156)#188kalbliz wants to merge 1 commit into
kalbliz wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /api/v1/admin/metrics/tvl,/revenue, and/active-usersendpoints returning{ success, data, timestamp }envelopesMetricsModulewith a 5-minuteMetricsSchedulerthat aggregates TVL, cumulative protocol fees, and 24h/7d/30d active traders, caching results in Redis and persistingProtocolMetricsSnapshotrowsAdminGuard(JWT +role: admin), Prisma schema extensions/migrations, and fixes the Soroban event indexer to upsert pools and usePool.idfor trade FKsexpress-rate-limitdependency, 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/loginwithADMIN_PASSWORDreturns JWTGET /api/v1/admin/metrics/tvlreturns 401success: trueprotocol_metrics_snapshotsrows are written by schedulerdocker compose up -d db redis+npm run prisma:migrateon a fresh checkoutNotes
Pool.reserveA/Bbeing populated; returns honest0until reserve sync landstradesCloses #156