Skip to content

fix: Remove dynamic imports, move myx to optional dependencies#8374

Open
gambinish wants to merge 5 commits intomainfrom
fix/remove-myx-dynamic-imports
Open

fix: Remove dynamic imports, move myx to optional dependencies#8374
gambinish wants to merge 5 commits intomainfrom
fix/remove-myx-dynamic-imports

Conversation

@gambinish
Copy link
Copy Markdown
Member

@gambinish gambinish commented Apr 2, 2026

Explanation

Fixes two related issues that caused webpack build failures and LavaMoat policy violations in the MetaMask extension when consuming @metamask/perps-controller@2.0.0: @myx-trade/sdk was being pulled into the static bundle, and webpack was failing to statically resolve MYXProvider.mjs which was intentionally excluded from the published dist/.

Root Cause

Two separate problems stemmed from the same underlying issue — MYX-related code was leaking into the static import graph even though MYX is not yet ready to ship.

Problem 1 — @myx-trade/sdk in the static bundle (LavaMoat violation)

The static import chain was:

dist/index.mjs
  → dist/utils/index.mjs        (export * from './myxAdapter')
  → dist/utils/myxAdapter.mjs   (imports MYXDirection, MYXDirectionEnum, etc.)
  → dist/types/myx-types.mjs    (re-exports values from @myx-trade/sdk)
  → @myx-trade/sdk              ← webpack pulls this in statically

Because myxAdapter.ts was re-exported from the package's public barrel (utils/index.ts → index.ts), webpack included @myx-trade/sdk in the bundle at build time. LavaMoat then flagged it because there was no policy entry for it.

Problem 2 — webpack static analysis failure on missing MYXProvider.mjs

dist/PerpsController.mjs contained import('./providers/MYXProvider.mjs') without a webpackIgnore hint. MYXProvider.mjs was intentionally excluded from the published dist (via package.json files exclusions), but webpack's static analysis tried to resolve it at build time before the runtime handleMYXImportError catch handler could do anything.

Changes

src/utils/index.ts — Remove export * from './myxAdapter' from the utils barrel. This severs myxAdapter.ts from the static import graph entirely.

src/index.ts — Remove the eight myxAdapter functions (adaptMarketFromMYX, adaptPriceFromMYX, adaptMarketDataFromMYX, filterMYXExclusiveMarkets, isOverlappingMarket, buildPoolSymbolMap, buildSymbolPoolsMap, extractSymbolFromPoolId) from the package's public exports. A codebase-wide search confirmed zero external consumers of these functions — they are used only internally by MYXProvider, which continues to import them directly via relative path and remains fully functional inside the dynamic-import boundary.

src/PerpsController.ts — Add /* webpackIgnore: true */ to the MYXProvider dynamic import. This instructs webpack to skip static resolution entirely. The existing handleMYXImportError catch handler already gracefully swallows the module-not-found error at runtime.

package.json — Move @myx-trade/sdk from dependencies to optionalDependencies. This prevents the extension (and other consumers) from installing it automatically, while keeping it available for developers working on MYX locally.

After These Changes
@myx-trade/sdk is only reachable through the dynamic-import boundary (MYXProvider), so webpack never processes it at build time and LavaMoat never needs a policy entry for it.

Breaking Change
The eight MYX adapter functions listed above are no longer public exports of @metamask/perps-controller. Since no external consumers were found, the practical impact is zero.

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
Medium risk because it introduces a breaking API surface change (removing MYX adapter utilities from public exports) and alters bundling behavior via dynamic-import hints and optional dependency resolution, which could impact downstream builds.

Overview
Prevents MYX-related code (and @myx-trade/sdk) from being pulled into consumers’ static bundles by making @myx-trade/sdk an optionalDependencies entry and removing myxAdapter re-exports from the public barrels (src/utils/index.ts and src/index.ts).

Updates the MYX provider dynamic import in PerpsController to include /* webpackIgnore: true */ so webpack doesn’t try to statically resolve the intentionally-unshipped MYXProvider module; documents the BREAKING removal of the MYX adapter exports in the changelog and marks the dependency optional in yarn.lock.

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

@gambinish gambinish requested review from a team as code owners April 2, 2026 22:22
@gambinish
Copy link
Copy Markdown
Member Author

