@metamask-previews/perps-controller 15.1.0-preview-00a181c → 15.1.0-preview-cfd35b8dd
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.cjs
CHANGED
|
@@ -10,9 +10,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
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");
|
|
11
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
12
|
};
|
|
13
|
-
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,
|
|
13
|
+
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;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PerpsController = exports.getDefaultPerpsControllerState = exports.DEFAULT_SELECTED_ORDER_TYPE = exports.DEFAULT_PRO_LAYOUT_PREFERENCES = exports.DEFAULT_PERPS_MODE = exports.DEFAULT_ORDER_BOOK_PREFERENCES = exports.PerpsMode = exports.InitializationState = exports.PERPS_ERROR_CODES = exports.resolveWatchlistExchangeKey = void 0;
|
|
15
|
+
exports.PerpsController = exports.getDefaultPerpsControllerState = exports.DEFAULT_SELECTED_ORDER_TYPE = exports.DEFAULT_PRO_LAYOUT_PREFERENCES = exports.DEFAULT_PERPS_MODE = exports.DEFAULT_ORDER_BOOK_PREFERENCES = exports.PerpsMode = exports.InitializationState = exports.PERPS_ERROR_CODES = exports.resolveMyxAuthConfig = exports.resolveWatchlistExchangeKey = exports.firstNonEmpty = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
17
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
@@ -72,6 +72,17 @@ function cloneUserDataSnapshot(snapshot) {
|
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the first non-empty string from the given values.
|
|
77
|
+
* Env vars default to '' (not null/undefined), so ?? wouldn't fall through.
|
|
78
|
+
*
|
|
79
|
+
* @param vals - String values to check in order.
|
|
80
|
+
* @returns The first non-empty string, or '' if all are empty/undefined.
|
|
81
|
+
*/
|
|
82
|
+
function firstNonEmpty(...vals) {
|
|
83
|
+
return (vals.find((val) => val !== null && val !== undefined && val !== '') ?? '');
|
|
84
|
+
}
|
|
85
|
+
exports.firstNonEmpty = firstNonEmpty;
|
|
75
86
|
/**
|
|
76
87
|
* Maps an active provider mode to the corresponding exchange key used in the
|
|
77
88
|
* AUS {@link PerpsWatchlistMarkets} schema.
|
|
@@ -87,10 +98,33 @@ function cloneUserDataSnapshot(snapshot) {
|
|
|
87
98
|
function resolveWatchlistExchangeKey(activeProvider) {
|
|
88
99
|
const map = {
|
|
89
100
|
hyperliquid: 'hyperliquid',
|
|
101
|
+
myx: 'myx',
|
|
90
102
|
};
|
|
91
103
|
return map[activeProvider] ?? null;
|
|
92
104
|
}
|
|
93
105
|
exports.resolveWatchlistExchangeKey = resolveWatchlistExchangeKey;
|
|
106
|
+
/**
|
|
107
|
+
* Resolves MYX auth config from provider credentials, handling
|
|
108
|
+
* testnet/mainnet fallback logic.
|
|
109
|
+
*
|
|
110
|
+
* @param myx - MYX provider credentials.
|
|
111
|
+
* @param isTestnet - Whether the controller is in testnet mode.
|
|
112
|
+
* @returns Resolved appId, apiSecret, and brokerAddress.
|
|
113
|
+
*/
|
|
114
|
+
function resolveMyxAuthConfig(myx, isTestnet) {
|
|
115
|
+
return {
|
|
116
|
+
appId: isTestnet
|
|
117
|
+
? (myx.appIdTestnet ?? '')
|
|
118
|
+
: firstNonEmpty(myx.appIdMainnet, myx.appIdTestnet),
|
|
119
|
+
apiSecret: isTestnet
|
|
120
|
+
? (myx.apiSecretTestnet ?? '')
|
|
121
|
+
: firstNonEmpty(myx.apiSecretMainnet, myx.apiSecretTestnet),
|
|
122
|
+
brokerAddress: isTestnet
|
|
123
|
+
? (myx.brokerAddressTestnet ?? '')
|
|
124
|
+
: firstNonEmpty(myx.brokerAddressMainnet, myx.brokerAddressTestnet),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
exports.resolveMyxAuthConfig = resolveMyxAuthConfig;
|
|
94
128
|
// Re-export error codes from separate file to avoid circular dependencies
|
|
95
129
|
var perpsErrorCodes_js_2 = require("./perpsErrorCodes.cjs");
|
|
96
130
|
Object.defineProperty(exports, "PERPS_ERROR_CODES", { enumerable: true, get: function () { return perpsErrorCodes_js_2.PERPS_ERROR_CODES; } });
|
|
@@ -118,6 +152,7 @@ Object.defineProperty(exports, "DEFAULT_SELECTED_ORDER_TYPE", { enumerable: true
|
|
|
118
152
|
* To change the active provider, modify the `activeProvider` value below:
|
|
119
153
|
* - 'hyperliquid': HyperLiquid provider (default, production)
|
|
120
154
|
* - 'aggregated': Multi-provider aggregation mode
|
|
155
|
+
* - 'myx': MYX provider (future implementation)
|
|
121
156
|
*
|
|
122
157
|
* @returns The default perps controller state.
|
|
123
158
|
*/
|
|
@@ -471,7 +506,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
471
506
|
'markTutorialCompleted',
|
|
472
507
|
'placeOrder',
|
|
473
508
|
'previewPositionModify',
|
|
474
|
-
'prepareTradingWallet',
|
|
475
509
|
'reconnect',
|
|
476
510
|
'recordMarketViewed',
|
|
477
511
|
'refreshEligibility',
|
|
@@ -492,7 +526,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
492
526
|
'setLiveDataConfig',
|
|
493
527
|
'setSelectedPaymentToken',
|
|
494
528
|
'setVisibleCandleCount',
|
|
495
|
-
'setTradingWalletOverride',
|
|
496
529
|
'startEligibilityMonitoring',
|
|
497
530
|
'startMarketDataPreload',
|
|
498
531
|
'stopEligibilityMonitoring',
|
|
@@ -529,7 +562,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
529
562
|
* - Live data uses direct callbacks for maximum performance
|
|
530
563
|
*/
|
|
531
564
|
class PerpsController extends base_controller_1.BaseController {
|
|
532
|
-
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false,
|
|
565
|
+
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, }) {
|
|
533
566
|
super({
|
|
534
567
|
name: 'PerpsController',
|
|
535
568
|
metadata,
|
|
@@ -542,6 +575,8 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
542
575
|
_PerpsController_isReinitializing.set(this, false);
|
|
543
576
|
_PerpsController_reinitializationOperationPromise.set(this, null);
|
|
544
577
|
_PerpsController_disconnectOperationPromise.set(this, null);
|
|
578
|
+
/** Tracks the async MYX dynamic import so performInitialization can await it. */
|
|
579
|
+
_PerpsController_myxRegistrationPromise.set(this, null);
|
|
545
580
|
_PerpsController_lighterRegistrationPromise.set(this, null);
|
|
546
581
|
this.blockedRegionList = {
|
|
547
582
|
list: [],
|
|
@@ -571,7 +606,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
571
606
|
_PerpsController_attributionContext.set(this, {});
|
|
572
607
|
/**
|
|
573
608
|
* Active provider instance for routing operations.
|
|
574
|
-
* When activeProvider is 'hyperliquid' or '
|
|
609
|
+
* When activeProvider is 'hyperliquid' or 'myx': points to specific provider directly
|
|
575
610
|
* When activeProvider is 'aggregated': points to AggregatedPerpsProvider wrapper
|
|
576
611
|
*/
|
|
577
612
|
this.activeProviderInstance = null;
|
|
@@ -601,9 +636,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
601
636
|
*/
|
|
602
637
|
_PerpsController_ausQueue.set(this, Promise.resolve());
|
|
603
638
|
_PerpsController_userDiskWrite.set(this, Promise.resolve());
|
|
604
|
-
// Resolves the local agent signer for the selected master account, or null.
|
|
605
|
-
// Passed through to the HyperLiquid provider for the agent signing seam.
|
|
606
|
-
_PerpsController_getAgentSigner.set(this, undefined);
|
|
607
639
|
// Store options for dependency injection (allows core package to inject platform-specific services)
|
|
608
640
|
_PerpsController_options.set(this, void 0);
|
|
609
641
|
// Service instances (instantiated with platform dependencies)
|
|
@@ -631,7 +663,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
631
663
|
_PerpsController_previousIsTestnet.set(this, null);
|
|
632
664
|
_PerpsController_previousHip3ConfigVersion.set(this, null);
|
|
633
665
|
__classPrivateFieldSet(this, _PerpsController_eligibilityCheckDeferred, deferEligibilityCheck, "f");
|
|
634
|
-
__classPrivateFieldSet(this, _PerpsController_getAgentSigner, getAgentSigner, "f");
|
|
635
666
|
// Store options for dependency injection
|
|
636
667
|
__classPrivateFieldSet(this, _PerpsController_options, {
|
|
637
668
|
messenger,
|
|
@@ -994,6 +1025,50 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
994
1025
|
return __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_initWithoutDisconnectWait).call(this);
|
|
995
1026
|
}
|
|
996
1027
|
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Registers the MYX provider after dynamic import resolves.
|
|
1030
|
+
*
|
|
1031
|
+
* Extracted from the import().then() callback so it can be tested directly
|
|
1032
|
+
* (Jest cannot resolve dynamic imports without --experimental-vm-modules).
|
|
1033
|
+
*
|
|
1034
|
+
* @param MYXProvider - Constructor class for the MYX provider.
|
|
1035
|
+
*/
|
|
1036
|
+
registerMYXProvider(MYXProvider) {
|
|
1037
|
+
if (typeof MYXProvider !== 'function') {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
const myxIsTestnet = perpsConfig_js_1.PROVIDER_CONFIG.MYX_TESTNET_ONLY || this.state.isTestnet;
|
|
1041
|
+
const myx = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.myx ?? {};
|
|
1042
|
+
const myxAuthConfig = resolveMyxAuthConfig(myx, myxIsTestnet);
|
|
1043
|
+
const MYXProviderConstructor = MYXProvider;
|
|
1044
|
+
const myxProvider = new MYXProviderConstructor({
|
|
1045
|
+
isTestnet: myxIsTestnet,
|
|
1046
|
+
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
1047
|
+
messenger: this.messenger,
|
|
1048
|
+
myxAuthConfig,
|
|
1049
|
+
});
|
|
1050
|
+
this.providers.set('myx', myxProvider);
|
|
1051
|
+
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, 'PerpsController: MYX provider registered', {
|
|
1052
|
+
isTestnet: myxIsTestnet,
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Handles errors from the MYX dynamic import.
|
|
1057
|
+
*
|
|
1058
|
+
* Module-not-found errors are expected (extension doesn't ship MYX) → debug log.
|
|
1059
|
+
* Other errors indicate constructor/config problems → Sentry via logError.
|
|
1060
|
+
*
|
|
1061
|
+
* @param error - The caught error from the dynamic import or constructor.
|
|
1062
|
+
*/
|
|
1063
|
+
handleMYXImportError(error) {
|
|
1064
|
+
const isModuleError = error?.code === 'MODULE_NOT_FOUND';
|
|
1065
|
+
if (isModuleError) {
|
|
1066
|
+
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, 'PerpsController: MYX provider module not available, skipping registration');
|
|
1067
|
+
}
|
|
1068
|
+
else {
|
|
1069
|
+
__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'));
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
997
1072
|
/**
|
|
998
1073
|
* Registers the Lighter provider after dynamic import resolves.
|
|
999
1074
|
*
|
|
@@ -1813,7 +1888,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1813
1888
|
if (params?.standalone && params.userAddress) {
|
|
1814
1889
|
// Use activeProviderInstance if available (respects provider abstraction)
|
|
1815
1890
|
// Fallback to cached standalone provider for pre-initialization discovery
|
|
1816
|
-
// TODO: When adding new providers, consider a provider factory pattern
|
|
1891
|
+
// TODO: When adding new providers (MYX), consider a provider factory pattern
|
|
1817
1892
|
const provider = this.activeProviderInstance ?? __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getOrCreateStandaloneProvider).call(this);
|
|
1818
1893
|
const operation = provider.getPositions(params);
|
|
1819
1894
|
return provider === __classPrivateFieldGet(this, _PerpsController_standaloneProvider, "f")
|
|
@@ -2402,25 +2477,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
2402
2477
|
// Provided properties win over attribution context.
|
|
2403
2478
|
return { ...utm, ...properties };
|
|
2404
2479
|
}
|
|
2405
|
-
/**
|
|
2406
|
-
* Override (or clear) the trading wallet the HyperLiquid provider signs with.
|
|
2407
|
-
*
|
|
2408
|
-
* The host app calls this with a local agent signer when an agent wallet
|
|
2409
|
-
* activates, and with `null` when the keyring locks (restoring the master
|
|
2410
|
-
* keyring path). Throws when the HyperLiquid provider is not (yet)
|
|
2411
|
-
* registered — callers should treat that as best-effort.
|
|
2412
|
-
*
|
|
2413
|
-
* @param signer - The agent signer to sign with, or null for the master path.
|
|
2414
|
-
* @returns A promise that resolves when the clients have re-initialized with
|
|
2415
|
-
* the new wallet.
|
|
2416
|
-
*/
|
|
2417
|
-
async setTradingWalletOverride(signer) {
|
|
2418
|
-
const provider = this.providers.get('hyperliquid');
|
|
2419
|
-
if (!(provider instanceof HyperLiquidProvider_js_1.HyperLiquidProvider)) {
|
|
2420
|
-
throw new Error(perpsErrorCodes_js_1.PERPS_ERROR_CODES.PROVIDER_NOT_AVAILABLE);
|
|
2421
|
-
}
|
|
2422
|
-
return provider.setTradingWalletOverride(signer);
|
|
2423
|
-
}
|
|
2424
2480
|
/**
|
|
2425
2481
|
* Toggle between testnet and mainnet
|
|
2426
2482
|
*
|
|
@@ -3025,24 +3081,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
3025
3081
|
? provider.approveSubscriptionBuilderFee()
|
|
3026
3082
|
: false;
|
|
3027
3083
|
}
|
|
3028
|
-
/**
|
|
3029
|
-
* Run the deferred trading-readiness steps for the active provider
|
|
3030
|
-
* (unified account enablement with user signing, builder fee approval) so
|
|
3031
|
-
* any required master signature surfaces during a guided session (e.g.
|
|
3032
|
-
* agent wallet setup) instead of as a surprise prompt on the first order.
|
|
3033
|
-
*
|
|
3034
|
-
* Reuses the provider's own trading-readiness sequence, which is cached:
|
|
3035
|
-
* an already-ready wallet completes without any signature. Providers
|
|
3036
|
-
* without deferred setup make this a no-op. Best-effort by design of the
|
|
3037
|
-
* underlying sequence: builder-fee failures are swallowed there and retried
|
|
3038
|
-
* at order time; only initialization/migration errors propagate.
|
|
3039
|
-
*/
|
|
3040
|
-
async prepareTradingWallet() {
|
|
3041
|
-
const provider = await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getActiveProviderWhenReady).call(this);
|
|
3042
|
-
if (provider.prepareTradingWallet) {
|
|
3043
|
-
await provider.prepareTradingWallet();
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
3084
|
/**
|
|
3047
3085
|
* Drop the cached subscription benefits snapshot.
|
|
3048
3086
|
*
|
|
@@ -3836,7 +3874,36 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
3836
3874
|
}
|
|
3837
3875
|
}
|
|
3838
3876
|
exports.PerpsController = PerpsController;
|
|
3839
|
-
_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(),
|
|
3877
|
+
_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() {
|
|
3878
|
+
const myx = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.myx;
|
|
3879
|
+
// Local env-var override (MM_PERPS_MYX_PROVIDER_ENABLED) always wins —
|
|
3880
|
+
// matches the UI selector (resolvePerpsMyxProviderEnabled) so controller
|
|
3881
|
+
// and UI agree on whether MYX is available.
|
|
3882
|
+
if (myx?.enabled) {
|
|
3883
|
+
return true;
|
|
3884
|
+
}
|
|
3885
|
+
// Credentials present → MYX is enabled regardless of remote flag.
|
|
3886
|
+
// Use || so empty-string env vars (default '') fall through.
|
|
3887
|
+
const hasCredentials = Boolean(
|
|
3888
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
3889
|
+
myx?.appIdTestnet || myx?.appIdMainnet);
|
|
3890
|
+
if (hasCredentials) {
|
|
3891
|
+
return true;
|
|
3892
|
+
}
|
|
3893
|
+
// No local override or credentials — check remote flag as fallback
|
|
3894
|
+
try {
|
|
3895
|
+
const remoteState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
3896
|
+
const remoteFlag = remoteState.remoteFeatureFlags?.perpsMyxProviderEnabled;
|
|
3897
|
+
if ((0, index_js_1.isVersionGatedFeatureFlag)(remoteFlag)) {
|
|
3898
|
+
const validated = __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure.featureFlags.validateVersionGated(remoteFlag);
|
|
3899
|
+
return validated ?? false;
|
|
3900
|
+
}
|
|
3901
|
+
return false;
|
|
3902
|
+
}
|
|
3903
|
+
catch {
|
|
3904
|
+
return false;
|
|
3905
|
+
}
|
|
3906
|
+
}, _PerpsController_isLighterProviderEnabled = function _PerpsController_isLighterProviderEnabled() {
|
|
3840
3907
|
const lighter = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.lighter;
|
|
3841
3908
|
if (lighter?.enabled) {
|
|
3842
3909
|
return true;
|
|
@@ -3874,6 +3941,7 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3874
3941
|
continue;
|
|
3875
3942
|
}
|
|
3876
3943
|
if (providerId === 'hyperliquid' ||
|
|
3944
|
+
(providerId === 'myx' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this)) ||
|
|
3877
3945
|
(providerId === 'lighter' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this)) ||
|
|
3878
3946
|
this.providers.has(providerId)) {
|
|
3879
3947
|
providerIds.add(providerId);
|
|
@@ -3996,7 +4064,6 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3996
4064
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
3997
4065
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
3998
4066
|
messenger: this.messenger,
|
|
3999
|
-
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4000
4067
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4001
4068
|
?.builderAddressTestnet,
|
|
4002
4069
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4219,13 +4286,15 @@ async function _PerpsController_performInitialization() {
|
|
|
4219
4286
|
this.providers.clear();
|
|
4220
4287
|
await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_cleanupStandaloneProvider).call(this);
|
|
4221
4288
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_createProviders).call(this);
|
|
4222
|
-
// Await
|
|
4223
|
-
//
|
|
4224
|
-
//
|
|
4289
|
+
// Await MYX dynamic import (if started) so MYX is in the providers
|
|
4290
|
+
// map before we assign the active provider. Runs concurrently with
|
|
4291
|
+
// the WebSocket readiness delay for zero additional latency.
|
|
4225
4292
|
await Promise.all([
|
|
4226
4293
|
(0, wait_js_1.wait)(perpsConfig_js_1.PERPS_CONSTANTS.ReconnectionCleanupDelayMs),
|
|
4294
|
+
__classPrivateFieldGet(this, _PerpsController_myxRegistrationPromise, "f"),
|
|
4227
4295
|
__classPrivateFieldGet(this, _PerpsController_lighterRegistrationPromise, "f"),
|
|
4228
4296
|
]);
|
|
4297
|
+
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, null, "f");
|
|
4229
4298
|
__classPrivateFieldSet(this, _PerpsController_lighterRegistrationPromise, null, "f");
|
|
4230
4299
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_assignActiveProvider).call(this);
|
|
4231
4300
|
this.isInitialized = true;
|
|
@@ -4296,7 +4365,6 @@ async function _PerpsController_performInitialization() {
|
|
|
4296
4365
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4297
4366
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4298
4367
|
messenger: this.messenger,
|
|
4299
|
-
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4300
4368
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4301
4369
|
?.builderAddressTestnet,
|
|
4302
4370
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4308,12 +4376,32 @@ async function _PerpsController_performInitialization() {
|
|
|
4308
4376
|
onChaseOrderMaxDistanceReached: __classPrivateFieldGet(this, _PerpsController_publishChaseOrderMaxDistanceReached, "f"),
|
|
4309
4377
|
});
|
|
4310
4378
|
this.providers.set('hyperliquid', hyperLiquidProvider);
|
|
4311
|
-
// Register
|
|
4312
|
-
//
|
|
4313
|
-
//
|
|
4314
|
-
//
|
|
4315
|
-
//
|
|
4316
|
-
// is only used when
|
|
4379
|
+
// Register MYX provider if enabled via feature flag.
|
|
4380
|
+
// Dynamic import because the MYX package pulls in heavy dependencies we
|
|
4381
|
+
// don't want bundled in extension. Until MYX fixes their package, extension
|
|
4382
|
+
// doesn't ship it — the catch branch silently skips registration.
|
|
4383
|
+
// Uses .then()/.catch() instead of await because #createProviders is not async;
|
|
4384
|
+
// MYX registration completing asynchronously is fine since it's only used when
|
|
4385
|
+
// explicitly enabled and selected.
|
|
4386
|
+
const isMYXEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this);
|
|
4387
|
+
if (isMYXEnabled) {
|
|
4388
|
+
// IMPORTANT: Must use import() — NOT require() — for core/extension tree-shaking.
|
|
4389
|
+
// require() is synchronous and bundlers include it in the main bundle.
|
|
4390
|
+
// import() enables true code splitting so MYX is excluded when not enabled.
|
|
4391
|
+
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
4392
|
+
// import argument and strip the webpackIgnore magic comment in core dist.
|
|
4393
|
+
const myxModulePath = './providers/MYXProvider';
|
|
4394
|
+
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, import(
|
|
4395
|
+
/* webpackIgnore: true */ myxModulePath)
|
|
4396
|
+
.then(({ MYXProvider }) => {
|
|
4397
|
+
this.registerMYXProvider(MYXProvider);
|
|
4398
|
+
return undefined;
|
|
4399
|
+
})
|
|
4400
|
+
.catch((error) => this.handleMYXImportError(error)), "f");
|
|
4401
|
+
}
|
|
4402
|
+
// Register Lighter provider if enabled (POC). Same dynamic-import pattern
|
|
4403
|
+
// as MYX so clients that do not ship the Lighter files skip registration
|
|
4404
|
+
// silently.
|
|
4317
4405
|
const isLighterEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this);
|
|
4318
4406
|
if (isLighterEnabled) {
|
|
4319
4407
|
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
@@ -4345,11 +4433,7 @@ async function _PerpsController_performInitialization() {
|
|
|
4345
4433
|
this.activeProviderInstance = hyperLiquidProvider;
|
|
4346
4434
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${activeProvider})`);
|
|
4347
4435
|
}
|
|
4348
|
-
else {
|
|
4349
|
-
// Any other direct provider, including a value persisted by an older
|
|
4350
|
-
// version whose venue has since been removed. `activeProvider` is
|
|
4351
|
-
// persisted, so throwing here would fail initialization on every
|
|
4352
|
-
// launch — the stale value must self-heal.
|
|
4436
|
+
else if (activeProvider === 'myx' || activeProvider === 'lighter') {
|
|
4353
4437
|
const directProvider = this.providers.get(activeProvider);
|
|
4354
4438
|
if (directProvider) {
|
|
4355
4439
|
this.activeProviderInstance = directProvider;
|
|
@@ -4363,6 +4447,9 @@ async function _PerpsController_performInitialization() {
|
|
|
4363
4447
|
}
|
|
4364
4448
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${this.activeProviderInstance === hyperLiquidProvider ? 'hyperliquid' : activeProvider})`);
|
|
4365
4449
|
}
|
|
4450
|
+
else {
|
|
4451
|
+
throw new Error(`Unsupported provider: ${String(activeProvider)}. Currently only 'hyperliquid', 'myx', 'lighter', and 'aggregated' are supported.`);
|
|
4452
|
+
}
|
|
4366
4453
|
}, _PerpsController_getErrorContext = function _PerpsController_getErrorContext(method, extra) {
|
|
4367
4454
|
return {
|
|
4368
4455
|
tags: {
|
|
@@ -5084,6 +5171,7 @@ async function _PerpsController_persistWatchlistToRemote(network) {
|
|
|
5084
5171
|
const existingWatchlist = prefs.perps
|
|
5085
5172
|
.watchlistMarkets ?? {
|
|
5086
5173
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5174
|
+
myx: { testnet: [], mainnet: [] },
|
|
5087
5175
|
};
|
|
5088
5176
|
const nextWatchlistMarkets = {
|
|
5089
5177
|
...existingWatchlist,
|
|
@@ -5151,6 +5239,7 @@ async function _PerpsController_syncWatchlistFromRemote() {
|
|
|
5151
5239
|
const existingWatchlist = prefs.perps
|
|
5152
5240
|
.watchlistMarkets ?? {
|
|
5153
5241
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5242
|
+
myx: { testnet: [], mainnet: [] },
|
|
5154
5243
|
};
|
|
5155
5244
|
const nextWatchlistMarkets = {
|
|
5156
5245
|
...existingWatchlist,
|