feat(perps): core resolver — providerCredentials, builder fee injection, env var centralization#27899
Conversation
…dynamic MYX import) Backport two commits made directly in core since the last mobile→core sync: - Add stopEligibilityMonitoring() method to disable geo-blocking checks when useExternalServices is toggled off (core 902236dba) - Dynamic import for MYXProvider to avoid bundling heavy MYX dependencies in extension until MYX fixes their package (core ee7281491)
|
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. |
…ar centralization
- Restructure PerpsControllerConfig: flat MYX fields → nested providerCredentials.{hyperliquid,myx}
- Inject HL builder fee addresses via config instead of hardcoded constants
- Move all process.env reads from Engine init to createMobileClientConfig() in mobileInfrastructure adapter
- Fix MYX dynamic import race condition: await in non-async → .then()/.catch()
- Extract #assignActiveProvider from #createProviders, called after await Promise.all([wait, myxRegistrationPromise]) so MYX has registered before active provider is assigned - Extract firstNonEmpty and resolveMyxAuthConfig as exported pure functions (testable without --experimental-vm-modules) - Fix switchProvider test: mock init on reinit call since import() rejects in Jest - 100% new code coverage (15/15 lines)
- Add createMobileClientConfig to test mock factory (CI fix) - Distinguish module-not-found from runtime errors in MYX .catch()
…g, builder address - Test MYX dynamic import catch: module-not-found → debug log - Test stopEligibilityMonitoring defers refreshEligibility - Test testnet builder address selection in HyperLiquidProvider - Test createMobileClientConfig default config shape - Harden catch handler for cross-realm errors (instanceof fails)
…lity Extract .then()/.catch() callbacks from the MYX dynamic import into protected methods (registerMYXProvider, handleMYXImportError) so they can be tested directly. Jest rejects dynamic import() without --experimental-vm-modules, making inline callbacks untestable. New code coverage: 97% (33/34 changed lines).
Switch from import() to require() for MYX provider dynamic loading. Both achieve lazy loading; require() works with Jest module mocking. Add integration test covering the full init → MYX registration path. New code coverage: 96% (26/27 changed lines).
Replace broad regex /cannot find|not found|module/ with precise error.code === 'MODULE_NOT_FOUND' check. Only Node's actual module resolution failures are treated as expected; constructor/config errors now correctly route to Sentry via logError.
…iles Investigation of PerpsController.ts growth (3,343 → 4,689 lines in 6 weeks) and HyperLiquidProvider.ts (8,342 lines). Documents root causes, phased extraction plan, and CI guardrails to prevent re-growth.
…shaking require() defeats webpack code splitting — only import() enables true tree-shaking so MYX is excluded from the extension bundle. Remove the integration test that depended on require() resolution (Jest can't resolve dynamic import() without --experimental-vm-modules); unit tests for registerMYXProvider and handleMYXImportError remain.
step_eslint_fix was backing up eslint-suppressions.json before running --prune-suppressions, then restoring the original — undoing the prune. Step 8 (Lint) then failed on the stale entries. Remove the backup/restore so pruned suppressions persist for lint and the eventual commit.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
The changes are internal refactoring (no new user-facing features), but the initialization flow changes and config restructuring warrant running perps-related E2E tests to verify the controller still initializes correctly and perps flows work end-to-end. Performance Test Selection: |
The committed fixture schema is out of date. To update, comment: |
|




Description
Resolves several core-parity and architecture concerns for the perps controller:
1. Backport core-only changes (existing)
stopEligibilityMonitoring()— Disables geo-blocking eligibility checks whenuseExternalServicesis toggled off.await import()→.then()/.catch()to avoid bundling heavy MYX dependencies in extension.2. Nested
providerCredentialsonPerpsControllerConfigmyxAppIdTestnet,myxProviderEnabled, etc.) intoproviderCredentials.myx.*.providerCredentials.hyperliquid.*for builder fee wallet addresses.PerpsProviderCredentials,HyperLiquidCredentials,MYXCredentials.3. Builder fee address injection
HyperLiquidProvideraccepts optionalbuilderAddressTestnet/builderAddressMainnetvia constructor.BUILDER_FEE_CONFIGdefaults when env vars are empty..js.env.example:MM_PERPS_HL_BUILDER_ADDRESS_TESTNET,MM_PERPS_HL_BUILDER_ADDRESS_MAINNET.4. Env var centralization in mobile adapter
createMobileClientConfig()inmobileInfrastructure.ts— allprocess.env.*reads in one place.perps-controller/index.ts) reduced from ~73 to ~37 lines — pure controller wiring, no env var reads.5. MYX dynamic import race condition fix
await import()inside non-async#createProviders(): void→.then()/.catch()chain.@ts-expect-errorsuppression. Fixes provider setup race condition flagged by bugbot.Changelog
CHANGELOG entry: null
Related issues
Fixes: N/A — architecture cleanup + core parity
Manual testing steps
Screenshots/Recordings
N/A — no UI changes
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches Perps provider initialization/selection and geo-eligibility monitoring, which can impact trading availability and protocol routing if misconfigured. Changes are largely additive but include async/dynamic-import ordering and new config wiring that should be validated across networks/providers.
Overview
Refactors Perps controller configuration to use a nested
providerCredentialsstructure and centralizes all Perpsprocess.envreads intocreateMobileClientConfig(), simplifyingperpsControllerInitto pure wiring.Adds HyperLiquid builder-fee address injection via new env vars and passes these through
PerpsControllerintoHyperLiquidProvider, falling back to hardcoded defaults when env values are empty.Hardens MYX provider registration and eligibility controls by switching MYX to a dynamic
import()flow with explicit error handling/awaiting during initialization, addingstopEligibilityMonitoring()(and messenger action typing) to defer geolocation checks, and extending tests to cover these behaviors.Written by Cursor Bugbot for commit 30f6e0a. This will update automatically on new commits. Configure here.