@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,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roundToSignificantFigures = exports.hasExceededSignificantFigures = exports.countSignificantFigures = void 0;
|
|
4
|
+
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Count significant figures in a price string.
|
|
7
|
+
* Pure math function extracted from formatUtils for portability.
|
|
8
|
+
*
|
|
9
|
+
* @param priceString - The price string to count significant figures for.
|
|
10
|
+
* @returns The number of significant figures in the price string.
|
|
11
|
+
*/
|
|
12
|
+
const countSignificantFigures = (priceString) => {
|
|
13
|
+
if (!priceString) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
17
|
+
const number = parseFloat(cleaned);
|
|
18
|
+
if (isNaN(number) || number === 0) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const normalized = number.toString();
|
|
22
|
+
const [integerPart, decimalPart = ''] = normalized.split('.');
|
|
23
|
+
const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
|
|
24
|
+
const effectiveIntegerLength = decimalPart
|
|
25
|
+
? trimmedInteger.length
|
|
26
|
+
: trimmedInteger.replace(/0+$/u, '').length ||
|
|
27
|
+
(trimmedInteger.length > 0 ? 1 : 0);
|
|
28
|
+
return effectiveIntegerLength + decimalPart.length;
|
|
29
|
+
};
|
|
30
|
+
exports.countSignificantFigures = countSignificantFigures;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a price string exceeds the maximum significant figures.
|
|
33
|
+
*
|
|
34
|
+
* @param priceString - The price string to check.
|
|
35
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
36
|
+
* @returns True if the price string exceeds the maximum significant figures.
|
|
37
|
+
*/
|
|
38
|
+
const hasExceededSignificantFigures = (priceString, maxSigFigs = perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
|
|
39
|
+
if (!priceString || priceString.trim() === '') {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
43
|
+
const number = parseFloat(cleaned);
|
|
44
|
+
if (isNaN(number)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const normalized = number.toString();
|
|
48
|
+
if (!normalized.includes('.')) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return (0, exports.countSignificantFigures)(priceString) > maxSigFigs;
|
|
52
|
+
};
|
|
53
|
+
exports.hasExceededSignificantFigures = hasExceededSignificantFigures;
|
|
54
|
+
/**
|
|
55
|
+
* Round a price string to the maximum significant figures.
|
|
56
|
+
*
|
|
57
|
+
* @param priceString - The price string to round.
|
|
58
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
59
|
+
* @returns The price string rounded to the specified significant figures.
|
|
60
|
+
*/
|
|
61
|
+
const roundToSignificantFigures = (priceString, maxSigFigs = perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
|
|
62
|
+
if (!priceString || priceString.trim() === '') {
|
|
63
|
+
return priceString;
|
|
64
|
+
}
|
|
65
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
66
|
+
const number = Number.parseFloat(cleaned);
|
|
67
|
+
if (Number.isNaN(number) || number === 0) {
|
|
68
|
+
return priceString;
|
|
69
|
+
}
|
|
70
|
+
const normalized = number.toString();
|
|
71
|
+
const [integerPart, decimalPart = ''] = normalized.split('.');
|
|
72
|
+
const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
|
|
73
|
+
const integerSigFigs = trimmedInteger.length;
|
|
74
|
+
if (!decimalPart) {
|
|
75
|
+
return normalized;
|
|
76
|
+
}
|
|
77
|
+
const allowedDecimalDigits = maxSigFigs - integerSigFigs;
|
|
78
|
+
if (allowedDecimalDigits <= 0) {
|
|
79
|
+
return Math.round(number).toString();
|
|
80
|
+
}
|
|
81
|
+
if (decimalPart.length <= allowedDecimalDigits) {
|
|
82
|
+
return normalized;
|
|
83
|
+
}
|
|
84
|
+
const rounded = number.toFixed(allowedDecimalDigits);
|
|
85
|
+
return Number.parseFloat(rounded).toString();
|
|
86
|
+
};
|
|
87
|
+
exports.roundToSignificantFigures = roundToSignificantFigures;
|
|
88
|
+
//# sourceMappingURL=significantFigures.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"significantFigures.cjs","sourceRoot":"","sources":["../../src/utils/significantFigures.ts"],"names":[],"mappings":";;;AAAA,8DAAoE;AAEpE;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,CAAC,WAAmB,EAAU,EAAE;IACrE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,K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,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,IAAI,oBAAoB,EAAE,CAAC;QAC/C,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC/C,CAAC,CAAC;AApCW,QAAA,yBAAyB,6BAoCpC","sourcesContent":["import { DECIMAL_PRECISION_CONFIG } from '../constants/perpsConfig';\n\n/**\n * Count significant figures in a price string.\n * Pure math function extracted from formatUtils for portability.\n *\n * @param priceString - The price string to count significant figures for.\n * @returns The number of significant figures in the price string.\n */\nexport const countSignificantFigures = (priceString: string): number => {\n if (!priceString) {\n return 0;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = parseFloat(cleaned);\n if (isNaN(number) || number === 0) {\n return 0;\n }\n\n const normalized = number.toString();\n const [integerPart, decimalPart = ''] = normalized.split('.');\n const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';\n\n const effectiveIntegerLength = decimalPart\n ? trimmedInteger.length\n : trimmedInteger.replace(/0+$/u, '').length ||\n (trimmedInteger.length > 0 ? 1 : 0);\n\n return effectiveIntegerLength + decimalPart.length;\n};\n\n/**\n * Check if a price string exceeds the maximum significant figures.\n *\n * @param priceString - The price string to check.\n * @param maxSigFigs - The maximum allowed significant figures.\n * @returns True if the price string exceeds the maximum significant figures.\n */\nexport const hasExceededSignificantFigures = (\n priceString: string,\n maxSigFigs: number = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures,\n): boolean => {\n if (!priceString || priceString.trim() === '') {\n return false;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = parseFloat(cleaned);\n if (isNaN(number)) {\n return false;\n }\n\n const normalized = number.toString();\n if (!normalized.includes('.')) {\n return false;\n }\n\n return countSignificantFigures(priceString) > maxSigFigs;\n};\n\n/**\n * Round a price string to the maximum significant figures.\n *\n * @param priceString - The price string to round.\n * @param maxSigFigs - The maximum allowed significant figures.\n * @returns The price string rounded to the specified significant figures.\n */\nexport const roundToSignificantFigures = (\n priceString: string,\n maxSigFigs: number = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures,\n): string => {\n if (!priceString || priceString.trim() === '') {\n return priceString;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = Number.parseFloat(cleaned);\n if (Number.isNaN(number) || number === 0) {\n return priceString;\n }\n\n const normalized = number.toString();\n const [integerPart, decimalPart = ''] = normalized.split('.');\n\n const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';\n const integerSigFigs = trimmedInteger.length;\n\n if (!decimalPart) {\n return normalized;\n }\n\n const allowedDecimalDigits = maxSigFigs - integerSigFigs;\n\n if (allowedDecimalDigits <= 0) {\n return Math.round(number).toString();\n }\n\n if (decimalPart.length <= allowedDecimalDigits) {\n return normalized;\n }\n\n const rounded = number.toFixed(allowedDecimalDigits);\n return Number.parseFloat(rounded).toString();\n};\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Count significant figures in a price string.
|
|
3
|
+
* Pure math function extracted from formatUtils for portability.
|
|
4
|
+
*
|
|
5
|
+
* @param priceString - The price string to count significant figures for.
|
|
6
|
+
* @returns The number of significant figures in the price string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const countSignificantFigures: (priceString: string) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a price string exceeds the maximum significant figures.
|
|
11
|
+
*
|
|
12
|
+
* @param priceString - The price string to check.
|
|
13
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
14
|
+
* @returns True if the price string exceeds the maximum significant figures.
|
|
15
|
+
*/
|
|
16
|
+
export declare const hasExceededSignificantFigures: (priceString: string, maxSigFigs?: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Round a price string to the maximum significant figures.
|
|
19
|
+
*
|
|
20
|
+
* @param priceString - The price string to round.
|
|
21
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
22
|
+
* @returns The price string rounded to the specified significant figures.
|
|
23
|
+
*/
|
|
24
|
+
export declare const roundToSignificantFigures: (priceString: string, maxSigFigs?: number) => string;
|
|
25
|
+
//# sourceMappingURL=significantFigures.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"significantFigures.d.cts","sourceRoot":"","sources":["../../src/utils/significantFigures.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,KAAG,MAqB7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,gBAC3B,MAAM,eACP,MAAM,KACjB,OAiBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,gBACvB,MAAM,eACP,MAAM,KACjB,MAiCF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Count significant figures in a price string.
|
|
3
|
+
* Pure math function extracted from formatUtils for portability.
|
|
4
|
+
*
|
|
5
|
+
* @param priceString - The price string to count significant figures for.
|
|
6
|
+
* @returns The number of significant figures in the price string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const countSignificantFigures: (priceString: string) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a price string exceeds the maximum significant figures.
|
|
11
|
+
*
|
|
12
|
+
* @param priceString - The price string to check.
|
|
13
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
14
|
+
* @returns True if the price string exceeds the maximum significant figures.
|
|
15
|
+
*/
|
|
16
|
+
export declare const hasExceededSignificantFigures: (priceString: string, maxSigFigs?: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Round a price string to the maximum significant figures.
|
|
19
|
+
*
|
|
20
|
+
* @param priceString - The price string to round.
|
|
21
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
22
|
+
* @returns The price string rounded to the specified significant figures.
|
|
23
|
+
*/
|
|
24
|
+
export declare const roundToSignificantFigures: (priceString: string, maxSigFigs?: number) => string;
|
|
25
|
+
//# sourceMappingURL=significantFigures.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"significantFigures.d.mts","sourceRoot":"","sources":["../../src/utils/significantFigures.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,KAAG,MAqB7D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,gBAC3B,MAAM,eACP,MAAM,KACjB,OAiBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,gBACvB,MAAM,eACP,MAAM,KACjB,MAiCF,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { DECIMAL_PRECISION_CONFIG } from "../constants/perpsConfig.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Count significant figures in a price string.
|
|
4
|
+
* Pure math function extracted from formatUtils for portability.
|
|
5
|
+
*
|
|
6
|
+
* @param priceString - The price string to count significant figures for.
|
|
7
|
+
* @returns The number of significant figures in the price string.
|
|
8
|
+
*/
|
|
9
|
+
export const countSignificantFigures = (priceString) => {
|
|
10
|
+
if (!priceString) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
14
|
+
const number = parseFloat(cleaned);
|
|
15
|
+
if (isNaN(number) || number === 0) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const normalized = number.toString();
|
|
19
|
+
const [integerPart, decimalPart = ''] = normalized.split('.');
|
|
20
|
+
const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
|
|
21
|
+
const effectiveIntegerLength = decimalPart
|
|
22
|
+
? trimmedInteger.length
|
|
23
|
+
: trimmedInteger.replace(/0+$/u, '').length ||
|
|
24
|
+
(trimmedInteger.length > 0 ? 1 : 0);
|
|
25
|
+
return effectiveIntegerLength + decimalPart.length;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Check if a price string exceeds the maximum significant figures.
|
|
29
|
+
*
|
|
30
|
+
* @param priceString - The price string to check.
|
|
31
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
32
|
+
* @returns True if the price string exceeds the maximum significant figures.
|
|
33
|
+
*/
|
|
34
|
+
export const hasExceededSignificantFigures = (priceString, maxSigFigs = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
|
|
35
|
+
if (!priceString || priceString.trim() === '') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
39
|
+
const number = parseFloat(cleaned);
|
|
40
|
+
if (isNaN(number)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const normalized = number.toString();
|
|
44
|
+
if (!normalized.includes('.')) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return countSignificantFigures(priceString) > maxSigFigs;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Round a price string to the maximum significant figures.
|
|
51
|
+
*
|
|
52
|
+
* @param priceString - The price string to round.
|
|
53
|
+
* @param maxSigFigs - The maximum allowed significant figures.
|
|
54
|
+
* @returns The price string rounded to the specified significant figures.
|
|
55
|
+
*/
|
|
56
|
+
export const roundToSignificantFigures = (priceString, maxSigFigs = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
|
|
57
|
+
if (!priceString || priceString.trim() === '') {
|
|
58
|
+
return priceString;
|
|
59
|
+
}
|
|
60
|
+
const cleaned = priceString.replace(/[$,]/gu, '').trim();
|
|
61
|
+
const number = Number.parseFloat(cleaned);
|
|
62
|
+
if (Number.isNaN(number) || number === 0) {
|
|
63
|
+
return priceString;
|
|
64
|
+
}
|
|
65
|
+
const normalized = number.toString();
|
|
66
|
+
const [integerPart, decimalPart = ''] = normalized.split('.');
|
|
67
|
+
const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
|
|
68
|
+
const integerSigFigs = trimmedInteger.length;
|
|
69
|
+
if (!decimalPart) {
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
const allowedDecimalDigits = maxSigFigs - integerSigFigs;
|
|
73
|
+
if (allowedDecimalDigits <= 0) {
|
|
74
|
+
return Math.round(number).toString();
|
|
75
|
+
}
|
|
76
|
+
if (decimalPart.length <= allowedDecimalDigits) {
|
|
77
|
+
return normalized;
|
|
78
|
+
}
|
|
79
|
+
const rounded = number.toFixed(allowedDecimalDigits);
|
|
80
|
+
return Number.parseFloat(rounded).toString();
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=significantFigures.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"significantFigures.mjs","sourceRoot":"","sources":["../../src/utils/significantFigures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,qCAAiC;AAEpE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,WAAmB,EAAU,EAAE;IACrE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9D,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAA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pure math function extracted from formatUtils for portability.\n *\n * @param priceString - The price string to count significant figures for.\n * @returns The number of significant figures in the price string.\n */\nexport const countSignificantFigures = (priceString: string): number => {\n if (!priceString) {\n return 0;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = parseFloat(cleaned);\n if (isNaN(number) || number === 0) {\n return 0;\n }\n\n const normalized = number.toString();\n const [integerPart, decimalPart = ''] = normalized.split('.');\n const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';\n\n const effectiveIntegerLength = decimalPart\n ? trimmedInteger.length\n : trimmedInteger.replace(/0+$/u, '').length ||\n (trimmedInteger.length > 0 ? 1 : 0);\n\n return effectiveIntegerLength + decimalPart.length;\n};\n\n/**\n * Check if a price string exceeds the maximum significant figures.\n *\n * @param priceString - The price string to check.\n * @param maxSigFigs - The maximum allowed significant figures.\n * @returns True if the price string exceeds the maximum significant figures.\n */\nexport const hasExceededSignificantFigures = (\n priceString: string,\n maxSigFigs: number = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures,\n): boolean => {\n if (!priceString || priceString.trim() === '') {\n return false;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = parseFloat(cleaned);\n if (isNaN(number)) {\n return false;\n }\n\n const normalized = number.toString();\n if (!normalized.includes('.')) {\n return false;\n }\n\n return countSignificantFigures(priceString) > maxSigFigs;\n};\n\n/**\n * Round a price string to the maximum significant figures.\n *\n * @param priceString - The price string to round.\n * @param maxSigFigs - The maximum allowed significant figures.\n * @returns The price string rounded to the specified significant figures.\n */\nexport const roundToSignificantFigures = (\n priceString: string,\n maxSigFigs: number = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures,\n): string => {\n if (!priceString || priceString.trim() === '') {\n return priceString;\n }\n\n const cleaned = priceString.replace(/[$,]/gu, '').trim();\n const number = Number.parseFloat(cleaned);\n if (Number.isNaN(number) || number === 0) {\n return priceString;\n }\n\n const normalized = number.toString();\n const [integerPart, decimalPart = ''] = normalized.split('.');\n\n const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';\n const integerSigFigs = trimmedInteger.length;\n\n if (!decimalPart) {\n return normalized;\n }\n\n const allowedDecimalDigits = maxSigFigs - integerSigFigs;\n\n if (allowedDecimalDigits <= 0) {\n return Math.round(number).toString();\n }\n\n if (decimalPart.length <= allowedDecimalDigits) {\n return normalized;\n }\n\n const rounded = number.toFixed(allowedDecimalDigits);\n return Number.parseFloat(rounded).toString();\n};\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortMarkets = exports.parseVolume = void 0;
|
|
4
|
+
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
5
|
+
const VOLUME_SUFFIX_REGEX = /\$?([\d.,]+)([KMBT])?/u;
|
|
6
|
+
const multipliers = {
|
|
7
|
+
K: 1e3,
|
|
8
|
+
M: 1e6,
|
|
9
|
+
B: 1e9,
|
|
10
|
+
T: 1e12,
|
|
11
|
+
};
|
|
12
|
+
const removeCommas = (str) => str.replace(/,/gu, '');
|
|
13
|
+
/**
|
|
14
|
+
* Parse a formatted volume string (e.g., "$1.5M", "$2.3B") to a numeric value.
|
|
15
|
+
* Extracted from hooks/usePerpsMarkets.ts for portability.
|
|
16
|
+
*
|
|
17
|
+
* @param volumeStr - The formatted volume string to parse.
|
|
18
|
+
* @returns The numeric volume value, or -1 if unparseable.
|
|
19
|
+
*/
|
|
20
|
+
const parseVolume = (volumeStr) => {
|
|
21
|
+
if (!volumeStr) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
if (volumeStr === perpsConfig_1.PERPS_CONSTANTS.FallbackPriceDisplay) {
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
if (volumeStr === '$<1') {
|
|
28
|
+
return 0.5;
|
|
29
|
+
}
|
|
30
|
+
const suffixMatch = VOLUME_SUFFIX_REGEX.exec(volumeStr);
|
|
31
|
+
if (suffixMatch) {
|
|
32
|
+
const [, numberPart, suffix] = suffixMatch;
|
|
33
|
+
const baseValue = Number.parseFloat(removeCommas(numberPart));
|
|
34
|
+
if (Number.isNaN(baseValue)) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
return suffix ? baseValue * multipliers[suffix] : baseValue;
|
|
38
|
+
}
|
|
39
|
+
// Fallback: try to parse as plain number
|
|
40
|
+
const cleaned = volumeStr.replace(/[$,]/gu, '');
|
|
41
|
+
const parsed = Number.parseFloat(cleaned);
|
|
42
|
+
return Number.isNaN(parsed) ? -1 : parsed;
|
|
43
|
+
};
|
|
44
|
+
exports.parseVolume = parseVolume;
|
|
45
|
+
/**
|
|
46
|
+
* Sorts markets based on the specified criteria.
|
|
47
|
+
*
|
|
48
|
+
* @param options0 - The sorting configuration.
|
|
49
|
+
* @param options0.markets - The array of market data to sort.
|
|
50
|
+
* @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).
|
|
51
|
+
* @param options0.direction - The sort direction (asc or desc).
|
|
52
|
+
* @returns A new sorted array of market data.
|
|
53
|
+
*/
|
|
54
|
+
const sortMarkets = ({ markets, sortBy, direction = perpsConfig_1.MARKET_SORTING_CONFIG.DefaultDirection, }) => {
|
|
55
|
+
const sortedMarkets = [...markets];
|
|
56
|
+
sortedMarkets.sort((a, b) => {
|
|
57
|
+
let compareValue = 0;
|
|
58
|
+
switch (sortBy) {
|
|
59
|
+
case perpsConfig_1.MARKET_SORTING_CONFIG.SortFields.Volume: {
|
|
60
|
+
const volumeA = (0, exports.parseVolume)(a.volume);
|
|
61
|
+
const volumeB = (0, exports.parseVolume)(b.volume);
|
|
62
|
+
compareValue = volumeA - volumeB;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case perpsConfig_1.MARKET_SORTING_CONFIG.SortFields.PriceChange: {
|
|
66
|
+
const changeA = parseFloat(a.change24hPercent?.replace(/[%+]/gu, '') || '0');
|
|
67
|
+
const changeB = parseFloat(b.change24hPercent?.replace(/[%+]/gu, '') || '0');
|
|
68
|
+
compareValue = changeA - changeB;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case perpsConfig_1.MARKET_SORTING_CONFIG.SortFields.FundingRate: {
|
|
72
|
+
const fundingA = a.fundingRate ?? 0;
|
|
73
|
+
const fundingB = b.fundingRate ?? 0;
|
|
74
|
+
compareValue = fundingA - fundingB;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case perpsConfig_1.MARKET_SORTING_CONFIG.SortFields.OpenInterest: {
|
|
78
|
+
const openInterestA = (0, exports.parseVolume)(a.openInterest);
|
|
79
|
+
const openInterestB = (0, exports.parseVolume)(b.openInterest);
|
|
80
|
+
compareValue = openInterestA - openInterestB;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return direction === perpsConfig_1.MARKET_SORTING_CONFIG.DefaultDirection
|
|
87
|
+
? compareValue * -1
|
|
88
|
+
: compareValue;
|
|
89
|
+
});
|
|
90
|
+
return sortedMarkets;
|
|
91
|
+
};
|
|
92
|
+
exports.sortMarkets = sortMarkets;
|
|
93
|
+
//# sourceMappingURL=sortMarkets.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMarkets.cjs","sourceRoot":"","sources":["../../src/utils/sortMarkets.ts"],"names":[],"mappings":";;;AAAA,8DAGkC;AAgBlC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAErD,MAAM,WAAW,GAA2B;IAC1C,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,IAAI;CACC,CAAC;AAEX,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAErE;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CAAC,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AAC,CAAC,CAAC,YAAY,CAAC,CAAC;gBAClD,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;gBAC7C,MAAM;YACR,CAAC;YAED;gBACE,MAAM;QACV,CAAC;QAED,OAAO,SAAS,KAAK,mCAAqB,CAAC,gBAAgB;YACzD,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC;YACnB,CAAC,CAAC,YAAY,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AArDW,QAAA,WAAW,eAqDtB","sourcesContent":["import {\n MARKET_SORTING_CONFIG,\n PERPS_CONSTANTS,\n} from '../constants/perpsConfig';\nimport type { PerpsMarketData } from '../types';\n\nexport type SortField =\n | 'volume'\n | 'priceChange'\n | 'fundingRate'\n | 'openInterest';\nexport type SortDirection = 'asc' | 'desc';\n\nexport type SortMarketsParams = {\n markets: PerpsMarketData[];\n sortBy: SortField;\n direction?: SortDirection;\n};\n\nconst VOLUME_SUFFIX_REGEX = /\\$?([\\d.,]+)([KMBT])?/u;\n\nconst multipliers: Record<string, number> = {\n K: 1e3,\n M: 1e6,\n B: 1e9,\n T: 1e12,\n} as const;\n\nconst removeCommas = (str: string): string => str.replace(/,/gu, '');\n\n/**\n * Parse a formatted volume string (e.g., \"$1.5M\", \"$2.3B\") to a numeric value.\n * Extracted from hooks/usePerpsMarkets.ts for portability.\n *\n * @param volumeStr - The formatted volume string to parse.\n * @returns The numeric volume value, or -1 if unparseable.\n */\nexport const parseVolume = (volumeStr: string | undefined): number => {\n if (!volumeStr) {\n return -1;\n }\n\n if (volumeStr === PERPS_CONSTANTS.FallbackPriceDisplay) {\n return -1;\n }\n if (volumeStr === '$<1') {\n return 0.5;\n }\n\n const suffixMatch = VOLUME_SUFFIX_REGEX.exec(volumeStr);\n if (suffixMatch) {\n const [, numberPart, suffix] = suffixMatch;\n const baseValue = Number.parseFloat(removeCommas(numberPart));\n\n if (Number.isNaN(baseValue)) {\n return -1;\n }\n\n return suffix ? baseValue * multipliers[suffix] : baseValue;\n }\n\n // Fallback: try to parse as plain number\n const cleaned = volumeStr.replace(/[$,]/gu, '');\n const parsed = Number.parseFloat(cleaned);\n return Number.isNaN(parsed) ? -1 : parsed;\n};\n\n/**\n * Sorts markets based on the specified criteria.\n *\n * @param options0 - The sorting configuration.\n * @param options0.markets - The array of market data to sort.\n * @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).\n * @param options0.direction - The sort direction (asc or desc).\n * @returns A new sorted array of market data.\n */\nexport const sortMarkets = ({\n markets,\n sortBy,\n direction = MARKET_SORTING_CONFIG.DefaultDirection,\n}: SortMarketsParams): PerpsMarketData[] => {\n const sortedMarkets = [...markets];\n\n sortedMarkets.sort((a, b) => {\n let compareValue = 0;\n\n switch (sortBy) {\n case MARKET_SORTING_CONFIG.SortFields.Volume: {\n const volumeA = parseVolume(a.volume);\n const volumeB = parseVolume(b.volume);\n compareValue = volumeA - volumeB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.PriceChange: {\n const changeA = parseFloat(\n a.change24hPercent?.replace(/[%+]/gu, '') || '0',\n );\n const changeB = parseFloat(\n b.change24hPercent?.replace(/[%+]/gu, '') || '0',\n );\n compareValue = changeA - changeB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.FundingRate: {\n const fundingA = a.fundingRate ?? 0;\n const fundingB = b.fundingRate ?? 0;\n compareValue = fundingA - fundingB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.OpenInterest: {\n const openInterestA = parseVolume(a.openInterest);\n const openInterestB = parseVolume(b.openInterest);\n compareValue = openInterestA - openInterestB;\n break;\n }\n\n default:\n break;\n }\n\n return direction === MARKET_SORTING_CONFIG.DefaultDirection\n ? compareValue * -1\n : compareValue;\n });\n\n return sortedMarkets;\n};\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PerpsMarketData } from "../types/index.cjs";
|
|
2
|
+
export type SortField = 'volume' | 'priceChange' | 'fundingRate' | 'openInterest';
|
|
3
|
+
export type SortDirection = 'asc' | 'desc';
|
|
4
|
+
export type SortMarketsParams = {
|
|
5
|
+
markets: PerpsMarketData[];
|
|
6
|
+
sortBy: SortField;
|
|
7
|
+
direction?: SortDirection;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Parse a formatted volume string (e.g., "$1.5M", "$2.3B") to a numeric value.
|
|
11
|
+
* Extracted from hooks/usePerpsMarkets.ts for portability.
|
|
12
|
+
*
|
|
13
|
+
* @param volumeStr - The formatted volume string to parse.
|
|
14
|
+
* @returns The numeric volume value, or -1 if unparseable.
|
|
15
|
+
*/
|
|
16
|
+
export declare const parseVolume: (volumeStr: string | undefined) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Sorts markets based on the specified criteria.
|
|
19
|
+
*
|
|
20
|
+
* @param options0 - The sorting configuration.
|
|
21
|
+
* @param options0.markets - The array of market data to sort.
|
|
22
|
+
* @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).
|
|
23
|
+
* @param options0.direction - The sort direction (asc or desc).
|
|
24
|
+
* @returns A new sorted array of market data.
|
|
25
|
+
*/
|
|
26
|
+
export declare const sortMarkets: ({ markets, sortBy, direction, }: SortMarketsParams) => PerpsMarketData[];
|
|
27
|
+
//# sourceMappingURL=sortMarkets.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMarkets.d.cts","sourceRoot":"","sources":["../../src/utils/sortMarkets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,2BAAiB;AAEhD,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,aAAa,GACb,aAAa,GACb,cAAc,CAAC;AACnB,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAaF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,cAAe,MAAM,GAAG,SAAS,KAAG,MA4B3D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,oCAIrB,iBAAiB,KAAG,eAAe,EAiDrC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PerpsMarketData } from "../types/index.mjs";
|
|
2
|
+
export type SortField = 'volume' | 'priceChange' | 'fundingRate' | 'openInterest';
|
|
3
|
+
export type SortDirection = 'asc' | 'desc';
|
|
4
|
+
export type SortMarketsParams = {
|
|
5
|
+
markets: PerpsMarketData[];
|
|
6
|
+
sortBy: SortField;
|
|
7
|
+
direction?: SortDirection;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Parse a formatted volume string (e.g., "$1.5M", "$2.3B") to a numeric value.
|
|
11
|
+
* Extracted from hooks/usePerpsMarkets.ts for portability.
|
|
12
|
+
*
|
|
13
|
+
* @param volumeStr - The formatted volume string to parse.
|
|
14
|
+
* @returns The numeric volume value, or -1 if unparseable.
|
|
15
|
+
*/
|
|
16
|
+
export declare const parseVolume: (volumeStr: string | undefined) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Sorts markets based on the specified criteria.
|
|
19
|
+
*
|
|
20
|
+
* @param options0 - The sorting configuration.
|
|
21
|
+
* @param options0.markets - The array of market data to sort.
|
|
22
|
+
* @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).
|
|
23
|
+
* @param options0.direction - The sort direction (asc or desc).
|
|
24
|
+
* @returns A new sorted array of market data.
|
|
25
|
+
*/
|
|
26
|
+
export declare const sortMarkets: ({ markets, sortBy, direction, }: SortMarketsParams) => PerpsMarketData[];
|
|
27
|
+
//# sourceMappingURL=sortMarkets.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMarkets.d.mts","sourceRoot":"","sources":["../../src/utils/sortMarkets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,2BAAiB;AAEhD,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,aAAa,GACb,aAAa,GACb,cAAc,CAAC;AACnB,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;AAE3C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAaF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,cAAe,MAAM,GAAG,SAAS,KAAG,MA4B3D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,oCAIrB,iBAAiB,KAAG,eAAe,EAiDrC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MARKET_SORTING_CONFIG, PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
|
|
2
|
+
const VOLUME_SUFFIX_REGEX = /\$?([\d.,]+)([KMBT])?/u;
|
|
3
|
+
const multipliers = {
|
|
4
|
+
K: 1e3,
|
|
5
|
+
M: 1e6,
|
|
6
|
+
B: 1e9,
|
|
7
|
+
T: 1e12,
|
|
8
|
+
};
|
|
9
|
+
const removeCommas = (str) => str.replace(/,/gu, '');
|
|
10
|
+
/**
|
|
11
|
+
* Parse a formatted volume string (e.g., "$1.5M", "$2.3B") to a numeric value.
|
|
12
|
+
* Extracted from hooks/usePerpsMarkets.ts for portability.
|
|
13
|
+
*
|
|
14
|
+
* @param volumeStr - The formatted volume string to parse.
|
|
15
|
+
* @returns The numeric volume value, or -1 if unparseable.
|
|
16
|
+
*/
|
|
17
|
+
export const parseVolume = (volumeStr) => {
|
|
18
|
+
if (!volumeStr) {
|
|
19
|
+
return -1;
|
|
20
|
+
}
|
|
21
|
+
if (volumeStr === PERPS_CONSTANTS.FallbackPriceDisplay) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
if (volumeStr === '$<1') {
|
|
25
|
+
return 0.5;
|
|
26
|
+
}
|
|
27
|
+
const suffixMatch = VOLUME_SUFFIX_REGEX.exec(volumeStr);
|
|
28
|
+
if (suffixMatch) {
|
|
29
|
+
const [, numberPart, suffix] = suffixMatch;
|
|
30
|
+
const baseValue = Number.parseFloat(removeCommas(numberPart));
|
|
31
|
+
if (Number.isNaN(baseValue)) {
|
|
32
|
+
return -1;
|
|
33
|
+
}
|
|
34
|
+
return suffix ? baseValue * multipliers[suffix] : baseValue;
|
|
35
|
+
}
|
|
36
|
+
// Fallback: try to parse as plain number
|
|
37
|
+
const cleaned = volumeStr.replace(/[$,]/gu, '');
|
|
38
|
+
const parsed = Number.parseFloat(cleaned);
|
|
39
|
+
return Number.isNaN(parsed) ? -1 : parsed;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Sorts markets based on the specified criteria.
|
|
43
|
+
*
|
|
44
|
+
* @param options0 - The sorting configuration.
|
|
45
|
+
* @param options0.markets - The array of market data to sort.
|
|
46
|
+
* @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).
|
|
47
|
+
* @param options0.direction - The sort direction (asc or desc).
|
|
48
|
+
* @returns A new sorted array of market data.
|
|
49
|
+
*/
|
|
50
|
+
export const sortMarkets = ({ markets, sortBy, direction = MARKET_SORTING_CONFIG.DefaultDirection, }) => {
|
|
51
|
+
const sortedMarkets = [...markets];
|
|
52
|
+
sortedMarkets.sort((a, b) => {
|
|
53
|
+
let compareValue = 0;
|
|
54
|
+
switch (sortBy) {
|
|
55
|
+
case MARKET_SORTING_CONFIG.SortFields.Volume: {
|
|
56
|
+
const volumeA = parseVolume(a.volume);
|
|
57
|
+
const volumeB = parseVolume(b.volume);
|
|
58
|
+
compareValue = volumeA - volumeB;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case MARKET_SORTING_CONFIG.SortFields.PriceChange: {
|
|
62
|
+
const changeA = parseFloat(a.change24hPercent?.replace(/[%+]/gu, '') || '0');
|
|
63
|
+
const changeB = parseFloat(b.change24hPercent?.replace(/[%+]/gu, '') || '0');
|
|
64
|
+
compareValue = changeA - changeB;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case MARKET_SORTING_CONFIG.SortFields.FundingRate: {
|
|
68
|
+
const fundingA = a.fundingRate ?? 0;
|
|
69
|
+
const fundingB = b.fundingRate ?? 0;
|
|
70
|
+
compareValue = fundingA - fundingB;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case MARKET_SORTING_CONFIG.SortFields.OpenInterest: {
|
|
74
|
+
const openInterestA = parseVolume(a.openInterest);
|
|
75
|
+
const openInterestB = parseVolume(b.openInterest);
|
|
76
|
+
compareValue = openInterestA - openInterestB;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
return direction === MARKET_SORTING_CONFIG.DefaultDirection
|
|
83
|
+
? compareValue * -1
|
|
84
|
+
: compareValue;
|
|
85
|
+
});
|
|
86
|
+
return sortedMarkets;
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=sortMarkets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortMarkets.mjs","sourceRoot":"","sources":["../../src/utils/sortMarkets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,eAAe,EAChB,qCAAiC;AAgBlC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAErD,MAAM,WAAW,GAA2B;IAC1C,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,IAAI;CACC,CAAC;AAEX,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAErE;;;;;;GAMG;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CAAC,CAAC,YAAY,CAAC,CAAC;gBAClD,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;gBAC7C,MAAM;YACR,CAAC;YAED;gBACE,MAAM;QACV,CAAC;QAED,OAAO,SAAS,KAAK,qBAAqB,CAAC,gBAAgB;YACzD,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC;YACnB,CAAC,CAAC,YAAY,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import {\n MARKET_SORTING_CONFIG,\n PERPS_CONSTANTS,\n} from '../constants/perpsConfig';\nimport type { PerpsMarketData } from '../types';\n\nexport type SortField =\n | 'volume'\n | 'priceChange'\n | 'fundingRate'\n | 'openInterest';\nexport type SortDirection = 'asc' | 'desc';\n\nexport type SortMarketsParams = {\n markets: PerpsMarketData[];\n sortBy: SortField;\n direction?: SortDirection;\n};\n\nconst VOLUME_SUFFIX_REGEX = /\\$?([\\d.,]+)([KMBT])?/u;\n\nconst multipliers: Record<string, number> = {\n K: 1e3,\n M: 1e6,\n B: 1e9,\n T: 1e12,\n} as const;\n\nconst removeCommas = (str: string): string => str.replace(/,/gu, '');\n\n/**\n * Parse a formatted volume string (e.g., \"$1.5M\", \"$2.3B\") to a numeric value.\n * Extracted from hooks/usePerpsMarkets.ts for portability.\n *\n * @param volumeStr - The formatted volume string to parse.\n * @returns The numeric volume value, or -1 if unparseable.\n */\nexport const parseVolume = (volumeStr: string | undefined): number => {\n if (!volumeStr) {\n return -1;\n }\n\n if (volumeStr === PERPS_CONSTANTS.FallbackPriceDisplay) {\n return -1;\n }\n if (volumeStr === '$<1') {\n return 0.5;\n }\n\n const suffixMatch = VOLUME_SUFFIX_REGEX.exec(volumeStr);\n if (suffixMatch) {\n const [, numberPart, suffix] = suffixMatch;\n const baseValue = Number.parseFloat(removeCommas(numberPart));\n\n if (Number.isNaN(baseValue)) {\n return -1;\n }\n\n return suffix ? baseValue * multipliers[suffix] : baseValue;\n }\n\n // Fallback: try to parse as plain number\n const cleaned = volumeStr.replace(/[$,]/gu, '');\n const parsed = Number.parseFloat(cleaned);\n return Number.isNaN(parsed) ? -1 : parsed;\n};\n\n/**\n * Sorts markets based on the specified criteria.\n *\n * @param options0 - The sorting configuration.\n * @param options0.markets - The array of market data to sort.\n * @param options0.sortBy - The field to sort by (volume, priceChange, fundingRate, or openInterest).\n * @param options0.direction - The sort direction (asc or desc).\n * @returns A new sorted array of market data.\n */\nexport const sortMarkets = ({\n markets,\n sortBy,\n direction = MARKET_SORTING_CONFIG.DefaultDirection,\n}: SortMarketsParams): PerpsMarketData[] => {\n const sortedMarkets = [...markets];\n\n sortedMarkets.sort((a, b) => {\n let compareValue = 0;\n\n switch (sortBy) {\n case MARKET_SORTING_CONFIG.SortFields.Volume: {\n const volumeA = parseVolume(a.volume);\n const volumeB = parseVolume(b.volume);\n compareValue = volumeA - volumeB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.PriceChange: {\n const changeA = parseFloat(\n a.change24hPercent?.replace(/[%+]/gu, '') || '0',\n );\n const changeB = parseFloat(\n b.change24hPercent?.replace(/[%+]/gu, '') || '0',\n );\n compareValue = changeA - changeB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.FundingRate: {\n const fundingA = a.fundingRate ?? 0;\n const fundingB = b.fundingRate ?? 0;\n compareValue = fundingA - fundingB;\n break;\n }\n\n case MARKET_SORTING_CONFIG.SortFields.OpenInterest: {\n const openInterestA = parseVolume(a.openInterest);\n const openInterestB = parseVolume(b.openInterest);\n compareValue = openInterestA - openInterestB;\n break;\n }\n\n default:\n break;\n }\n\n return direction === MARKET_SORTING_CONFIG.DefaultDirection\n ? compareValue * -1\n : compareValue;\n });\n\n return sortedMarkets;\n};\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryStandaloneOpenOrders = exports.queryStandaloneClearinghouseStates = exports.createStandaloneInfoClient = void 0;
|
|
4
|
+
const hyperliquid_1 = require("@nktkas/hyperliquid");
|
|
5
|
+
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a standalone InfoClient for lightweight read-only queries.
|
|
8
|
+
* Does not require full perps initialization (no wallet, WebSocket, etc.)
|
|
9
|
+
*
|
|
10
|
+
* @param options - The configuration options for the standalone client.
|
|
11
|
+
* @returns A new InfoClient instance configured for read-only queries.
|
|
12
|
+
*/
|
|
13
|
+
const createStandaloneInfoClient = (options) => {
|
|
14
|
+
const { isTestnet, timeout = perpsConfig_1.PERPS_CONSTANTS.ConnectionTimeoutMs } = options;
|
|
15
|
+
const httpTransport = new hyperliquid_1.HttpTransport({
|
|
16
|
+
isTestnet,
|
|
17
|
+
timeout,
|
|
18
|
+
});
|
|
19
|
+
return new hyperliquid_1.InfoClient({ transport: httpTransport });
|
|
20
|
+
};
|
|
21
|
+
exports.createStandaloneInfoClient = createStandaloneInfoClient;
|
|
22
|
+
/**
|
|
23
|
+
* Query clearinghouseState across multiple DEXs in parallel.
|
|
24
|
+
* Used by standalone mode to aggregate positions/account state across HIP-3 DEXs.
|
|
25
|
+
*
|
|
26
|
+
* @param infoClient - The HyperLiquid InfoClient instance to use for queries.
|
|
27
|
+
* @param userAddress - The user's wallet address to query state for.
|
|
28
|
+
* @param dexs - The array of DEX identifiers to query (null for main DEX).
|
|
29
|
+
* @returns A promise that resolves to an array of clearinghouse state responses.
|
|
30
|
+
*/
|
|
31
|
+
const queryStandaloneClearinghouseStates = async (infoClient, userAddress, dexs) => {
|
|
32
|
+
const results = await Promise.allSettled(dexs.map(async (dex) => {
|
|
33
|
+
const queryParams = {
|
|
34
|
+
user: userAddress,
|
|
35
|
+
};
|
|
36
|
+
if (dex) {
|
|
37
|
+
queryParams.dex = dex;
|
|
38
|
+
}
|
|
39
|
+
return infoClient.clearinghouseState(queryParams);
|
|
40
|
+
}));
|
|
41
|
+
return results
|
|
42
|
+
.filter((result) => result.status === 'fulfilled')
|
|
43
|
+
.map((result) => result.value);
|
|
44
|
+
};
|
|
45
|
+
exports.queryStandaloneClearinghouseStates = queryStandaloneClearinghouseStates;
|
|
46
|
+
/**
|
|
47
|
+
* Query frontendOpenOrders across multiple DEXs in parallel.
|
|
48
|
+
* Used by standalone mode to fetch open orders across HIP-3 DEXs.
|
|
49
|
+
*
|
|
50
|
+
* @param infoClient - The HyperLiquid InfoClient instance to use for queries.
|
|
51
|
+
* @param userAddress - The user's wallet address to query orders for.
|
|
52
|
+
* @param dexs - The array of DEX identifiers to query (null for main DEX).
|
|
53
|
+
* @returns A promise that resolves to an array of frontend open orders responses.
|
|
54
|
+
*/
|
|
55
|
+
const queryStandaloneOpenOrders = async (infoClient, userAddress, dexs) => {
|
|
56
|
+
const results = await Promise.allSettled(dexs.map(async (dex) => {
|
|
57
|
+
const queryParams = {
|
|
58
|
+
user: userAddress,
|
|
59
|
+
};
|
|
60
|
+
if (dex) {
|
|
61
|
+
queryParams.dex = dex;
|
|
62
|
+
}
|
|
63
|
+
return infoClient.frontendOpenOrders(queryParams);
|
|
64
|
+
}));
|
|
65
|
+
return results
|
|
66
|
+
.filter((result) => result.status === 'fulfilled')
|
|
67
|
+
.map((result) => result.value);
|
|
68
|
+
};
|
|
69
|
+
exports.queryStandaloneOpenOrders = queryStandaloneOpenOrders;
|
|
70
|
+
//# sourceMappingURL=standaloneInfoClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standaloneInfoClient.cjs","sourceRoot":"","sources":["../../src/utils/standaloneInfoClient.ts"],"names":[],"mappings":";;;AAAA,qDAAgE;AAEhE,8DAA2D;AAa3D;;;;;;GAMG;AACI,MAAM,0BAA0B,GAAG,CACxC,OAAoC,EACxB,EAAE;IACd,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,6BAAe,CAAC,mBAAmB,EAAE,GAAG,OAAO,CAAC;IAE7E,MAAM,aAAa,GA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AkB,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO;SACX,MAAM,CACL,CAAC,MAAM,EAAgE,EAAE,CACvE,MAAM,CAAC,MAAM,KAAK,WAAW,CAChC;SACA,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC,CAAC;AAvBW,QAAA,yBAAyB,6BAuBpC","sourcesContent":["import { HttpTransport, InfoClient } from '@nktkas/hyperliquid';\n\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type {\n ClearinghouseStateResponse,\n FrontendOpenOrdersResponse,\n} from '../types/hyperliquid-types';\n\nexport type StandaloneInfoClientOptions = {\n /** Whether to use testnet API endpoint */\n isTestnet: boolean;\n /** Request timeout in ms (default: CONNECTION_TIMEOUT_MS) */\n timeout?: number;\n};\n\n/**\n * Creates a standalone InfoClient for lightweight read-only queries.\n * Does not require full perps initialization (no wallet, WebSocket, etc.)\n *\n * @param options - The configuration options for the standalone client.\n * @returns A new InfoClient instance configured for read-only queries.\n */\nexport const createStandaloneInfoClient = (\n options: StandaloneInfoClientOptions,\n): InfoClient => {\n const { isTestnet, timeout = PERPS_CONSTANTS.ConnectionTimeoutMs } = options;\n\n const httpTransport = new HttpTransport({\n isTestnet,\n timeout,\n });\n\n return new InfoClient({ transport: httpTransport });\n};\n\n/**\n * Query clearinghouseState across multiple DEXs in parallel.\n * Used by standalone mode to aggregate positions/account state across HIP-3 DEXs.\n *\n * @param infoClient - The HyperLiquid InfoClient instance to use for queries.\n * @param userAddress - The user's wallet address to query state for.\n * @param dexs - The array of DEX identifiers to query (null for main DEX).\n * @returns A promise that resolves to an array of clearinghouse state responses.\n */\nexport const queryStandaloneClearinghouseStates = async (\n infoClient: InfoClient,\n userAddress: string,\n dexs: (string | null)[],\n): Promise<ClearinghouseStateResponse[]> => {\n const results = await Promise.allSettled(\n dexs.map(async (dex) => {\n const queryParams: { user: string; dex?: string } = {\n user: userAddress,\n };\n if (dex) {\n queryParams.dex = dex;\n }\n return infoClient.clearinghouseState(queryParams);\n }),\n );\n\n return results\n .filter(\n (result): result is PromiseFulfilledResult<ClearinghouseStateResponse> =>\n result.status === 'fulfilled',\n )\n .map((result) => result.value);\n};\n\n/**\n * Query frontendOpenOrders across multiple DEXs in parallel.\n * Used by standalone mode to fetch open orders across HIP-3 DEXs.\n *\n * @param infoClient - The HyperLiquid InfoClient instance to use for queries.\n * @param userAddress - The user's wallet address to query orders for.\n * @param dexs - The array of DEX identifiers to query (null for main DEX).\n * @returns A promise that resolves to an array of frontend open orders responses.\n */\nexport const queryStandaloneOpenOrders = async (\n infoClient: InfoClient,\n userAddress: string,\n dexs: (string | null)[],\n): Promise<FrontendOpenOrdersResponse[]> => {\n const results = await Promise.allSettled(\n dexs.map(async (dex) => {\n const queryParams: { user: string; dex?: string } = {\n user: userAddress,\n };\n if (dex) {\n queryParams.dex = dex;\n }\n return infoClient.frontendOpenOrders(queryParams);\n }),\n );\n\n return results\n .filter(\n (result): result is PromiseFulfilledResult<FrontendOpenOrdersResponse> =>\n result.status === 'fulfilled',\n )\n .map((result) => result.value);\n};\n"]}
|