Skip to content

feat: Support profile based Perps trading fee grants [NEEDS CORE PR MERGED/RELEASED FIRST] - #37146

Open
geositta wants to merge 6 commits into
mainfrom
TAT-4020-rewards-grant
Open

geositta wants to merge 6 commits into
mainfrom
TAT-4020-rewards-grant

Conversation

@geositta

@geositta geositta commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds support for profile-based Perps trading fee grants. These grants apply to eligible Profile Sync users independently of Rewards opt-in or VIP membership.

Mobile retrieves grants using the Profile Sync JWT and supplies them to the fee resolver introduced in
MetaMask/core#10664. Core selects the lowest applicable fee and returns its source with the quote, preventing Mobile from applying discounts twice.

The UI now presents the resolved source appropriately:

  • VIP rewards retain the VIP badge.
  • Profile grants display “Promotional discount.”
  • Subscription or mixed/unknown discounts display “Fee discount.”

This also adds accurate original fee totals, mixed-source handling for close all flows, runtime response validation, stale profile protection, and focused test coverage.

Changelog

CHANGELOG entry: Added profile based promotional fee grants for eligible Perps trades.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-4020

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Simulator Screenshot - iPhone 17 Pro - 2026-10-08 at 21 48 38 Simulator Screenshot - iPhone 17 Pro - 2026-10-08 at 21 48 44

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches fee quoting, Rewards API auth, and payment-adjacent display logic across many Perps surfaces; incorrect grant or double-discount handling would misstate costs to users.

Overview
Adds profile-based Perps trading fee grants wired through Rewards (getPerpsTradingFeeGrant, Profile Sync JWT on GET /trading-fee-grants) and mobile infrastructure, without gating VIP discount lookup on the VIP feature flag. Bumps @metamask/perps-controller to a preview build so Core resolves the winning fee and returns feeSource; mobile hooks (usePerpsOrderFees, usePerpsCloseAllCalculations) stop re-applying Rewards discounts and only derive presentation via new feeDiscount helpers.

Fee UI now distinguishes attribution: VIP badge for rewards, “Promotional discount” for grants, generic “Fee discount” otherwise (PerpsFeeDiscountLabel, updated tooltips and trade/close summaries with originalTotalFees / feeDiscountKind). Close-all aggregation weights by notional and uses generic labeling when sources mix.

Separately, transaction history treats missing realized PnL as unknown (blank close amounts, safer fill aggregation) instead of coercing to zero.

Reviewed by Cursor Bugbot for commit af50d38. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

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.

@geositta geositta changed the title Tat 4020 rewards grant feat: Support profile based Perps trading fee grants Oct 2, 2026
@socket-security

socket-security Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​metamask-previews/​perps-controller@​19.0.0-preview-0305ce09010010098100

View full report

@geositta
geositta force-pushed the TAT-4020-rewards-grant branch from fa959e7 to f903a5e Compare October 2, 2026 00:54
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Smart E2E Test Selection

Selected E2E tags: ALL

Selected Performance tags: @PerformancePreps

AI Confidence: 100

E2E reasoning

Expand to read

This PR introduces significant changes to the Perps fee discount system and RewardsController:

  1. Package version update (hard rule seed: ALL): @metamask/perps-controller updated to a preview version 19.0.0-preview-0305ce0. This is a controller package change that could affect perps behavior broadly.

  2. SmokePerps (primary): Direct changes to perps fee display (PerpsFeesDisplay, PerpsFeeDiscountLabel replacing RewardsVipBadge), fee discount logic (new feeDiscount.ts utility with vip/promotional/generic kinds), order fees hooks (usePerpsOrderFees, usePerpsRewards, usePerpsCloseAllCalculations), close position flows (PerpsClosePositionBottomSheet, PerpsCloseAllPositionsView), trade screen (PerpsTradeScreen), and mobile infrastructure adapter (getPerpsTradingFeeGrant). These changes directly affect the perps Add Funds flow and position management.

  3. SmokeWalletPlatform (required by SmokePerps tag description): Perps is a section inside the Trending tab. Changes to Perps views (PerpsCloseAllPositionsView, PerpsOrderView, PerpsProMarketView) affect Trending.

  4. SmokeConfirmations (required by SmokePerps tag description): Perps Add Funds deposits are on-chain transactions that go through the confirmation flow. Fee display changes in the trade screen affect what users see during confirmation.

The hard rule seed selected ALL due to the controller package version update. I'm refining to the most relevant tags since the changes are scoped to Perps/Rewards functionality. The RewardsController changes (new getPerpsTradingFeeGrant method) and the perps-controller preview version are the highest-risk elements, but they primarily affect the perps flow rather than all wallet functionality. The activity adapter fix for perps transactions without PnL is also scoped to perps transaction history display.

Performance reasoning

Expand to read

The perps fee calculation logic has been significantly refactored (usePerpsOrderFees, usePerpsCloseAllCalculations, usePerpsRewards hooks all updated). The mobile infrastructure adapter now calls getPerpsTradingFeeGrant in addition to getPerpsDiscountForAccount, adding a new async call to the fee resolution path. These changes could impact perps market loading, position management, and add funds flow performance. @PerformancePreps covers perps market loading, position management, add funds flow, and order execution - all directly affected by these fee calculation changes.

View run

@aganglada aganglada added the team-perps Perps team label Oct 8, 2026
@metamask-ci

metamask-ci Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Manual testing steps still contain template content (the Gherkin example title or a [...] placeholder). Replace with real steps, or write N/A — <reason>.
  • Pre-merge author checklist has unchecked items (e.g. "I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards."). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

geositta and others added 5 commits October 8, 2026 21:52
display resolved perps fee discounts

use perps controller fee grant preview
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Alejandro Garcia Anglada <aganglada@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@geositta
geositta force-pushed the TAT-4020-rewards-grant branch from 55702f4 to ec648e6 Compare October 9, 2026 03:12
@geositta
geositta marked this pull request as ready for review October 9, 2026 03:28
@geositta
geositta requested review from a team as code owners October 9, 2026 03:28

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ec648e6. Configure here.

Comment thread app/components/UI/Perps/utils/feeDiscount.ts
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

⚡ Performance Test Results

ℹ️ Performance test results are currently non-blocking and will not block this PR.

⚠️ Results incomplete — No test results found


Branch: TAT-4020-rewards-grant · Build: E2E · Commit: 2e39f1e · View full run

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@geositta geositta changed the title feat: Support profile based Perps trading fee grants feat: Support profile based Perps trading fee grants [NOT READY] Oct 10, 2026
@geositta geositta changed the title feat: Support profile based Perps trading fee grants [NOT READY] feat: Support profile based Perps trading fee grants Oct 10, 2026
@geositta geositta changed the title feat: Support profile based Perps trading fee grants feat: Support profile based Perps trading fee grants [NOT READY] Oct 10, 2026
@geositta geositta changed the title feat: Support profile based Perps trading fee grants [NOT READY] feat: Support profile based Perps trading fee grants [NEEDS CORE PR MERGED/RELEASED FIRST] Oct 10, 2026

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants