Repository navigation
feat: provide split routing recommendations minimizing slippage acros… - #320
p70436464-prog wants to merge 2 commits into
Conversation
…s venues
- Calculate proportions per venue for a given size that minimise total slippage
- Return split proportions only when splitting beats the single-venue route
- Include single-venue alternative comparison in response
- Add GET /price/:assetA/:assetB/split route filtering on and echoing network
- Fully declare /price/{assetA}/{assetB}/split and schemas in openapi.yaml and openapi.json
- Add vitest tests covering size where splitting wins and where it does not
|
@p70436464-prog 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! 🚀 |
|
CI is red, and both of your open PRs fail on the same file for the same reason —
const { mockThing } = vi.hoisted(() => ({ mockThing: vi.fn() }))
vi.mock('../network/clients', () => ({ getHorizonServer: mockThing }))
There is a second trap behind this one, specific to mocking Separately: #320 and #322 both carry |
tsc --noEmit clean vitest 97 files, 1135 passing dropped-tests none #311 adaptive slippage impact endpoint #323 trade size and volume concentration metrics #320 and #322 screened clean individually but conflict once #311 and #323 are in -- all four touch the same routing and pricing surface. They need a rebase rather than a fix; noted on both. Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB
Miracle656
left a comment
There was a problem hiding this comment.
Needs a rebase. This screened clean on its own — tsc --noEmit passes against main as it was — but conflicts once #311 (adaptive slippage) and #323 (trade size and volume concentration) are in, and those landed as b906b47.
All four touch the same routing and pricing surface, which is why they collided rather than merged. Nothing is wrong with the code.
Rebase on current main and re-run npx vitest run before re-requesting. Two things worth checking while you are there, because both have caught PRs in this repo today:
- the logging-hygiene test forbids
console.*in non-test source — usecreateLogger(three PRs tripped this in two batches) tests/openapi.test.tsfails if you document a route without registering it insrc/app.ts, or the reverse
Happy to take it as soon as it is green.
Miracle656
left a comment
There was a problem hiding this comment.
Scanned clean. Rebased cleanly onto current main — no conflicts at all now, which is what the last round was about. But it no longer compiles, and the cause is different from last time.
npx tsc --noEmit gives 5 errors, all of them the same thing: src/aggregator/splitRoute.ts and src/api/rest.ts import five symbols that do not exist anywhere.
src/aggregator/splitRoute.ts(6): '"../types"' has no exported member 'SplitRecommendation'
src/aggregator/splitRoute.ts(7): '"../types"' has no exported member 'SplitVenueAllocation'
src/aggregator/splitRoute.ts(8): '"../types"' has no exported member 'SplitComparison'
src/aggregator/splitRoute.ts(9): '"../types"' has no exported member 'SplitProvenance'
src/api/rest.ts(20): '"./schemas"' has no exported member 'splitResponseSchema'
The branch does not touch src/types.ts or src/api/schemas.ts:
$ git diff --stat origin/main L320 -- src/types.ts src/api/schemas.ts
(no output)
and they are not on main either:
$ git grep -ln "SplitRecommendation\|splitResponseSchema" origin/main -- src
(no output)
So the four types and the response schema were never committed. My guess is they were dropped during the rebase — a rebase that resolves a conflict in src/types.ts by taking main's side wholesale would do exactly this, silently, because the file then has no marker left to notice. src/types.ts and src/api/schemas.ts are two of the most contended files in this repo right now, so they are the easiest place for it to happen.
Worth checking your reflog or the pre-rebase commit for them before rewriting from scratch; they almost certainly still exist.
Two notes for when you add them back:
splitResponseSchemais the wire contract for/split, so whatever shape it declares is what clients get. It needs to match what the route actually returns, andtests/openapi.test.tswill hold you to documenting the route inopenapi.yamltoo — every documented path must be registered and every registered non-internal route must be documented.- Paths in
openapi.yamlnow carry the/v1prefix (97c50bf). A new route is registered at its bare path and documented at/v1/<path>; the version segment is resolved byrewriteUrl, so you do not register it twice.
The split-routing logic itself I have no complaint about — minimising slippage across venues is worth having, and 351 lines of it with tests is real work. It just cannot be reviewed properly until it builds.
Get npx tsc --noEmit clean and re-request, and I will take it quickly.
Closes #296
Summary
Best route previously picked a single venue. For orders large enough to experience price impact, splitting volume across venues (SDEX and AMM) beats routing the entirety to a single venue.
This PR adds split routing recommendations that calculate optimal proportions per venue to minimize total slippage for a given swap size:
singleVenueRoute,singleVenueOutput,outputImprovement,outputImprovementPct) are included in the response.req.network ?? activeNetwork, scopes pool queries, and echoesnetworkin the response.GET /price/:assetA/:assetB/splitwith?network=query parameter inopenapi.yamland synchronizesopenapi.json.Testing
src/__tests__/splitRoute.test.tscovering:src/__tests__/schemaValidation.test.ts.