@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.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,
|
|
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, _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;
|
|
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,16 +69,6 @@ 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
|
-
}
|
|
82
72
|
/**
|
|
83
73
|
* Maps an active provider mode to the corresponding exchange key used in the
|
|
84
74
|
* AUS {@link PerpsWatchlistMarkets} schema.
|
|
@@ -94,31 +84,9 @@ export function firstNonEmpty(...vals) {
|
|
|
94
84
|
export function resolveWatchlistExchangeKey(activeProvider) {
|
|
95
85
|
const map = {
|
|
96
86
|
hyperliquid: 'hyperliquid',
|
|
97
|
-
myx: 'myx',
|
|
98
87
|
};
|
|
99
88
|
return map[activeProvider] ?? null;
|
|
100
89
|
}
|
|
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
|
-
}
|
|
122
90
|
// Re-export error codes from separate file to avoid circular dependencies
|
|
123
91
|
export { PERPS_ERROR_CODES } from "./perpsErrorCodes.mjs";
|
|
124
92
|
/**
|
|
@@ -140,7 +108,6 @@ export { PerpsMode, DEFAULT_ORDER_BOOK_PREFERENCES, DEFAULT_PERPS_MODE, DEFAULT_
|
|
|
140
108
|
* To change the active provider, modify the `activeProvider` value below:
|
|
141
109
|
* - 'hyperliquid': HyperLiquid provider (default, production)
|
|
142
110
|
* - 'aggregated': Multi-provider aggregation mode
|
|
143
|
-
* - 'myx': MYX provider (future implementation)
|
|
144
111
|
*
|
|
145
112
|
* @returns The default perps controller state.
|
|
146
113
|
*/
|
|
@@ -493,6 +460,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
493
460
|
'markTutorialCompleted',
|
|
494
461
|
'placeOrder',
|
|
495
462
|
'previewPositionModify',
|
|
463
|
+
'prepareTradingWallet',
|
|
496
464
|
'reconnect',
|
|
497
465
|
'recordMarketViewed',
|
|
498
466
|
'refreshEligibility',
|
|
@@ -513,6 +481,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
513
481
|
'setLiveDataConfig',
|
|
514
482
|
'setSelectedPaymentToken',
|
|
515
483
|
'setVisibleCandleCount',
|
|
484
|
+
'setTradingWalletOverride',
|
|
516
485
|
'startEligibilityMonitoring',
|
|
517
486
|
'startMarketDataPreload',
|
|
518
487
|
'stopEligibilityMonitoring',
|
|
@@ -549,7 +518,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
549
518
|
* - Live data uses direct callbacks for maximum performance
|
|
550
519
|
*/
|
|
551
520
|
export class PerpsController extends BaseController {
|
|
552
|
-
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, }) {
|
|
521
|
+
constructor({ messenger, state = {}, clientConfig = {}, infrastructure, deferEligibilityCheck = false, getAgentSigner, }) {
|
|
553
522
|
super({
|
|
554
523
|
name: 'PerpsController',
|
|
555
524
|
metadata,
|
|
@@ -562,8 +531,6 @@ export class PerpsController extends BaseController {
|
|
|
562
531
|
_PerpsController_isReinitializing.set(this, false);
|
|
563
532
|
_PerpsController_reinitializationOperationPromise.set(this, null);
|
|
564
533
|
_PerpsController_disconnectOperationPromise.set(this, null);
|
|
565
|
-
/** Tracks the async MYX dynamic import so performInitialization can await it. */
|
|
566
|
-
_PerpsController_myxRegistrationPromise.set(this, null);
|
|
567
534
|
_PerpsController_lighterRegistrationPromise.set(this, null);
|
|
568
535
|
this.blockedRegionList = {
|
|
569
536
|
list: [],
|
|
@@ -593,7 +560,7 @@ export class PerpsController extends BaseController {
|
|
|
593
560
|
_PerpsController_attributionContext.set(this, {});
|
|
594
561
|
/**
|
|
595
562
|
* Active provider instance for routing operations.
|
|
596
|
-
* When activeProvider is 'hyperliquid' or '
|
|
563
|
+
* When activeProvider is 'hyperliquid' or 'lighter': points to specific provider directly
|
|
597
564
|
* When activeProvider is 'aggregated': points to AggregatedPerpsProvider wrapper
|
|
598
565
|
*/
|
|
599
566
|
this.activeProviderInstance = null;
|
|
@@ -623,6 +590,9 @@ export class PerpsController extends BaseController {
|
|
|
623
590
|
*/
|
|
624
591
|
_PerpsController_ausQueue.set(this, Promise.resolve());
|
|
625
592
|
_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);
|
|
626
596
|
// Store options for dependency injection (allows core package to inject platform-specific services)
|
|
627
597
|
_PerpsController_options.set(this, void 0);
|
|
628
598
|
// Service instances (instantiated with platform dependencies)
|
|
@@ -650,6 +620,7 @@ export class PerpsController extends BaseController {
|
|
|
650
620
|
_PerpsController_previousIsTestnet.set(this, null);
|
|
651
621
|
_PerpsController_previousHip3ConfigVersion.set(this, null);
|
|
652
622
|
__classPrivateFieldSet(this, _PerpsController_eligibilityCheckDeferred, deferEligibilityCheck, "f");
|
|
623
|
+
__classPrivateFieldSet(this, _PerpsController_getAgentSigner, getAgentSigner, "f");
|
|
653
624
|
// Store options for dependency injection
|
|
654
625
|
__classPrivateFieldSet(this, _PerpsController_options, {
|
|
655
626
|
messenger,
|
|
@@ -1012,50 +983,6 @@ export class PerpsController extends BaseController {
|
|
|
1012
983
|
return __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_initWithoutDisconnectWait).call(this);
|
|
1013
984
|
}
|
|
1014
985
|
}
|
|
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
|
-
}
|
|
1059
986
|
/**
|
|
1060
987
|
* Registers the Lighter provider after dynamic import resolves.
|
|
1061
988
|
*
|
|
@@ -1875,7 +1802,7 @@ export class PerpsController extends BaseController {
|
|
|
1875
1802
|
if (params?.standalone && params.userAddress) {
|
|
1876
1803
|
// Use activeProviderInstance if available (respects provider abstraction)
|
|
1877
1804
|
// Fallback to cached standalone provider for pre-initialization discovery
|
|
1878
|
-
// TODO: When adding new providers
|
|
1805
|
+
// TODO: When adding new providers, consider a provider factory pattern
|
|
1879
1806
|
const provider = this.activeProviderInstance ?? __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_getOrCreateStandaloneProvider).call(this);
|
|
1880
1807
|
const operation = provider.getPositions(params);
|
|
1881
1808
|
return provider === __classPrivateFieldGet(this, _PerpsController_standaloneProvider, "f")
|
|
@@ -2464,6 +2391,25 @@ export class PerpsController extends BaseController {
|
|
|
2464
2391
|
// Provided properties win over attribution context.
|
|
2465
2392
|
return { ...utm, ...properties };
|
|
2466
2393
|
}
|
|
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
|
+
}
|
|
2467
2413
|
/**
|
|
2468
2414
|
* Toggle between testnet and mainnet
|
|
2469
2415
|
*
|
|
@@ -3068,6 +3014,24 @@ export class PerpsController extends BaseController {
|
|
|
3068
3014
|
? provider.approveSubscriptionBuilderFee()
|
|
3069
3015
|
: false;
|
|
3070
3016
|
}
|
|
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
|
+
}
|
|
3071
3035
|
/**
|
|
3072
3036
|
* Drop the cached subscription benefits snapshot.
|
|
3073
3037
|
*
|
|
@@ -3860,36 +3824,7 @@ export class PerpsController extends BaseController {
|
|
|
3860
3824
|
return __classPrivateFieldGet(this, _PerpsController_isReinitializing, "f");
|
|
3861
3825
|
}
|
|
3862
3826
|
}
|
|
3863
|
-
_a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _PerpsController_isReinitializing = new WeakMap(), _PerpsController_reinitializationOperationPromise = new WeakMap(), _PerpsController_disconnectOperationPromise = new WeakMap(),
|
|
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() {
|
|
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(), _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() {
|
|
3893
3828
|
const lighter = __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.lighter;
|
|
3894
3829
|
if (lighter?.enabled) {
|
|
3895
3830
|
return true;
|
|
@@ -3927,7 +3862,6 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
3927
3862
|
continue;
|
|
3928
3863
|
}
|
|
3929
3864
|
if (providerId === 'hyperliquid' ||
|
|
3930
|
-
(providerId === 'myx' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isMYXProviderEnabled).call(this)) ||
|
|
3931
3865
|
(providerId === 'lighter' && __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this)) ||
|
|
3932
3866
|
this.providers.has(providerId)) {
|
|
3933
3867
|
providerIds.add(providerId);
|
|
@@ -4050,6 +3984,7 @@ _a = PerpsController, _PerpsController_initializationPromise = new WeakMap(), _P
|
|
|
4050
3984
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4051
3985
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4052
3986
|
messenger: this.messenger,
|
|
3987
|
+
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4053
3988
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4054
3989
|
?.builderAddressTestnet,
|
|
4055
3990
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4272,15 +4207,13 @@ async function _PerpsController_performInitialization() {
|
|
|
4272
4207
|
this.providers.clear();
|
|
4273
4208
|
await __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_cleanupStandaloneProvider).call(this);
|
|
4274
4209
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_createProviders).call(this);
|
|
4275
|
-
// Await
|
|
4276
|
-
// map before we assign the active provider. Runs concurrently
|
|
4277
|
-
// the WebSocket readiness delay for zero additional latency.
|
|
4210
|
+
// Await the Lighter dynamic import (if started) so Lighter is in the
|
|
4211
|
+
// providers map before we assign the active provider. Runs concurrently
|
|
4212
|
+
// with the WebSocket readiness delay for zero additional latency.
|
|
4278
4213
|
await Promise.all([
|
|
4279
4214
|
wait(PERPS_CONSTANTS.ReconnectionCleanupDelayMs),
|
|
4280
|
-
__classPrivateFieldGet(this, _PerpsController_myxRegistrationPromise, "f"),
|
|
4281
4215
|
__classPrivateFieldGet(this, _PerpsController_lighterRegistrationPromise, "f"),
|
|
4282
4216
|
]);
|
|
4283
|
-
__classPrivateFieldSet(this, _PerpsController_myxRegistrationPromise, null, "f");
|
|
4284
4217
|
__classPrivateFieldSet(this, _PerpsController_lighterRegistrationPromise, null, "f");
|
|
4285
4218
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_assignActiveProvider).call(this);
|
|
4286
4219
|
this.isInitialized = true;
|
|
@@ -4351,6 +4284,7 @@ async function _PerpsController_performInitialization() {
|
|
|
4351
4284
|
priceDeviationLimit: __classPrivateFieldGet(this, _PerpsController_priceDeviationLimit, "f"),
|
|
4352
4285
|
platformDependencies: __classPrivateFieldGet(this, _PerpsController_options, "f").infrastructure,
|
|
4353
4286
|
messenger: this.messenger,
|
|
4287
|
+
getAgentSigner: __classPrivateFieldGet(this, _PerpsController_getAgentSigner, "f"),
|
|
4354
4288
|
builderAddressTestnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
4355
4289
|
?.builderAddressTestnet,
|
|
4356
4290
|
builderAddressMainnet: __classPrivateFieldGet(this, _PerpsController_options, "f").clientConfig?.providerCredentials?.hyperliquid
|
|
@@ -4362,32 +4296,12 @@ async function _PerpsController_performInitialization() {
|
|
|
4362
4296
|
onChaseOrderMaxDistanceReached: __classPrivateFieldGet(this, _PerpsController_publishChaseOrderMaxDistanceReached, "f"),
|
|
4363
4297
|
});
|
|
4364
4298
|
this.providers.set('hyperliquid', hyperLiquidProvider);
|
|
4365
|
-
// Register
|
|
4366
|
-
//
|
|
4367
|
-
//
|
|
4368
|
-
//
|
|
4369
|
-
//
|
|
4370
|
-
//
|
|
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.
|
|
4299
|
+
// Register Lighter provider if enabled (POC). Dynamic import so clients
|
|
4300
|
+
// that do not ship the Lighter files skip registration silently, and so
|
|
4301
|
+
// bundlers can code-split it out when it is not enabled.
|
|
4302
|
+
// Uses .then()/.catch() instead of await because #createProviders is not
|
|
4303
|
+
// async; registration completing asynchronously is fine since the provider
|
|
4304
|
+
// is only used when explicitly enabled and selected.
|
|
4391
4305
|
const isLighterEnabled = __classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_isLighterProviderEnabled).call(this);
|
|
4392
4306
|
if (isLighterEnabled) {
|
|
4393
4307
|
// NOTE: Keep the path in a variable so ts-bridge does not rewrite the
|
|
@@ -4419,7 +4333,11 @@ async function _PerpsController_performInitialization() {
|
|
|
4419
4333
|
this.activeProviderInstance = hyperLiquidProvider;
|
|
4420
4334
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${activeProvider})`);
|
|
4421
4335
|
}
|
|
4422
|
-
else
|
|
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.
|
|
4423
4341
|
const directProvider = this.providers.get(activeProvider);
|
|
4424
4342
|
if (directProvider) {
|
|
4425
4343
|
this.activeProviderInstance = directProvider;
|
|
@@ -4433,9 +4351,6 @@ async function _PerpsController_performInitialization() {
|
|
|
4433
4351
|
}
|
|
4434
4352
|
__classPrivateFieldGet(this, _PerpsController_instances, "m", _PerpsController_debugLog).call(this, `PerpsController: Using direct provider (${this.activeProviderInstance === hyperLiquidProvider ? 'hyperliquid' : activeProvider})`);
|
|
4435
4353
|
}
|
|
4436
|
-
else {
|
|
4437
|
-
throw new Error(`Unsupported provider: ${String(activeProvider)}. Currently only 'hyperliquid', 'myx', 'lighter', and 'aggregated' are supported.`);
|
|
4438
|
-
}
|
|
4439
4354
|
}, _PerpsController_getErrorContext = function _PerpsController_getErrorContext(method, extra) {
|
|
4440
4355
|
return {
|
|
4441
4356
|
tags: {
|
|
@@ -5157,7 +5072,6 @@ async function _PerpsController_persistWatchlistToRemote(network) {
|
|
|
5157
5072
|
const existingWatchlist = prefs.perps
|
|
5158
5073
|
.watchlistMarkets ?? {
|
|
5159
5074
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5160
|
-
myx: { testnet: [], mainnet: [] },
|
|
5161
5075
|
};
|
|
5162
5076
|
const nextWatchlistMarkets = {
|
|
5163
5077
|
...existingWatchlist,
|
|
@@ -5225,7 +5139,6 @@ async function _PerpsController_syncWatchlistFromRemote() {
|
|
|
5225
5139
|
const existingWatchlist = prefs.perps
|
|
5226
5140
|
.watchlistMarkets ?? {
|
|
5227
5141
|
hyperliquid: { testnet: [], mainnet: [] },
|
|
5228
|
-
myx: { testnet: [], mainnet: [] },
|
|
5229
5142
|
};
|
|
5230
5143
|
const nextWatchlistMarkets = {
|
|
5231
5144
|
...existingWatchlist,
|