Skip to content

feat(positions): add --defi flag with grouped DeFi view#77

Merged
graysonhyc merged 3 commits into
mainfrom
feat/positions-defi-flag
May 15, 2026
Merged

feat(positions): add --defi flag with grouped DeFi view#77
graysonhyc merged 3 commits into
mainfrom
feat/positions-defi-flag

Conversation

@graysonhyc
Copy link
Copy Markdown
Collaborator

Summary

  • New --defi flag on zerion positions — shorthand for --positions defi plus a DeFi-aware JSON shape (protocols[] → groups[] → tokens[]) grouped by dapp.
  • LP positions sharing a group_id collapse into a single pool entry. Loans are netted against deposits in per-protocol totals so the displayed value matches what the user "actually owns."
  • Pretty mode renders [position_type] badges colored by polarity: deposit/staked green, loan red, reward yellow, locked cyan.

API mapping

Uses the existing filter[positions]=only_complex route. Enrichment pulls protocol, protocol_module, position_type, group_id, pool_address, and application_metadata from each position's attributes.

Output shape (--defi, JSON)

{
  "wallet": {...},
  "filter": "defi",
  "summary": { "total_value": 4200, "gross_value": 4500, "protocols": 2, "positions": 4 },
  "protocols": [
    { "dapp": "Aave V3", "module": "lending", "net_value": 3700,
      "groups": [
        { "position_type": "deposit", "value": 4000, "tokens": [...] },
        { "position_type": "loan",    "value": 300,  "tokens": [...] }
      ]}
  ]
}

Conflict handling

--defi --positions all|simpleconflicting_flags error. --defi --positions defi is fine (treated as the same intent).

Test plan

  • npm test — 173 unit tests pass (6 new for formatDefiPositions)
  • node cli/zerion.js positions vitalik.eth --defi --pretty — manual smoke
  • node cli/zerion.js positions <addr> --defi --chain ethereum — chain filter still applies
  • node cli/zerion.js positions <addr> --defi --positions all — verify conflict error
  • Compare against old --positions defi --pretty output to confirm grouping reads better

🤖 Generated with Claude Code

graysonhyc and others added 3 commits May 15, 2026 12:45
Shorthand for --positions defi that returns a richer response grouped
by dapp -> group_id -> tokens. Loans net against deposits in per-protocol
totals. LP positions sharing a group_id collapse into a single pool row.

Pretty output adds position_type badges colored by polarity:
deposit/staked green, loan red, reward yellow, locked cyan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Describes the new --defi shorthand on `zerion positions`, the protocol/
group_id rollup, loan-netting in net_value vs gross_value, and the
conflicting_flags error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@graysonhyc graysonhyc merged commit 97da693 into main May 15, 2026
1 check passed
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