feat: display Hyperliquid perp positions in Social Leaderboard (TSA-628)#31570
feat: display Hyperliquid perp positions in Social Leaderboard (TSA-628)#31570joaosantos15 wants to merge 9 commits into
Conversation
Render perp metadata across the Social Leaderboard trader profile and position detail screens, consuming the new perp fields exposed by @metamask/social-controllers. - Add a shared PerpBadges component (leverage pill + LONG/SHORT pill) and perp helpers (isPerpPosition / direction resolution for positions and trades). - Trader profile position rows and the position detail header show the Hyperliquid network badge, leverage, and long/short direction for perps; spot rows are unchanged. - Trade rows read "opened/closed" with leverage + direction badges for perp fills. - The position detail footer swaps the single Buy CTA for Long/Short buttons on perps (placeholders — not wired to a flow yet); the chart shows its existing no-data placeholder since perp pricing isn't available. - Pin @metamask/social-controllers to the perps preview build so the new Position/Trade perp fields are available (paired with MetaMask/core#9094). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
|
||
| /** | ||
| * Resolves the side (long/short) of a perp trade. Prefers `perpPositionType`; | ||
| * for perp-classified fills that omit it, infers from `direction` |
There was a problem hiding this comment.
hmm afaik there shouldn't be perp-classified fills that don't have a perpPositionType - if you saw some in the API responses let's sync up about it! There are a lot of event types on HL because the chain natively implements several forms of liquidation but I think we assign a perpPositionType to all of those.
| return position.perpPositionType; | ||
| } | ||
| if (position.chain?.toLowerCase() === HYPERLIQUID_CHAIN_NAME) { | ||
| return (position.positionAmount ?? 0) < 0 ? 'short' : 'long'; |
There was a problem hiding this comment.
hmm I think this could work but I generally worry that the multiple paths in the data => display mapping here could make things hard to debug. Maybe we can do some data integrity checks on the clicker side and/or add stronger perp data types so that this isn't necessary.
This defensiveness may be here because perpPositionType is nullable in Clicker API schema, but it'd really be better expressed as a union type - for the perps side of the union, it is always populated.
Make PnL coloring consistent across the trader profile list and the position detail card: the absolute $ amount stays neutral and the percentage carries the red/green, matching spot rows (PositionRow, TraderPositionPnLCard). Snapshot of in-progress TSA-628 Social Leaderboard work in the working tree (perp position rendering, Hyperliquid price utils, navigation and locale updates). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # app/components/Views/SocialLeaderboard/TraderPositionView/TraderPositionView.tsx # app/components/Views/SocialLeaderboard/TraderProfileView/components/PositionRow.tsx # yarn.lock
SOCIAL_API_URL fell back to http://localhost:3000, which would point shipped builds at a local dev server. Default to the production social-api host (https://social.api.cx.metamask.io), matching the DIGEST/SECURITY_ALERTS pattern; set SOCIAL_API_URL locally to override. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The profile headline summed perChainPnl across SPOT_CHAINS only, excluding hyperliquid. That made a perps-only trader's "30D Return" show $0 even though the leaderboard (chain-filtered) showed their real PnL. The spot-only exclusion is correct for the "All" leaderboard ranking (so perps don't dominate it) but wrong on an individual profile. Sum perChainPnl across all chains (including hyperliquid) for the headline; still fall back to the global stats.pnl30d when no per-chain breakdown exists. Spot-only traders are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…amount sign - PositionRow renders the leveraged size (positionAmountWithLeverage) for perps so the displayed size, the leverage badge, and the (now leverage-correct) PnL cohere. - getPerpPositionDirection returns null when perpPositionType is absent instead of inferring a side from the sign of positionAmount. Clicker reports perp size as a positive magnitude and conveys direction only via perpPositionType, so the sign is not a reliable signal (HL spot tokens can carry a negative amount with no side), which previously produced fabricated long/short badges. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Description
Adds Hyperliquid (perps) support to the Social Leaderboard UI — the second step of the perps work, consuming the perp fields now exposed by
@metamask/social-controllersand the social API.What changed
PerpBadgescomponent (leverage pill +LONG/SHORTpill) andutils/perp.tshelpers (isPerpPosition/isPerpTrade+ long/short direction resolution), so perp classification lives in one place.getPositionNetworkBadgeresolves the Hyperliquid network logo (HyperEVM image source) for the token avatar badge, without addinghyperliquidtochainNameToId(so the spot price/QuickBuy paths still treat it as unsupported).@metamask/social-controllersto the perps preview build so the newPosition/Tradeperp fields are typed/available.Motivation: unblock the mobile Perps leaderboard/position UX (perp metadata was being dropped because the client types/UI didn't model it).
Perp PnL display corrections (audit follow-up — TSA-726)
positionAmountWithLeverage) for perps, so the displayed size, the leverage badge, and the (now leverage-correct) PnL coming from the API cohere.getPerpPositionDirectionno longer infers a side from the sign ofpositionAmount— Clicker reports perp size as a positive magnitude and conveys direction only viaperpPositionType, so the sign is not a reliable signal (HL spot tokens can carry a negative amount with no side). It returnsnullwhen the side is absent, removing fabricatedLONG/SHORTbadges. Pairs with the server-side PnL fix in consensys-vertical-apps/va-mmcx-social-api#86.Changelog
CHANGELOG entry: Added Hyperliquid perpetuals to the Social Leaderboard — trader profiles and position details now show leverage, long/short direction, and the Hyperliquid network badge.
Related issues
Fixes: TSA-628
Part of: TSA-726 (mobile display portion — perp PnL is computed server-side in consensys-vertical-apps/va-mmcx-social-api#86)
Depends on:
@metamask/social-controllersperp fields — pinned here as a preview build until released)chains=all+ gated perp notifications)Manual testing steps
Screenshots/Recordings
Before
Spot-only positions; no leverage/direction/HL badge.
After
To be captured on-device before marking Ready for review — matches the approved designs (profile list with
5x LONG/8x SHORTrows + HL badge, and the position detail with leverage/direction badges and Long/Short footer).Pre-merge author checklist