-
Notifications
You must be signed in to change notification settings - Fork 13
Take orders V6 SDK implementation #2388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2025-12-18-exact-swap
Are you sure you want to change the base?
Conversation
…currency control [skip ci]
- Add PRAGMA quick_check query to detect database corruption at startup - Add check_integrity() method to BootstrapPipeline trait - Reset database automatically when corruption is detected - Handle both cases: non-"ok" response and query errors (severe corruption) - Add IntegrityCheckRow struct to parse JSON response from quick_check
- split monolithic take_orders.rs into focused modules - candidates.rs: TakeOrderCandidate building from orders - simulation.rs: buy/spend simulation over candidates - config.rs: TakeOrdersMode enum and config building - price.rs: Float comparison utilities
- make_candidate: creates TakeOrderCandidate for unit tests - make_simulation_candidate: creates candidate for simulation tests
- get_take_orders_calldata: public API for generating takeOrders4 calldata - request.rs: input parsing and validation - selection.rs: cross-orderbook simulation and selection - result.rs: calldata result construction with pricing info - comprehensive e2e tests with mock subgraph/rpc
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Improves readability of INPUT_TOKENS_CLAUSE_BODY and OUTPUT_TOKENS_CLAUSE_BODY by converting from single-line strings with embedded \n to proper multi-line string literals.
…med-fix Add database integrity check to detect and recover from corruption
…ified When filtering orders by tokens with both inputs and outputs provided, the query now uses OR semantics (token in inputs OR token in outputs) instead of AND semantics. This fixes the UI behavior where selecting a token should show all orders involving that token on either side. - Local DB: Combined EXISTS clause with OR inside when both have tokens - Subgraph: Two separate filter objects in the OR array
…-orders-candidates
Verify that input token params come before output token params in the combined OR clause construction.
…-orders-candidates
When inputs and outputs lists are identical, use OR logic for "any-IO" filtering (UI use case). When they differ, use separate EXISTS clauses with AND logic to support directional filtering (SDK use case).
…-orders-candidates
Use buffered() instead of buffer_unordered() to preserve input order when zipping orders with their quote results.
Brings in token filtering changes and database integrity check. The race condition fix (buffer_unordered -> buffered) was already present in the refactored SDK module structure.
Code reviewFound 1 issue:
Documentation states: But implementation shows mode-dependent behavior: let max_sell_cap = if mode.is_buy_mode() {
mode.target_amount().mul(price_cap)? // buy: amount * priceCap
} else {
mode.target_amount() // spend: just amount
};rain.orderbook/crates/common/src/raindex_client/take_orders/mod.rs Lines 59 to 61 in f42c905
rain.orderbook/crates/common/src/raindex_client/take_orders/result.rs Lines 59 to 65 in f42c905
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Chained PRs
Motivation
See issues:
This is the V6 implementation of the take orders SDK, replacing the V5 version from #2360.
The V6 interface (from #2366) provides better exact swap support with
minimumIO,maximumIO, andmaximumIORatioparameters, enabling four distinct trading modes: buy exact, buy up to, spend exact, and spend up to.Solution
SDK Layer (
crates/common/src/take_orders/)Modular SDK for take orders simulation and config building:
candidates.rs- BuildTakeOrderCandidatefrom orders with concurrent quote fetchingsimulation.rs- Simulate buy/spend modes over candidates with price-cap filteringconfig.rs-TakeOrdersModeenum andTakeOrdersConfigV5buildingprice.rs- Float comparison utilitiesAPI Layer (
crates/common/src/raindex_client/take_orders/)Public API for generating takeOrders4 calldata:
get_take_orders_calldata- Main entry point that fetches orders, simulates, and returns calldatarequest.rs- Input parsing and validationselection.rs- Cross-orderbook simulation and best-yield selectionresult.rs- Calldata result with pricing info (effective price, per-leg prices, max sell cap)Key Features
buyExact,buyUpTo,spendExact,spendUpToChecks
By submitting this for review, I'm confirming I've done the following: