Skip to content

feat(rewards|perps): support batch points estimation for perps#21658

Merged
abretonc7s merged 3 commits into
mainfrom
feat/rewards/batch-close
Oct 27, 2025
Merged

feat(rewards|perps): support batch points estimation for perps#21658
abretonc7s merged 3 commits into
mainfrom
feat/rewards/batch-close

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds support for batch PERPS position estimation in the RewardsController to enable the "close all positions" feature. The backend API (rewards team PR #247) was already deployed with support for accepting perpsContext as either a single object or an array of positions, returning aggregated points and bonus estimates.

Changes:

  1. Updated EstimatePointsContextDto type to accept perpsContext as either a single object or an array
  2. Enhanced JSDoc documentation to explain batch estimation behavior (aggregated points sum + average bonus)
  3. Added minimal unit test coverage for batch PERPS array functionality

The implementation maintains backwards compatibility with existing single-position calls and follows a pass-through architecture (no controller logic changes needed).

Changelog

CHANGELOG entry: support batch points estimation for perps

Related issues

Fixes:

Manual testing steps

Feature: Batch PERPS position rewards estimation

  Scenario: user estimates rewards for closing multiple PERPS positions
    Given user has multiple open PERPS positions
    And rewards feature is enabled
    And user has opted into rewards

    When user requests to close all positions
    Then RewardsController estimates points for all positions in a single batch request
    And backend returns aggregated points estimate (sum of all position points)
    And backend returns average bonus across all positions

Screenshots/Recordings

N/A - Backend/Controller change only, no UI modifications

Before

perpsContext only accepted single object

After

perpsContext accepts single object or array of objects for batch estimation

Pre-merge author checklist

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.

Technical Details

Files Modified:

  • app/core/Engine/controllers/rewards-controller/types.ts (lines 133-147)
  • app/core/Engine/controllers/rewards-controller/RewardsController.ts (lines 1544-1550)
  • app/core/Engine/controllers/rewards-controller/RewardsController.test.ts (lines 820-850)

Type Changes:

// Before
perpsContext?: EstimatePerpsContextDto;

// After
perpsContext?: EstimatePerpsContextDto | EstimatePerpsContextDto[];

Test Coverage:

  • Added test: "estimates points for batch PERPS positions with array"
  • All existing tests pass (4/4 estimatePoints tests passing)
  • No regressions introduced

Note

Add batch PERPS points estimation by allowing perpsContext to be an array, updating docs, and adding a unit test; controller forwards requests unchanged.

  • Rewards/Perps:
    • Types: Update EstimatePointsContextDto to accept perpsContext as EstimatePerpsContextDto | EstimatePerpsContextDto[] for batch estimation.
    • Controller: Add JSDoc note in RewardsController.estimatePoints documenting batch behavior (aggregated points, average bonus).
    • Tests: Add unit test in RewardsController.test.ts to verify estimating points with an array of PERPS positions passes through to RewardsDataService:estimatePoints.

Written by Cursor Bugbot for commit 42bf6bb. This will update automatically on new commits. Configure here.

@abretonc7s abretonc7s requested a review from a team as a code owner October 27, 2025 01:02
@github-actions

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.

@abretonc7s abretonc7s added team-perps Perps team team-rewards Rewards team and removed team-earn labels Oct 27, 2025
@abretonc7s abretonc7s added the No QA Needed Apply this label when your PR does not need any QA effort. label Oct 27, 2025
@abretonc7s abretonc7s enabled auto-merge October 27, 2025 12:27
@sonarqubecloud

Copy link
Copy Markdown

@abretonc7s abretonc7s added this pull request to the merge queue Oct 27, 2025
Merged via the queue into main with commit 9713bcd Oct 27, 2025
83 checks passed
@abretonc7s abretonc7s deleted the feat/rewards/batch-close branch October 27, 2025 14:16
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2025
@metamaskbot metamaskbot added the release-7.59.0 Issue or pull request that will be included in release 7.59.0 label Oct 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

No QA Needed Apply this label when your PR does not need any QA effort. release-7.59.0 Issue or pull request that will be included in release 7.59.0 size-S team-perps Perps team team-rewards Rewards team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants