@metamask-previews/perps-controller 13.1.0-preview-8c2a2eeb2 → 13.1.0-preview-4f4c98e
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 +4 -1
- package/dist/{PerpsController-method-action-types.d.mts → PerpsController-method-action-types.d.ts} +2 -2
- package/dist/PerpsController-method-action-types.d.ts.map +1 -0
- package/dist/{PerpsController-method-action-types.mjs → PerpsController-method-action-types.js} +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -0
- package/dist/{PerpsController.d.mts → PerpsController.d.ts} +17 -17
- package/dist/PerpsController.d.ts.map +1 -0
- package/dist/{PerpsController.mjs → PerpsController.js} +33 -31
- package/dist/PerpsController.js.map +1 -0
- package/dist/aggregation/{SubscriptionMultiplexer.d.cts → SubscriptionMultiplexer.d.ts} +2 -2
- package/dist/aggregation/SubscriptionMultiplexer.d.ts.map +1 -0
- package/dist/aggregation/{SubscriptionMultiplexer.mjs → SubscriptionMultiplexer.js} +3 -3
- package/dist/aggregation/SubscriptionMultiplexer.js.map +1 -0
- package/dist/aggregation/index.d.ts +6 -0
- package/dist/aggregation/index.d.ts.map +1 -0
- package/dist/aggregation/index.js +5 -0
- package/dist/aggregation/index.js.map +1 -0
- package/dist/constants/{chartConfig.d.mts → chartConfig.d.ts} +34 -34
- package/dist/constants/chartConfig.d.ts.map +1 -0
- package/dist/constants/{chartConfig.mjs → chartConfig.js} +1 -1
- package/dist/constants/chartConfig.js.map +1 -0
- package/dist/constants/eventNames.d.ts +555 -0
- package/dist/constants/eventNames.d.ts.map +1 -0
- package/dist/constants/{eventNames.mjs → eventNames.js} +1 -1
- package/dist/constants/eventNames.js.map +1 -0
- package/dist/constants/{hyperLiquidConfig.d.cts → hyperLiquidConfig.d.ts} +12 -12
- package/dist/constants/hyperLiquidConfig.d.ts.map +1 -0
- package/dist/constants/{hyperLiquidConfig.mjs → hyperLiquidConfig.js} +4 -4
- package/dist/constants/hyperLiquidConfig.js.map +1 -0
- package/dist/constants/index.d.ts +12 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +12 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/{myxConfig.d.mts → myxConfig.d.ts} +9 -8
- package/dist/constants/myxConfig.d.ts.map +1 -0
- package/dist/constants/{myxConfig.mjs → myxConfig.js} +2 -2
- package/dist/constants/myxConfig.js.map +1 -0
- package/dist/constants/{orderTypes.d.cts → orderTypes.d.ts} +7 -7
- package/dist/constants/orderTypes.d.ts.map +1 -0
- package/dist/constants/{orderTypes.mjs → orderTypes.js} +1 -1
- package/dist/constants/orderTypes.js.map +1 -0
- package/dist/constants/{performanceMetrics.d.cts → performanceMetrics.d.ts} +1 -1
- package/dist/constants/performanceMetrics.d.ts.map +1 -0
- package/dist/constants/{performanceMetrics.mjs → performanceMetrics.js} +1 -1
- package/dist/constants/performanceMetrics.js.map +1 -0
- package/dist/constants/{perpsConfig.d.mts → perpsConfig.d.ts} +56 -56
- package/dist/constants/perpsConfig.d.ts.map +1 -0
- package/dist/constants/{perpsConfig.mjs → perpsConfig.js} +1 -1
- package/dist/constants/perpsConfig.js.map +1 -0
- package/dist/constants/{transactionsHistoryConfig.d.cts → transactionsHistoryConfig.d.ts} +1 -1
- package/dist/constants/transactionsHistoryConfig.d.ts.map +1 -0
- package/dist/constants/{transactionsHistoryConfig.mjs → transactionsHistoryConfig.js} +1 -1
- package/dist/constants/transactionsHistoryConfig.js.map +1 -0
- package/dist/{index.d.mts → index.d.ts} +64 -64
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +41 -41
- package/dist/index.js.map +1 -0
- package/dist/perpsErrorCodes.d.ts +104 -0
- package/dist/perpsErrorCodes.d.ts.map +1 -0
- package/dist/{perpsErrorCodes.mjs → perpsErrorCodes.js} +1 -1
- package/dist/perpsErrorCodes.js.map +1 -0
- package/dist/providers/{AggregatedPerpsProvider.d.cts → AggregatedPerpsProvider.d.ts} +5 -5
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -0
- package/dist/providers/{AggregatedPerpsProvider.mjs → AggregatedPerpsProvider.js} +5 -5
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -0
- package/dist/providers/{HyperLiquidProvider.d.mts → HyperLiquidProvider.d.ts} +7 -7
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -0
- package/dist/providers/{HyperLiquidProvider.mjs → HyperLiquidProvider.js} +48 -50
- package/dist/providers/HyperLiquidProvider.js.map +1 -0
- package/dist/routing/{ProviderRouter.d.mts → ProviderRouter.d.ts} +2 -2
- package/dist/routing/ProviderRouter.d.ts.map +1 -0
- package/dist/routing/{ProviderRouter.mjs → ProviderRouter.js} +1 -1
- package/dist/routing/ProviderRouter.js.map +1 -0
- package/dist/routing/index.d.ts +6 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +5 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/{selectors.d.mts → selectors.d.ts} +97 -97
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +4 -4
- package/dist/selectors.js.map +1 -0
- package/dist/services/{AccountService.d.cts → AccountService.d.ts} +4 -4
- package/dist/services/AccountService.d.ts.map +1 -0
- package/dist/services/{AccountService.mjs → AccountService.js} +9 -9
- package/dist/services/AccountService.js.map +1 -0
- package/dist/services/{AggregatedOrderBookConnection.d.cts → AggregatedOrderBookConnection.d.ts} +2 -2
- package/dist/services/AggregatedOrderBookConnection.d.ts.map +1 -0
- package/dist/services/{AggregatedOrderBookConnection.mjs → AggregatedOrderBookConnection.js} +3 -3
- package/dist/services/AggregatedOrderBookConnection.js.map +1 -0
- package/dist/services/{DataLakeService.d.cts → DataLakeService.d.ts} +4 -4
- package/dist/services/DataLakeService.d.ts.map +1 -0
- package/dist/services/{DataLakeService.mjs → DataLakeService.js} +7 -7
- package/dist/services/DataLakeService.js.map +1 -0
- package/dist/services/{DepositService.d.cts → DepositService.d.ts} +4 -4
- package/dist/services/DepositService.d.ts.map +1 -0
- package/dist/services/{DepositService.mjs → DepositService.js} +7 -7
- package/dist/services/DepositService.js.map +1 -0
- package/dist/services/{DexDiscoveryCacheManager.d.cts → DexDiscoveryCacheManager.d.ts} +2 -2
- package/dist/services/DexDiscoveryCacheManager.d.ts.map +1 -0
- package/dist/services/{DexDiscoveryCacheManager.mjs → DexDiscoveryCacheManager.js} +2 -2
- package/dist/services/DexDiscoveryCacheManager.js.map +1 -0
- package/dist/services/{EligibilityService.d.cts → EligibilityService.d.ts} +2 -2
- package/dist/services/EligibilityService.d.ts.map +1 -0
- package/dist/services/{EligibilityService.mjs → EligibilityService.js} +3 -3
- package/dist/services/EligibilityService.js.map +1 -0
- package/dist/services/{FeatureFlagConfigurationService.d.cts → FeatureFlagConfigurationService.d.ts} +3 -3
- package/dist/services/FeatureFlagConfigurationService.d.ts.map +1 -0
- package/dist/services/{FeatureFlagConfigurationService.mjs → FeatureFlagConfigurationService.js} +7 -7
- package/dist/services/FeatureFlagConfigurationService.js.map +1 -0
- package/dist/services/{HyperLiquidClientService.d.cts → HyperLiquidClientService.d.ts} +10 -10
- package/dist/services/HyperLiquidClientService.d.ts.map +1 -0
- package/dist/services/{HyperLiquidClientService.mjs → HyperLiquidClientService.js} +11 -11
- package/dist/services/HyperLiquidClientService.js.map +1 -0
- package/dist/services/{HyperLiquidSubscriptionService.d.cts → HyperLiquidSubscriptionService.d.ts} +6 -6
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -0
- package/dist/services/{HyperLiquidSubscriptionService.mjs → HyperLiquidSubscriptionService.js} +12 -12
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -0
- package/dist/services/{HyperLiquidWalletService.d.cts → HyperLiquidWalletService.d.ts} +4 -4
- package/dist/services/HyperLiquidWalletService.d.ts.map +1 -0
- package/dist/services/{HyperLiquidWalletService.mjs → HyperLiquidWalletService.js} +5 -5
- package/dist/services/HyperLiquidWalletService.js.map +1 -0
- package/dist/services/{MarketDataService.d.cts → MarketDataService.d.ts} +5 -5
- package/dist/services/MarketDataService.d.ts.map +1 -0
- package/dist/services/{MarketDataService.mjs → MarketDataService.js} +9 -9
- package/dist/services/MarketDataService.js.map +1 -0
- package/dist/services/{RewardsIntegrationService.d.cts → RewardsIntegrationService.d.ts} +3 -3
- package/dist/services/RewardsIntegrationService.d.ts.map +1 -0
- package/dist/services/{RewardsIntegrationService.mjs → RewardsIntegrationService.js} +6 -6
- package/dist/services/RewardsIntegrationService.js.map +1 -0
- package/dist/services/{ServiceContext.d.cts → ServiceContext.d.ts} +3 -3
- package/dist/services/ServiceContext.d.ts.map +1 -0
- package/dist/services/ServiceContext.js +2 -0
- package/dist/services/ServiceContext.js.map +1 -0
- package/dist/services/{TerminalMarketService.d.cts → TerminalMarketService.d.ts} +2 -2
- package/dist/services/TerminalMarketService.d.ts.map +1 -0
- package/dist/services/{TerminalMarketService.mjs → TerminalMarketService.js} +9 -9
- package/dist/services/TerminalMarketService.js.map +1 -0
- package/dist/services/{TradingReadinessCache.d.mts → TradingReadinessCache.d.ts} +1 -1
- package/dist/services/TradingReadinessCache.d.ts.map +1 -0
- package/dist/services/{TradingReadinessCache.mjs → TradingReadinessCache.js} +1 -1
- package/dist/services/TradingReadinessCache.js.map +1 -0
- package/dist/services/{TradingService.d.cts → TradingService.d.ts} +4 -4
- package/dist/services/TradingService.d.ts.map +1 -0
- package/dist/services/{TradingService.mjs → TradingService.js} +10 -10
- package/dist/services/TradingService.js.map +1 -0
- package/dist/types/{config.d.cts → config.d.ts} +2 -2
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/{hyperliquid-types.d.cts → hyperliquid-types.d.ts} +6 -6
- package/dist/types/hyperliquid-types.d.ts.map +1 -0
- package/dist/types/{hyperliquid-types.mjs → hyperliquid-types.js} +1 -1
- package/dist/types/hyperliquid-types.js.map +1 -0
- package/dist/types/{index.d.cts → index.d.ts} +41 -41
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/{index.mjs → index.js} +3 -3
- package/dist/types/index.js.map +1 -0
- package/dist/types/{messenger.d.mts → messenger.d.ts} +11 -11
- package/dist/types/messenger.d.ts.map +1 -0
- package/dist/types/messenger.js +2 -0
- package/dist/types/messenger.js.map +1 -0
- package/dist/types/{myx-types.d.mts → myx-types.d.ts} +16 -16
- package/dist/types/myx-types.d.ts.map +1 -0
- package/dist/types/{myx-types.mjs → myx-types.js} +3 -3
- package/dist/types/myx-types.js.map +1 -0
- package/dist/types/{perps-types.d.cts → perps-types.d.ts} +4 -4
- package/dist/types/perps-types.d.ts.map +1 -0
- package/dist/types/perps-types.js +2 -0
- package/dist/types/perps-types.js.map +1 -0
- package/dist/types/{token.d.cts → token.d.ts} +2 -2
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +2 -0
- package/dist/types/token.js.map +1 -0
- package/dist/types/{transactionTypes.d.cts → transactionTypes.d.ts} +1 -1
- package/dist/types/transactionTypes.d.ts.map +1 -0
- package/dist/types/{transactionTypes.mjs → transactionTypes.js} +2 -2
- package/dist/types/transactionTypes.js.map +1 -0
- package/dist/utils/{accountUtils.d.cts → accountUtils.d.ts} +4 -4
- package/dist/utils/accountUtils.d.ts.map +1 -0
- package/dist/utils/{accountUtils.mjs → accountUtils.js} +2 -2
- package/dist/utils/accountUtils.js.map +1 -0
- package/dist/utils/{capabilitySymbols.d.mts → capabilitySymbols.d.ts} +1 -1
- package/dist/utils/capabilitySymbols.d.ts.map +1 -0
- package/dist/utils/{capabilitySymbols.mjs → capabilitySymbols.js} +1 -1
- package/dist/utils/capabilitySymbols.js.map +1 -0
- package/dist/utils/{coalescePerpsRestRequest.d.cts → coalescePerpsRestRequest.d.ts} +1 -1
- package/dist/utils/coalescePerpsRestRequest.d.ts.map +1 -0
- package/dist/utils/{coalescePerpsRestRequest.mjs → coalescePerpsRestRequest.js} +2 -2
- package/dist/utils/coalescePerpsRestRequest.js.map +1 -0
- package/dist/utils/{errorUtils.d.mts → errorUtils.d.ts} +1 -1
- package/dist/utils/errorUtils.d.ts.map +1 -0
- package/dist/utils/{errorUtils.mjs → errorUtils.js} +3 -3
- package/dist/utils/errorUtils.js.map +1 -0
- package/dist/utils/{hyperLiquidAbstraction.d.cts → hyperLiquidAbstraction.d.ts} +2 -2
- package/dist/utils/hyperLiquidAbstraction.d.ts.map +1 -0
- package/dist/utils/{hyperLiquidAbstraction.mjs → hyperLiquidAbstraction.js} +1 -1
- package/dist/utils/hyperLiquidAbstraction.js.map +1 -0
- package/dist/utils/{hyperLiquidAdapter.d.cts → hyperLiquidAdapter.d.ts} +4 -4
- package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -0
- package/dist/utils/{hyperLiquidAdapter.mjs → hyperLiquidAdapter.js} +9 -9
- package/dist/utils/hyperLiquidAdapter.js.map +1 -0
- package/dist/utils/{hyperLiquidOrderBookProcessor.d.mts → hyperLiquidOrderBookProcessor.d.ts} +3 -3
- package/dist/utils/hyperLiquidOrderBookProcessor.d.ts.map +1 -0
- package/dist/utils/{hyperLiquidOrderBookProcessor.mjs → hyperLiquidOrderBookProcessor.js} +1 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.js.map +1 -0
- package/dist/utils/{hyperLiquidValidation.d.cts → hyperLiquidValidation.d.ts} +4 -4
- package/dist/utils/hyperLiquidValidation.d.ts.map +1 -0
- package/dist/utils/{hyperLiquidValidation.mjs → hyperLiquidValidation.js} +6 -6
- package/dist/utils/hyperLiquidValidation.js.map +1 -0
- package/dist/utils/{idUtils.d.cts → idUtils.d.ts} +1 -1
- package/dist/utils/idUtils.d.ts.map +1 -0
- package/dist/utils/{idUtils.mjs → idUtils.js} +2 -2
- package/dist/utils/idUtils.js.map +1 -0
- package/dist/utils/index.d.ts +28 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/{index.mjs → index.js} +21 -21
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/{marketDataTransform.d.cts → marketDataTransform.d.ts} +3 -3
- package/dist/utils/marketDataTransform.d.ts.map +1 -0
- package/dist/utils/{marketDataTransform.mjs → marketDataTransform.js} +5 -5
- package/dist/utils/marketDataTransform.js.map +1 -0
- package/dist/utils/{marketSearch.d.cts → marketSearch.d.ts} +2 -2
- package/dist/utils/marketSearch.d.ts.map +1 -0
- package/dist/utils/{marketSearch.mjs → marketSearch.js} +1 -1
- package/dist/utils/marketSearch.js.map +1 -0
- package/dist/utils/{marketUtils.d.cts → marketUtils.d.ts} +3 -3
- package/dist/utils/marketUtils.d.ts.map +1 -0
- package/dist/utils/{marketUtils.mjs → marketUtils.js} +2 -2
- package/dist/utils/marketUtils.js.map +1 -0
- package/dist/utils/{myxAdapter.d.cts → myxAdapter.d.ts} +3 -3
- package/dist/utils/myxAdapter.d.ts.map +1 -0
- package/dist/utils/{myxAdapter.mjs → myxAdapter.js} +3 -3
- package/dist/utils/myxAdapter.js.map +1 -0
- package/dist/utils/{orderCalculations.d.cts → orderCalculations.d.ts} +4 -4
- package/dist/utils/orderCalculations.d.ts.map +1 -0
- package/dist/utils/{orderCalculations.mjs → orderCalculations.js} +6 -6
- package/dist/utils/orderCalculations.js.map +1 -0
- package/dist/utils/{orderTypes.d.mts → orderTypes.d.ts} +3 -3
- package/dist/utils/orderTypes.d.ts.map +1 -0
- package/dist/utils/{orderTypes.mjs → orderTypes.js} +1 -1
- package/dist/utils/orderTypes.js.map +1 -0
- package/dist/utils/{perpsConnectionAttemptContext.d.mts → perpsConnectionAttemptContext.d.ts} +1 -1
- package/dist/utils/perpsConnectionAttemptContext.d.ts.map +1 -0
- package/dist/utils/{perpsConnectionAttemptContext.mjs → perpsConnectionAttemptContext.js} +1 -1
- package/dist/utils/perpsConnectionAttemptContext.js.map +1 -0
- package/dist/utils/{perpsDiskPersistence.d.cts → perpsDiskPersistence.d.ts} +2 -2
- package/dist/utils/perpsDiskPersistence.d.ts.map +1 -0
- package/dist/utils/{perpsDiskPersistence.mjs → perpsDiskPersistence.js} +2 -2
- package/dist/utils/perpsDiskPersistence.js.map +1 -0
- package/dist/utils/{perpsFormatters.d.cts → perpsFormatters.d.ts} +1 -1
- package/dist/utils/perpsFormatters.d.ts.map +1 -0
- package/dist/utils/{perpsFormatters.mjs → perpsFormatters.js} +2 -2
- package/dist/utils/perpsFormatters.js.map +1 -0
- package/dist/utils/{rewardsUtils.d.cts → rewardsUtils.d.ts} +4 -4
- package/dist/utils/rewardsUtils.d.ts.map +1 -0
- package/dist/utils/{rewardsUtils.mjs → rewardsUtils.js} +4 -4
- package/dist/utils/rewardsUtils.js.map +1 -0
- package/dist/utils/{significantFigures.d.cts → significantFigures.d.ts} +1 -1
- package/dist/utils/significantFigures.d.ts.map +1 -0
- package/dist/utils/{significantFigures.mjs → significantFigures.js} +2 -2
- package/dist/utils/significantFigures.js.map +1 -0
- package/dist/utils/{sortMarkets.d.cts → sortMarkets.d.ts} +2 -2
- package/dist/utils/sortMarkets.d.ts.map +1 -0
- package/dist/utils/{sortMarkets.mjs → sortMarkets.js} +2 -2
- package/dist/utils/sortMarkets.js.map +1 -0
- package/dist/utils/{standaloneInfoClient.d.cts → standaloneInfoClient.d.ts} +3 -3
- package/dist/utils/standaloneInfoClient.d.ts.map +1 -0
- package/dist/utils/{standaloneInfoClient.mjs → standaloneInfoClient.js} +3 -3
- package/dist/utils/standaloneInfoClient.js.map +1 -0
- package/dist/utils/{stringParseUtils.d.cts → stringParseUtils.d.ts} +1 -1
- package/dist/utils/stringParseUtils.d.ts.map +1 -0
- package/dist/utils/{stringParseUtils.mjs → stringParseUtils.js} +1 -1
- package/dist/utils/stringParseUtils.js.map +1 -0
- package/dist/utils/{transferData.d.cts → transferData.d.ts} +1 -1
- package/dist/utils/transferData.d.ts.map +1 -0
- package/dist/utils/{transferData.mjs → transferData.js} +3 -3
- package/dist/utils/transferData.js.map +1 -0
- package/dist/utils/{wait.d.cts → wait.d.ts} +1 -1
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/{wait.mjs → wait.js} +1 -1
- package/dist/utils/wait.js.map +1 -0
- package/package.json +20 -48
- package/dist/PerpsController-method-action-types.cjs +0 -7
- package/dist/PerpsController-method-action-types.cjs.map +0 -1
- package/dist/PerpsController-method-action-types.d.cts +0 -1163
- package/dist/PerpsController-method-action-types.d.cts.map +0 -1
- package/dist/PerpsController-method-action-types.d.mts.map +0 -1
- package/dist/PerpsController-method-action-types.mjs.map +0 -1
- package/dist/PerpsController.cjs +0 -5063
- package/dist/PerpsController.cjs.map +0 -1
- package/dist/PerpsController.d.cts +0 -1274
- package/dist/PerpsController.d.cts.map +0 -1
- package/dist/PerpsController.d.mts.map +0 -1
- package/dist/PerpsController.mjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -441
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -171
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
- package/dist/aggregation/index.cjs +0 -9
- package/dist/aggregation/index.cjs.map +0 -1
- package/dist/aggregation/index.d.cts +0 -6
- package/dist/aggregation/index.d.cts.map +0 -1
- package/dist/aggregation/index.d.mts +0 -6
- package/dist/aggregation/index.d.mts.map +0 -1
- package/dist/aggregation/index.mjs +0 -5
- package/dist/aggregation/index.mjs.map +0 -1
- package/dist/constants/chartConfig.cjs +0 -239
- package/dist/constants/chartConfig.cjs.map +0 -1
- package/dist/constants/chartConfig.d.cts +0 -228
- package/dist/constants/chartConfig.d.cts.map +0 -1
- package/dist/constants/chartConfig.d.mts.map +0 -1
- package/dist/constants/chartConfig.mjs.map +0 -1
- package/dist/constants/eventNames.cjs +0 -650
- package/dist/constants/eventNames.cjs.map +0 -1
- package/dist/constants/eventNames.d.cts +0 -555
- package/dist/constants/eventNames.d.cts.map +0 -1
- package/dist/constants/eventNames.d.mts +0 -555
- package/dist/constants/eventNames.d.mts.map +0 -1
- package/dist/constants/eventNames.mjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.cjs +0 -607
- package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.mts +0 -280
- package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
- package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
- package/dist/constants/index.cjs +0 -28
- package/dist/constants/index.cjs.map +0 -1
- package/dist/constants/index.d.cts +0 -12
- package/dist/constants/index.d.cts.map +0 -1
- package/dist/constants/index.d.mts +0 -12
- package/dist/constants/index.d.mts.map +0 -1
- package/dist/constants/index.mjs +0 -12
- package/dist/constants/index.mjs.map +0 -1
- 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.map +0 -1
- package/dist/constants/myxConfig.mjs.map +0 -1
- package/dist/constants/orderTypes.cjs +0 -31
- package/dist/constants/orderTypes.cjs.map +0 -1
- package/dist/constants/orderTypes.d.cts.map +0 -1
- package/dist/constants/orderTypes.d.mts +0 -19
- package/dist/constants/orderTypes.d.mts.map +0 -1
- package/dist/constants/orderTypes.mjs.map +0 -1
- package/dist/constants/performanceMetrics.cjs +0 -63
- package/dist/constants/performanceMetrics.cjs.map +0 -1
- package/dist/constants/performanceMetrics.d.cts.map +0 -1
- package/dist/constants/performanceMetrics.d.mts +0 -46
- package/dist/constants/performanceMetrics.d.mts.map +0 -1
- package/dist/constants/performanceMetrics.mjs.map +0 -1
- package/dist/constants/perpsConfig.cjs +0 -553
- package/dist/constants/perpsConfig.cjs.map +0 -1
- package/dist/constants/perpsConfig.d.cts +0 -474
- package/dist/constants/perpsConfig.d.cts.map +0 -1
- package/dist/constants/perpsConfig.d.mts.map +0 -1
- package/dist/constants/perpsConfig.mjs.map +0 -1
- package/dist/constants/transactionsHistoryConfig.cjs +0 -38
- package/dist/constants/transactionsHistoryConfig.cjs.map +0 -1
- package/dist/constants/transactionsHistoryConfig.d.cts.map +0 -1
- package/dist/constants/transactionsHistoryConfig.d.mts +0 -35
- package/dist/constants/transactionsHistoryConfig.d.mts.map +0 -1
- package/dist/constants/transactionsHistoryConfig.mjs.map +0 -1
- package/dist/index.cjs +0 -344
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -92
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/perpsErrorCodes.cjs +0 -127
- package/dist/perpsErrorCodes.cjs.map +0 -1
- package/dist/perpsErrorCodes.d.cts +0 -104
- package/dist/perpsErrorCodes.d.cts.map +0 -1
- package/dist/perpsErrorCodes.d.mts +0 -104
- package/dist/perpsErrorCodes.d.mts.map +0 -1
- package/dist/perpsErrorCodes.mjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +0 -689
- package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +0 -232
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.cjs +0 -10416
- package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -625
- package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
- package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
- package/dist/routing/ProviderRouter.cjs +0 -154
- package/dist/routing/ProviderRouter.cjs.map +0 -1
- package/dist/routing/ProviderRouter.d.cts +0 -112
- package/dist/routing/ProviderRouter.d.cts.map +0 -1
- package/dist/routing/ProviderRouter.d.mts.map +0 -1
- package/dist/routing/ProviderRouter.mjs.map +0 -1
- package/dist/routing/index.cjs +0 -9
- package/dist/routing/index.cjs.map +0 -1
- package/dist/routing/index.d.cts +0 -6
- package/dist/routing/index.d.cts.map +0 -1
- package/dist/routing/index.d.mts +0 -6
- package/dist/routing/index.d.mts.map +0 -1
- package/dist/routing/index.mjs +0 -5
- package/dist/routing/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -264
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -336
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/AccountService.cjs +0 -324
- package/dist/services/AccountService.cjs.map +0 -1
- package/dist/services/AccountService.d.cts.map +0 -1
- package/dist/services/AccountService.d.mts +0 -56
- package/dist/services/AccountService.d.mts.map +0 -1
- package/dist/services/AccountService.mjs.map +0 -1
- package/dist/services/AggregatedOrderBookConnection.cjs +0 -405
- package/dist/services/AggregatedOrderBookConnection.cjs.map +0 -1
- package/dist/services/AggregatedOrderBookConnection.d.cts.map +0 -1
- package/dist/services/AggregatedOrderBookConnection.d.mts +0 -106
- package/dist/services/AggregatedOrderBookConnection.d.mts.map +0 -1
- package/dist/services/AggregatedOrderBookConnection.mjs.map +0 -1
- package/dist/services/DataLakeService.cjs +0 -233
- package/dist/services/DataLakeService.cjs.map +0 -1
- package/dist/services/DataLakeService.d.cts.map +0 -1
- package/dist/services/DataLakeService.d.mts +0 -51
- package/dist/services/DataLakeService.d.mts.map +0 -1
- package/dist/services/DataLakeService.mjs.map +0 -1
- package/dist/services/DepositService.cjs +0 -99
- package/dist/services/DepositService.cjs.map +0 -1
- package/dist/services/DepositService.d.cts.map +0 -1
- package/dist/services/DepositService.d.mts +0 -39
- package/dist/services/DepositService.d.mts.map +0 -1
- package/dist/services/DepositService.mjs.map +0 -1
- package/dist/services/DexDiscoveryCacheManager.cjs +0 -147
- package/dist/services/DexDiscoveryCacheManager.cjs.map +0 -1
- package/dist/services/DexDiscoveryCacheManager.d.cts.map +0 -1
- package/dist/services/DexDiscoveryCacheManager.d.mts +0 -52
- package/dist/services/DexDiscoveryCacheManager.d.mts.map +0 -1
- package/dist/services/DexDiscoveryCacheManager.mjs.map +0 -1
- package/dist/services/EligibilityService.cjs +0 -78
- package/dist/services/EligibilityService.cjs.map +0 -1
- package/dist/services/EligibilityService.d.cts.map +0 -1
- package/dist/services/EligibilityService.d.mts +0 -28
- package/dist/services/EligibilityService.d.mts.map +0 -1
- package/dist/services/EligibilityService.mjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.cjs +0 -257
- package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.mts +0 -73
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
- package/dist/services/HyperLiquidClientService.cjs +0 -1045
- package/dist/services/HyperLiquidClientService.cjs.map +0 -1
- package/dist/services/HyperLiquidClientService.d.cts.map +0 -1
- package/dist/services/HyperLiquidClientService.d.mts +0 -239
- package/dist/services/HyperLiquidClientService.d.mts.map +0 -1
- package/dist/services/HyperLiquidClientService.mjs.map +0 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +0 -3196
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +0 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +0 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -227
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +0 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +0 -1
- package/dist/services/HyperLiquidWalletService.cjs +0 -186
- package/dist/services/HyperLiquidWalletService.cjs.map +0 -1
- package/dist/services/HyperLiquidWalletService.d.cts.map +0 -1
- package/dist/services/HyperLiquidWalletService.d.mts +0 -84
- package/dist/services/HyperLiquidWalletService.d.mts.map +0 -1
- package/dist/services/HyperLiquidWalletService.mjs.map +0 -1
- package/dist/services/MarketDataService.cjs +0 -1138
- package/dist/services/MarketDataService.cjs.map +0 -1
- package/dist/services/MarketDataService.d.cts.map +0 -1
- package/dist/services/MarketDataService.d.mts +0 -334
- package/dist/services/MarketDataService.d.mts.map +0 -1
- package/dist/services/MarketDataService.mjs.map +0 -1
- package/dist/services/RewardsIntegrationService.cjs +0 -391
- package/dist/services/RewardsIntegrationService.cjs.map +0 -1
- package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
- package/dist/services/RewardsIntegrationService.d.mts +0 -84
- package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
- package/dist/services/RewardsIntegrationService.mjs.map +0 -1
- package/dist/services/ServiceContext.cjs +0 -3
- package/dist/services/ServiceContext.cjs.map +0 -1
- package/dist/services/ServiceContext.d.cts.map +0 -1
- package/dist/services/ServiceContext.d.mts +0 -102
- package/dist/services/ServiceContext.d.mts.map +0 -1
- package/dist/services/ServiceContext.mjs +0 -2
- package/dist/services/ServiceContext.mjs.map +0 -1
- package/dist/services/TerminalMarketService.cjs +0 -623
- package/dist/services/TerminalMarketService.cjs.map +0 -1
- package/dist/services/TerminalMarketService.d.cts.map +0 -1
- package/dist/services/TerminalMarketService.d.mts +0 -45
- package/dist/services/TerminalMarketService.d.mts.map +0 -1
- package/dist/services/TerminalMarketService.mjs.map +0 -1
- package/dist/services/TradingReadinessCache.cjs +0 -329
- package/dist/services/TradingReadinessCache.cjs.map +0 -1
- package/dist/services/TradingReadinessCache.d.cts +0 -204
- package/dist/services/TradingReadinessCache.d.cts.map +0 -1
- package/dist/services/TradingReadinessCache.d.mts.map +0 -1
- package/dist/services/TradingReadinessCache.mjs.map +0 -1
- package/dist/services/TradingService.cjs +0 -1865
- package/dist/services/TradingService.cjs.map +0 -1
- package/dist/services/TradingService.d.cts.map +0 -1
- package/dist/services/TradingService.d.mts +0 -201
- package/dist/services/TradingService.d.mts.map +0 -1
- package/dist/services/TradingService.mjs.map +0 -1
- package/dist/types/config.cjs +0 -3
- package/dist/types/config.cjs.map +0 -1
- package/dist/types/config.d.cts.map +0 -1
- package/dist/types/config.d.mts +0 -49
- package/dist/types/config.d.mts.map +0 -1
- package/dist/types/config.mjs +0 -2
- package/dist/types/config.mjs.map +0 -1
- package/dist/types/hyperliquid-types.cjs +0 -45
- package/dist/types/hyperliquid-types.cjs.map +0 -1
- package/dist/types/hyperliquid-types.d.cts.map +0 -1
- package/dist/types/hyperliquid-types.d.mts +0 -67
- package/dist/types/hyperliquid-types.d.mts.map +0 -1
- package/dist/types/hyperliquid-types.mjs.map +0 -1
- package/dist/types/index.cjs +0 -151
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -1951
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/messenger.cjs +0 -3
- package/dist/types/messenger.cjs.map +0 -1
- package/dist/types/messenger.d.cts +0 -30
- package/dist/types/messenger.d.cts.map +0 -1
- package/dist/types/messenger.d.mts.map +0 -1
- package/dist/types/messenger.mjs +0 -2
- package/dist/types/messenger.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.map +0 -1
- package/dist/types/myx-types.mjs.map +0 -1
- package/dist/types/perps-types.cjs +0 -7
- package/dist/types/perps-types.cjs.map +0 -1
- package/dist/types/perps-types.d.cts.map +0 -1
- package/dist/types/perps-types.d.mts +0 -184
- package/dist/types/perps-types.d.mts.map +0 -1
- package/dist/types/perps-types.mjs +0 -5
- package/dist/types/perps-types.mjs.map +0 -1
- package/dist/types/token.cjs +0 -3
- package/dist/types/token.cjs.map +0 -1
- package/dist/types/token.d.cts.map +0 -1
- package/dist/types/token.d.mts +0 -25
- package/dist/types/token.d.mts.map +0 -1
- package/dist/types/token.mjs +0 -2
- package/dist/types/token.mjs.map +0 -1
- package/dist/types/transactionTypes.cjs +0 -29
- package/dist/types/transactionTypes.cjs.map +0 -1
- package/dist/types/transactionTypes.d.cts.map +0 -1
- package/dist/types/transactionTypes.d.mts +0 -60
- package/dist/types/transactionTypes.d.mts.map +0 -1
- package/dist/types/transactionTypes.mjs.map +0 -1
- package/dist/utils/accountUtils.cjs +0 -236
- package/dist/utils/accountUtils.cjs.map +0 -1
- package/dist/utils/accountUtils.d.cts.map +0 -1
- package/dist/utils/accountUtils.d.mts +0 -72
- package/dist/utils/accountUtils.d.mts.map +0 -1
- package/dist/utils/accountUtils.mjs.map +0 -1
- package/dist/utils/capabilitySymbols.cjs +0 -25
- package/dist/utils/capabilitySymbols.cjs.map +0 -1
- package/dist/utils/capabilitySymbols.d.cts +0 -15
- package/dist/utils/capabilitySymbols.d.cts.map +0 -1
- package/dist/utils/capabilitySymbols.d.mts.map +0 -1
- package/dist/utils/capabilitySymbols.mjs.map +0 -1
- package/dist/utils/coalescePerpsRestRequest.cjs +0 -71
- package/dist/utils/coalescePerpsRestRequest.cjs.map +0 -1
- package/dist/utils/coalescePerpsRestRequest.d.cts.map +0 -1
- package/dist/utils/coalescePerpsRestRequest.d.mts +0 -32
- package/dist/utils/coalescePerpsRestRequest.d.mts.map +0 -1
- package/dist/utils/coalescePerpsRestRequest.mjs.map +0 -1
- package/dist/utils/errorUtils.cjs +0 -104
- package/dist/utils/errorUtils.cjs.map +0 -1
- package/dist/utils/errorUtils.d.cts +0 -50
- package/dist/utils/errorUtils.d.cts.map +0 -1
- package/dist/utils/errorUtils.d.mts.map +0 -1
- package/dist/utils/errorUtils.mjs.map +0 -1
- package/dist/utils/hyperLiquidAbstraction.cjs +0 -23
- package/dist/utils/hyperLiquidAbstraction.cjs.map +0 -1
- package/dist/utils/hyperLiquidAbstraction.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAbstraction.d.mts +0 -11
- package/dist/utils/hyperLiquidAbstraction.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAbstraction.mjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.cjs +0 -512
- package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +0 -77
- package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -83
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -55
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.cjs +0 -799
- package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.mts +0 -192
- package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
- package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
- package/dist/utils/idUtils.cjs +0 -18
- package/dist/utils/idUtils.cjs.map +0 -1
- package/dist/utils/idUtils.d.cts.map +0 -1
- package/dist/utils/idUtils.d.mts +0 -6
- package/dist/utils/idUtils.d.mts.map +0 -1
- package/dist/utils/idUtils.mjs.map +0 -1
- package/dist/utils/index.cjs +0 -65
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts +0 -28
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.mts +0 -28
- package/dist/utils/index.d.mts.map +0 -1
- package/dist/utils/index.mjs.map +0 -1
- package/dist/utils/marketDataTransform.cjs +0 -250
- package/dist/utils/marketDataTransform.cjs.map +0 -1
- package/dist/utils/marketDataTransform.d.cts.map +0 -1
- package/dist/utils/marketDataTransform.d.mts +0 -71
- package/dist/utils/marketDataTransform.d.mts.map +0 -1
- package/dist/utils/marketDataTransform.mjs.map +0 -1
- package/dist/utils/marketSearch.cjs +0 -111
- package/dist/utils/marketSearch.cjs.map +0 -1
- package/dist/utils/marketSearch.d.cts.map +0 -1
- package/dist/utils/marketSearch.d.mts +0 -48
- package/dist/utils/marketSearch.d.mts.map +0 -1
- package/dist/utils/marketSearch.mjs.map +0 -1
- package/dist/utils/marketUtils.cjs +0 -266
- package/dist/utils/marketUtils.cjs.map +0 -1
- package/dist/utils/marketUtils.d.cts.map +0 -1
- package/dist/utils/marketUtils.d.mts +0 -73
- package/dist/utils/marketUtils.d.mts.map +0 -1
- package/dist/utils/marketUtils.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.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.map +0 -1
- package/dist/utils/orderCalculations.cjs +0 -823
- package/dist/utils/orderCalculations.cjs.map +0 -1
- package/dist/utils/orderCalculations.d.cts.map +0 -1
- package/dist/utils/orderCalculations.d.mts +0 -298
- package/dist/utils/orderCalculations.d.mts.map +0 -1
- package/dist/utils/orderCalculations.mjs.map +0 -1
- package/dist/utils/orderTypes.cjs +0 -301
- package/dist/utils/orderTypes.cjs.map +0 -1
- package/dist/utils/orderTypes.d.cts +0 -166
- package/dist/utils/orderTypes.d.cts.map +0 -1
- package/dist/utils/orderTypes.d.mts.map +0 -1
- package/dist/utils/orderTypes.mjs.map +0 -1
- package/dist/utils/perpsConnectionAttemptContext.cjs +0 -20
- package/dist/utils/perpsConnectionAttemptContext.cjs.map +0 -1
- package/dist/utils/perpsConnectionAttemptContext.d.cts +0 -7
- package/dist/utils/perpsConnectionAttemptContext.d.cts.map +0 -1
- package/dist/utils/perpsConnectionAttemptContext.d.mts.map +0 -1
- package/dist/utils/perpsConnectionAttemptContext.mjs.map +0 -1
- package/dist/utils/perpsDiskPersistence.cjs +0 -259
- package/dist/utils/perpsDiskPersistence.cjs.map +0 -1
- package/dist/utils/perpsDiskPersistence.d.cts.map +0 -1
- package/dist/utils/perpsDiskPersistence.d.mts +0 -112
- package/dist/utils/perpsDiskPersistence.d.mts.map +0 -1
- package/dist/utils/perpsDiskPersistence.mjs.map +0 -1
- package/dist/utils/perpsFormatters.cjs +0 -509
- package/dist/utils/perpsFormatters.cjs.map +0 -1
- package/dist/utils/perpsFormatters.d.cts.map +0 -1
- package/dist/utils/perpsFormatters.d.mts +0 -204
- package/dist/utils/perpsFormatters.d.mts.map +0 -1
- package/dist/utils/perpsFormatters.mjs.map +0 -1
- package/dist/utils/rewardsUtils.cjs +0 -98
- package/dist/utils/rewardsUtils.cjs.map +0 -1
- package/dist/utils/rewardsUtils.d.cts.map +0 -1
- package/dist/utils/rewardsUtils.d.mts +0 -33
- package/dist/utils/rewardsUtils.d.mts.map +0 -1
- package/dist/utils/rewardsUtils.mjs.map +0 -1
- package/dist/utils/significantFigures.cjs +0 -88
- package/dist/utils/significantFigures.cjs.map +0 -1
- package/dist/utils/significantFigures.d.cts.map +0 -1
- package/dist/utils/significantFigures.d.mts +0 -25
- package/dist/utils/significantFigures.d.mts.map +0 -1
- package/dist/utils/significantFigures.mjs.map +0 -1
- package/dist/utils/sortMarkets.cjs +0 -93
- package/dist/utils/sortMarkets.cjs.map +0 -1
- package/dist/utils/sortMarkets.d.cts.map +0 -1
- package/dist/utils/sortMarkets.d.mts +0 -25
- package/dist/utils/sortMarkets.d.mts.map +0 -1
- package/dist/utils/sortMarkets.mjs.map +0 -1
- package/dist/utils/standaloneInfoClient.cjs +0 -70
- package/dist/utils/standaloneInfoClient.cjs.map +0 -1
- package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
- package/dist/utils/standaloneInfoClient.d.mts +0 -37
- package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
- package/dist/utils/standaloneInfoClient.mjs.map +0 -1
- package/dist/utils/stringParseUtils.cjs +0 -34
- package/dist/utils/stringParseUtils.cjs.map +0 -1
- package/dist/utils/stringParseUtils.d.cts.map +0 -1
- package/dist/utils/stringParseUtils.d.mts +0 -11
- package/dist/utils/stringParseUtils.d.mts.map +0 -1
- package/dist/utils/stringParseUtils.mjs.map +0 -1
- package/dist/utils/transferData.cjs +0 -33
- package/dist/utils/transferData.cjs.map +0 -1
- package/dist/utils/transferData.d.cts.map +0 -1
- package/dist/utils/transferData.d.mts +0 -9
- package/dist/utils/transferData.d.mts.map +0 -1
- package/dist/utils/transferData.mjs.map +0 -1
- package/dist/utils/wait.cjs +0 -6
- package/dist/utils/wait.cjs.map +0 -1
- package/dist/utils/wait.d.cts.map +0 -1
- package/dist/utils/wait.d.mts +0 -2
- package/dist/utils/wait.d.mts.map +0 -1
- package/dist/utils/wait.mjs.map +0 -1
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.aggregateAccountStates = exports.addSpotBalanceToAccountState = exports.getSpotHold = exports.getSpotBalance = exports.calculateWeightedReturnOnEquity = exports.getSelectedEvmAccountFromMessenger = exports.getSelectedEvmAccountDetailsFromMessenger = exports.getSelectedEvmAccount = exports.getEvmAccountFromAccountGroup = exports.findEvmAccount = void 0;
|
|
4
|
-
const perpsConfig_js_1 = require("../constants/perpsConfig.cjs");
|
|
5
|
-
const EVM_ACCOUNT_TYPES = new Set(['eip155:eoa', 'eip155:erc4337']);
|
|
6
|
-
function isEvmAccountType(type) {
|
|
7
|
-
return EVM_ACCOUNT_TYPES.has(type);
|
|
8
|
-
}
|
|
9
|
-
function findEvmAccount(accounts) {
|
|
10
|
-
const evmAccount = accounts.find((account) => account && isEvmAccountType(account.type));
|
|
11
|
-
return evmAccount ?? null;
|
|
12
|
-
}
|
|
13
|
-
exports.findEvmAccount = findEvmAccount;
|
|
14
|
-
function getEvmAccountFromAccountGroup(accounts) {
|
|
15
|
-
const evmAccount = findEvmAccount(accounts);
|
|
16
|
-
return evmAccount ? { address: evmAccount.address } : undefined;
|
|
17
|
-
}
|
|
18
|
-
exports.getEvmAccountFromAccountGroup = getEvmAccountFromAccountGroup;
|
|
19
|
-
function getSelectedEvmAccount(accounts) {
|
|
20
|
-
return getEvmAccountFromAccountGroup(accounts);
|
|
21
|
-
}
|
|
22
|
-
exports.getSelectedEvmAccount = getSelectedEvmAccount;
|
|
23
|
-
function isAccountLike(value) {
|
|
24
|
-
const account = value;
|
|
25
|
-
return (typeof value === 'object' &&
|
|
26
|
-
value !== null &&
|
|
27
|
-
typeof account?.address === 'string' &&
|
|
28
|
-
typeof account.type === 'string');
|
|
29
|
-
}
|
|
30
|
-
function getSelectedEvmAccountDetailsFromMessenger(messenger) {
|
|
31
|
-
try {
|
|
32
|
-
const selectedAccount = messenger.call('AccountsController:getSelectedAccount');
|
|
33
|
-
if (isAccountLike(selectedAccount)) {
|
|
34
|
-
const evmAccount = findEvmAccount([selectedAccount]);
|
|
35
|
-
if (evmAccount) {
|
|
36
|
-
return evmAccount;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// Fall back to the selected account group if the direct lookup is unavailable.
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const selectedAccountGroup = messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
45
|
-
return Array.isArray(selectedAccountGroup)
|
|
46
|
-
? (findEvmAccount(selectedAccountGroup.filter(isAccountLike)) ??
|
|
47
|
-
undefined)
|
|
48
|
-
: undefined;
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.getSelectedEvmAccountDetailsFromMessenger = getSelectedEvmAccountDetailsFromMessenger;
|
|
55
|
-
function getSelectedEvmAccountFromMessenger(messenger) {
|
|
56
|
-
const evmAccount = getSelectedEvmAccountDetailsFromMessenger(messenger);
|
|
57
|
-
return evmAccount ? { address: evmAccount.address } : undefined;
|
|
58
|
-
}
|
|
59
|
-
exports.getSelectedEvmAccountFromMessenger = getSelectedEvmAccountFromMessenger;
|
|
60
|
-
function calculateWeightedReturnOnEquity(accounts) {
|
|
61
|
-
if (accounts.length === 0) {
|
|
62
|
-
return '0';
|
|
63
|
-
}
|
|
64
|
-
let totalWeightedROE = 0;
|
|
65
|
-
let totalMarginUsed = 0;
|
|
66
|
-
for (const account of accounts) {
|
|
67
|
-
const unrealizedPnl = typeof account.unrealizedPnl === 'string'
|
|
68
|
-
? Number.parseFloat(account.unrealizedPnl)
|
|
69
|
-
: account.unrealizedPnl;
|
|
70
|
-
const returnOnEquity = typeof account.returnOnEquity === 'string'
|
|
71
|
-
? Number.parseFloat(account.returnOnEquity)
|
|
72
|
-
: account.returnOnEquity;
|
|
73
|
-
if (Number.isNaN(unrealizedPnl) || Number.isNaN(returnOnEquity)) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (returnOnEquity === 0) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const marginUsed = (unrealizedPnl / returnOnEquity) * 100;
|
|
80
|
-
if (Number.isNaN(marginUsed) || marginUsed <= 0) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
const roeDecimal = returnOnEquity / 100;
|
|
84
|
-
totalWeightedROE += roeDecimal * marginUsed;
|
|
85
|
-
totalMarginUsed += marginUsed;
|
|
86
|
-
}
|
|
87
|
-
if (totalMarginUsed <= 0) {
|
|
88
|
-
return '0';
|
|
89
|
-
}
|
|
90
|
-
const weightedROE = (totalWeightedROE / totalMarginUsed) * 100;
|
|
91
|
-
return weightedROE.toString();
|
|
92
|
-
}
|
|
93
|
-
exports.calculateWeightedReturnOnEquity = calculateWeightedReturnOnEquity;
|
|
94
|
-
// The release-branch balance bridge is USDC-only. Non-USDC spot assets must
|
|
95
|
-
// not inflate the balances shown or validated by withdraw/payment flows.
|
|
96
|
-
const SPOT_COLLATERAL_COINS = new Set(['USDC']);
|
|
97
|
-
function getSpotBalance(spotState) {
|
|
98
|
-
if (!spotState?.balances || !Array.isArray(spotState.balances)) {
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
return spotState.balances.reduce((sum, balance) => {
|
|
102
|
-
if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {
|
|
103
|
-
return sum;
|
|
104
|
-
}
|
|
105
|
-
const value = parseFloat(balance.total ?? '0');
|
|
106
|
-
return Number.isFinite(value) ? sum + value : sum;
|
|
107
|
-
}, 0);
|
|
108
|
-
}
|
|
109
|
-
exports.getSpotBalance = getSpotBalance;
|
|
110
|
-
function getSpotHold(spotState) {
|
|
111
|
-
if (!spotState?.balances || !Array.isArray(spotState.balances)) {
|
|
112
|
-
return 0;
|
|
113
|
-
}
|
|
114
|
-
return spotState.balances.reduce((sum, balance) => {
|
|
115
|
-
if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {
|
|
116
|
-
return sum;
|
|
117
|
-
}
|
|
118
|
-
const value = parseFloat(balance.hold ?? '0');
|
|
119
|
-
return Number.isFinite(value) ? sum + value : sum;
|
|
120
|
-
}, 0);
|
|
121
|
-
}
|
|
122
|
-
exports.getSpotHold = getSpotHold;
|
|
123
|
-
/**
|
|
124
|
-
* Add spot USDC to the AccountState contract. Caller decides whether the
|
|
125
|
-
* spot balance counts as perps collateral via `options.foldIntoCollateral`
|
|
126
|
-
* — the util stays provider-agnostic.
|
|
127
|
-
*
|
|
128
|
-
* @param accountState - Base AccountState produced by a provider adapter.
|
|
129
|
-
* @param spotState - Raw spot clearinghouse response (HL-shaped); null or missing means no spot balance and the state is returned unchanged.
|
|
130
|
-
* @param options - See {@link AddSpotBalanceOptions}.
|
|
131
|
-
* @returns AccountState with spot folded into `totalBalance` always, and into spendable/withdrawable when `foldIntoCollateral` is true.
|
|
132
|
-
*/
|
|
133
|
-
function addSpotBalanceToAccountState(accountState, spotState, options) {
|
|
134
|
-
// Fail-closed default: align with `hyperLiquidModeFoldsSpot(null) → false`.
|
|
135
|
-
// A caller that omits `options` should NOT silently fold spot — that would
|
|
136
|
-
// over-report withdrawable funds for Standard / dexAbstraction users.
|
|
137
|
-
const foldIntoCollateral = options?.foldIntoCollateral ?? false;
|
|
138
|
-
const spotBalance = getSpotBalance(spotState);
|
|
139
|
-
const spotHold = getSpotHold(spotState);
|
|
140
|
-
const freeSpot = Math.max(0, spotBalance - spotHold);
|
|
141
|
-
const currentTotal = parseFloat(accountState.totalBalance);
|
|
142
|
-
const currentSpendable = parseFloat(accountState.spendableBalance);
|
|
143
|
-
const currentWithdrawable = parseFloat(accountState.withdrawableBalance);
|
|
144
|
-
// Preserve sentinel totals (e.g. PERPS_CONSTANTS.FallbackDataDisplay '--')
|
|
145
|
-
// rather than coercing them to NaN.
|
|
146
|
-
if (!Number.isFinite(currentTotal)) {
|
|
147
|
-
return accountState;
|
|
148
|
-
}
|
|
149
|
-
if (spotBalance === 0) {
|
|
150
|
-
// No spot wealth means no hold either in the HL payload shape, so the
|
|
151
|
-
// later totalBalance adjustment would also be a no-op.
|
|
152
|
-
return accountState;
|
|
153
|
-
}
|
|
154
|
-
// Folding is gated strictly on the resolved abstraction mode (see callers'
|
|
155
|
-
// `foldIntoCollateral` argument). Standard / DEX-abstraction users keep
|
|
156
|
-
// perps and spot independent, so spot must NOT surface as a perps-
|
|
157
|
-
// withdrawable balance for them — withdraw3 only draws from the perps
|
|
158
|
-
// ledger in those modes. Unified / portfolio-margin users get the fold;
|
|
159
|
-
// live callers fail-CLOSED via `hyperLiquidModeFoldsSpot` when mode is
|
|
160
|
-
// unresolved.
|
|
161
|
-
const nextSpendable = resolveFoldedBalance(currentSpendable, accountState.spendableBalance, freeSpot, foldIntoCollateral);
|
|
162
|
-
const nextWithdrawable = resolveFoldedBalance(currentWithdrawable, accountState.withdrawableBalance, freeSpot, foldIntoCollateral);
|
|
163
|
-
// Total always reflects combined wealth: subtract spotHold to avoid
|
|
164
|
-
// double-counting on Unified/PM accounts where marginSummary.accountValue
|
|
165
|
-
// already includes the margin that HL surfaces via spot.hold. Standard
|
|
166
|
-
// mode has spotHold = 0 by construction, so the subtraction is a no-op.
|
|
167
|
-
const nextTotal = currentTotal + spotBalance - spotHold;
|
|
168
|
-
return {
|
|
169
|
-
...accountState,
|
|
170
|
-
totalBalance: nextTotal.toString(),
|
|
171
|
-
spendableBalance: nextSpendable,
|
|
172
|
-
withdrawableBalance: nextWithdrawable,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
exports.addSpotBalanceToAccountState = addSpotBalanceToAccountState;
|
|
176
|
-
function resolveFoldedBalance(currentNumeric, currentRaw, freeSpot, foldIntoCollateral) {
|
|
177
|
-
if (!foldIntoCollateral) {
|
|
178
|
-
return currentRaw;
|
|
179
|
-
}
|
|
180
|
-
if (Number.isFinite(currentNumeric)) {
|
|
181
|
-
return (currentNumeric + freeSpot).toString();
|
|
182
|
-
}
|
|
183
|
-
// Non-finite currentNumeric means the adapter passed a sentinel like
|
|
184
|
-
// `PERPS_CONSTANTS.FallbackDataDisplay` ("--") during loading. Preserve
|
|
185
|
-
// the sentinel rather than synthesising a numeric fold; the caller's
|
|
186
|
-
// UI treats "--" as "loading" and would otherwise show a misleading
|
|
187
|
-
// spot-only figure while the per-DEX perps fetch is still in flight.
|
|
188
|
-
return currentRaw;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Aggregate multiple per-DEX AccountState objects into one by summing numeric fields.
|
|
192
|
-
* ROE is recalculated as (totalUnrealizedPnl / totalMarginUsed) * 100.
|
|
193
|
-
*
|
|
194
|
-
* @param states - The array of per-DEX account states to aggregate.
|
|
195
|
-
* @returns The combined account state with summed balances and recalculated ROE.
|
|
196
|
-
*/
|
|
197
|
-
function aggregateAccountStates(states) {
|
|
198
|
-
const fallback = {
|
|
199
|
-
spendableBalance: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
200
|
-
withdrawableBalance: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
201
|
-
totalBalance: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
202
|
-
marginUsed: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
203
|
-
unrealizedPnl: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
204
|
-
returnOnEquity: perpsConfig_js_1.PERPS_CONSTANTS.FallbackDataDisplay,
|
|
205
|
-
};
|
|
206
|
-
if (states.length === 0) {
|
|
207
|
-
return fallback;
|
|
208
|
-
}
|
|
209
|
-
const aggregated = states.reduce((acc, state, index) => {
|
|
210
|
-
if (index === 0) {
|
|
211
|
-
return { ...state };
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
spendableBalance: (parseFloat(acc.spendableBalance) + parseFloat(state.spendableBalance)).toString(),
|
|
215
|
-
withdrawableBalance: (parseFloat(acc.withdrawableBalance) +
|
|
216
|
-
parseFloat(state.withdrawableBalance)).toString(),
|
|
217
|
-
totalBalance: (parseFloat(acc.totalBalance) + parseFloat(state.totalBalance)).toString(),
|
|
218
|
-
marginUsed: (parseFloat(acc.marginUsed) + parseFloat(state.marginUsed)).toString(),
|
|
219
|
-
unrealizedPnl: (parseFloat(acc.unrealizedPnl) + parseFloat(state.unrealizedPnl)).toString(),
|
|
220
|
-
returnOnEquity: '0',
|
|
221
|
-
};
|
|
222
|
-
}, fallback);
|
|
223
|
-
// Recalculate ROE across all DEXs
|
|
224
|
-
const totalMarginUsed = parseFloat(aggregated.marginUsed);
|
|
225
|
-
const totalUnrealizedPnl = parseFloat(aggregated.unrealizedPnl);
|
|
226
|
-
if (totalMarginUsed > 0) {
|
|
227
|
-
aggregated.returnOnEquity = ((totalUnrealizedPnl / totalMarginUsed) *
|
|
228
|
-
100).toString();
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
aggregated.returnOnEquity = '0';
|
|
232
|
-
}
|
|
233
|
-
return aggregated;
|
|
234
|
-
}
|
|
235
|
-
exports.aggregateAccountStates = aggregateAccountStates;
|
|
236
|
-
//# sourceMappingURL=accountUtils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountUtils.cjs","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":";;;AAMA,iEAA8D;AAI9D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEpE,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,cAAc,CAC5B,QAAoD;IAEpD,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAC9B,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,IAA+B,CAAC,CACvE,CAAC;IACF,OAAO,UAAU,IAAI,IAAI,CAAC;AAC5B,CAAC;AARD,wCAQC;AAED,SAAgB,6BAA6B,CAC3C,QAAoD;IAEpD,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC;AALD,sEAKC;AAED,SAAgB,qBAAqB,CACnC,QAAoD;IAEpD,OAAO,6BAA6B,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC;AAJD,sDAIC;AAUD,SAAS,aAAa,CACpB,KAAc;IAEd,MAAM,OAAO,GAAG,KAAqD,CAAC;IAEtE,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,OAAO,EAAE,OAAO,KAAK,QAAQ;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AAC;AACpB,CAAC;AArDD,wDAqDC","sourcesContent":["/**\n * Account utilities for Perps components\n * Handles account selection and EVM account filtering\n */\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig.js';\nimport type { SpotClearinghouseStateResponse } from '../types/hyperliquid-types.js';\nimport type { AccountState, PerpsInternalAccount } from '../types/index.js';\n\nconst EVM_ACCOUNT_TYPES = new Set(['eip155:eoa', 'eip155:erc4337']);\n\nfunction isEvmAccountType(type: string): boolean {\n return EVM_ACCOUNT_TYPES.has(type);\n}\n\nexport function findEvmAccount(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): InternalAccount | PerpsInternalAccount | null {\n const evmAccount = accounts.find(\n (account) =>\n account && isEvmAccountType(account.type as InternalAccount['type']),\n );\n return evmAccount ?? null;\n}\n\nexport function getEvmAccountFromAccountGroup(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): { address: string } | undefined {\n const evmAccount = findEvmAccount(accounts);\n return evmAccount ? { address: evmAccount.address } : undefined;\n}\n\nexport function getSelectedEvmAccount(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): { address: string } | undefined {\n return getEvmAccountFromAccountGroup(accounts);\n}\n\ntype SelectedEvmAccountMessenger = {\n call(\n actionType:\n | 'AccountsController:getSelectedAccount'\n | 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ): unknown;\n};\n\nfunction isAccountLike(\n value: unknown,\n): value is InternalAccount | PerpsInternalAccount {\n const account = value as { address?: unknown; type?: unknown } | null;\n\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof account?.address === 'string' &&\n typeof account.type === 'string'\n );\n}\n\nexport function getSelectedEvmAccountDetailsFromMessenger(\n messenger: SelectedEvmAccountMessenger,\n): InternalAccount | PerpsInternalAccount | undefined {\n try {\n const selectedAccount = messenger.call(\n 'AccountsController:getSelectedAccount',\n );\n if (isAccountLike(selectedAccount)) {\n const evmAccount = findEvmAccount([selectedAccount]);\n if (evmAccount) {\n return evmAccount;\n }\n }\n } catch {\n // Fall back to the selected account group if the direct lookup is unavailable.\n }\n\n try {\n const selectedAccountGroup = messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n );\n return Array.isArray(selectedAccountGroup)\n ? (findEvmAccount(selectedAccountGroup.filter(isAccountLike)) ??\n undefined)\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function getSelectedEvmAccountFromMessenger(\n messenger: SelectedEvmAccountMessenger,\n): { address: string } | undefined {\n const evmAccount = getSelectedEvmAccountDetailsFromMessenger(messenger);\n\n return evmAccount ? { address: evmAccount.address } : undefined;\n}\n\nexport type ReturnOnEquityInput = {\n unrealizedPnl: string | number;\n returnOnEquity: string | number;\n};\n\nexport function calculateWeightedReturnOnEquity(\n accounts: ReturnOnEquityInput[],\n): string {\n if (accounts.length === 0) {\n return '0';\n }\n\n let totalWeightedROE = 0;\n let totalMarginUsed = 0;\n\n for (const account of accounts) {\n const unrealizedPnl =\n typeof account.unrealizedPnl === 'string'\n ? Number.parseFloat(account.unrealizedPnl)\n : account.unrealizedPnl;\n const returnOnEquity =\n typeof account.returnOnEquity === 'string'\n ? Number.parseFloat(account.returnOnEquity)\n : account.returnOnEquity;\n\n if (Number.isNaN(unrealizedPnl) || Number.isNaN(returnOnEquity)) {\n continue;\n }\n\n if (returnOnEquity === 0) {\n continue;\n }\n\n const marginUsed = (unrealizedPnl / returnOnEquity) * 100;\n\n if (Number.isNaN(marginUsed) || marginUsed <= 0) {\n continue;\n }\n\n const roeDecimal = returnOnEquity / 100;\n\n totalWeightedROE += roeDecimal * marginUsed;\n totalMarginUsed += marginUsed;\n }\n\n if (totalMarginUsed <= 0) {\n return '0';\n }\n\n const weightedROE = (totalWeightedROE / totalMarginUsed) * 100;\n return weightedROE.toString();\n}\n\n// The release-branch balance bridge is USDC-only. Non-USDC spot assets must\n// not inflate the balances shown or validated by withdraw/payment flows.\nconst SPOT_COLLATERAL_COINS = new Set<string>(['USDC']);\n\nexport function getSpotBalance(\n spotState?: SpotClearinghouseStateResponse | null,\n): number {\n if (!spotState?.balances || !Array.isArray(spotState.balances)) {\n return 0;\n }\n\n return spotState.balances.reduce(\n (sum: number, balance: { coin?: string; total?: string }) => {\n if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {\n return sum;\n }\n const value = parseFloat(balance.total ?? '0');\n return Number.isFinite(value) ? sum + value : sum;\n },\n 0,\n );\n}\n\nexport function getSpotHold(\n spotState?: SpotClearinghouseStateResponse | null,\n): number {\n if (!spotState?.balances || !Array.isArray(spotState.balances)) {\n return 0;\n }\n\n return spotState.balances.reduce(\n (sum: number, balance: { coin?: string; hold?: string }) => {\n if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {\n return sum;\n }\n const value = parseFloat(balance.hold ?? '0');\n return Number.isFinite(value) ? sum + value : sum;\n },\n 0,\n );\n}\n\n/**\n * Options controlling how `addSpotBalanceToAccountState` folds spot balance\n * into the three-field AccountState contract.\n */\nexport type AddSpotBalanceOptions = {\n /**\n * When `true`, free spot USDC contributes to both `spendableBalance` and\n * `withdrawableBalance` in addition to `totalBalance` — appropriate for\n * venues where spot is automatically used as perps collateral (e.g.\n * HyperLiquid Unified/Portfolio mode, where `withdraw3` draws from the\n * unified ledger).\n *\n * When `false`, free spot contributes to `totalBalance` only; spendable\n * and withdrawable stay perps-only — appropriate for venues where spot\n * is a separate ledger the backend cannot auto-draw from (e.g. HL\n * Standard mode). The caller is responsible for translating\n * provider-specific state into this flag.\n *\n * Defaults to `true` for backward compatibility with call sites that\n * haven't yet been wired with provider-specific context.\n */\n foldIntoCollateral?: boolean;\n};\n\n/**\n * Add spot USDC to the AccountState contract. Caller decides whether the\n * spot balance counts as perps collateral via `options.foldIntoCollateral`\n * — the util stays provider-agnostic.\n *\n * @param accountState - Base AccountState produced by a provider adapter.\n * @param spotState - Raw spot clearinghouse response (HL-shaped); null or missing means no spot balance and the state is returned unchanged.\n * @param options - See {@link AddSpotBalanceOptions}.\n * @returns AccountState with spot folded into `totalBalance` always, and into spendable/withdrawable when `foldIntoCollateral` is true.\n */\nexport function addSpotBalanceToAccountState(\n accountState: AccountState,\n spotState?: SpotClearinghouseStateResponse | null,\n options?: AddSpotBalanceOptions,\n): AccountState {\n // Fail-closed default: align with `hyperLiquidModeFoldsSpot(null) → false`.\n // A caller that omits `options` should NOT silently fold spot — that would\n // over-report withdrawable funds for Standard / dexAbstraction users.\n const foldIntoCollateral = options?.foldIntoCollateral ?? false;\n\n const spotBalance = getSpotBalance(spotState);\n const spotHold = getSpotHold(spotState);\n const freeSpot = Math.max(0, spotBalance - spotHold);\n\n const currentTotal = parseFloat(accountState.totalBalance);\n const currentSpendable = parseFloat(accountState.spendableBalance);\n const currentWithdrawable = parseFloat(accountState.withdrawableBalance);\n\n // Preserve sentinel totals (e.g. PERPS_CONSTANTS.FallbackDataDisplay '--')\n // rather than coercing them to NaN.\n if (!Number.isFinite(currentTotal)) {\n return accountState;\n }\n\n if (spotBalance === 0) {\n // No spot wealth means no hold either in the HL payload shape, so the\n // later totalBalance adjustment would also be a no-op.\n return accountState;\n }\n\n // Folding is gated strictly on the resolved abstraction mode (see callers'\n // `foldIntoCollateral` argument). Standard / DEX-abstraction users keep\n // perps and spot independent, so spot must NOT surface as a perps-\n // withdrawable balance for them — withdraw3 only draws from the perps\n // ledger in those modes. Unified / portfolio-margin users get the fold;\n // live callers fail-CLOSED via `hyperLiquidModeFoldsSpot` when mode is\n // unresolved.\n const nextSpendable = resolveFoldedBalance(\n currentSpendable,\n accountState.spendableBalance,\n freeSpot,\n foldIntoCollateral,\n );\n const nextWithdrawable = resolveFoldedBalance(\n currentWithdrawable,\n accountState.withdrawableBalance,\n freeSpot,\n foldIntoCollateral,\n );\n\n // Total always reflects combined wealth: subtract spotHold to avoid\n // double-counting on Unified/PM accounts where marginSummary.accountValue\n // already includes the margin that HL surfaces via spot.hold. Standard\n // mode has spotHold = 0 by construction, so the subtraction is a no-op.\n const nextTotal = currentTotal + spotBalance - spotHold;\n\n return {\n ...accountState,\n totalBalance: nextTotal.toString(),\n spendableBalance: nextSpendable,\n withdrawableBalance: nextWithdrawable,\n };\n}\n\nfunction resolveFoldedBalance(\n currentNumeric: number,\n currentRaw: string,\n freeSpot: number,\n foldIntoCollateral: boolean,\n): string {\n if (!foldIntoCollateral) {\n return currentRaw;\n }\n if (Number.isFinite(currentNumeric)) {\n return (currentNumeric + freeSpot).toString();\n }\n // Non-finite currentNumeric means the adapter passed a sentinel like\n // `PERPS_CONSTANTS.FallbackDataDisplay` (\"--\") during loading. Preserve\n // the sentinel rather than synthesising a numeric fold; the caller's\n // UI treats \"--\" as \"loading\" and would otherwise show a misleading\n // spot-only figure while the per-DEX perps fetch is still in flight.\n return currentRaw;\n}\n\n/**\n * Aggregate multiple per-DEX AccountState objects into one by summing numeric fields.\n * ROE is recalculated as (totalUnrealizedPnl / totalMarginUsed) * 100.\n *\n * @param states - The array of per-DEX account states to aggregate.\n * @returns The combined account state with summed balances and recalculated ROE.\n */\nexport function aggregateAccountStates(states: AccountState[]): AccountState {\n const fallback: AccountState = {\n spendableBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n withdrawableBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n totalBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n marginUsed: PERPS_CONSTANTS.FallbackDataDisplay,\n unrealizedPnl: PERPS_CONSTANTS.FallbackDataDisplay,\n returnOnEquity: PERPS_CONSTANTS.FallbackDataDisplay,\n };\n\n if (states.length === 0) {\n return fallback;\n }\n\n const aggregated = states.reduce<AccountState>((acc, state, index) => {\n if (index === 0) {\n return { ...state };\n }\n\n return {\n spendableBalance: (\n parseFloat(acc.spendableBalance) + parseFloat(state.spendableBalance)\n ).toString(),\n withdrawableBalance: (\n parseFloat(acc.withdrawableBalance) +\n parseFloat(state.withdrawableBalance)\n ).toString(),\n totalBalance: (\n parseFloat(acc.totalBalance) + parseFloat(state.totalBalance)\n ).toString(),\n marginUsed: (\n parseFloat(acc.marginUsed) + parseFloat(state.marginUsed)\n ).toString(),\n unrealizedPnl: (\n parseFloat(acc.unrealizedPnl) + parseFloat(state.unrealizedPnl)\n ).toString(),\n returnOnEquity: '0',\n };\n }, fallback);\n\n // Recalculate ROE across all DEXs\n const totalMarginUsed = parseFloat(aggregated.marginUsed);\n const totalUnrealizedPnl = parseFloat(aggregated.unrealizedPnl);\n if (totalMarginUsed > 0) {\n aggregated.returnOnEquity = (\n (totalUnrealizedPnl / totalMarginUsed) *\n 100\n ).toString();\n } else {\n aggregated.returnOnEquity = '0';\n }\n\n return aggregated;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountUtils.d.cts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EAAE,8BAA8B,EAAE,uCAAsC;AACpF,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,2BAA0B;AAQ5E,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,CAAC,eAAe,GAAG,oBAAoB,CAAC,EAAE,GACnD,eAAe,GAAG,oBAAoB,GAAG,IAAI,CAM/C;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,CAAC,eAAe,GAAG,oBAAoB,CAAC,EAAE,GACnD;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAGjC;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,CAAC,eAAe,GAAG,oBAAoB,CAAC,EAAE,GACnD;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAEjC;AAED,KAAK,2BAA2B,GAAG;IACjC,IAAI,CACF,UAAU,EACN,uCAAuC,GACvC,2DAA2D,GAC9D,OAAO,CAAC;CACZ,CAAC;AAeF,wBAAgB,yCAAyC,CACvD,SAAS,EAAE,2BAA2B,GACrC,eAAe,GAAG,oBAAoB,GAAG,SAAS,CA0BpD;AAED,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,2BAA2B,GACrC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAIjC;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC,CAAC;AAEF,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,mBAAmB,EAAE,GAC9B,MAAM,CA4CR;AAMD,wBAAgB,cAAc,CAC5B,SAAS,CAAC,EAAE,8BAA8B,GAAG,IAAI,GAChD,MAAM,CAeR;AAED,wBAAgB,WAAW,CACzB,SAAS,CAAC,EAAE,8BAA8B,GAAG,IAAI,GAChD,MAAM,CAeR;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;;;;;;;;;;;OAeG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,YAAY,EAC1B,SAAS,CAAC,EAAE,8BAA8B,GAAG,IAAI,EACjD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,YAAY,CA0Dd;AAsBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAqD3E"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account utilities for Perps components
|
|
3
|
-
* Handles account selection and EVM account filtering
|
|
4
|
-
*/
|
|
5
|
-
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
6
|
-
import type { SpotClearinghouseStateResponse } from "../types/hyperliquid-types.mjs";
|
|
7
|
-
import type { AccountState, PerpsInternalAccount } from "../types/index.mjs";
|
|
8
|
-
export declare function findEvmAccount(accounts: (InternalAccount | PerpsInternalAccount)[]): InternalAccount | PerpsInternalAccount | null;
|
|
9
|
-
export declare function getEvmAccountFromAccountGroup(accounts: (InternalAccount | PerpsInternalAccount)[]): {
|
|
10
|
-
address: string;
|
|
11
|
-
} | undefined;
|
|
12
|
-
export declare function getSelectedEvmAccount(accounts: (InternalAccount | PerpsInternalAccount)[]): {
|
|
13
|
-
address: string;
|
|
14
|
-
} | undefined;
|
|
15
|
-
type SelectedEvmAccountMessenger = {
|
|
16
|
-
call(actionType: 'AccountsController:getSelectedAccount' | 'AccountTreeController:getAccountsFromSelectedAccountGroup'): unknown;
|
|
17
|
-
};
|
|
18
|
-
export declare function getSelectedEvmAccountDetailsFromMessenger(messenger: SelectedEvmAccountMessenger): InternalAccount | PerpsInternalAccount | undefined;
|
|
19
|
-
export declare function getSelectedEvmAccountFromMessenger(messenger: SelectedEvmAccountMessenger): {
|
|
20
|
-
address: string;
|
|
21
|
-
} | undefined;
|
|
22
|
-
export type ReturnOnEquityInput = {
|
|
23
|
-
unrealizedPnl: string | number;
|
|
24
|
-
returnOnEquity: string | number;
|
|
25
|
-
};
|
|
26
|
-
export declare function calculateWeightedReturnOnEquity(accounts: ReturnOnEquityInput[]): string;
|
|
27
|
-
export declare function getSpotBalance(spotState?: SpotClearinghouseStateResponse | null): number;
|
|
28
|
-
export declare function getSpotHold(spotState?: SpotClearinghouseStateResponse | null): number;
|
|
29
|
-
/**
|
|
30
|
-
* Options controlling how `addSpotBalanceToAccountState` folds spot balance
|
|
31
|
-
* into the three-field AccountState contract.
|
|
32
|
-
*/
|
|
33
|
-
export type AddSpotBalanceOptions = {
|
|
34
|
-
/**
|
|
35
|
-
* When `true`, free spot USDC contributes to both `spendableBalance` and
|
|
36
|
-
* `withdrawableBalance` in addition to `totalBalance` — appropriate for
|
|
37
|
-
* venues where spot is automatically used as perps collateral (e.g.
|
|
38
|
-
* HyperLiquid Unified/Portfolio mode, where `withdraw3` draws from the
|
|
39
|
-
* unified ledger).
|
|
40
|
-
*
|
|
41
|
-
* When `false`, free spot contributes to `totalBalance` only; spendable
|
|
42
|
-
* and withdrawable stay perps-only — appropriate for venues where spot
|
|
43
|
-
* is a separate ledger the backend cannot auto-draw from (e.g. HL
|
|
44
|
-
* Standard mode). The caller is responsible for translating
|
|
45
|
-
* provider-specific state into this flag.
|
|
46
|
-
*
|
|
47
|
-
* Defaults to `true` for backward compatibility with call sites that
|
|
48
|
-
* haven't yet been wired with provider-specific context.
|
|
49
|
-
*/
|
|
50
|
-
foldIntoCollateral?: boolean;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Add spot USDC to the AccountState contract. Caller decides whether the
|
|
54
|
-
* spot balance counts as perps collateral via `options.foldIntoCollateral`
|
|
55
|
-
* — the util stays provider-agnostic.
|
|
56
|
-
*
|
|
57
|
-
* @param accountState - Base AccountState produced by a provider adapter.
|
|
58
|
-
* @param spotState - Raw spot clearinghouse response (HL-shaped); null or missing means no spot balance and the state is returned unchanged.
|
|
59
|
-
* @param options - See {@link AddSpotBalanceOptions}.
|
|
60
|
-
* @returns AccountState with spot folded into `totalBalance` always, and into spendable/withdrawable when `foldIntoCollateral` is true.
|
|
61
|
-
*/
|
|
62
|
-
export declare function addSpotBalanceToAccountState(accountState: AccountState, spotState?: SpotClearinghouseStateResponse | null, options?: AddSpotBalanceOptions): AccountState;
|
|
63
|
-
/**
|
|
64
|
-
* Aggregate multiple per-DEX AccountState objects into one by summing numeric fields.
|
|
65
|
-
* ROE is recalculated as (totalUnrealizedPnl / totalMarginUsed) * 100.
|
|
66
|
-
*
|
|
67
|
-
* @param states - The array of per-DEX account states to aggregate.
|
|
68
|
-
* @returns The combined account state with summed balances and recalculated ROE.
|
|
69
|
-
*/
|
|
70
|
-
export declare function aggregateAccountStates(states: AccountState[]): AccountState;
|
|
71
|
-
export {};
|
|
72
|
-
//# sourceMappingURL=accountUtils.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountUtils.d.mts","sourceRoot":"","sources":["../../src/utils/accountU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,UAAU,CAAC,cAAc,GAAG,CAC1B,CAAC,kBAAkB,GAAG,eAAe,CAAC;YACtC,GAAG,CACJ,CAAC,QAAQ,EAAE,CAAC;IACf,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,cAAc,GAAG,GAAG,CAAC;IAClC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Account utilities for Perps components\n * Handles account selection and EVM account filtering\n */\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig.js';\nimport type { SpotClearinghouseStateResponse } from '../types/hyperliquid-types.js';\nimport type { AccountState, PerpsInternalAccount } from '../types/index.js';\n\nconst EVM_ACCOUNT_TYPES = new Set(['eip155:eoa', 'eip155:erc4337']);\n\nfunction isEvmAccountType(type: string): boolean {\n return EVM_ACCOUNT_TYPES.has(type);\n}\n\nexport function findEvmAccount(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): InternalAccount | PerpsInternalAccount | null {\n const evmAccount = accounts.find(\n (account) =>\n account && isEvmAccountType(account.type as InternalAccount['type']),\n );\n return evmAccount ?? null;\n}\n\nexport function getEvmAccountFromAccountGroup(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): { address: string } | undefined {\n const evmAccount = findEvmAccount(accounts);\n return evmAccount ? { address: evmAccount.address } : undefined;\n}\n\nexport function getSelectedEvmAccount(\n accounts: (InternalAccount | PerpsInternalAccount)[],\n): { address: string } | undefined {\n return getEvmAccountFromAccountGroup(accounts);\n}\n\ntype SelectedEvmAccountMessenger = {\n call(\n actionType:\n | 'AccountsController:getSelectedAccount'\n | 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ): unknown;\n};\n\nfunction isAccountLike(\n value: unknown,\n): value is InternalAccount | PerpsInternalAccount {\n const account = value as { address?: unknown; type?: unknown } | null;\n\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof account?.address === 'string' &&\n typeof account.type === 'string'\n );\n}\n\nexport function getSelectedEvmAccountDetailsFromMessenger(\n messenger: SelectedEvmAccountMessenger,\n): InternalAccount | PerpsInternalAccount | undefined {\n try {\n const selectedAccount = messenger.call(\n 'AccountsController:getSelectedAccount',\n );\n if (isAccountLike(selectedAccount)) {\n const evmAccount = findEvmAccount([selectedAccount]);\n if (evmAccount) {\n return evmAccount;\n }\n }\n } catch {\n // Fall back to the selected account group if the direct lookup is unavailable.\n }\n\n try {\n const selectedAccountGroup = messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n );\n return Array.isArray(selectedAccountGroup)\n ? (findEvmAccount(selectedAccountGroup.filter(isAccountLike)) ??\n undefined)\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function getSelectedEvmAccountFromMessenger(\n messenger: SelectedEvmAccountMessenger,\n): { address: string } | undefined {\n const evmAccount = getSelectedEvmAccountDetailsFromMessenger(messenger);\n\n return evmAccount ? { address: evmAccount.address } : undefined;\n}\n\nexport type ReturnOnEquityInput = {\n unrealizedPnl: string | number;\n returnOnEquity: string | number;\n};\n\nexport function calculateWeightedReturnOnEquity(\n accounts: ReturnOnEquityInput[],\n): string {\n if (accounts.length === 0) {\n return '0';\n }\n\n let totalWeightedROE = 0;\n let totalMarginUsed = 0;\n\n for (const account of accounts) {\n const unrealizedPnl =\n typeof account.unrealizedPnl === 'string'\n ? Number.parseFloat(account.unrealizedPnl)\n : account.unrealizedPnl;\n const returnOnEquity =\n typeof account.returnOnEquity === 'string'\n ? Number.parseFloat(account.returnOnEquity)\n : account.returnOnEquity;\n\n if (Number.isNaN(unrealizedPnl) || Number.isNaN(returnOnEquity)) {\n continue;\n }\n\n if (returnOnEquity === 0) {\n continue;\n }\n\n const marginUsed = (unrealizedPnl / returnOnEquity) * 100;\n\n if (Number.isNaN(marginUsed) || marginUsed <= 0) {\n continue;\n }\n\n const roeDecimal = returnOnEquity / 100;\n\n totalWeightedROE += roeDecimal * marginUsed;\n totalMarginUsed += marginUsed;\n }\n\n if (totalMarginUsed <= 0) {\n return '0';\n }\n\n const weightedROE = (totalWeightedROE / totalMarginUsed) * 100;\n return weightedROE.toString();\n}\n\n// The release-branch balance bridge is USDC-only. Non-USDC spot assets must\n// not inflate the balances shown or validated by withdraw/payment flows.\nconst SPOT_COLLATERAL_COINS = new Set<string>(['USDC']);\n\nexport function getSpotBalance(\n spotState?: SpotClearinghouseStateResponse | null,\n): number {\n if (!spotState?.balances || !Array.isArray(spotState.balances)) {\n return 0;\n }\n\n return spotState.balances.reduce(\n (sum: number, balance: { coin?: string; total?: string }) => {\n if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {\n return sum;\n }\n const value = parseFloat(balance.total ?? '0');\n return Number.isFinite(value) ? sum + value : sum;\n },\n 0,\n );\n}\n\nexport function getSpotHold(\n spotState?: SpotClearinghouseStateResponse | null,\n): number {\n if (!spotState?.balances || !Array.isArray(spotState.balances)) {\n return 0;\n }\n\n return spotState.balances.reduce(\n (sum: number, balance: { coin?: string; hold?: string }) => {\n if (!balance.coin || !SPOT_COLLATERAL_COINS.has(balance.coin)) {\n return sum;\n }\n const value = parseFloat(balance.hold ?? '0');\n return Number.isFinite(value) ? sum + value : sum;\n },\n 0,\n );\n}\n\n/**\n * Options controlling how `addSpotBalanceToAccountState` folds spot balance\n * into the three-field AccountState contract.\n */\nexport type AddSpotBalanceOptions = {\n /**\n * When `true`, free spot USDC contributes to both `spendableBalance` and\n * `withdrawableBalance` in addition to `totalBalance` — appropriate for\n * venues where spot is automatically used as perps collateral (e.g.\n * HyperLiquid Unified/Portfolio mode, where `withdraw3` draws from the\n * unified ledger).\n *\n * When `false`, free spot contributes to `totalBalance` only; spendable\n * and withdrawable stay perps-only — appropriate for venues where spot\n * is a separate ledger the backend cannot auto-draw from (e.g. HL\n * Standard mode). The caller is responsible for translating\n * provider-specific state into this flag.\n *\n * Defaults to `true` for backward compatibility with call sites that\n * haven't yet been wired with provider-specific context.\n */\n foldIntoCollateral?: boolean;\n};\n\n/**\n * Add spot USDC to the AccountState contract. Caller decides whether the\n * spot balance counts as perps collateral via `options.foldIntoCollateral`\n * — the util stays provider-agnostic.\n *\n * @param accountState - Base AccountState produced by a provider adapter.\n * @param spotState - Raw spot clearinghouse response (HL-shaped); null or missing means no spot balance and the state is returned unchanged.\n * @param options - See {@link AddSpotBalanceOptions}.\n * @returns AccountState with spot folded into `totalBalance` always, and into spendable/withdrawable when `foldIntoCollateral` is true.\n */\nexport function addSpotBalanceToAccountState(\n accountState: AccountState,\n spotState?: SpotClearinghouseStateResponse | null,\n options?: AddSpotBalanceOptions,\n): AccountState {\n // Fail-closed default: align with `hyperLiquidModeFoldsSpot(null) → false`.\n // A caller that omits `options` should NOT silently fold spot — that would\n // over-report withdrawable funds for Standard / dexAbstraction users.\n const foldIntoCollateral = options?.foldIntoCollateral ?? false;\n\n const spotBalance = getSpotBalance(spotState);\n const spotHold = getSpotHold(spotState);\n const freeSpot = Math.max(0, spotBalance - spotHold);\n\n const currentTotal = parseFloat(accountState.totalBalance);\n const currentSpendable = parseFloat(accountState.spendableBalance);\n const currentWithdrawable = parseFloat(accountState.withdrawableBalance);\n\n // Preserve sentinel totals (e.g. PERPS_CONSTANTS.FallbackDataDisplay '--')\n // rather than coercing them to NaN.\n if (!Number.isFinite(currentTotal)) {\n return accountState;\n }\n\n if (spotBalance === 0) {\n // No spot wealth means no hold either in the HL payload shape, so the\n // later totalBalance adjustment would also be a no-op.\n return accountState;\n }\n\n // Folding is gated strictly on the resolved abstraction mode (see callers'\n // `foldIntoCollateral` argument). Standard / DEX-abstraction users keep\n // perps and spot independent, so spot must NOT surface as a perps-\n // withdrawable balance for them — withdraw3 only draws from the perps\n // ledger in those modes. Unified / portfolio-margin users get the fold;\n // live callers fail-CLOSED via `hyperLiquidModeFoldsSpot` when mode is\n // unresolved.\n const nextSpendable = resolveFoldedBalance(\n currentSpendable,\n accountState.spendableBalance,\n freeSpot,\n foldIntoCollateral,\n );\n const nextWithdrawable = resolveFoldedBalance(\n currentWithdrawable,\n accountState.withdrawableBalance,\n freeSpot,\n foldIntoCollateral,\n );\n\n // Total always reflects combined wealth: subtract spotHold to avoid\n // double-counting on Unified/PM accounts where marginSummary.accountValue\n // already includes the margin that HL surfaces via spot.hold. Standard\n // mode has spotHold = 0 by construction, so the subtraction is a no-op.\n const nextTotal = currentTotal + spotBalance - spotHold;\n\n return {\n ...accountState,\n totalBalance: nextTotal.toString(),\n spendableBalance: nextSpendable,\n withdrawableBalance: nextWithdrawable,\n };\n}\n\nfunction resolveFoldedBalance(\n currentNumeric: number,\n currentRaw: string,\n freeSpot: number,\n foldIntoCollateral: boolean,\n): string {\n if (!foldIntoCollateral) {\n return currentRaw;\n }\n if (Number.isFinite(currentNumeric)) {\n return (currentNumeric + freeSpot).toString();\n }\n // Non-finite currentNumeric means the adapter passed a sentinel like\n // `PERPS_CONSTANTS.FallbackDataDisplay` (\"--\") during loading. Preserve\n // the sentinel rather than synthesising a numeric fold; the caller's\n // UI treats \"--\" as \"loading\" and would otherwise show a misleading\n // spot-only figure while the per-DEX perps fetch is still in flight.\n return currentRaw;\n}\n\n/**\n * Aggregate multiple per-DEX AccountState objects into one by summing numeric fields.\n * ROE is recalculated as (totalUnrealizedPnl / totalMarginUsed) * 100.\n *\n * @param states - The array of per-DEX account states to aggregate.\n * @returns The combined account state with summed balances and recalculated ROE.\n */\nexport function aggregateAccountStates(states: AccountState[]): AccountState {\n const fallback: AccountState = {\n spendableBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n withdrawableBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n totalBalance: PERPS_CONSTANTS.FallbackDataDisplay,\n marginUsed: PERPS_CONSTANTS.FallbackDataDisplay,\n unrealizedPnl: PERPS_CONSTANTS.FallbackDataDisplay,\n returnOnEquity: PERPS_CONSTANTS.FallbackDataDisplay,\n };\n\n if (states.length === 0) {\n return fallback;\n }\n\n const aggregated = states.reduce<AccountState>((acc, state, index) => {\n if (index === 0) {\n return { ...state };\n }\n\n return {\n spendableBalance: (\n parseFloat(acc.spendableBalance) + parseFloat(state.spendableBalance)\n ).toString(),\n withdrawableBalance: (\n parseFloat(acc.withdrawableBalance) +\n parseFloat(state.withdrawableBalance)\n ).toString(),\n totalBalance: (\n parseFloat(acc.totalBalance) + parseFloat(state.totalBalance)\n ).toString(),\n marginUsed: (\n parseFloat(acc.marginUsed) + parseFloat(state.marginUsed)\n ).toString(),\n unrealizedPnl: (\n parseFloat(acc.unrealizedPnl) + parseFloat(state.unrealizedPnl)\n ).toString(),\n returnOnEquity: '0',\n };\n }, fallback);\n\n // Recalculate ROE across all DEXs\n const totalMarginUsed = parseFloat(aggregated.marginUsed);\n const totalUnrealizedPnl = parseFloat(aggregated.unrealizedPnl);\n if (totalMarginUsed > 0) {\n aggregated.returnOnEquity = (\n (totalUnrealizedPnl / totalMarginUsed) *\n 100\n ).toString();\n } else {\n aggregated.returnOnEquity = '0';\n }\n\n return aggregated;\n}\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidCapabilitySymbol = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Check whether a capability symbol has the provider-independent shape the
|
|
6
|
-
* caller allows.
|
|
7
|
-
*
|
|
8
|
-
* @param symbol - Market symbol supplied by a consumer.
|
|
9
|
-
* @param options - Provider route syntax supported by the caller.
|
|
10
|
-
* @param options.allowProviderRoute - Whether one non-empty `dex:market`
|
|
11
|
-
* route prefix is allowed.
|
|
12
|
-
* @returns Whether the symbol is non-empty, contains no whitespace, and uses
|
|
13
|
-
* the allowed route shape.
|
|
14
|
-
*/
|
|
15
|
-
function isValidCapabilitySymbol(symbol, options) {
|
|
16
|
-
if (symbol.length === 0 || /\s/u.test(symbol)) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const routeParts = symbol.split(':');
|
|
20
|
-
return options.allowProviderRoute
|
|
21
|
-
? routeParts.length <= 2 && routeParts.every((part) => part.length > 0)
|
|
22
|
-
: routeParts.length === 1;
|
|
23
|
-
}
|
|
24
|
-
exports.isValidCapabilitySymbol = isValidCapabilitySymbol;
|
|
25
|
-
//# sourceMappingURL=capabilitySymbols.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilitySymbols.cjs","sourceRoot":"","sources":["../../src/utils/capabilitySymbols.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,SAAgB,uBAAuB,CACrC,MAAc,EACd,OAAwC;IAExC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,kBAAkB;QAC/B,CAAC,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACvE,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;AAC9B,CAAC;AAZD,0DAYC","sourcesContent":["/**\n * Check whether a capability symbol has the provider-independent shape the\n * caller allows.\n *\n * @param symbol - Market symbol supplied by a consumer.\n * @param options - Provider route syntax supported by the caller.\n * @param options.allowProviderRoute - Whether one non-empty `dex:market`\n * route prefix is allowed.\n * @returns Whether the symbol is non-empty, contains no whitespace, and uses\n * the allowed route shape.\n */\nexport function isValidCapabilitySymbol(\n symbol: string,\n options: { allowProviderRoute: boolean },\n): boolean {\n if (symbol.length === 0 || /\\s/u.test(symbol)) {\n return false;\n }\n\n const routeParts = symbol.split(':');\n return options.allowProviderRoute\n ? routeParts.length <= 2 && routeParts.every((part) => part.length > 0)\n : routeParts.length === 1;\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check whether a capability symbol has the provider-independent shape the
|
|
3
|
-
* caller allows.
|
|
4
|
-
*
|
|
5
|
-
* @param symbol - Market symbol supplied by a consumer.
|
|
6
|
-
* @param options - Provider route syntax supported by the caller.
|
|
7
|
-
* @param options.allowProviderRoute - Whether one non-empty `dex:market`
|
|
8
|
-
* route prefix is allowed.
|
|
9
|
-
* @returns Whether the symbol is non-empty, contains no whitespace, and uses
|
|
10
|
-
* the allowed route shape.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isValidCapabilitySymbol(symbol: string, options: {
|
|
13
|
-
allowProviderRoute: boolean;
|
|
14
|
-
}): boolean;
|
|
15
|
-
//# sourceMappingURL=capabilitySymbols.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilitySymbols.d.cts","sourceRoot":"","sources":["../../src/utils/capabilitySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,kBAAkB,EAAE,OAAO,CAAA;CAAE,GACvC,OAAO,CAST"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilitySymbols.d.mts","sourceRoot":"","sources":["../../src/utils/capabilitySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,kBAAkB,EAAE,OAAO,CAAA;CAAE,GACvC,OAAO,CAST"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilitySymbols.mjs","sourceRoot":"","sources":["../../src/utils/capabilitySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,OAAwC;IAExC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,kBAAkB;QAC/B,CAAC,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACvE,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Check whether a capability symbol has the provider-independent shape the\n * caller allows.\n *\n * @param symbol - Market symbol supplied by a consumer.\n * @param options - Provider route syntax supported by the caller.\n * @param options.allowProviderRoute - Whether one non-empty `dex:market`\n * route prefix is allowed.\n * @returns Whether the symbol is non-empty, contains no whitespace, and uses\n * the allowed route shape.\n */\nexport function isValidCapabilitySymbol(\n symbol: string,\n options: { allowProviderRoute: boolean },\n): boolean {\n if (symbol.length === 0 || /\\s/u.test(symbol)) {\n return false;\n }\n\n const routeParts = symbol.split(':');\n return options.allowProviderRoute\n ? routeParts.length <= 2 && routeParts.every((part) => part.length > 0)\n : routeParts.length === 1;\n}\n"]}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resetPerpsRestCacheForTests = exports.coalescePerpsRestRequest = void 0;
|
|
4
|
-
const perpsConfig_js_1 = require("../constants/perpsConfig.cjs");
|
|
5
|
-
const inflight = new Map();
|
|
6
|
-
const cache = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* Coalesce an idempotent perps REST call.
|
|
9
|
-
*
|
|
10
|
-
* - If a fresh cached value exists for `key`, it is returned immediately.
|
|
11
|
-
* - If an in-flight promise exists for `key`, it is shared with the caller.
|
|
12
|
-
* - Otherwise, `fetcher` runs once; the result populates the cache for `ttlMs`.
|
|
13
|
-
*
|
|
14
|
-
* `forceRefresh` skips both cache and in-flight dedup.
|
|
15
|
-
*
|
|
16
|
-
* @param key - Stable cache key identifying this logical REST call.
|
|
17
|
-
* @param fetcher - Thunk that performs the REST call when no cache/inflight hit.
|
|
18
|
-
* @param options - Optional overrides for TTL and forceRefresh behavior.
|
|
19
|
-
* @returns The fetched (or cached) value.
|
|
20
|
-
*/
|
|
21
|
-
function coalescePerpsRestRequest(key, fetcher, options = {}) {
|
|
22
|
-
const ttlMs = options.ttlMs ?? perpsConfig_js_1.PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs;
|
|
23
|
-
const forceRefresh = options.forceRefresh ?? false;
|
|
24
|
-
if (forceRefresh) {
|
|
25
|
-
cache.delete(key);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const now = Date.now();
|
|
29
|
-
const cached = cache.get(key);
|
|
30
|
-
if (cached) {
|
|
31
|
-
if (cached.expiresAt > now) {
|
|
32
|
-
return Promise.resolve(cached.value);
|
|
33
|
-
}
|
|
34
|
-
// Evict expired entry so callers with per-call-unique keys (e.g.
|
|
35
|
-
// CandleStreamChannel historical paging with per-page endTime) do
|
|
36
|
-
// not accumulate dead blobs for the life of the process.
|
|
37
|
-
cache.delete(key);
|
|
38
|
-
}
|
|
39
|
-
const existing = inflight.get(key);
|
|
40
|
-
if (existing !== undefined) {
|
|
41
|
-
return existing;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const run = fetcher().then((value) => {
|
|
45
|
-
// Only the currently-tracked in-flight promise writes to cache. A stale
|
|
46
|
-
// in-flight (e.g. one that was racing a later forceRefresh=true caller)
|
|
47
|
-
// must not clobber the fresh value once it finally resolves.
|
|
48
|
-
if (inflight.get(key) === run) {
|
|
49
|
-
cache.set(key, { value, expiresAt: Date.now() + ttlMs });
|
|
50
|
-
inflight.delete(key);
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
}, (error) => {
|
|
54
|
-
if (inflight.get(key) === run) {
|
|
55
|
-
inflight.delete(key);
|
|
56
|
-
}
|
|
57
|
-
throw error;
|
|
58
|
-
});
|
|
59
|
-
inflight.set(key, run);
|
|
60
|
-
return run;
|
|
61
|
-
}
|
|
62
|
-
exports.coalescePerpsRestRequest = coalescePerpsRestRequest;
|
|
63
|
-
/**
|
|
64
|
-
* Test-only: wipe all cached entries and in-flight promises.
|
|
65
|
-
*/
|
|
66
|
-
function resetPerpsRestCacheForTests() {
|
|
67
|
-
cache.clear();
|
|
68
|
-
inflight.clear();
|
|
69
|
-
}
|
|
70
|
-
exports.resetPerpsRestCacheForTests = resetPerpsRestCacheForTests;
|
|
71
|
-
//# sourceMappingURL=coalescePerpsRestRequest.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescePerpsRestRequest.cjs","sourceRoot":"","sources":["../../src/utils/coalescePerpsRestRequest.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AAkBjE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;AACrD,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;AAerD;;;;;;;;;;;;;GAaG;AACH,SAAgB,wBAAwB,CACtC,GAAW,EACX,OAA8B,EAC9B,UAA2B,EAAE;IAE7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,mCAAkB,CAAC,sBAAsB,CAAC;IACzE,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,KAAK,CAAC;IAEnD,IAAI,YAAY,EAAE,CAAC;QACjB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAmC,CAAC;QAChE,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,MAAM,CAAC,SAAS,GAAG,GAAG,EAAE,CA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ANCE_CONFIG } from '../constants/perpsConfig.js';\n\n// Rapid perps market switching (candle bridge + activity tab burst) drives\n// duplicate REST calls against api.hyperliquid.xyz and occasionally trips 429.\n// This helper collapses concurrent identical calls into one in-flight promise\n// and serves a short TTL cache to absorb the burst. Explicit refresh bypasses\n// the cache so user-initiated refetch still re-runs.\n//\n// Lives at the service layer (MarketDataService) rather than per-hook so every\n// current and future caller — hooks, controller, aggregated provider — is\n// deduped automatically. Centralized at MarketDataService because it is\n// already a single choke point.\n\ntype CacheEntry<TValue> = {\n value: TValue;\n expiresAt: number;\n};\n\nconst inflight = new Map<string, Promise<unknown>>();\nconst cache = new Map<string, CacheEntry<unknown>>();\n\nexport type CoalesceOptions = {\n /**\n * Cache TTL in milliseconds. Defaults to\n * {@link PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs}.\n */\n ttlMs?: number;\n /**\n * Bypass the cache and any in-flight promise. The fresh result will be\n * written back to the cache under the same key.\n */\n forceRefresh?: boolean;\n};\n\n/**\n * Coalesce an idempotent perps REST call.\n *\n * - If a fresh cached value exists for `key`, it is returned immediately.\n * - If an in-flight promise exists for `key`, it is shared with the caller.\n * - Otherwise, `fetcher` runs once; the result populates the cache for `ttlMs`.\n *\n * `forceRefresh` skips both cache and in-flight dedup.\n *\n * @param key - Stable cache key identifying this logical REST call.\n * @param fetcher - Thunk that performs the REST call when no cache/inflight hit.\n * @param options - Optional overrides for TTL and forceRefresh behavior.\n * @returns The fetched (or cached) value.\n */\nexport function coalescePerpsRestRequest<TValue>(\n key: string,\n fetcher: () => Promise<TValue>,\n options: CoalesceOptions = {},\n): Promise<TValue> {\n const ttlMs = options.ttlMs ?? PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs;\n const forceRefresh = options.forceRefresh ?? false;\n\n if (forceRefresh) {\n cache.delete(key);\n } else {\n const now = Date.now();\n const cached = cache.get(key) as CacheEntry<TValue> | undefined;\n if (cached) {\n if (cached.expiresAt > now) {\n return Promise.resolve(cached.value);\n }\n // Evict expired entry so callers with per-call-unique keys (e.g.\n // CandleStreamChannel historical paging with per-page endTime) do\n // not accumulate dead blobs for the life of the process.\n cache.delete(key);\n }\n const existing = inflight.get(key) as Promise<TValue> | undefined;\n if (existing !== undefined) {\n return existing;\n }\n }\n\n const run = fetcher().then(\n (value) => {\n // Only the currently-tracked in-flight promise writes to cache. A stale\n // in-flight (e.g. one that was racing a later forceRefresh=true caller)\n // must not clobber the fresh value once it finally resolves.\n if (inflight.get(key) === run) {\n cache.set(key, { value, expiresAt: Date.now() + ttlMs });\n inflight.delete(key);\n }\n return value;\n },\n (error) => {\n if (inflight.get(key) === run) {\n inflight.delete(key);\n }\n throw error;\n },\n );\n\n inflight.set(key, run);\n return run;\n}\n\n/**\n * Test-only: wipe all cached entries and in-flight promises.\n */\nexport function resetPerpsRestCacheForTests(): void {\n cache.clear();\n inflight.clear();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescePerpsRestRequest.d.cts","sourceRoot":"","sources":["../../src/utils/coalescePerpsRestRequest.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAC7C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAC9B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CA6CjB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export type CoalesceOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Cache TTL in milliseconds. Defaults to
|
|
4
|
-
* {@link PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs}.
|
|
5
|
-
*/
|
|
6
|
-
ttlMs?: number;
|
|
7
|
-
/**
|
|
8
|
-
* Bypass the cache and any in-flight promise. The fresh result will be
|
|
9
|
-
* written back to the cache under the same key.
|
|
10
|
-
*/
|
|
11
|
-
forceRefresh?: boolean;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Coalesce an idempotent perps REST call.
|
|
15
|
-
*
|
|
16
|
-
* - If a fresh cached value exists for `key`, it is returned immediately.
|
|
17
|
-
* - If an in-flight promise exists for `key`, it is shared with the caller.
|
|
18
|
-
* - Otherwise, `fetcher` runs once; the result populates the cache for `ttlMs`.
|
|
19
|
-
*
|
|
20
|
-
* `forceRefresh` skips both cache and in-flight dedup.
|
|
21
|
-
*
|
|
22
|
-
* @param key - Stable cache key identifying this logical REST call.
|
|
23
|
-
* @param fetcher - Thunk that performs the REST call when no cache/inflight hit.
|
|
24
|
-
* @param options - Optional overrides for TTL and forceRefresh behavior.
|
|
25
|
-
* @returns The fetched (or cached) value.
|
|
26
|
-
*/
|
|
27
|
-
export declare function coalescePerpsRestRequest<TValue>(key: string, fetcher: () => Promise<TValue>, options?: CoalesceOptions): Promise<TValue>;
|
|
28
|
-
/**
|
|
29
|
-
* Test-only: wipe all cached entries and in-flight promises.
|
|
30
|
-
*/
|
|
31
|
-
export declare function resetPerpsRestCacheForTests(): void;
|
|
32
|
-
//# sourceMappingURL=coalescePerpsRestRequest.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coalescePerpsRestRequest.d.mts","sourceRoot":"","sources":["../../src/utils/coalescePerpsRestRequest.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAC7C,GAAG,E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gC,CAAC;QAClE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC,IAAI,CACxB,CAAC,KAAK,EAAE,EAAE;QACR,wEAAwE;QACxE,wEAAwE;QACxE,6DAA6D;QAC7D,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;YACzD,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;QACR,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9B,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC,CACF,CAAC;IAEF,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvB,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC","sourcesContent":["import { PERFORMANCE_CONFIG } from '../constants/perpsConfig.js';\n\n// Rapid perps market switching (candle bridge + activity tab burst) drives\n// duplicate REST calls against api.hyperliquid.xyz and occasionally trips 429.\n// This helper collapses concurrent identical calls into one in-flight promise\n// and serves a short TTL cache to absorb the burst. Explicit refresh bypasses\n// the cache so user-initiated refetch still re-runs.\n//\n// Lives at the service layer (MarketDataService) rather than per-hook so every\n// current and future caller — hooks, controller, aggregated provider — is\n// deduped automatically. Centralized at MarketDataService because it is\n// already a single choke point.\n\ntype CacheEntry<TValue> = {\n value: TValue;\n expiresAt: number;\n};\n\nconst inflight = new Map<string, Promise<unknown>>();\nconst cache = new Map<string, CacheEntry<unknown>>();\n\nexport type CoalesceOptions = {\n /**\n * Cache TTL in milliseconds. Defaults to\n * {@link PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs}.\n */\n ttlMs?: number;\n /**\n * Bypass the cache and any in-flight promise. The fresh result will be\n * written back to the cache under the same key.\n */\n forceRefresh?: boolean;\n};\n\n/**\n * Coalesce an idempotent perps REST call.\n *\n * - If a fresh cached value exists for `key`, it is returned immediately.\n * - If an in-flight promise exists for `key`, it is shared with the caller.\n * - Otherwise, `fetcher` runs once; the result populates the cache for `ttlMs`.\n *\n * `forceRefresh` skips both cache and in-flight dedup.\n *\n * @param key - Stable cache key identifying this logical REST call.\n * @param fetcher - Thunk that performs the REST call when no cache/inflight hit.\n * @param options - Optional overrides for TTL and forceRefresh behavior.\n * @returns The fetched (or cached) value.\n */\nexport function coalescePerpsRestRequest<TValue>(\n key: string,\n fetcher: () => Promise<TValue>,\n options: CoalesceOptions = {},\n): Promise<TValue> {\n const ttlMs = options.ttlMs ?? PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs;\n const forceRefresh = options.forceRefresh ?? false;\n\n if (forceRefresh) {\n cache.delete(key);\n } else {\n const now = Date.now();\n const cached = cache.get(key) as CacheEntry<TValue> | undefined;\n if (cached) {\n if (cached.expiresAt > now) {\n return Promise.resolve(cached.value);\n }\n // Evict expired entry so callers with per-call-unique keys (e.g.\n // CandleStreamChannel historical paging with per-page endTime) do\n // not accumulate dead blobs for the life of the process.\n cache.delete(key);\n }\n const existing = inflight.get(key) as Promise<TValue> | undefined;\n if (existing !== undefined) {\n return existing;\n }\n }\n\n const run = fetcher().then(\n (value) => {\n // Only the currently-tracked in-flight promise writes to cache. A stale\n // in-flight (e.g. one that was racing a later forceRefresh=true caller)\n // must not clobber the fresh value once it finally resolves.\n if (inflight.get(key) === run) {\n cache.set(key, { value, expiresAt: Date.now() + ttlMs });\n inflight.delete(key);\n }\n return value;\n },\n (error) => {\n if (inflight.get(key) === run) {\n inflight.delete(key);\n }\n throw error;\n },\n );\n\n inflight.set(key, run);\n return run;\n}\n\n/**\n * Test-only: wipe all cached entries and in-flight promises.\n */\nexport function resetPerpsRestCacheForTests(): void {\n cache.clear();\n inflight.clear();\n}\n"]}
|