Skip to content

feat(correlator): Implement multi-dimensional correlation engine#60

Merged
geminimir merged 1 commit intomainfrom
feature/correlation-engine
Mar 18, 2026
Merged

feat(correlator): Implement multi-dimensional correlation engine#60
geminimir merged 1 commit intomainfrom
feature/correlation-engine

Conversation

@geminimir
Copy link
Owner

Summary

Build the core correlation engine that consumes events from both the stripe-events and chain-transactions Redis Streams, and matches Stripe Payment Intents to on-chain transactions using multi-dimensional heuristics.

Changes

  • StreamConsumer: Redis Streams consumer group for both stripe-events and chain-transactions streams
  • CorrelationEngine: Multi-dimensional matching pipeline with:
    • Exact amount matching with configurable tolerance (default 0.01 USDC)
    • Timing window matching (default +/- 30 minutes)
    • Chain matching (optional hint from Stripe event)
    • Token contract matching
  • Confidence Scoring (0.0-1.0) based on match quality:
    • Amount match: base 40%, up to 50% for exact match
    • Timing match: up to 25% based on proximity
    • Chain match: 15%
    • Token match: 10%
  • RedisCorrelationPublisher: Publishes correlation results to correlation-results stream
  • New shared types: CorrelationCandidate, MatchDetails, CorrelationResult, StripeEventMessage

How to Test

  1. npm ci
  2. npm run typecheck
  3. npm test --workspace=@stripeonchain/correlator

Tests

  • Tests added/updated (24 new tests)
  • Exact match (all four dimensions) produces confidence >= 0.95
  • Amount-only match produces lower confidence
  • No match leaves events in pending state
  • All tests pass (npm test)
  • Lint passes (npm run lint)
  • Formatting passes (npm run format:check)

Checklist

  • No secrets or credentials committed
  • Migrations run cleanly up and down (npm run migrate:up / npm run migrate:down)
  • Docker Compose starts without errors (docker compose up)

Related Issues

Closes #18

Made with Cursor

- Add StreamConsumer for consuming from stripe-events and chain-transactions streams
- Implement CorrelationEngine with multi-dimensional matching:
  - Exact amount matching with configurable tolerance (default 0.01 USDC)
  - Timing window matching (default +/- 30 minutes)
  - Chain matching (optional hint from Stripe)
  - Token contract matching
- Implement confidence scoring (0.0-1.0) based on match quality:
  - Amount match: base 40%, up to 50% for exact match
  - Timing match: up to 25% based on proximity
  - Chain match: 15%
  - Token match: 10%
- Add RedisCorrelationPublisher for publishing results to correlation-results stream
- Add comprehensive types: CorrelationCandidate, MatchDetails, CorrelationResult
- Add 24 unit tests covering all matching scenarios

Closes #18

Made-with: Cursor
@geminimir geminimir merged commit 73e9ab5 into main Mar 18, 2026
1 check passed
@geminimir geminimir deleted the feature/correlation-engine branch March 18, 2026 07:46
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.

Implement correlation engine: multi-dimensional matching

1 participant