Skip to content

DEX Pathfinding Payment Router #499

Description

@Kingsman-99

Description

When the payer and recipients use different Stellar assets, the SDK must route payment through Stellar's decentralised exchange pathfinding to find the best conversion path. Currently the SDK only supports direct same-asset payments and rejects cross-asset invoices. A DEX pathfinding router should query findStrictSendPaths or findStrictReceivePaths on Horizon and select the optimal path for each split leg.

Technical Context

Add src/pathRouter.ts. Uses @stellar/stellar-sdk Server.strictSendPaths() and Server.strictReceivePaths() methods. Consumes SplitConfig.paymentAsset and RecipientShare.receiveAsset from src/types.ts. Integrates with src/txBuilder.ts to replace Payment operations with PathPaymentStrictSend or PathPaymentStrictReceive operations when paths are needed. Caches path results via src/cache.ts.

Acceptance Criteria

  • PathRouter.findBestPath(sourceAsset, destAsset, amount): Promise<PathResult> returns the highest-value path from Horizon
  • Automatically selects strictSend vs strictReceive based on whether the payer or recipient amount is the fixed quantity
  • Falls back to a direct payment operation when source and destination assets match
  • src/txBuilder.ts calls PathRouter per recipient leg and builds the appropriate operation type
  • Unit tests cover: same-asset short-circuit, cross-asset path found, no path available (throws NoPathError)
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions