Skip to content

Feature/expose public package view functions#6

Closed
bathord wants to merge 4 commits into
mainfrom
feature/expose-public-package-view-functions
Closed

Feature/expose public package view functions#6
bathord wants to merge 4 commits into
mainfrom
feature/expose-public-package-view-functions

Conversation

@bathord

@bathord bathord commented Dec 3, 2025

Copy link
Copy Markdown
Collaborator

Description

Expose existing public(package) view functions and add 1 new view function to provide more view-data for integrators.

Changes

  • big_vector.move: make view functions and accessors for Slice and SliceRef public;
  • pool.move: add bids_and_asks public view function, returning Book's bids and asks as BigVector references;
  • balances.move: make base, quote and deep getters public;
  • deep_price.move: make fee_quantity view function public.

@bathord

bathord commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

Closed in deepbook repo.

@bathord bathord closed this Dec 9, 2025
bathord pushed a commit that referenced this pull request Mar 14, 2026
* feat: add portfolio endpoint for margin wallet overview

Adds GET /portfolio/:wallet_address endpoint that returns a comprehensive
margin portfolio view including positions, collateral, and LP balances
with real-time USD valuations.

* fix: address claude review comments on portfolio endpoint

- Add wallet address format validation (0x prefix + 64 hex chars)
- Increment db_requests_failed metric on query errors
- Fix LP query to filter on supplier (indexed) instead of sender (unindexed),
  using margin_manager_created join to resolve wallet -> balance_manager_id;
  uses existing idx_asset_supplied_supplier / idx_asset_withdrawn_supplier
- Remove spurious + 0.0 in PortfolioSummary construction
- Add comment explaining LIKE asset_id suffix matching pattern
- Consolidate row struct definitions above queries for readability

* fix: revert LP query sender->supplier change, document missing index

The supplier column in asset_supplied/asset_withdrawn stores the
SupplierCap NFT object ID, not the balance_manager_id. The join through
margin_manager_created.balance_manager_id produced zero results.

Revert to filtering on sender (wallet address) which is correct, and
add a comment noting that sender lacks an index — a follow-up migration
should add idx_asset_supplied_sender and idx_asset_withdrawn_sender.

* fix: address SQL linter findings in portfolio queries

- Guard am.decimals against NULL with COALESCE(am.decimals, 9) in
  collateral query division (linter: division without zero guard)
- Document intentional UNION dedup in asset_meta CTE (linter: UNION vs UNION ALL)

* fix: address PR review comments #1, #2, #5, #6

- Fix metrics accounting: increment per-query (3 succeeded on full
  success) instead of 1, consistent with rest of codebase
- Add hex character validation to wallet address check
- Add TODO for LIKE '%...' pattern preventing index use on balances.asset
- Move row structs (MarginPositionRow, CollateralRow, LpPositionRow) to
  module level, consistent with OhclvRow

* fix: remove lp.price_usd from GROUP BY, use short diesel type aliases

- Remove lp.price_usd from collateral query GROUP BY clause. It is
  functionally dependent on am.symbol (already in GROUP BY) and could
  produce phantom duplicate rows if latest_prices returns NULL.
- Switch row struct diesel annotations from fully qualified paths
  (diesel::sql_types::Text) to imported short aliases (Text, Double,
  BigInt) for consistency with OhclvRow.
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