@metamaskbot publish-previews

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.0.0-preview-f6f25fa44
@metamask-previews/accounts-controller@37.2.0-preview-f6f25fa44
@metamask-previews/address-book-controller@7.1.1-preview-f6f25fa44
@metamask-previews/ai-controllers@0.6.3-preview-f6f25fa44
@metamask-previews/analytics-controller@1.0.1-preview-f6f25fa44
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-f6f25fa44
@metamask-previews/announcement-controller@8.1.0-preview-f6f25fa44
@metamask-previews/app-metadata-controller@2.0.1-preview-f6f25fa44
@metamask-previews/approval-controller@9.0.1-preview-f6f25fa44
@metamask-previews/assets-controller@4.0.0-preview-f6f25fa44
@metamask-previews/assets-controllers@103.1.1-preview-f6f25fa44
@metamask-previews/base-controller@9.0.1-preview-f6f25fa44
@metamask-previews/base-data-service@0.1.1-preview-f6f25fa44
@metamask-previews/bridge-controller@70.0.1-preview-f6f25fa44
@metamask-previews/bridge-status-controller@70.0.5-preview-f6f25fa44
@metamask-previews/build-utils@3.0.4-preview-f6f25fa44
@metamask-previews/chain-agnostic-permission@1.5.0-preview-f6f25fa44
@metamask-previews/claims-controller@0.5.0-preview-f6f25fa44
@metamask-previews/client-controller@1.0.1-preview-f6f25fa44
@metamask-previews/compliance-controller@2.0.0-preview-f6f25fa44
@metamask-previews/composable-controller@12.0.1-preview-f6f25fa44
@metamask-previews/config-registry-controller@0.2.0-preview-f6f25fa44
@metamask-previews/connectivity-controller@0.2.0-preview-f6f25fa44
@metamask-previews/controller-utils@11.20.0-preview-f6f25fa44
@metamask-previews/core-backend@6.2.1-preview-f6f25fa44
@metamask-previews/delegation-controller@2.1.0-preview-f6f25fa44
@metamask-previews/earn-controller@11.2.1-preview-f6f25fa44
@metamask-previews/eip-5792-middleware@3.0.3-preview-f6f25fa44
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-f6f25fa44
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-f6f25fa44
@metamask-previews/ens-controller@19.1.1-preview-f6f25fa44
@metamask-previews/eth-block-tracker@15.0.1-preview-f6f25fa44
@metamask-previews/eth-json-rpc-middleware@23.1.1-preview-f6f25fa44
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-f6f25fa44
@metamask-previews/foundryup@1.0.1-preview-f6f25fa44
@metamask-previews/gas-fee-controller@26.1.1-preview-f6f25fa44
@metamask-previews/gator-permissions-controller@3.0.1-preview-f6f25fa44
@metamask-previews/geolocation-controller@0.1.2-preview-f6f25fa44
@metamask-previews/json-rpc-engine@10.2.4-preview-f6f25fa44
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-f6f25fa44
@metamask-previews/keyring-controller@25.2.0-preview-f6f25fa44
@metamask-previews/logging-controller@8.0.1-preview-f6f25fa44
@metamask-previews/message-manager@14.1.1-preview-f6f25fa44
@metamask-previews/messenger@1.1.0-preview-f6f25fa44
@metamask-previews/money-account-controller@0.1.0-preview-f6f25fa44
@metamask-previews/multichain-account-service@8.0.1-preview-f6f25fa44
@metamask-previews/multichain-api-middleware@2.0.0-preview-f6f25fa44
@metamask-previews/multichain-network-controller@3.0.6-preview-f6f25fa44
@metamask-previews/multichain-transactions-controller@7.0.4-preview-f6f25fa44
@metamask-previews/name-controller@9.1.1-preview-f6f25fa44
@metamask-previews/network-controller@30.0.1-preview-f6f25fa44
@metamask-previews/network-enablement-controller@5.0.2-preview-f6f25fa44
@metamask-previews/notification-services-controller@23.0.1-preview-f6f25fa44
@metamask-previews/permission-controller@12.3.0-preview-f6f25fa44
@metamask-previews/permission-log-controller@5.1.0-preview-f6f25fa44
@metamask-previews/perps-controller@2.0.0-preview-f6f25fa44
@metamask-previews/phishing-controller@17.1.1-preview-f6f25fa44
@metamask-previews/polling-controller@16.0.4-preview-f6f25fa44
@metamask-previews/preferences-controller@23.1.0-preview-f6f25fa44
@metamask-previews/profile-metrics-controller@3.1.3-preview-f6f25fa44
@metamask-previews/profile-sync-controller@28.0.2-preview-f6f25fa44
@metamask-previews/ramps-controller@12.1.0-preview-f6f25fa44
@metamask-previews/rate-limit-controller@7.0.1-preview-f6f25fa44
@metamask-previews/react-data-query@0.2.0-preview-f6f25fa44
@metamask-previews/remote-feature-flag-controller@4.2.0-preview-f6f25fa44
@metamask-previews/sample-controllers@4.0.4-preview-f6f25fa44
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-f6f25fa44
@metamask-previews/selected-network-controller@26.1.0-preview-f6f25fa44
@metamask-previews/shield-controller@5.1.1-preview-f6f25fa44
@metamask-previews/signature-controller@39.1.2-preview-f6f25fa44
@metamask-previews/social-controllers@0.1.0-preview-f6f25fa44
@metamask-previews/storage-service@1.0.1-preview-f6f25fa44
@metamask-previews/subscription-controller@6.1.2-preview-f6f25fa44
@metamask-previews/transaction-controller@64.0.0-preview-f6f25fa44
@metamask-previews/transaction-pay-controller@19.0.2-preview-f6f25fa44
@metamask-previews/user-operation-controller@41.2.0-preview-f6f25fa44

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.

1 participant