Docs: Route solver in-depth guide + optimization theory #310
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#310
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Current codebase
The indexer route solver lives primarily in:
indexer/src/api/route_solver.rs— GET/POST/api/v1/route/solve, BFS path discovery, cache (ROUTE_CACHE_TTL), hop caps (3 hybrid / 4 pool-only).indexer/src/api/hybrid_route_opt.rs— per-hop and joint hybrid split optimization (coordinate descent, grid points).indexer/src/api/best_execution.rs(if present) — top-K path enumeration, winner selection via LCDsimulate_swap_operations.docs/adr/0002-global-best-execution-route-solver.md) — high-level decision record (#209).skills/AGENTS_INDEXER_HYBRID_BEST_EXECUTION.md.Terminology is scattered across ADR 0001/0002,
docs/indexer-invariants.md, API OpenAPI schemas (RouteQuoteKind,solver_version,optimality_scope), and inline Rust comments. There is no single in-depth explainer for integrators or contributors covering algorithm steps, notation, and known non-optimality bounds.Optimization implementation uses heuristics (top-5 paths, 17-point grids, 2 coordinate-descent passes) without documented ties to classical graph/routing literature.
Why this is needed
Contributors and integrators need one authoritative doc to understand what the solver optimizes, what it does not guarantee, and how hybrid legs interact across hops. Without this, clients misread
hybrid_notes/optimality_scope, over-trust quotes, or duplicate partial logic.A research-grounded optimization section helps justify future algorithm changes (e.g. Yen's k-shortest paths, convex split search, liquidity-weighted edge costs) and sets expectations for audit / compliance reviews.
Constraints / guardrails
max_spread/min_receiveon-chain is authoritative.MAX_PATH_CANDIDATES,AMOUNT_CACHE_BUCKET, LCD budgets) — no aspirational algorithms presented as shipped.frontend-dappswap routing) should cross-link but is out of scope unless terminology overlaps.Relevant files
indexer/src/api/route_solver.rsindexer/src/api/hybrid_route_opt.rs,hybrid_orderbook_sim.rsdocs/adr/0001-hybrid-quoting-and-routing.md,docs/adr/0002-global-best-execution-route-solver.mddocs/indexer-invariants.mdskills/AGENTS_INDEXER_HYBRID_BEST_EXECUTION.mdindexer/tests/route / hybrid integration testsRecommended direction
Documentation deliverable (
docs/route-solver.mdor extend ADR appendix)book_input/pool_input,RouteQuoteKind, degraded hybrid,solver_version.pool_onlyescape hatch,amount_inrequirement for optimization.Optimization theory section
Relate implemented heuristics to literature (with citations):
find_paths_top_kcapbook_inputgrid + CD passesInclude a “future work” subsection: when to upgrade k, grid density, or add edge-weight pruning — tied to gas/LCD cost.
Acceptance criteria
docs/with glossary, pipeline, API matrix, and non-goals.docs/indexer-invariants.mdand ADR 0002 link to the new doc./route/solvefields align with glossary terms.optimality_scopestrings returned by API.Test plan (all paths)
route_solver.rs/best_execution.rsAttack / abuse / hack vectors
optimality_scopeexplained with boundsVerification criteria
curlsample GET/api/v1/route/solve?...interpreted correctly using only the new doc.docs/READMEor architecture index if one exists.mentioned in commit
b8a51aadc3mentioned in merge request !784
Implementation complete for https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/work_items/310
MR: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/66
Deliverables
docs/route-solver.md— glossary, pipeline (mermaid), GET/POST matrix, non-goals, shipped constants, optimization theory (6 heuristics × code locations × literature), abuse vectors, curl interpretation guideindexer-invariants.md,docs/README.md,integrators.md,skills/AGENTS_INDEXER_HYBRID_BEST_EXECUTION.mdSolveRouteParams,RouteSolveResponse,RouteQuoteKind,HybridHopJson,SolveRoutePostBodyscripts/check_route_solver_docs.py+make check-route-solver-docsVerification
python3 scripts/check_route_solver_docs.pycd indexer && cargo test --lib route_solver --Issue left open for maintainer technical review per acceptance criteria.
mentioned in commit
feb8b3c327Verification — issue #310 (agent:verify)
Issue: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/work_items/310
Implementation: merged via !784 (
b8a51aaonmain)Acceptance criteria
docs/with glossary, pipeline, API matrix, non-goalsdocs/route-solver.mdpresent onorigin/main; sections: Glossary, Pipeline (mermaid), API matrix, Non-goals, Shipped constantsdocs/indexer-invariants.mdand ADR 0002 link to new docgrep route-solverin both; ADR 0002 Links sectionindexer/src/api/route_solver.rs—SolveRouteParams,RouteSolveResponse,RouteQuoteKind,SolveRoutePostBodydoc comments referencedocs/route-solver.mdand glossary termsoptimality_scopeAPI stringpython3 scripts/check_route_solver_docs.py(fullOPTIMALITY_SCOPEin doc); tie-break text matchesbest_execution.rs(out_u > prevonly)Test plan
make check-route-solver-docs→ OKdocs/route-solver.mdresolve (./adr/…,./indexer-invariants.md,../skills/…, etc.)quote_kindvalues matchRouteQuoteKindsnake_caseserde; integration tests assertsolver_version,optimality_scope,quote_kindscripts/check_route_solver_docs.py+make check-route-solver-docscd indexer && cargo test --lib route_solver --— 5 passedcurlGET sampleindexer/.envabsent, port 3001 down). Doc includes curl + field interpretation guide (§ API matrix). Covered byindexer/tests/api_route_solve.rsglobal metadata tests on mock LCD.Architecture index
docs/README.mdMaintainer review
Listed in issue acceptance criteria — out of scope for automated verify (implementation already merged).
Outcome: All acceptance criteria PASS on
main. Closing as verified.