@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -11
- package/dist/PerpsController.cjs +66 -2224
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +79 -933
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +79 -933
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +64 -2221
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/index.cjs +1 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -19
- package/dist/__mocks__/hyperliquidMock.cjs +0 -68
- package/dist/__mocks__/hyperliquidMock.cjs.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.cts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.cts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.mts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.mts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.mjs +0 -65
- package/dist/__mocks__/hyperliquidMock.mjs.map +0 -1
- package/dist/__mocks__/providerMocks.cjs +0 -144
- package/dist/__mocks__/providerMocks.cjs.map +0 -1
- package/dist/__mocks__/providerMocks.d.cts +0 -44
- package/dist/__mocks__/providerMocks.d.cts.map +0 -1
- package/dist/__mocks__/providerMocks.d.mts +0 -44
- package/dist/__mocks__/providerMocks.d.mts.map +0 -1
- package/dist/__mocks__/providerMocks.mjs +0 -136
- package/dist/__mocks__/providerMocks.mjs.map +0 -1
- package/dist/__mocks__/serviceMocks.cjs +0 -187
- package/dist/__mocks__/serviceMocks.cjs.map +0 -1
- package/dist/__mocks__/serviceMocks.d.cts +0 -58
- package/dist/__mocks__/serviceMocks.d.cts.map +0 -1
- package/dist/__mocks__/serviceMocks.d.mts +0 -58
- package/dist/__mocks__/serviceMocks.d.mts.map +0 -1
- package/dist/__mocks__/serviceMocks.mjs +0 -180
- package/dist/__mocks__/serviceMocks.mjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -459
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -455
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
- package/dist/aggregation/index.cjs +0 -9
- package/dist/aggregation/index.cjs.map +0 -1
- package/dist/aggregation/index.d.cts +0 -6
- package/dist/aggregation/index.d.cts.map +0 -1
- package/dist/aggregation/index.d.mts +0 -6
- package/dist/aggregation/index.d.mts.map +0 -1
- package/dist/aggregation/index.mjs +0 -5
- package/dist/aggregation/index.mjs.map +0 -1
- package/dist/constants/eventNames.cjs +0 -117
- package/dist/constants/eventNames.cjs.map +0 -1
- package/dist/constants/eventNames.d.cts +0 -106
- package/dist/constants/eventNames.d.cts.map +0 -1
- package/dist/constants/eventNames.d.mts +0 -106
- package/dist/constants/eventNames.d.mts.map +0 -1
- package/dist/constants/eventNames.mjs +0 -114
- package/dist/constants/eventNames.mjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.cjs +0 -366
- package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.cts +0 -276
- package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.mts +0 -276
- package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
- package/dist/constants/hyperLiquidConfig.mjs +0 -357
- package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
- package/dist/constants/index.cjs +0 -23
- package/dist/constants/index.cjs.map +0 -1
- package/dist/constants/index.d.cts +0 -7
- package/dist/constants/index.d.cts.map +0 -1
- package/dist/constants/index.d.mts +0 -7
- package/dist/constants/index.d.mts.map +0 -1
- package/dist/constants/index.mjs +0 -7
- package/dist/constants/index.mjs.map +0 -1
- package/dist/constants/orderTypes.cjs +0 -31
- package/dist/constants/orderTypes.cjs.map +0 -1
- package/dist/constants/orderTypes.d.cts +0 -19
- package/dist/constants/orderTypes.d.cts.map +0 -1
- package/dist/constants/orderTypes.d.mts +0 -19
- package/dist/constants/orderTypes.d.mts.map +0 -1
- package/dist/constants/orderTypes.mjs +0 -27
- package/dist/constants/orderTypes.mjs.map +0 -1
- package/dist/constants/performanceMetrics.cjs +0 -61
- package/dist/constants/performanceMetrics.cjs.map +0 -1
- package/dist/constants/performanceMetrics.d.cts +0 -44
- package/dist/constants/performanceMetrics.d.cts.map +0 -1
- package/dist/constants/performanceMetrics.d.mts +0 -44
- package/dist/constants/performanceMetrics.d.mts.map +0 -1
- package/dist/constants/performanceMetrics.mjs +0 -58
- package/dist/constants/performanceMetrics.mjs.map +0 -1
- package/dist/constants/perpsConfig.cjs +0 -461
- package/dist/constants/perpsConfig.cjs.map +0 -1
- package/dist/constants/perpsConfig.d.cts +0 -343
- package/dist/constants/perpsConfig.d.cts.map +0 -1
- package/dist/constants/perpsConfig.d.mts +0 -343
- package/dist/constants/perpsConfig.d.mts.map +0 -1
- package/dist/constants/perpsConfig.mjs +0 -458
- package/dist/constants/perpsConfig.mjs.map +0 -1
- package/dist/constants/perpsErrorCodes.cjs +0 -79
- package/dist/constants/perpsErrorCodes.cjs.map +0 -1
- package/dist/constants/perpsErrorCodes.d.cts +0 -64
- package/dist/constants/perpsErrorCodes.d.cts.map +0 -1
- package/dist/constants/perpsErrorCodes.d.mts +0 -64
- package/dist/constants/perpsErrorCodes.d.mts.map +0 -1
- package/dist/constants/perpsErrorCodes.mjs +0 -76
- package/dist/constants/perpsErrorCodes.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.cjs +0 -857
- package/dist/platform-services/HyperLiquidClientService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.cts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.mts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.mjs +0 -853
- package/dist/platform-services/HyperLiquidClientService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs +0 -2170
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs +0 -2166
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.cjs +0 -140
- package/dist/platform-services/HyperLiquidWalletService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.cts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.mts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.mjs +0 -136
- package/dist/platform-services/HyperLiquidWalletService.mjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +0 -777
- package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +0 -773
- package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.cjs +0 -5172
- package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -881
- package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.mts +0 -881
- package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
- package/dist/providers/HyperLiquidProvider.mjs +0 -5168
- package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
- package/dist/providers/index.cjs +0 -11
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.d.cts +0 -6
- package/dist/providers/index.d.cts.map +0 -1
- package/dist/providers/index.d.mts +0 -6
- package/dist/providers/index.d.mts.map +0 -1
- package/dist/providers/index.mjs +0 -6
- package/dist/providers/index.mjs.map +0 -1
- package/dist/routing/ProviderRouter.cjs +0 -148
- package/dist/routing/ProviderRouter.cjs.map +0 -1
- package/dist/routing/ProviderRouter.d.cts +0 -124
- package/dist/routing/ProviderRouter.d.cts.map +0 -1
- package/dist/routing/ProviderRouter.d.mts +0 -124
- package/dist/routing/ProviderRouter.d.mts.map +0 -1
- package/dist/routing/ProviderRouter.mjs +0 -144
- package/dist/routing/ProviderRouter.mjs.map +0 -1
- package/dist/routing/index.cjs +0 -9
- package/dist/routing/index.cjs.map +0 -1
- package/dist/routing/index.d.cts +0 -6
- package/dist/routing/index.d.cts.map +0 -1
- package/dist/routing/index.d.mts +0 -6
- package/dist/routing/index.d.mts.map +0 -1
- package/dist/routing/index.mjs +0 -5
- package/dist/routing/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -161
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -345
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -345
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -153
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/AccountService.cjs +0 -313
- package/dist/services/AccountService.cjs.map +0 -1
- package/dist/services/AccountService.d.cts +0 -53
- package/dist/services/AccountService.d.cts.map +0 -1
- package/dist/services/AccountService.d.mts +0 -53
- package/dist/services/AccountService.d.mts.map +0 -1
- package/dist/services/AccountService.mjs +0 -309
- package/dist/services/AccountService.mjs.map +0 -1
- package/dist/services/DataLakeService.cjs +0 -219
- package/dist/services/DataLakeService.cjs.map +0 -1
- package/dist/services/DataLakeService.d.cts +0 -49
- package/dist/services/DataLakeService.d.cts.map +0 -1
- package/dist/services/DataLakeService.d.mts +0 -49
- package/dist/services/DataLakeService.d.mts.map +0 -1
- package/dist/services/DataLakeService.mjs +0 -215
- package/dist/services/DataLakeService.mjs.map +0 -1
- package/dist/services/DepositService.cjs +0 -96
- package/dist/services/DepositService.cjs.map +0 -1
- package/dist/services/DepositService.d.cts +0 -37
- package/dist/services/DepositService.d.cts.map +0 -1
- package/dist/services/DepositService.d.mts +0 -37
- package/dist/services/DepositService.d.mts.map +0 -1
- package/dist/services/DepositService.mjs +0 -92
- package/dist/services/DepositService.mjs.map +0 -1
- package/dist/services/EligibilityService.cjs +0 -156
- package/dist/services/EligibilityService.cjs.map +0 -1
- package/dist/services/EligibilityService.d.cts +0 -48
- package/dist/services/EligibilityService.d.cts.map +0 -1
- package/dist/services/EligibilityService.d.mts +0 -48
- package/dist/services/EligibilityService.d.mts.map +0 -1
- package/dist/services/EligibilityService.mjs +0 -152
- package/dist/services/EligibilityService.mjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.cjs +0 -258
- package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.cts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.mts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.mjs +0 -254
- package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
- package/dist/services/MarketDataService.cjs +0 -875
- package/dist/services/MarketDataService.cjs.map +0 -1
- package/dist/services/MarketDataService.d.cts +0 -289
- package/dist/services/MarketDataService.d.cts.map +0 -1
- package/dist/services/MarketDataService.d.mts +0 -289
- package/dist/services/MarketDataService.d.mts.map +0 -1
- package/dist/services/MarketDataService.mjs +0 -871
- package/dist/services/MarketDataService.mjs.map +0 -1
- package/dist/services/RewardsIntegrationService.cjs +0 -94
- package/dist/services/RewardsIntegrationService.cjs.map +0 -1
- package/dist/services/RewardsIntegrationService.d.cts +0 -30
- package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
- package/dist/services/RewardsIntegrationService.d.mts +0 -30
- package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
- package/dist/services/RewardsIntegrationService.mjs +0 -90
- package/dist/services/RewardsIntegrationService.mjs.map +0 -1
- package/dist/services/ServiceContext.cjs +0 -3
- package/dist/services/ServiceContext.cjs.map +0 -1
- package/dist/services/ServiceContext.d.cts +0 -110
- package/dist/services/ServiceContext.d.cts.map +0 -1
- package/dist/services/ServiceContext.d.mts +0 -110
- package/dist/services/ServiceContext.d.mts.map +0 -1
- package/dist/services/ServiceContext.mjs +0 -2
- package/dist/services/ServiceContext.mjs.map +0 -1
- package/dist/services/TradingService.cjs +0 -1481
- package/dist/services/TradingService.cjs.map +0 -1
- package/dist/services/TradingService.d.cts +0 -308
- package/dist/services/TradingService.d.cts.map +0 -1
- package/dist/services/TradingService.d.mts +0 -308
- package/dist/services/TradingService.d.mts.map +0 -1
- package/dist/services/TradingService.mjs +0 -1477
- package/dist/services/TradingService.mjs.map +0 -1
- package/dist/services/index.cjs +0 -26
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts +0 -11
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -11
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs +0 -10
- package/dist/services/index.mjs.map +0 -1
- package/dist/services/utils.cjs +0 -16
- package/dist/services/utils.cjs.map +0 -1
- package/dist/services/utils.d.cts +0 -8
- package/dist/services/utils.d.cts.map +0 -1
- package/dist/services/utils.d.mts +0 -8
- package/dist/services/utils.d.mts.map +0 -1
- package/dist/services/utils.mjs +0 -12
- package/dist/services/utils.mjs.map +0 -1
- package/dist/types/chart.cjs +0 -42
- package/dist/types/chart.cjs.map +0 -1
- package/dist/types/chart.d.cts +0 -62
- package/dist/types/chart.d.cts.map +0 -1
- package/dist/types/chart.d.mts +0 -62
- package/dist/types/chart.d.mts.map +0 -1
- package/dist/types/chart.mjs +0 -39
- package/dist/types/chart.mjs.map +0 -1
- package/dist/types/hyperliquid-types.cjs +0 -3
- package/dist/types/hyperliquid-types.cjs.map +0 -1
- package/dist/types/hyperliquid-types.d.cts +0 -52
- package/dist/types/hyperliquid-types.d.cts.map +0 -1
- package/dist/types/hyperliquid-types.d.mts +0 -52
- package/dist/types/hyperliquid-types.d.mts.map +0 -1
- package/dist/types/hyperliquid-types.mjs +0 -2
- package/dist/types/hyperliquid-types.mjs.map +0 -1
- package/dist/types/index.cjs +0 -96
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -1153
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -1153
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -79
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/transactionTypes.cjs +0 -28
- package/dist/types/transactionTypes.cjs.map +0 -1
- package/dist/types/transactionTypes.d.cts +0 -64
- package/dist/types/transactionTypes.d.cts.map +0 -1
- package/dist/types/transactionTypes.d.mts +0 -64
- package/dist/types/transactionTypes.d.mts.map +0 -1
- package/dist/types/transactionTypes.mjs +0 -23
- package/dist/types/transactionTypes.mjs.map +0 -1
- package/dist/utils/accountUtils.cjs +0 -65
- package/dist/utils/accountUtils.cjs.map +0 -1
- package/dist/utils/accountUtils.d.cts +0 -26
- package/dist/utils/accountUtils.d.cts.map +0 -1
- package/dist/utils/accountUtils.d.mts +0 -26
- package/dist/utils/accountUtils.d.mts.map +0 -1
- package/dist/utils/accountUtils.mjs +0 -61
- package/dist/utils/accountUtils.mjs.map +0 -1
- package/dist/utils/amountConversion.cjs +0 -61
- package/dist/utils/amountConversion.cjs.map +0 -1
- package/dist/utils/amountConversion.d.cts +0 -16
- package/dist/utils/amountConversion.d.cts.map +0 -1
- package/dist/utils/amountConversion.d.mts +0 -16
- package/dist/utils/amountConversion.d.mts.map +0 -1
- package/dist/utils/amountConversion.mjs +0 -54
- package/dist/utils/amountConversion.mjs.map +0 -1
- package/dist/utils/chartUtils.cjs +0 -98
- package/dist/utils/chartUtils.cjs.map +0 -1
- package/dist/utils/chartUtils.d.cts +0 -14
- package/dist/utils/chartUtils.d.cts.map +0 -1
- package/dist/utils/chartUtils.d.mts +0 -14
- package/dist/utils/chartUtils.d.mts.map +0 -1
- package/dist/utils/chartUtils.mjs +0 -94
- package/dist/utils/chartUtils.mjs.map +0 -1
- package/dist/utils/errorUtils.cjs +0 -22
- package/dist/utils/errorUtils.cjs.map +0 -1
- package/dist/utils/errorUtils.d.cts +0 -13
- package/dist/utils/errorUtils.d.cts.map +0 -1
- package/dist/utils/errorUtils.d.mts +0 -13
- package/dist/utils/errorUtils.d.mts.map +0 -1
- package/dist/utils/errorUtils.mjs +0 -18
- package/dist/utils/errorUtils.mjs.map +0 -1
- package/dist/utils/formatUtils.cjs +0 -987
- package/dist/utils/formatUtils.cjs.map +0 -1
- package/dist/utils/formatUtils.d.cts +0 -387
- package/dist/utils/formatUtils.d.cts.map +0 -1
- package/dist/utils/formatUtils.d.mts +0 -387
- package/dist/utils/formatUtils.d.mts.map +0 -1
- package/dist/utils/formatUtils.mjs +0 -966
- package/dist/utils/formatUtils.mjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.cjs +0 -454
- package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.mjs +0 -439
- package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -89
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -84
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.cjs +0 -426
- package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.cts +0 -143
- package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.mts +0 -143
- package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
- package/dist/utils/hyperLiquidValidation.mjs +0 -413
- package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
- package/dist/utils/idUtils.cjs +0 -50
- package/dist/utils/idUtils.cjs.map +0 -1
- package/dist/utils/idUtils.d.cts +0 -38
- package/dist/utils/idUtils.d.cts.map +0 -1
- package/dist/utils/idUtils.d.mts +0 -38
- package/dist/utils/idUtils.d.mts.map +0 -1
- package/dist/utils/idUtils.mjs +0 -42
- package/dist/utils/idUtils.mjs.map +0 -1
- package/dist/utils/marginUtils.cjs +0 -137
- package/dist/utils/marginUtils.cjs.map +0 -1
- package/dist/utils/marginUtils.d.cts +0 -64
- package/dist/utils/marginUtils.d.cts.map +0 -1
- package/dist/utils/marginUtils.d.mts +0 -64
- package/dist/utils/marginUtils.d.mts.map +0 -1
- package/dist/utils/marginUtils.mjs +0 -131
- package/dist/utils/marginUtils.mjs.map +0 -1
- package/dist/utils/marketDataTransform.cjs +0 -227
- package/dist/utils/marketDataTransform.cjs.map +0 -1
- package/dist/utils/marketDataTransform.d.cts +0 -45
- package/dist/utils/marketDataTransform.d.cts.map +0 -1
- package/dist/utils/marketDataTransform.d.mts +0 -45
- package/dist/utils/marketDataTransform.d.mts.map +0 -1
- package/dist/utils/marketDataTransform.mjs +0 -220
- package/dist/utils/marketDataTransform.mjs.map +0 -1
- package/dist/utils/marketUtils.cjs +0 -420
- package/dist/utils/marketUtils.cjs.map +0 -1
- package/dist/utils/marketUtils.d.cts +0 -227
- package/dist/utils/marketUtils.d.cts.map +0 -1
- package/dist/utils/marketUtils.d.mts +0 -227
- package/dist/utils/marketUtils.d.mts.map +0 -1
- package/dist/utils/marketUtils.mjs +0 -404
- package/dist/utils/marketUtils.mjs.map +0 -1
- package/dist/utils/orderBookGrouping.cjs +0 -151
- package/dist/utils/orderBookGrouping.cjs.map +0 -1
- package/dist/utils/orderBookGrouping.d.cts +0 -76
- package/dist/utils/orderBookGrouping.d.cts.map +0 -1
- package/dist/utils/orderBookGrouping.d.mts +0 -76
- package/dist/utils/orderBookGrouping.d.mts.map +0 -1
- package/dist/utils/orderBookGrouping.mjs +0 -143
- package/dist/utils/orderBookGrouping.mjs.map +0 -1
- package/dist/utils/orderCalculations.cjs +0 -283
- package/dist/utils/orderCalculations.cjs.map +0 -1
- package/dist/utils/orderCalculations.d.cts +0 -107
- package/dist/utils/orderCalculations.d.cts.map +0 -1
- package/dist/utils/orderCalculations.d.mts +0 -107
- package/dist/utils/orderCalculations.d.mts.map +0 -1
- package/dist/utils/orderCalculations.mjs +0 -274
- package/dist/utils/orderCalculations.mjs.map +0 -1
- package/dist/utils/orderUtils.cjs +0 -159
- package/dist/utils/orderUtils.cjs.map +0 -1
- package/dist/utils/orderUtils.d.cts +0 -66
- package/dist/utils/orderUtils.d.cts.map +0 -1
- package/dist/utils/orderUtils.d.mts +0 -66
- package/dist/utils/orderUtils.d.mts.map +0 -1
- package/dist/utils/orderUtils.mjs +0 -151
- package/dist/utils/orderUtils.mjs.map +0 -1
- package/dist/utils/pnlCalculations.cjs +0 -107
- package/dist/utils/pnlCalculations.cjs.map +0 -1
- package/dist/utils/pnlCalculations.d.cts +0 -79
- package/dist/utils/pnlCalculations.d.cts.map +0 -1
- package/dist/utils/pnlCalculations.d.mts +0 -79
- package/dist/utils/pnlCalculations.d.mts.map +0 -1
- package/dist/utils/pnlCalculations.mjs +0 -97
- package/dist/utils/pnlCalculations.mjs.map +0 -1
- package/dist/utils/positionCalculations.cjs +0 -176
- package/dist/utils/positionCalculations.cjs.map +0 -1
- package/dist/utils/positionCalculations.d.cts +0 -85
- package/dist/utils/positionCalculations.d.cts.map +0 -1
- package/dist/utils/positionCalculations.d.mts +0 -85
- package/dist/utils/positionCalculations.d.mts.map +0 -1
- package/dist/utils/positionCalculations.mjs +0 -165
- package/dist/utils/positionCalculations.mjs.map +0 -1
- package/dist/utils/sortMarkets.cjs +0 -88
- package/dist/utils/sortMarkets.cjs.map +0 -1
- package/dist/utils/sortMarkets.d.cts +0 -21
- package/dist/utils/sortMarkets.d.cts.map +0 -1
- package/dist/utils/sortMarkets.d.mts +0 -21
- package/dist/utils/sortMarkets.d.mts.map +0 -1
- package/dist/utils/sortMarkets.mjs +0 -84
- package/dist/utils/sortMarkets.mjs.map +0 -1
- package/dist/utils/standaloneInfoClient.cjs +0 -34
- package/dist/utils/standaloneInfoClient.cjs.map +0 -1
- package/dist/utils/standaloneInfoClient.d.cts +0 -31
- package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
- package/dist/utils/standaloneInfoClient.d.mts +0 -31
- package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
- package/dist/utils/standaloneInfoClient.mjs +0 -30
- package/dist/utils/standaloneInfoClient.mjs.map +0 -1
- package/dist/utils/stringParseUtils.cjs +0 -49
- package/dist/utils/stringParseUtils.cjs.map +0 -1
- package/dist/utils/stringParseUtils.d.cts +0 -35
- package/dist/utils/stringParseUtils.d.cts.map +0 -1
- package/dist/utils/stringParseUtils.d.mts +0 -35
- package/dist/utils/stringParseUtils.d.mts.map +0 -1
- package/dist/utils/stringParseUtils.mjs +0 -44
- package/dist/utils/stringParseUtils.mjs.map +0 -1
- package/dist/utils/time.cjs +0 -37
- package/dist/utils/time.cjs.map +0 -1
- package/dist/utils/time.d.cts +0 -17
- package/dist/utils/time.d.cts.map +0 -1
- package/dist/utils/time.d.mts +0 -17
- package/dist/utils/time.d.mts.map +0 -1
- package/dist/utils/time.mjs +0 -33
- package/dist/utils/time.mjs.map +0 -1
- package/dist/utils/tpslValidation.cjs +0 -505
- package/dist/utils/tpslValidation.cjs.map +0 -1
- package/dist/utils/tpslValidation.d.cts +0 -182
- package/dist/utils/tpslValidation.d.cts.map +0 -1
- package/dist/utils/tpslValidation.d.mts +0 -182
- package/dist/utils/tpslValidation.d.mts.map +0 -1
- package/dist/utils/tpslValidation.mjs +0 -482
- package/dist/utils/tpslValidation.mjs.map +0 -1
- package/dist/utils/transactionUtils.cjs +0 -36
- package/dist/utils/transactionUtils.cjs.map +0 -1
- package/dist/utils/transactionUtils.d.cts +0 -17
- package/dist/utils/transactionUtils.d.cts.map +0 -1
- package/dist/utils/transactionUtils.d.mts +0 -17
- package/dist/utils/transactionUtils.d.mts.map +0 -1
- package/dist/utils/transactionUtils.mjs +0 -32
- package/dist/utils/transactionUtils.mjs.map +0 -1
- package/dist/utils/wait.cjs +0 -12
- package/dist/utils/wait.cjs.map +0 -1
- package/dist/utils/wait.d.cts +0 -8
- package/dist/utils/wait.d.cts.map +0 -1
- package/dist/utils/wait.d.mts +0 -8
- package/dist/utils/wait.d.mts.map +0 -1
- package/dist/utils/wait.mjs +0 -8
- package/dist/utils/wait.mjs.map +0 -1
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for validating Take Profit and Stop Loss prices based on position direction
|
|
3
|
-
*
|
|
4
|
-
* For Long positions:
|
|
5
|
-
* - Take Profit must be above current price (profit when price goes up)
|
|
6
|
-
* - Stop Loss must be below current price (loss when price goes down)
|
|
7
|
-
*
|
|
8
|
-
* For Short positions:
|
|
9
|
-
* - Take Profit must be below current price (profit when price goes down)
|
|
10
|
-
* - Stop Loss must be above current price (loss when price goes up)
|
|
11
|
-
*/
|
|
12
|
-
import { DECIMAL_PRECISION_CONFIG } from "../constants/perpsConfig.mjs";
|
|
13
|
-
// Re-export significant figures utilities from formatUtils for backwards compatibility
|
|
14
|
-
// These utilities are now consolidated in formatUtils.ts to avoid duplication
|
|
15
|
-
export { countSignificantFigures, hasExceededSignificantFigures, roundToSignificantFigures } from "./formatUtils.mjs";
|
|
16
|
-
/**
|
|
17
|
-
* Validates if a take profit price is valid for the given direction.
|
|
18
|
-
*
|
|
19
|
-
* @param price - The take profit price to validate
|
|
20
|
-
* @param validationParams - Validation parameters
|
|
21
|
-
* @param validationParams.currentPrice - The current market price
|
|
22
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
23
|
-
* @returns True if the take profit price is valid, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
export const isValidTakeProfitPrice = (price, { currentPrice, direction }) => {
|
|
26
|
-
if (!currentPrice || !direction || !price) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
const tpPrice = parseFloat(price.replace(/[$,]/gu, ''));
|
|
30
|
-
if (isNaN(tpPrice)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
const isLong = direction === 'long';
|
|
34
|
-
return isLong ? tpPrice > currentPrice : tpPrice < currentPrice;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Validates if a stop loss price is valid for the given direction.
|
|
38
|
-
*
|
|
39
|
-
* @param price - The stop loss price to validate
|
|
40
|
-
* @param validationParams - Validation parameters
|
|
41
|
-
* @param validationParams.currentPrice - The current market price
|
|
42
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
43
|
-
* @returns True if the stop loss price is valid, false otherwise
|
|
44
|
-
*/
|
|
45
|
-
export const isValidStopLossPrice = (price, { currentPrice, direction }) => {
|
|
46
|
-
if (!currentPrice || !direction || !price) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
const slPrice = parseFloat(price.replace(/[$,]/gu, ''));
|
|
50
|
-
if (isNaN(slPrice)) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
const isLong = direction === 'long';
|
|
54
|
-
return isLong ? slPrice < currentPrice : slPrice > currentPrice;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Validates if a stop loss price is within the liquidation price.
|
|
58
|
-
* For long positions: stop loss must be ABOVE liquidation price.
|
|
59
|
-
* For short positions: stop loss must be BELOW liquidation price.
|
|
60
|
-
*
|
|
61
|
-
* @param price - The stop loss price to validate
|
|
62
|
-
* @param liquidationPrice - The liquidation price threshold
|
|
63
|
-
* @param direction - The position direction (long or short)
|
|
64
|
-
* @returns True if the stop loss is safe from liquidation, false otherwise
|
|
65
|
-
*/
|
|
66
|
-
export const isStopLossSafeFromLiquidation = (price, liquidationPrice, direction) => {
|
|
67
|
-
if (!liquidationPrice || !direction || !price) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
// Clean up string values if necessary ($ or ,)
|
|
71
|
-
const slPriceNum = parseFloat(price.replace(/[$,]/gu, ''));
|
|
72
|
-
const liquidationPriceNum = parseFloat(liquidationPrice.replace(/[$,]/gu, ''));
|
|
73
|
-
if (isNaN(slPriceNum) || isNaN(liquidationPriceNum)) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
const isLong = direction === 'long';
|
|
77
|
-
return isLong
|
|
78
|
-
? slPriceNum > liquidationPriceNum
|
|
79
|
-
: slPriceNum < liquidationPriceNum;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Validates both take profit and stop loss prices.
|
|
83
|
-
*
|
|
84
|
-
* @param takeProfitPrice - The take profit price to validate
|
|
85
|
-
* @param stopLossPrice - The stop loss price to validate
|
|
86
|
-
* @param params - Validation parameters including currentPrice, direction, and liquidationPrice
|
|
87
|
-
* @returns True if both prices are valid, false otherwise
|
|
88
|
-
*/
|
|
89
|
-
export const validateTPSLPrices = (takeProfitPrice, stopLossPrice, params) => {
|
|
90
|
-
if (!params.currentPrice || !params.direction) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
let isValid = true;
|
|
94
|
-
if (takeProfitPrice) {
|
|
95
|
-
isValid = isValid && isValidTakeProfitPrice(takeProfitPrice, params);
|
|
96
|
-
}
|
|
97
|
-
if (stopLossPrice) {
|
|
98
|
-
isValid = isValid && isValidStopLossPrice(stopLossPrice, params);
|
|
99
|
-
}
|
|
100
|
-
if (params.liquidationPrice) {
|
|
101
|
-
isValid =
|
|
102
|
-
isValid &&
|
|
103
|
-
isStopLossSafeFromLiquidation(stopLossPrice, params.liquidationPrice, params.direction);
|
|
104
|
-
}
|
|
105
|
-
return isValid;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Gets the direction text for take profit error message.
|
|
109
|
-
*
|
|
110
|
-
* @param direction - The position direction (long or short)
|
|
111
|
-
* @returns Direction text (above/below) or empty string if no direction
|
|
112
|
-
*/
|
|
113
|
-
export const getTakeProfitErrorDirection = (direction) => {
|
|
114
|
-
if (!direction) {
|
|
115
|
-
return '';
|
|
116
|
-
}
|
|
117
|
-
return direction === 'long' ? 'above' : 'below';
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Gets the direction text for stop loss error message.
|
|
121
|
-
*
|
|
122
|
-
* @param direction - The position direction (long or short)
|
|
123
|
-
* @returns Direction text (below/above) or empty string if no direction
|
|
124
|
-
*/
|
|
125
|
-
export const getStopLossErrorDirection = (direction) => {
|
|
126
|
-
if (!direction) {
|
|
127
|
-
return '';
|
|
128
|
-
}
|
|
129
|
-
return direction === 'long' ? 'below' : 'above';
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Gets the direction text for stop loss liquidation error message.
|
|
133
|
-
*
|
|
134
|
-
* @param direction - The position direction (long or short)
|
|
135
|
-
* @returns Direction text (above/below) or empty string if no direction
|
|
136
|
-
*/
|
|
137
|
-
export const getStopLossLiquidationErrorDirection = (direction) => {
|
|
138
|
-
if (!direction) {
|
|
139
|
-
return '';
|
|
140
|
-
}
|
|
141
|
-
return direction === 'long' ? 'above' : 'below';
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Calculates price based on percentage change from current price.
|
|
145
|
-
*
|
|
146
|
-
* @param percentage - The percentage change
|
|
147
|
-
* @param isProfit - Whether this is for take profit (true) or stop loss (false)
|
|
148
|
-
* @param validationParams - Validation parameters
|
|
149
|
-
* @param validationParams.currentPrice - The current market price
|
|
150
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
151
|
-
* @returns The calculated price as a string
|
|
152
|
-
*/
|
|
153
|
-
export const calculatePriceForPercentage = (percentage, isProfit, { currentPrice, direction }) => {
|
|
154
|
-
if (!currentPrice) {
|
|
155
|
-
return '';
|
|
156
|
-
}
|
|
157
|
-
// For long positions: profit = price up, loss = price down
|
|
158
|
-
// For short positions: profit = price down, loss = price up
|
|
159
|
-
const isLong = direction === 'long';
|
|
160
|
-
const profitMultiplier = isLong ? 1 + percentage / 100 : 1 - percentage / 100;
|
|
161
|
-
const lossMultiplier = isLong ? 1 - percentage / 100 : 1 + percentage / 100;
|
|
162
|
-
const multiplier = isProfit ? profitMultiplier : lossMultiplier;
|
|
163
|
-
const calculatedPrice = currentPrice * multiplier;
|
|
164
|
-
// Return raw number string without formatting
|
|
165
|
-
return calculatedPrice.toFixed(2);
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Calculates percentage change based on target price.
|
|
169
|
-
*
|
|
170
|
-
* @param price - The target price (as string, may include formatting)
|
|
171
|
-
* @param isProfit - Whether this is for take profit (true) or stop loss (false)
|
|
172
|
-
* @param validationParams - Validation parameters
|
|
173
|
-
* @param validationParams.currentPrice - The current market price
|
|
174
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
175
|
-
* @returns The percentage as a string
|
|
176
|
-
*/
|
|
177
|
-
export const calculatePercentageForPrice = (price, isProfit, { currentPrice, direction }) => {
|
|
178
|
-
if (!currentPrice || !price) {
|
|
179
|
-
return '';
|
|
180
|
-
}
|
|
181
|
-
const priceNum = parseFloat(price.replace(/[$,]/gu, ''));
|
|
182
|
-
if (isNaN(priceNum)) {
|
|
183
|
-
return '';
|
|
184
|
-
}
|
|
185
|
-
const isLong = direction === 'long';
|
|
186
|
-
const priceDiff = priceNum - currentPrice;
|
|
187
|
-
const percentage = Math.abs((priceDiff / currentPrice) * 100);
|
|
188
|
-
// Validate direction consistency
|
|
189
|
-
if (isProfit) {
|
|
190
|
-
// For profit: long needs higher price, short needs lower price
|
|
191
|
-
const isValidDirection = isLong ? priceDiff > 0 : priceDiff < 0;
|
|
192
|
-
return isValidDirection
|
|
193
|
-
? percentage.toFixed(2)
|
|
194
|
-
: `-${percentage.toFixed(2)}`;
|
|
195
|
-
}
|
|
196
|
-
// For loss: long needs lower price, short needs higher price
|
|
197
|
-
const isValidDirection = isLong ? priceDiff < 0 : priceDiff > 0;
|
|
198
|
-
return isValidDirection ? percentage.toFixed(2) : `-${percentage.toFixed(2)}`;
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Checks if take profit or stop loss values have changed from their initial values
|
|
202
|
-
*
|
|
203
|
-
* @param currentTakeProfitPrice Current take profit price value
|
|
204
|
-
* @param currentStopLossPrice Current stop loss price value
|
|
205
|
-
* @param initialTakeProfitPrice Initial take profit price value
|
|
206
|
-
* @param initialStopLossPrice Initial stop loss price value
|
|
207
|
-
* @returns true if either value has changed, false if both are unchanged
|
|
208
|
-
*/
|
|
209
|
-
export const hasTPSLValuesChanged = (currentTakeProfitPrice, currentStopLossPrice, initialTakeProfitPrice, initialStopLossPrice) => {
|
|
210
|
-
// Normalize values - remove formatting, convert to numbers for comparison
|
|
211
|
-
const normalizeValue = (value) => {
|
|
212
|
-
if (!value || value.trim() === '') {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
const cleaned = value.replace(/[$,]/gu, '');
|
|
216
|
-
const parsed = parseFloat(cleaned);
|
|
217
|
-
return isNaN(parsed) ? undefined : parsed;
|
|
218
|
-
};
|
|
219
|
-
const normalizedCurrentTP = normalizeValue(currentTakeProfitPrice);
|
|
220
|
-
const normalizedCurrentSL = normalizeValue(currentStopLossPrice);
|
|
221
|
-
const normalizedInitialTP = normalizeValue(initialTakeProfitPrice);
|
|
222
|
-
const normalizedInitialSL = normalizeValue(initialStopLossPrice);
|
|
223
|
-
// Check if take profit has changed
|
|
224
|
-
const tpChanged = normalizedCurrentTP !== normalizedInitialTP;
|
|
225
|
-
// Check if stop loss has changed
|
|
226
|
-
const slChanged = normalizedCurrentSL !== normalizedInitialSL;
|
|
227
|
-
return tpChanged || slChanged;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Calculates the trigger price for a given RoE percentage.
|
|
231
|
-
* RoE% = (PnL / marginUsed) * 100
|
|
232
|
-
* PnL = (exitPrice - entryPrice) * size (for long)
|
|
233
|
-
* PnL = (entryPrice - exitPrice) * size (for short)
|
|
234
|
-
*
|
|
235
|
-
* @param roePercentage - The target RoE percentage (e.g., 10 for +10%, -5 for -5%)
|
|
236
|
-
* @param isProfit - Whether this is for take profit (true) or stop loss (false)
|
|
237
|
-
* @param validationParams - Validation parameters
|
|
238
|
-
* @param validationParams.currentPrice - The current market price
|
|
239
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
240
|
-
* @param validationParams.leverage - The position leverage multiplier
|
|
241
|
-
* @param validationParams.entryPrice - The entry price for existing positions
|
|
242
|
-
* @returns The calculated trigger price as a string
|
|
243
|
-
*/
|
|
244
|
-
export const calculatePriceForRoE = (roePercentage, isProfit, { currentPrice, direction, leverage = 1, entryPrice }) => {
|
|
245
|
-
// Use entry price if available (for existing positions), otherwise use current price
|
|
246
|
-
const basePrice = entryPrice ?? currentPrice;
|
|
247
|
-
if (!basePrice || basePrice <= 0 || !direction) {
|
|
248
|
-
return '';
|
|
249
|
-
}
|
|
250
|
-
const isLong = direction === 'long';
|
|
251
|
-
let adjustedRoePercentage = roePercentage;
|
|
252
|
-
// Prevent stop loss from exceeding maximum possible loss
|
|
253
|
-
// Maximum theoretical loss is 100% * leverage (before liquidation)
|
|
254
|
-
// But we'll cap it at 99% to avoid negative prices
|
|
255
|
-
if (!isProfit && Math.abs(roePercentage) >= leverage * 99) {
|
|
256
|
-
// Cap at 99% of max loss to prevent negative prices
|
|
257
|
-
adjustedRoePercentage = -(leverage * 99);
|
|
258
|
-
}
|
|
259
|
-
// RoE% = (PnL / marginUsed) * 100
|
|
260
|
-
// PnL = RoE% * marginUsed / 100
|
|
261
|
-
// marginUsed = positionValue / leverage
|
|
262
|
-
// positionValue = entryPrice * size
|
|
263
|
-
// Therefore: PnL = RoE% * (entryPrice * size) / (leverage * 100)
|
|
264
|
-
// Simplifying: PnL/positionValue = RoE% / (leverage * 100)
|
|
265
|
-
// priceChange/entryPrice = RoE% / (leverage * 100)
|
|
266
|
-
// priceChange = entryPrice * RoE% / (leverage * 100)
|
|
267
|
-
const priceChangeRatio = adjustedRoePercentage / (leverage * 100);
|
|
268
|
-
let calculatedPrice;
|
|
269
|
-
if (isProfit) {
|
|
270
|
-
// For take profit
|
|
271
|
-
if (isLong) {
|
|
272
|
-
// Long TP: price needs to go up
|
|
273
|
-
calculatedPrice = basePrice * (1 + priceChangeRatio);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
// Short TP: price needs to go down
|
|
277
|
-
calculatedPrice = basePrice * (1 - priceChangeRatio);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else if (isLong) {
|
|
281
|
-
// For stop loss (negative RoE)
|
|
282
|
-
// Long SL: price needs to go down
|
|
283
|
-
calculatedPrice = basePrice * (1 - -priceChangeRatio);
|
|
284
|
-
// Ensure price never goes negative
|
|
285
|
-
if (calculatedPrice <= 0) {
|
|
286
|
-
calculatedPrice = basePrice * 0.01; // Minimum 1% of base price
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
// Short SL: price needs to go up
|
|
291
|
-
calculatedPrice = basePrice * (1 + -priceChangeRatio);
|
|
292
|
-
}
|
|
293
|
-
// Determine appropriate precision based on the price magnitude
|
|
294
|
-
// For very small prices (like PEPE), use more decimal places
|
|
295
|
-
let precision = 2;
|
|
296
|
-
if (calculatedPrice < 0.01) {
|
|
297
|
-
precision = 8; // For prices less than $0.01, use 8 decimal places
|
|
298
|
-
}
|
|
299
|
-
else if (calculatedPrice < 1) {
|
|
300
|
-
precision = DECIMAL_PRECISION_CONFIG.MaxPriceDecimals; // For prices less than $1, use MAX_PRICE_DECIMALS decimal places
|
|
301
|
-
}
|
|
302
|
-
else if (calculatedPrice < 100) {
|
|
303
|
-
precision = 4; // For prices less than $100, use 4 decimal places
|
|
304
|
-
}
|
|
305
|
-
let finalResult = calculatedPrice.toFixed(precision);
|
|
306
|
-
// Apply clean formatting - remove unnecessary trailing zeros and decimal point
|
|
307
|
-
const numValue = parseFloat(finalResult);
|
|
308
|
-
if (numValue % 1 === 0) {
|
|
309
|
-
// If it's a whole number, show without decimals
|
|
310
|
-
finalResult = numValue.toString();
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
// Otherwise, use the formatted result but remove trailing zeros
|
|
314
|
-
finalResult = parseFloat(finalResult).toString();
|
|
315
|
-
}
|
|
316
|
-
return finalResult;
|
|
317
|
-
};
|
|
318
|
-
/**
|
|
319
|
-
* Calculates the RoE percentage for a given trigger price.
|
|
320
|
-
*
|
|
321
|
-
* @param price - The trigger price (as string, may include formatting)
|
|
322
|
-
* @param isProfit - Whether this is for take profit (true) or stop loss (false)
|
|
323
|
-
* @param isForPositionBoundTpsl - Whether this is for position bound TP/SL roe calculation
|
|
324
|
-
* @param validationParams - Validation parameters
|
|
325
|
-
* @param validationParams.currentPrice - The current market price
|
|
326
|
-
* @param validationParams.direction - The position direction (long or short)
|
|
327
|
-
* @param validationParams.leverage - The position leverage multiplier
|
|
328
|
-
* @param validationParams.entryPrice - The entry price for existing positions
|
|
329
|
-
* @returns The RoE percentage as a string
|
|
330
|
-
*/
|
|
331
|
-
export const calculateRoEForPrice = (price, isProfit, isForPositionBoundTpsl, { currentPrice, direction, leverage = 1, entryPrice }) => {
|
|
332
|
-
// Use entry price if available (for existing positions), otherwise use current price
|
|
333
|
-
const basePrice = entryPrice ?? currentPrice;
|
|
334
|
-
if (!basePrice || basePrice <= 0 || !price || !direction) {
|
|
335
|
-
return '';
|
|
336
|
-
}
|
|
337
|
-
const priceNum = parseFloat(price.replace(/[$,]/gu, ''));
|
|
338
|
-
if (isNaN(priceNum) || priceNum <= 0) {
|
|
339
|
-
return '';
|
|
340
|
-
}
|
|
341
|
-
const isLong = direction === 'long';
|
|
342
|
-
// Calculate price change ratio
|
|
343
|
-
const priceChangeRatio = (priceNum - basePrice) / basePrice;
|
|
344
|
-
// RoE% = priceChangeRatio * leverage * 100
|
|
345
|
-
let roePercentage = priceChangeRatio * leverage * 100;
|
|
346
|
-
if (!isLong) {
|
|
347
|
-
roePercentage = -roePercentage;
|
|
348
|
-
}
|
|
349
|
-
if (!isForPositionBoundTpsl &&
|
|
350
|
-
((isProfit && roePercentage < 0) || (!isProfit && roePercentage > 0))) {
|
|
351
|
-
roePercentage = 0;
|
|
352
|
-
}
|
|
353
|
-
return roePercentage.toFixed(2);
|
|
354
|
-
};
|
|
355
|
-
/**
|
|
356
|
-
* Safely parse RoE percentage to avoid NaN display in UI
|
|
357
|
-
*
|
|
358
|
-
* @param roePercent - RoE percentage string from calculateRoEForPrice
|
|
359
|
-
* @returns Formatted percentage string or empty string for invalid input
|
|
360
|
-
*/
|
|
361
|
-
export const safeParseRoEPercentage = (roePercent) => {
|
|
362
|
-
if (!roePercent || roePercent.trim() === '') {
|
|
363
|
-
return ''; // Return empty string for invalid input
|
|
364
|
-
}
|
|
365
|
-
const parsed = parseFloat(roePercent);
|
|
366
|
-
if (isNaN(parsed)) {
|
|
367
|
-
return ''; // Return empty string for NaN
|
|
368
|
-
}
|
|
369
|
-
// Show clean integers when possible (10% instead of 10.00%)
|
|
370
|
-
return parsed % 1 === 0 ? parsed.toFixed(0) : parsed.toFixed(2);
|
|
371
|
-
};
|
|
372
|
-
/**
|
|
373
|
-
* Format RoE percentage for display based on focus state
|
|
374
|
-
*
|
|
375
|
-
* @param value - The raw percentage value as string
|
|
376
|
-
* @param isFocused - Whether the input is currently focused
|
|
377
|
-
* @returns Formatted percentage string for display
|
|
378
|
-
*/
|
|
379
|
-
export const formatRoEPercentageDisplay = (value, isFocused) => {
|
|
380
|
-
if (!value || value.trim() === '') {
|
|
381
|
-
return '';
|
|
382
|
-
}
|
|
383
|
-
// When focused, preserve the exact user input including signs and decimal points
|
|
384
|
-
if (isFocused) {
|
|
385
|
-
// Allow valid numeric patterns with optional sign and space
|
|
386
|
-
if (value === '.' ||
|
|
387
|
-
value === '+' ||
|
|
388
|
-
value === '-' ||
|
|
389
|
-
/^[+-]?\s?\d*\.?\d*$/u.test(value)) {
|
|
390
|
-
return value;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const parsed = parseFloat(value);
|
|
394
|
-
if (isNaN(parsed)) {
|
|
395
|
-
return '';
|
|
396
|
-
}
|
|
397
|
-
if (isFocused) {
|
|
398
|
-
// This branch shouldn't be reached now, but keep as fallback
|
|
399
|
-
return value;
|
|
400
|
-
}
|
|
401
|
-
// When not focused, show clean display format with appropriate sign
|
|
402
|
-
const absValue = Math.abs(parsed);
|
|
403
|
-
const formattedValue = absValue % 1 === 0 ? absValue.toFixed(0) : absValue.toFixed(2);
|
|
404
|
-
// Always show sign for display
|
|
405
|
-
if (parsed >= 0) {
|
|
406
|
-
return `+ ${formattedValue}`;
|
|
407
|
-
}
|
|
408
|
-
return `- ${formattedValue}`;
|
|
409
|
-
};
|
|
410
|
-
/**
|
|
411
|
-
* Calculate the maximum allowed stop loss percentage based on leverage
|
|
412
|
-
*
|
|
413
|
-
* @param leverage The position leverage
|
|
414
|
-
* @returns The maximum stop loss percentage (as a positive number)
|
|
415
|
-
*/
|
|
416
|
-
export const getMaxStopLossPercentage = (leverage) =>
|
|
417
|
-
// Maximum theoretical loss is 100% * leverage (before liquidation)
|
|
418
|
-
// But we cap it at 99% to avoid negative prices and leave room for fees
|
|
419
|
-
Math.min(leverage * 99, 999);
|
|
420
|
-
/**
|
|
421
|
-
* Validate if a stop loss percentage is within allowed bounds
|
|
422
|
-
*
|
|
423
|
-
* @param percentage The stop loss percentage (as a positive number)
|
|
424
|
-
* @param leverage The position leverage
|
|
425
|
-
* @returns True if valid, false otherwise
|
|
426
|
-
*/
|
|
427
|
-
export const isValidStopLossPercentage = (percentage, leverage) => {
|
|
428
|
-
if (percentage <= 0) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
const maxAllowed = getMaxStopLossPercentage(leverage);
|
|
432
|
-
return percentage <= maxAllowed;
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* Sanitizes input text for percentage fields by handling signs and decimal points
|
|
436
|
-
*
|
|
437
|
-
* @param text - Raw input text
|
|
438
|
-
* @param currentValue - Current field value for length comparison (optional)
|
|
439
|
-
* @param maxDecimalPlaces - Maximum allowed decimal places (default: 5)
|
|
440
|
-
* @returns Sanitized text with proper sign and decimal handling, or null if validation fails
|
|
441
|
-
*/
|
|
442
|
-
export const sanitizePercentageInput = (text, currentValue, maxDecimalPlaces = 5) => {
|
|
443
|
-
// Allow numbers, decimal point, and plus/minus signs
|
|
444
|
-
// Also handle en-dash (–) and em-dash (—) which might come from typing --
|
|
445
|
-
const sanitized = text.replace(/[–—]/gu, '-').replace(/[^0-9.+-]/gu, '');
|
|
446
|
-
// Handle sign placement - only allow at the beginning
|
|
447
|
-
let finalValue = sanitized;
|
|
448
|
-
if (sanitized.includes('+') || sanitized.includes('-')) {
|
|
449
|
-
// Remove duplicate consecutive signs but keep the first one
|
|
450
|
-
// e.g., "++" becomes "+", "--" becomes "-"
|
|
451
|
-
finalValue = sanitized.replace(/([+-])\1+/gu, '$1');
|
|
452
|
-
// Only do mixed sign cleanup if there are actually mixed signs
|
|
453
|
-
// Check if there are different types of signs in the string
|
|
454
|
-
const hasPlus = finalValue.includes('+');
|
|
455
|
-
const hasMinus = finalValue.includes('-');
|
|
456
|
-
if (hasPlus && hasMinus) {
|
|
457
|
-
// Mixed signs - keep only the first sign
|
|
458
|
-
const firstSignMatch = /[+-]/u.exec(finalValue);
|
|
459
|
-
if (firstSignMatch) {
|
|
460
|
-
const sign = firstSignMatch[0];
|
|
461
|
-
const restOfString = finalValue.substring(1);
|
|
462
|
-
const numberPart = restOfString.replace(/[+-]/gu, '');
|
|
463
|
-
finalValue = numberPart ? sign + numberPart : sign;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
// Prevent multiple decimal points
|
|
468
|
-
const parts = finalValue.replace(/[+-]/gu, '').split('.');
|
|
469
|
-
if (parts.length > 2) {
|
|
470
|
-
return null;
|
|
471
|
-
} // Return null for invalid input
|
|
472
|
-
// Allow erasing but prevent adding when there are more than maxDecimalPlaces decimal places
|
|
473
|
-
if (currentValue !== undefined) {
|
|
474
|
-
const decimalPart = parts[1];
|
|
475
|
-
if (decimalPart?.length > maxDecimalPlaces &&
|
|
476
|
-
finalValue.length >= currentValue.length) {
|
|
477
|
-
return null; // Return null to prevent the update
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return finalValue;
|
|
481
|
-
};
|
|
482
|
-
//# sourceMappingURL=tpslValidation.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tpslVal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Y,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,IACE,WAAW,EAAE,MAAM,GAAG,gBAAgB;YACtC,UAAU,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,EACxC,CAAC;YACD,OAAO,IAAI,CAAC,CAAC,oCAAoC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC","sourcesContent":["/**\n * Utility functions for validating Take Profit and Stop Loss prices based on position direction\n *\n * For Long positions:\n * - Take Profit must be above current price (profit when price goes up)\n * - Stop Loss must be below current price (loss when price goes down)\n *\n * For Short positions:\n * - Take Profit must be below current price (profit when price goes down)\n * - Stop Loss must be above current price (loss when price goes up)\n */\n\nimport { DECIMAL_PRECISION_CONFIG } from '../constants/perpsConfig';\n// Re-export significant figures utilities from formatUtils for backwards compatibility\n// These utilities are now consolidated in formatUtils.ts to avoid duplication\nexport {\n countSignificantFigures,\n hasExceededSignificantFigures,\n roundToSignificantFigures,\n} from './formatUtils';\n\ntype ValidationParams = {\n currentPrice: number;\n direction?: 'long' | 'short';\n leverage?: number;\n entryPrice?: number; // For existing positions\n liquidationPrice?: string;\n};\n\n/**\n * Validates if a take profit price is valid for the given direction.\n *\n * @param price - The take profit price to validate\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns True if the take profit price is valid, false otherwise\n */\nexport const isValidTakeProfitPrice = (\n price: string,\n { currentPrice, direction }: ValidationParams,\n): boolean => {\n if (!currentPrice || !direction || !price) {\n return true;\n }\n\n const tpPrice = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(tpPrice)) {\n return true;\n }\n\n const isLong = direction === 'long';\n return isLong ? tpPrice > currentPrice : tpPrice < currentPrice;\n};\n\n/**\n * Validates if a stop loss price is valid for the given direction.\n *\n * @param price - The stop loss price to validate\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns True if the stop loss price is valid, false otherwise\n */\nexport const isValidStopLossPrice = (\n price: string,\n { currentPrice, direction }: ValidationParams,\n): boolean => {\n if (!currentPrice || !direction || !price) {\n return true;\n }\n\n const slPrice = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(slPrice)) {\n return true;\n }\n\n const isLong = direction === 'long';\n return isLong ? slPrice < currentPrice : slPrice > currentPrice;\n};\n\n/**\n * Validates if a stop loss price is within the liquidation price.\n * For long positions: stop loss must be ABOVE liquidation price.\n * For short positions: stop loss must be BELOW liquidation price.\n *\n * @param price - The stop loss price to validate\n * @param liquidationPrice - The liquidation price threshold\n * @param direction - The position direction (long or short)\n * @returns True if the stop loss is safe from liquidation, false otherwise\n */\nexport const isStopLossSafeFromLiquidation = (\n price?: string,\n liquidationPrice?: string,\n direction?: 'long' | 'short',\n): boolean => {\n if (!liquidationPrice || !direction || !price) {\n return true;\n }\n\n // Clean up string values if necessary ($ or ,)\n const slPriceNum = parseFloat(price.replace(/[$,]/gu, ''));\n const liquidationPriceNum = parseFloat(\n liquidationPrice.replace(/[$,]/gu, ''),\n );\n\n if (isNaN(slPriceNum) || isNaN(liquidationPriceNum)) {\n return true;\n }\n\n const isLong = direction === 'long';\n\n return isLong\n ? slPriceNum > liquidationPriceNum\n : slPriceNum < liquidationPriceNum;\n};\n\n/**\n * Validates both take profit and stop loss prices.\n *\n * @param takeProfitPrice - The take profit price to validate\n * @param stopLossPrice - The stop loss price to validate\n * @param params - Validation parameters including currentPrice, direction, and liquidationPrice\n * @returns True if both prices are valid, false otherwise\n */\nexport const validateTPSLPrices = (\n takeProfitPrice: string | undefined,\n stopLossPrice: string | undefined,\n params: ValidationParams,\n): boolean => {\n if (!params.currentPrice || !params.direction) {\n return true;\n }\n\n let isValid = true;\n\n if (takeProfitPrice) {\n isValid = isValid && isValidTakeProfitPrice(takeProfitPrice, params);\n }\n\n if (stopLossPrice) {\n isValid = isValid && isValidStopLossPrice(stopLossPrice, params);\n }\n\n if (params.liquidationPrice) {\n isValid =\n isValid &&\n isStopLossSafeFromLiquidation(\n stopLossPrice,\n params.liquidationPrice,\n params.direction,\n );\n }\n\n return isValid;\n};\n\n/**\n * Gets the direction text for take profit error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (above/below) or empty string if no direction\n */\nexport const getTakeProfitErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'above' : 'below';\n};\n\n/**\n * Gets the direction text for stop loss error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (below/above) or empty string if no direction\n */\nexport const getStopLossErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'below' : 'above';\n};\n\n/**\n * Gets the direction text for stop loss liquidation error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (above/below) or empty string if no direction\n */\nexport const getStopLossLiquidationErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'above' : 'below';\n};\n\n/**\n * Calculates price based on percentage change from current price.\n *\n * @param percentage - The percentage change\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns The calculated price as a string\n */\nexport const calculatePriceForPercentage = (\n percentage: number,\n isProfit: boolean,\n { currentPrice, direction }: ValidationParams,\n): string => {\n if (!currentPrice) {\n return '';\n }\n\n // For long positions: profit = price up, loss = price down\n // For short positions: profit = price down, loss = price up\n const isLong = direction === 'long';\n const profitMultiplier = isLong ? 1 + percentage / 100 : 1 - percentage / 100;\n const lossMultiplier = isLong ? 1 - percentage / 100 : 1 + percentage / 100;\n const multiplier = isProfit ? profitMultiplier : lossMultiplier;\n\n const calculatedPrice = currentPrice * multiplier;\n // Return raw number string without formatting\n return calculatedPrice.toFixed(2);\n};\n\n/**\n * Calculates percentage change based on target price.\n *\n * @param price - The target price (as string, may include formatting)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns The percentage as a string\n */\nexport const calculatePercentageForPrice = (\n price: string,\n isProfit: boolean,\n { currentPrice, direction }: ValidationParams,\n): string => {\n if (!currentPrice || !price) {\n return '';\n }\n\n const priceNum = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(priceNum)) {\n return '';\n }\n\n const isLong = direction === 'long';\n const priceDiff = priceNum - currentPrice;\n const percentage = Math.abs((priceDiff / currentPrice) * 100);\n\n // Validate direction consistency\n if (isProfit) {\n // For profit: long needs higher price, short needs lower price\n const isValidDirection = isLong ? priceDiff > 0 : priceDiff < 0;\n return isValidDirection\n ? percentage.toFixed(2)\n : `-${percentage.toFixed(2)}`;\n }\n // For loss: long needs lower price, short needs higher price\n const isValidDirection = isLong ? priceDiff < 0 : priceDiff > 0;\n return isValidDirection ? percentage.toFixed(2) : `-${percentage.toFixed(2)}`;\n};\n\n/**\n * Checks if take profit or stop loss values have changed from their initial values\n *\n * @param currentTakeProfitPrice Current take profit price value\n * @param currentStopLossPrice Current stop loss price value\n * @param initialTakeProfitPrice Initial take profit price value\n * @param initialStopLossPrice Initial stop loss price value\n * @returns true if either value has changed, false if both are unchanged\n */\nexport const hasTPSLValuesChanged = (\n currentTakeProfitPrice: string | undefined,\n currentStopLossPrice: string | undefined,\n initialTakeProfitPrice: string | undefined,\n initialStopLossPrice: string | undefined,\n): boolean => {\n // Normalize values - remove formatting, convert to numbers for comparison\n const normalizeValue = (value: string | undefined): number | undefined => {\n if (!value || value.trim() === '') {\n return undefined;\n }\n const cleaned = value.replace(/[$,]/gu, '');\n const parsed = parseFloat(cleaned);\n return isNaN(parsed) ? undefined : parsed;\n };\n\n const normalizedCurrentTP = normalizeValue(currentTakeProfitPrice);\n const normalizedCurrentSL = normalizeValue(currentStopLossPrice);\n const normalizedInitialTP = normalizeValue(initialTakeProfitPrice);\n const normalizedInitialSL = normalizeValue(initialStopLossPrice);\n\n // Check if take profit has changed\n const tpChanged = normalizedCurrentTP !== normalizedInitialTP;\n\n // Check if stop loss has changed\n const slChanged = normalizedCurrentSL !== normalizedInitialSL;\n\n return tpChanged || slChanged;\n};\n\n/**\n * Calculates the trigger price for a given RoE percentage.\n * RoE% = (PnL / marginUsed) * 100\n * PnL = (exitPrice - entryPrice) * size (for long)\n * PnL = (entryPrice - exitPrice) * size (for short)\n *\n * @param roePercentage - The target RoE percentage (e.g., 10 for +10%, -5 for -5%)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @param validationParams.leverage - The position leverage multiplier\n * @param validationParams.entryPrice - The entry price for existing positions\n * @returns The calculated trigger price as a string\n */\nexport const calculatePriceForRoE = (\n roePercentage: number,\n isProfit: boolean,\n { currentPrice, direction, leverage = 1, entryPrice }: ValidationParams,\n): string => {\n // Use entry price if available (for existing positions), otherwise use current price\n const basePrice = entryPrice ?? currentPrice;\n if (!basePrice || basePrice <= 0 || !direction) {\n return '';\n }\n\n const isLong = direction === 'long';\n let adjustedRoePercentage = roePercentage;\n\n // Prevent stop loss from exceeding maximum possible loss\n // Maximum theoretical loss is 100% * leverage (before liquidation)\n // But we'll cap it at 99% to avoid negative prices\n if (!isProfit && Math.abs(roePercentage) >= leverage * 99) {\n // Cap at 99% of max loss to prevent negative prices\n adjustedRoePercentage = -(leverage * 99);\n }\n\n // RoE% = (PnL / marginUsed) * 100\n // PnL = RoE% * marginUsed / 100\n // marginUsed = positionValue / leverage\n // positionValue = entryPrice * size\n // Therefore: PnL = RoE% * (entryPrice * size) / (leverage * 100)\n // Simplifying: PnL/positionValue = RoE% / (leverage * 100)\n // priceChange/entryPrice = RoE% / (leverage * 100)\n // priceChange = entryPrice * RoE% / (leverage * 100)\n\n const priceChangeRatio = adjustedRoePercentage / (leverage * 100);\n\n let calculatedPrice: number;\n if (isProfit) {\n // For take profit\n if (isLong) {\n // Long TP: price needs to go up\n calculatedPrice = basePrice * (1 + priceChangeRatio);\n } else {\n // Short TP: price needs to go down\n calculatedPrice = basePrice * (1 - priceChangeRatio);\n }\n } else if (isLong) {\n // For stop loss (negative RoE)\n // Long SL: price needs to go down\n calculatedPrice = basePrice * (1 - -priceChangeRatio);\n // Ensure price never goes negative\n if (calculatedPrice <= 0) {\n calculatedPrice = basePrice * 0.01; // Minimum 1% of base price\n }\n } else {\n // Short SL: price needs to go up\n calculatedPrice = basePrice * (1 + -priceChangeRatio);\n }\n\n // Determine appropriate precision based on the price magnitude\n // For very small prices (like PEPE), use more decimal places\n let precision = 2;\n if (calculatedPrice < 0.01) {\n precision = 8; // For prices less than $0.01, use 8 decimal places\n } else if (calculatedPrice < 1) {\n precision = DECIMAL_PRECISION_CONFIG.MaxPriceDecimals; // For prices less than $1, use MAX_PRICE_DECIMALS decimal places\n } else if (calculatedPrice < 100) {\n precision = 4; // For prices less than $100, use 4 decimal places\n }\n\n let finalResult = calculatedPrice.toFixed(precision);\n\n // Apply clean formatting - remove unnecessary trailing zeros and decimal point\n const numValue = parseFloat(finalResult);\n if (numValue % 1 === 0) {\n // If it's a whole number, show without decimals\n finalResult = numValue.toString();\n } else {\n // Otherwise, use the formatted result but remove trailing zeros\n finalResult = parseFloat(finalResult).toString();\n }\n\n return finalResult;\n};\n\n/**\n * Calculates the RoE percentage for a given trigger price.\n *\n * @param price - The trigger price (as string, may include formatting)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param isForPositionBoundTpsl - Whether this is for position bound TP/SL roe calculation\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @param validationParams.leverage - The position leverage multiplier\n * @param validationParams.entryPrice - The entry price for existing positions\n * @returns The RoE percentage as a string\n */\nexport const calculateRoEForPrice = (\n price: string,\n isProfit: boolean,\n isForPositionBoundTpsl: boolean,\n { currentPrice, direction, leverage = 1, entryPrice }: ValidationParams,\n): string => {\n // Use entry price if available (for existing positions), otherwise use current price\n const basePrice = entryPrice ?? currentPrice;\n if (!basePrice || basePrice <= 0 || !price || !direction) {\n return '';\n }\n\n const priceNum = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(priceNum) || priceNum <= 0) {\n return '';\n }\n\n const isLong = direction === 'long';\n\n // Calculate price change ratio\n const priceChangeRatio = (priceNum - basePrice) / basePrice;\n\n // RoE% = priceChangeRatio * leverage * 100\n let roePercentage = priceChangeRatio * leverage * 100;\n if (!isLong) {\n roePercentage = -roePercentage;\n }\n\n if (\n !isForPositionBoundTpsl &&\n ((isProfit && roePercentage < 0) || (!isProfit && roePercentage > 0))\n ) {\n roePercentage = 0;\n }\n\n return roePercentage.toFixed(2);\n};\n\n/**\n * Safely parse RoE percentage to avoid NaN display in UI\n *\n * @param roePercent - RoE percentage string from calculateRoEForPrice\n * @returns Formatted percentage string or empty string for invalid input\n */\nexport const safeParseRoEPercentage = (roePercent: string): string => {\n if (!roePercent || roePercent.trim() === '') {\n return ''; // Return empty string for invalid input\n }\n\n const parsed = parseFloat(roePercent);\n if (isNaN(parsed)) {\n return ''; // Return empty string for NaN\n }\n\n // Show clean integers when possible (10% instead of 10.00%)\n return parsed % 1 === 0 ? parsed.toFixed(0) : parsed.toFixed(2);\n};\n\n/**\n * Format RoE percentage for display based on focus state\n *\n * @param value - The raw percentage value as string\n * @param isFocused - Whether the input is currently focused\n * @returns Formatted percentage string for display\n */\nexport const formatRoEPercentageDisplay = (\n value: string,\n isFocused: boolean,\n): string => {\n if (!value || value.trim() === '') {\n return '';\n }\n\n // When focused, preserve the exact user input including signs and decimal points\n if (isFocused) {\n // Allow valid numeric patterns with optional sign and space\n if (\n value === '.' ||\n value === '+' ||\n value === '-' ||\n /^[+-]?\\s?\\d*\\.?\\d*$/u.test(value)\n ) {\n return value;\n }\n }\n\n const parsed = parseFloat(value);\n if (isNaN(parsed)) {\n return '';\n }\n\n if (isFocused) {\n // This branch shouldn't be reached now, but keep as fallback\n return value;\n }\n\n // When not focused, show clean display format with appropriate sign\n const absValue = Math.abs(parsed);\n const formattedValue =\n absValue % 1 === 0 ? absValue.toFixed(0) : absValue.toFixed(2);\n\n // Always show sign for display\n if (parsed >= 0) {\n return `+ ${formattedValue}`;\n }\n return `- ${formattedValue}`;\n};\n\n/**\n * Calculate the maximum allowed stop loss percentage based on leverage\n *\n * @param leverage The position leverage\n * @returns The maximum stop loss percentage (as a positive number)\n */\nexport const getMaxStopLossPercentage = (leverage: number): number =>\n // Maximum theoretical loss is 100% * leverage (before liquidation)\n // But we cap it at 99% to avoid negative prices and leave room for fees\n Math.min(leverage * 99, 999);\n\n/**\n * Validate if a stop loss percentage is within allowed bounds\n *\n * @param percentage The stop loss percentage (as a positive number)\n * @param leverage The position leverage\n * @returns True if valid, false otherwise\n */\nexport const isValidStopLossPercentage = (\n percentage: number,\n leverage: number,\n): boolean => {\n if (percentage <= 0) {\n return false;\n }\n const maxAllowed = getMaxStopLossPercentage(leverage);\n return percentage <= maxAllowed;\n};\n\n/**\n * Sanitizes input text for percentage fields by handling signs and decimal points\n *\n * @param text - Raw input text\n * @param currentValue - Current field value for length comparison (optional)\n * @param maxDecimalPlaces - Maximum allowed decimal places (default: 5)\n * @returns Sanitized text with proper sign and decimal handling, or null if validation fails\n */\nexport const sanitizePercentageInput = (\n text: string,\n currentValue?: string,\n maxDecimalPlaces: number = 5,\n): string | null => {\n // Allow numbers, decimal point, and plus/minus signs\n // Also handle en-dash (–) and em-dash (—) which might come from typing --\n const sanitized = text.replace(/[–—]/gu, '-').replace(/[^0-9.+-]/gu, '');\n\n // Handle sign placement - only allow at the beginning\n let finalValue = sanitized;\n if (sanitized.includes('+') || sanitized.includes('-')) {\n // Remove duplicate consecutive signs but keep the first one\n // e.g., \"++\" becomes \"+\", \"--\" becomes \"-\"\n finalValue = sanitized.replace(/([+-])\\1+/gu, '$1');\n\n // Only do mixed sign cleanup if there are actually mixed signs\n // Check if there are different types of signs in the string\n const hasPlus = finalValue.includes('+');\n const hasMinus = finalValue.includes('-');\n if (hasPlus && hasMinus) {\n // Mixed signs - keep only the first sign\n const firstSignMatch = /[+-]/u.exec(finalValue);\n if (firstSignMatch) {\n const sign = firstSignMatch[0];\n const restOfString = finalValue.substring(1);\n const numberPart = restOfString.replace(/[+-]/gu, '');\n finalValue = numberPart ? sign + numberPart : sign;\n }\n }\n }\n\n // Prevent multiple decimal points\n const parts = finalValue.replace(/[+-]/gu, '').split('.');\n if (parts.length > 2) {\n return null;\n } // Return null for invalid input\n\n // Allow erasing but prevent adding when there are more than maxDecimalPlaces decimal places\n if (currentValue !== undefined) {\n const decimalPart = parts[1];\n if (\n decimalPart?.length > maxDecimalPlaces &&\n finalValue.length >= currentValue.length\n ) {\n return null; // Return null to prevent the update\n }\n }\n\n return finalValue;\n};\n"]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateTransferData = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
// ERC-20 transfer function selector: keccak256('transfer(address,uint256)').slice(0, 10)
|
|
6
|
-
const TRANSFER_FUNCTION_SELECTOR = '0xa9059cbb';
|
|
7
|
-
/**
|
|
8
|
-
* Generate ERC-20 transfer call data.
|
|
9
|
-
*
|
|
10
|
-
* Encodes the function selector and parameters for an ERC-20 transfer(address,uint256) call.
|
|
11
|
-
* This is equivalent to the mobile implementation using ethereumjs-abi rawEncode.
|
|
12
|
-
*
|
|
13
|
-
* @param type - The transfer type (only 'transfer' supported).
|
|
14
|
-
* @param opts - Options containing toAddress and amount.
|
|
15
|
-
* @param opts.toAddress - The recipient address (20 bytes, with or without 0x prefix).
|
|
16
|
-
* @param opts.amount - The amount as hex string (with or without 0x prefix).
|
|
17
|
-
* @returns Encoded transfer data as hex string with 0x prefix.
|
|
18
|
-
*/
|
|
19
|
-
function generateTransferData(type, opts) {
|
|
20
|
-
// Type guard - this function only supports 'transfer' type
|
|
21
|
-
// The type parameter is kept for API compatibility with mobile's version
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
-
const _type = type;
|
|
24
|
-
// Pad address to 32 bytes (64 hex chars)
|
|
25
|
-
// Remove 0x prefix, lowercase, then left-pad with zeros
|
|
26
|
-
const paddedAddress = (0, utils_1.remove0x)(opts.toAddress)
|
|
27
|
-
.toLowerCase()
|
|
28
|
-
.padStart(64, '0');
|
|
29
|
-
// Pad amount to 32 bytes (64 hex chars)
|
|
30
|
-
// Remove 0x prefix, then left-pad with zeros
|
|
31
|
-
const paddedAmount = (0, utils_1.remove0x)(opts.amount).padStart(64, '0');
|
|
32
|
-
// Combine: selector (4 bytes) + address (32 bytes) + amount (32 bytes)
|
|
33
|
-
return (0, utils_1.add0x)(`${(0, utils_1.remove0x)(TRANSFER_FUNCTION_SELECTOR)}${paddedAddress}${paddedAmount}`);
|
|
34
|
-
}
|
|
35
|
-
exports.generateTransferData = generateTransferData;
|
|
36
|
-
//# sourceMappingURL=transactionUtils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transactionUtils.cjs","sourceRoot":"","sources":["../../src/utils/transactionUtils.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAElD,yFAAyF;AACzF,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,SAAgB,oBAAoB,CAClC,IAAgB,EAChB,IAA2C;IAE3C,2DAA2D;IAC3D,yEAAyE;IACzE,6DAA6D;IAC7D,MAAM,KAAK,GAAe,IAAI,CAAC;IAE/B,yCAAyC;IACzC,wDAAwD;IACxD,MAAM,aAAa,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,SAAS,CAAC;SAC3C,WAAW,EAAE;SACb,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAErB,wCAAwC;IACxC,6CAA6C;IAC7C,MAAM,YAAY,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAE7D,uEAAuE;IACvE,OAAO,IAAA,aAAK,EACV,GAAG,IAAA,gBAAQ,EAAC,0BAA0B,CAAC,GAAG,aAAa,GAAG,YAAY,EAAE,CACzE,CAAC;AACJ,CAAC;AAvBD,oDAuBC","sourcesContent":["import { add0x, remove0x } from '@metamask/utils';\n\n// ERC-20 transfer function selector: keccak256('transfer(address,uint256)').slice(0, 10)\nconst TRANSFER_FUNCTION_SELECTOR = '0xa9059cbb';\n\n/**\n * Generate ERC-20 transfer call data.\n *\n * Encodes the function selector and parameters for an ERC-20 transfer(address,uint256) call.\n * This is equivalent to the mobile implementation using ethereumjs-abi rawEncode.\n *\n * @param type - The transfer type (only 'transfer' supported).\n * @param opts - Options containing toAddress and amount.\n * @param opts.toAddress - The recipient address (20 bytes, with or without 0x prefix).\n * @param opts.amount - The amount as hex string (with or without 0x prefix).\n * @returns Encoded transfer data as hex string with 0x prefix.\n */\nexport function generateTransferData(\n type: 'transfer',\n opts: { toAddress: string; amount: string },\n): string {\n // Type guard - this function only supports 'transfer' type\n // The type parameter is kept for API compatibility with mobile's version\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const _type: 'transfer' = type;\n\n // Pad address to 32 bytes (64 hex chars)\n // Remove 0x prefix, lowercase, then left-pad with zeros\n const paddedAddress = remove0x(opts.toAddress)\n .toLowerCase()\n .padStart(64, '0');\n\n // Pad amount to 32 bytes (64 hex chars)\n // Remove 0x prefix, then left-pad with zeros\n const paddedAmount = remove0x(opts.amount).padStart(64, '0');\n\n // Combine: selector (4 bytes) + address (32 bytes) + amount (32 bytes)\n return add0x(\n `${remove0x(TRANSFER_FUNCTION_SELECTOR)}${paddedAddress}${paddedAmount}`,\n );\n}\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate ERC-20 transfer call data.
|
|
3
|
-
*
|
|
4
|
-
* Encodes the function selector and parameters for an ERC-20 transfer(address,uint256) call.
|
|
5
|
-
* This is equivalent to the mobile implementation using ethereumjs-abi rawEncode.
|
|
6
|
-
*
|
|
7
|
-
* @param type - The transfer type (only 'transfer' supported).
|
|
8
|
-
* @param opts - Options containing toAddress and amount.
|
|
9
|
-
* @param opts.toAddress - The recipient address (20 bytes, with or without 0x prefix).
|
|
10
|
-
* @param opts.amount - The amount as hex string (with or without 0x prefix).
|
|
11
|
-
* @returns Encoded transfer data as hex string with 0x prefix.
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateTransferData(type: 'transfer', opts: {
|
|
14
|
-
toAddress: string;
|
|
15
|
-
amount: string;
|
|
16
|
-
}): string;
|
|
17
|
-
//# sourceMappingURL=transactionUtils.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.cts","sourceRoot":"","sources":["../../src/utils/transactionUtils.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,MAAM,CAoBR"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate ERC-20 transfer call data.
|
|
3
|
-
*
|
|
4
|
-
* Encodes the function selector and parameters for an ERC-20 transfer(address,uint256) call.
|
|
5
|
-
* This is equivalent to the mobile implementation using ethereumjs-abi rawEncode.
|
|
6
|
-
*
|
|
7
|
-
* @param type - The transfer type (only 'transfer' supported).
|
|
8
|
-
* @param opts - Options containing toAddress and amount.
|
|
9
|
-
* @param opts.toAddress - The recipient address (20 bytes, with or without 0x prefix).
|
|
10
|
-
* @param opts.amount - The amount as hex string (with or without 0x prefix).
|
|
11
|
-
* @returns Encoded transfer data as hex string with 0x prefix.
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateTransferData(type: 'transfer', opts: {
|
|
14
|
-
toAddress: string;
|
|
15
|
-
amount: string;
|
|
16
|
-
}): string;
|
|
17
|
-
//# sourceMappingURL=transactionUtils.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.mts","sourceRoot":"","sources":["../../src/utils/transactionUtils.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,MAAM,CAoBR"}
|