Skip to content

feat: DB models (User, EventLog, Bet index) + Soroban RPC event subscription - #1163

Merged
Ehonrie merged 6 commits into
Netwalls:mainfrom
Sundriveauto:main
Jul 27, 2026
Merged

feat: DB models (User, EventLog, Bet index) + Soroban RPC event subscription#1163
Ehonrie merged 6 commits into
Netwalls:mainfrom
Sundriveauto:main

Conversation

@Sundriveauto

Copy link
Copy Markdown
Contributor

Closes #1061
Closes #1062
Closes #1063
Closes #1064

Summary

This PR implements four tasks that add database models, indexes, and a multi-contract Soroban RPC event subscription system.


Commit 1: UserModel DB table (Task 1)

  • User model with address as primary key (Stellar G…56 format)
  • Stellar address format validation regex in user.model.ts
  • createdAt and updatedAt timestamps

Commit 2: DB schema + migration (Tasks 2 & 3)

  • BetModel: Added composite index @@index([marketId, bettor]) for fast lookups
  • EventLogModel: New table for raw ingested contract events
    • @@unique([txHash, eventType]) guarantees idempotent ingestion
    • processedAt nullable DateTime with index for efficient "unprocessed" queries
    • Stores txHash, eventType, contractId, ledger, ledgerClosedAt, body (JSON)
  • Migration SQL for all three schema changes

Commits 3 & 4: Soroban RPC event subscription (Task 4)

  • Indexer entry point (src/indexer/index.ts): Bootstraps the long-lived event listener
  • Indexer service (src/services/indexer.service.ts):
    • Subscribes to ALL Soroban contract events (no contractIds filter) — dynamically deployed Market contract events are never missed across restarts
    • Writes raw events to EventLog before any downstream processing via persistRawEvents() with idempotent upsert
    • Marks events as processed after successful handling via markEventsProcessed()
    • Exponential backoff reconnection on RPC disconnect (1s → 30s max)

Acceptance Criteria

Task AC Status
1. UserModel address PK, validated as Stellar address Done
2. BetModel FK to MarketModel.marketId, index on (marketId, bettor) Done
3. EventLogModel @@unique(txHash, eventType) for idempotent ingestion, processedAt nullable indexed Done
4. RPC subscription Reconnects with backoff, writes to EventLog before processing Done

Sundriveauto and others added 6 commits July 26, 2026 14:16
- Add User model to Prisma schema with address as primary key
- Stellar address format validation regex (G...56 chars)
- createdAt and updatedAt timestamps

Task 1: Implement the DB table/migration for UserModel
- Add User model: address PK, createdAt, updatedAt
- Add EventLog model: idempotent ingestion via @@unique(txHash, eventType),
  nullable processedAt with index for unprocessed queries
- Add @@index([marketId, bettor]) on Bet for fast lookups
- Migration SQL for all three schema changes

Tasks 1-3: DB table/migration for UserModel, BetModel, EventLogModel
- Bootstraps the indexer by calling startIndexer()
- Graceful crash handling with exit code 1
- Requires STELLAR_RPC_URL, MARKET_FACTORY_CONTRACT_ID, and DATABASE_URL

Task 4 (part 1): Indexer entry point
… processing

- Subscribe to ALL contract events (no contractIds filter) so dynamically
  deployed Market contract events are never missed across restarts
- Write raw events to EventLog table BEFORE downstream processing via
  persistRawEvents() with idempotent upsert on (txHash, eventType)
- Mark events as processed after successful downstream processing via
  markEventsProcessed() using nullable processedAt index
- Exponential backoff reconnection on RPC disconnect (existing behavior)
- Route known events through switch/case handlers, log warnings for unknowns

Task 4: Subscribe to Soroban RPC events for all three contracts
         and persist raw events
…iption

feat: DB models (User, EventLog, Bet index) + Soroban RPC event subscription
@Ehonrie
Ehonrie merged commit 6370970 into Netwalls:main Jul 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants