Skip to content

feat(cbc): cooperative batch clearing module over house vaults#123

Draft
JaeLeex wants to merge 1 commit into
jae/house-modulefrom
jae/cbc-module
Draft

feat(cbc): cooperative batch clearing module over house vaults#123
JaeLeex wants to merge 1 commit into
jae/house-modulefrom
jae/cbc-module

Conversation

@JaeLeex

@JaeLeex JaeLeex commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add nunchi-cbc: uniform-price cooperative batch clearing (PRD in PRD: Hybrid AMM design — house + CBC + off-chain bin manager #119). Signed intents from house vaults and allowlisted MMs rest in per-market queues; the keeper closes batches; all executable fills clear at one deterministic price and settle through nunchi-house's checked clearing API.
  • Price discovery maximizes executable volume over intent limit prices plus the oracle price, so batches clear exactly at oracle whenever it sits inside the volume-maximizing range (matches the PRD worked example); ties break toward oracle, then lower. Out-of-band prices record OutsideBand and leave the queue untouched.
  • Buy intents reserve worst-case quote (limit × qty) in the house module at submission — a vault can never distort the batch price with intents it cannot settle. Allocation walks submission order; each matched chunk validates both sides against live house state (mode gates, reducing capacity, caps, leverage) and settles immediately, so settlement is conservation-preserving by construction.
  • Intents rest across batches (partial fills stay pending), reduce-only quantities cap against inventory, and batch results (outcome, prices, aggregate fills, retired intents) are the queryable event surface for ABM reconciliation.

Trust seams (documented in README)

  • Keeper posts the oracle price per clearing call — interim seam until oracle-module wiring; this is why CloseAndClearBatch is keeper-gated, not permissionless.
  • Sell intents post no collateral (bounded by notional caps + house exposure checks); economic short margining arrives with perps wiring.
  • KKT risk-weighted clearing (gamma/c) is the v1.1 price-rule upgrade.

Test plan

  • cargo test -p nunchi-cbc (11 tests, including the PRD worked example end-to-end: house +1,200 long sells vs two MM bids → clears 1,000 @ oracle 10,000, house left +200 PartiallyFilled, quote conserved across free+reserved balances)
  • cargo check --workspace --all-targets
  • cargo check -p nunchi-cbc --no-default-features
  • cargo clippy -p nunchi-cbc --all-targets -- -D warnings

Stacking

Base is jae/house-module#119#117. This completes the on-chain half of the hybrid AMM stack; the ABM stays off-chain per the PRD.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.05556% with 391 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cbc/src/rpc.rs 0.00% 144 Missing ⚠️
cbc/src/ledger.rs 80.00% 64 Missing and 64 partials ⚠️
cbc/src/types.rs 75.89% 7 Missing and 47 partials ⚠️
cbc/src/genesis.rs 0.00% 35 Missing ⚠️
cbc/src/transaction.rs 78.88% 9 Missing and 10 partials ⚠️
cbc/src/db.rs 87.91% 10 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@JaeLeex
JaeLeex marked this pull request as draft July 8, 2026 12:34
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.

1 participant