-
Notifications
You must be signed in to change notification settings - Fork 13
Add LocalDB support for order vault volume queries #2376
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-25-re-enable-volume-tab-order-detail
Are you sure you want to change the base?
Add LocalDB support for order vault volume queries #2376
Conversation
Add fetch_order_vaults_volume query module with: - SQL query using FLOAT_SUM to aggregate volumes per vault - LocalDbVaultVolume struct with total_in/total_out hex Floats - Builder function with optional timestamp filtering
Add fetch_order_vaults_volume executor using generic LocalDbQueryExecutor pattern, matching the existing fetch_order_trades implementation.
- Add try_from_local_db_vault_volume conversion to RaindexVaultVolume - Update get_vaults_volume() to use LocalDB when available, falling back to subgraph otherwise (dual data source pattern)
WalkthroughIntroduces a new local database query to fetch vault volume data for orders, including SQL query logic for aggregating trading events, a result data structure, a statement builder function, and an executor function. Integrates a local-DB fast-path into the RaindexOrder API that falls back to the remote orderbook client when unavailable. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant RaindexOrder
participant LocalDB
participant OrderbookClient
participant Converter
Client->>RaindexOrder: get_vaults_volume(order_hash, ...)
alt Local DB Available
RaindexOrder->>LocalDB: fetch_order_vaults_volume(order_hash)
LocalDB->>LocalDB: Execute SQL query<br/>(aggregate events)
LocalDB-->>RaindexOrder: Vec<LocalDbVaultVolume>
RaindexOrder->>Converter: try_from_local_db_vault_volume<br/>(for each volume)
Converter-->>RaindexOrder: RaindexVaultVolume
RaindexOrder-->>Client: Vec<RaindexVaultVolume>
else Fall back to Remote
RaindexOrder->>OrderbookClient: fetch_vaults_volume(order_hash)
OrderbookClient-->>RaindexOrder: Vec<VaultVolume>
RaindexOrder->>Converter: try_from_vault_volume<br/>(for each volume)
Converter-->>RaindexOrder: RaindexVaultVolume
RaindexOrder-->>Client: Vec<RaindexVaultVolume>
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
crates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/local_db/query/fetch_order_vaults_volume/query.sqlcrates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
🧰 Additional context used
📓 Path-based instructions (3)
crates/**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
crates/**/*.rs: For Rust crates incrates/*, run lints usingnix develop -c cargo clippy --workspace --all-targets --all-features -D warnings
For Rust crates incrates/*, run tests usingnix develop -c cargo test --workspaceor--package <crate>
Files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
**/crates/**
📄 CodeRabbit inference engine (AGENTS.md)
Rust workspace organized as
crates/*with subdirectories: cli, common, bindings, js_api, quote, subgraph, settings, math, integration_tests
Files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/local_db/query/fetch_order_vaults_volume/query.sqlcrates/common/src/raindex_client/vaults.rs
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Rust: format code withnix develop -c cargo fmt --all
Rust: lint withnix develop -c rainix-rs-static(preconfigured flags included)
Rust: crates and modules usesnake_case; types usePascalCase
Files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
🧠 Learnings (21)
📓 Common learnings
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/create_tables/query.sql:71-72
Timestamp: 2025-10-06T11:44:07.888Z
Learning: The local DB feature in the rain.orderbook codebase is not live yet (as of PR #2145), so schema migrations for existing databases are not required when modifying table structures in `crates/common/src/raindex_client/local_db/query/create_tables/query.sql`.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the format: "TOTAL=number ADDITIONS=number DELETIONS=number". This report should exclude irrelevant files such as lock files (e.g., package-lock.json, cargo.lock).
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR #1884 and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.717Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T21:25:47.873Z
Learning: After each new commit review for rainlanguage/rain.orderbook repository, generate a PR size report in a separate comment with the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". This report should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: rouzwelt
Repo: rainlanguage/rain.orderbook PR: 0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2155
File: crates/common/src/raindex_client/trades.rs:133-152
Timestamp: 2025-10-06T14:13:18.531Z
Learning: In the rain.orderbook codebase, the `page` parameter in `RaindexOrder::get_trades_list` method (in crates/common/src/raindex_client/trades.rs) is kept for backwards compatibility with subgraph logic, but the LocalDb fast-path intentionally returns all trades without implementing pagination.
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:319-336
Timestamp: 2025-08-01T07:44:53.910Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore (crates/js_api/src/filters/raindex_filter_store.rs), the team chose a simplified monolithic approach with hard-coded keys and default auto-save behavior over configurable stores. The update_vaults method intentionally auto-saves to both localStorage and URL after each update as the default behavior, following a design evolution from a previous configurable approach.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql:6-7
Timestamp: 2025-10-06T11:28:30.692Z
Learning: In `crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql`, the orderbook_address is currently hardcoded to '0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB' because the system only supports a single orderbook at the moment. Multiorderbook logic is not yet implemented and will be added in the future.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2237
File: crates/common/src/raindex_client/local_db/sync.rs:79-89
Timestamp: 2025-10-18T10:38:41.273Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the sync_database method currently only supports indexing a single orderbook per chain ID, which is why `.first()` is used to select the orderbook configuration. Multi-orderbook support per chain ID is planned for future PRs.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1947
File: crates/common/src/raindex_client/orders.rs:98-125
Timestamp: 2025-06-24T08:46:03.368Z
Learning: In the vault merging logic in crates/common/src/raindex_client/orders.rs, optimization isn't necessary because the maximum list items are usually around 5 items. For such small datasets, the simple three-loop approach is preferred over HashMap-based optimization due to clarity and minimal performance impact.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2155
File: crates/common/src/raindex_client/local_db/query/fetch_order_trades/query.sql:86-108
Timestamp: 2025-10-06T14:12:05.824Z
Learning: CTEs (Common Table Expressions) are not supported in the local DB SQL implementation used in the rain.orderbook codebase.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2163
File: crates/common/src/raindex_client/orders.rs:738-741
Timestamp: 2025-10-02T19:17:20.332Z
Learning: In crates/common/src/raindex_client/orders.rs, fetch_dotrain_source() is intentionally called in try_from_sg_order for every order conversion because the dotrain source information is needed immediately. A future optimization with local DB logic is planned to eliminate the network round-trip concern.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1872
File: packages/webapp/src/__tests__/handleVaultDeposit.test.ts:20-53
Timestamp: 2025-06-07T05:19:46.330Z
Learning: In the rain.orderbook codebase, simple wrapper/adapter functions that just delegate to other functions (like handleVaultDeposit) don't need extensive edge case testing for missing parameters or error handling - the current test coverage focusing on core functionality is sufficient.
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/raindex_client/trades.rs:215-223
Timestamp: 2025-07-04T10:24:56.163Z
Learning: In the rain.orderbook codebase, the get_trade_count method implementation that fetches all trades to count them is intentionally consistent with previous implementations and not considered a performance issue, as indicated by findolor for the trades counting functionality in crates/common/src/raindex_client/trades.rs.
📚 Learning: 2025-05-17T15:32:28.733Z
Learnt from: 0xgleb
Repo: rainlanguage/rain.orderbook PR: 1790
File: tauri-app/src-tauri/src/commands/vault.rs:67-67
Timestamp: 2025-05-17T15:32:28.733Z
Learning: For the PR focused on testing Tauri commands::order module, the generic type parameter R: Runtime was selectively added where needed for the PR scope, applying the changes primarily to order.rs and related files while leaving other modules like vault.rs for potential future refactoring.
Applied to files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs
📚 Learning: 2025-06-24T08:46:03.368Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1947
File: crates/common/src/raindex_client/orders.rs:98-125
Timestamp: 2025-06-24T08:46:03.368Z
Learning: In the vault merging logic in crates/common/src/raindex_client/orders.rs, optimization isn't necessary because the maximum list items are usually around 5 items. For such small datasets, the simple three-loop approach is preferred over HashMap-based optimization due to clarity and minimal performance impact.
Applied to files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
📚 Learning: 2025-10-18T10:38:41.273Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2237
File: crates/common/src/raindex_client/local_db/sync.rs:79-89
Timestamp: 2025-10-18T10:38:41.273Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the sync_database method currently only supports indexing a single orderbook per chain ID, which is why `.first()` is used to select the orderbook configuration. Multi-orderbook support per chain ID is planned for future PRs.
Applied to files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
📚 Learning: 2025-10-06T14:13:18.531Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2155
File: crates/common/src/raindex_client/trades.rs:133-152
Timestamp: 2025-10-06T14:13:18.531Z
Learning: In the rain.orderbook codebase, the `page` parameter in `RaindexOrder::get_trades_list` method (in crates/common/src/raindex_client/trades.rs) is kept for backwards compatibility with subgraph logic, but the LocalDb fast-path intentionally returns all trades without implementing pagination.
Applied to files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-07-30T07:41:39.271Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2012
File: crates/js_api/src/registry.rs:485-512
Timestamp: 2025-07-30T07:41:39.271Z
Learning: In crates/js_api/src/registry.rs, findolor considers the current concurrent fetching of order files using futures::future::join_all without concurrency limits to be acceptable, preferring the simple approach over adding concurrency limiting mechanisms for the DotrainRegistry implementation.
Applied to files:
crates/common/src/local_db/query/mod.rscrates/common/src/raindex_client/local_db/query/mod.rs
📚 Learning: 2025-07-16T10:40:05.717Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.717Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Applied to files:
crates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/orders.rscrates/common/src/raindex_client/vaults.rs
📚 Learning: 2025-10-06T11:44:07.888Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/create_tables/query.sql:71-72
Timestamp: 2025-10-06T11:44:07.888Z
Learning: The local DB feature in the rain.orderbook codebase is not live yet (as of PR #2145), so schema migrations for existing databases are not required when modifying table structures in `crates/common/src/raindex_client/local_db/query/create_tables/query.sql`.
Applied to files:
crates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/local_db/query/fetch_order_vaults_volume/mod.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-08-01T07:44:53.910Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:319-336
Timestamp: 2025-08-01T07:44:53.910Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore (crates/js_api/src/filters/raindex_filter_store.rs), the team chose a simplified monolithic approach with hard-coded keys and default auto-save behavior over configurable stores. The update_vaults method intentionally auto-saves to both localStorage and URL after each update as the default behavior, following a design evolution from a previous configurable approach.
Applied to files:
crates/common/src/raindex_client/local_db/query/mod.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-10-02T19:17:20.332Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2163
File: crates/common/src/raindex_client/orders.rs:738-741
Timestamp: 2025-10-02T19:17:20.332Z
Learning: In crates/common/src/raindex_client/orders.rs, fetch_dotrain_source() is intentionally called in try_from_sg_order for every order conversion because the dotrain source information is needed immediately. A future optimization with local DB logic is planned to eliminate the network round-trip concern.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-08-01T09:07:20.383Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: packages/orderbook/README.md:186-189
Timestamp: 2025-08-01T09:07:20.383Z
Learning: In the rainlanguage/rain.orderbook project, Rust methods on structs like RaindexVaultsList are exported as JavaScript getters in WASM bindings using #[wasm_bindgen(getter)]. This means while the Rust code uses method calls like items(), the JavaScript/WASM API exposes them as property access like .items. The README.md correctly documents the JavaScript API surface, not the Rust implementation details.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-10-06T11:28:30.692Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2145
File: crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql:6-7
Timestamp: 2025-10-06T11:28:30.692Z
Learning: In `crates/common/src/raindex_client/local_db/query/fetch_orders/query.sql`, the orderbook_address is currently hardcoded to '0x2f209e5b67A33B8fE96E28f24628dF6Da301c8eB' because the system only supports a single orderbook at the moment. Multiorderbook logic is not yet implemented and will be added in the future.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rscrates/common/src/raindex_client/orders.rs
📚 Learning: 2025-07-31T19:34:11.716Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2044
File: crates/common/src/raindex_client/vaults_list.rs:363-423
Timestamp: 2025-07-31T19:34:11.716Z
Learning: In the rainlanguage/rain.orderbook project, for WASM-exposed functionality like VaultsList, the team prefers to keep comprehensive tests in the non-WASM environment due to the complexity of recreating objects like RaindexVaults in WASM. WASM tests focus on basic functionality and error cases since the WASM code reuses the already-tested non-WASM implementation.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs
📚 Learning: 2025-08-02T03:55:25.215Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: packages/orderbook/test/js_api/filters.test.ts:19-36
Timestamp: 2025-08-02T03:55:25.215Z
Learning: In the rainlanguage/rain.orderbook project's WASM tests, the pattern of chaining `.value!` calls on WASM result types (like from VaultsFilterBuilder methods) is the established and preferred approach for handling WASM results, and should not be refactored into intermediate variables as it would add unnecessary verbosity without improving the code.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs
📚 Learning: 2025-08-02T02:34:32.237Z
Learnt from: brusherru
Repo: rainlanguage/rain.orderbook PR: 2036
File: crates/js_api/src/filters/raindex_filter_store.rs:446-533
Timestamp: 2025-08-02T02:34:32.237Z
Learning: In the rainlanguage/rain.orderbook project's RaindexFilterStore WASM tests (crates/js_api/src/filters/raindex_filter_store.rs), brusherru decided to focus on testing only methods without side effects (that don't use web_sys) due to difficulties with mocking localStorage and window APIs in the WASM test environment. This pragmatic approach tests pure logic separately from browser integration.
Applied to files:
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs
📚 Learning: 2025-12-03T10:40:25.429Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2344
File: crates/common/src/local_db/pipeline/runner/mod.rs:18-31
Timestamp: 2025-12-03T10:40:25.429Z
Learning: In `crates/common/src/local_db/pipeline/runner/mod.rs`, the `TargetSuccess` struct does not need separate `ob_id` or `orderbook_key` fields because the contained `SyncOutcome` already includes orderbook identification information such as chain_id and orderbook_address. This avoids redundant data duplication.
Applied to files:
crates/common/src/local_db/query/fetch_order_vaults_volume/mod.rs
📚 Learning: 2025-10-14T07:51:55.148Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2202
File: crates/common/src/raindex_client/local_db/sync.rs:33-34
Timestamp: 2025-10-14T07:51:55.148Z
Learning: In `crates/common/src/raindex_client/local_db/sync.rs`, the hard-coded `DEFAULT_SYNC_CHAIN_ID` constant (set to `SUPPORTED_LOCAL_DB_CHAINS[0]`) will be replaced with proper chain ID handling in downstream PRs as part of the multi-network/orderbook implementation.
Applied to files:
crates/common/src/raindex_client/orders.rs
📚 Learning: 2025-07-04T10:24:56.163Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1956
File: crates/common/src/raindex_client/trades.rs:215-223
Timestamp: 2025-07-04T10:24:56.163Z
Learning: In the rain.orderbook codebase, the get_trade_count method implementation that fetches all trades to count them is intentionally consistent with previous implementations and not considered a performance issue, as indicated by findolor for the trades counting functionality in crates/common/src/raindex_client/trades.rs.
Applied to files:
crates/common/src/raindex_client/orders.rs
📚 Learning: 2025-09-30T21:18:01.636Z
Learnt from: hardyjosh
Repo: rainlanguage/rain.orderbook PR: 2167
File: crates/virtual-raindex/src/engine/take.rs:131-138
Timestamp: 2025-09-30T21:18:01.636Z
Learning: In the virtual-raindex take order flow (crates/virtual-raindex/src/engine/take.rs), balance diffs are written from the order's perspective where the taker is the counterparty: the order's input column receives taker_output (what the taker provides to the order) and the order's output column receives taker_input (what the taker requests from the order).
Applied to files:
crates/common/src/local_db/query/fetch_order_vaults_volume/query.sql
📚 Learning: 2025-06-20T07:51:08.790Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 1941
File: crates/js_api/src/raindex/vaults.rs:175-181
Timestamp: 2025-06-20T07:51:08.790Z
Learning: In the RaindexClient vault methods, `&self` parameters are intentionally kept for API consistency to make all vault operations instance methods, even when the methods don't use client state. This is a design preference for maintaining a uniform interface.
Applied to files:
crates/common/src/raindex_client/vaults.rs
📚 Learning: 2025-10-06T11:13:29.956Z
Learnt from: findolor
Repo: rainlanguage/rain.orderbook PR: 2123
File: crates/common/src/raindex_client/local_db/mod.rs:23-29
Timestamp: 2025-10-06T11:13:29.956Z
Learning: In `crates/common/src/raindex_client/local_db/mod.rs`, the `Default` implementation for `LocalDb` that creates an RPC client pointing to `http://localhost:4444` is acceptable because the RPC client must be explicitly configured before actual usage in production scenarios.
Applied to files:
crates/common/src/raindex_client/vaults.rs
🧬 Code graph analysis (4)
crates/common/src/local_db/query/mod.rs (1)
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs (1)
fetch_order_vaults_volume(8-18)
crates/common/src/raindex_client/local_db/query/mod.rs (1)
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs (1)
fetch_order_vaults_volume(8-18)
crates/common/src/raindex_client/orders.rs (4)
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs (1)
fetch_order_vaults_volume(8-18)crates/common/src/raindex_client/vaults.rs (13)
chain_id(114-116)chain_id(161-163)chain_id(255-257)chain_id(282-284)chain_id(1891-1892)orderbook(146-148)orderbook(185-187)orderbook(696-698)orderbook(735-737)new(49-51)new(204-209)try_from_local_db_vault_volume(964-1002)try_from_vault_volume(951-962)crates/common/src/raindex_client/local_db/query/fetch_orders.rs (1)
orderbook(84-86)crates/common/src/local_db/mod.rs (1)
new(344-349)
crates/common/src/raindex_client/vaults.rs (1)
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs (1)
fetch_order_vaults_volume(8-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: test
- GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
- GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
- GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
- GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-browser-test)
- GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
- GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
- GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
- GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
- GitHub Check: test
- GitHub Check: git-clean
- GitHub Check: test
- GitHub Check: Deploy-Preview-Push
- GitHub Check: build-tauri (ubuntu-22.04, true)
- GitHub Check: Deploy-Docs-Preview
🔇 Additional comments (6)
crates/common/src/local_db/query/mod.rs (1)
11-11: New local-db vault volume module export is consistent
pub mod fetch_order_vaults_volume;cleanly follows the existing query module pattern and matches the new module path; no issues here.crates/common/src/raindex_client/local_db/query/mod.rs (1)
7-7: Raindex client local-db module wiring looks correctExporting
fetch_order_vaults_volumehere matches the new wrapper module and allowsorders.rsto import it viasuper::local_db::query::fetch_order_vaults_volume; this is consistent with existing query wiring.crates/common/src/raindex_client/vaults.rs (1)
2-2: Local‑DB vault volume conversion mirrors subgraph path correctlyThe new
LocalDbVaultVolumeimport andRaindexVaultVolume::try_from_local_db_vault_volumeimplementation look sound:
- Enforces
token_decimalspresence viaMissingErc20Decimals, consistent with howtry_from_sg_erc20treats decimals for required tokens.- Builds
RaindexVaultTokenfrom local DB metadata in the same shape as other local‑DB mappings (id as address string, address, optional name/symbol, concrete decimals).- Parses
total_in/total_outfrom hexFloatstrings, then derivestotal_vol = total_in + total_outandnet_vol = total_in - total_outand formatted strings exactly likefrom_volume_details.This should give identical semantics between local‑DB and subgraph volume results.
Also applies to: 963-1002
crates/common/src/raindex_client/local_db/query/fetch_order_vaults_volume.rs (1)
1-68: Wrapper correctly delegates to SQL builder and executor
fetch_order_vaults_volumeis a thin, type‑safe adapter overbuild_fetch_order_vaults_volume_stmt+LocalDbQueryExecutor::query_json, and the wasm test verifies the wrapper uses the builder’s SQL verbatim. This matches the existing local‑DB query pattern and looks solid.crates/common/src/local_db/query/fetch_order_vaults_volume/mod.rs (1)
1-119: SQL statement builder andLocalDbVaultVolumeshape look correct
LocalDbVaultVolumefields align with the finalSELECTcolumns inquery.sql(vault_id, token, token_name/symbol/decimals, total_in, total_out), and usingStringfor totals matches the hexFloatrepresentation expected byFloat::from_hex.build_fetch_order_vaults_volume_stmtcorrectly:
- Seeds parameters with
(chain_id, orderbook_address, order_hash).- Optionally binds
start_timestamp/end_timestampviabind_param_clause, removing the/*START_TS_CLAUSE*///*END_TS_CLAUSE*/markers and appendingblock_timestamp >=/<=predicates.- Converts
u64timestamps toi64with explicitSqlBuildErroron overflow, which is a reasonable guardrail.- Tests exercise both filtered and unfiltered cases and validate SQL shape and parameter ordering.
No issues here.
crates/common/src/local_db/query/fetch_order_vaults_volume/query.sql (1)
1-259: Volume SQL looks semantically correct but depends on CTE support in LocalDBThe CTE‑based query for
fetch_order_vaults_volumeis carefully structured:
take_tradesandclear_alice/clear_bobcorrectly derive per‑trade input/output vaults and deltas from take and clear events, using:
- Order‑scoped
order_add_eventswith the usual “latest AddOrder before event, no newer AddOrder before trade/clear” pattern to pick the right order version.- Input deltas from the order’s perspective (
taker_output,alice_input,bob_input) and output deltas as their negation, which matches the existing balance‑diff convention.input_volumesandoutput_volumesaggregate those deltas per(vault_id, token), usingFLOAT_SUMandFLOAT_NEGATEso thattotal_inandtotal_outare positive volume figures.all_vaults(UNION over input/output vaults) plus the final SELECT witherc20_tokensyields exactly the columns expected byLocalDbVaultVolume, with sensible zero defaults viaFLOAT_ZERO_HEX()andCOALESCE.filtered_tradesis designed for dynamic time filters via the/*START_TS_CLAUSE*/and/*END_TS_CLAUSE*/placeholders the Rust builder fills.The main thing to double‑check is engine support: earlier work on local‑DB queries avoided CTEs because the local‑DB SQL implementation did not support them. If that is still true in the environment where this query runs (e.g. the WASM/sql.js path), this statement would fail at runtime despite passing Rust tests that only inspect SQL strings.
Please verify that:
- The LocalDB backend used for these queries now supports
WITHCTEs, or- This query is executed only against a backend that does (e.g. real SQLite), and never against the limited engine covered by the previous “no CTEs” constraint.
If CTEs are still unsupported in the primary LocalDB engine, this query will need to be refactored into an equivalent non‑CTE form (similar to prior local‑DB queries). Based on learnings, CTE support is a known constraint in this codebase.
Chained PRs
Motivation
See issues:
The Volume tab currently only loads vault volumes from the subgraph. This PR enables LocalDB as an alternative data source, following the dual data source pattern already established for trades. This allows the Volume tab to function when LocalDB is enabled and populated, without depending on the subgraph.
Solution
Implemented LocalDB support for
RaindexOrder.getVaultsVolume()with three key components:SQL Query Module (
fetch_order_vaults_volume/): Added a SQL query that aggregates volumes per vault usingFLOAT_SUMdirectly in SQLite, avoiding the I/O overhead of fetching all trades and computing in Rust. The query returnstotal_inandtotal_outas hex Float strings.Executor Wrapper (
fetch_order_vaults_volume.rs): Created a generic executor using theLocalDbQueryExecutorpattern, matching the existingfetch_order_tradesimplementation.Dual Source Integration: Updated
get_vaults_volume()to check LocalDB first when available, falling back to subgraph otherwise. Addedtry_from_local_db_vault_volumeconversion that computestotal_volandnet_volfrom the SQL results.Checks
By submitting this for review, I'm confirming I've done the following:
fix #1989
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.