Skip to content

refactor(perps): ensure object parameter consistency in controller files#25688

Merged
abretonc7s merged 4 commits intomainfrom
refactor/perps/cleanup-signature
Feb 6, 2026
Merged

refactor(perps): ensure object parameter consistency in controller files#25688
abretonc7s merged 4 commits intomainfrom
refactor/perps/cleanup-signature

Conversation

@abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Feb 5, 2026

Description

This PR refactors the Perps codebase to ensure consistent usage of object parameters across all service and provider methods. This is a pure code quality improvement with no behavioral changes.

Changes Summary

1. HyperLiquidClientService.ts

  • Extracted repeated inline wallet type to HyperLiquidWalletParams interface (was duplicated 3x)
  • Converted ensureTransportReady(timeoutMs) to ensureTransportReady({ timeoutMs? })
  • Converted fetchHistoricalCandles(symbol, interval, limit, endTime) to object params

2. EligibilityService.ts

  • Converted checkEligibility(blockedRegions) to checkEligibility({ blockedRegions })

3. HyperLiquidProvider.ts

  • Updated updateMargin() to use existing UpdateMarginParams type from types/index.ts

4. PerpsController.ts

  • Updated fetchHistoricalCandles() to use object parameters

5. Updated all call sites:

  • HyperLiquidSubscriptionService.ts
  • MarketDataService.ts
  • CandleStreamChannel.ts
  • All related test files

Why This Change

The Perps codebase already uses object parameters pattern for ~95% of its methods. This PR addresses the remaining 5% of inconsistencies to:

  • Ensure a consistent API style across the codebase
  • Reduce code duplication (wallet type was defined inline 3 times)
  • Make future API extensions easier (adding optional params to object is non-breaking)
  • Align with the established patterns in PerpsProvider interface

Changelog

CHANGELOG entry: null

Related issues

N/A - Code quality refactor

Manual testing steps

Feature: Perps functionality works unchanged

  Scenario: User views candle charts
    Given user is on a perps trading view
    When user opens the chart for any asset
    Then chart should display candle data correctly

  Scenario: Eligibility check works
    Given user opens perps feature
    When geo-location is checked
    Then eligibility is determined correctly based on blocked regions

Screenshots/Recordings

N/A - No visual changes

Before

N/A

After

N/A

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.

Note

Low Risk
Mostly signature/type refactors with updated tests; primary risk is missed call sites or subtle default-value differences causing runtime argument mismatches.

Overview
Standardizes Perps controller/service/provider APIs to use object parameters instead of positional arguments, updating all call sites and tests accordingly.

Key refactors include: PerpsController.fetchHistoricalCandles, MarketDataService delegation to provider clientService.fetchHistoricalCandles, EligibilityService.checkEligibility, and HyperLiquidClientService.ensureTransportReady/fetchHistoricalCandles (plus extracting a shared HyperLiquidWalletParams type). HyperLiquidProvider.updateMargin is also switched to the shared UpdateMarginParams type.

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

@abretonc7s abretonc7s requested a review from a team as a code owner February 5, 2026 04:29
@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

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.

@metamaskbot metamaskbot added the team-perps Perps team label Feb 5, 2026
@github-actions github-actions bot added the size-M label Feb 5, 2026
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.50%. Comparing base (e922e16) to head (2b56903).
⚠️ Report is 106 commits behind head on main.

Files with missing lines Patch % Lines
...components/UI/Perps/controllers/PerpsController.ts 50.00% 1 Missing ⚠️
...ents/UI/Perps/services/HyperLiquidClientService.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25688      +/-   ##
==========================================
- Coverage   80.50%   80.50%   -0.01%     
==========================================
  Files        4292     4296       +4     
  Lines      111089   111268     +179     
  Branches    23641    23697      +56     
==========================================
+ Hits        89432    89574     +142     
- Misses      15442    15461      +19     
- Partials     6215     6233      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@abretonc7s abretonc7s enabled auto-merge February 5, 2026 13:15
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR is a refactoring effort that converts function signatures from positional parameters to named object parameters across the Perps (perpetuals trading) feature. The changes affect:

  1. PerpsController.ts (marked CRITICAL): Modified fetchHistoricalCandles() and checkEligibility() call signatures
  2. HyperLiquidProvider.ts: Updated updateMargin() to use typed params
  3. EligibilityService.ts: Changed checkEligibility() signature
  4. MarketDataService.ts: Updated type definitions and call sites
  5. HyperLiquidClientService.ts: Extracted wallet interface, updated multiple method signatures
  6. CandleStreamChannel.ts and HyperLiquidSubscriptionService.ts: Updated call sites

Key observations:

  • Pure refactoring: No logic changes, only parameter passing style changes
  • All changes internal to Perps module: No external API changes
  • Unit tests updated: All 4 test files have been updated to match new signatures
  • Type safety improvements: Added CheckEligibilityParams and HyperLiquidWalletParams interfaces

Selected tags based on tag descriptions:

  • SmokePerps: Primary tag - tests perpetuals trading functionality including Add Funds flow, balance verification, and Perps interface
  • SmokeWalletPlatform: Perps is a section inside the Trending tab; changes to Perps views affect Trending
  • SmokeConfirmations: Per SmokePerps description, Add Funds deposits are on-chain transactions requiring confirmation testing

Risk is medium because while the changes are refactoring-only with no logic changes, they touch a critical controller (PerpsController) and multiple service layers that handle real trading functionality.

Performance Test Selection:
The changes affect the Perps feature including HyperLiquidClientService which handles WebSocket connections, candle data fetching, and subscription management. While the changes are refactoring (parameter style changes), they touch performance-sensitive areas like data streaming and market data fetching. Running @PerformancePreps will validate that the refactored code maintains expected performance for perps market loading, position management, and add funds flow.

View GitHub Actions results

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
78.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@abretonc7s abretonc7s added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Feb 6, 2026
@abretonc7s abretonc7s added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit 6a41411 Feb 6, 2026
362 of 376 checks passed
@abretonc7s abretonc7s deleted the refactor/perps/cleanup-signature branch February 6, 2026 09:34
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2026
@metamaskbot metamaskbot added the release-7.66.0 Issue or pull request that will be included in release 7.66.0 label Feb 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.66.0 Issue or pull request that will be included in release 7.66.0 size-M skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants