Skip to content

feat: defer eligibility to allow for onboarding to proceed without le…#8197

Merged
gambinish merged 5 commits into
mainfrom
perps/feat/defer-eligibility
Mar 16, 2026
Merged

feat: defer eligibility to allow for onboarding to proceed without le…#8197
gambinish merged 5 commits into
mainfrom
perps/feat/defer-eligibility

Conversation

@gambinish

@gambinish gambinish commented Mar 12, 2026

Copy link
Copy Markdown
Member

Explanation

Add deferEligibilityCheck constructor option that prevents the eager geolocation fetch to on-ramp.api.cx.metamask.io/geolocation from firing during wallet onboarding, fixing a privacy compliance violation in the extension's maximum-privacy onboarding E2E test

Add startEligibilityMonitoring() public method that the consumer calls post-onboarding to read the current feature flag state, perform the initial eligibility check, and unblock the already-registered RemoteFeatureFlagController:stateChange subscription

Implementation uses a single guard in refreshEligibilityOnFeatureFlagChange

Note: This does not update the perps-controller to use the new geolocation service. This would require removing the existing EligibilityService in order to keep the change as minimal as possible to unblock extension development. We can revisit to migrate to this new service soon after the blocked extension PRs have been merged.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes geo-blocking eligibility timing by gating refreshEligibility() behind a new deferral flag and adding a new public start hook; mistakes could leave users incorrectly marked ineligible/eligible until monitoring starts.

Overview
Adds an opt-in deferEligibilityCheck constructor option to prevent geo-blocking eligibility checks (and the associated geolocation fetch) from running during PerpsController construction.

Introduces startEligibilityMonitoring() (exposed via messenger) to re-enable eligibility processing post-onboarding by reading current RemoteFeatureFlagController state and triggering the initial eligibility evaluation; refreshEligibility() now no-ops while deferred.

Adds unit tests covering the deferral behavior, the new start method, and the default non-deferred path.

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

@gambinish gambinish requested review from a team as code owners March 12, 2026 19:40
Comment thread packages/perps-controller/src/PerpsController.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

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

Comment thread packages/perps-controller/src/PerpsController.ts
@gambinish

Copy link
Copy Markdown
Member Author

@metamaskbot publish-previews

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "5.0.1-preview-935b6049c",
  "@metamask-previews/accounts-controller": "37.0.0-preview-935b6049c",
  "@metamask-previews/address-book-controller": "7.0.1-preview-935b6049c",
  "@metamask-previews/ai-controllers": "0.2.0-preview-935b6049c",
  "@metamask-previews/analytics-controller": "1.0.0-preview-935b6049c",
  "@metamask-previews/analytics-data-regulation-controller": "0.0.0-preview-935b6049c",
  "@metamask-previews/announcement-controller": "8.0.0-preview-935b6049c",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-935b6049c",
  "@metamask-previews/approval-controller": "8.0.0-preview-935b6049c",
  "@metamask-previews/assets-controller": "2.3.0-preview-935b6049c",
  "@metamask-previews/assets-controllers": "100.2.1-preview-935b6049c",
  "@metamask-previews/base-controller": "9.0.0-preview-935b6049c",
  "@metamask-previews/base-data-service": "0.0.0-preview-935b6049c",
  "@metamask-previews/bridge-controller": "69.1.0-preview-935b6049c",
  "@metamask-previews/bridge-status-controller": "68.1.0-preview-935b6049c",
  "@metamask-previews/build-utils": "3.0.4-preview-935b6049c",
  "@metamask-previews/chain-agnostic-permission": "1.4.0-preview-935b6049c",
  "@metamask-previews/claims-controller": "0.4.3-preview-935b6049c",
  "@metamask-previews/client-controller": "1.0.0-preview-935b6049c",
  "@metamask-previews/compliance-controller": "1.0.1-preview-935b6049c",
  "@metamask-previews/composable-controller": "12.0.0-preview-935b6049c",
  "@metamask-previews/config-registry-controller": "0.1.1-preview-935b6049c",
  "@metamask-previews/connectivity-controller": "0.1.0-preview-935b6049c",
  "@metamask-previews/controller-utils": "11.19.0-preview-935b6049c",
  "@metamask-previews/core-backend": "6.1.1-preview-935b6049c",
  "@metamask-previews/delegation-controller": "2.0.2-preview-935b6049c",
  "@metamask-previews/earn-controller": "11.1.2-preview-935b6049c",
  "@metamask-previews/eip-5792-middleware": "3.0.0-preview-935b6049c",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-935b6049c",
  "@metamask-previews/eip1193-permission-middleware": "1.0.3-preview-935b6049c",
  "@metamask-previews/ens-controller": "19.0.3-preview-935b6049c",
  "@metamask-previews/error-reporting-service": "3.0.1-preview-935b6049c",
  "@metamask-previews/eth-block-tracker": "15.0.1-preview-935b6049c",
  "@metamask-previews/eth-json-rpc-middleware": "23.1.0-preview-935b6049c",
  "@metamask-previews/eth-json-rpc-provider": "6.0.0-preview-935b6049c",
  "@metamask-previews/foundryup": "1.0.1-preview-935b6049c",
  "@metamask-previews/gas-fee-controller": "26.0.3-preview-935b6049c",
  "@metamask-previews/gator-permissions-controller": "2.1.0-preview-935b6049c",
  "@metamask-previews/geolocation-controller": "0.1.1-preview-935b6049c",
  "@metamask-previews/json-rpc-engine": "10.2.3-preview-935b6049c",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-935b6049c",
  "@metamask-previews/keyring-controller": "25.1.0-preview-935b6049c",
  "@metamask-previews/logging-controller": "7.0.1-preview-935b6049c",
  "@metamask-previews/message-manager": "14.1.0-preview-935b6049c",
  "@metamask-previews/messenger": "0.3.0-preview-935b6049c",
  "@metamask-previews/multichain-account-service": "7.1.0-preview-935b6049c",
  "@metamask-previews/multichain-api-middleware": "1.2.7-preview-935b6049c",
  "@metamask-previews/multichain-network-controller": "3.0.5-preview-935b6049c",
  "@metamask-previews/multichain-transactions-controller": "7.0.2-preview-935b6049c",
  "@metamask-previews/name-controller": "9.0.0-preview-935b6049c",
  "@metamask-previews/network-controller": "30.0.0-preview-935b6049c",
  "@metamask-previews/network-enablement-controller": "4.2.0-preview-935b6049c",
  "@metamask-previews/notification-services-controller": "23.0.0-preview-935b6049c",
  "@metamask-previews/permission-controller": "12.2.0-preview-935b6049c",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-935b6049c",
  "@metamask-previews/perps-controller": "1.0.1-preview-935b6049c",
  "@metamask-previews/phishing-controller": "16.3.0-preview-935b6049c",
  "@metamask-previews/polling-controller": "16.0.3-preview-935b6049c",
  "@metamask-previews/preferences-controller": "23.0.0-preview-935b6049c",
  "@metamask-previews/profile-metrics-controller": "3.0.3-preview-935b6049c",
  "@metamask-previews/profile-sync-controller": "28.0.0-preview-935b6049c",
  "@metamask-previews/ramps-controller": "12.0.0-preview-935b6049c",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-935b6049c",
  "@metamask-previews/remote-feature-flag-controller": "4.1.0-preview-935b6049c",
  "@metamask-previews/sample-controllers": "4.0.3-preview-935b6049c",
  "@metamask-previews/seedless-onboarding-controller": "8.1.0-preview-935b6049c",
  "@metamask-previews/selected-network-controller": "26.0.3-preview-935b6049c",
  "@metamask-previews/shield-controller": "5.0.1-preview-935b6049c",
  "@metamask-previews/signature-controller": "39.0.5-preview-935b6049c",
  "@metamask-previews/storage-service": "1.0.0-preview-935b6049c",
  "@metamask-previews/subscription-controller": "6.0.1-preview-935b6049c",
  "@metamask-previews/transaction-controller": "62.21.0-preview-935b6049c",
  "@metamask-previews/transaction-pay-controller": "16.4.1-preview-935b6049c",
  "@metamask-previews/user-operation-controller": "41.0.3-preview-935b6049c"
}

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

We cant modify core directly, it should come from mobile than sync to core or we loose mobile as source of truth

abretonc7s
abretonc7s previously approved these changes Mar 16, 2026

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

Approving before the resync

@abretonc7s abretonc7s added this pull request to the merge queue Mar 16, 2026
@abretonc7s abretonc7s removed this pull request from the merge queue due to a manual request Mar 16, 2026
Comment thread packages/perps-controller/CHANGELOG.md
@gambinish gambinish removed the request for review from a team March 16, 2026 15:44
@gambinish gambinish enabled auto-merge March 16, 2026 15:48
@gambinish gambinish added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit dd45156 Mar 16, 2026
321 of 322 checks passed
@gambinish gambinish deleted the perps/feat/defer-eligibility branch March 16, 2026 15:59
github-merge-queue Bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Mar 19, 2026
)

## **Description**

Adds `deferEligibilityCheck` constructor option to `PerpsController`
that prevents the eager geolocation fetch during wallet onboarding
(privacy compliance). Also adds `startEligibilityMonitoring()` method to
resume checks post-onboarding.

