Skip to content

feat(aggregator): multi-hop swap routing through configurable interme… - #585

Merged
Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
dmoonventure070-art:feat/multi-hop-routing
Oct 22, 2026
Merged

Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
dmoonventure070-art:feat/multi-hop-routing

Conversation

@dmoonventure070-art

Copy link
Copy Markdown

Closes #295

feat(aggregator): Multi-hop Swap Routing through Intermediate Assets

Summary

Implements bounded multi-hop routing for Stellar asset swaps in src/aggregator/bestRoute.ts. Previously, bestRoute only compared direct SDEX vs AMM pools. For thin pairs, direct execution routinely incurs heavy slippage or insufficient liquidity where two-hop routes through liquid assets (such as XLM or Circle USDC) offer significantly better output.

Key Changes

  • Multi-hop Routing Engine:
    • Explores multi-hop execution paths up to maxHops depth (configured via ROUTING_MAX_HOPS, defaulting to 3).
    • Evaluates routes across configurable intermediate assets (configured via ROUTING_INTERMEDIATES, defaulting to native XLM and Circle USDC with whole issuer addresses).
    • Simulates each hop against SDEX strict-send paths and AMM constant-product reserves.
    • Names each hop with assetIn, assetOut, venue, poolId, price, spotPrice, and slippagePct.
    • Compounds overall slippage across hops.
  • Direct vs. Multi-hop Comparison:
    • Retains direct route recommendations when direct execution beats intermediate paths.
    • Returns comparison in the payload displaying both direct execution and multiHop options side-by-side.
  • Provenance & Network Scope:
    • Includes a provenance block on every response stating sampledAt, network, venuesQueried, sampleCount, and freshnessSeconds.
    • Exposes ?network= query parameter handling on GET /price/:assetA/:assetB/route.
  • API Spec & Schema Updates:
    • Updated Fastify JSON schemas in src/api/schemas.ts.
    • Updated OpenAPI specifications in openapi.yaml and regenerated openapi.json.
    • Updated GraphQL SDL in src/api/graphql.ts and regenerated schema.graphql.
    • Added changeset in .changeset/multi-hop-routing.md.
  • Testing:
    • Added unit test cases covering thin pairs where two hops beat direct routes.
    • Added tests ensuring direct route wins when better and verifying maxHops configuration bounds.
    • Verified full test suite (npm test, 85 test files, 919 passing tests) and tsc --noEmit.

…diate assets

- Evaluate multi-hop paths across configurable intermediates (ROUTING_INTERMEDIATES, defaulting to XLM and Circle USDC) up to ROUTING_MAX_HOPS depth bound
- Detail each hop with venue (SDEX/AMM), poolId, price, spot price, and slippage percentage
- Provide side-by-side comparison between direct and multi-hop routes, preferring direct when superior
- Include provenance metadata with query timestamps, network, venues queried, sample counts, and data freshness age
- Expose network parameter on GET /price/:assetA/:assetB/route and declare schema updates in openapi.yaml and schema.graphql
- Add unit and property test coverage verifying multi-hop route selection on thin pairs
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@dmoonventure070-art 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

@Miracle656
Miracle656 merged commit 3c836b8 into Divinity-Labs:main Oct 22, 2026
Miracle656 added a commit that referenced this pull request Oct 22, 2026
  tsc --noEmit   clean
  vitest         106 files, 1232 passing (up from 102 / 1157)
  dropped-tests  none

Four of the eight screened in this group. The other four were held, and the
reason is worth stating because it keeps recurring: each one merges cleanly
and fails on its own.

  #590  72 type errors alone, including syntax errors in src/api/rest.ts and
        src/api/schemas.ts -- "Declaration or statement expected",
        "Expression expected". Not type mismatches; the file does not parse.
  #584  3 type errors alone
  #592  conflicts
  #595  conflicts

Merged together before screening, that group produced 68 failing test files
and syntax errors I first mistook for a bad three-way merge. They were not:
#590 carries them on its own branch. Screening each PR individually before
batching costs one typecheck per PR and saves an hour of bisection, which is
the lesson of the day.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB
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.

The best route ignores multi-hop paths

2 participants