@metamask-previews/perps-controller 15.1.0-preview-00a181c → 15.1.0-preview-a302de5c3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -14
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +1 -20
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +1 -20
- package/dist/PerpsController-method-action-types.d.mts.map +1 -1
- package/dist/PerpsController-method-action-types.mjs.map +1 -1
- package/dist/PerpsController.cjs +154 -65
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +43 -37
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +43 -37
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +151 -64
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +1 -1
- package/dist/constants/index.cjs +1 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +1 -0
- package/dist/constants/index.d.cts.map +1 -1
- package/dist/constants/index.d.mts +1 -0
- package/dist/constants/index.d.mts.map +1 -1
- package/dist/constants/index.mjs +1 -0
- package/dist/constants/index.mjs.map +1 -1
- package/dist/constants/myxConfig.cjs +253 -0
- package/dist/constants/myxConfig.cjs.map +1 -0
- package/dist/constants/myxConfig.d.cts +145 -0
- package/dist/constants/myxConfig.d.cts.map +1 -0
- package/dist/constants/myxConfig.d.mts +145 -0
- package/dist/constants/myxConfig.d.mts.map +1 -0
- package/dist/constants/myxConfig.mjs +243 -0
- package/dist/constants/myxConfig.mjs.map +1 -0
- package/dist/constants/perpsConfig.cjs +9 -4
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +5 -3
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +5 -3
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +9 -4
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/index.cjs +175 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +2 -8
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +2 -3
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +2 -3
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +2 -8
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +22 -118
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -31
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +0 -31
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +22 -118
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/providers/LighterProvider.cjs +1 -1
- package/dist/providers/LighterProvider.cjs.map +1 -1
- package/dist/providers/LighterProvider.mjs +1 -1
- package/dist/providers/LighterProvider.mjs.map +1 -1
- package/dist/routing/ProviderRouter.cjs +1 -1
- package/dist/routing/ProviderRouter.cjs.map +1 -1
- package/dist/routing/ProviderRouter.d.cts +1 -1
- package/dist/routing/ProviderRouter.d.mts +1 -1
- package/dist/routing/ProviderRouter.mjs +1 -1
- package/dist/routing/ProviderRouter.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts +16 -26
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts +16 -26
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.cjs +30 -80
- package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.cts +22 -48
- package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.mts +22 -48
- package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
- package/dist/services/HyperLiquidWalletService.mjs +30 -80
- package/dist/services/HyperLiquidWalletService.mjs.map +1 -1
- package/dist/services/LighterWalletService.cjs +1 -1
- package/dist/services/LighterWalletService.cjs.map +1 -1
- package/dist/services/LighterWalletService.d.cts +1 -1
- package/dist/services/LighterWalletService.d.mts +1 -1
- package/dist/services/LighterWalletService.mjs +1 -1
- package/dist/services/LighterWalletService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +16 -10
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +16 -10
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/myx-types.cjs +41 -0
- package/dist/types/myx-types.cjs.map +1 -0
- package/dist/types/myx-types.d.cts +94 -0
- package/dist/types/myx-types.d.cts.map +1 -0
- package/dist/types/myx-types.d.mts +94 -0
- package/dist/types/myx-types.d.mts.map +1 -0
- package/dist/types/myx-types.mjs +26 -0
- package/dist/types/myx-types.mjs.map +1 -0
- package/dist/utils/lighterAdapter.cjs +2 -1
- package/dist/utils/lighterAdapter.cjs.map +1 -1
- package/dist/utils/lighterAdapter.d.cts +2 -1
- package/dist/utils/lighterAdapter.d.cts.map +1 -1
- package/dist/utils/lighterAdapter.d.mts +2 -1
- package/dist/utils/lighterAdapter.d.mts.map +1 -1
- package/dist/utils/lighterAdapter.mjs +2 -1
- package/dist/utils/lighterAdapter.mjs.map +1 -1
- package/dist/utils/myxAdapter.cjs +569 -0
- package/dist/utils/myxAdapter.cjs.map +1 -0
- package/dist/utils/myxAdapter.d.cts +168 -0
- package/dist/utils/myxAdapter.d.cts.map +1 -0
- package/dist/utils/myxAdapter.d.mts +168 -0
- package/dist/utils/myxAdapter.d.mts.map +1 -0
- package/dist/utils/myxAdapter.mjs +548 -0
- package/dist/utils/myxAdapter.mjs.map +1 -0
- package/package.json +8 -2
package/dist/PerpsController.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _PerpsController_instances, _a, _PerpsController_initializationPromise, _PerpsController_isReinitializing, _PerpsController_reinitializationOperationPromise, _PerpsController_disconnectOperationPromise, _PerpsController_lighterRegistrationPromise, _PerpsController_blockedRegionListVersion, _PerpsController_hip3Enabled, _PerpsController_hip3AllowlistMarkets, _PerpsController_hip3BlocklistMarkets, _PerpsController_hip3ConfigSource, _PerpsController_priceDeviationLimit, _PerpsController_attributionContext, _PerpsController_isLighterProviderEnabled, _PerpsController_standaloneProvider, _PerpsController_handlersRegistered, _PerpsController_standaloneProviderIsTestnet, _PerpsController_standaloneProviderHip3Version, _PerpsController_standaloneProviderOperations, _PerpsController_eligibilityCheckDeferred, _PerpsController_ausQueue, _PerpsController_userDiskWrite,
|
|
12
|
+
var _PerpsController_instances, _a, _PerpsController_initializationPromise, _PerpsController_isReinitializing, _PerpsController_reinitializationOperationPromise, _PerpsController_disconnectOperationPromise, _PerpsController_myxRegistrationPromise, _PerpsController_lighterRegistrationPromise, _PerpsController_blockedRegionListVersion, _PerpsController_hip3Enabled, _PerpsController_hip3AllowlistMarkets, _PerpsController_hip3BlocklistMarkets, _PerpsController_hip3ConfigSource, _PerpsController_priceDeviationLimit, _PerpsController_attributionContext, _PerpsController_isMYXProviderEnabled, _PerpsController_isLighterProviderEnabled, _PerpsController_standaloneProvider, _PerpsController_handlersRegistered, _PerpsController_standaloneProviderIsTestnet, _PerpsController_standaloneProviderHip3Version, _PerpsController_standaloneProviderOperations, _PerpsController_eligibilityCheckDeferred, _PerpsController_ausQueue, _PerpsController_userDiskWrite, _PerpsController_options, _PerpsController_tradingService, _PerpsController_marketDataService, _PerpsController_accountService, _PerpsController_eligibilityService, _PerpsController_dataLakeService, _PerpsController_depositService, _PerpsController_featureFlagConfigurationService, _PerpsController_rewardsIntegrationService, _PerpsController_publishChaseOrderMaxDistanceReached, _PerpsController_logError, _PerpsController_debugLog, _PerpsController_getAggregatedCacheProviderIds, _PerpsController_isMarketCacheEntryCurrent, _PerpsController_isUserCacheIdentityCurrent, _PerpsController_fetchAndCacheUserDataSnapshot, _PerpsController_getOrCreateStandaloneProvider, _PerpsController_trackStandaloneProviderOperation, _PerpsController_retireStandaloneProvider, _PerpsController_cleanupStandaloneProvider, _PerpsController_getMetrics, _PerpsController_findNetworkClientIdForChain, _PerpsController_submitTransaction, _PerpsController_migrateRequestsIfNeeded, _PerpsController_withStreamPause, _PerpsController_initWithoutDisconnectWait, _PerpsController_beginReinitialization, _PerpsController_performInitialization, _PerpsController_createProviders, _PerpsController_assignActiveProvider, _PerpsController_getErrorContext, _PerpsController_getControllerState, _PerpsController_buildMarketAllowedFilter, _PerpsController_compilePatternsSafely, _PerpsController_createServiceContext, _PerpsController_ensureTradingServiceDeps, _PerpsController_getActiveProviderWhenReady, _PerpsController_getUnavailableScalePriceLadder, _PerpsController_getUnavailableOrderCapabilities, _PerpsController_getDirectProviderId, _PerpsController_hasConflictingProviderRoute, _PerpsController_resolveRoutedOrderProvider, _PerpsController_buildGlobalSnapshotContext, _PerpsController_getStaticSnapshotDexes, _PerpsController_preloadWatchedPaths, _PerpsController_preloadTimer, _PerpsController_preloadStartRequested, _PerpsController_isPreloading, _PerpsController_marketPreloadQueued, _PerpsController_isPreloadingUserData, _PerpsController_userPreloadQueued, _PerpsController_lifecycleGeneration, _PerpsController_userSnapshotRequests, _PerpsController_preloadStateUnsubscribe, _PerpsController_accountChangeUnsubscribe, _PerpsController_previousIsTestnet, _PerpsController_previousHip3ConfigVersion, _PerpsController_preloadRefreshMs, _PerpsController_preloadGuardMs, _PerpsController_hydrateCacheFromDiskSync, _PerpsController_persistUserCacheToDisk, _PerpsController_performMarketDataPreload, _PerpsController_performUserDataPreload, _PerpsController_performDisconnect, _PerpsController_persistWatchlistToRemote, _PerpsController_syncWatchlistFromRemote;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { ORIGIN_METAMASK } from "@metamask/controller-utils";
|
|
15
15
|
import { v4 as uuidv4 } from "uuid";
|
|
@@ -69,6 +69,16 @@ function cloneUserDataSnapshot(snapshot) {
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the first non-empty string from the given values.
|
|
74
|
+
* Env vars default to '' (not null/undefined), so ?? wouldn't fall through.
|
|
75
|
+
*
|
|
76
|
+
* @param vals - String values to check in order.
|
|
77
|
+
* @returns The first non-empty string, or '' if all are empty/undefined.
|
|
78
|
+
*/
|
|
79
|
+
export function firstNonEmpty(...vals) {
|
|
80
|
+
return (vals.find((val) => val !== null && val !== undefined && val !== '') ?? '');
|
|
81
|
+
}
|
|
72
82
|
/**
|
|
73
83
|
* Maps an active provider mode to the corresponding exchange key used in the
|
|
74
84
|
* AUS {@link PerpsWatchlistMarkets} schema.
|
|
@@ -84,9 +94,31 @@ function cloneUserDataSnapshot(snapshot) {
|
|
|
84
94
|
export function resolveWatchlistExchangeKey(activeProvider) {
|
|
85
95
|
const map = {
|
|
86
96
|
hyperliquid: 'hyperliquid',
|
|
97
|
+
myx: 'myx',
|
|
87
98
|
};
|
|
88
99
|
return map[activeProvider] ?? null;
|
|
89
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolves MYX auth config from provider credentials, handling
|
|
103
|
+
* testnet/mainnet fallback logic.
|
|
104
|
+
*
|
|
105
|
+
* @param myx - MYX provider credentials.
|
|
106
|
+
* @param isTestnet - Whether the controller is in testnet mode.
|
|
107
|
+
* @returns Resolved appId, apiSecret, and brokerAddress.
|
|
108
|
+
*/
|
|
109
|
+
export function resolveMyxAuthConfig(myx, isTestnet) {
|
|
110
|
+
return {
|
|
111
|
+
appId: isTestnet
|
|
112
|
+
? (myx.appIdTestnet ?? '')
|
|
113
|
+
: firstNonEmpty(myx.appIdMainnet, myx.appIdTestnet),
|
|
114
|
+
apiSecret: isTestnet
|
|
115
|
+
? (myx.apiSecretTestnet ?? '')
|
|
116
|
+
: firstNonEmpty(myx.apiSecretMainnet, myx.apiSecretTestnet),
|
|
117
|
+
brokerAddress: isTestnet
|
|
118
|
+
? (myx.brokerAddressTestnet ?? '')
|
|
119
|
+
: firstNonEmpty(myx.brokerAddressMainnet, myx.brokerAddressTestnet),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
90
122
|
// Re-export error codes from separate file to avoid circular dependencies
|
|
91
123
|
export { PERPS_ERROR_CODES } from "./perpsErrorCodes.mjs";
|
|
92
124
|
/**
|
|
@@ -108,6 +140,7 @@ export { PerpsMode, DEFAULT_ORDER_BOOK_PREFERENCES, DEFAULT_PERPS_MODE, DEFAULT_
|
|
|
108
140
|
* To change the active provider, modify the `activeProvider` value below:
|
|
109
141
|
* - 'hyperliquid': HyperLiquid provider (default, production)
|
|
110
142
|
* - 'aggregated': Multi-provider aggregation mode
|
|
143
|
+
* - 'myx': MYX provider (future implementation)
|
|
111
144
|
*
|
|
112
145
|
* @returns The default perps controller state.
|
|
113
146
|
*/
|
|
@@ -460,7 +493,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
460
493
|
'markTutorialCompleted',
|
|
461
494
|
'placeOrder',
|
|
462
495
|
'previewPositionModify',
|
|
463
|
-
'prepareTradingWallet',
|
|
464
496
|
'reconnect',
|
|
465
497
|
'recordMarketViewed',
|
|
466
498
|
'refreshEligibility',
|
|
@@ -481,7 +513,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
481
513
|
'setLiveDataConfig',
|
|
482
514
|
'setSelectedPaymentToken',
|
|
483
515
|
'setVisibleCandleCount',
|
|
484
|
-
'setTradingWalletOverride',
|
|
485
516
|
'startEligibilityMonitoring',
|
|
486
517
|
'startMarketDataPreload',
|
|
487
518
|
'stopEligibilityMonitoring',
|
|
@@ -518,7 +549,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
518
549
|
* - Live data uses direct callbacks for maximum performance
|
|
519
550
|
*/
|
|
520
551
|
export class PerpsController extends BaseController {
|
|
521
|
-
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false,
|
|
552
|
+
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, }) {
|
|
522
553
|
super({
|
|
523
554
|
name: 'PerpsController',
|
|
524
555
|
metadata,
|
|
@@ -531,6 +562,8 @@ export class PerpsController extends BaseController {
|
|
|
531
562
|
_PerpsController_isReinitializing.set(this, false);
|
|
532
563
|
_PerpsController_reinitializationOperationPromise.set(this, null);
|
|
533
564
|
_PerpsController_disconnectOperationPromise.set(this, null);
|
|
565
|
+
/** Tracks the async MYX dynamic import so performInitialization can await it. */
|
|
566
|
+
_PerpsController_myxRegistrationPromise.set(this, null);
|
|
534
567
|
_PerpsController_lighterRegistrationPromise.set(this, null);
|
|
535
568
|
this.blockedRegionList = {
|
|
536
569
|
list: [],
|
|
@@ -560,7 +593,7 @@ export class PerpsController extends BaseController {
|
|
|
560
593
|
_PerpsController_attributionContext.set(this, {});
|
|
561
594
|
/**
|
|
562
595
|
* Active provider instance for routing operations.
|
|
563
|
-
* When activeProvider is 'hyperliquid' or '
|
|
596
|
+
* When activeProvider is 'hyperliquid' or 'myx': points to specific provider directly
|
|
564
597
|
* When activeProvider is 'aggregated': points to AggregatedPerpsProvider wrapper
|
|
565
598
|
*/
|
|
566
599
|
this.activeProviderInstance = null;
|
|
@@ -590,9 +623,6 @@ export class PerpsController extends BaseController {
|
|
|
590
623
|
*/
|
|
591
624
|
_PerpsController_ausQueue.set(this, Promise.resolve());
|
|
592
625
|
_PerpsController_userDiskWrite.set(this, Promise.resolve());
|
|
593
|
-
// Resolves the local agent signer for the selected master account, or null.
|
|
594
|
-
// Passed through to the HyperLiquid provider for the agent signing seam.
|
|
595
|
-
_PerpsController_getAgentSigner.set(this, undefined);
|
|
596
626
|
// Store options for dependency injection (allows core package to inject platform-specific services)
|
|
597
627
|
_PerpsController_options.set(this, void 0);
|
|
598
628
|
// Service instances (instantiated with platform dependencies)
|
|
@@ -620,7 +650,6 @@ export class PerpsController extends BaseController {
|
|
|
620
650
|
_PerpsController_previousIsTestnet.set(this, null);
|
|
621
651
|
_PerpsController_previousHip3ConfigVersion.set(this, null);
|
|
622
652
|
__classPrivateFieldSet(this, _PerpsController_eligibilityCheckDeferred, deferEligibilityCheck, "f");
|
|
623
|
-
__classPrivateFieldSet(this, _PerpsController_getAgentSigner, getAgentSigner, "f");
|
|
624
653
|
// Store options for dependency injection
|
|
625
654
|
__classPrivateFieldSet(this, _PerpsController_options, {
|
|
626
655
|
messenger,
|
|
@@ -983,6 +1012,50 @@ export class PerpsController extends BaseController {
|
|
|
983
1012
|
return __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_initWithoutDisconnectWait).call(this);
|
|
984
1013
|
}
|
|
985
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Registers the MYX provider after dynamic import resolves.
|
|
1017
|
+
*
|
|
1018
|
+
* Extracted from the import().then() callback so it can be tested directly
|
|
1019
|
+
* (Jest cannot resolve dynamic imports without --experimental-vm-modules).
|
|
1020
|
+
*
|
|
1021
|
+
* @param MYXProvider - Constructor class for the MYX provider.
|
|
1022
|
+
*/
|
|
1023
|
+
registerMYXProvider(MYXProvider) {
|
|
1024
|
+
if (typeof MYXProvider !== 'function') {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const myxIsTestnet = PROVIDER_CONFIG.MYX_TESTNET_ONLY || this.state.isTestnet;
|
|
1028
|
+
const myx = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.myx ?? {};
|
|
1029
|
+
const myxAuthConfig = resolveMyxAuthConfig(myx, myxIsTestnet);
|
|
1030
|
+
const MYXProviderConstructor = MYXProvider;
|
|
1031
|
+
const myxProvider = new MYXProviderConstructor({
|
|
1032
|
+
isTestnet: myxIsTestnet,
|
|
1033
|
+
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
1034
|
+
messenger: this.messenger,
|
|
1035
|
+
myxAuthConfig,
|
|
1036
|
+
});
|
|
1037
|
+
this.providers.set('myx', myxProvider);
|
|
1038
|
+
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, 'PerpsController: MYX provider registered', {
|
|
1039
|
+
isTestnet: myxIsTestnet,
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Handles errors from the MYX dynamic import.
|
|
1044
|
+
*
|
|
1045
|
+
* Module-not-found errors are expected (extension doesn't ship MYX) → debug log.
|
|
1046
|
+
* Other errors indicate constructor/config problems → Sentry via logError.
|
|
1047
|
+
*
|
|
1048
|
+
* @param error - The caught error from the dynamic import or constructor.
|
|
1049
|
+
*/
|
|
1050
|
+
handleMYXImportError(error) {
|
|
1051
|
+
const isModuleError = error?.code === 'MODULE_NOT_FOUND';
|
|
1052
|
+
if (isModuleError) {
|
|
1053
|
+
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, 'PerpsController: MYX provider module not available, skipping registration');
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_logError).call(this, error instanceof Error ? error : new Error(String(error)), __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getErrorContext).call(this, 'createProviders.myx'));
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
986
1059
|
/**
|
|
987
1060
|
* Registers the Lighter provider after dynamic import resolves.
|
|
988
1061
|
*
|
|
@@ -1802,7 +1875,7 @@ export class PerpsController extends BaseController {
|
|
|
1802
1875
|
if (params?.standalone && params.userAddress) {
|
|
1803
1876
|
// Use activeProviderInstance if available (respects provider abstraction)
|
|
1804
1877
|
// Fallback to cached standalone provider for pre-initialization discovery
|
|
1805
|
-
// TODO: When adding new providers, consider a provider factory pattern
|
|
1878
|
+
// TODO: When adding new providers (MYX), consider a provider factory pattern
|
|
1806
1879
|
const provider = this.activeProviderInstance ?? __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getOrCreateStandaloneProvider).call(this);
|
|
1807
1880
|
const operation = provider.getPositions(params);
|
|
1808
1881
|
return provider === __classPrivateFieldGet(this, _PerpsController_standaloneProvider, "f")
|
|
@@ -2391,25 +2464,6 @@ export class PerpsController extends BaseController {
|
|
|
2391
2464
|
// Provided properties win over attribution context.
|
|
2392
2465
|
return { ...utm, ...properties };
|
|
2393
2466
|
}
|
|
2394
|
-
/**
|
|
2395
|
-
* Override (or clear) the trading wallet the HyperLiquid provider signs with.
|
|
2396
|
-
*
|
|
2397
|
-
* The host app calls this with a local agent signer when an agent wallet
|
|
2398
|
-
* activates, and with `null` when the keyring locks (restoring the master
|
|
2399
|
-
* keyring path). Throws when the HyperLiquid provider is not (yet)
|
|
2400
|
-
* registered — callers should treat that as best-effort.
|
|
2401
|
-
*
|
|
2402
|
-
* @param signer - The agent signer to sign with, or null for the master path.
|
|
2403
|
-
* @returns A promise that resolves when the clients have re-initialized with
|
|
2404
|
-
* the new wallet.
|
|
2405
|
-
*/
|
|
2406
|
-
async setTradingWalletOverride(signer) {
|
|
2407
|
-
const provider = this.providers.get('hyperliquid');
|
|
2408
|
-
if (!(provider instanceof HyperLiquidProvider)) {
|
|
2409
|
-
throw new Error(PERPS_ERROR_CODES.PROVIDER_NOT_AVAILABLE);
|
|
2410
|
-
}
|
|
2411
|
-
return provider.setTradingWalletOverride(signer);
|
|
2412
|
-
}
|
|
2413
2467
|
/**
|
|
2414
2468
|
* Toggle between testnet and mainnet
|
|
2415
2469
|
*
|
|
@@ -3014,24 +3068,6 @@ export class PerpsController extends BaseController {
|
|
|
3014
3068
|
? provider.approveSubscriptionBuilderFee()
|
|
3015
3069
|
: false;
|
|
3016
3070
|
}
|
|
3017
|
-
/**
|
|
3018
|
-
* Run the deferred trading-readiness steps for the active provider
|
|
3019
|
-
* (unified account enablement with user signing, builder fee approval) so
|
|
3020
|
-
* any required master signature surfaces during a guided session (e.g.
|
|
3021
|
-
* agent wallet setup) instead of as a surprise prompt on the first order.
|
|
3022
|
-
*
|
|
3023
|
-
* Reuses the provider's own trading-readiness sequence, which is cached:
|
|
3024
|
-
* an already-ready wallet completes without any signature. Providers
|
|
3025
|
-
* without deferred setup make this a no-op. Best-effort by design of the
|
|
3026
|
-
* underlying sequence: builder-fee failures are swallowed there and retried
|
|
3027
|
-
* at order time; only initialization/migration errors propagate.
|
|
3028
|
-
*/
|
|
3029
|
-
async prepareTradingWallet() {
|
|
3030
|
-
const provider = await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getActiveProviderWhenReady).call(this);
|
|
3031
|
-
if (provider.prepareTradingWallet) {
|
|
3032
|
-
await provider.prepareTradingWallet();
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
3071
|
/**
|
|
3036
3072
|
* Drop the cached subscription benefits snapshot.
|
|
3037
3073
|
*
|
|
@@ -3824,7 +3860,36 @@ export class PerpsController extends BaseController {
|
|
|
3824
3860
|
return __classPrivateFieldGet(this, _PerpsController_isReinitializing, "f");
|
|
3825
3861
|
}
|
|
3826
3862
|
}
|
|
3827
|
-
_a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _PerpsController_isReinitializing = new WeakMap(), _PerpsController_reinitializationOperationPromise = new WeakMap(), _PerpsController_disconnectOperationPromise = new WeakMap(), _PerpsController_lighterRegistrationPromise = new WeakMap(), _PerpsController_blockedRegionListVersion = new WeakMap(), _PerpsController_hip3Enabled = new WeakMap(), _PerpsController_hip3AllowlistMarkets = new WeakMap(), _PerpsController_hip3BlocklistMarkets = new WeakMap(), _PerpsController_hip3ConfigSource = new WeakMap(), _PerpsController_priceDeviationLimit = new WeakMap(), _PerpsController_attributionContext = new WeakMap(), _PerpsController_standaloneProvider = new WeakMap(), _PerpsController_handlersRegistered = new WeakMap(), _PerpsController_standaloneProviderIsTestnet = new WeakMap(), _PerpsController_standaloneProviderHip3Version = new WeakMap(), _PerpsController_standaloneProviderOperations = new WeakMap(), _PerpsController_eligibilityCheckDeferred = new WeakMap(), _PerpsController_ausQueue = new WeakMap(), _PerpsController_userDiskWrite = new WeakMap(),
|
|
3863
|
+
_a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _PerpsController_isReinitializing = new WeakMap(), _PerpsController_reinitializationOperationPromise = new WeakMap(), _PerpsController_disconnectOperationPromise = new WeakMap(), _PerpsController_myxRegistrationPromise = new WeakMap(), _PerpsController_lighterRegistrationPromise = new WeakMap(), _PerpsController_blockedRegionListVersion = new WeakMap(), _PerpsController_hip3Enabled = new WeakMap(), _PerpsController_hip3AllowlistMarkets = new WeakMap(), _PerpsController_hip3BlocklistMarkets = new WeakMap(), _PerpsController_hip3ConfigSource = new WeakMap(), _PerpsController_priceDeviationLimit = new WeakMap(), _PerpsController_attributionContext = new WeakMap(), _PerpsController_standaloneProvider = new WeakMap(), _PerpsController_handlersRegistered = new WeakMap(), _PerpsController_standaloneProviderIsTestnet = new WeakMap(), _PerpsController_standaloneProviderHip3Version = new WeakMap(), _PerpsController_standaloneProviderOperations = new WeakMap(), _PerpsController_eligibilityCheckDeferred = new WeakMap(), _PerpsController_ausQueue = new WeakMap(), _PerpsController_userDiskWrite = new WeakMap(), _PerpsController_options = new WeakMap(), _PerpsController_tradingService = new WeakMap(), _PerpsController_marketDataService = new WeakMap(), _PerpsController_accountService = new WeakMap(), _PerpsController_eligibilityService = new WeakMap(), _PerpsController_dataLakeService = new WeakMap(), _PerpsController_depositService = new WeakMap(), _PerpsController_featureFlagConfigurationService = new WeakMap(), _PerpsController_rewardsIntegrationService = new WeakMap(), _PerpsController_publishChaseOrderMaxDistanceReached = new WeakMap(), _PerpsController_preloadTimer = new WeakMap(), _PerpsController_preloadStartRequested = new WeakMap(), _PerpsController_isPreloading = new WeakMap(), _PerpsController_marketPreloadQueued = new WeakMap(), _PerpsController_isPreloadingUserData = new WeakMap(), _PerpsController_userPreloadQueued = new WeakMap(), _PerpsController_lifecycleGeneration = new WeakMap(), _PerpsController_userSnapshotRequests = new WeakMap(), _PerpsController_preloadStateUnsubscribe = new WeakMap(), _PerpsController_accountChangeUnsubscribe = new WeakMap(), _PerpsController_previousIsTestnet = new WeakMap(), _PerpsController_previousHip3ConfigVersion = new WeakMap(), _PerpsController_instances = new WeakSet(), _PerpsController_isMYXProviderEnabled = function _PerpsController_isMYXProviderEnabled() {
|
|
3864
|
+
const myx = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.myx;
|
|
3865
|
+
// Local env-var override (MM_PERPS_MYX_PROVIDER_ENABLED) always wins —
|
|
3866
|
+
// matches the UI selector (resolvePerpsMyxProviderEnabled) so controller
|
|
3867
|
+
// and UI agree on whether MYX is available.
|
|
3868
|
+
if (myx?.enabled) {
|
|
3869
|
+
return true;
|
|
3870
|
+
}
|
|
3871
|
+
// Credentials present → MYX is enabled regardless of remote flag.
|
|
3872
|
+
// Use || so empty-string env vars (default '') fall through.
|
|
3873
|
+
const hasCredentials = Boolean(
|
|
3874
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
3875
|
+
myx?.appIdTestnet || myx?.appIdMainnet);
|
|
3876
|
+
if (hasCredentials) {
|
|
3877
|
+
return true;
|
|
3878
|
+
}
|
|
3879
|
+
// No local override or credentials — check remote flag as fallback
|
|
3880
|
+
try {
|
|
3881
|
+
const remoteState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
3882
|
+
const remoteFlag = remoteState.remoteFeatureFlags?.perpsMyxProviderEnabled;
|
|
3883
|
+
if (isVersionGatedFeatureFlag(remoteFlag)) {
|
|
3884
|
+
const validated = __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure.featureFlags.validateVersionGated(remoteFlag);
|
|
3885
|
+
return validated ?? false;
|
|
3886
|
+
}
|
|
3887
|
+
return false;
|
|
3888
|
+
}
|
|
3889
|
+
catch {
|
|
3890
|
+
return false;
|
|
3891
|
+
}
|
|
3892
|
+
}, _PerpsController_isLighterProviderEnabled = function _PerpsController_isLighterProviderEnabled() {
|
|
3828
3893
|
const lighter = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.lighter;
|
|
3829
3894
|
if (lighter?.enabled) {
|
|
3830
3895
|
return true;
|
|
@@ -3862,6 +3927,7 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3862
3927
|
continue;
|
|
3863
3928
|
}
|
|
3864
3929
|
if (providerId === 'hyperliquid' ||
|
|
3930
|
+
(providerId === 'myx' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this)) ||
|
|
3865
3931
|
(providerId === 'lighter' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this)) ||
|
|
3866
3932
|
this.providers.has(providerId)) {
|
|
3867
3933
|
providerIds.add(providerId);
|
|
@@ -3984,7 +4050,6 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3984
4050
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
3985
4051
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
3986
4052
|
messenger: this.messenger,
|
|
3987
|
-
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
3988
4053
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
3989
4054
|
?.builderAddressTestnet,
|
|
3990
4055
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4207,13 +4272,15 @@ async function _PerpsController_performInitialization() {
|
|
|
4207
4272
|
this.providers.clear();
|
|
4208
4273
|
await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_cleanupStandaloneProvider).call(this);
|
|
4209
4274
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_createProviders).call(this);
|
|
4210
|
-
// Await
|
|
4211
|
-
//
|
|
4212
|
-
//
|
|
4275
|
+
// Await MYX dynamic import (if started) so MYX is in the providers
|
|
4276
|
+
// map before we assign the active provider. Runs concurrently with
|
|
4277
|
+
// the WebSocket readiness delay for zero additional latency.
|
|
4213
4278
|
await Promise.all([
|
|
4214
4279
|
wait(PERPS_CONSTANTS.ReconnectionCleanupDelayMs),
|
|
4280
|
+
__classPrivateFieldGet(this, _PerpsController_myxRegistrationPromise, "f"),
|
|
4215
4281
|
__classPrivateFieldGet(this, _PerpsController_lighterRegistrationPromise, "f"),
|
|
4216
4282
|
]);
|
|
4283
|
+
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, null, "f");
|
|
4217
4284
|
__classPrivateFieldSet(this, _PerpsController_lighterRegistrationPromise, null, "f");
|
|
4218
4285
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_assignActiveProvider).call(this);
|
|
4219
4286
|
this.isInitialized = true;
|
|
@@ -4284,7 +4351,6 @@ async function _PerpsController_performInitialization() {
|
|
|
4284
4351
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4285
4352
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4286
4353
|
messenger: this.messenger,
|
|
4287
|
-
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4288
4354
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4289
4355
|
?.builderAddressTestnet,
|
|
4290
4356
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4296,12 +4362,32 @@ async function _PerpsController_performInitialization() {
|
|
|
4296
4362
|
onChaseOrderMaxDistanceReached: __classPrivateFieldGet(this, _PerpsController_publishChaseOrderMaxDistanceReached, "f"),
|
|
4297
4363
|
});
|
|
4298
4364
|
this.providers.set('hyperliquid', hyperLiquidProvider);
|
|
4299
|
-
// Register
|
|
4300
|
-
//
|
|
4301
|
-
//
|
|
4302
|
-
//
|
|
4303
|
-
//
|
|
4304
|
-
// is only used when
|
|
4365
|
+
// Register MYX provider if enabled via feature flag.
|
|
4366
|
+
// Dynamic import because the MYX package pulls in heavy dependencies we
|
|
4367
|
+
// don't want bundled in extension. Until MYX fixes their package, extension
|
|
4368
|
+
// doesn't ship it — the catch branch silently skips registration.
|
|
4369
|
+
// Uses .then()/.catch() instead of await because #createProviders is not async;
|
|
4370
|
+
// MYX registration completing asynchronously is fine since it's only used when
|
|
4371
|
+
// explicitly enabled and selected.
|
|
4372
|
+
const isMYXEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this);
|
|
4373
|
+
if (isMYXEnabled) {
|
|
4374
|
+
// IMPORTANT: Must use import() — NOT require() — for core/extension tree-shaking.
|
|
4375
|
+
// require() is synchronous and bundlers include it in the main bundle.
|
|
4376
|
+
// import() enables true code splitting so MYX is excluded when not enabled.
|
|
4377
|
+
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
4378
|
+
// import argument and strip the webpackIgnore magic comment in core dist.
|
|
4379
|
+
const myxModulePath = './providers/MYXProvider';
|
|
4380
|
+
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, import(
|
|
4381
|
+
/* webpackIgnore: true */ myxModulePath)
|
|
4382
|
+
.then(({ MYXProvider }) => {
|
|
4383
|
+
this.registerMYXProvider(MYXProvider);
|
|
4384
|
+
return undefined;
|
|
4385
|
+
})
|
|
4386
|
+
.catch((error) => this.handleMYXImportError(error)), "f");
|
|
4387
|
+
}
|
|
4388
|
+
// Register Lighter provider if enabled (POC). Same dynamic-import pattern
|
|
4389
|
+
// as MYX so clients that do not ship the Lighter files skip registration
|
|
4390
|
+
// silently.
|
|
4305
4391
|
const isLighterEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this);
|
|
4306
4392
|
if (isLighterEnabled) {
|
|
4307
4393
|
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
@@ -4333,11 +4419,7 @@ async function _PerpsController_performInitialization() {
|
|
|
4333
4419
|
this.activeProviderInstance = hyperLiquidProvider;
|
|
4334
4420
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${activeProvider})`);
|
|
4335
4421
|
}
|
|
4336
|
-
else {
|
|
4337
|
-
// Any other direct provider, including a value persisted by an older
|
|
4338
|
-
// version whose venue has since been removed. `activeProvider` is
|
|
4339
|
-
// persisted, so throwing here would fail initialization on every
|
|
4340
|
-
// launch — the stale value must self-heal.
|
|
4422
|
+
else if (activeProvider === 'myx' || activeProvider === 'lighter') {
|
|
4341
4423
|
const directProvider = this.providers.get(activeProvider);
|
|
4342
4424
|
if (directProvider) {
|
|
4343
4425
|
this.activeProviderInstance = directProvider;
|
|
@@ -4351,6 +4433,9 @@ async function _PerpsController_performInitialization() {
|
|
|
4351
4433
|
}
|
|
4352
4434
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${this.activeProviderInstance === hyperLiquidProvider ? 'hyperliquid' : activeProvider})`);
|
|
4353
4435
|
}
|
|
4436
|
+
else {
|
|
4437
|
+
throw new Error(`Unsupported provider: ${String(activeProvider)}. Currently only 'hyperliquid', 'myx', 'lighter', and 'aggregated' are supported.`);
|
|
4438
|
+
}
|
|
4354
4439
|
}, _PerpsController_getErrorContext = function _PerpsController_getErrorContext(method, extra) {
|
|
4355
4440
|
return {
|
|
4356
4441
|
tags: {
|
|
@@ -5072,6 +5157,7 @@ async function _PerpsController_persistWatchlistToRemote(network) {
|
|
|
5072
5157
|
const existingWatchlist = prefs.perps
|
|
5073
5158
|
.watchlistMarkets ?? {
|
|
5074
5159
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5160
|
+
myx: { testnet: [], mainnet: [] },
|
|
5075
5161
|
};
|
|
5076
5162
|
const nextWatchlistMarkets = {
|
|
5077
5163
|
...existingWatchlist,
|
|
@@ -5139,6 +5225,7 @@ async function _PerpsController_syncWatchlistFromRemote() {
|
|
|
5139
5225
|
const existingWatchlist = prefs.perps
|
|
5140
5226
|
.watchlistMarkets ?? {
|
|
5141
5227
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5228
|
+
myx: { testnet: [], mainnet: [] },
|
|
5142
5229
|
};
|
|
5143
5230
|
const nextWatchlistMarkets = {
|
|
5144
5231
|
...existingWatchlist,
|