feat: read any wallet's order-book portfolio by address#162
Conversation
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. |
|
Warning Review limit reached
More reviews will be available in 23 minutes and 25 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 review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling 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 (5)
📝 WalkthroughWalkthroughTwo new public methods are added to ChangesWallet-address portfolio getters on OrderbookAction
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/types/orderbook.ts (1)
157-158: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a string-literal union for
positionType.The JSDoc enumerates exactly
'holding' | 'buy_order' | 'sell_order', but the field is typed asstring. A union would give callers compile-time safety and autocompletion.♻️ Optional
- /** Kind of position: 'holding' | 'buy_order' | 'sell_order' */ - positionType: string; + /** Kind of position */ + positionType: "holding" | "buy_order" | "sell_order";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/types/orderbook.ts` around lines 157 - 158, The positionType field in the orderbook type is too broad and should match the documented allowed values. Update the type definition in the orderbook model to use a string-literal union for holding, buy_order, and sell_order, keeping the JSDoc and the actual type aligned so callers of positionType get compile-time safety and autocomplete.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/contracts-api/orderbookAction.ts`:
- Around line 747-754: getCollateralByWallet currently only checks for an empty
bridge string, so update it to use the existing validateBridge helper just like
createMarket does. Replace the ad hoc bridge guard inside getCollateralByWallet
with validateBridge(bridge) to keep the whitelist consistent for known
order-book bridges and fail fast on invalid values.
---
Nitpick comments:
In `@src/types/orderbook.ts`:
- Around line 157-158: The positionType field in the orderbook type is too broad
and should match the documented allowed values. Update the type definition in
the orderbook model to use a string-literal union for holding, buy_order, and
sell_order, keeping the JSDoc and the actual type aligned so callers of
positionType get compile-time safety and autocomplete.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3780df59-78cc-4e57-8f9f-4ba480e46d08
📒 Files selected for processing (5)
src/contracts-api/orderbookAction.test.tssrc/contracts-api/orderbookAction.tssrc/internal.tssrc/types/orderbook.tssrc/util/orderbookHelpers.ts
|
@holdex pr submit-time 2h |
7ad7dfb to
af17f91
Compare
resolves: https://github.com/truflation/website/issues/4171
Problem
The JS SDK can only read an order-book portfolio for the signer itself —
getUserPositions/getUserCollateralare@caller-scoped. There's no way for an owner, or a delegated market-maker bot, to read another wallet's positions/collateral by address, the way the Go and Python SDKs already can (migration 051). This is needed to monitor an agent wallet (MAA) without holding its key.Change
Adds two address-parameterized order-book getters to
OrderbookAction, at parity with sdk-go/sdk-py:getPositionsByWallet(walletHex)→WalletPosition[](callsget_positions_by_wallet)getCollateralByWallet(walletHex, bridge)→UserCollateral(callsget_collateral_by_wallet)Both read the wallet you pass in, not the signer. Supporting pieces:
WalletPosition/RawWalletPositiontypes — they carrypositionType(the node'sposition_typecolumn), so they intentionally differ from the@callerUserPosition(which carrieslastUpdated);UserCollateralis reused as-is.validateWalletHexhelper (20-byte hex, optional0x), mirroring sdk-go's validation.[](positions) /{ "0", "0", "0" }(collateral), matching sdk-go/sdk-py.Verification
orderbookAction.test.ts) assert the exact action name, named params, row→object mapping, empty-result handling, wallet validation, and error paths.npm run typecheckclean; full unit suite green (266 tests).getPositionsByWallet→[]andgetCollateralByWallet→ zeros for a data-provision MAA — a clean return proving migration 051 is live on the network.Summary by CodeRabbit
New Features
Bug Fixes