@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba
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 +1 -11
- package/dist/PerpsController.cjs +66 -2224
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +79 -933
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +79 -933
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +64 -2221
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/index.cjs +1 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -19
- package/dist/__mocks__/hyperliquidMock.cjs +0 -68
- package/dist/__mocks__/hyperliquidMock.cjs.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.cts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.cts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.mts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.mts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.mjs +0 -65
- package/dist/__mocks__/hyperliquidMock.mjs.map +0 -1
- package/dist/__mocks__/providerMocks.cjs +0 -144
- package/dist/__mocks__/providerMocks.cjs.map +0 -1
- package/dist/__mocks__/providerMocks.d.cts +0 -44
- package/dist/__mocks__/providerMocks.d.cts.map +0 -1
- package/dist/__mocks__/providerMocks.d.mts +0 -44
- package/dist/__mocks__/providerMocks.d.mts.map +0 -1
- package/dist/__mocks__/providerMocks.mjs +0 -136
- package/dist/__mocks__/providerMocks.mjs.map +0 -1
- package/dist/__mocks__/serviceMocks.cjs +0 -187
- package/dist/__mocks__/serviceMocks.cjs.map +0 -1
- package/dist/__mocks__/serviceMocks.d.cts +0 -58
- package/dist/__mocks__/serviceMocks.d.cts.map +0 -1
- package/dist/__mocks__/serviceMocks.d.mts +0 -58
- package/dist/__mocks__/serviceMocks.d.mts.map +0 -1
- package/dist/__mocks__/serviceMocks.mjs +0 -180
- package/dist/__mocks__/serviceMocks.mjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -459
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -455
- 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/eventNames.cjs +0 -117
- package/dist/constants/eventNames.cjs.map +0 -1
- package/dist/constants/eventNames.d.cts +0 -106
- package/dist/constants/eventNames.d.cts.map +0 -1
- package/dist/constants/eventNames.d.mts +0 -106
- package/dist/constants/eventNames.d.mts.map +0 -1
- package/dist/constants/eventNames.mjs +0 -114
- package/dist/constants/eventNames.mjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.cjs +0 -366
- package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.cts +0 -276
- package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.mts +0 -276
- package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
- package/dist/constants/hyperLiquidConfig.mjs +0 -357
- package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
- package/dist/constants/index.cjs +0 -23
- package/dist/constants/index.cjs.map +0 -1
- package/dist/constants/index.d.cts +0 -7
- package/dist/constants/index.d.cts.map +0 -1
- package/dist/constants/index.d.mts +0 -7
- package/dist/constants/index.d.mts.map +0 -1
- package/dist/constants/index.mjs +0 -7
- package/dist/constants/index.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 +0 -19
- 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 +0 -27
- package/dist/constants/orderTypes.mjs.map +0 -1
- package/dist/constants/performanceMetrics.cjs +0 -61
- package/dist/constants/performanceMetrics.cjs.map +0 -1
- package/dist/constants/performanceMetrics.d.cts +0 -44
- package/dist/constants/performanceMetrics.d.cts.map +0 -1
- package/dist/constants/performanceMetrics.d.mts +0 -44
- package/dist/constants/performanceMetrics.d.mts.map +0 -1
- package/dist/constants/performanceMetrics.mjs +0 -58
- package/dist/constants/performanceMetrics.mjs.map +0 -1
- package/dist/constants/perpsConfig.cjs +0 -461
- package/dist/constants/perpsConfig.cjs.map +0 -1
- package/dist/constants/perpsConfig.d.cts +0 -343
- package/dist/constants/perpsConfig.d.cts.map +0 -1
- package/dist/constants/perpsConfig.d.mts +0 -343
- package/dist/constants/perpsConfig.d.mts.map +0 -1
- package/dist/constants/perpsConfig.mjs +0 -458
- package/dist/constants/perpsConfig.mjs.map +0 -1
- package/dist/constants/perpsErrorCodes.cjs +0 -79
- package/dist/constants/perpsErrorCodes.cjs.map +0 -1
- package/dist/constants/perpsErrorCodes.d.cts +0 -64
- package/dist/constants/perpsErrorCodes.d.cts.map +0 -1
- package/dist/constants/perpsErrorCodes.d.mts +0 -64
- package/dist/constants/perpsErrorCodes.d.mts.map +0 -1
- package/dist/constants/perpsErrorCodes.mjs +0 -76
- package/dist/constants/perpsErrorCodes.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.cjs +0 -857
- package/dist/platform-services/HyperLiquidClientService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.cts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.mts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.mjs +0 -853
- package/dist/platform-services/HyperLiquidClientService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs +0 -2170
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs +0 -2166
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.cjs +0 -140
- package/dist/platform-services/HyperLiquidWalletService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.cts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.mts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.mjs +0 -136
- package/dist/platform-services/HyperLiquidWalletService.mjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +0 -777
- package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +0 -773
- package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.cjs +0 -5172
- package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -881
- package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.mts +0 -881
- package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
- package/dist/providers/HyperLiquidProvider.mjs +0 -5168
- package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
- package/dist/providers/index.cjs +0 -11
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.d.cts +0 -6
- package/dist/providers/index.d.cts.map +0 -1
- package/dist/providers/index.d.mts +0 -6
- package/dist/providers/index.d.mts.map +0 -1
- package/dist/providers/index.mjs +0 -6
- package/dist/providers/index.mjs.map +0 -1
- package/dist/routing/ProviderRouter.cjs +0 -148
- package/dist/routing/ProviderRouter.cjs.map +0 -1
- package/dist/routing/ProviderRouter.d.cts +0 -124
- package/dist/routing/ProviderRouter.d.cts.map +0 -1
- package/dist/routing/ProviderRouter.d.mts +0 -124
- package/dist/routing/ProviderRouter.d.mts.map +0 -1
- package/dist/routing/ProviderRouter.mjs +0 -144
- 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 -161
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -345
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -345
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -153
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/AccountService.cjs +0 -313
- package/dist/services/AccountService.cjs.map +0 -1
- package/dist/services/AccountService.d.cts +0 -53
- package/dist/services/AccountService.d.cts.map +0 -1
- package/dist/services/AccountService.d.mts +0 -53
- package/dist/services/AccountService.d.mts.map +0 -1
- package/dist/services/AccountService.mjs +0 -309
- package/dist/services/AccountService.mjs.map +0 -1
- package/dist/services/DataLakeService.cjs +0 -219
- package/dist/services/DataLakeService.cjs.map +0 -1
- package/dist/services/DataLakeService.d.cts +0 -49
- package/dist/services/DataLakeService.d.cts.map +0 -1
- package/dist/services/DataLakeService.d.mts +0 -49
- package/dist/services/DataLakeService.d.mts.map +0 -1
- package/dist/services/DataLakeService.mjs +0 -215
- package/dist/services/DataLakeService.mjs.map +0 -1
- package/dist/services/DepositService.cjs +0 -96
- package/dist/services/DepositService.cjs.map +0 -1
- package/dist/services/DepositService.d.cts +0 -37
- package/dist/services/DepositService.d.cts.map +0 -1
- package/dist/services/DepositService.d.mts +0 -37
- package/dist/services/DepositService.d.mts.map +0 -1
- package/dist/services/DepositService.mjs +0 -92
- package/dist/services/DepositService.mjs.map +0 -1
- package/dist/services/EligibilityService.cjs +0 -156
- package/dist/services/EligibilityService.cjs.map +0 -1
- package/dist/services/EligibilityService.d.cts +0 -48
- package/dist/services/EligibilityService.d.cts.map +0 -1
- package/dist/services/EligibilityService.d.mts +0 -48
- package/dist/services/EligibilityService.d.mts.map +0 -1
- package/dist/services/EligibilityService.mjs +0 -152
- package/dist/services/EligibilityService.mjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.cjs +0 -258
- package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.cts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.mts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.mjs +0 -254
- package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
- package/dist/services/MarketDataService.cjs +0 -875
- package/dist/services/MarketDataService.cjs.map +0 -1
- package/dist/services/MarketDataService.d.cts +0 -289
- package/dist/services/MarketDataService.d.cts.map +0 -1
- package/dist/services/MarketDataService.d.mts +0 -289
- package/dist/services/MarketDataService.d.mts.map +0 -1
- package/dist/services/MarketDataService.mjs +0 -871
- package/dist/services/MarketDataService.mjs.map +0 -1
- package/dist/services/RewardsIntegrationService.cjs +0 -94
- package/dist/services/RewardsIntegrationService.cjs.map +0 -1
- package/dist/services/RewardsIntegrationService.d.cts +0 -30
- package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
- package/dist/services/RewardsIntegrationService.d.mts +0 -30
- package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
- package/dist/services/RewardsIntegrationService.mjs +0 -90
- 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 +0 -110
- package/dist/services/ServiceContext.d.cts.map +0 -1
- package/dist/services/ServiceContext.d.mts +0 -110
- 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/TradingService.cjs +0 -1481
- package/dist/services/TradingService.cjs.map +0 -1
- package/dist/services/TradingService.d.cts +0 -308
- package/dist/services/TradingService.d.cts.map +0 -1
- package/dist/services/TradingService.d.mts +0 -308
- package/dist/services/TradingService.d.mts.map +0 -1
- package/dist/services/TradingService.mjs +0 -1477
- package/dist/services/TradingService.mjs.map +0 -1
- package/dist/services/index.cjs +0 -26
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts +0 -11
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -11
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs +0 -10
- package/dist/services/index.mjs.map +0 -1
- package/dist/services/utils.cjs +0 -16
- package/dist/services/utils.cjs.map +0 -1
- package/dist/services/utils.d.cts +0 -8
- package/dist/services/utils.d.cts.map +0 -1
- package/dist/services/utils.d.mts +0 -8
- package/dist/services/utils.d.mts.map +0 -1
- package/dist/services/utils.mjs +0 -12
- package/dist/services/utils.mjs.map +0 -1
- package/dist/types/chart.cjs +0 -42
- package/dist/types/chart.cjs.map +0 -1
- package/dist/types/chart.d.cts +0 -62
- package/dist/types/chart.d.cts.map +0 -1
- package/dist/types/chart.d.mts +0 -62
- package/dist/types/chart.d.mts.map +0 -1
- package/dist/types/chart.mjs +0 -39
- package/dist/types/chart.mjs.map +0 -1
- package/dist/types/hyperliquid-types.cjs +0 -3
- package/dist/types/hyperliquid-types.cjs.map +0 -1
- package/dist/types/hyperliquid-types.d.cts +0 -52
- package/dist/types/hyperliquid-types.d.cts.map +0 -1
- package/dist/types/hyperliquid-types.d.mts +0 -52
- package/dist/types/hyperliquid-types.d.mts.map +0 -1
- package/dist/types/hyperliquid-types.mjs +0 -2
- package/dist/types/hyperliquid-types.mjs.map +0 -1
- package/dist/types/index.cjs +0 -96
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -1153
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -1153
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -79
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/transactionTypes.cjs +0 -28
- package/dist/types/transactionTypes.cjs.map +0 -1
- package/dist/types/transactionTypes.d.cts +0 -64
- package/dist/types/transactionTypes.d.cts.map +0 -1
- package/dist/types/transactionTypes.d.mts +0 -64
- package/dist/types/transactionTypes.d.mts.map +0 -1
- package/dist/types/transactionTypes.mjs +0 -23
- package/dist/types/transactionTypes.mjs.map +0 -1
- package/dist/utils/accountUtils.cjs +0 -65
- package/dist/utils/accountUtils.cjs.map +0 -1
- package/dist/utils/accountUtils.d.cts +0 -26
- package/dist/utils/accountUtils.d.cts.map +0 -1
- package/dist/utils/accountUtils.d.mts +0 -26
- package/dist/utils/accountUtils.d.mts.map +0 -1
- package/dist/utils/accountUtils.mjs +0 -61
- package/dist/utils/accountUtils.mjs.map +0 -1
- package/dist/utils/amountConversion.cjs +0 -61
- package/dist/utils/amountConversion.cjs.map +0 -1
- package/dist/utils/amountConversion.d.cts +0 -16
- package/dist/utils/amountConversion.d.cts.map +0 -1
- package/dist/utils/amountConversion.d.mts +0 -16
- package/dist/utils/amountConversion.d.mts.map +0 -1
- package/dist/utils/amountConversion.mjs +0 -54
- package/dist/utils/amountConversion.mjs.map +0 -1
- package/dist/utils/chartUtils.cjs +0 -98
- package/dist/utils/chartUtils.cjs.map +0 -1
- package/dist/utils/chartUtils.d.cts +0 -14
- package/dist/utils/chartUtils.d.cts.map +0 -1
- package/dist/utils/chartUtils.d.mts +0 -14
- package/dist/utils/chartUtils.d.mts.map +0 -1
- package/dist/utils/chartUtils.mjs +0 -94
- package/dist/utils/chartUtils.mjs.map +0 -1
- package/dist/utils/errorUtils.cjs +0 -22
- package/dist/utils/errorUtils.cjs.map +0 -1
- package/dist/utils/errorUtils.d.cts +0 -13
- package/dist/utils/errorUtils.d.cts.map +0 -1
- package/dist/utils/errorUtils.d.mts +0 -13
- package/dist/utils/errorUtils.d.mts.map +0 -1
- package/dist/utils/errorUtils.mjs +0 -18
- package/dist/utils/errorUtils.mjs.map +0 -1
- package/dist/utils/formatUtils.cjs +0 -987
- package/dist/utils/formatUtils.cjs.map +0 -1
- package/dist/utils/formatUtils.d.cts +0 -387
- package/dist/utils/formatUtils.d.cts.map +0 -1
- package/dist/utils/formatUtils.d.mts +0 -387
- package/dist/utils/formatUtils.d.mts.map +0 -1
- package/dist/utils/formatUtils.mjs +0 -966
- package/dist/utils/formatUtils.mjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.cjs +0 -454
- package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.mjs +0 -439
- package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -89
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -84
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.cjs +0 -426
- package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.cts +0 -143
- package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.mts +0 -143
- package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
- package/dist/utils/hyperLiquidValidation.mjs +0 -413
- package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
- package/dist/utils/idUtils.cjs +0 -50
- package/dist/utils/idUtils.cjs.map +0 -1
- package/dist/utils/idUtils.d.cts +0 -38
- package/dist/utils/idUtils.d.cts.map +0 -1
- package/dist/utils/idUtils.d.mts +0 -38
- package/dist/utils/idUtils.d.mts.map +0 -1
- package/dist/utils/idUtils.mjs +0 -42
- package/dist/utils/idUtils.mjs.map +0 -1
- package/dist/utils/marginUtils.cjs +0 -137
- package/dist/utils/marginUtils.cjs.map +0 -1
- package/dist/utils/marginUtils.d.cts +0 -64
- package/dist/utils/marginUtils.d.cts.map +0 -1
- package/dist/utils/marginUtils.d.mts +0 -64
- package/dist/utils/marginUtils.d.mts.map +0 -1
- package/dist/utils/marginUtils.mjs +0 -131
- package/dist/utils/marginUtils.mjs.map +0 -1
- package/dist/utils/marketDataTransform.cjs +0 -227
- package/dist/utils/marketDataTransform.cjs.map +0 -1
- package/dist/utils/marketDataTransform.d.cts +0 -45
- package/dist/utils/marketDataTransform.d.cts.map +0 -1
- package/dist/utils/marketDataTransform.d.mts +0 -45
- package/dist/utils/marketDataTransform.d.mts.map +0 -1
- package/dist/utils/marketDataTransform.mjs +0 -220
- package/dist/utils/marketDataTransform.mjs.map +0 -1
- package/dist/utils/marketUtils.cjs +0 -420
- package/dist/utils/marketUtils.cjs.map +0 -1
- package/dist/utils/marketUtils.d.cts +0 -227
- package/dist/utils/marketUtils.d.cts.map +0 -1
- package/dist/utils/marketUtils.d.mts +0 -227
- package/dist/utils/marketUtils.d.mts.map +0 -1
- package/dist/utils/marketUtils.mjs +0 -404
- package/dist/utils/marketUtils.mjs.map +0 -1
- package/dist/utils/orderBookGrouping.cjs +0 -151
- package/dist/utils/orderBookGrouping.cjs.map +0 -1
- package/dist/utils/orderBookGrouping.d.cts +0 -76
- package/dist/utils/orderBookGrouping.d.cts.map +0 -1
- package/dist/utils/orderBookGrouping.d.mts +0 -76
- package/dist/utils/orderBookGrouping.d.mts.map +0 -1
- package/dist/utils/orderBookGrouping.mjs +0 -143
- package/dist/utils/orderBookGrouping.mjs.map +0 -1
- package/dist/utils/orderCalculations.cjs +0 -283
- package/dist/utils/orderCalculations.cjs.map +0 -1
- package/dist/utils/orderCalculations.d.cts +0 -107
- package/dist/utils/orderCalculations.d.cts.map +0 -1
- package/dist/utils/orderCalculations.d.mts +0 -107
- package/dist/utils/orderCalculations.d.mts.map +0 -1
- package/dist/utils/orderCalculations.mjs +0 -274
- package/dist/utils/orderCalculations.mjs.map +0 -1
- package/dist/utils/orderUtils.cjs +0 -159
- package/dist/utils/orderUtils.cjs.map +0 -1
- package/dist/utils/orderUtils.d.cts +0 -66
- package/dist/utils/orderUtils.d.cts.map +0 -1
- package/dist/utils/orderUtils.d.mts +0 -66
- package/dist/utils/orderUtils.d.mts.map +0 -1
- package/dist/utils/orderUtils.mjs +0 -151
- package/dist/utils/orderUtils.mjs.map +0 -1
- package/dist/utils/pnlCalculations.cjs +0 -107
- package/dist/utils/pnlCalculations.cjs.map +0 -1
- package/dist/utils/pnlCalculations.d.cts +0 -79
- package/dist/utils/pnlCalculations.d.cts.map +0 -1
- package/dist/utils/pnlCalculations.d.mts +0 -79
- package/dist/utils/pnlCalculations.d.mts.map +0 -1
- package/dist/utils/pnlCalculations.mjs +0 -97
- package/dist/utils/pnlCalculations.mjs.map +0 -1
- package/dist/utils/positionCalculations.cjs +0 -176
- package/dist/utils/positionCalculations.cjs.map +0 -1
- package/dist/utils/positionCalculations.d.cts +0 -85
- package/dist/utils/positionCalculations.d.cts.map +0 -1
- package/dist/utils/positionCalculations.d.mts +0 -85
- package/dist/utils/positionCalculations.d.mts.map +0 -1
- package/dist/utils/positionCalculations.mjs +0 -165
- package/dist/utils/positionCalculations.mjs.map +0 -1
- package/dist/utils/sortMarkets.cjs +0 -88
- package/dist/utils/sortMarkets.cjs.map +0 -1
- package/dist/utils/sortMarkets.d.cts +0 -21
- package/dist/utils/sortMarkets.d.cts.map +0 -1
- package/dist/utils/sortMarkets.d.mts +0 -21
- package/dist/utils/sortMarkets.d.mts.map +0 -1
- package/dist/utils/sortMarkets.mjs +0 -84
- package/dist/utils/sortMarkets.mjs.map +0 -1
- package/dist/utils/standaloneInfoClient.cjs +0 -34
- package/dist/utils/standaloneInfoClient.cjs.map +0 -1
- package/dist/utils/standaloneInfoClient.d.cts +0 -31
- package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
- package/dist/utils/standaloneInfoClient.d.mts +0 -31
- package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
- package/dist/utils/standaloneInfoClient.mjs +0 -30
- package/dist/utils/standaloneInfoClient.mjs.map +0 -1
- package/dist/utils/stringParseUtils.cjs +0 -49
- package/dist/utils/stringParseUtils.cjs.map +0 -1
- package/dist/utils/stringParseUtils.d.cts +0 -35
- package/dist/utils/stringParseUtils.d.cts.map +0 -1
- package/dist/utils/stringParseUtils.d.mts +0 -35
- package/dist/utils/stringParseUtils.d.mts.map +0 -1
- package/dist/utils/stringParseUtils.mjs +0 -44
- package/dist/utils/stringParseUtils.mjs.map +0 -1
- package/dist/utils/time.cjs +0 -37
- package/dist/utils/time.cjs.map +0 -1
- package/dist/utils/time.d.cts +0 -17
- package/dist/utils/time.d.cts.map +0 -1
- package/dist/utils/time.d.mts +0 -17
- package/dist/utils/time.d.mts.map +0 -1
- package/dist/utils/time.mjs +0 -33
- package/dist/utils/time.mjs.map +0 -1
- package/dist/utils/tpslValidation.cjs +0 -505
- package/dist/utils/tpslValidation.cjs.map +0 -1
- package/dist/utils/tpslValidation.d.cts +0 -182
- package/dist/utils/tpslValidation.d.cts.map +0 -1
- package/dist/utils/tpslValidation.d.mts +0 -182
- package/dist/utils/tpslValidation.d.mts.map +0 -1
- package/dist/utils/tpslValidation.mjs +0 -482
- package/dist/utils/tpslValidation.mjs.map +0 -1
- package/dist/utils/transactionUtils.cjs +0 -36
- package/dist/utils/transactionUtils.cjs.map +0 -1
- package/dist/utils/transactionUtils.d.cts +0 -17
- package/dist/utils/transactionUtils.d.cts.map +0 -1
- package/dist/utils/transactionUtils.d.mts +0 -17
- package/dist/utils/transactionUtils.d.mts.map +0 -1
- package/dist/utils/transactionUtils.mjs +0 -32
- package/dist/utils/transactionUtils.mjs.map +0 -1
- package/dist/utils/wait.cjs +0 -12
- package/dist/utils/wait.cjs.map +0 -1
- package/dist/utils/wait.d.cts +0 -8
- package/dist/utils/wait.d.cts.map +0 -1
- package/dist/utils/wait.d.mts +0 -8
- package/dist/utils/wait.d.mts.map +0 -1
- package/dist/utils/wait.mjs +0 -8
- package/dist/utils/wait.mjs.map +0 -1
|
@@ -1,857 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _HyperLiquidClientService_instances, _HyperLiquidClientService_exchangeClient, _HyperLiquidClientService_infoClient, _HyperLiquidClientService_infoClientHttp, _HyperLiquidClientService_subscriptionClient, _HyperLiquidClientService_wsTransport, _HyperLiquidClientService_httpTransport, _HyperLiquidClientService_isTestnet, _HyperLiquidClientService_connectionState, _HyperLiquidClientService_disconnectionPromise, _HyperLiquidClientService_onTerminateCallback, _HyperLiquidClientService_onReconnectCallback, _HyperLiquidClientService_reconnectionAttempt, _HyperLiquidClientService_connectionStateListeners, _HyperLiquidClientService_reconnectionRetryTimeout, _HyperLiquidClientService_deps, _HyperLiquidClientService_isReconnecting, _HyperLiquidClientService_createTransports, _HyperLiquidClientService_getIntervalMilliseconds, _HyperLiquidClientService_performDisconnection, _HyperLiquidClientService_updateConnectionState, _HyperLiquidClientService_notifyConnectionStateListeners, _HyperLiquidClientService_handleConnectionDrop;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.HyperLiquidClientService = exports.WebSocketConnectionState = void 0;
|
|
16
|
-
const hyperliquid_1 = require("@nktkas/hyperliquid");
|
|
17
|
-
const hyperLiquidConfig_1 = require("../constants/hyperLiquidConfig.cjs");
|
|
18
|
-
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
19
|
-
const perpsErrorCodes_1 = require("../constants/perpsErrorCodes.cjs");
|
|
20
|
-
const chartUtils_1 = require("../utils/chartUtils.cjs");
|
|
21
|
-
/**
|
|
22
|
-
* Ensures we have a proper Error object for logging.
|
|
23
|
-
* Converts unknown/string errors to proper Error instances.
|
|
24
|
-
*
|
|
25
|
-
* @param error - The caught error (could be Error, string, or unknown)
|
|
26
|
-
* @returns A proper Error instance
|
|
27
|
-
*/
|
|
28
|
-
function ensureError(error) {
|
|
29
|
-
if (error instanceof Error) {
|
|
30
|
-
return error;
|
|
31
|
-
}
|
|
32
|
-
return new Error(String(error));
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Connection states for WebSocket management
|
|
36
|
-
*/
|
|
37
|
-
var WebSocketConnectionState;
|
|
38
|
-
(function (WebSocketConnectionState) {
|
|
39
|
-
WebSocketConnectionState["Disconnected"] = "disconnected";
|
|
40
|
-
WebSocketConnectionState["Connecting"] = "connecting";
|
|
41
|
-
WebSocketConnectionState["Connected"] = "connected";
|
|
42
|
-
WebSocketConnectionState["Disconnecting"] = "disconnecting";
|
|
43
|
-
})(WebSocketConnectionState || (exports.WebSocketConnectionState = WebSocketConnectionState = {}));
|
|
44
|
-
/**
|
|
45
|
-
* Maximum number of reconnection attempts before giving up
|
|
46
|
-
*/
|
|
47
|
-
const MAX_RECONNECTION_ATTEMPTS = 10;
|
|
48
|
-
/**
|
|
49
|
-
* Service for managing HyperLiquid SDK clients
|
|
50
|
-
* Handles initialization, transport creation, and client lifecycle
|
|
51
|
-
*/
|
|
52
|
-
class HyperLiquidClientService {
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new HyperLiquidClientService instance.
|
|
55
|
-
*
|
|
56
|
-
* @param deps - Platform dependencies for logging
|
|
57
|
-
* @param options - Configuration options
|
|
58
|
-
* @param options.isTestnet - Whether to use testnet mode
|
|
59
|
-
*/
|
|
60
|
-
constructor(deps, options = {}) {
|
|
61
|
-
_HyperLiquidClientService_instances.add(this);
|
|
62
|
-
_HyperLiquidClientService_exchangeClient.set(this, void 0);
|
|
63
|
-
_HyperLiquidClientService_infoClient.set(this, void 0); // WebSocket transport (default)
|
|
64
|
-
_HyperLiquidClientService_infoClientHttp.set(this, void 0); // HTTP transport (fallback)
|
|
65
|
-
_HyperLiquidClientService_subscriptionClient.set(this, void 0);
|
|
66
|
-
_HyperLiquidClientService_wsTransport.set(this, void 0);
|
|
67
|
-
_HyperLiquidClientService_httpTransport.set(this, void 0);
|
|
68
|
-
_HyperLiquidClientService_isTestnet.set(this, void 0);
|
|
69
|
-
_HyperLiquidClientService_connectionState.set(this, WebSocketConnectionState.Disconnected);
|
|
70
|
-
_HyperLiquidClientService_disconnectionPromise.set(this, null);
|
|
71
|
-
// Callback for SDK terminate event (fired when all reconnection attempts exhausted)
|
|
72
|
-
_HyperLiquidClientService_onTerminateCallback.set(this, null);
|
|
73
|
-
_HyperLiquidClientService_onReconnectCallback.set(this, void 0);
|
|
74
|
-
// Reconnection attempt counter
|
|
75
|
-
_HyperLiquidClientService_reconnectionAttempt.set(this, 0);
|
|
76
|
-
// Connection state change listeners for event-based notifications
|
|
77
|
-
_HyperLiquidClientService_connectionStateListeners.set(this, new Set());
|
|
78
|
-
// Timeout reference for reconnection retry, tracked to enable cancellation on disconnect
|
|
79
|
-
_HyperLiquidClientService_reconnectionRetryTimeout.set(this, null);
|
|
80
|
-
// Platform dependencies for logging
|
|
81
|
-
_HyperLiquidClientService_deps.set(this, void 0);
|
|
82
|
-
// Flag to prevent concurrent reconnection attempts
|
|
83
|
-
_HyperLiquidClientService_isReconnecting.set(this, false);
|
|
84
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_deps, deps, "f");
|
|
85
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, options.isTestnet ?? false, "f");
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Initialize all HyperLiquid SDK clients
|
|
89
|
-
*
|
|
90
|
-
* IMPORTANT: This method awaits transport.ready() to ensure the WebSocket is
|
|
91
|
-
* in OPEN state before marking initialization complete. This prevents race
|
|
92
|
-
* conditions where subscriptions are attempted before the WebSocket handshake
|
|
93
|
-
* completes (which would cause "subscribe error: undefined" errors).
|
|
94
|
-
*
|
|
95
|
-
* @param wallet - Wallet adapter with signTypedData capability
|
|
96
|
-
* @param wallet.address - The wallet address
|
|
97
|
-
* @param wallet.signTypedData - Function to sign typed data
|
|
98
|
-
* @param wallet.getChainId - Optional function to get chain ID
|
|
99
|
-
*/
|
|
100
|
-
async initialize(wallet) {
|
|
101
|
-
try {
|
|
102
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connecting);
|
|
103
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
|
|
104
|
-
// Ensure transports are created
|
|
105
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f") || !__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
|
|
106
|
-
throw new Error('Failed to create transports');
|
|
107
|
-
}
|
|
108
|
-
// Wallet adapter implements AbstractViemJsonRpcAccount interface with signTypedData method
|
|
109
|
-
// ExchangeClient uses HTTP transport for write operations (orders, approvals, etc.)
|
|
110
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, new hyperliquid_1.ExchangeClient({
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
-
wallet: wallet,
|
|
113
|
-
transport: __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f"),
|
|
114
|
-
}), "f");
|
|
115
|
-
// InfoClient with WebSocket transport (default) - multiplexed requests over single connection
|
|
116
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, new hyperliquid_1.InfoClient({ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f") }), "f");
|
|
117
|
-
// InfoClient with HTTP transport (fallback) - for specific calls if WebSocket has issues
|
|
118
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, new hyperliquid_1.InfoClient({ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f") }), "f");
|
|
119
|
-
// SubscriptionClient uses WebSocket transport for real-time pub/sub (price feeds, position updates)
|
|
120
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, new hyperliquid_1.SubscriptionClient({
|
|
121
|
-
transport: __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f"),
|
|
122
|
-
}), "f");
|
|
123
|
-
// Wait for WebSocket to actually be ready before setting CONNECTED
|
|
124
|
-
// This ensures we have a real connection, not just client objects
|
|
125
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").ready();
|
|
126
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connected);
|
|
127
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid SDK clients initialized', {
|
|
128
|
-
testnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
129
|
-
timestamp: new Date().toISOString(),
|
|
130
|
-
connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
|
|
131
|
-
note: 'Using WebSocket for InfoClient (default), HTTP fallback available',
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
// Cleanup on failure to prevent leaks and ensure isInitialized() returns false
|
|
136
|
-
// Clear clients first, then transports
|
|
137
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, undefined, "f");
|
|
138
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, undefined, "f");
|
|
139
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, undefined, "f");
|
|
140
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, undefined, "f");
|
|
141
|
-
// Close WebSocket transport to release resources and event listeners
|
|
142
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
|
|
143
|
-
try {
|
|
144
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
// Ignore cleanup errors
|
|
148
|
-
}
|
|
149
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
|
|
150
|
-
}
|
|
151
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
|
|
152
|
-
const errorInstance = ensureError(error);
|
|
153
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
154
|
-
// Log to Sentry: initialization failure blocks all Perps functionality
|
|
155
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
156
|
-
tags: {
|
|
157
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
158
|
-
service: 'HyperLiquidClientService',
|
|
159
|
-
network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
|
|
160
|
-
},
|
|
161
|
-
context: {
|
|
162
|
-
name: 'sdk_initialization',
|
|
163
|
-
data: {
|
|
164
|
-
operation: 'initialize',
|
|
165
|
-
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Toggle testnet mode and reinitialize clients
|
|
174
|
-
*
|
|
175
|
-
* @param wallet - Wallet adapter with signTypedData capability
|
|
176
|
-
* @param wallet.address - The wallet address
|
|
177
|
-
* @param wallet.signTypedData - Function to sign typed data
|
|
178
|
-
* @param wallet.getChainId - Optional function to get chain ID
|
|
179
|
-
* @returns The new network mode
|
|
180
|
-
*/
|
|
181
|
-
async toggleTestnet(wallet) {
|
|
182
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, !__classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"), "f");
|
|
183
|
-
await this.initialize(wallet);
|
|
184
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Check if clients are properly initialized
|
|
188
|
-
*
|
|
189
|
-
* @returns True if all clients are initialized
|
|
190
|
-
*/
|
|
191
|
-
isInitialized() {
|
|
192
|
-
return Boolean(__classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f") &&
|
|
193
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f") &&
|
|
194
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f") &&
|
|
195
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f"));
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Ensure clients are initialized, throw if not
|
|
199
|
-
*/
|
|
200
|
-
ensureInitialized() {
|
|
201
|
-
if (!this.isInitialized()) {
|
|
202
|
-
throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.CLIENT_NOT_INITIALIZED);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Recreate subscription client if needed (for reconnection scenarios)
|
|
207
|
-
*
|
|
208
|
-
* @param wallet - Wallet adapter with signTypedData capability
|
|
209
|
-
* @param wallet.address - The wallet address
|
|
210
|
-
* @param wallet.signTypedData - Function to sign typed data
|
|
211
|
-
* @param wallet.getChainId - Optional function to get chain ID
|
|
212
|
-
*/
|
|
213
|
-
async ensureSubscriptionClient(wallet) {
|
|
214
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f")) {
|
|
215
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Recreating subscription client after disconnect');
|
|
216
|
-
await this.initialize(wallet);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Get the exchange client
|
|
221
|
-
*
|
|
222
|
-
* @returns The exchange client
|
|
223
|
-
*/
|
|
224
|
-
getExchangeClient() {
|
|
225
|
-
this.ensureInitialized();
|
|
226
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f")) {
|
|
227
|
-
throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.EXCHANGE_CLIENT_NOT_AVAILABLE);
|
|
228
|
-
}
|
|
229
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f");
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Get the info client
|
|
233
|
-
*
|
|
234
|
-
* @param options - Options for client selection
|
|
235
|
-
* @param options.useHttp - Force HTTP transport instead of WebSocket (default: false)
|
|
236
|
-
* @returns InfoClient instance with the selected transport
|
|
237
|
-
*/
|
|
238
|
-
getInfoClient(options) {
|
|
239
|
-
this.ensureInitialized();
|
|
240
|
-
if (options?.useHttp) {
|
|
241
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f")) {
|
|
242
|
-
throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
|
|
243
|
-
}
|
|
244
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f");
|
|
245
|
-
}
|
|
246
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f")) {
|
|
247
|
-
throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
|
|
248
|
-
}
|
|
249
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f");
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Get the subscription client
|
|
253
|
-
*
|
|
254
|
-
* @returns The subscription client or undefined if not initialized
|
|
255
|
-
*/
|
|
256
|
-
getSubscriptionClient() {
|
|
257
|
-
if (!__classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f")) {
|
|
258
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('SubscriptionClient not initialized');
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
261
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f");
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Ensures the WebSocket transport is in OPEN state and ready for subscriptions.
|
|
265
|
-
* This MUST be called before any subscription operations to prevent race conditions.
|
|
266
|
-
*
|
|
267
|
-
* The SDK's `transport.ready()` method:
|
|
268
|
-
* - Returns immediately if WebSocket is already in OPEN state
|
|
269
|
-
* - Waits for the "open" event if WebSocket is in CONNECTING state
|
|
270
|
-
* - Supports AbortSignal for timeout/cancellation
|
|
271
|
-
*
|
|
272
|
-
* @param timeoutMs - Maximum time to wait for transport ready (default 5000ms)
|
|
273
|
-
* @throws Error if transport not ready within timeout or subscription client unavailable
|
|
274
|
-
*/
|
|
275
|
-
async ensureTransportReady(timeoutMs = 5000) {
|
|
276
|
-
const subscriptionClient = this.getSubscriptionClient();
|
|
277
|
-
if (!subscriptionClient) {
|
|
278
|
-
throw new Error('Subscription client not initialized');
|
|
279
|
-
}
|
|
280
|
-
const controller = new AbortController();
|
|
281
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
282
|
-
try {
|
|
283
|
-
await subscriptionClient.config_.transport.ready(controller.signal);
|
|
284
|
-
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
if (controller.signal.aborted) {
|
|
287
|
-
throw new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`);
|
|
288
|
-
}
|
|
289
|
-
throw error;
|
|
290
|
-
}
|
|
291
|
-
finally {
|
|
292
|
-
clearTimeout(timeoutId);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Get current network state
|
|
297
|
-
*
|
|
298
|
-
* @returns The current network ('mainnet' or 'testnet')
|
|
299
|
-
*/
|
|
300
|
-
getNetwork() {
|
|
301
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Check if running on testnet
|
|
305
|
-
*
|
|
306
|
-
* @returns True if running on testnet
|
|
307
|
-
*/
|
|
308
|
-
isTestnetMode() {
|
|
309
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f");
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Update testnet mode
|
|
313
|
-
*
|
|
314
|
-
* @param testnet - Whether to use testnet
|
|
315
|
-
*/
|
|
316
|
-
setTestnetMode(testnet) {
|
|
317
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, testnet, "f");
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Fetch historical candle data using the HyperLiquid SDK
|
|
321
|
-
*
|
|
322
|
-
* @param symbol - The asset symbol (e.g., "BTC", "ETH")
|
|
323
|
-
* @param interval - The interval (e.g., "1m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M")
|
|
324
|
-
* @param limit - Number of candles to fetch (default: 100)
|
|
325
|
-
* @param endTime - End timestamp in milliseconds (default: now). Used for fetching historical data before a specific time.
|
|
326
|
-
* @returns Promise resolving to CandleData or null
|
|
327
|
-
*/
|
|
328
|
-
async fetchHistoricalCandles(symbol, interval, limit = 100, endTime) {
|
|
329
|
-
this.ensureInitialized();
|
|
330
|
-
try {
|
|
331
|
-
// Calculate start and end times based on interval and limit
|
|
332
|
-
const now = endTime ?? Date.now();
|
|
333
|
-
const intervalMs = __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_getIntervalMilliseconds).call(this, interval);
|
|
334
|
-
const startTime = now - limit * intervalMs;
|
|
335
|
-
// Use the SDK's InfoClient to fetch candle data
|
|
336
|
-
// HyperLiquid SDK uses 'coin' terminology
|
|
337
|
-
const infoClient = this.getInfoClient();
|
|
338
|
-
const data = await infoClient.candleSnapshot({
|
|
339
|
-
coin: symbol, // Map to HyperLiquid SDK's 'coin' parameter
|
|
340
|
-
interval,
|
|
341
|
-
startTime,
|
|
342
|
-
endTime: now,
|
|
343
|
-
});
|
|
344
|
-
// Transform API response to match expected format
|
|
345
|
-
if (Array.isArray(data) && data.length > 0) {
|
|
346
|
-
const candles = data.map((candle) => ({
|
|
347
|
-
time: candle.t, // open time
|
|
348
|
-
open: candle.o.toString(),
|
|
349
|
-
high: candle.h.toString(),
|
|
350
|
-
low: candle.l.toString(),
|
|
351
|
-
close: candle.c.toString(),
|
|
352
|
-
volume: candle.v.toString(),
|
|
353
|
-
}));
|
|
354
|
-
return {
|
|
355
|
-
symbol,
|
|
356
|
-
interval,
|
|
357
|
-
candles,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
return {
|
|
361
|
-
symbol,
|
|
362
|
-
interval,
|
|
363
|
-
candles: [],
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
catch (error) {
|
|
367
|
-
const errorInstance = ensureError(error);
|
|
368
|
-
// Log to Sentry: prevents initial chart data load
|
|
369
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
370
|
-
tags: {
|
|
371
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
372
|
-
service: 'HyperLiquidClientService',
|
|
373
|
-
network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
|
|
374
|
-
},
|
|
375
|
-
context: {
|
|
376
|
-
name: 'historical_candles_api',
|
|
377
|
-
data: {
|
|
378
|
-
operation: 'fetchHistoricalCandles',
|
|
379
|
-
symbol,
|
|
380
|
-
interval,
|
|
381
|
-
limit,
|
|
382
|
-
hasEndTime: endTime !== undefined,
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
throw error;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Subscribe to candle updates via WebSocket
|
|
391
|
-
*
|
|
392
|
-
* @param params - Subscription parameters
|
|
393
|
-
* @param params.symbol - The asset symbol (e.g., "BTC", "ETH")
|
|
394
|
-
* @param params.interval - The interval (e.g., "1m", "5m", "15m", etc.)
|
|
395
|
-
* @param params.duration - Optional time duration for calculating initial fetch size
|
|
396
|
-
* @param params.callback - Function called with updated candle data
|
|
397
|
-
* @param params.onError - Optional function called if subscription initialization fails
|
|
398
|
-
* @returns Cleanup function to unsubscribe
|
|
399
|
-
*/
|
|
400
|
-
subscribeToCandles({ symbol, interval, duration, callback, onError, }) {
|
|
401
|
-
this.ensureInitialized();
|
|
402
|
-
const subscriptionClient = this.getSubscriptionClient();
|
|
403
|
-
if (!subscriptionClient) {
|
|
404
|
-
throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.SUBSCRIPTION_CLIENT_NOT_AVAILABLE);
|
|
405
|
-
}
|
|
406
|
-
let currentCandleData = null;
|
|
407
|
-
let wsUnsubscribe = null;
|
|
408
|
-
let isUnsubscribed = false;
|
|
409
|
-
// Calculate initial fetch size dynamically based on duration and interval
|
|
410
|
-
// Match main branch behavior: up to 500 candles initially
|
|
411
|
-
const initialLimit = duration
|
|
412
|
-
? Math.min((0, chartUtils_1.calculateCandleCount)(duration, interval), 500)
|
|
413
|
-
: 100; // Default to 100 if no duration provided
|
|
414
|
-
// Helper to handle candle event updates
|
|
415
|
-
const handleCandleEvent = (candleEvent) => {
|
|
416
|
-
// Don't process events if already unsubscribed
|
|
417
|
-
if (isUnsubscribed) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
// Transform SDK CandleEvent to our Candle format
|
|
421
|
-
const newCandle = {
|
|
422
|
-
time: candleEvent.t,
|
|
423
|
-
open: candleEvent.o.toString(),
|
|
424
|
-
high: candleEvent.h.toString(),
|
|
425
|
-
low: candleEvent.l.toString(),
|
|
426
|
-
close: candleEvent.c.toString(),
|
|
427
|
-
volume: candleEvent.v.toString(),
|
|
428
|
-
};
|
|
429
|
-
if (currentCandleData) {
|
|
430
|
-
// Check if this is an update to the last candle or a new candle
|
|
431
|
-
const { candles } = currentCandleData;
|
|
432
|
-
const lastCandle = candles[candles.length - 1];
|
|
433
|
-
if (lastCandle && lastCandle.time === newCandle.time) {
|
|
434
|
-
// Update existing candle (live candle update)
|
|
435
|
-
currentCandleData = {
|
|
436
|
-
...currentCandleData,
|
|
437
|
-
candles: [...candles.slice(0, -1), newCandle],
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
// New candle (completed candle)
|
|
442
|
-
currentCandleData = {
|
|
443
|
-
...currentCandleData,
|
|
444
|
-
candles: [...candles, newCandle],
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
currentCandleData = {
|
|
450
|
-
symbol,
|
|
451
|
-
interval,
|
|
452
|
-
candles: [newCandle],
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
callback(currentCandleData);
|
|
456
|
-
};
|
|
457
|
-
// Helper to handle subscription setup
|
|
458
|
-
const setupSubscription = async () => {
|
|
459
|
-
try {
|
|
460
|
-
// 1. Fetch initial historical data
|
|
461
|
-
const initialData = await this.fetchHistoricalCandles(symbol, interval, initialLimit);
|
|
462
|
-
// Don't proceed if already unsubscribed
|
|
463
|
-
if (isUnsubscribed) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
currentCandleData = initialData;
|
|
467
|
-
if (currentCandleData) {
|
|
468
|
-
callback(currentCandleData);
|
|
469
|
-
}
|
|
470
|
-
// 2. Subscribe to WebSocket for new candles
|
|
471
|
-
const sub = await subscriptionClient.candle({ coin: symbol, interval }, handleCandleEvent);
|
|
472
|
-
wsUnsubscribe = () => {
|
|
473
|
-
sub.unsubscribe().catch(() => {
|
|
474
|
-
// Ignore unsubscribe errors
|
|
475
|
-
});
|
|
476
|
-
};
|
|
477
|
-
// If already unsubscribed while waiting, clean up immediately
|
|
478
|
-
if (isUnsubscribed && wsUnsubscribe) {
|
|
479
|
-
wsUnsubscribe();
|
|
480
|
-
wsUnsubscribe = null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
const errorInstance = ensureError(error);
|
|
485
|
-
// Log to Sentry
|
|
486
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
|
|
487
|
-
tags: {
|
|
488
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
489
|
-
service: 'HyperLiquidClientService',
|
|
490
|
-
network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
|
|
491
|
-
},
|
|
492
|
-
context: {
|
|
493
|
-
name: 'candle_subscription',
|
|
494
|
-
data: {
|
|
495
|
-
operation: 'subscribeToCandles',
|
|
496
|
-
symbol,
|
|
497
|
-
interval,
|
|
498
|
-
initialLimit,
|
|
499
|
-
},
|
|
500
|
-
},
|
|
501
|
-
});
|
|
502
|
-
// Notify caller of error
|
|
503
|
-
onError?.(errorInstance);
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
// Start the subscription setup (fire and forget with proper error handling)
|
|
507
|
-
setupSubscription().catch(() => {
|
|
508
|
-
// Errors are already handled in setupSubscription
|
|
509
|
-
});
|
|
510
|
-
// Return cleanup function
|
|
511
|
-
return () => {
|
|
512
|
-
isUnsubscribed = true;
|
|
513
|
-
if (wsUnsubscribe) {
|
|
514
|
-
wsUnsubscribe();
|
|
515
|
-
wsUnsubscribe = null;
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Disconnect and cleanup all clients
|
|
521
|
-
*
|
|
522
|
-
* @returns Promise that resolves when disconnection is complete
|
|
523
|
-
*/
|
|
524
|
-
async disconnect() {
|
|
525
|
-
// Return existing promise if already disconnecting
|
|
526
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f")) {
|
|
527
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f");
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
// If already disconnected, return immediately
|
|
531
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
// Create and store the disconnection promise
|
|
535
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_disconnectionPromise, __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_performDisconnection).call(this), "f");
|
|
536
|
-
try {
|
|
537
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f");
|
|
538
|
-
}
|
|
539
|
-
finally {
|
|
540
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_disconnectionPromise, null, "f");
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Get current WebSocket connection state
|
|
545
|
-
*
|
|
546
|
-
* @returns The current connection state
|
|
547
|
-
*/
|
|
548
|
-
getConnectionState() {
|
|
549
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f");
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Check if WebSocket is fully disconnected
|
|
553
|
-
*
|
|
554
|
-
* @returns True if disconnected
|
|
555
|
-
*/
|
|
556
|
-
isDisconnected() {
|
|
557
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Set callback to be invoked when reconnection is needed
|
|
561
|
-
* This allows the service to notify external components (like PerpsConnectionManager)
|
|
562
|
-
* when a connection drop is detected
|
|
563
|
-
*
|
|
564
|
-
* @param callback - Callback to invoke on reconnection
|
|
565
|
-
*/
|
|
566
|
-
setOnReconnectCallback(callback) {
|
|
567
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_onReconnectCallback, callback, "f");
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Set callback for WebSocket termination events
|
|
571
|
-
* Called when the SDK exhausts all reconnection attempts
|
|
572
|
-
*
|
|
573
|
-
* @param callback - Callback to invoke on termination
|
|
574
|
-
*/
|
|
575
|
-
setOnTerminateCallback(callback) {
|
|
576
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_onTerminateCallback, callback, "f");
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Subscribe to connection state changes.
|
|
580
|
-
* The listener will be called immediately with the current state and whenever the state changes.
|
|
581
|
-
*
|
|
582
|
-
* @param listener - Callback function that receives the new connection state and reconnection attempt
|
|
583
|
-
* @returns Unsubscribe function to remove the listener
|
|
584
|
-
*/
|
|
585
|
-
subscribeToConnectionState(listener) {
|
|
586
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").add(listener);
|
|
587
|
-
// Immediately notify with current state
|
|
588
|
-
// Wrap in try-catch to match notifyConnectionStateListeners behavior
|
|
589
|
-
// This ensures the unsubscribe function is always returned even if listener throws
|
|
590
|
-
try {
|
|
591
|
-
listener(__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"), __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"));
|
|
592
|
-
}
|
|
593
|
-
catch {
|
|
594
|
-
// Ignore errors in listeners to prevent breaking subscription mechanism
|
|
595
|
-
// If listener throws, it will be removed when unsubscribe is called
|
|
596
|
-
}
|
|
597
|
-
// Return unsubscribe function
|
|
598
|
-
return () => {
|
|
599
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").delete(listener);
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Manually trigger a reconnection attempt.
|
|
604
|
-
* This is exposed for UI retry buttons when user wants to force reconnection.
|
|
605
|
-
* Resets the reconnection attempt counter to allow retrying after max attempts.
|
|
606
|
-
*
|
|
607
|
-
* @returns Promise that resolves when reconnection attempt is complete
|
|
608
|
-
*/
|
|
609
|
-
async reconnect() {
|
|
610
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('[HyperLiquidClientService] reconnect() called', {
|
|
611
|
-
previousAttempt: __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"),
|
|
612
|
-
currentState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
|
|
613
|
-
});
|
|
614
|
-
// Reset attempt counter when user manually triggers retry
|
|
615
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, 0, "f");
|
|
616
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_handleConnectionDrop).call(this);
|
|
617
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('[HyperLiquidClientService] reconnect() completed', {
|
|
618
|
-
newState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
exports.HyperLiquidClientService = HyperLiquidClientService;
|
|
623
|
-
_HyperLiquidClientService_exchangeClient = new WeakMap(), _HyperLiquidClientService_infoClient = new WeakMap(), _HyperLiquidClientService_infoClientHttp = new WeakMap(), _HyperLiquidClientService_subscriptionClient = new WeakMap(), _HyperLiquidClientService_wsTransport = new WeakMap(), _HyperLiquidClientService_httpTransport = new WeakMap(), _HyperLiquidClientService_isTestnet = new WeakMap(), _HyperLiquidClientService_connectionState = new WeakMap(), _HyperLiquidClientService_disconnectionPromise = new WeakMap(), _HyperLiquidClientService_onTerminateCallback = new WeakMap(), _HyperLiquidClientService_onReconnectCallback = new WeakMap(), _HyperLiquidClientService_reconnectionAttempt = new WeakMap(), _HyperLiquidClientService_connectionStateListeners = new WeakMap(), _HyperLiquidClientService_reconnectionRetryTimeout = new WeakMap(), _HyperLiquidClientService_deps = new WeakMap(), _HyperLiquidClientService_isReconnecting = new WeakMap(), _HyperLiquidClientService_instances = new WeakSet(), _HyperLiquidClientService_createTransports = function _HyperLiquidClientService_createTransports() {
|
|
624
|
-
// Prevent duplicate transport creation and listener accumulation
|
|
625
|
-
// This guards against re-entry if initialize() is called multiple times
|
|
626
|
-
// (e.g., after a failed initialization attempt that didn't properly clean up)
|
|
627
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f") && __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f")) {
|
|
628
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Transports already exist, skipping creation');
|
|
629
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f");
|
|
630
|
-
}
|
|
631
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Creating transports', {
|
|
632
|
-
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
633
|
-
timestamp: new Date().toISOString(),
|
|
634
|
-
note: 'SDK will auto-select endpoints based on isTestnet flag',
|
|
635
|
-
});
|
|
636
|
-
// HTTP transport for request/response operations (InfoClient, ExchangeClient)
|
|
637
|
-
// SDK automatically selects: mainnet (https://api.hyperliquid.xyz) or testnet (https://api.hyperliquid-testnet.xyz)
|
|
638
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, new hyperliquid_1.HttpTransport({
|
|
639
|
-
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
640
|
-
timeout: hyperLiquidConfig_1.HYPERLIQUID_TRANSPORT_CONFIG.timeout,
|
|
641
|
-
}), "f");
|
|
642
|
-
// WebSocket transport for real-time subscriptions (SubscriptionClient)
|
|
643
|
-
// SDK automatically selects: mainnet (wss://api.hyperliquid.xyz/ws) or testnet (wss://api.hyperliquid-testnet.xyz/ws)
|
|
644
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, new hyperliquid_1.WebSocketTransport({
|
|
645
|
-
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
646
|
-
...hyperLiquidConfig_1.HYPERLIQUID_TRANSPORT_CONFIG,
|
|
647
|
-
reconnect: {
|
|
648
|
-
...hyperLiquidConfig_1.HYPERLIQUID_TRANSPORT_CONFIG.reconnect,
|
|
649
|
-
// Use globalThis.WebSocket for cross-platform compatibility (Node.js and browser)
|
|
650
|
-
WebSocket: globalThis.WebSocket,
|
|
651
|
-
},
|
|
652
|
-
}), "f");
|
|
653
|
-
// Listen for WebSocket termination (fired when SDK exhausts all reconnection attempts)
|
|
654
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").socket.addEventListener('terminate', (event) => {
|
|
655
|
-
const customEvent = event;
|
|
656
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: WebSocket terminated', {
|
|
657
|
-
reason: customEvent.detail?.code,
|
|
658
|
-
timestamp: new Date().toISOString(),
|
|
659
|
-
});
|
|
660
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
661
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_onTerminateCallback, "f")) {
|
|
662
|
-
const terminateError = customEvent.detail instanceof Error
|
|
663
|
-
? customEvent.detail
|
|
664
|
-
: new Error(`WebSocket terminated: ${customEvent.detail?.code ?? 'unknown'}`);
|
|
665
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_onTerminateCallback, "f").call(this, terminateError);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
return __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f");
|
|
669
|
-
}, _HyperLiquidClientService_getIntervalMilliseconds = function _HyperLiquidClientService_getIntervalMilliseconds(interval) {
|
|
670
|
-
const intervalMap = {
|
|
671
|
-
'1m': 1 * 60 * 1000,
|
|
672
|
-
'3m': 3 * 60 * 1000,
|
|
673
|
-
'5m': 5 * 60 * 1000,
|
|
674
|
-
'15m': 15 * 60 * 1000,
|
|
675
|
-
'30m': 30 * 60 * 1000,
|
|
676
|
-
'1h': 60 * 60 * 1000,
|
|
677
|
-
'2h': 2 * 60 * 60 * 1000,
|
|
678
|
-
'4h': 4 * 60 * 60 * 1000,
|
|
679
|
-
'8h': 8 * 60 * 60 * 1000,
|
|
680
|
-
'12h': 12 * 60 * 60 * 1000,
|
|
681
|
-
'1d': 24 * 60 * 60 * 1000,
|
|
682
|
-
'3d': 3 * 24 * 60 * 60 * 1000,
|
|
683
|
-
'1w': 7 * 24 * 60 * 60 * 1000,
|
|
684
|
-
'1M': 30 * 24 * 60 * 60 * 1000, // Approximate
|
|
685
|
-
};
|
|
686
|
-
return intervalMap[interval] ?? 60 * 60 * 1000; // Default to 1 hour
|
|
687
|
-
}, _HyperLiquidClientService_performDisconnection =
|
|
688
|
-
/**
|
|
689
|
-
* Perform the actual disconnection
|
|
690
|
-
*/
|
|
691
|
-
async function _HyperLiquidClientService_performDisconnection() {
|
|
692
|
-
try {
|
|
693
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnecting);
|
|
694
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Disconnecting SDK clients', {
|
|
695
|
-
isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
|
|
696
|
-
timestamp: new Date().toISOString(),
|
|
697
|
-
connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
|
|
698
|
-
});
|
|
699
|
-
// Clear callbacks
|
|
700
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_onReconnectCallback, undefined, "f");
|
|
701
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_onTerminateCallback, null, "f");
|
|
702
|
-
// Cancel any pending reconnection retry timeout
|
|
703
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f")) {
|
|
704
|
-
clearTimeout(__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f"));
|
|
705
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f");
|
|
706
|
-
}
|
|
707
|
-
// Clear connection state listeners to prevent stale callbacks
|
|
708
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").clear();
|
|
709
|
-
// Reset reconnection flag to allow future manual retries
|
|
710
|
-
// This prevents a race condition where disconnecting during an active
|
|
711
|
-
// reconnection attempt could leave the flag stuck, blocking subsequent retries
|
|
712
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
|
|
713
|
-
// Close WebSocket transport only (HTTP is stateless)
|
|
714
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
|
|
715
|
-
try {
|
|
716
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
|
|
717
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Closed WebSocket transport', {
|
|
718
|
-
timestamp: new Date().toISOString(),
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
catch (error) {
|
|
722
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(ensureError(error), {
|
|
723
|
-
context: {
|
|
724
|
-
name: 'HyperLiquidClientService.performDisconnection',
|
|
725
|
-
data: { action: 'close_transport' },
|
|
726
|
-
},
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
// Clear client references
|
|
731
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, undefined, "f");
|
|
732
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, undefined, "f");
|
|
733
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, undefined, "f");
|
|
734
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, undefined, "f");
|
|
735
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
|
|
736
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
|
|
737
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
738
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: SDK clients fully disconnected', {
|
|
739
|
-
timestamp: new Date().toISOString(),
|
|
740
|
-
connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
catch (error) {
|
|
744
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
745
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(ensureError(error), {
|
|
746
|
-
context: {
|
|
747
|
-
name: 'HyperLiquidClientService.performDisconnection',
|
|
748
|
-
data: { action: 'outer_catch' },
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
throw error;
|
|
752
|
-
}
|
|
753
|
-
}, _HyperLiquidClientService_updateConnectionState = function _HyperLiquidClientService_updateConnectionState(newState) {
|
|
754
|
-
const previousState = __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f");
|
|
755
|
-
const stateChanged = previousState !== newState;
|
|
756
|
-
const isReconnectionAttempt = newState === WebSocketConnectionState.Connecting &&
|
|
757
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") > 0;
|
|
758
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_connectionState, newState, "f");
|
|
759
|
-
// Reset reconnection attempt counter when successfully connected
|
|
760
|
-
if (newState === WebSocketConnectionState.Connected) {
|
|
761
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, 0, "f");
|
|
762
|
-
}
|
|
763
|
-
// Notify if state changed OR if this is a reconnection attempt (to update attempt count)
|
|
764
|
-
if (stateChanged || isReconnectionAttempt) {
|
|
765
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_notifyConnectionStateListeners).call(this);
|
|
766
|
-
}
|
|
767
|
-
}, _HyperLiquidClientService_notifyConnectionStateListeners = function _HyperLiquidClientService_notifyConnectionStateListeners() {
|
|
768
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").forEach((listener) => {
|
|
769
|
-
try {
|
|
770
|
-
listener(__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"), __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"));
|
|
771
|
-
}
|
|
772
|
-
catch {
|
|
773
|
-
// Ignore errors in listeners to prevent breaking other listeners
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
}, _HyperLiquidClientService_handleConnectionDrop =
|
|
777
|
-
/**
|
|
778
|
-
* Handle detected connection drop
|
|
779
|
-
* Recreates WebSocket transport and notifies callback to restore subscriptions
|
|
780
|
-
* Will give up after MAX_RECONNECTION_ATTEMPTS and mark status as disconnected
|
|
781
|
-
*/
|
|
782
|
-
async function _HyperLiquidClientService_handleConnectionDrop() {
|
|
783
|
-
// Prevent multiple simultaneous reconnection attempts
|
|
784
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_isReconnecting, "f")) {
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, true, "f");
|
|
788
|
-
// Increment reconnection attempt counter
|
|
789
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") + 1, "f");
|
|
790
|
-
// Check if we've exceeded max retry attempts
|
|
791
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") > MAX_RECONNECTION_ATTEMPTS) {
|
|
792
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
|
|
793
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
try {
|
|
797
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connecting);
|
|
798
|
-
// Close existing WebSocket transport and clear references
|
|
799
|
-
// so createTransports() will create fresh ones
|
|
800
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
|
|
801
|
-
try {
|
|
802
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
|
|
803
|
-
}
|
|
804
|
-
catch {
|
|
805
|
-
// Ignore errors during close - transport may already be dead
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
|
|
809
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
|
|
810
|
-
// Recreate WebSocket transport - returns the new transport for type safety
|
|
811
|
-
const newWsTransport = __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
|
|
812
|
-
// Recreate clients that use WebSocket transport
|
|
813
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, new hyperliquid_1.InfoClient({ transport: newWsTransport }), "f");
|
|
814
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, new hyperliquid_1.SubscriptionClient({
|
|
815
|
-
transport: newWsTransport,
|
|
816
|
-
}), "f");
|
|
817
|
-
await newWsTransport.ready();
|
|
818
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Transport ready, restoring subscriptions', { timestamp: new Date().toISOString() });
|
|
819
|
-
// NOW safe to restore subscriptions
|
|
820
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_onReconnectCallback, "f")) {
|
|
821
|
-
await __classPrivateFieldGet(this, _HyperLiquidClientService_onReconnectCallback, "f").call(this);
|
|
822
|
-
}
|
|
823
|
-
// Cancel any pending retry timeout from previous failed attempts
|
|
824
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f")) {
|
|
825
|
-
clearTimeout(__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f"));
|
|
826
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f");
|
|
827
|
-
}
|
|
828
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connected);
|
|
829
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
|
|
830
|
-
}
|
|
831
|
-
catch {
|
|
832
|
-
// Reset flag before scheduling retry so the next attempt can proceed
|
|
833
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
|
|
834
|
-
// Check if we've exceeded max retry attempts
|
|
835
|
-
if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") >= MAX_RECONNECTION_ATTEMPTS) {
|
|
836
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
// Reconnection failed - schedule a retry after a delay
|
|
840
|
-
// Store timeout reference so it can be cancelled on intentional disconnect
|
|
841
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, setTimeout(() => {
|
|
842
|
-
__classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f"); // Clear reference after execution
|
|
843
|
-
// Only retry if we haven't been intentionally disconnected
|
|
844
|
-
// and no manual reconnect() is already in progress
|
|
845
|
-
// Note: State may be CONNECTING or DISCONNECTED (if terminate event fired during reconnect)
|
|
846
|
-
if ((__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Connecting ||
|
|
847
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected) &&
|
|
848
|
-
!__classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f") &&
|
|
849
|
-
!__classPrivateFieldGet(this, _HyperLiquidClientService_isReconnecting, "f")) {
|
|
850
|
-
__classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_handleConnectionDrop).call(this).catch(() => {
|
|
851
|
-
// Errors are handled internally in handleConnectionDrop
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
}, perpsConfig_1.PERPS_CONSTANTS.ReconnectionRetryDelayMs), "f");
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
//# sourceMappingURL=HyperLiquidClientService.cjs.map
|