Skip to content

feat: Sequence Cache, Path Router, Offer Tracker & Claimable Balance Lifecycle - #574

Open
micmusjnr20 wants to merge 5 commits into
Stellar-split:mainfrom
micmusjnr20:main
Open

feat: Sequence Cache, Path Router, Offer Tracker & Claimable Balance Lifecycle#574
micmusjnr20 wants to merge 5 commits into
Stellar-split:mainfrom
micmusjnr20:main

Conversation

@micmusjnr20

@micmusjnr20 micmusjnr20 commented Jul 28, 2026

Copy link
Copy Markdown

Closes #498
Closes #499
Closes #500
Closes #501

Summary

This PR adds four new SDK modules that improve transaction throughput, enable cross-asset payments, track DEX offer lifecycles, and manage claimable balance lifecycles.


1. Sequence Cache (src/sequenceCache.ts)

Prefetches account sequence numbers from Horizon, increments them locally, and eliminates a round-trip latency per payment under high-frequency split invoice submissions.

  • SequenceCache.getSequence(accountId) returns the next sequence number without a Horizon call
  • Automatically invalidates and re-fetches on SEQUENCE_NUMBER_TOO_OLD errors via isSequenceTooOld()
  • Integrates with txBuilder.submitWithSequence() and txBuilder.buildWithSequence()
  • Uses SimpleCache for TTL-based eviction

2. Path Router (src/pathRouter.ts)

Routes cross-asset payments through Stellar's DEX by querying Horizon strictSendPaths / strictReceivePaths to find optimal conversion paths.

  • findStrictSendPath() / findStrictReceivePath() return the cheapest path with estimated amounts
  • Results cached via SimpleCache with per-asset-pair TTL
  • Builds PathPaymentStrictSend / PathPaymentStrictReceive operations
  • Integrates with txBuilder via addPathPaymentStrictSend / addPathPaymentStrictReceive

3. Offer Tracker (src/offerTracker.ts)

Monitors outstanding DEX offers, detects fill progress via Horizon polling, and emits typed lifecycle events.

  • Emits offerFilled, offerPartiallyFilled, offerCancelled events via TypedEventEmitter
  • cancelOffer() submits cancellation transactions
  • Auto-detects stale offers past configurable threshold
  • Adds OfferRecord and OfferStatus types

4. Claimable Balance Lifecycle (extended src/claimableBalanceFallback.ts)

Tracks claimable balances from creation through claim/expiry with Horizon polling and typed event emission.

  • ClaimableBalanceLifecycle class with start()/stop() polling
  • Emits balanceClaimed and balanceExpired typed events
  • claimBalance() submits claimClaimableBalance operations
  • queryByClaimant() lists all pending balances for a claimant
  • Adds ClaimableBalanceRecord and ClaimableBalanceStatus types

Files Changed

File Change
src/sequenceCache.ts New — Sequence cache with Horizon integration
src/pathRouter.ts New — DEX pathfinding router
src/offerTracker.ts New — DEX offer lifecycle tracker
src/claimableBalanceFallback.ts Modified — Added ClaimableBalanceLifecycle
src/txBuilder.ts Modified — Sequence cache integration + path payment ops
src/types.ts Modified — New types for all modules
src/errors.ts Modified — New error types for all modules
src/index.ts Modified — Exports for all new modules
src/client.ts Modified — Fixed duplicate class declaration

…nce numbers

- Add src/sequenceCache.ts: wraps Horizon loadAccount() with local
  sequence-number incrementing to eliminate round-trip latency per
  payment operation under high-frequency split invoice submissions.
- Inject SimpleCache for TTL-based eviction of stale entries.
- Add isSequenceTooOld() helper to detect SEQUENCE_NUMBER_TOO_OLD
  submission errors and trigger cache invalidation.
- Integrate with txBuilder.ts via submitWithSequence() and
  buildWithSequence() to skip loadAccount() when cached.
- Add SequenceCacheError and SequenceNumberTooOldError to errors.ts.
- Add SplitConfig and RecipientShare types.
- Export SequenceCache and isSequenceTooOld from index.ts.
…e balances

- Extend src/claimableBalanceFallback.ts with ClaimableBalanceLifecycle
  class that tracks the create-to-claim lifecycle of claimable balances.
- Polls Horizon for status changes and emits balanceClaimed and
  balanceExpired typed events via TypedEventEmitter.
- Exposes claimBalance() to submit claimClaimableBalance operations.
- Exposes queryByClaimant() to list all pending balances for a claimant.
- Add ClaimableBalanceRecord and ClaimableBalanceStatus to types.ts.
- Add ClaimableBalanceLifecycleError to errors.ts.
- Export ClaimableBalanceLifecycle and related types from index.ts.
- Add src/pathRouter.ts: queries Horizon strictSendPaths and
  strictReceivePaths to find optimal DEX conversion paths when
  payer and recipients use different Stellar assets.
- Caches path results via SimpleCache to avoid redundant queries.
- Exposes buildPathPaymentStrictSend/buildPathPaymentStrictReceive
  helpers to construct path-payment operations.
- Integrates with txBuilder.ts via addPathPaymentStrictSend and
  addPathPaymentStrictReceive methods.
- Add PathNotFoundError and PathRouterError to errors.ts.
- Export PathRouter, PathResult, PathHop, PathRequest, PathRouterConfig
  from index.ts.
- Add src/offerTracker.ts: monitors outstanding DEX offers placed
  during split-payment conversions, detects fill progress via
  Horizon polling, and emits typed events (offerFilled,
  offerPartiallyFilled, offerCancelled).
- Auto-detects stale offers past a configurable threshold.
- Exposes cancelOffer() to submit cancellation transactions.
- Uses TypedEventEmitter for strongly-typed event dispatch.
- Add OfferRecord and OfferStatus to types.ts.
- Add OfferTrackingError to errors.ts.
- Export OfferTracker, OfferTrackerConfig, OfferTrackerEventMap
  from index.ts.
…able

feat: Sequence Cache, Path Router, Offer Tracker & Claimable Balance Lifecycle
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@micmusjnr20 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

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.

DEX Offer Order Tracker Claimable Balance Lifecycle Manager DEX Pathfinding Payment Router Account Sequence Number Prefetch Cache

1 participant