Add get trades by owner API#2468
Open
findolor wants to merge 10 commits into2026-02-17-trades-by-tx-hashfrom
Open
Add get trades by owner API#2468findolor wants to merge 10 commits into2026-02-17-trades-by-tx-hashfrom
findolor wants to merge 10 commits into2026-02-17-trades-by-tx-hashfrom
Conversation
Add SgOwnerTradesListQuery, SgOwnerTradesCountQuery types and owner_trades_list/owner_trades_count client methods to support querying trades filtered by order owner address.
Add fetch_owner_trades and fetch_owner_trades_count query modules to support paginated trade lookups by owner address from the local SQLite database.
Add SubgraphTrades struct mirroring LocalDbTrades to cleanly abstract subgraph trade queries. Add get_trades_for_owner public API with local DB primary path and subgraph fallback, along with RaindexTradesListResult for paginated results.
Replace inline subgraph client calls with SubgraphTrades struct, making the fallback path symmetric with the local DB path.
Co-locate LocalDbTrades alongside SubgraphTrades in the trades module for better code organization. Both data source structs now live next to the public API that consumes them.
Contributor
|
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 Use the checkbox below for a quick retry:
✨ 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 |
Pass start_timestamp/end_timestamp through to SgOwnerTradesListQuery and SgOwnerTradesCountQuery so owner trade lookups can be filtered by time range at the subgraph level.
Replace bare page param with PaginationParams (page + page_size) and add TimeFilter (start/end timestamps) throughout the owner trades query stack: local DB SQL builders, fetch wrappers, LocalDbTrades, and SubgraphTrades.
Move PaginationParams and TimeFilter into a shared types.rs module and add OrderbookIdentifierParams as a wasm-safe wrapper that converts to OrderbookIdentifier. Update get_trades_for_owner to accept OrderbookIdentifierParams instead of separate chain_id and orderbook_address params.
Address::to_string() produces EIP-55 checksummed (mixed-case) hex
but the subgraph matches lowercase. Use format!("{:#x}", owner) to
ensure lowercase in get_by_owner and count_by_owner.
Remove duplicated cfg-gated impl blocks for PaginationParams, TimeFilter, and OrderbookIdentifierParams by using single wasm_bindgen impl blocks that work on both targets. Add pub new() constructor to RaindexTradesListResult for non-wasm targets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chained PRs
Motivation
See issues:
The trades public API needed a way to query trades filtered by order owner address. Additionally, the existing trade query code had inline subgraph logic in the fallback path while the local DB path was cleanly abstracted into
LocalDbTrades. This asymmetry made the code harder to maintain and extend.Solution
Subgraph layer: Added
SgOwnerTradesListQuery,SgOwnerTradesCountQuerytypes andowner_trades_list/owner_trades_countclient methods for querying trades by owner address with pagination support.Local DB layer: Added
fetch_owner_tradesandfetch_owner_trades_countquery modules with SQL queries that join trade events with token metadata, supporting paginated lookups by owner address from SQLite.Public API: Added
get_trades_for_owneronRaindexClientreturningRaindexTradesListResult(paginated trades + total count), with local DB as the primary path and subgraph fallback.SubgraphTrades struct: Extracted inline subgraph trade logic into a
SubgraphTradesstruct mirroringLocalDbTrades, withget_by_tx_hash,get_by_owner, andcount_by_ownermethods. Refactoredget_by_txto use it for consistency.Code organization: Co-located
LocalDbTradesandSubgraphTradesin thetrades/module so both data source structs live next to the API that consumes them.Checks
By submitting this for review, I'm confirming I've done the following: