Skip to content

feat(sep-38): aggregate RFQ quotes with Stellar DEX order book depth … - #668

Merged
Topmatrixmor2014 merged 2 commits into
FinChippay:mainfrom
Killerjunior:feat/issue-347-sep38-quote-aggregation
Aug 18, 2026
Merged

feat(sep-38): aggregate RFQ quotes with Stellar DEX order book depth …#668
Topmatrixmor2014 merged 2 commits into
FinChippay:mainfrom
Killerjunior:feat/issue-347-sep38-quote-aggregation

Conversation

@Killerjunior

Copy link
Copy Markdown
Contributor

feat(sep-38): aggregate RFQ quotes with Stellar DEX order book depth (#347)

Summary

Aggregates SEP-38 RFQ quotes across Stellar DEX order book depth via Horizon, calculating volume-weighted average execution prices, slippage, and price impact with a 2-second cache TTL. It also updates the frontend TradeForm to display order book depth, estimated slippage, and a "Best Price" badge for optimal fills.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / chore
  • Smart contract change

Related issue

Closes #347

Changes

  • Backend Order Book Service (backend/src/services/sep/orderBookService.js):
    • Implemented parseAsset supporting SEP-38 identifiers (stellar:native, stellar:CODE:ISSUER, shorthand assets).
    • Implemented getOrderBook with Horizon /order_book integration and a 2-second Redis/LRU cache TTL.
    • Implemented calculateWeightedPrice to walk order book depth levels, compute volume-weighted execution prices, and handle partial fills.
    • Implemented estimateSlippage to calculate execution slippage against top-of-book and price impact against the marginal fill level.
  • Backend SEP-38 Service & API Routes (backend/src/services/sep/sep38Service.js, backend/src/routes/sep38.js, backend/src/server.js):
    • Added getAggregatedQuote method returning execution price, top-of-book price, slippage %, price impact %, levels consumed, and partial fill indicators.
    • Added GET /api/v1/sep38/quote/aggregated and GET /sep38/quote/aggregated endpoints with full query validation (sell_asset, buy_asset, sell_amount).
    • Mounted /api/v1/sep38 routes in server.js.
  • Frontend Swap Interface (frontend/components/TradeForm.tsx):
    • Integrated fetchAggregatedQuote with client-side 2-second caching.
    • Added "Best Price" badge indicator in the swap preview when aggregated depth provides optimal fill pricing.
    • Displayed order book depth (levels consumed) and estimated slippage in the swap preview panel.
  • Unit & Integration Tests:
    • Added backend/__tests__/orderBook.test.js and updated backend/__tests__/sep38.test.js (single-level fill, multi-level depth fill, partial fill, 2s cache TTL).
    • Added frontend test suite in frontend/__tests__/TradeForm.test.tsx for aggregated quotes, Best Price badge, and depth display.

Testing

  • Tested locally on Testnet
  • Added/updated unit tests
  • Manually tested UI flow

Test Results:

  • backend: jest __tests__/orderBook.test.js __tests__/sep38.test.js (25/25 tests passing)
  • frontend: jest __tests__/TradeForm.test.tsx (41/41 tests passing)
  • Linting & Formatting: ESLint passed with 0 errors; Prettier formatting verified.

Screenshots (if UI change)

Aggregated quote details and "Best Price" badge rendered in the TradeForm swap preview.

Checklist

  • My code follows the project style
  • I've updated docs if needed
  • No console errors or warnings
  • I've rebased on latest main

@github-actions github-actions Bot added the needs-review PR ready for Greptile AI code review label Aug 17, 2026
@github-actions

Copy link
Copy Markdown

🤖 Greptile AI Code Review

Greptile will automatically review this PR (9 file(s) changed).

Review gates:

  • ✅ CodeQL Security Scan
  • ✅ Custom rules (.greptile/config.json)
  • ✅ Architecture guidelines (.greptile/rules.md)

To manually trigger a re-review, comment @greptileai on this PR.
To skip review, add the skip-review label.

@Topmatrixmor2014
Topmatrixmor2014 merged commit 661cad1 into FinChippay:main Aug 18, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review PR ready for Greptile AI code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[New] SEP-38 RFQ Quote Aggregation with Order Book Depth

2 participants