@metamask-previews/perps-controller 15.1.0-preview-6b7c25c → 15.1.0-preview-00a181c
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 +14 -0
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +20 -1
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +20 -1
- 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 +65 -154
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +37 -43
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +37 -43
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +64 -151
- 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 +0 -1
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +0 -1
- package/dist/constants/index.d.cts.map +1 -1
- package/dist/constants/index.d.mts +0 -1
- package/dist/constants/index.d.mts.map +1 -1
- package/dist/constants/index.mjs +0 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +4 -9
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +3 -5
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +3 -5
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +4 -9
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/index.cjs +146 -175
- 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 +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +8 -2
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +3 -2
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +3 -2
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +8 -2
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +118 -22
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +31 -0
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +31 -0
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +118 -22
- 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 +26 -16
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts +26 -16
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.cjs +80 -30
- package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.cts +48 -22
- package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.mts +48 -22
- package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
- package/dist/services/HyperLiquidWalletService.mjs +80 -30
- 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 +10 -16
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +10 -16
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/lighterAdapter.cjs +1 -2
- package/dist/utils/lighterAdapter.cjs.map +1 -1
- package/dist/utils/lighterAdapter.d.cts +1 -2
- package/dist/utils/lighterAdapter.d.cts.map +1 -1
- package/dist/utils/lighterAdapter.d.mts +1 -2
- package/dist/utils/lighterAdapter.d.mts.map +1 -1
- package/dist/utils/lighterAdapter.mjs +1 -2
- package/dist/utils/lighterAdapter.mjs.map +1 -1
- package/package.json +2 -8
- package/dist/constants/myxConfig.cjs +0 -253
- package/dist/constants/myxConfig.cjs.map +0 -1
- package/dist/constants/myxConfig.d.cts +0 -145
- package/dist/constants/myxConfig.d.cts.map +0 -1
- package/dist/constants/myxConfig.d.mts +0 -145
- package/dist/constants/myxConfig.d.mts.map +0 -1
- package/dist/constants/myxConfig.mjs +0 -243
- package/dist/constants/myxConfig.mjs.map +0 -1
- package/dist/types/myx-types.cjs +0 -41
- package/dist/types/myx-types.cjs.map +0 -1
- package/dist/types/myx-types.d.cts +0 -94
- package/dist/types/myx-types.d.cts.map +0 -1
- package/dist/types/myx-types.d.mts +0 -94
- package/dist/types/myx-types.d.mts.map +0 -1
- package/dist/types/myx-types.mjs +0 -26
- package/dist/types/myx-types.mjs.map +0 -1
- package/dist/utils/myxAdapter.cjs +0 -569
- package/dist/utils/myxAdapter.cjs.map +0 -1
- package/dist/utils/myxAdapter.d.cts +0 -168
- package/dist/utils/myxAdapter.d.cts.map +0 -1
- package/dist/utils/myxAdapter.d.mts +0 -168
- package/dist/utils/myxAdapter.d.mts.map +0 -1
- package/dist/utils/myxAdapter.mjs +0 -548
- package/dist/utils/myxAdapter.mjs.map +0 -1
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,
|
|
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, _PerpsController_getAgentSigner, _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.
|
|
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;
|
|
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,17 +72,6 @@ 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;
|
|
86
75
|
/**
|
|
87
76
|
* Maps an active provider mode to the corresponding exchange key used in the
|
|
88
77
|
* AUS {@link PerpsWatchlistMarkets} schema.
|
|
@@ -98,33 +87,10 @@ exports.firstNonEmpty = firstNonEmpty;
|
|
|
98
87
|
function resolveWatchlistExchangeKey(activeProvider) {
|
|
99
88
|
const map = {
|
|
100
89
|
hyperliquid: 'hyperliquid',
|
|
101
|
-
myx: 'myx',
|
|
102
90
|
};
|
|
103
91
|
return map[activeProvider] ?? null;
|
|
104
92
|
}
|
|
105
93
|
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;
|
|
128
94
|
// Re-export error codes from separate file to avoid circular dependencies
|
|
129
95
|
var perpsErrorCodes_js_2 = require("./perpsErrorCodes.cjs");
|
|
130
96
|
Object.defineProperty(exports, "PERPS_ERROR_CODES", { enumerable: true, get: function () { return perpsErrorCodes_js_2.PERPS_ERROR_CODES; } });
|
|
@@ -152,7 +118,6 @@ Object.defineProperty(exports, "DEFAULT_SELECTED_ORDER_TYPE", { enumerable: true
|
|
|
152
118
|
* To change the active provider, modify the `activeProvider` value below:
|
|
153
119
|
* - 'hyperliquid': HyperLiquid provider (default, production)
|
|
154
120
|
* - 'aggregated': Multi-provider aggregation mode
|
|
155
|
-
* - 'myx': MYX provider (future implementation)
|
|
156
121
|
*
|
|
157
122
|
* @returns The default perps controller state.
|
|
158
123
|
*/
|
|
@@ -506,6 +471,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
506
471
|
'markTutorialCompleted',
|
|
507
472
|
'placeOrder',
|
|
508
473
|
'previewPositionModify',
|
|
474
|
+
'prepareTradingWallet',
|
|
509
475
|
'reconnect',
|
|
510
476
|
'recordMarketViewed',
|
|
511
477
|
'refreshEligibility',
|
|
@@ -526,6 +492,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
526
492
|
'setLiveDataConfig',
|
|
527
493
|
'setSelectedPaymentToken',
|
|
528
494
|
'setVisibleCandleCount',
|
|
495
|
+
'setTradingWalletOverride',
|
|
529
496
|
'startEligibilityMonitoring',
|
|
530
497
|
'startMarketDataPreload',
|
|
531
498
|
'stopEligibilityMonitoring',
|
|
@@ -562,7 +529,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
562
529
|
* - Live data uses direct callbacks for maximum performance
|
|
563
530
|
*/
|
|
564
531
|
class PerpsController extends base_controller_1.BaseController {
|
|
565
|
-
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, }) {
|
|
532
|
+
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, getAgentSigner, }) {
|
|
566
533
|
super({
|
|
567
534
|
name: 'PerpsController',
|
|
568
535
|
metadata,
|
|
@@ -575,8 +542,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
575
542
|
_PerpsController_isReinitializing.set(this, false);
|
|
576
543
|
_PerpsController_reinitializationOperationPromise.set(this, null);
|
|
577
544
|
_PerpsController_disconnectOperationPromise.set(this, null);
|
|
578
|
-
/** Tracks the async MYX dynamic import so performInitialization can await it. */
|
|
579
|
-
_PerpsController_myxRegistrationPromise.set(this, null);
|
|
580
545
|
_PerpsController_lighterRegistrationPromise.set(this, null);
|
|
581
546
|
this.blockedRegionList = {
|
|
582
547
|
list: [],
|
|
@@ -606,7 +571,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
606
571
|
_PerpsController_attributionContext.set(this, {});
|
|
607
572
|
/**
|
|
608
573
|
* Active provider instance for routing operations.
|
|
609
|
-
* When activeProvider is 'hyperliquid' or '
|
|
574
|
+
* When activeProvider is 'hyperliquid' or 'lighter': points to specific provider directly
|
|
610
575
|
* When activeProvider is 'aggregated': points to AggregatedPerpsProvider wrapper
|
|
611
576
|
*/
|
|
612
577
|
this.activeProviderInstance = null;
|
|
@@ -636,6 +601,9 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
636
601
|
*/
|
|
637
602
|
_PerpsController_ausQueue.set(this, Promise.resolve());
|
|
638
603
|
_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);
|
|
639
607
|
// Store options for dependency injection (allows core package to inject platform-specific services)
|
|
640
608
|
_PerpsController_options.set(this, void 0);
|
|
641
609
|
// Service instances (instantiated with platform dependencies)
|
|
@@ -663,6 +631,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
663
631
|
_PerpsController_previousIsTestnet.set(this, null);
|
|
664
632
|
_PerpsController_previousHip3ConfigVersion.set(this, null);
|
|
665
633
|
__classPrivateFieldSet(this, _PerpsController_eligibilityCheckDeferred, deferEligibilityCheck, "f");
|
|
634
|
+
__classPrivateFieldSet(this, _PerpsController_getAgentSigner, getAgentSigner, "f");
|
|
666
635
|
// Store options for dependency injection
|
|
667
636
|
__classPrivateFieldSet(this, _PerpsController_options, {
|
|
668
637
|
messenger,
|
|
@@ -1025,50 +994,6 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1025
994
|
return __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_initWithoutDisconnectWait).call(this);
|
|
1026
995
|
}
|
|
1027
996
|
}
|
|
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
|
-
}
|
|
1072
997
|
/**
|
|
1073
998
|
* Registers the Lighter provider after dynamic import resolves.
|
|
1074
999
|
*
|
|
@@ -1888,7 +1813,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
1888
1813
|
if (params?.standalone && params.userAddress) {
|
|
1889
1814
|
// Use activeProviderInstance if available (respects provider abstraction)
|
|
1890
1815
|
// Fallback to cached standalone provider for pre-initialization discovery
|
|
1891
|
-
// TODO: When adding new providers
|
|
1816
|
+
// TODO: When adding new providers, consider a provider factory pattern
|
|
1892
1817
|
const provider = this.activeProviderInstance ?? __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getOrCreateStandaloneProvider).call(this);
|
|
1893
1818
|
const operation = provider.getPositions(params);
|
|
1894
1819
|
return provider === __classPrivateFieldGet(this, _PerpsController_standaloneProvider, "f")
|
|
@@ -2477,6 +2402,25 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
2477
2402
|
// Provided properties win over attribution context.
|
|
2478
2403
|
return { ...utm, ...properties };
|
|
2479
2404
|
}
|
|
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
|
+
}
|
|
2480
2424
|
/**
|
|
2481
2425
|
* Toggle between testnet and mainnet
|
|
2482
2426
|
*
|
|
@@ -3081,6 +3025,24 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
3081
3025
|
? provider.approveSubscriptionBuilderFee()
|
|
3082
3026
|
: false;
|
|
3083
3027
|
}
|
|
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
|
+
}
|
|
3084
3046
|
/**
|
|
3085
3047
|
* Drop the cached subscription benefits snapshot.
|
|
3086
3048
|
*
|
|
@@ -3874,36 +3836,7 @@ class PerpsController extends base_controller_1.BaseController {
|
|
|
3874
3836
|
}
|
|
3875
3837
|
}
|
|
3876
3838
|
exports.PerpsController = PerpsController;
|
|
3877
|
-
_a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _PerpsController_isReinitializing = new WeakMap(), _PerpsController_reinitializationOperationPromise = new WeakMap(), _PerpsController_disconnectOperationPromise = new WeakMap(),
|
|
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() {
|
|
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(), _PerpsController_getAgentSigner = 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_isLighterProviderEnabled = function _PerpsController_isLighterProviderEnabled() {
|
|
3907
3840
|
const lighter = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.lighter;
|
|
3908
3841
|
if (lighter?.enabled) {
|
|
3909
3842
|
return true;
|
|
@@ -3941,7 +3874,6 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3941
3874
|
continue;
|
|
3942
3875
|
}
|
|
3943
3876
|
if (providerId === 'hyperliquid' ||
|
|
3944
|
-
(providerId === 'myx' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this)) ||
|
|
3945
3877
|
(providerId === 'lighter' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this)) ||
|
|
3946
3878
|
this.providers.has(providerId)) {
|
|
3947
3879
|
providerIds.add(providerId);
|
|
@@ -4064,6 +3996,7 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
4064
3996
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4065
3997
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4066
3998
|
messenger: this.messenger,
|
|
3999
|
+
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4067
4000
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4068
4001
|
?.builderAddressTestnet,
|
|
4069
4002
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4286,15 +4219,13 @@ async function _PerpsController_performInitialization() {
|
|
|
4286
4219
|
this.providers.clear();
|
|
4287
4220
|
await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_cleanupStandaloneProvider).call(this);
|
|
4288
4221
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_createProviders).call(this);
|
|
4289
|
-
// Await
|
|
4290
|
-
// map before we assign the active provider. Runs concurrently
|
|
4291
|
-
// the WebSocket readiness delay for zero additional latency.
|
|
4222
|
+
// Await the Lighter dynamic import (if started) so Lighter is in the
|
|
4223
|
+
// providers map before we assign the active provider. Runs concurrently
|
|
4224
|
+
// with the WebSocket readiness delay for zero additional latency.
|
|
4292
4225
|
await Promise.all([
|
|
4293
4226
|
(0, wait_js_1.wait)(perpsConfig_js_1.PERPS_CONSTANTS.ReconnectionCleanupDelayMs),
|
|
4294
|
-
__classPrivateFieldGet(this, _PerpsController_myxRegistrationPromise, "f"),
|
|
4295
4227
|
__classPrivateFieldGet(this, _PerpsController_lighterRegistrationPromise, "f"),
|
|
4296
4228
|
]);
|
|
4297
|
-
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, null, "f");
|
|
4298
4229
|
__classPrivateFieldSet(this, _PerpsController_lighterRegistrationPromise, null, "f");
|
|
4299
4230
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_assignActiveProvider).call(this);
|
|
4300
4231
|
this.isInitialized = true;
|
|
@@ -4365,6 +4296,7 @@ async function _PerpsController_performInitialization() {
|
|
|
4365
4296
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4366
4297
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4367
4298
|
messenger: this.messenger,
|
|
4299
|
+
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4368
4300
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4369
4301
|
?.builderAddressTestnet,
|
|
4370
4302
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4376,32 +4308,12 @@ async function _PerpsController_performInitialization() {
|
|
|
4376
4308
|
onChaseOrderMaxDistanceReached: __classPrivateFieldGet(this, _PerpsController_publishChaseOrderMaxDistanceReached, "f"),
|
|
4377
4309
|
});
|
|
4378
4310
|
this.providers.set('hyperliquid', hyperLiquidProvider);
|
|
4379
|
-
// Register
|
|
4380
|
-
//
|
|
4381
|
-
//
|
|
4382
|
-
//
|
|
4383
|
-
//
|
|
4384
|
-
//
|
|
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.
|
|
4311
|
+
// Register Lighter provider if enabled (POC). Dynamic import so clients
|
|
4312
|
+
// that do not ship the Lighter files skip registration silently, and so
|
|
4313
|
+
// bundlers can code-split it out when it is not enabled.
|
|
4314
|
+
// Uses .then()/.catch() instead of await because #createProviders is not
|
|
4315
|
+
// async; registration completing asynchronously is fine since the provider
|
|
4316
|
+
// is only used when explicitly enabled and selected.
|
|
4405
4317
|
const isLighterEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this);
|
|
4406
4318
|
if (isLighterEnabled) {
|
|
4407
4319
|
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
@@ -4433,7 +4345,11 @@ async function _PerpsController_performInitialization() {
|
|
|
4433
4345
|
this.activeProviderInstance = hyperLiquidProvider;
|
|
4434
4346
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${activeProvider})`);
|
|
4435
4347
|
}
|
|
4436
|
-
else
|
|
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.
|
|
4437
4353
|
const directProvider = this.providers.get(activeProvider);
|
|
4438
4354
|
if (directProvider) {
|
|
4439
4355
|
this.activeProviderInstance = directProvider;
|
|
@@ -4447,9 +4363,6 @@ async function _PerpsController_performInitialization() {
|
|
|
4447
4363
|
}
|
|
4448
4364
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${this.activeProviderInstance === hyperLiquidProvider ? 'hyperliquid' : activeProvider})`);
|
|
4449
4365
|
}
|
|
4450
|
-
else {
|
|
4451
|
-
throw new Error(`Unsupported provider: ${String(activeProvider)}. Currently only 'hyperliquid', 'myx', 'lighter', and 'aggregated' are supported.`);
|
|
4452
|
-
}
|
|
4453
4366
|
}, _PerpsController_getErrorContext = function _PerpsController_getErrorContext(method, extra) {
|
|
4454
4367
|
return {
|
|
4455
4368
|
tags: {
|
|
@@ -5171,7 +5084,6 @@ async function _PerpsController_persistWatchlistToRemote(network) {
|
|
|
5171
5084
|
const existingWatchlist = prefs.perps
|
|
5172
5085
|
.watchlistMarkets ?? {
|
|
5173
5086
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5174
|
-
myx: { testnet: [], mainnet: [] },
|
|
5175
5087
|
};
|
|
5176
5088
|
const nextWatchlistMarkets = {
|
|
5177
5089
|
...existingWatchlist,
|
|
@@ -5239,7 +5151,6 @@ async function _PerpsController_syncWatchlistFromRemote() {
|
|
|
5239
5151
|
const existingWatchlist = prefs.perps
|
|
5240
5152
|
.watchlistMarkets ?? {
|
|
5241
5153
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5242
|
-
myx: { testnet: [], mainnet: [] },
|
|
5243
5154
|
};
|
|
5244
5155
|
const nextWatchlistMarkets = {
|
|
5245
5156
|
...existingWatchlist,
|