feat: read any wallet's order-book positions and collateral#195
Conversation
|
Warning Review limit reached
More reviews will be available in 59 minutes and 59 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ 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 |
Time Submission Status
Submit or update total time with: Add time on top of previous submission with: See available commands to help comply with our Guidelines. |
|
@holdex pr submit-time 3h |
resolves: truflation/website#4171 ## What Read a wallet's order-book portfolio by **address** from Python, plus a working demonstration in the MAA lifecycle example: - `TNClient.get_positions_by_wallet(wallet_address)` — holdings + open orders - `TNClient.get_collateral_by_wallet(wallet_address, bridge)` — total locked collateral on a bridge ## Why `get_user_positions` / `get_user_collateral` read the signer (`@caller`), so they cannot read a wallet you do not sign for — e.g. an owner, or a delegated market-maker bot, watching an **agent wallet (MAA)** whose positions live under the MAA's participant id, not the signer's. These wrap the new node action and sdk-go methods. ## How - gopy bindings (`GetPositionsByWallet` / `GetCollateralByWallet`) forwarding to sdk-go, plus thin `TNClient` wrappers that JSON-parse the result and reuse the existing `UserPosition` / `UserCollateral` types. - Re-pins `sdk-go` to the merged commit that adds the methods (`go.mod` / `go.sum`); `kwil-db` is unchanged. ## Example `examples/maa_lifecycle_example` now: - loads config from a gitignored `.env` (zero-dependency loader; real env vars still win), with a committed `.env.example` - adds step (h): reads the agent wallet's positions/collateral by address - uses a fresh salt per run so the smoke test is re-runnable (`MAA_SALT` pins it) ## Testing - `tests/test_portfolio_by_wallet.py` — pure unit tests (monkeypatched binding) for argument forwarding, JSON parsing, and empty handling. All pass. - Verified live: the example's step (h) runs against testnet and both getters return cleanly (migration 051 applied), proving the path end-to-end. ## Depends on (merged) - <trufnetwork/node#1399> - <trufnetwork/sdk-go#195> ## Context - <truflation/website#4121> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added wallet-scoped order-book queries: `get_positions_by_wallet()` retrieves positions and holdings for any wallet address, while `get_collateral_by_wallet()` returns collateral data without requiring the wallet signer. * **Documentation** * Updated lifecycle example to use .env file configuration and added documentation for new wallet address-based portfolio queries. * **Tests** * Added unit tests covering wallet-scoped portfolio retrieval methods. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
resolves: https://github.com/truflation/website/issues/4171
What
SDK methods to read a wallet's order-book portfolio by address rather than by signer:
OrderBook.GetPositionsByWallet(ctx, GetPositionsByWalletInput{WalletHex})OrderBook.GetCollateralByWallet(ctx, GetCollateralByWalletInput{WalletHex, Bridge})Why
GetUserPositions/GetUserCollateralread@caller, so they only return the signer's own rows — they cannot read a wallet you do not sign for, e.g. an owner or a delegated market-maker bot watching an agent wallet (MAA). These map to the new node getters and reuse the existingUserPosition/UserCollateralresult types.How
Validate()that accept the wallet with or without a0xprefix (the node action normalizes either form) and require a non-empty bridge for the collateral read.GetUserPositions/GetUserCollateralplumbing and reuseparseUserPositionRow/parseUserCollateralRow.IOrderBookentries; the existingvar _ IOrderBook = (*OrderBook)(nil)assertion covers them.Testing
core/types/order_book_portfolio_by_wallet_test.go— node-free validation tests for both input types (0x / bare-hex / empty / malformed / missing-bridge), all pass.go build ./...andgo vetclean.Depends on
The matching node action (migration 051):
Context