Skip to content

feat: read any wallet's order-book positions and collateral#195

Merged
MicBun merged 1 commit into
mainfrom
feat/portfolio-by-wallet
Jun 23, 2026
Merged

feat: read any wallet's order-book positions and collateral#195
MicBun merged 1 commit into
mainfrom
feat/portfolio-by-wallet

Conversation

@MicBun

@MicBun MicBun commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

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 / GetUserCollateral read @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 existing UserPosition / UserCollateral result types.

How

  • New input types with Validate() that accept the wallet with or without a 0x prefix (the node action normalizes either form) and require a non-empty bridge for the collateral read.
  • Methods mirror the existing GetUserPositions / GetUserCollateral plumbing and reuse parseUserPositionRow / parseUserCollateralRow.
  • New IOrderBook entries; the existing var _ 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 ./... and go vet clean.

Depends on

The matching node action (migration 051):

Context

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@MicBun, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 34ab840d-5fc7-4edf-816d-5a6aa633b92c

📥 Commits

Reviewing files that changed from the base of the PR and between f266b73 and 61f71d8.

📒 Files selected for processing (3)
  • core/contractsapi/order_book_queries.go
  • core/types/order_book_portfolio_by_wallet_test.go
  • core/types/order_book_types.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/portfolio-by-wallet

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@holdex

holdex Bot commented Jun 23, 2026

Copy link
Copy Markdown

Time Submission Status

Member # Time Running Total Status Last Update
MicBun 3h ✅ Submitted Jun 23, 2026, 10:18 AM

Submit or update total time with:

@holdex pr submit-time 2h

Add time on top of previous submission with:

@holdex pr add-time 1h30m

See available commands to help comply with our Guidelines.

@MicBun MicBun self-assigned this Jun 23, 2026
@MicBun

MicBun commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

@holdex pr submit-time 3h

@MicBun MicBun merged commit a88c54a into main Jun 23, 2026
5 checks passed
@MicBun MicBun deleted the feat/portfolio-by-wallet branch June 23, 2026 10:19
MicBun added a commit to trufnetwork/sdk-py that referenced this pull request Jun 23, 2026
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant