Add batch order quotes WASM binding with RaindexOrders wrapper#2482
Add batch order quotes WASM binding with RaindexOrders wrapper#2482
Conversation
New orders_list module with wasm_bindgen constructor, push, items getter, and inner() accessor. Registered in mod.rs.
- Add get_order_quotes_batch free function that batches all order pairs into a single multicall and groups results per-order - Add getOrderQuotesBatch wasm_export on RaindexClient accepting &RaindexOrders - Update candidates.rs to use the batch function - Change gas param from Option<String> to Option<u64> on getQuotes and getOrderQuotesBatch
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (4)
WalkthroughAdds batch order-quoting: new RaindexOrders wrapper and a batched get_order_quotes_batch API (with wasm bindings), replaces per-order concurrent quote fetching with a single batched call, and propagates chunk_size through candidate-building paths. Tests updated to cover batch behavior. Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant RaindexClient as RaindexClient
participant BatchProcessor as BatchProcessor
participant RPC as RPC/Subgraph
Client->>RaindexClient: get_order_quotes_batch(orders, block, chunk_size)
RaindexClient->>BatchProcessor: to_subgraph_orders(orders)
BatchProcessor->>BatchProcessor: compute per-order pair_counts
BatchProcessor->>RPC: single multicall for all pairs (chunked by chunk_size)
RPC-->>BatchProcessor: flat list of quotes
BatchProcessor->>BatchProcessor: repartition flat results by pair_counts
BatchProcessor-->>RaindexClient: Vec<Vec<RaindexOrderQuote>>
RaindexClient-->>Client: per-order quote vectors
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/common/src/raindex_client/order_quotes.rs`:
- Around line 198-203: Ensure get_order_quotes_batch enforces the single-chain
invariant before reusing RPCs from the first order: validate that every Order in
orders has the same chain identifier (e.g., compare chain_id or network property
exposed by Order) as orders[0] and return an error if any differ, then only
collect RPC URLs via get_rpc_urls() on orders[0] into rpcs after that check;
this prevents using first-order RPCs for mixed-chain inputs and fails fast when
orders span multiple chains.
ℹ️ Review info
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
crates/common/src/raindex_client/mod.rscrates/common/src/raindex_client/order_quotes.rscrates/common/src/raindex_client/orders_list.rscrates/common/src/take_orders/candidates.rspackages/orderbook/test/js_api/raindexClient.test.ts
Return an error early if orders span multiple chains, preventing silent use of first-order RPCs for mixed-chain inputs.
…quote-wasm-binding Resolve conflicts by replacing gas parameter with chunk_size across batch quoting and candidate building. Plumb chunk_size through build_take_order_candidates_for_pair and build_candidates_for_chain to allow runtime configuration of quote chunk sizes.
|
@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment: S/M/L PR Classification Guidelines:This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed. Small (S)Characteristics:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
|
Tip For best results, initiate chat on the files or code changes. SIZE=L 🧠 Learnings used |
Chained PRs
Motivation
The parent PR (#2480) flattened batch quotes into a single multicall at the
crates/quotelevel. However, the WASM/JS layer still needed a way to call this batch function, and the existingcandidates.rswas still quoting orders individually via a buffered stream with concurrency of 5.This PR exposes the batch quoting to JS consumers and updates the internal candidate-building logic to use the same single-multicall path.
Solution
RaindexOrdersmodule (orders_list.rs): New wrapper type following theRaindexVaultsListpattern. In WASM, uses an empty constructor +push(&RaindexOrder)to work around wasm-bindgen's inability to acceptVec<T>of opaque classes.get_order_quotes_batchfunction (order_quotes.rs): Free function that converts&[RaindexOrder]→Vec<SgOrder>, pre-computes pair counts per order, calls the single-multicallget_order_quotes, and slices the flat results back into per-order groups.RaindexClient.getOrderQuotesBatchWASM method: Exposes the batch function to JS, acceptingRaindexOrders, optional block number, and optional gas limit.candidates.rsrefactor: Replaced thefutures::stream::bufferedper-order quoting loop with a singleget_order_quotes_batchcall. RemovedDEFAULT_QUOTE_CONCURRENCYconstant andfutures::StreamExtimport.gasfromOption<String>toOption<u64>on bothgetQuotesandgetOrderQuotesBatch, removing unnecessary string parsing.Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit
New Features
Improvements
Tests