Fix/trade indexer and pagination helpers - #639
Merged
Chucks1093 merged 10 commits intoJul 26, 2026
Merged
Conversation
|
@Mosas2000 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…nd-pagination-helpers
4 tasks
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
Testing
pnpm lintpnpm buildpnpm exec prisma generatewhen schema or generated types changedChecklist
This PR resolves issues #619, #625, #630, and #631.
Added Trade Prisma model in prisma/schema/trade.prisma with a compound unique index on (ledger, txHash) to support idempotent event writes.
Added processTradeEvent service in src/modules/indexer/trade-indexer.service.ts to validate required fields (buyer, creator_id, quantity, price, ledger, tx_hash, timestamp), persist valid events, skip duplicate events, and warn-log malformed inputs.
Created integration test src/modules/indexer/trade-indexer.integration.test.ts to verify field accuracy, idempotency, malformed event skipping, and warn logging.
Added queryTradesPage(creatorId: string, cursor: string | null, limit: number, db: any) helper in src/utils/trade-pagination.utils.ts.
Encodes/decodes (ledger, tx_hash) using HMAC-signed base64url cursors for stable keyset pagination ordered by ledger desc, txHash desc.
Added unit tests in src/utils/tests/trade-pagination.utils.test.ts asserting first page ordering, cursor page traversal, has_more correctness, and record uniqueness across pages.
Updated httpGetCreatorStats in src/modules/creators/creators.controllers.ts and mapPublicCreatorStats in src/modules/creators/creators.stats.ts to query active key holders (KeyOwnership records with balance > 0) and expose both holderCount and holder_count.
Created integration test src/modules/creators/creator-detail-holder-count-sequential.integration.test.ts verifying holder count changes across sequential buys and sells across multiple wallets (0 → 1 → 2 → 2 → 1 → 0).
Added buildLogFields(base: LogFields): Record<string, unknown> in src/utils/log-fields.utils.ts to enforce snake_case keys, ISO 8601 timestamps, and truncation of string values exceeding 500 characters with a [TRUNCATED] suffix.
Applied buildLogFields across server log call sites.
Added unit tests in src/utils/tests/log-fields.utils.test.ts verifying key conversion, ISO timestamp formatting, and string truncation rules.