Follow-up fixes included in this PR:
- **Remove mobile-only imports from perps controller code** —
`@sentry/react-native` (PerpsController, TradingService) and
`AppConstants` (MYXClientService) were breaking core sync. Routed
`addBreadcrumb` through `PerpsTracer` infrastructure injection, replaced
`AppConstants.ZERO_ADDRESS` with existing perps constant.
- **Fix core sync script** — `--ext .ts` no longer works with core's
flat eslint config; replaced with glob patterns.
- **Fix `@metamask/geolocation-controller` missing from core
tsconfig/package.json** — added as devDependency and project reference
so perps-controller builds in core.

## **Changelog**

CHANGELOG entry: null

## **Related issues**

Fixes: Core PR [#8197](MetaMask/core#8197)

## **Manual testing steps**

```gherkin
Feature: Deferred eligibility check

  Scenario: PerpsController defers geolocation during onboarding
    Given PerpsController is instantiated with deferEligibilityCheck: true

    When refreshEligibility is called
    Then it returns immediately without fetching geolocation

  Scenario: Eligibility monitoring resumes post-onboarding
    Given PerpsController was instantiated with deferEligibilityCheck: true

    When startEligibilityMonitoring() is called
    Then eligibility checks resume using current remote feature flag state
```

## **Screenshots/Recordings**

N/A — internal controller changes, no UI impact.

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).

## **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.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches eligibility/geo-blocking flow by optionally skipping
geolocation and adding a new entry point to re-enable checks, which
could affect region-gating if misused. Default behavior is unchanged
when the new option is not set, and coverage is added via unit tests.
> 
> **Overview**
> Adds an optional `deferEligibilityCheck` constructor flag to
`PerpsController` that **prevents the initial geolocation-based
eligibility check** from running until explicitly resumed.
> 
> Introduces `startEligibilityMonitoring()` (also exposed via messenger
action types) to clear the deferral, read current remote feature flags,
and immediately trigger an eligibility refresh, with error logging if
feature-flag state lookup fails.
> 
> Extends `PerpsController` tests to cover the deferred/ resumed
behavior and error logging, plus a small typing cleanup in preload cache
key assertions.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cf17d6b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
github-merge-queue Bot pushed a commit that referenced this pull request Mar 25, 2026
## Explanation

Mobile (`feat/perps/core-resolver`, PR MetaMask/metamask-mobile#27899)
is the source of truth for perps code. The last sync to core was Feb 26
— 27 days stale. Since then, 4 commits went directly to core (#7941,
#8197, #8214, #8234), all of which have been backported into the mobile
branch.

This PR syncs the latest mobile perps code to core using
`validate-core-sync.sh`. Key changes:

- **Geolocation dependency**: Added `@metamask/geolocation-controller`
as a devDependency + tsconfig reference — `messenger.ts` now imports
`GeolocationControllerGetGeolocationAction` for eligibility geolocation
checks.
- **New files**: `MYXWalletService.ts` (MYX wallet integration) and
`PerpsController-method-action-types.ts` (typed action map).
- **Package exclusion**: Added `!dist/services/MYXWalletService*` to
`files` in `package.json` to keep MYX code out of published package.
- **MYX provider**: Enhanced error handling (tightened to `error.code`
check), wallet service integration, expanded config constants.
- **HyperLiquid provider**: Subscription reliability improvements, order
book processing, expanded event names.
- **Eligibility service**: Refactored for geolocation-based region
blocking via GeolocationController messenger action.
- **ESLint**: 3 suppressions (1 `no-restricted-globals` for `require()`
in MYX dynamic load, 2 `@typescript-eslint/no-base-to-string` in
myxAdapter).

Supersedes stale PR #8207 (`feat/perps/newsync`, 139 commits behind
main).

## References

- Supersedes #8207
- Related to MetaMask/metamask-mobile#27899
- Backported core PRs: #7941, #8197, #8214, #8234

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches core Perps controller/provider logic (provider init, caching,
eligibility geo-checks) and adds MYX wallet/authenticated reads, which
could affect data freshness and provider availability across networks.
> 
> **Overview**
> Syncs Perps code from mobile into core, including **new MYX
wallet/auth plumbing** and broader provider/config updates.
> 
> `PerpsController` now (a) defers messenger handler registration until
`init()`, (b) resolves MYX enablement via credentials/flags and
dynamically imports/registers MYX with explicit auth config resolution,
and (c) replaces single cached preload fields with
**per-provider/per-network market+user caches** (with reinit guards and
preload retriggering).
> 
> Adds geolocation-based eligibility checking via
`GeolocationController:getGeolocation`, expands analytics/event
constants, and refactors exports to explicit named exports. HyperLiquid
reliability is improved with better multi-DEX failure handling, asset-id
repair/backfill, stale market-data fallback, configurable builder
addresses, and a new `fetchHistoricalCandles`; MYX config/endpoints are
updated and `MYXProvider` gains authenticated read support
(positions/orders/fills/funding/history) plus candle subscription (REST
+ WS updates).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d8a453d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants