Skip to content

Feat/portfolio pnl 2#1125

Merged
w84april merged 30 commits intofeat/portfolio-history-apifrom
feat/portfolio-pnl-2
Apr 6, 2026
Merged

Feat/portfolio pnl 2#1125
w84april merged 30 commits intofeat/portfolio-history-apifrom
feat/portfolio-pnl-2

Conversation

@w84april
Copy link
Copy Markdown
Collaborator

@w84april w84april commented Mar 19, 2026

Description

This PR introduces a new holdings PnL engine for GET /api/holdings/pnl.

It adds:

  • FIFO lot-based PnL tracking per Yearn vault family
  • family-level accounting that treats the base vault and staking wrapper as a single position
  • transaction-scoped enrichment so router flows, stake/unstake flows, and supported migrations can preserve basis when possible
  • conservative handling of ambiguous transfers by marking lots as unknown-basis instead of inventing cost basis
  • USD mark-to-market PnL for known-basis lots using acquisition-time, realization-time, and current underlying token prices
  • configurable unknown transfer handling via strict, zero_basis, and windfall
  • completeness metadata (status, costBasisStatus, isComplete) so the API makes uncertainty explicit
  • supporting DefiLlama price-fetching/cache improvements needed to make repeated PnL requests fast and reusable
  • product / contributor documentation in api/lib/holdings/PNL.md

How Has This Been Tested?

Automated:

  • unit coverage for core PnL ledger / lot behavior in api/lib/holdings/services/pnl.test.ts
  • regression coverage for DefiLlama batching, missing-pair fetching, and requested-timestamp caching in api/lib/holdings/services/defillama.test.ts
  • bun run tslint
  • bun run lint:fix

Manual:

  • exercised GET /api/holdings/pnl against real wallets with deposits, withdrawals, staking wrappers, and transfer-heavy histories
  • repeated the same request to verify historical prices are cached under requested timestamps and warm requests only fetch fresh current prices

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 19, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 41075bd.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 19, 2026

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

Project Deployment Actions Updated (UTC)
yearnfi Ready Ready Preview, Comment Apr 6, 2026 8:29pm

Request Review

@rossgalloway
Copy link
Copy Markdown
Collaborator

When visiting the portfolio page, I get 502 errors on the api/holdings endpoint for multiple wallets (although one worked, but was not showing the correct balance)

Is there a way to test the PNL endpoint from the UI or does it need to be called from a CLI?

@w84april w84april marked this pull request as draft March 19, 2026 20:13
@w84april
Copy link
Copy Markdown
Collaborator Author

@rossgalloway my bad, this should have been drafted instead. this pr focuses on pnl api and likely breaks related stuff

* feat: init excessive

* chore: naming

* feat: actually add drilldown

* fix: v2/v3 filter

* fix: version

* fix: env

* feat: cover crvusd rewards

* feat: vault to vault migrate via enso

* feat: init katana rewards

* chore: upd receiver address

* feat: fix bold

* feat: add fetchType + paginationMode

* feat: support fetchtype + pagination on vercel
@w84april w84april merged commit 92423a8 into feat/portfolio-history-api Apr 6, 2026
7 checks passed
@w84april w84april deleted the feat/portfolio-pnl-2 branch April 6, 2026 20:32
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