Skip to content

feat(indexer): decode real Soroban XDR events and validate envelopes (closes #43) - #44

Open
shobhamerabacha-star wants to merge 1 commit into
OBP-ORG:mainfrom
shobhamerabacha-star:fix/issue-43-decode-soroban-xdr-events
Open

shobhamerabacha-star wants to merge 1 commit into
OBP-ORG:mainfrom
shobhamerabacha-star:fix/issue-43-decode-soroban-xdr-events

Conversation

@shobhamerabacha-star

Copy link
Copy Markdown

Summary of Changes

Closes #43

This PR implements proper Stellar Soroban ScVal XDR event decoding and strict envelope validation for the OrbitPay analytics indexer, replacing loose object stringification and shallow spreading.

Key Implementations:

  1. Soroban ScVal XDR Decoding (src/lib/indexer/decoder.ts):
    • Explicitly decodes xdr.ScVal instances, wrapped { xdr: string } responses, and base64 XDR strings using scValToNative.
    • Losslessly handles addresses (Address to public key string), 64-bit and 128-bit integers (u64, i128, u32, i32), symbols, maps, vectors, booleans, and timestamps.
  2. Strict Event Envelope Validation:
    • Validates that eventId, ledger (> 0 integer), txHash, contractId, and non-empty topic are present and valid.
    • Treats missing or manufactured identities ("unknown", 0, empty strings) as visible decode failures rather than projecting corrupt entities.
  3. Dead-Letter Quarantining & Metrics Integration (src/lib/indexer/engine.ts):
    • Captures visible decode failures, increments decodeFailures.inc({ contract }), and records them in prisma.deadLetterEvent table.
    • Enforces KNOWN_TOPICS per configured contract (treasury, payroll, vesting, governance) and quarantines unknown topics with QuarantineError.
  4. Comprehensive Test Suite (src/__tests__/decoder.test.ts):
    • Unit tests covering envelope failures, ScVal primitive and struct decoding.
    • Real captured SDK-shaped fixtures for Treasury (TreasuryDeposit), Payroll (StreamCreated), and Governance (VoteCast).

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.

[Hard] Decode real Soroban XDR events before projection

1 participant