feat(defi): show DeFi positions under the token table in chain view#252
Merged
Merged
Conversation
EVM asset pages now display DeFi positions (staked / supplied / borrowed /
LP / claimable protocol holdings) in their own section below the existing
token table, sourced from the KeepKey Zapper proxy
(GET /api/v1/zapper/portfolio/{address}).
Backend:
- New src/bun/zapper.ts with pure classifyDefiPosition / normalizeDefiPositions
helpers. An item is DeFi when any of tokenType === 'contract-position',
appId, groupId, or metaType is present; each is normalized with
is_defi + protocol (= appId) plus display fields. Plain wallet tokens are
dropped (Pioneer already serves those) so the section never duplicates them.
- fetchDefiPositions() hits the Zapper proxy at the resolved Pioneer base URL,
degrading to [] on any error (DeFi is supplementary).
- New getDefiPositions RPC (mirrors getStakingPositions); live-fetched,
display-only, not persisted.
Frontend:
- New DefiPositionsPanel renders below the token table on EVM chains only,
per active address. Values use the existing useFiat() formatting (shows BRL
when selected). Reuses the position icon when present and applies the same
hide-dust (zero-USD behind a toggle) behavior as the token list.
- Normal token list is unchanged.
Tests: 14 unit tests for the classification/normalization logic.
Note: full typecheck/build requires the hdwallet submodule pipeline
(make modules-build), not run in this environment.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EVM asset pages now display DeFi positions (staked / supplied / borrowed / LP / claimable protocol holdings) in their own section directly below the existing token table, sourced from the KeepKey Zapper proxy (
GET /api/v1/zapper/portfolio/{address}). The normal token list is unchanged.How DeFi positions are classified
An item from the Zapper response is marked DeFi when any of these are present:
tokenType === 'contract-position'appIdgroupIdmetaTypeEach is normalized with
is_defi: booleanandprotocol: appId ?? null, plus display fields (name, symbol, network, type, metaType, balance, balanceUsd, icon). Plain wallet tokens are dropped — Pioneer already serves those, so the DeFi section never duplicates the token table.Backend
src/bun/zapper.ts(new) — pureclassifyDefiPosition/normalizeDefiPositionshelpers +fetchDefiPositions(address). The fetch resolves the same base URL as every other Pioneer call and degrades to[]on any error (DeFi is supplementary).getDefiPositions({ address })RPC — mirrors the existinggetStakingPositionshandler. Live-fetched, display-only (not added to chain/portfolio totals), and not persisted (passphrase-safe).Frontend
DefiPositionsPanel.tsx(new) — lazy-loaded, rendered below the token table on EVM chains only, for the active address.useFiat()formatting, so they respect the user's selected currency (shows R$ when BRL is selected).enandpt.Scope boundaries (by design)
balanceUsdor portfolio totals (avoids double-counting against Pioneer's token entries and keeps cache/total/passphrase logic untouched).Testing
bun test __tests__/defi-classify.test.ts— 14 passing unit tests covering the DeFi detection rules, protocol mapping, field-normalization fallbacks, response-shape unwrapping, and malformed-input tolerance.make modules-build), which was not run in this environment.🤖 Generated with Claude Code