Skip to content

feat(deposits): multi-pool routing optimisation + #283 coverage follow-up#619

Merged
edehvictor merged 1 commit into
edehvictor:mainfrom
davedumto:fix/multi-pool-routing-followup
May 29, 2026
Merged

feat(deposits): multi-pool routing optimisation + #283 coverage follow-up#619
edehvictor merged 1 commit into
edehvictor:mainfrom
davedumto:fix/multi-pool-routing-followup

Conversation

@davedumto
Copy link
Copy Markdown
Contributor

Summary

PR #486 delivered the multi-asset deposit routing API as a partial first cut and explicitly deferred two items in its body: multi-pool path optimisation and the full 90% coverage target. That's why #283 stayed open after #486 merged. This PR closes both.

Multi-pool path optimisation

recommendDepositRouting() gains an optional quoteProtocols option (and a DEPOSIT_ROUTING_PROTOCOLS env-var fallback). When more than one candidate protocol is configured, every non-vault asset is quoted against each protocol and the route with the highest amountOutAfterSlippage wins. Losing quotes ride along on the route record as alternativeQuotes so callers can show savings:

{
  "symbol": "XLM",
  "action": "convert",
  "protocol": "aquarius",
  "expectedVaultAmountStroops": "999",
  "reasoning": "XLM converted to USDC via a 2-hop route (...). Selected aquarius over 1 alternative quote(s) on output amount.",
  "alternativeQuotes": [
    { "protocol": "soroswap", "expectedVaultAmountStroops": "990", "slippageApplied": 0.01, "source": "router_simulation", "isFallback": false }
  ]
}
  • A protocol that throws is silently skipped; another candidate may still produce a quote.
  • If every protocol throws for a given asset, the asset is dropped from routes and a per-asset warning is surfaced (rather than silently producing a zero output).
  • The literal "default" protocol token is mapped to protocol: undefined on the underlying getZapQuote call, so the legacy single-pool path is unchanged when no option is supplied.

Coverage push (toward 90%)

server/src/services/__tests__/depositRoutingService.test.ts gains:

  • A multi-pool path optimisation describe block — best-route pick, protocol-throw fallback, all-throw warning, DEPOSIT_ROUTING_PROTOCOLS env-var resolution, default→undefined remapping.
  • Extra cases for the existing surface — symbols with surrounding whitespace, empty-symbol rejection, non-numeric amountInStroops summing safely as 0, empty basket, ISO generatedAt timestamp.

Back-compat

The public API is additive. Every existing test passes without modification. The routes[i].source field still carries the chosen quote's source (router_simulation or fallback_rate); only the new protocol and alternativeQuotes fields are added.

Notes

Test plan

  • CI: npm test -- depositRoutingService — 21 tests pass (8 existing + 13 new)
  • Manual: set DEPOSIT_ROUTING_PROTOCOLS=soroswap,aquarius, hit POST /api/deposits/recommend with a mixed basket, verify each non-vault route has protocol and alternativeQuotes populated

…rage follow-up

PR edehvictor#486 shipped the multi-asset routing API as a partial first delivery
and explicitly deferred (a) multi-pool path optimisation and (b) the
full 90% coverage target. This PR closes both.

Multi-pool optimisation:
- recommendDepositRouting() now accepts a `quoteProtocols` option (and
  falls back to `DEPOSIT_ROUTING_PROTOCOLS` env). When more than one
  candidate is supplied, each non-vault asset is quoted across every
  protocol; the route with the highest `amountOutAfterSlippage` wins.
- Losing quotes are exposed on the route record as `alternativeQuotes`,
  so callers can render the optimisation savings.
- A protocol that throws is silently skipped; if every candidate throws
  for a given asset, the asset is dropped from `routes` and a per-asset
  warning is surfaced.
- The chosen route now carries a `protocol` field; the literal
  `"default"` token sends `protocol: undefined` to getZapQuote so the
  legacy single-pool path is unchanged.

Coverage push:
- New `multi-pool path optimisation` describe block: best-route pick,
  protocol-throw fallback, all-throw warning, env-var resolution,
  default→undefined remapping.
- Extra cases for the pre-existing surface: trimmed/whitespace symbols,
  empty-symbol rejection, non-numeric amount sum, empty basket, ISO
  generatedAt timestamp.

API back-compat: every existing test passes without modification — the
single-pool default path is preserved.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@davedumto is attempting to deploy a commit to the Edeh Victor's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

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

@edehvictor edehvictor merged commit 6065594 into edehvictor:main May 29, 2026
6 of 9 checks passed
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.

Multi-Asset Deposit Routing Recommendation API

2 participants