Skip to content

fix: prefer selected evm account#30253

Merged
abretonc7s merged 8 commits into
mainfrom
perps/prefer-selected-evm-account
May 21, 2026
Merged

fix: prefer selected evm account#30253
abretonc7s merged 8 commits into
mainfrom
perps/prefer-selected-evm-account

Conversation

@geositta

@geositta geositta commented May 15, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates Perps account resolution so compliance gated Perps flows evaluate the same EVM account the user currently has selected.

As part of the compliance work, Perps needs to reliably identify the active wallet address before allowing account specific actions such as deposits, trades, signing, and account state operations. The previous logic derived the address from the selected account group, which could pick a different EVM account than the user facing selected account when multiple EVM accounts exist in the group.

The solution adds a selected-account-first lookup across the Perps controller and related services. Perps now reads AccountsController:getSelectedAccount when it is an EVM account, and falls back to the existing selected account group behavior when needed. The PR also delegates that action through the Perps controller messenger so the selected account path works at runtime.

This keeps Perps address resolution aligned with the active wallet while preserving compatibility with the existing account group fallback path.

This also wires Perps cache invalidation to selected-account changes, so switching between EVM accounts in the same account group clears stale user data and preloads data for the newly selected account.

Changelog

CHANGELOG entry: Prefer the selected EVM account when resolving Perps account state and compliance-gated actions.

Related issues

Fixes:

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

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
Changes how Perps resolves the active wallet address and when it clears/preloads cached user data, which can impact deposits/signing and account-scoped state if the new selection logic misidentifies the active account.

Overview
Perps now resolves the active EVM address by preferring AccountsController:getSelectedAccount (when it’s an EVM account) and falling back to the selected account group, via new getSelectedEvmAccountFromMessenger helpers.

This selection logic is applied across PerpsController and related services (deposit/withdrawal, wallet adapters, rewards, data lake reporting), and market/user-data preloading now also listens to AccountsController:selectedAccountChange to clear disk+memory user cache and refresh data on account switches. Tests were added/updated to cover selected-account preference, cache invalidation, and messenger delegation.

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

@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.

@metamaskbotv2 metamaskbotv2 Bot added the team-perps Perps team label May 15, 2026
@github-actions github-actions Bot added pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. size-M labels May 15, 2026
@geositta geositta marked this pull request as ready for review May 18, 2026 14:51
@geositta geositta requested a review from a team as a code owner May 18, 2026 14:51
Comment thread app/controllers/perps/PerpsController.ts
@geositta geositta changed the title fix(perps): prefer selected evm account fix(perps): prefer selected evm account [NOT READY] May 19, 2026
Comment thread app/controllers/perps/utils/accountUtils.ts
@geositta geositta force-pushed the perps/prefer-selected-evm-account branch from 90862bc to 054bf27 Compare May 20, 2026 01:13

@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 2 potential issues.

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 054bf27. Configure here.

Comment thread app/controllers/perps/PerpsController.ts
Comment thread app/controllers/perps/services/HyperLiquidWalletService.test.ts Outdated
@geositta geositta changed the title fix(perps): prefer selected evm account [NOT READY] fix: prefer selected evm account [NOT READY] May 20, 2026
@geositta geositta changed the title fix: prefer selected evm account [NOT READY] fix: prefer selected evm account May 20, 2026
@github-actions github-actions Bot added size-L and removed size-M labels May 20, 2026
@geositta geositta force-pushed the perps/prefer-selected-evm-account branch from eec46e9 to d3e5f0c Compare May 20, 2026 12:59
@abretonc7s abretonc7s enabled auto-merge May 21, 2026 01:55
@abretonc7s abretonc7s removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label May 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR refactors account resolution in the PerpsController and all its services (AccountService, DataLakeService, DepositService, HyperLiquidWalletService, MYXWalletService, RewardsIntegrationService). The key changes are:

  1. A new utility function getSelectedEvmAccountFromMessenger replaces direct AccountTreeController:getAccountsFromSelectedAccountGroup calls across all perps services. The new function first tries AccountsController:getSelectedAccount (more direct/reliable) and falls back to the AccountTree approach.

  2. The PerpsController now subscribes to AccountsController:selectedAccountChange in addition to AccountTreeController:selectedAccountGroupChange for account change detection.

  3. The messenger configuration is updated to allow the new AccountsController action and event.

This is a medium-risk refactoring that changes how the selected EVM account is resolved across all perps operations. While the logic is equivalent (with an improved primary path), any regression could break:

  • The Add Funds deposit flow (DepositService)
  • Wallet adapter creation for signing (HyperLiquidWalletService, MYXWalletService)
  • Account change detection and cache invalidation (PerpsController)
  • Balance/rewards calculations (AccountService, DataLakeService, RewardsIntegrationService)

Tags selected:

  • SmokePerps: Directly tests perps functionality including Add Funds flow and balance verification — the primary area affected by these changes
  • SmokeWalletPlatform: Required by SmokePerps description (Perps is a section inside Trending tab); also covers multi-SRP architecture which is relevant since account resolution is changing
  • SmokeConfirmations: Required by SmokePerps description (Add Funds deposits are on-chain transactions)

Performance Test Selection:
The changes are a refactoring of account resolution logic — replacing direct AccountTreeController calls with a new utility function that adds a primary path via AccountsController with fallback. This is a code quality improvement with no expected performance impact. The account resolution is a lightweight synchronous/async call that doesn't affect rendering, list performance, or app startup times. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@abretonc7s abretonc7s added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit cc154d3 May 21, 2026
274 of 280 checks passed
@abretonc7s abretonc7s deleted the perps/prefer-selected-evm-account branch May 21, 2026 06:41
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-L team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants