Skip to content

Test functions#1

Open
avernikoz wants to merge 6 commits into
mainfrom
v3-tag-fork-test-methods
Open

Test functions#1
avernikoz wants to merge 6 commits into
mainfrom
v3-tag-fork-test-methods

Conversation

@avernikoz

Copy link
Copy Markdown
  1. add create_order_info_for_tests test func
  2. make functions public (remove (package)) for bm and pool tests

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.

2 participants