Skip to content

feat: add apr / apy in position view#367

Merged
antoncoding merged 4 commits intomasterfrom
feat/history-report
Feb 4, 2026
Merged

feat: add apr / apy in position view#367
antoncoding merged 4 commits intomasterfrom
feat/history-report

Conversation

@antoncoding
Copy link
Copy Markdown
Owner

@antoncoding antoncoding commented Feb 4, 2026

Summary by CodeRabbit

  • New Features

    • Historical APY display for selected earnings periods
    • Period-based earnings calculations with 1D, 7D, and 30D labels
    • Real-time loading indicators for earnings data
  • UI Updates

    • Removed risk indicators and risk tiers column from positions table
    • Updated table headers to include period labels for better clarity
    • Improved earnings column layout for enhanced readability

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
monarch Ready Ready Preview, Comment Feb 4, 2026 9:37am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Introduces period-based APY calculation for vaults by adding a new useVaultHistoricalApy hook that computes historical APY from share price changes across configurable periods. Threads this data through the positions UI, updates vault/position components to display period-based APY with loading states, and removes risk indicator columns.

Changes

Cohort / File(s) Summary
Type definitions
src/data-sources/subgraph/v2-vaults.ts, src/utils/types.ts
Added actualApy?: number to UserVaultV2; added actualApy: number, avgCapital: string, effectiveTime: number to MarketPositionWithEarnings and GroupedPosition.
APY calculation hook
src/hooks/useVaultHistoricalApy.ts
New hook that fetches block data per chain, estimates past blocks, retrieves share prices (current and historical), and calculates APY using the formula: (currentPrice / pastPrice)^(365*86400 / periodSeconds) - 1. Uses React Query with multicall batching per network and error handling per network.
Positions data utilities
src/utils/positions.ts
Added getGroupedActualApy() function to compute time-weighted APY across markets. Initialized actualApy field in GroupedPosition and MarketPositionWithEarnings structures. Updated earnings initialization to include new fields.
Vault table UI
src/features/positions/components/user-vaults-table.tsx
Added period and isEarningsLoading props. Replaced static APY with period-aware rate labels and new historical APY column that displays actualApy with loading indicator (PulseLoader) and tooltip. Removed risk tier column.
Morpho Blue positions table
src/features/positions/components/supplied-morpho-blue-grouped-table.tsx
Removed AggregatedRiskIndicators component and risk tier column. Expanded interest header to show both rate label and accrued interest. Added actual APY cell with loading state and tooltip. Adjusted row expansion colSpan from 10 to 7.
Risk indicators component
src/features/positions/components/vault-risk-indicators.tsx
Deleted entire AggregatedVaultRiskIndicators component and supporting logic (market warning aggregation, warning deduplication, risk indicator rendering).
Positions integration
src/features/positions/positions-view.tsx
Integrated useVaultHistoricalApy hook, derived period from filter state via useMemo, merged APY data into vault objects, and passed period and isEarningsLoading to UserVaultsTable.
Hook updates
src/hooks/usePositionsWithEarnings.ts, src/hooks/useVaultAllocations.ts
Extended usePositionsWithEarnings to return actualApy, avgCapital, effectiveTime fields. Updated useVaultAllocations to propagate loading states from useProcessedMarkets and useVaultV2Data.

Sequence Diagram

sequenceDiagram
    actor User
    participant positionsView as positions-view<br/>(Component)
    participant useVaultHistoricalApy as useVaultHistoricalApy<br/>(Hook)
    participant RPC as RPC Endpoints<br/>(Block Data & Multicalls)
    participant userVaultsTable as user-vaults-table<br/>(Component)

    User->>positionsView: Select earnings period
    activate positionsView
    positionsView->>useVaultHistoricalApy: Call with vaults + period
    activate useVaultHistoricalApy
    
    useVaultHistoricalApy->>RPC: Fetch current blocks per chain
    RPC-->>useVaultHistoricalApy: Current block numbers & timestamps
    
    useVaultHistoricalApy->>useVaultHistoricalApy: Estimate past blocks<br/>(timestamp - period)
    
    useVaultHistoricalApy->>RPC: Fetch timestamps for past blocks
    RPC-->>useVaultHistoricalApy: Past block timestamps
    
    useVaultHistoricalApy->>RPC: Multicall current share prices<br/>(convertToAssets per network)
    RPC-->>useVaultHistoricalApy: Current share prices
    
    useVaultHistoricalApy->>RPC: Multicall past share prices<br/>(at estimated blocks)
    RPC-->>useVaultHistoricalApy: Past share prices
    
    useVaultHistoricalApy->>useVaultHistoricalApy: Calculate APY per vault<br/>(price ratio ^ time factor - 1)
    useVaultHistoricalApy-->>positionsView: Map of vault → {actualApy}
    deactivate useVaultHistoricalApy
    
    positionsView->>positionsView: Merge actualApy into vault objects
    positionsView->>userVaultsTable: Render with period + vaults
    activate userVaultsTable
    userVaultsTable->>User: Display period label + APY + tooltip
    deactivate userVaultsTable
    deactivate positionsView
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

feature request, ui

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective: adding APR/APY calculations and display in the position view across multiple components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/history-report

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


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 and usage tips.

@coderabbitai coderabbitai Bot added feature request Specific feature ready to be implemented ui User interface labels Feb 4, 2026
Copy link
Copy Markdown
Collaborator

@starksama starksama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

Changes reviewed:

  1. New hook — Clean implementation with proper multicall batching per network. Good use of useMemo for stable query keys and network grouping.

  2. Extended typesactualApy, avgCapital, effectiveTime properly added to MarketPositionWithEarnings and propagated through.

  3. Risk indicators removal — Clean deletion of vault-risk-indicators.tsx and corresponding imports/usage.

  4. UI updates — Period labels (1D/7D/30D) consistent across both vault and grouped tables. Loading states with PulseLoader are nice.

Minor observations (non-blocking):

  • The formatRate helper in user-vaults-table.tsx is clean — could potentially be extracted to utils if reused elsewhere later.
  • colSpan updated from 10→7 in grouped table matches the removed columns.

Ship it 🚀

Copy link
Copy Markdown
Collaborator

@starksama starksama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

Changes reviewed:

  1. New useVaultHistoricalApy hook — Clean implementation with proper multicall batching per network. Good use of useMemo for stable query keys and network grouping.

  2. Extended types — actualApy, avgCapital, effectiveTime properly added to MarketPositionWithEarnings and propagated through.

  3. Risk indicators removal — Clean deletion of vault-risk-indicators.tsx and corresponding imports/usage.

  4. UI updates — Period labels (1D/7D/30D) consistent across both vault and grouped tables. Loading states with PulseLoader are nice.

Minor observations (non-blocking):

  • The formatRate helper in user-vaults-table.tsx is clean — could potentially be extracted to utils if reused elsewhere later.
  • colSpan updated from 10→7 in grouped table matches the removed columns.

Ship it 🚀

@antoncoding antoncoding merged commit c0fcfcf into master Feb 4, 2026
4 checks passed
@antoncoding antoncoding deleted the feat/history-report branch February 4, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Specific feature ready to be implemented ui User interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants