Skip to content

feat: implement On-Chain Event Correlation Service#643

Open
nazteeemba wants to merge 1 commit into
Pulsefy:mainfrom
nazteeemba:feat/on-chain-event-correlation-v2
Open

feat: implement On-Chain Event Correlation Service#643
nazteeemba wants to merge 1 commit into
Pulsefy:mainfrom
nazteeemba:feat/on-chain-event-correlation-v2

Conversation

@nazteeemba

Copy link
Copy Markdown

Closes #546

Summary

Implements the On-Chain Event Correlation Service — a NestJS module that automatically fetches Soroban smart contract events, maps them to internal AidPackage and Claim records by package_id/claim_id, and persists the mapping (tx hash, ledger, event topic) idempotently. Correlated events are surfaced on the claim and package read endpoints.

Changes

New files

File Description
prisma/migrations/.../migration.sql Creates OnChainEvent and CorrelationCursor tables with unique index and 4 query indexes
src/onchain/event-correlation/event-mapper.ts Pure EventMapper — decodes ScVal topics/values, extracts package_id/claim_id, DB lookups, full error handling
src/onchain/event-correlation/event-correlation.service.ts correlate() with cursor-based ledger resumption, @Cron scheduler (every 5 min), isRunning concurrency guard
src/onchain/event-correlation/event-correlation.controller.ts POST /v1/onchain/events/correlate — on-demand trigger with ledger validation, HTTP 502 on RPC failure
src/onchain/event-correlation/dto/correlation-result.dto.ts CorrelationResult interface

Modified files

File Change
prisma/schema.prisma Added OnChainEvent and CorrelationCursor models
src/onchain/onchain.module.ts Registered EventMapper, EventCorrelationService, EventCorrelationController
src/onchain/aid-escrow.controller.ts GET /onchain/aid-escrow/packages/:id returns onChainEvents array
src/onchain/aid-escrow.module.ts Added PrismaService to providers
src/claims/claims.service.ts findOne includes onChainEvents array (always present, empty when no events)

Acceptance criteria

  • Correlation runs on-demand via POST /v1/onchain/events/correlate
  • Correlation runs automatically on a 5-minute cron schedule
  • Correlated data exposed on GET /v1/claims/:id and GET /onchain/aid-escrow/packages/:id
  • Mapper logic covered by unit tests (P1–P4 property tests + E1–E10 example tests)

Testing

# From app/backend/
npx prisma migrate deploy
npx jest --testPathPattern="event-mapper|event-correlation" --run

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@nazteeemba is attempting to deploy a commit to the Cedarich's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@nazteeemba 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! 🚀

Learn more about application limits

@Cedarich

Copy link
Copy Markdown
Contributor

@nazteeemba

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.

Add On-Chain Event Correlation Service (Package + Claim)

2 participants