feat(indexer): hybrid orderbook sim for CG/CMC depth (pool + limit book) #220
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#220
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?
Summary
Extend
/cg/orderbookand/cmc/orderbook/*depth generation from pool-only AMM curve-walk to a hybrid-simulated book that merges constant-product pool levels with on-chain FIFO limit order depth, so listing endpoints reflect CL8Y’s production execution model (pool + limit book).Parent / prerequisite: #210 (AMM curve-walk with
ceil_div+fee_bps). Related: #108 (hybrid disclosure), #194 (deep limit book LCD proxy).Current codebase
indexer/src/api/orderbook_sim.rswalk_amm_book+ LCDpool/pairs.fee_bps; used by CG/CMC orderbook handlersindexer/src/api/cg.rscg_orderbooksimulate_orderbook_cached; returns AMM-simbids/asksonlyindexer/src/api/cmc.rscmc_orderbookindexer/src/api/limit_book_lcd.rslimit-book, paginated); not wired to CG/CMCindexer/src/api/hybrid_route_opt.rs/api/v1/route/solve*— not orderbook depth exportdocs/CG_CMC_COMPLIANCE.md§ AMM Orderbook Simulation;docs/limit-orders.mdstates CG/CMC depth is curve-sim only#210 closed the AMM stub gap; CG/CMC responses still omit resting limit liquidity that traders see on
/tradeviaOrderBookPanel+limit-book.Why this is needed
docs/integrators.mdand #108 require clear hybrid disclosure — a labeled hybrid-sim book is preferable to silent pool-only depth.Constraints and guardrails
max_maker_fills-style walks; cache merged books (TTL aligned withdocs/indexer-invariants.md).fee_bps+ceil_divper #210. Book legs: use on-chain limit prices/sizes; fee on fills per pair rules (no trader discount tiers on public API).limit-bookintegrator API; frontendOrderBookPanel; Prometheus (#200).Relevant files
indexer/src/api/orderbook_sim.rsindexer/src/api/limit_book_lcd.rsindexer/src/api/cg.rs,cmc.rsindexer/src/api/mod.rsOrderbookCache, routesindexer/tests/api_orderbook_lcd_mock.rsindexer/tests/api_limit_book_deep.rsdocs/CG_CMC_COMPLIANCE.md,docs/limit-orders.mdskills/AGENTS_INDEXER_AMM_ORDERBOOK_SIM.mdRecommended direction
hybrid_orderbook_simmodule (or extendorderbook_sim):build_hybrid_book(pool_reserves, limit_bids, limit_asks, depth, fee_bps) -> OrderbookData.poolpath; limits fromlimit_book_lcdpage walk up to N orders per side (reuse pagination caps from #194).(pair, depth, fee_bps, book_head_hash_or_version)to avoid stale merge when book moves.ORDERBOOK_HYBRID=1for staged rollout; default on once tested.Acceptance criteria
/cg/orderbookand/cmc/orderbook/*include both AMM-walk levels and resting limit levels when the pair has on-chain book liquidity (per merge spec).docs/CG_CMC_COMPLIANCE.mdupdated (hybrid-sim, not “AMM only”).Test plan — functional paths
depth=1depth(cap)Run:
cd indexer && cargo test orderbook hybrid limit_book api_orderbook -- --test-threads=1Test plan — attack vectors / abuse
depth=100+ book paginationVerification criteria
/cg/orderbooklevels tolimit-book+ pool spot for one localnet pair.cargo testorderbook + limit_book suites green.marked as related to #210
marked as related to #108
marked as related to #194
mentioned in issue #210
Implemented (merged to
main—8b595c8)CG/CMC orderbook endpoints now return hybrid-simulated depth: constant-product pool curve levels merged with resting on-chain FIFO limit orders (LCD
order_book_head+limit_orderwalk, bounded per side).What changed
indexer/src/api/hybrid_orderbook_sim.rs— price-sorted merge, same-price qty sum, per-side truncation (works with Openware total-depth split #221 vialevels_per_side).orderbook_sim.rs— wires hybrid merge by default; cache key(pair, requested_depth, fee_bps, bid_head, ask_head);ORDERBOOK_HYBRID=0for pool-only rollback./cg/orderbookand/cmc/orderbook/*— same merge logic; OpenAPI descriptions updated.docs/CG_CMC_COMPLIANCE.md§ Hybrid Orderbook Simulation,docs/indexer-invariants.md,docs/limit-orders.md.skills/AGENTS_INDEXER_AMM_ORDERBOOK_SIM.md(+AGENTS_TESTING_P2_EPIC.mdcrosslink).hybrid_orderbook_sim) +api_orderbook_lcd_mock(incl.start_hybrid_orderbook_mock).Disclosure
Responses are indicative simulation (pool + resting limits), not a live CEX L2 feed or guaranteed fill quote.
Verification checklist
Please confirm on staging/localnet:
/cg/orderbookand/cmc/orderbook/:pairshow limit prices in the merged ladder (compare toGET /api/v1/pairs/{addr}/limit-book).depth=100→ 50 bids + 50 asks (Openware #221);depth=1→ 1+1.ORDERBOOK_HYBRID=0restores pool-only behavior.CG_CMC_COMPLIANCE.md.Tests run:
cargo test --lib orderbookandcargo test --test api_orderbook_lcd_mock -- --test-threads=1(green).@brouie — could you verify on your side when convenient? Leaving this issue open until sign-off.
mentioned in commit
e2f717f25bmentioned in commit
8b595c89f3Verification run (worktree
verify/issue-220, agent)Verified hybrid CG/CMC orderbook implementation on localnet + CI tests. No code changes were required;
mainis already up to date with the #220 merge (8b595c8lineage).What was checked
Automated (worktree
indexer/):cargo test orderbook -- --test-threads=1— 19 unit tests green (pool walk + hybrid merge)cargo test hybrid -- --test-threads=1— hybrid merge unit tests greencargo test limit_book -- --test-threads=1— limit book integration tests greencargo test api_orderbook -- --test-threads=1— 10/10api_orderbook_lcd_mocktests green (hybrid mock, CG/CMC parity, cache, Openware depth split)Manual (indexer @
:3001, LocalTerra @:26657):EMBER_ONYXbid @45.920642…) appears in/cg/orderbookmerged ladder3999866base from quote escrow) present in bidsEMBER_CORAL)depth=100→ 50 bids + 50 asksdepth=1→ 1+1CG_CMC_COMPLIANCE.md§ Hybrid Orderbook Simulation,indexer-invariants.md,limit-orders.md,skills/AGENTS_INDEXER_AMM_ORDERBOOK_SIM.mdNote on ask-side truncation:
CORAL_JADEhas a resting ask @0.011617…, but pool-sim asks are better (lower) down to ~0.01024. Withdepth=100(50/side cap) the limit ranks ~#51 and is correctly truncated — not a merge bug.Not live-tested:
ORDERBOOK_HYBRID=0rollback (would require indexer restart with env; code path + docs verified).Acceptance criteria status
Checklist for @brouie
docs/CG_CMC_COMPLIANCE.mdis acceptable for CoinGecko/CoinMarketCap listing teams/cg/orderbookvs/api/v1/pairs/{addr}/limit-book?side=bid|ask)ORDERBOOK_HYBRID=0rollback behavior if ops needs pool-only stagingLeaving open pending product sign-off. @brouie
Product sign-off received
Hybrid disclosure wording in
docs/CG_CMC_COMPLIANCE.md(§ Hybrid Orderbook Simulation) is approved:All verification criteria from #220 (acceptance + manual/CI checks from prior verification run) are pass. Closing.
mentioned in issue #224
mentioned in issue #279
mentioned in merge request !761
mentioned in issue #319
marked as related to #319
mentioned in issue #597
mentioned in issue #685