@metamask-previews/perps-controller 0.0.0-preview-685dbf46b → 1.0.0-preview-bc00f2c
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 +30 -2
- package/dist/PerpsController.cjs +3077 -65
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +969 -82
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +969 -82
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +3073 -62
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +441 -0
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +1 -0
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +171 -0
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +1 -0
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +171 -0
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +1 -0
- package/dist/aggregation/SubscriptionMultiplexer.mjs +437 -0
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +1 -0
- package/dist/aggregation/index.cjs +9 -0
- package/dist/aggregation/index.cjs.map +1 -0
- package/dist/aggregation/index.d.cts +6 -0
- package/dist/aggregation/index.d.cts.map +1 -0
- package/dist/aggregation/index.d.mts +6 -0
- package/dist/aggregation/index.d.mts.map +1 -0
- package/dist/aggregation/index.mjs +5 -0
- package/dist/aggregation/index.mjs.map +1 -0
- package/dist/constants/chartConfig.cjs +227 -0
- package/dist/constants/chartConfig.cjs.map +1 -0
- package/dist/constants/chartConfig.d.cts +216 -0
- package/dist/constants/chartConfig.d.cts.map +1 -0
- package/dist/constants/chartConfig.d.mts +216 -0
- package/dist/constants/chartConfig.d.mts.map +1 -0
- package/dist/constants/chartConfig.mjs +221 -0
- package/dist/constants/chartConfig.mjs.map +1 -0
- package/dist/constants/eventNames.cjs +436 -0
- package/dist/constants/eventNames.cjs.map +1 -0
- package/dist/constants/eventNames.d.cts +387 -0
- package/dist/constants/eventNames.d.cts.map +1 -0
- package/dist/constants/eventNames.d.mts +387 -0
- package/dist/constants/eventNames.d.mts.map +1 -0
- package/dist/constants/eventNames.mjs +433 -0
- package/dist/constants/eventNames.mjs.map +1 -0
- package/dist/constants/hyperLiquidConfig.cjs +380 -0
- package/dist/constants/hyperLiquidConfig.cjs.map +1 -0
- package/dist/constants/hyperLiquidConfig.d.cts +236 -0
- package/dist/constants/hyperLiquidConfig.d.cts.map +1 -0
- package/dist/constants/hyperLiquidConfig.d.mts +236 -0
- package/dist/constants/hyperLiquidConfig.d.mts.map +1 -0
- package/dist/constants/hyperLiquidConfig.mjs +371 -0
- package/dist/constants/hyperLiquidConfig.mjs.map +1 -0
- package/dist/constants/index.cjs +28 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +12 -0
- package/dist/constants/index.d.cts.map +1 -0
- package/dist/constants/index.d.mts +12 -0
- package/dist/constants/index.d.mts.map +1 -0
- package/dist/constants/index.mjs +12 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/constants/myxConfig.cjs +229 -0
- package/dist/constants/myxConfig.cjs.map +1 -0
- package/dist/constants/myxConfig.d.cts +106 -0
- package/dist/constants/myxConfig.d.cts.map +1 -0
- package/dist/constants/myxConfig.d.mts +106 -0
- package/dist/constants/myxConfig.d.mts.map +1 -0
- package/dist/constants/myxConfig.mjs +219 -0
- package/dist/constants/myxConfig.mjs.map +1 -0
- package/dist/constants/orderTypes.cjs +31 -0
- package/dist/constants/orderTypes.cjs.map +1 -0
- package/dist/constants/orderTypes.d.cts +19 -0
- package/dist/constants/orderTypes.d.cts.map +1 -0
- package/dist/constants/orderTypes.d.mts +19 -0
- package/dist/constants/orderTypes.d.mts.map +1 -0
- package/dist/constants/orderTypes.mjs +27 -0
- package/dist/constants/orderTypes.mjs.map +1 -0
- package/dist/constants/performanceMetrics.cjs +63 -0
- package/dist/constants/performanceMetrics.cjs.map +1 -0
- package/dist/constants/performanceMetrics.d.cts +46 -0
- package/dist/constants/performanceMetrics.d.cts.map +1 -0
- package/dist/constants/performanceMetrics.d.mts +46 -0
- package/dist/constants/performanceMetrics.d.mts.map +1 -0
- package/dist/constants/performanceMetrics.mjs +60 -0
- package/dist/constants/performanceMetrics.mjs.map +1 -0
- package/dist/constants/perpsConfig.cjs +295 -0
- package/dist/constants/perpsConfig.cjs.map +1 -0
- package/dist/constants/perpsConfig.d.cts +221 -0
- package/dist/constants/perpsConfig.d.cts.map +1 -0
- package/dist/constants/perpsConfig.d.mts +221 -0
- package/dist/constants/perpsConfig.d.mts.map +1 -0
- package/dist/constants/perpsConfig.mjs +292 -0
- package/dist/constants/perpsConfig.mjs.map +1 -0
- package/dist/constants/transactionsHistoryConfig.cjs +19 -0
- package/dist/constants/transactionsHistoryConfig.cjs.map +1 -0
- package/dist/constants/transactionsHistoryConfig.d.cts +16 -0
- package/dist/constants/transactionsHistoryConfig.d.cts.map +1 -0
- package/dist/constants/transactionsHistoryConfig.d.mts +16 -0
- package/dist/constants/transactionsHistoryConfig.d.mts.map +1 -0
- package/dist/constants/transactionsHistoryConfig.mjs +16 -0
- package/dist/constants/transactionsHistoryConfig.mjs.map +1 -0
- package/dist/index.cjs +63 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +38 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +46 -1
- package/dist/index.mjs.map +1 -1
- package/dist/perpsErrorCodes.cjs +80 -0
- package/dist/perpsErrorCodes.cjs.map +1 -0
- package/dist/perpsErrorCodes.d.cts +65 -0
- package/dist/perpsErrorCodes.d.cts.map +1 -0
- package/dist/perpsErrorCodes.d.mts +65 -0
- package/dist/perpsErrorCodes.d.mts.map +1 -0
- package/dist/perpsErrorCodes.mjs +77 -0
- package/dist/perpsErrorCodes.mjs.map +1 -0
- package/dist/providers/AggregatedPerpsProvider.cjs +508 -0
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -0
- package/dist/providers/AggregatedPerpsProvider.d.cts +171 -0
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -0
- package/dist/providers/AggregatedPerpsProvider.d.mts +171 -0
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -0
- package/dist/providers/AggregatedPerpsProvider.mjs +504 -0
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -0
- package/dist/providers/HyperLiquidProvider.cjs +5679 -0
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -0
- package/dist/providers/HyperLiquidProvider.d.cts +516 -0
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -0
- package/dist/providers/HyperLiquidProvider.d.mts +516 -0
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -0
- package/dist/providers/HyperLiquidProvider.mjs +5675 -0
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -0
- package/dist/providers/MYXProvider.cjs +514 -0
- package/dist/providers/MYXProvider.cjs.map +1 -0
- package/dist/providers/MYXProvider.d.cts +105 -0
- package/dist/providers/MYXProvider.d.cts.map +1 -0
- package/dist/providers/MYXProvider.d.mts +105 -0
- package/dist/providers/MYXProvider.d.mts.map +1 -0
- package/dist/providers/MYXProvider.mjs +510 -0
- package/dist/providers/MYXProvider.mjs.map +1 -0
- package/dist/routing/ProviderRouter.cjs +154 -0
- package/dist/routing/ProviderRouter.cjs.map +1 -0
- package/dist/routing/ProviderRouter.d.cts +112 -0
- package/dist/routing/ProviderRouter.d.cts.map +1 -0
- package/dist/routing/ProviderRouter.d.mts +112 -0
- package/dist/routing/ProviderRouter.d.mts.map +1 -0
- package/dist/routing/ProviderRouter.mjs +150 -0
- package/dist/routing/ProviderRouter.mjs.map +1 -0
- package/dist/routing/index.cjs +9 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +6 -0
- package/dist/routing/index.d.cts.map +1 -0
- package/dist/routing/index.d.mts +6 -0
- package/dist/routing/index.d.mts.map +1 -0
- package/dist/routing/index.mjs +5 -0
- package/dist/routing/index.mjs.map +1 -0
- package/dist/selectors.cjs +166 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/selectors.d.cts +362 -0
- package/dist/selectors.d.cts.map +1 -0
- package/dist/selectors.d.mts +362 -0
- package/dist/selectors.d.mts.map +1 -0
- package/dist/selectors.mjs +158 -0
- package/dist/selectors.mjs.map +1 -0
- package/dist/services/AccountService.cjs +324 -0
- package/dist/services/AccountService.cjs.map +1 -0
- package/dist/services/AccountService.d.cts +56 -0
- package/dist/services/AccountService.d.cts.map +1 -0
- package/dist/services/AccountService.d.mts +56 -0
- package/dist/services/AccountService.d.mts.map +1 -0
- package/dist/services/AccountService.mjs +320 -0
- package/dist/services/AccountService.mjs.map +1 -0
- package/dist/services/DataLakeService.cjs +233 -0
- package/dist/services/DataLakeService.cjs.map +1 -0
- package/dist/services/DataLakeService.d.cts +51 -0
- package/dist/services/DataLakeService.d.cts.map +1 -0
- package/dist/services/DataLakeService.d.mts +51 -0
- package/dist/services/DataLakeService.d.mts.map +1 -0
- package/dist/services/DataLakeService.mjs +229 -0
- package/dist/services/DataLakeService.mjs.map +1 -0
- package/dist/services/DepositService.cjs +98 -0
- package/dist/services/DepositService.cjs.map +1 -0
- package/dist/services/DepositService.d.cts +39 -0
- package/dist/services/DepositService.d.cts.map +1 -0
- package/dist/services/DepositService.d.mts +39 -0
- package/dist/services/DepositService.d.mts.map +1 -0
- package/dist/services/DepositService.mjs +94 -0
- package/dist/services/DepositService.mjs.map +1 -0
- package/dist/services/EligibilityService.cjs +173 -0
- package/dist/services/EligibilityService.cjs.map +1 -0
- package/dist/services/EligibilityService.d.cts +39 -0
- package/dist/services/EligibilityService.d.cts.map +1 -0
- package/dist/services/EligibilityService.d.mts +39 -0
- package/dist/services/EligibilityService.d.mts.map +1 -0
- package/dist/services/EligibilityService.mjs +169 -0
- package/dist/services/EligibilityService.mjs.map +1 -0
- package/dist/services/FeatureFlagConfigurationService.cjs +257 -0
- package/dist/services/FeatureFlagConfigurationService.cjs.map +1 -0
- package/dist/services/FeatureFlagConfigurationService.d.cts +73 -0
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +1 -0
- package/dist/services/FeatureFlagConfigurationService.d.mts +73 -0
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +1 -0
- package/dist/services/FeatureFlagConfigurationService.mjs +253 -0
- package/dist/services/FeatureFlagConfigurationService.mjs.map +1 -0
- package/dist/services/HyperLiquidClientService.cjs +867 -0
- package/dist/services/HyperLiquidClientService.cjs.map +1 -0
- package/dist/services/HyperLiquidClientService.d.cts +214 -0
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -0
- package/dist/services/HyperLiquidClientService.d.mts +214 -0
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -0
- package/dist/services/HyperLiquidClientService.mjs +862 -0
- package/dist/services/HyperLiquidClientService.mjs.map +1 -0
- package/dist/services/HyperLiquidSubscriptionService.cjs +2199 -0
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -0
- package/dist/services/HyperLiquidSubscriptionService.d.cts +187 -0
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -0
- package/dist/services/HyperLiquidSubscriptionService.d.mts +187 -0
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -0
- package/dist/services/HyperLiquidSubscriptionService.mjs +2195 -0
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -0
- package/dist/services/HyperLiquidWalletService.cjs +163 -0
- package/dist/services/HyperLiquidWalletService.cjs.map +1 -0
- package/dist/services/HyperLiquidWalletService.d.cts +78 -0
- package/dist/services/HyperLiquidWalletService.d.cts.map +1 -0
- package/dist/services/HyperLiquidWalletService.d.mts +78 -0
- package/dist/services/HyperLiquidWalletService.d.mts.map +1 -0
- package/dist/services/HyperLiquidWalletService.mjs +159 -0
- package/dist/services/HyperLiquidWalletService.mjs.map +1 -0
- package/dist/services/MYXClientService.cjs +304 -0
- package/dist/services/MYXClientService.cjs.map +1 -0
- package/dist/services/MYXClientService.d.cts +81 -0
- package/dist/services/MYXClientService.d.cts.map +1 -0
- package/dist/services/MYXClientService.d.mts +81 -0
- package/dist/services/MYXClientService.d.mts.map +1 -0
- package/dist/services/MYXClientService.mjs +300 -0
- package/dist/services/MYXClientService.mjs.map +1 -0
- package/dist/services/MarketDataService.cjs +848 -0
- package/dist/services/MarketDataService.cjs.map +1 -0
- package/dist/services/MarketDataService.d.cts +291 -0
- package/dist/services/MarketDataService.d.cts.map +1 -0
- package/dist/services/MarketDataService.d.mts +291 -0
- package/dist/services/MarketDataService.d.mts.map +1 -0
- package/dist/services/MarketDataService.mjs +844 -0
- package/dist/services/MarketDataService.mjs.map +1 -0
- package/dist/services/RewardsIntegrationService.cjs +120 -0
- package/dist/services/RewardsIntegrationService.cjs.map +1 -0
- package/dist/services/RewardsIntegrationService.d.cts +28 -0
- package/dist/services/RewardsIntegrationService.d.cts.map +1 -0
- package/dist/services/RewardsIntegrationService.d.mts +28 -0
- package/dist/services/RewardsIntegrationService.d.mts.map +1 -0
- package/dist/services/RewardsIntegrationService.mjs +116 -0
- package/dist/services/RewardsIntegrationService.mjs.map +1 -0
- package/dist/services/ServiceContext.cjs +3 -0
- package/dist/services/ServiceContext.cjs.map +1 -0
- package/dist/services/ServiceContext.d.cts +86 -0
- package/dist/services/ServiceContext.d.cts.map +1 -0
- package/dist/services/ServiceContext.d.mts +86 -0
- package/dist/services/ServiceContext.d.mts.map +1 -0
- package/dist/services/ServiceContext.mjs +2 -0
- package/dist/services/ServiceContext.mjs.map +1 -0
- package/dist/services/TradingReadinessCache.cjs +288 -0
- package/dist/services/TradingReadinessCache.cjs.map +1 -0
- package/dist/services/TradingReadinessCache.d.cts +174 -0
- package/dist/services/TradingReadinessCache.d.cts.map +1 -0
- package/dist/services/TradingReadinessCache.d.mts +174 -0
- package/dist/services/TradingReadinessCache.d.mts.map +1 -0
- package/dist/services/TradingReadinessCache.mjs +285 -0
- package/dist/services/TradingReadinessCache.mjs.map +1 -0
- package/dist/services/TradingService.cjs +1457 -0
- package/dist/services/TradingService.cjs.map +1 -0
- package/dist/services/TradingService.d.cts +195 -0
- package/dist/services/TradingService.d.cts.map +1 -0
- package/dist/services/TradingService.d.mts +195 -0
- package/dist/services/TradingService.d.mts.map +1 -0
- package/dist/services/TradingService.mjs +1453 -0
- package/dist/services/TradingService.mjs.map +1 -0
- package/dist/types/config.cjs +3 -0
- package/dist/types/config.cjs.map +1 -0
- package/dist/types/config.d.cts +49 -0
- package/dist/types/config.d.cts.map +1 -0
- package/dist/types/config.d.mts +49 -0
- package/dist/types/config.d.mts.map +1 -0
- package/dist/types/config.mjs +2 -0
- package/dist/types/config.mjs.map +1 -0
- package/dist/types/hyperliquid-types.cjs +3 -0
- package/dist/types/hyperliquid-types.cjs.map +1 -0
- package/dist/types/hyperliquid-types.d.cts +20 -0
- package/dist/types/hyperliquid-types.d.cts.map +1 -0
- package/dist/types/hyperliquid-types.d.mts +20 -0
- package/dist/types/hyperliquid-types.d.mts.map +1 -0
- package/dist/types/hyperliquid-types.mjs +2 -0
- package/dist/types/hyperliquid-types.mjs.map +1 -0
- package/dist/types/index.cjs +115 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +1262 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.mts +1262 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +97 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/messenger.cjs +3 -0
- package/dist/types/messenger.cjs.map +1 -0
- package/dist/types/messenger.d.cts +27 -0
- package/dist/types/messenger.d.cts.map +1 -0
- package/dist/types/messenger.d.mts +27 -0
- package/dist/types/messenger.d.mts.map +1 -0
- package/dist/types/messenger.mjs +2 -0
- package/dist/types/messenger.mjs.map +1 -0
- package/dist/types/myx-types.cjs +25 -0
- package/dist/types/myx-types.cjs.map +1 -0
- package/dist/types/myx-types.d.cts +63 -0
- package/dist/types/myx-types.d.cts.map +1 -0
- package/dist/types/myx-types.d.mts +63 -0
- package/dist/types/myx-types.d.mts.map +1 -0
- package/dist/types/myx-types.mjs +22 -0
- package/dist/types/myx-types.mjs.map +1 -0
- package/dist/types/perps-types.cjs +4 -0
- package/dist/types/perps-types.cjs.map +1 -0
- package/dist/types/perps-types.d.cts +105 -0
- package/dist/types/perps-types.d.cts.map +1 -0
- package/dist/types/perps-types.d.mts +105 -0
- package/dist/types/perps-types.d.mts.map +1 -0
- package/dist/types/perps-types.mjs +2 -0
- package/dist/types/perps-types.mjs.map +1 -0
- package/dist/types/token.cjs +3 -0
- package/dist/types/token.cjs.map +1 -0
- package/dist/types/token.d.cts +25 -0
- package/dist/types/token.d.cts.map +1 -0
- package/dist/types/token.d.mts +25 -0
- package/dist/types/token.d.mts.map +1 -0
- package/dist/types/token.mjs +2 -0
- package/dist/types/token.mjs.map +1 -0
- package/dist/types/transactionTypes.cjs +28 -0
- package/dist/types/transactionTypes.cjs.map +1 -0
- package/dist/types/transactionTypes.d.cts +64 -0
- package/dist/types/transactionTypes.d.cts.map +1 -0
- package/dist/types/transactionTypes.d.mts +64 -0
- package/dist/types/transactionTypes.d.mts.map +1 -0
- package/dist/types/transactionTypes.mjs +23 -0
- package/dist/types/transactionTypes.mjs.map +1 -0
- package/dist/utils/accountUtils.cjs +100 -0
- package/dist/utils/accountUtils.cjs.map +1 -0
- package/dist/utils/accountUtils.d.cts +30 -0
- package/dist/utils/accountUtils.d.cts.map +1 -0
- package/dist/utils/accountUtils.d.mts +30 -0
- package/dist/utils/accountUtils.d.mts.map +1 -0
- package/dist/utils/accountUtils.mjs +92 -0
- package/dist/utils/accountUtils.mjs.map +1 -0
- package/dist/utils/errorUtils.cjs +35 -0
- package/dist/utils/errorUtils.cjs.map +1 -0
- package/dist/utils/errorUtils.d.cts +15 -0
- package/dist/utils/errorUtils.d.cts.map +1 -0
- package/dist/utils/errorUtils.d.mts +15 -0
- package/dist/utils/errorUtils.d.mts.map +1 -0
- package/dist/utils/errorUtils.mjs +31 -0
- package/dist/utils/errorUtils.mjs.map +1 -0
- package/dist/utils/hyperLiquidAdapter.cjs +331 -0
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -0
- package/dist/utils/hyperLiquidAdapter.d.cts +42 -0
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -0
- package/dist/utils/hyperLiquidAdapter.d.mts +42 -0
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -0
- package/dist/utils/hyperLiquidAdapter.mjs +316 -0
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +83 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +1 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +55 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +1 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +55 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +1 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs +78 -0
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +1 -0
- package/dist/utils/hyperLiquidValidation.cjs +426 -0
- package/dist/utils/hyperLiquidValidation.cjs.map +1 -0
- package/dist/utils/hyperLiquidValidation.d.cts +143 -0
- package/dist/utils/hyperLiquidValidation.d.cts.map +1 -0
- package/dist/utils/hyperLiquidValidation.d.mts +143 -0
- package/dist/utils/hyperLiquidValidation.d.mts.map +1 -0
- package/dist/utils/hyperLiquidValidation.mjs +413 -0
- package/dist/utils/hyperLiquidValidation.mjs.map +1 -0
- package/dist/utils/idUtils.cjs +18 -0
- package/dist/utils/idUtils.cjs.map +1 -0
- package/dist/utils/idUtils.d.cts +6 -0
- package/dist/utils/idUtils.d.cts.map +1 -0
- package/dist/utils/idUtils.d.mts +6 -0
- package/dist/utils/idUtils.d.mts.map +1 -0
- package/dist/utils/idUtils.mjs +10 -0
- package/dist/utils/idUtils.mjs.map +1 -0
- package/dist/utils/index.cjs +59 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +25 -0
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +25 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +30 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils/marketDataTransform.cjs +211 -0
- package/dist/utils/marketDataTransform.cjs.map +1 -0
- package/dist/utils/marketDataTransform.d.cts +40 -0
- package/dist/utils/marketDataTransform.d.cts.map +1 -0
- package/dist/utils/marketDataTransform.d.mts +40 -0
- package/dist/utils/marketDataTransform.d.mts.map +1 -0
- package/dist/utils/marketDataTransform.mjs +205 -0
- package/dist/utils/marketDataTransform.mjs.map +1 -0
- package/dist/utils/marketUtils.cjs +151 -0
- package/dist/utils/marketUtils.cjs.map +1 -0
- package/dist/utils/marketUtils.d.cts +30 -0
- package/dist/utils/marketUtils.d.cts.map +1 -0
- package/dist/utils/marketUtils.d.mts +30 -0
- package/dist/utils/marketUtils.d.mts.map +1 -0
- package/dist/utils/marketUtils.mjs +138 -0
- package/dist/utils/marketUtils.mjs.map +1 -0
- package/dist/utils/myxAdapter.cjs +224 -0
- package/dist/utils/myxAdapter.cjs.map +1 -0
- package/dist/utils/myxAdapter.d.cts +81 -0
- package/dist/utils/myxAdapter.d.cts.map +1 -0
- package/dist/utils/myxAdapter.d.mts +81 -0
- package/dist/utils/myxAdapter.d.mts.map +1 -0
- package/dist/utils/myxAdapter.mjs +213 -0
- package/dist/utils/myxAdapter.mjs.map +1 -0
- package/dist/utils/orderCalculations.cjs +283 -0
- package/dist/utils/orderCalculations.cjs.map +1 -0
- package/dist/utils/orderCalculations.d.cts +107 -0
- package/dist/utils/orderCalculations.d.cts.map +1 -0
- package/dist/utils/orderCalculations.d.mts +107 -0
- package/dist/utils/orderCalculations.d.mts.map +1 -0
- package/dist/utils/orderCalculations.mjs +274 -0
- package/dist/utils/orderCalculations.mjs.map +1 -0
- package/dist/utils/rewardsUtils.cjs +98 -0
- package/dist/utils/rewardsUtils.cjs.map +1 -0
- package/dist/utils/rewardsUtils.d.cts +33 -0
- package/dist/utils/rewardsUtils.d.cts.map +1 -0
- package/dist/utils/rewardsUtils.d.mts +33 -0
- package/dist/utils/rewardsUtils.d.mts.map +1 -0
- package/dist/utils/rewardsUtils.mjs +92 -0
- package/dist/utils/rewardsUtils.mjs.map +1 -0
- package/dist/utils/significantFigures.cjs +88 -0
- package/dist/utils/significantFigures.cjs.map +1 -0
- package/dist/utils/significantFigures.d.cts +25 -0
- package/dist/utils/significantFigures.d.cts.map +1 -0
- package/dist/utils/significantFigures.d.mts +25 -0
- package/dist/utils/significantFigures.d.mts.map +1 -0
- package/dist/utils/significantFigures.mjs +82 -0
- package/dist/utils/significantFigures.mjs.map +1 -0
- package/dist/utils/sortMarkets.cjs +93 -0
- package/dist/utils/sortMarkets.cjs.map +1 -0
- package/dist/utils/sortMarkets.d.cts +27 -0
- package/dist/utils/sortMarkets.d.cts.map +1 -0
- package/dist/utils/sortMarkets.d.mts +27 -0
- package/dist/utils/sortMarkets.d.mts.map +1 -0
- package/dist/utils/sortMarkets.mjs +88 -0
- package/dist/utils/sortMarkets.mjs.map +1 -0
- package/dist/utils/standaloneInfoClient.cjs +70 -0
- package/dist/utils/standaloneInfoClient.cjs.map +1 -0
- package/dist/utils/standaloneInfoClient.d.cts +37 -0
- package/dist/utils/standaloneInfoClient.d.cts.map +1 -0
- package/dist/utils/standaloneInfoClient.d.mts +37 -0
- package/dist/utils/standaloneInfoClient.d.mts.map +1 -0
- package/dist/utils/standaloneInfoClient.mjs +64 -0
- package/dist/utils/standaloneInfoClient.mjs.map +1 -0
- package/dist/utils/stringParseUtils.cjs +18 -0
- package/dist/utils/stringParseUtils.cjs.map +1 -0
- package/dist/utils/stringParseUtils.d.cts +3 -0
- package/dist/utils/stringParseUtils.d.cts.map +1 -0
- package/dist/utils/stringParseUtils.d.mts +3 -0
- package/dist/utils/stringParseUtils.d.mts.map +1 -0
- package/dist/utils/stringParseUtils.mjs +13 -0
- package/dist/utils/stringParseUtils.mjs.map +1 -0
- package/dist/utils/transferData.cjs +33 -0
- package/dist/utils/transferData.cjs.map +1 -0
- package/dist/utils/transferData.d.cts +9 -0
- package/dist/utils/transferData.d.cts.map +1 -0
- package/dist/utils/transferData.d.mts +9 -0
- package/dist/utils/transferData.d.mts.map +1 -0
- package/dist/utils/transferData.mjs +29 -0
- package/dist/utils/transferData.mjs.map +1 -0
- package/dist/utils/wait.cjs +6 -0
- package/dist/utils/wait.cjs.map +1 -0
- package/dist/utils/wait.d.cts +2 -0
- package/dist/utils/wait.d.cts.map +1 -0
- package/dist/utils/wait.d.mts +2 -0
- package/dist/utils/wait.d.mts.map +1 -0
- package/dist/utils/wait.mjs +2 -0
- package/dist/utils/wait.mjs.map +1 -0
- package/package.json +16 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { BboWsEvent, L2BookResponse } from "@nktkas/hyperliquid";
|
|
2
|
+
import type { PriceUpdate } from "../types/index.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* HyperLiquid Order Book Processor
|
|
5
|
+
*
|
|
6
|
+
* Utility functions for processing Level 2 order book data from HyperLiquid WebSocket.
|
|
7
|
+
* Extracts best bid/ask prices, calculates spreads, and updates caches.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Order book cache entry structure
|
|
11
|
+
*/
|
|
12
|
+
export type OrderBookCacheEntry = {
|
|
13
|
+
bestBid?: string;
|
|
14
|
+
bestAsk?: string;
|
|
15
|
+
spread?: string;
|
|
16
|
+
lastUpdated: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for processing L2 book data
|
|
20
|
+
*/
|
|
21
|
+
export type ProcessL2BookDataParams = {
|
|
22
|
+
symbol: string;
|
|
23
|
+
data: L2BookResponse;
|
|
24
|
+
orderBookCache: Map<string, OrderBookCacheEntry>;
|
|
25
|
+
cachedPriceData: Map<string, PriceUpdate> | null;
|
|
26
|
+
createPriceUpdate: (symbol: string, price: string) => PriceUpdate;
|
|
27
|
+
notifySubscribers: () => void;
|
|
28
|
+
};
|
|
29
|
+
export type ProcessBboDataParams = {
|
|
30
|
+
symbol: string;
|
|
31
|
+
data: BboWsEvent;
|
|
32
|
+
orderBookCache: Map<string, OrderBookCacheEntry>;
|
|
33
|
+
cachedPriceData: Map<string, PriceUpdate> | null;
|
|
34
|
+
createPriceUpdate: (symbol: string, price: string) => PriceUpdate;
|
|
35
|
+
notifySubscribers: () => void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Process Level 2 order book data and update caches
|
|
39
|
+
*
|
|
40
|
+
* Extracts best bid/ask prices from order book levels, calculates spread,
|
|
41
|
+
* and updates the order book cache and price data cache.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Processing parameters
|
|
44
|
+
*/
|
|
45
|
+
export declare function processL2BookData(params: ProcessL2BookDataParams): void;
|
|
46
|
+
/**
|
|
47
|
+
* Process BBO (best bid/offer) data and update caches
|
|
48
|
+
*
|
|
49
|
+
* BBO is lightweight and independent from L2Book aggregation parameters,
|
|
50
|
+
* making it ideal for spread / top-of-book display.
|
|
51
|
+
*
|
|
52
|
+
* @param params - The BBO processing parameters including symbol, data, and caches.
|
|
53
|
+
*/
|
|
54
|
+
export declare function processBboData(params: ProcessBboDataParams): void;
|
|
55
|
+
//# sourceMappingURL=hyperLiquidOrderBookProcessor.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperLiquidOrderBookProcessor.d.cts","sourceRoot":"","sources":["../../src/utils/hyperLiquidOrderBookProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,4BAA4B;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,2BAAiB;AAE5C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;IACrB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACjD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;IACjD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;IAClE,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACjD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;IACjD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;IAClE,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAgDvE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAyCjE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { BboWsEvent, L2BookResponse } from "@nktkas/hyperliquid";
|
|
2
|
+
import type { PriceUpdate } from "../types/index.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* HyperLiquid Order Book Processor
|
|
5
|
+
*
|
|
6
|
+
* Utility functions for processing Level 2 order book data from HyperLiquid WebSocket.
|
|
7
|
+
* Extracts best bid/ask prices, calculates spreads, and updates caches.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Order book cache entry structure
|
|
11
|
+
*/
|
|
12
|
+
export type OrderBookCacheEntry = {
|
|
13
|
+
bestBid?: string;
|
|
14
|
+
bestAsk?: string;
|
|
15
|
+
spread?: string;
|
|
16
|
+
lastUpdated: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for processing L2 book data
|
|
20
|
+
*/
|
|
21
|
+
export type ProcessL2BookDataParams = {
|
|
22
|
+
symbol: string;
|
|
23
|
+
data: L2BookResponse;
|
|
24
|
+
orderBookCache: Map<string, OrderBookCacheEntry>;
|
|
25
|
+
cachedPriceData: Map<string, PriceUpdate> | null;
|
|
26
|
+
createPriceUpdate: (symbol: string, price: string) => PriceUpdate;
|
|
27
|
+
notifySubscribers: () => void;
|
|
28
|
+
};
|
|
29
|
+
export type ProcessBboDataParams = {
|
|
30
|
+
symbol: string;
|
|
31
|
+
data: BboWsEvent;
|
|
32
|
+
orderBookCache: Map<string, OrderBookCacheEntry>;
|
|
33
|
+
cachedPriceData: Map<string, PriceUpdate> | null;
|
|
34
|
+
createPriceUpdate: (symbol: string, price: string) => PriceUpdate;
|
|
35
|
+
notifySubscribers: () => void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Process Level 2 order book data and update caches
|
|
39
|
+
*
|
|
40
|
+
* Extracts best bid/ask prices from order book levels, calculates spread,
|
|
41
|
+
* and updates the order book cache and price data cache.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Processing parameters
|
|
44
|
+
*/
|
|
45
|
+
export declare function processL2BookData(params: ProcessL2BookDataParams): void;
|
|
46
|
+
/**
|
|
47
|
+
* Process BBO (best bid/offer) data and update caches
|
|
48
|
+
*
|
|
49
|
+
* BBO is lightweight and independent from L2Book aggregation parameters,
|
|
50
|
+
* making it ideal for spread / top-of-book display.
|
|
51
|
+
*
|
|
52
|
+
* @param params - The BBO processing parameters including symbol, data, and caches.
|
|
53
|
+
*/
|
|
54
|
+
export declare function processBboData(params: ProcessBboDataParams): void;
|
|
55
|
+
//# sourceMappingURL=hyperLiquidOrderBookProcessor.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperLiquidOrderBookProcessor.d.mts","sourceRoot":"","sources":["../../src/utils/hyperLiquidOrderBookProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,4BAA4B;AAEtE,OAAO,KAAK,EAAE,WAAW,EAAE,2BAAiB;AAE5C;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;IACrB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACjD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;IACjD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;IAClE,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACjD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC;IACjD,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;IAClE,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAgDvE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAyCjE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process Level 2 order book data and update caches
|
|
3
|
+
*
|
|
4
|
+
* Extracts best bid/ask prices from order book levels, calculates spread,
|
|
5
|
+
* and updates the order book cache and price data cache.
|
|
6
|
+
*
|
|
7
|
+
* @param params - Processing parameters
|
|
8
|
+
*/
|
|
9
|
+
export function processL2BookData(params) {
|
|
10
|
+
const { symbol, data, orderBookCache, cachedPriceData, createPriceUpdate, notifySubscribers, } = params;
|
|
11
|
+
if (data?.coin !== symbol || !data?.levels) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// Extract best bid and ask from order book
|
|
15
|
+
const bestBid = data.levels[0]?.[0]; // First bid level
|
|
16
|
+
const bestAsk = data.levels[1]?.[0]; // First ask level
|
|
17
|
+
if (!bestBid && !bestAsk) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const bidPrice = bestBid ? parseFloat(bestBid.px) : 0;
|
|
21
|
+
const askPrice = bestAsk ? parseFloat(bestAsk.px) : 0;
|
|
22
|
+
const spread = bidPrice > 0 && askPrice > 0 ? (askPrice - bidPrice).toFixed(5) : undefined;
|
|
23
|
+
// Update order book cache
|
|
24
|
+
orderBookCache.set(symbol, {
|
|
25
|
+
bestBid: bestBid?.px,
|
|
26
|
+
bestAsk: bestAsk?.px,
|
|
27
|
+
spread,
|
|
28
|
+
lastUpdated: Date.now(),
|
|
29
|
+
});
|
|
30
|
+
// Update cached price data with new order book data
|
|
31
|
+
const currentCachedPrice = cachedPriceData?.get(symbol);
|
|
32
|
+
if (!currentCachedPrice) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const updatedPrice = createPriceUpdate(symbol, currentCachedPrice.price);
|
|
36
|
+
// Ensure cache exists before setting
|
|
37
|
+
if (cachedPriceData) {
|
|
38
|
+
cachedPriceData.set(symbol, updatedPrice);
|
|
39
|
+
notifySubscribers();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Process BBO (best bid/offer) data and update caches
|
|
44
|
+
*
|
|
45
|
+
* BBO is lightweight and independent from L2Book aggregation parameters,
|
|
46
|
+
* making it ideal for spread / top-of-book display.
|
|
47
|
+
*
|
|
48
|
+
* @param params - The BBO processing parameters including symbol, data, and caches.
|
|
49
|
+
*/
|
|
50
|
+
export function processBboData(params) {
|
|
51
|
+
const { symbol, data, orderBookCache, cachedPriceData, createPriceUpdate, notifySubscribers, } = params;
|
|
52
|
+
if (data?.coin !== symbol || !Array.isArray(data?.bbo)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const [bestBid, bestAsk] = data.bbo;
|
|
56
|
+
if (!bestBid && !bestAsk) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const bidPrice = bestBid ? parseFloat(bestBid.px) : 0;
|
|
60
|
+
const askPrice = bestAsk ? parseFloat(bestAsk.px) : 0;
|
|
61
|
+
const spread = bidPrice > 0 && askPrice > 0 ? (askPrice - bidPrice).toFixed(5) : undefined;
|
|
62
|
+
orderBookCache.set(symbol, {
|
|
63
|
+
bestBid: bestBid?.px,
|
|
64
|
+
bestAsk: bestAsk?.px,
|
|
65
|
+
spread,
|
|
66
|
+
lastUpdated: Date.now(),
|
|
67
|
+
});
|
|
68
|
+
const currentCachedPrice = cachedPriceData?.get(symbol);
|
|
69
|
+
if (!currentCachedPrice) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const updatedPrice = createPriceUpdate(symbol, currentCachedPrice.price);
|
|
73
|
+
if (cachedPriceData) {
|
|
74
|
+
cachedPriceData.set(symbol, updatedPrice);
|
|
75
|
+
notifySubscribers();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=hyperLiquidOrderBookProcessor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperLiquidOrderBookProcessor.mjs","sourceRoot":"","sources":["../../src/utils/hyperLiquidOrderBookProcessor.ts"],"names":[],"mappings":"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","sourcesContent":["import type { BboWsEvent, L2BookResponse } from '@nktkas/hyperliquid';\n\nimport type { PriceUpdate } from '../types';\n\n/**\n * HyperLiquid Order Book Processor\n *\n * Utility functions for processing Level 2 order book data from HyperLiquid WebSocket.\n * Extracts best bid/ask prices, calculates spreads, and updates caches.\n */\n\n/**\n * Order book cache entry structure\n */\nexport type OrderBookCacheEntry = {\n bestBid?: string;\n bestAsk?: string;\n spread?: string;\n lastUpdated: number;\n};\n\n/**\n * Parameters for processing L2 book data\n */\nexport type ProcessL2BookDataParams = {\n symbol: string;\n data: L2BookResponse;\n orderBookCache: Map<string, OrderBookCacheEntry>;\n cachedPriceData: Map<string, PriceUpdate> | null;\n createPriceUpdate: (symbol: string, price: string) => PriceUpdate;\n notifySubscribers: () => void;\n};\n\nexport type ProcessBboDataParams = {\n symbol: string;\n data: BboWsEvent;\n orderBookCache: Map<string, OrderBookCacheEntry>;\n cachedPriceData: Map<string, PriceUpdate> | null;\n createPriceUpdate: (symbol: string, price: string) => PriceUpdate;\n notifySubscribers: () => void;\n};\n\n/**\n * Process Level 2 order book data and update caches\n *\n * Extracts best bid/ask prices from order book levels, calculates spread,\n * and updates the order book cache and price data cache.\n *\n * @param params - Processing parameters\n */\nexport function processL2BookData(params: ProcessL2BookDataParams): void {\n const {\n symbol,\n data,\n orderBookCache,\n cachedPriceData,\n createPriceUpdate,\n notifySubscribers,\n } = params;\n\n if (data?.coin !== symbol || !data?.levels) {\n return;\n }\n\n // Extract best bid and ask from order book\n const bestBid = data.levels[0]?.[0]; // First bid level\n const bestAsk = data.levels[1]?.[0]; // First ask level\n\n if (!bestBid && !bestAsk) {\n return;\n }\n\n const bidPrice = bestBid ? parseFloat(bestBid.px) : 0;\n const askPrice = bestAsk ? parseFloat(bestAsk.px) : 0;\n const spread =\n bidPrice > 0 && askPrice > 0 ? (askPrice - bidPrice).toFixed(5) : undefined;\n\n // Update order book cache\n orderBookCache.set(symbol, {\n bestBid: bestBid?.px,\n bestAsk: bestAsk?.px,\n spread,\n lastUpdated: Date.now(),\n });\n\n // Update cached price data with new order book data\n const currentCachedPrice = cachedPriceData?.get(symbol);\n if (!currentCachedPrice) {\n return;\n }\n\n const updatedPrice = createPriceUpdate(symbol, currentCachedPrice.price);\n\n // Ensure cache exists before setting\n if (cachedPriceData) {\n cachedPriceData.set(symbol, updatedPrice);\n notifySubscribers();\n }\n}\n\n/**\n * Process BBO (best bid/offer) data and update caches\n *\n * BBO is lightweight and independent from L2Book aggregation parameters,\n * making it ideal for spread / top-of-book display.\n *\n * @param params - The BBO processing parameters including symbol, data, and caches.\n */\nexport function processBboData(params: ProcessBboDataParams): void {\n const {\n symbol,\n data,\n orderBookCache,\n cachedPriceData,\n createPriceUpdate,\n notifySubscribers,\n } = params;\n\n if (data?.coin !== symbol || !Array.isArray(data?.bbo)) {\n return;\n }\n\n const [bestBid, bestAsk] = data.bbo;\n if (!bestBid && !bestAsk) {\n return;\n }\n\n const bidPrice = bestBid ? parseFloat(bestBid.px) : 0;\n const askPrice = bestAsk ? parseFloat(bestAsk.px) : 0;\n const spread =\n bidPrice > 0 && askPrice > 0 ? (askPrice - bidPrice).toFixed(5) : undefined;\n\n orderBookCache.set(symbol, {\n bestBid: bestBid?.px,\n bestAsk: bestAsk?.px,\n spread,\n lastUpdated: Date.now(),\n });\n\n const currentCachedPrice = cachedPriceData?.get(symbol);\n if (!currentCachedPrice) {\n return;\n }\n\n const updatedPrice = createPriceUpdate(symbol, currentCachedPrice.price);\n if (cachedPriceData) {\n cachedPriceData.set(symbol, updatedPrice);\n notifySubscribers();\n }\n}\n"]}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCoinExists = exports.validateOrderParams = exports.getMaxOrderValue = exports.getSupportedPaths = exports.applyPathFilters = exports.validateBalance = exports.validateAssetSupport = exports.validateDepositParams = exports.validateWithdrawalParams = exports.createErrorResult = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const hyperLiquidConfig_1 = require("../constants/hyperLiquidConfig.cjs");
|
|
6
|
+
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
7
|
+
const perpsErrorCodes_1 = require("../perpsErrorCodes.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* Validation utilities for HyperLiquid operations
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Create standardized error response.
|
|
13
|
+
*
|
|
14
|
+
* @param error - The error that occurred
|
|
15
|
+
* @param defaultResponse - The default response object to use as template
|
|
16
|
+
* @returns The error response with success=false and error message
|
|
17
|
+
*/
|
|
18
|
+
function createErrorResult(error, defaultResponse) {
|
|
19
|
+
return {
|
|
20
|
+
...defaultResponse,
|
|
21
|
+
success: false,
|
|
22
|
+
error: error instanceof Error ? error.message : perpsErrorCodes_1.PERPS_ERROR_CODES.UNKNOWN_ERROR,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.createErrorResult = createErrorResult;
|
|
26
|
+
/**
|
|
27
|
+
* Validate withdrawal parameters.
|
|
28
|
+
*
|
|
29
|
+
* @param params - Withdrawal parameters to validate
|
|
30
|
+
* @param params.assetId - The CAIP asset ID to withdraw
|
|
31
|
+
* @param params.amount - Amount to withdraw as string
|
|
32
|
+
* @param params.destination - Optional destination hex address
|
|
33
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
34
|
+
* @returns Validation result with isValid flag and optional error message
|
|
35
|
+
*/
|
|
36
|
+
function validateWithdrawalParams(params, debugLogger) {
|
|
37
|
+
debugLogger?.log('validateWithdrawalParams: Starting validation', {
|
|
38
|
+
params,
|
|
39
|
+
hasAssetId: Boolean(params.assetId),
|
|
40
|
+
hasAmount: Boolean(params.amount),
|
|
41
|
+
hasDestination: Boolean(params.destination),
|
|
42
|
+
});
|
|
43
|
+
// Validate required parameters
|
|
44
|
+
if (!params.assetId) {
|
|
45
|
+
debugLogger?.log('validateWithdrawalParams: Missing assetId', {
|
|
46
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_ASSET_ID_REQUIRED,
|
|
47
|
+
params,
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
isValid: false,
|
|
51
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_ASSET_ID_REQUIRED,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Validate amount
|
|
55
|
+
if (!params.amount) {
|
|
56
|
+
debugLogger?.log('validateWithdrawalParams: Missing amount', {
|
|
57
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_AMOUNT_REQUIRED,
|
|
58
|
+
params,
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
isValid: false,
|
|
62
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_AMOUNT_REQUIRED,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const amount = parseFloat(params.amount);
|
|
66
|
+
if (isNaN(amount) || amount <= 0) {
|
|
67
|
+
debugLogger?.log('validateWithdrawalParams: Invalid amount', {
|
|
68
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_AMOUNT_POSITIVE,
|
|
69
|
+
amount: params.amount,
|
|
70
|
+
parsedAmount: amount,
|
|
71
|
+
isNaN: isNaN(amount),
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
isValid: false,
|
|
75
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_AMOUNT_POSITIVE,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Validate destination address if provided
|
|
79
|
+
if (params.destination && !(0, utils_1.isValidHexAddress)(params.destination)) {
|
|
80
|
+
debugLogger?.log('validateWithdrawalParams: Invalid destination address', {
|
|
81
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_INVALID_DESTINATION,
|
|
82
|
+
destination: params.destination,
|
|
83
|
+
isValidHex: (0, utils_1.isValidHexAddress)(params.destination),
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
isValid: false,
|
|
87
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_INVALID_DESTINATION,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
debugLogger?.log('validateWithdrawalParams: All validations passed', {
|
|
91
|
+
assetId: params.assetId,
|
|
92
|
+
amount: params.amount,
|
|
93
|
+
destination: params.destination ?? 'will use user wallet',
|
|
94
|
+
});
|
|
95
|
+
return { isValid: true };
|
|
96
|
+
}
|
|
97
|
+
exports.validateWithdrawalParams = validateWithdrawalParams;
|
|
98
|
+
/**
|
|
99
|
+
* Validate deposit parameters.
|
|
100
|
+
*
|
|
101
|
+
* @param params - Deposit parameters to validate
|
|
102
|
+
* @param params.assetId - The CAIP asset ID to deposit
|
|
103
|
+
* @param params.amount - Amount to deposit as string
|
|
104
|
+
* @param params.isTestnet - Whether this is a testnet deposit
|
|
105
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
106
|
+
* @returns Validation result with isValid flag and optional error message
|
|
107
|
+
*/
|
|
108
|
+
function validateDepositParams(params, debugLogger) {
|
|
109
|
+
debugLogger?.log('validateDepositParams: Starting validation', {
|
|
110
|
+
params,
|
|
111
|
+
hasAssetId: Boolean(params.assetId),
|
|
112
|
+
hasAmount: Boolean(params.amount),
|
|
113
|
+
isTestnet: params.isTestnet,
|
|
114
|
+
});
|
|
115
|
+
// Validate required parameters
|
|
116
|
+
if (!params.assetId) {
|
|
117
|
+
debugLogger?.log('validateDepositParams: Missing assetId', {
|
|
118
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_ASSET_ID_REQUIRED,
|
|
119
|
+
params,
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
isValid: false,
|
|
123
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_ASSET_ID_REQUIRED,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Validate amount
|
|
127
|
+
if (!params.amount) {
|
|
128
|
+
debugLogger?.log('validateDepositParams: Missing amount', {
|
|
129
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_AMOUNT_REQUIRED,
|
|
130
|
+
params,
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
isValid: false,
|
|
134
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_AMOUNT_REQUIRED,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const amount = parseFloat(params.amount);
|
|
138
|
+
if (isNaN(amount) || amount <= 0) {
|
|
139
|
+
debugLogger?.log('validateDepositParams: Invalid amount', {
|
|
140
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_AMOUNT_POSITIVE,
|
|
141
|
+
amount: params.amount,
|
|
142
|
+
parsedAmount: amount,
|
|
143
|
+
isNaN: isNaN(amount),
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
isValid: false,
|
|
147
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_AMOUNT_POSITIVE,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Check minimum deposit amount
|
|
151
|
+
const minimumAmount = params.isTestnet
|
|
152
|
+
? hyperLiquidConfig_1.TRADING_DEFAULTS.amount.testnet
|
|
153
|
+
: hyperLiquidConfig_1.TRADING_DEFAULTS.amount.mainnet;
|
|
154
|
+
debugLogger?.log('validateDepositParams: Checking minimum amount', {
|
|
155
|
+
amount,
|
|
156
|
+
minimumAmount,
|
|
157
|
+
isTestnet: params.isTestnet,
|
|
158
|
+
network: params.isTestnet ? 'testnet' : 'mainnet',
|
|
159
|
+
});
|
|
160
|
+
if (amount < minimumAmount) {
|
|
161
|
+
debugLogger?.log('validateDepositParams: Below minimum deposit', {
|
|
162
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_MINIMUM_AMOUNT,
|
|
163
|
+
amount,
|
|
164
|
+
minimumAmount,
|
|
165
|
+
difference: minimumAmount - amount,
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
isValid: false,
|
|
169
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.DEPOSIT_MINIMUM_AMOUNT,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
debugLogger?.log('validateDepositParams: All validations passed', {
|
|
173
|
+
assetId: params.assetId,
|
|
174
|
+
amount: params.amount,
|
|
175
|
+
parsedAmount: amount,
|
|
176
|
+
minimumAmount,
|
|
177
|
+
isTestnet: params.isTestnet,
|
|
178
|
+
});
|
|
179
|
+
return { isValid: true };
|
|
180
|
+
}
|
|
181
|
+
exports.validateDepositParams = validateDepositParams;
|
|
182
|
+
/**
|
|
183
|
+
* Validate asset support for withdrawals using AssetRoute arrays.
|
|
184
|
+
*
|
|
185
|
+
* @param assetId - The CAIP asset ID to validate
|
|
186
|
+
* @param supportedRoutes - Array of supported asset routes
|
|
187
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
188
|
+
* @returns Validation result with isValid flag and optional error message
|
|
189
|
+
*/
|
|
190
|
+
function validateAssetSupport(assetId, supportedRoutes, debugLogger) {
|
|
191
|
+
debugLogger?.log('validateAssetSupport: Checking asset support', {
|
|
192
|
+
assetId,
|
|
193
|
+
supportedRoutesCount: supportedRoutes.length,
|
|
194
|
+
});
|
|
195
|
+
const supportedAssetIds = supportedRoutes.map((route) => route.assetId);
|
|
196
|
+
// Check if asset is supported
|
|
197
|
+
const isSupported = supportedAssetIds.includes(assetId);
|
|
198
|
+
if (!isSupported) {
|
|
199
|
+
// Also check case-insensitive match for contract addresses
|
|
200
|
+
const isSupportedCaseInsensitive = supportedAssetIds.some((supportedId) => supportedId.toLowerCase() === assetId.toLowerCase());
|
|
201
|
+
if (!isSupportedCaseInsensitive) {
|
|
202
|
+
debugLogger?.log('validateAssetSupport: Asset not supported', {
|
|
203
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_ASSET_NOT_SUPPORTED,
|
|
204
|
+
assetId,
|
|
205
|
+
supportedAssetIds,
|
|
206
|
+
checkedCaseInsensitive: true,
|
|
207
|
+
});
|
|
208
|
+
return {
|
|
209
|
+
isValid: false,
|
|
210
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_ASSET_NOT_SUPPORTED,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
debugLogger?.log('⚠️ validateAssetSupport: Asset supported with case mismatch', {
|
|
214
|
+
providedAssetId: assetId,
|
|
215
|
+
matchedAssetId: supportedAssetIds.find((id) => id.toLowerCase() === assetId.toLowerCase()),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
debugLogger?.log('validateAssetSupport: Asset is supported', {
|
|
219
|
+
assetId,
|
|
220
|
+
});
|
|
221
|
+
return { isValid: true };
|
|
222
|
+
}
|
|
223
|
+
exports.validateAssetSupport = validateAssetSupport;
|
|
224
|
+
/**
|
|
225
|
+
* Validate balance against withdrawal amount.
|
|
226
|
+
*
|
|
227
|
+
* @param withdrawAmount - The amount to withdraw
|
|
228
|
+
* @param availableBalance - The available balance
|
|
229
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
230
|
+
* @returns Validation result with isValid flag and optional error message
|
|
231
|
+
*/
|
|
232
|
+
function validateBalance(withdrawAmount, availableBalance, debugLogger) {
|
|
233
|
+
debugLogger?.log('validateBalance: Checking balance sufficiency', {
|
|
234
|
+
withdrawAmount,
|
|
235
|
+
availableBalance,
|
|
236
|
+
difference: availableBalance - withdrawAmount,
|
|
237
|
+
});
|
|
238
|
+
if (withdrawAmount > availableBalance) {
|
|
239
|
+
const shortfall = withdrawAmount - availableBalance;
|
|
240
|
+
debugLogger?.log('validateBalance: Insufficient balance', {
|
|
241
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_INSUFFICIENT_BALANCE,
|
|
242
|
+
withdrawAmount,
|
|
243
|
+
availableBalance,
|
|
244
|
+
shortfall,
|
|
245
|
+
percentageOfAvailable: `${((withdrawAmount / availableBalance) * 100).toFixed(2)}%`,
|
|
246
|
+
});
|
|
247
|
+
return {
|
|
248
|
+
isValid: false,
|
|
249
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.WITHDRAW_INSUFFICIENT_BALANCE,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const remainingBalance = availableBalance - withdrawAmount;
|
|
253
|
+
debugLogger?.log('validateBalance: Balance is sufficient', {
|
|
254
|
+
withdrawAmount,
|
|
255
|
+
availableBalance,
|
|
256
|
+
remainingBalance,
|
|
257
|
+
percentageUsed: `${((withdrawAmount / availableBalance) * 100).toFixed(2)}%`,
|
|
258
|
+
});
|
|
259
|
+
return { isValid: true };
|
|
260
|
+
}
|
|
261
|
+
exports.validateBalance = validateBalance;
|
|
262
|
+
/**
|
|
263
|
+
* Apply filters to asset paths with comprehensive logging.
|
|
264
|
+
*
|
|
265
|
+
* @param assets - Array of CAIP asset IDs to filter
|
|
266
|
+
* @param params - Filter parameters including chainId, symbol, and assetId
|
|
267
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
268
|
+
* @returns Filtered array of CAIP asset IDs
|
|
269
|
+
*/
|
|
270
|
+
function applyPathFilters(assets, params, debugLogger) {
|
|
271
|
+
if (!params) {
|
|
272
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - no params, returning all assets', { assets });
|
|
273
|
+
return assets;
|
|
274
|
+
}
|
|
275
|
+
let filtered = assets;
|
|
276
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - starting filter', {
|
|
277
|
+
initialAssets: assets,
|
|
278
|
+
filterParams: params,
|
|
279
|
+
});
|
|
280
|
+
if (params.chainId) {
|
|
281
|
+
const before = filtered;
|
|
282
|
+
filtered = filtered.filter((asset) => asset.startsWith(params.chainId));
|
|
283
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - chainId filter', {
|
|
284
|
+
chainId: params.chainId,
|
|
285
|
+
before,
|
|
286
|
+
after: filtered,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (params.symbol && params.symbol in hyperLiquidConfig_1.HYPERLIQUID_ASSET_CONFIGS) {
|
|
290
|
+
const config = hyperLiquidConfig_1.HYPERLIQUID_ASSET_CONFIGS[params.symbol];
|
|
291
|
+
const isTestnet = params.isTestnet ?? false;
|
|
292
|
+
const selectedAsset = isTestnet ? config.testnet : config.mainnet;
|
|
293
|
+
const before = filtered;
|
|
294
|
+
filtered = [selectedAsset];
|
|
295
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - symbol filter', {
|
|
296
|
+
symbol: params.symbol,
|
|
297
|
+
isTestnet,
|
|
298
|
+
config,
|
|
299
|
+
selectedAsset,
|
|
300
|
+
before,
|
|
301
|
+
after: filtered,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
if (params.assetId) {
|
|
305
|
+
const before = filtered;
|
|
306
|
+
// Use case-insensitive comparison for asset ID matching to handle address case differences
|
|
307
|
+
filtered = filtered.filter((asset) => asset.toLowerCase() === params.assetId?.toLowerCase());
|
|
308
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - assetId filter', {
|
|
309
|
+
assetId: params.assetId,
|
|
310
|
+
before,
|
|
311
|
+
after: filtered,
|
|
312
|
+
exactMatch: before.includes(params.assetId),
|
|
313
|
+
caseInsensitiveMatch: before.some((asset) => asset.toLowerCase() === params.assetId?.toLowerCase()),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
debugLogger?.log('HyperLiquid: applyPathFilters - final result', {
|
|
317
|
+
initialAssets: assets,
|
|
318
|
+
finalFiltered: filtered,
|
|
319
|
+
filterParams: params,
|
|
320
|
+
});
|
|
321
|
+
return filtered;
|
|
322
|
+
}
|
|
323
|
+
exports.applyPathFilters = applyPathFilters;
|
|
324
|
+
/**
|
|
325
|
+
* Get supported deposit/withdrawal paths with filtering.
|
|
326
|
+
*
|
|
327
|
+
* @param params - Filter parameters including isTestnet, chainId, symbol
|
|
328
|
+
* @param debugLogger - Optional debug logger for detailed logging
|
|
329
|
+
* @returns Array of supported CAIP asset IDs
|
|
330
|
+
*/
|
|
331
|
+
function getSupportedPaths(params, debugLogger) {
|
|
332
|
+
const isTestnet = params?.isTestnet ?? false;
|
|
333
|
+
const assets = (0, hyperLiquidConfig_1.getSupportedAssets)(isTestnet);
|
|
334
|
+
const filteredAssets = applyPathFilters(assets, params, debugLogger);
|
|
335
|
+
debugLogger?.log('HyperLiquid: getSupportedPaths', {
|
|
336
|
+
isTestnet,
|
|
337
|
+
requestedParams: params,
|
|
338
|
+
allAssets: assets,
|
|
339
|
+
filteredAssets,
|
|
340
|
+
returnType: 'CaipAssetId[]',
|
|
341
|
+
example: filteredAssets[0],
|
|
342
|
+
});
|
|
343
|
+
return filteredAssets;
|
|
344
|
+
}
|
|
345
|
+
exports.getSupportedPaths = getSupportedPaths;
|
|
346
|
+
/**
|
|
347
|
+
* Get maximum order value based on leverage and order type.
|
|
348
|
+
* Based on HyperLiquid contract specifications.
|
|
349
|
+
*
|
|
350
|
+
* @param maxLeverage - The maximum leverage for the market
|
|
351
|
+
* @param orderType - The order type (market or limit)
|
|
352
|
+
* @returns Maximum order value in USD
|
|
353
|
+
*/
|
|
354
|
+
function getMaxOrderValue(maxLeverage, orderType) {
|
|
355
|
+
let marketLimit;
|
|
356
|
+
if (maxLeverage >= 25) {
|
|
357
|
+
marketLimit = perpsConfig_1.HYPERLIQUID_ORDER_LIMITS.MarketOrderLimits.HighLeverage;
|
|
358
|
+
}
|
|
359
|
+
else if (maxLeverage >= 20) {
|
|
360
|
+
marketLimit = perpsConfig_1.HYPERLIQUID_ORDER_LIMITS.MarketOrderLimits.MediumHighLeverage;
|
|
361
|
+
}
|
|
362
|
+
else if (maxLeverage >= 10) {
|
|
363
|
+
marketLimit = perpsConfig_1.HYPERLIQUID_ORDER_LIMITS.MarketOrderLimits.MediumLeverage;
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
marketLimit = perpsConfig_1.HYPERLIQUID_ORDER_LIMITS.MarketOrderLimits.LowLeverage;
|
|
367
|
+
}
|
|
368
|
+
return orderType === 'limit'
|
|
369
|
+
? marketLimit * perpsConfig_1.HYPERLIQUID_ORDER_LIMITS.LimitOrderMultiplier
|
|
370
|
+
: marketLimit;
|
|
371
|
+
}
|
|
372
|
+
exports.getMaxOrderValue = getMaxOrderValue;
|
|
373
|
+
/**
|
|
374
|
+
* Validate order parameters.
|
|
375
|
+
* Basic validation - checks required fields are present.
|
|
376
|
+
* Amount validation (size/USD) is handled by validateOrder.
|
|
377
|
+
*
|
|
378
|
+
* @param params - Order parameters to validate
|
|
379
|
+
* @param params.coin - The trading pair coin symbol
|
|
380
|
+
* @param params.size - The order size as string
|
|
381
|
+
* @param params.price - The order price as string
|
|
382
|
+
* @param params.orderType - The order type (market or limit)
|
|
383
|
+
* @returns Validation result with isValid flag and optional error message
|
|
384
|
+
*/
|
|
385
|
+
function validateOrderParams(params) {
|
|
386
|
+
if (!params.coin) {
|
|
387
|
+
return {
|
|
388
|
+
isValid: false,
|
|
389
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.ORDER_COIN_REQUIRED,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
// Note: Size validation removed - validateOrder handles amount validation using USD as source of truth
|
|
393
|
+
// Require price for limit orders
|
|
394
|
+
if (params.orderType === 'limit' && !params.price) {
|
|
395
|
+
return {
|
|
396
|
+
isValid: false,
|
|
397
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.ORDER_LIMIT_PRICE_REQUIRED,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (params.price && parseFloat(params.price) <= 0) {
|
|
401
|
+
return {
|
|
402
|
+
isValid: false,
|
|
403
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.ORDER_PRICE_POSITIVE,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
return { isValid: true };
|
|
407
|
+
}
|
|
408
|
+
exports.validateOrderParams = validateOrderParams;
|
|
409
|
+
/**
|
|
410
|
+
* Validate coin exists in asset mapping.
|
|
411
|
+
*
|
|
412
|
+
* @param coin - The coin symbol to validate
|
|
413
|
+
* @param coinToAssetId - Map of coin symbols to asset IDs
|
|
414
|
+
* @returns Validation result with isValid flag and optional error message
|
|
415
|
+
*/
|
|
416
|
+
function validateCoinExists(coin, coinToAssetId) {
|
|
417
|
+
if (!coinToAssetId.has(coin)) {
|
|
418
|
+
return {
|
|
419
|
+
isValid: false,
|
|
420
|
+
error: perpsErrorCodes_1.PERPS_ERROR_CODES.ORDER_UNKNOWN_COIN,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return { isValid: true };
|
|
424
|
+
}
|
|
425
|
+
exports.validateCoinExists = validateCoinExists;
|
|
426
|
+
//# sourceMappingURL=hyperLiquidValidation.cjs.map
|