@metamask-previews/perps-controller 3.2.0-preview-6ce5d58fa → 4.0.0-preview-1e2fe74a0
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 +29 -1
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +9 -0
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +9 -0
- package/dist/PerpsController-method-action-types.d.mts.map +1 -1
- package/dist/PerpsController-method-action-types.mjs.map +1 -1
- package/dist/PerpsController.cjs +15 -3
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +18 -3
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +18 -3
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +15 -3
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +28 -0
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +3 -0
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +3 -0
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +28 -0
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +16 -6
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +12 -4
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +12 -4
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +16 -6
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +56 -20
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +29 -4
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +29 -4
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +57 -21
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs +131 -60
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts +23 -0
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts +23 -0
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs +132 -61
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +193 -11
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +194 -12
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/MarketDataService.cjs +89 -6
- package/dist/services/MarketDataService.cjs.map +1 -1
- package/dist/services/MarketDataService.d.cts +19 -0
- package/dist/services/MarketDataService.d.cts.map +1 -1
- package/dist/services/MarketDataService.d.mts +19 -0
- package/dist/services/MarketDataService.d.mts.map +1 -1
- package/dist/services/MarketDataService.mjs +89 -6
- package/dist/services/MarketDataService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +21 -3
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +21 -3
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/accountUtils.cjs +74 -1
- package/dist/utils/accountUtils.cjs.map +1 -1
- package/dist/utils/accountUtils.d.cts +4 -0
- package/dist/utils/accountUtils.d.cts.map +1 -1
- package/dist/utils/accountUtils.d.mts +4 -0
- package/dist/utils/accountUtils.d.mts.map +1 -1
- package/dist/utils/accountUtils.mjs +70 -0
- package/dist/utils/accountUtils.mjs.map +1 -1
- package/dist/utils/coalescePerpsRestRequest.cjs +71 -0
- package/dist/utils/coalescePerpsRestRequest.cjs.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.d.cts +32 -0
- package/dist/utils/coalescePerpsRestRequest.d.cts.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.d.mts +32 -0
- package/dist/utils/coalescePerpsRestRequest.d.mts.map +1 -0
- package/dist/utils/coalescePerpsRestRequest.mjs +66 -0
- package/dist/utils/coalescePerpsRestRequest.mjs.map +1 -0
- package/dist/utils/hyperLiquidAdapter.cjs +7 -7
- package/dist/utils/hyperLiquidAdapter.cjs.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +2 -2
- package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +2 -2
- package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -1
- package/dist/utils/hyperLiquidAdapter.mjs +7 -7
- package/dist/utils/hyperLiquidAdapter.mjs.map +1 -1
- package/dist/utils/perpsFormatters.cjs +5 -1
- package/dist/utils/perpsFormatters.cjs.map +1 -1
- package/dist/utils/perpsFormatters.d.cts.map +1 -1
- package/dist/utils/perpsFormatters.d.mts.map +1 -1
- package/dist/utils/perpsFormatters.mjs +5 -1
- package/dist/utils/perpsFormatters.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -118,6 +118,34 @@ exports.PERFORMANCE_CONFIG = {
|
|
|
118
118
|
// Candle subscription debounce delay (milliseconds)
|
|
119
119
|
// Prevents WS subscription churn during rapid market switching (#28141)
|
|
120
120
|
CandleConnectDebounceMs: 500,
|
|
121
|
+
// Candle WS teardown delay (milliseconds)
|
|
122
|
+
// When the last subscriber for a cacheKey unsubscribes, wait this long before
|
|
123
|
+
// tearing down the WS. A subsequent subscribe inside the window cancels the
|
|
124
|
+
// teardown so rapid back-and-forth switches do not churn the connection.
|
|
125
|
+
CandleTeardownDelayMs: 150,
|
|
126
|
+
// Perps REST coalesce TTL (milliseconds)
|
|
127
|
+
//
|
|
128
|
+
// Window in which identical GET-style REST calls (getOrderFills, getOrders,
|
|
129
|
+
// getFunding, historicalOrders) share a single in-flight promise / cached
|
|
130
|
+
// result. `forceRefresh` still bypasses the cache end-to-end (hooks →
|
|
131
|
+
// controller → MarketDataService → provider → HyperLiquidClientService), so
|
|
132
|
+
// pull-to-refresh always hits the network.
|
|
133
|
+
//
|
|
134
|
+
// Why 60 s: HyperLiquid's documented rate limit is 1200 weight / IP /
|
|
135
|
+
// rolling 60 s window. Sizing TTL = window length caps each endpoint-per-
|
|
136
|
+
// account at ≤1 REST hit per window under any UI activity pattern — rapid
|
|
137
|
+
// market switching, re-mounts (usePerpsMarketFills, usePerpsTransactionHistory),
|
|
138
|
+
// and multi-tab scans all share a single request. Live fills/orders/prices
|
|
139
|
+
// still flow via WS subscriptions, so REST is seed/backfill only — cache
|
|
140
|
+
// staleness inside the 60 s window is never user-visible.
|
|
141
|
+
PerpsRestCoalesceTtlMs: 60000,
|
|
142
|
+
// Candle snapshot REST coalesce TTL (milliseconds).
|
|
143
|
+
// Longer than PerpsRestCoalesceTtlMs because WS stream keeps live candles
|
|
144
|
+
// fresh — the REST snapshot only seeds the chart on initial subscribe. A
|
|
145
|
+
// 30 s window lets rapid market switching (pass 1 → pass 2 of a stress
|
|
146
|
+
// loop) share the same snapshot per (symbol, interval), cutting
|
|
147
|
+
// candleSnapshot REST weight roughly in half.
|
|
148
|
+
PerpsCandleCoalesceTtlMs: 30000,
|
|
121
149
|
// Navigation params delay (milliseconds)
|
|
122
150
|
// Required for React Navigation to complete state transitions before setting params
|
|
123
151
|
// This ensures navigation context is available when programmatically selecting tabs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpsConfig.c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;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAC,KAGrC;IACC,OAAO,GAAG,KAAK,CAAC,cAAc,IAAI,uBAAe,CAAC,eAAe,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACjH,CAAC;AALD,sDAKC;AAED;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,UAAkB,EAClB,SAAkB;IAElB,MAAM,gBAAgB,GACpB,UAAU,KAAK,KAAK;QAClB,CAAC,CAAC,uBAAe,CAAC,gBAAgB,IAAI,SAAS;QAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,GAAG,UAAU,IAAI,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACrE,CAAC;AATD,sDASC","sourcesContent":["/**\n * Perps feature constants - Controller layer (portable)\n *\n * This file contains only controller-portable configuration:\n * - Constants used by controller logic, providers, and services\n * - Calculation thresholds, API configs, and protocol constants\n *\n * UI-only constants (layout, display, navigation) live in:\n * app/components/UI/Perps/constants/perpsConfig.ts\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\nexport const ZERO_BALANCE = '0x0';\n\nexport const PERPS_CONSTANTS = {\n FeatureFlagKey: 'perpsEnabled',\n FeatureName: 'perps', // Constant for Sentry error filtering - enables \"feature:perps\" dashboard queries\n /** Token description used to identify the synthetic \"Perps balance\" option in pay-with token lists */\n PerpsBalanceTokenDescription: 'perps-balance',\n /** Symbol displayed for the synthetic \"Perps balance\" token in pay-with token lists */\n PerpsBalanceTokenSymbol: 'USD',\n WebsocketTimeout: 5000, // 5 seconds\n WebsocketCleanupDelay: 1000, // 1 second\n BackgroundDisconnectDelay: 20_000, // 20 seconds delay before disconnecting when app is backgrounded or when user exits perps UX\n ConnectionTimeoutMs: 10_000, // 10 seconds timeout for connection and position loading states\n DefaultMonitoringTimeoutMs: 10_000, // 10 seconds default timeout for data monitoring operations\n\n // Connection timing constants\n ConnectionGracePeriodMs: 20_000, // 20 seconds grace period before actual disconnection (same as BackgroundDisconnectDelay for semantic clarity)\n ConnectionAttemptTimeoutMs: 30_000, // 30 seconds timeout for connection attempts to prevent indefinite hanging\n WebsocketPingTimeoutMs: 5_000, // 5 seconds timeout for WebSocket health check ping\n ConnectRetryDelayMs: 200, // Delay before retrying connect() when connection isn't ready yet\n ForegroundPingRetryDelayMs: 500, // Delay before retrying ping in resumeFromForeground — JS thread may be sluggish right after foregrounding\n ReconnectionCleanupDelayMs: 500, // Platform-agnostic delay to ensure WebSocket is ready\n ReconnectionDelayAndroidMs: 300, // Android-specific reconnection delay for better reliability on slower devices\n ReconnectionDelayIosMs: 100, // iOS-specific reconnection delay for optimal performance\n ReconnectionRetryDelayMs: 5_000, // 5 seconds delay between reconnection attempts\n NetworkRestoreMaxRetries: 8, // Max retry attempts when reconnecting after WiFi/network restore\n NetworkRestoreRetryBaseMs: 1_500, // Base delay (ms) between network restore retries (multiplied by attempt number)\n\n // Connection manager timing constants\n BalanceUpdateThrottleMs: 15000, // Update at most every 15 seconds to reduce state updates in PerpsConnectionManager\n InitialDataDelayMs: 100, // Delay to allow initial data to load after connection establishment\n\n // Deposit toast timing\n DepositTakingLongerToastDelayMs: 30_000, // Delay before showing \"Deposit taking longer than usual\" toast\n\n DefaultAssetPreviewLimit: 5,\n DefaultMaxLeverage: 3 as number, // Default fallback max leverage when market data is unavailable - conservative default\n FallbackPriceDisplay: '$---', // Display when price data is unavailable\n FallbackPercentageDisplay: '--%', // Display when change data is unavailable\n FallbackDataDisplay: '--', // Display when non-price data is unavailable\n ZeroAmountDisplay: '$0', // Display for zero dollar amounts (e.g., no volume)\n ZeroAmountDetailedDisplay: '$0.00', // Display for zero dollar amounts with decimals\n\n RecentActivityLimit: 3,\n\n // Historical data fetching constants\n FillsLookbackMs: 90 * 24 * 60 * 60 * 1000, // 3 months in milliseconds - limits REST API fills fetch\n} as const;\n\n/**\n * Withdrawal-specific constants (protocol-agnostic)\n * Note: Protocol-specific values like estimated time should be defined in each protocol's config\n */\nexport const WITHDRAWAL_CONSTANTS = {\n DefaultMinAmount: '1.01', // Default minimum withdrawal amount in USDC\n DefaultFeeAmount: 1, // Default withdrawal fee in USDC\n DefaultFeeToken: 'USDC', // Default fee token\n} as const;\n\n/**\n * Validation thresholds for UI warnings and checks\n * These values control when warnings are shown to users\n */\nexport const VALIDATION_THRESHOLDS = {\n // Leverage threshold for warning users about high leverage\n HighLeverageWarning: 20, // Show warning when leverage > 20x\n\n // Limit price difference threshold (as decimal, 0.1 = 10%)\n LimitPriceDifferenceWarning: 0.1, // Warn if limit price differs by >10% from current price\n\n // Price deviation threshold (as decimal, 0.1 = 10%)\n PriceDeviation: 0.1, // Warn if perps price deviates by >10% from spot price\n} as const;\n\n/**\n * Order slippage configuration\n * Controls default slippage tolerance for different order types\n * Conservative defaults based on HyperLiquid platform interface\n * See: docs/perps/hyperliquid/ORDER-MATCHING-ERRORS.md\n */\nexport const ORDER_SLIPPAGE_CONFIG = {\n // Market order slippage (basis points)\n // 300 basis points = 3% = 0.03 decimal\n // Conservative default for measured rollout, prevents most IOC failures\n DefaultMarketSlippageBps: 300,\n\n // TP/SL order slippage (basis points)\n // 1000 basis points = 10% = 0.10 decimal\n // Aligns with HyperLiquid platform default for triggered orders\n DefaultTpslSlippageBps: 1000,\n\n // Limit order slippage (basis points)\n // 100 basis points = 1% = 0.01 decimal\n // Kept conservative as limit orders rest on book (not IOC/immediate execution)\n DefaultLimitSlippageBps: 100,\n} as const;\n\n/**\n * Max order amount buffer to reduce \"Insufficient margin\" rejections from the exchange.\n * When the user selects 100% (slider or Max), we cap the order at (1 - this) of the\n * theoretical max so that fees, rounding, and exchange-side margin checks are covered.\n * Value as decimal (e.g. 0.005 = 0.5%).\n */\nexport const MAX_ORDER_MARGIN_BUFFER = 0.005; // 0.5%\n\n/**\n * Performance optimization constants\n * These values control debouncing and throttling for better performance\n */\nexport const PERFORMANCE_CONFIG = {\n // Price updates debounce delay (milliseconds)\n // Batches rapid WebSocket price updates to reduce re-renders\n PriceUpdateDebounceMs: 1000,\n\n // Order validation debounce delay (milliseconds)\n // Prevents excessive validation calls during rapid form input changes\n ValidationDebounceMs: 300,\n\n // Liquidation price debounce delay (milliseconds)\n // Prevents excessive liquidation price calls during rapid form input changes\n LiquidationPriceDebounceMs: 500,\n\n // Candle subscription debounce delay (milliseconds)\n // Prevents WS subscription churn during rapid market switching (#28141)\n CandleConnectDebounceMs: 500,\n\n // Navigation params delay (milliseconds)\n // Required for React Navigation to complete state transitions before setting params\n // This ensures navigation context is available when programmatically selecting tabs\n NavigationParamsDelayMs: 200,\n\n // Tab control reset delay (milliseconds)\n // Delay to reset programmatic tab control after tab switching to prevent render loops\n TabControlResetDelayMs: 500,\n\n // Market data cache duration (milliseconds)\n // How long to cache market list data before fetching fresh data\n MarketDataCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n // Asset metadata cache duration (milliseconds)\n // How long to cache asset icon validation results\n AssetMetadataCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Max leverage cache duration (milliseconds)\n // How long to cache max leverage values per asset (leverage rarely changes)\n MaxLeverageCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Rewards cache durations (milliseconds)\n // How long to cache fee discount data from rewards API\n FeeDiscountCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n // How long to cache points calculation parameters from rewards API\n PointsCalculationCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n /**\n * Performance logging markers for filtering logs during development and debugging\n * These markers help isolate performance-related logs from general application logs\n * Usage: Use in DevLogger calls to easily filter specific performance areas\n * Impact: Development only (uses DevLogger) - zero production performance cost\n *\n * Examples:\n * - Filter Sentry performance logs: `adb logcat | grep PERPSMARK_SENTRY`\n * - Filter MetaMetrics events: `adb logcat | grep PERPSMARK_METRICS`\n * - Filter WebSocket performance: `adb logcat | grep PERPSMARK_WS`\n * - Filter all Perps performance: `adb logcat | grep PERPSMARK_`\n */\n LoggingMarkers: {\n // Sentry performance measurement logs (screen loads, bottom sheets, API timing)\n SentryPerformance: 'PERPSMARK_SENTRY',\n\n // MetaMetrics event tracking logs (user interactions, business analytics)\n MetametricsEvents: 'PERPSMARK_METRICS',\n\n // WebSocket performance logs (connection timing, data flow, reconnections)\n WebsocketPerformance: 'PERPSMARK_SENTRY_WS',\n } as const,\n} as const;\n\nexport const TP_SL_CONFIG = {\n UsePositionBoundTpsl: true,\n} as const;\n\n/**\n * HyperLiquid order limits based on leverage\n * From: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/contract-specifications\n */\nexport const HYPERLIQUID_ORDER_LIMITS = {\n // Market orders\n MarketOrderLimits: {\n // $15,000,000 for max leverage >= 25\n HighLeverage: 15_000_000,\n // $5,000,000 for max leverage in [20, 25)\n MediumHighLeverage: 5_000_000,\n // $2,000,000 for max leverage in [10, 20)\n MediumLeverage: 2_000_000,\n // $500,000 for max leverage < 10\n LowLeverage: 500_000,\n },\n // Limit orders are 10x market order limits\n LimitOrderMultiplier: 10,\n} as const;\n\n/**\n * Close position configuration\n * Controls behavior and constants specific to position closing\n */\nexport const CLOSE_POSITION_CONFIG = {\n // Decimal places for USD amount input display\n UsdDecimalPlaces: 2,\n\n // Default close percentage when opening the close position view\n DefaultClosePercentage: 100,\n\n // Precision for position size calculations to prevent rounding errors\n AmountCalculationPrecision: 6,\n\n // Throttle delay for real-time price updates during position closing\n PriceThrottleMs: 3000,\n\n // Fallback decimal places for tokens without metadata\n FallbackTokenDecimals: 18,\n} as const;\n\n/**\n * Margin adjustment configuration\n * Controls behavior for adding/removing margin from positions\n */\nexport const MARGIN_ADJUSTMENT_CONFIG = {\n // Risk thresholds for margin removal warnings\n // Threshold values represent ratio of (price distance to liquidation) / (liquidation price)\n // Values < 1.0 mean price is dangerously close to liquidation\n LiquidationRiskThreshold: 1.2, // 20% buffer before liquidation - triggers danger state\n LiquidationWarningThreshold: 1.5, // 50% buffer before liquidation - triggers warning state\n\n // Minimum margin adjustment amount (USD)\n // Prevents dust adjustments and ensures meaningful position changes\n MinAdjustmentAmount: 1,\n\n // Precision for margin calculations\n // Ensures accurate decimal handling in margin/leverage calculations\n CalculationPrecision: 6,\n\n // Safety buffer for margin removal to account for HyperLiquid's transfer margin requirement\n // HyperLiquid enforces: transfer_margin_required = max(initial_margin_required, 0.1 * total_position_value)\n // See: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/margin-and-pnl\n MarginRemovalSafetyBuffer: 0.1,\n\n // Fallback max leverage when market data is unavailable\n // Conservative value to prevent over-removal of margin\n // Most HyperLiquid assets support at least 50x leverage\n FallbackMaxLeverage: 50,\n} as const;\n\n/**\n * Data Lake API configuration\n * Endpoints for reporting perps trading activity for notifications\n */\nexport const DATA_LAKE_API_CONFIG = {\n // Order reporting endpoint - only used for mainnet perps trading\n OrdersEndpoint: 'https://perps.api.cx.metamask.io/api/v1/orders',\n} as const;\n\n/**\n * Decimal precision configuration\n * Controls maximum decimal places for price and input validation\n */\nexport const DECIMAL_PRECISION_CONFIG = {\n // Maximum decimal places for price input (matches Hyperliquid limit)\n // Used in TP/SL forms, limit price inputs, and price validation\n MaxPriceDecimals: 6,\n // Maximum significant figures allowed by HyperLiquid API\n // Orders with more than 5 significant figures will be rejected\n MaxSignificantFigures: 5,\n // Defensive fallback for size decimals when market data fails to load\n // Real szDecimals should always come from market data API (varies by asset)\n // Using 6 as safe maximum to prevent crashes (covers most assets)\n // NOTE: This is NOT semantically correct - just a defensive measure\n FallbackSizeDecimals: 6,\n} as const;\n\n/**\n * Market sorting configuration\n * Controls sorting behavior and presets for the trending markets view\n */\nexport const MARKET_SORTING_CONFIG = {\n // Default sort settings\n DefaultSortOptionId: 'volume' as const,\n DefaultDirection: 'desc' as const,\n\n // Available sort fields (only includes fields supported by PerpsMarketData)\n SortFields: {\n Volume: 'volume',\n PriceChange: 'priceChange',\n OpenInterest: 'openInterest',\n FundingRate: 'fundingRate',\n } as const,\n\n // Sort button presets for filter chips (simplified buttons without direction)\n SortButtonPresets: [\n { field: 'volume', labelKey: 'perps.sort.volume' },\n { field: 'priceChange', labelKey: 'perps.sort.price_change' },\n { field: 'fundingRate', labelKey: 'perps.sort.funding_rate' },\n ] as const,\n\n // Sort options for the bottom sheet\n // All options support direction toggle (high-to-low / low-to-high)\n SortOptions: [\n {\n id: 'volume',\n labelKey: 'perps.sort.volume',\n field: 'volume',\n direction: 'desc',\n },\n {\n id: 'priceChange',\n labelKey: 'perps.sort.price_change',\n field: 'priceChange',\n direction: 'desc',\n },\n {\n id: 'openInterest',\n labelKey: 'perps.sort.open_interest',\n field: 'openInterest',\n direction: 'desc',\n },\n {\n id: 'fundingRate',\n labelKey: 'perps.sort.funding_rate',\n field: 'fundingRate',\n direction: 'desc',\n },\n ] as const,\n} as const;\n\n/**\n * Type for valid sort option IDs\n * Derived from SORT_OPTIONS to ensure type safety\n * Valid values: 'volume' | 'priceChange' | 'openInterest' | 'fundingRate'\n */\nexport type SortOptionId =\n (typeof MARKET_SORTING_CONFIG.SortOptions)[number]['id'];\n\n/**\n * Funding rate display configuration\n * Controls how funding rates are formatted and displayed\n */\nexport const FUNDING_RATE_CONFIG = {\n // Number of decimal places to display for funding rates\n Decimals: 4,\n // Default display value when funding rate is zero or unavailable\n ZeroDisplay: '0.0000%',\n // Multiplier to convert decimal funding rate to percentage\n PercentageMultiplier: 100,\n} as const;\n\n/**\n * Provider configuration for multi-provider support\n */\nexport const PROVIDER_CONFIG = {\n /** Default perpetual DEX provider when no explicit selection exists */\n DefaultProvider: 'hyperliquid' as const,\n /** Force MYX to testnet only (mainnet credentials not yet available) */\n MYX_TESTNET_ONLY: false,\n} as const;\n\n// Disk-backed cold-start cache keys and throttle interval\nexport const PERPS_DISK_CACHE_MARKETS = 'PERPS_DISK_CACHE_MARKETS';\nexport const PERPS_DISK_CACHE_USER_DATA = 'PERPS_DISK_CACHE_USER_DATA';\nexport const PERPS_DISK_CACHE_THROTTLE_MS = 30_000;\n\n/**\n * Build the standard provider:network cache key from controller state.\n *\n * @param state - Controller state containing provider and network info.\n * @param state.activeProvider - Active perps provider name.\n * @param state.isTestnet - Whether testnet mode is active.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function getProviderNetworkKey(state: {\n activeProvider?: string;\n isTestnet?: boolean;\n}): string {\n return `${state.activeProvider ?? PROVIDER_CONFIG.DefaultProvider}:${state.isTestnet ? 'testnet' : 'mainnet'}`;\n}\n\n/**\n * Build a provider:network cache key for a specific provider id.\n * Accounts for MYX_TESTNET_ONLY: MYX is always on testnet regardless of the\n * global network flag.\n *\n * @param providerId - The provider identifier (e.g. \"hyperliquid\", \"myx\").\n * @param isTestnet - Global testnet flag from controller state.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function buildProviderCacheKey(\n providerId: string,\n isTestnet: boolean,\n): string {\n const effectiveTestnet =\n providerId === 'myx'\n ? PROVIDER_CONFIG.MYX_TESTNET_ONLY || isTestnet\n : isTestnet;\n return `${providerId}:${effectiveTestnet ? 'testnet' : 'mainnet'}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"perpsConfig.cjs","sourceRoot":"","sources":["../../src/constants/perpsConfig.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG,4CAA4C,CAAC;AAC5D,QAAA,YAAY,GAAG,KAAK,CAAC;AAErB,QAAA,eAAe,GAAG;IAC7B,cAAc,EAAE,cAAc;IAC9B,WAAW,EAAE,OAAO,EAAE,kFAAkF;IACxG,sGAAsG;IACtG,4BAA4B,EAAE,eAAe;IAC7C,uFAAuF;IACvF,uBAAuB,EAAE,KAAK;IAC9B,gBAAgB,EAAE,IAAI,EAAE,YAAY;IACpC,qBAAqB,EAAE,IAAI,EAAE,WAAW;IACxC,yBAAyB,EAAE,KAAM,EAAE,6FAA6F;IAChI,mBAAmB,EAAE,KAAM,EAAE,gEAAgE;IAC7F,0BAA0B,EAAE,KAAM,EAAE,4DAA4D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AAC,cAAc,IAAI,uBAAe,CAAC,eAAe,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACjH,CAAC;AALD,sDAKC;AAED;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,UAAkB,EAClB,SAAkB;IAElB,MAAM,gBAAgB,GACpB,UAAU,KAAK,KAAK;QAClB,CAAC,CAAC,uBAAe,CAAC,gBAAgB,IAAI,SAAS;QAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,GAAG,UAAU,IAAI,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACrE,CAAC;AATD,sDASC","sourcesContent":["/**\n * Perps feature constants - Controller layer (portable)\n *\n * This file contains only controller-portable configuration:\n * - Constants used by controller logic, providers, and services\n * - Calculation thresholds, API configs, and protocol constants\n *\n * UI-only constants (layout, display, navigation) live in:\n * app/components/UI/Perps/constants/perpsConfig.ts\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\nexport const ZERO_BALANCE = '0x0';\n\nexport const PERPS_CONSTANTS = {\n FeatureFlagKey: 'perpsEnabled',\n FeatureName: 'perps', // Constant for Sentry error filtering - enables \"feature:perps\" dashboard queries\n /** Token description used to identify the synthetic \"Perps balance\" option in pay-with token lists */\n PerpsBalanceTokenDescription: 'perps-balance',\n /** Symbol displayed for the synthetic \"Perps balance\" token in pay-with token lists */\n PerpsBalanceTokenSymbol: 'USD',\n WebsocketTimeout: 5000, // 5 seconds\n WebsocketCleanupDelay: 1000, // 1 second\n BackgroundDisconnectDelay: 20_000, // 20 seconds delay before disconnecting when app is backgrounded or when user exits perps UX\n ConnectionTimeoutMs: 10_000, // 10 seconds timeout for connection and position loading states\n DefaultMonitoringTimeoutMs: 10_000, // 10 seconds default timeout for data monitoring operations\n\n // Connection timing constants\n ConnectionGracePeriodMs: 20_000, // 20 seconds grace period before actual disconnection (same as BackgroundDisconnectDelay for semantic clarity)\n ConnectionAttemptTimeoutMs: 30_000, // 30 seconds timeout for connection attempts to prevent indefinite hanging\n WebsocketPingTimeoutMs: 5_000, // 5 seconds timeout for WebSocket health check ping\n ConnectRetryDelayMs: 200, // Delay before retrying connect() when connection isn't ready yet\n ForegroundPingRetryDelayMs: 500, // Delay before retrying ping in resumeFromForeground — JS thread may be sluggish right after foregrounding\n ReconnectionCleanupDelayMs: 500, // Platform-agnostic delay to ensure WebSocket is ready\n ReconnectionDelayAndroidMs: 300, // Android-specific reconnection delay for better reliability on slower devices\n ReconnectionDelayIosMs: 100, // iOS-specific reconnection delay for optimal performance\n ReconnectionRetryDelayMs: 5_000, // 5 seconds delay between reconnection attempts\n NetworkRestoreMaxRetries: 8, // Max retry attempts when reconnecting after WiFi/network restore\n NetworkRestoreRetryBaseMs: 1_500, // Base delay (ms) between network restore retries (multiplied by attempt number)\n\n // Connection manager timing constants\n BalanceUpdateThrottleMs: 15000, // Update at most every 15 seconds to reduce state updates in PerpsConnectionManager\n InitialDataDelayMs: 100, // Delay to allow initial data to load after connection establishment\n\n // Deposit toast timing\n DepositTakingLongerToastDelayMs: 30_000, // Delay before showing \"Deposit taking longer than usual\" toast\n\n DefaultAssetPreviewLimit: 5,\n DefaultMaxLeverage: 3 as number, // Default fallback max leverage when market data is unavailable - conservative default\n FallbackPriceDisplay: '$---', // Display when price data is unavailable\n FallbackPercentageDisplay: '--%', // Display when change data is unavailable\n FallbackDataDisplay: '--', // Display when non-price data is unavailable\n ZeroAmountDisplay: '$0', // Display for zero dollar amounts (e.g., no volume)\n ZeroAmountDetailedDisplay: '$0.00', // Display for zero dollar amounts with decimals\n\n RecentActivityLimit: 3,\n\n // Historical data fetching constants\n FillsLookbackMs: 90 * 24 * 60 * 60 * 1000, // 3 months in milliseconds - limits REST API fills fetch\n} as const;\n\n/**\n * Withdrawal-specific constants (protocol-agnostic)\n * Note: Protocol-specific values like estimated time should be defined in each protocol's config\n */\nexport const WITHDRAWAL_CONSTANTS = {\n DefaultMinAmount: '1.01', // Default minimum withdrawal amount in USDC\n DefaultFeeAmount: 1, // Default withdrawal fee in USDC\n DefaultFeeToken: 'USDC', // Default fee token\n} as const;\n\n/**\n * Validation thresholds for UI warnings and checks\n * These values control when warnings are shown to users\n */\nexport const VALIDATION_THRESHOLDS = {\n // Leverage threshold for warning users about high leverage\n HighLeverageWarning: 20, // Show warning when leverage > 20x\n\n // Limit price difference threshold (as decimal, 0.1 = 10%)\n LimitPriceDifferenceWarning: 0.1, // Warn if limit price differs by >10% from current price\n\n // Price deviation threshold (as decimal, 0.1 = 10%)\n PriceDeviation: 0.1, // Warn if perps price deviates by >10% from spot price\n} as const;\n\n/**\n * Order slippage configuration\n * Controls default slippage tolerance for different order types\n * Conservative defaults based on HyperLiquid platform interface\n * See: docs/perps/hyperliquid/ORDER-MATCHING-ERRORS.md\n */\nexport const ORDER_SLIPPAGE_CONFIG = {\n // Market order slippage (basis points)\n // 300 basis points = 3% = 0.03 decimal\n // Conservative default for measured rollout, prevents most IOC failures\n DefaultMarketSlippageBps: 300,\n\n // TP/SL order slippage (basis points)\n // 1000 basis points = 10% = 0.10 decimal\n // Aligns with HyperLiquid platform default for triggered orders\n DefaultTpslSlippageBps: 1000,\n\n // Limit order slippage (basis points)\n // 100 basis points = 1% = 0.01 decimal\n // Kept conservative as limit orders rest on book (not IOC/immediate execution)\n DefaultLimitSlippageBps: 100,\n} as const;\n\n/**\n * Max order amount buffer to reduce \"Insufficient margin\" rejections from the exchange.\n * When the user selects 100% (slider or Max), we cap the order at (1 - this) of the\n * theoretical max so that fees, rounding, and exchange-side margin checks are covered.\n * Value as decimal (e.g. 0.005 = 0.5%).\n */\nexport const MAX_ORDER_MARGIN_BUFFER = 0.005; // 0.5%\n\n/**\n * Performance optimization constants\n * These values control debouncing and throttling for better performance\n */\nexport const PERFORMANCE_CONFIG = {\n // Price updates debounce delay (milliseconds)\n // Batches rapid WebSocket price updates to reduce re-renders\n PriceUpdateDebounceMs: 1000,\n\n // Order validation debounce delay (milliseconds)\n // Prevents excessive validation calls during rapid form input changes\n ValidationDebounceMs: 300,\n\n // Liquidation price debounce delay (milliseconds)\n // Prevents excessive liquidation price calls during rapid form input changes\n LiquidationPriceDebounceMs: 500,\n\n // Candle subscription debounce delay (milliseconds)\n // Prevents WS subscription churn during rapid market switching (#28141)\n CandleConnectDebounceMs: 500,\n\n // Candle WS teardown delay (milliseconds)\n // When the last subscriber for a cacheKey unsubscribes, wait this long before\n // tearing down the WS. A subsequent subscribe inside the window cancels the\n // teardown so rapid back-and-forth switches do not churn the connection.\n CandleTeardownDelayMs: 150,\n\n // Perps REST coalesce TTL (milliseconds)\n //\n // Window in which identical GET-style REST calls (getOrderFills, getOrders,\n // getFunding, historicalOrders) share a single in-flight promise / cached\n // result. `forceRefresh` still bypasses the cache end-to-end (hooks →\n // controller → MarketDataService → provider → HyperLiquidClientService), so\n // pull-to-refresh always hits the network.\n //\n // Why 60 s: HyperLiquid's documented rate limit is 1200 weight / IP /\n // rolling 60 s window. Sizing TTL = window length caps each endpoint-per-\n // account at ≤1 REST hit per window under any UI activity pattern — rapid\n // market switching, re-mounts (usePerpsMarketFills, usePerpsTransactionHistory),\n // and multi-tab scans all share a single request. Live fills/orders/prices\n // still flow via WS subscriptions, so REST is seed/backfill only — cache\n // staleness inside the 60 s window is never user-visible.\n PerpsRestCoalesceTtlMs: 60_000,\n\n // Candle snapshot REST coalesce TTL (milliseconds).\n // Longer than PerpsRestCoalesceTtlMs because WS stream keeps live candles\n // fresh — the REST snapshot only seeds the chart on initial subscribe. A\n // 30 s window lets rapid market switching (pass 1 → pass 2 of a stress\n // loop) share the same snapshot per (symbol, interval), cutting\n // candleSnapshot REST weight roughly in half.\n PerpsCandleCoalesceTtlMs: 30_000,\n\n // Navigation params delay (milliseconds)\n // Required for React Navigation to complete state transitions before setting params\n // This ensures navigation context is available when programmatically selecting tabs\n NavigationParamsDelayMs: 200,\n\n // Tab control reset delay (milliseconds)\n // Delay to reset programmatic tab control after tab switching to prevent render loops\n TabControlResetDelayMs: 500,\n\n // Market data cache duration (milliseconds)\n // How long to cache market list data before fetching fresh data\n MarketDataCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n // Asset metadata cache duration (milliseconds)\n // How long to cache asset icon validation results\n AssetMetadataCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Max leverage cache duration (milliseconds)\n // How long to cache max leverage values per asset (leverage rarely changes)\n MaxLeverageCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Rewards cache durations (milliseconds)\n // How long to cache fee discount data from rewards API\n FeeDiscountCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n // How long to cache points calculation parameters from rewards API\n PointsCalculationCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n /**\n * Performance logging markers for filtering logs during development and debugging\n * These markers help isolate performance-related logs from general application logs\n * Usage: Use in DevLogger calls to easily filter specific performance areas\n * Impact: Development only (uses DevLogger) - zero production performance cost\n *\n * Examples:\n * - Filter Sentry performance logs: `adb logcat | grep PERPSMARK_SENTRY`\n * - Filter MetaMetrics events: `adb logcat | grep PERPSMARK_METRICS`\n * - Filter WebSocket performance: `adb logcat | grep PERPSMARK_WS`\n * - Filter all Perps performance: `adb logcat | grep PERPSMARK_`\n */\n LoggingMarkers: {\n // Sentry performance measurement logs (screen loads, bottom sheets, API timing)\n SentryPerformance: 'PERPSMARK_SENTRY',\n\n // MetaMetrics event tracking logs (user interactions, business analytics)\n MetametricsEvents: 'PERPSMARK_METRICS',\n\n // WebSocket performance logs (connection timing, data flow, reconnections)\n WebsocketPerformance: 'PERPSMARK_SENTRY_WS',\n } as const,\n} as const;\n\nexport const TP_SL_CONFIG = {\n UsePositionBoundTpsl: true,\n} as const;\n\n/**\n * HyperLiquid order limits based on leverage\n * From: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/contract-specifications\n */\nexport const HYPERLIQUID_ORDER_LIMITS = {\n // Market orders\n MarketOrderLimits: {\n // $15,000,000 for max leverage >= 25\n HighLeverage: 15_000_000,\n // $5,000,000 for max leverage in [20, 25)\n MediumHighLeverage: 5_000_000,\n // $2,000,000 for max leverage in [10, 20)\n MediumLeverage: 2_000_000,\n // $500,000 for max leverage < 10\n LowLeverage: 500_000,\n },\n // Limit orders are 10x market order limits\n LimitOrderMultiplier: 10,\n} as const;\n\n/**\n * Close position configuration\n * Controls behavior and constants specific to position closing\n */\nexport const CLOSE_POSITION_CONFIG = {\n // Decimal places for USD amount input display\n UsdDecimalPlaces: 2,\n\n // Default close percentage when opening the close position view\n DefaultClosePercentage: 100,\n\n // Precision for position size calculations to prevent rounding errors\n AmountCalculationPrecision: 6,\n\n // Throttle delay for real-time price updates during position closing\n PriceThrottleMs: 3000,\n\n // Fallback decimal places for tokens without metadata\n FallbackTokenDecimals: 18,\n} as const;\n\n/**\n * Margin adjustment configuration\n * Controls behavior for adding/removing margin from positions\n */\nexport const MARGIN_ADJUSTMENT_CONFIG = {\n // Risk thresholds for margin removal warnings\n // Threshold values represent ratio of (price distance to liquidation) / (liquidation price)\n // Values < 1.0 mean price is dangerously close to liquidation\n LiquidationRiskThreshold: 1.2, // 20% buffer before liquidation - triggers danger state\n LiquidationWarningThreshold: 1.5, // 50% buffer before liquidation - triggers warning state\n\n // Minimum margin adjustment amount (USD)\n // Prevents dust adjustments and ensures meaningful position changes\n MinAdjustmentAmount: 1,\n\n // Precision for margin calculations\n // Ensures accurate decimal handling in margin/leverage calculations\n CalculationPrecision: 6,\n\n // Safety buffer for margin removal to account for HyperLiquid's transfer margin requirement\n // HyperLiquid enforces: transfer_margin_required = max(initial_margin_required, 0.1 * total_position_value)\n // See: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/margin-and-pnl\n MarginRemovalSafetyBuffer: 0.1,\n\n // Fallback max leverage when market data is unavailable\n // Conservative value to prevent over-removal of margin\n // Most HyperLiquid assets support at least 50x leverage\n FallbackMaxLeverage: 50,\n} as const;\n\n/**\n * Data Lake API configuration\n * Endpoints for reporting perps trading activity for notifications\n */\nexport const DATA_LAKE_API_CONFIG = {\n // Order reporting endpoint - only used for mainnet perps trading\n OrdersEndpoint: 'https://perps.api.cx.metamask.io/api/v1/orders',\n} as const;\n\n/**\n * Decimal precision configuration\n * Controls maximum decimal places for price and input validation\n */\nexport const DECIMAL_PRECISION_CONFIG = {\n // Maximum decimal places for price input (matches Hyperliquid limit)\n // Used in TP/SL forms, limit price inputs, and price validation\n MaxPriceDecimals: 6,\n // Maximum significant figures allowed by HyperLiquid API\n // Orders with more than 5 significant figures will be rejected\n MaxSignificantFigures: 5,\n // Defensive fallback for size decimals when market data fails to load\n // Real szDecimals should always come from market data API (varies by asset)\n // Using 6 as safe maximum to prevent crashes (covers most assets)\n // NOTE: This is NOT semantically correct - just a defensive measure\n FallbackSizeDecimals: 6,\n} as const;\n\n/**\n * Market sorting configuration\n * Controls sorting behavior and presets for the trending markets view\n */\nexport const MARKET_SORTING_CONFIG = {\n // Default sort settings\n DefaultSortOptionId: 'volume' as const,\n DefaultDirection: 'desc' as const,\n\n // Available sort fields (only includes fields supported by PerpsMarketData)\n SortFields: {\n Volume: 'volume',\n PriceChange: 'priceChange',\n OpenInterest: 'openInterest',\n FundingRate: 'fundingRate',\n } as const,\n\n // Sort button presets for filter chips (simplified buttons without direction)\n SortButtonPresets: [\n { field: 'volume', labelKey: 'perps.sort.volume' },\n { field: 'priceChange', labelKey: 'perps.sort.price_change' },\n { field: 'fundingRate', labelKey: 'perps.sort.funding_rate' },\n ] as const,\n\n // Sort options for the bottom sheet\n // All options support direction toggle (high-to-low / low-to-high)\n SortOptions: [\n {\n id: 'volume',\n labelKey: 'perps.sort.volume',\n field: 'volume',\n direction: 'desc',\n },\n {\n id: 'priceChange',\n labelKey: 'perps.sort.price_change',\n field: 'priceChange',\n direction: 'desc',\n },\n {\n id: 'openInterest',\n labelKey: 'perps.sort.open_interest',\n field: 'openInterest',\n direction: 'desc',\n },\n {\n id: 'fundingRate',\n labelKey: 'perps.sort.funding_rate',\n field: 'fundingRate',\n direction: 'desc',\n },\n ] as const,\n} as const;\n\n/**\n * Type for valid sort option IDs\n * Derived from SORT_OPTIONS to ensure type safety\n * Valid values: 'volume' | 'priceChange' | 'openInterest' | 'fundingRate'\n */\nexport type SortOptionId =\n (typeof MARKET_SORTING_CONFIG.SortOptions)[number]['id'];\n\n/**\n * Funding rate display configuration\n * Controls how funding rates are formatted and displayed\n */\nexport const FUNDING_RATE_CONFIG = {\n // Number of decimal places to display for funding rates\n Decimals: 4,\n // Default display value when funding rate is zero or unavailable\n ZeroDisplay: '0.0000%',\n // Multiplier to convert decimal funding rate to percentage\n PercentageMultiplier: 100,\n} as const;\n\n/**\n * Provider configuration for multi-provider support\n */\nexport const PROVIDER_CONFIG = {\n /** Default perpetual DEX provider when no explicit selection exists */\n DefaultProvider: 'hyperliquid' as const,\n /** Force MYX to testnet only (mainnet credentials not yet available) */\n MYX_TESTNET_ONLY: false,\n} as const;\n\n// Disk-backed cold-start cache keys and throttle interval\nexport const PERPS_DISK_CACHE_MARKETS = 'PERPS_DISK_CACHE_MARKETS';\nexport const PERPS_DISK_CACHE_USER_DATA = 'PERPS_DISK_CACHE_USER_DATA';\nexport const PERPS_DISK_CACHE_THROTTLE_MS = 30_000;\n\n/**\n * Build the standard provider:network cache key from controller state.\n *\n * @param state - Controller state containing provider and network info.\n * @param state.activeProvider - Active perps provider name.\n * @param state.isTestnet - Whether testnet mode is active.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function getProviderNetworkKey(state: {\n activeProvider?: string;\n isTestnet?: boolean;\n}): string {\n return `${state.activeProvider ?? PROVIDER_CONFIG.DefaultProvider}:${state.isTestnet ? 'testnet' : 'mainnet'}`;\n}\n\n/**\n * Build a provider:network cache key for a specific provider id.\n * Accounts for MYX_TESTNET_ONLY: MYX is always on testnet regardless of the\n * global network flag.\n *\n * @param providerId - The provider identifier (e.g. \"hyperliquid\", \"myx\").\n * @param isTestnet - Global testnet flag from controller state.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function buildProviderCacheKey(\n providerId: string,\n isTestnet: boolean,\n): string {\n const effectiveTestnet =\n providerId === 'myx'\n ? PROVIDER_CONFIG.MYX_TESTNET_ONLY || isTestnet\n : isTestnet;\n return `${providerId}:${effectiveTestnet ? 'testnet' : 'mainnet'}`;\n}\n"]}
|
|
@@ -91,6 +91,9 @@ export declare const PERFORMANCE_CONFIG: {
|
|
|
91
91
|
readonly ValidationDebounceMs: 300;
|
|
92
92
|
readonly LiquidationPriceDebounceMs: 500;
|
|
93
93
|
readonly CandleConnectDebounceMs: 500;
|
|
94
|
+
readonly CandleTeardownDelayMs: 150;
|
|
95
|
+
readonly PerpsRestCoalesceTtlMs: 60000;
|
|
96
|
+
readonly PerpsCandleCoalesceTtlMs: 30000;
|
|
94
97
|
readonly NavigationParamsDelayMs: 200;
|
|
95
98
|
readonly TabControlResetDelayMs: 500;
|
|
96
99
|
readonly MarketDataCacheDurationMs: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpsConfig.d.cts","sourceRoot":"","sources":["../../src/constants/perpsConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,+CAA+C,CAAC;AACzE,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,eAAe;;;IAG1B,sGAAsG;;IAEtG,uFAAuF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC/E,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;CASxB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;CAexB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAQ,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"perpsConfig.d.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;IAC1B,uEAAuE;;IAEvE,wEAAwE;;CAEhE,CAAC;AAGX,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AACvE,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,MAAM,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GACjB,MAAM,CAMR"}
|
|
@@ -91,6 +91,9 @@ export declare const PERFORMANCE_CONFIG: {
|
|
|
91
91
|
readonly ValidationDebounceMs: 300;
|
|
92
92
|
readonly LiquidationPriceDebounceMs: 500;
|
|
93
93
|
readonly CandleConnectDebounceMs: 500;
|
|
94
|
+
readonly CandleTeardownDelayMs: 150;
|
|
95
|
+
readonly PerpsRestCoalesceTtlMs: 60000;
|
|
96
|
+
readonly PerpsCandleCoalesceTtlMs: 30000;
|
|
94
97
|
readonly NavigationParamsDelayMs: 200;
|
|
95
98
|
readonly TabControlResetDelayMs: 500;
|
|
96
99
|
readonly MarketDataCacheDurationMs: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpsConfig.d.mts","sourceRoot":"","sources":["../../src/constants/perpsConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,+CAA+C,CAAC;AACzE,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,eAAe;;;IAG1B,sGAAsG;;IAEtG,uFAAuF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC/E,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,qBAAqB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IG;AACH,MAAM,MAAM,YAAY,GACtB,CAAC,OAAO,qBAAqB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;CAOtB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B,uEAAuE;;IAEvE,wEAAwE;;CAEhE,CAAC;AAGX,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AACvE,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,MAAM,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GACjB,MAAM,CAMR"}
|
|
@@ -115,6 +115,34 @@ export const PERFORMANCE_CONFIG = {
|
|
|
115
115
|
// Candle subscription debounce delay (milliseconds)
|
|
116
116
|
// Prevents WS subscription churn during rapid market switching (#28141)
|
|
117
117
|
CandleConnectDebounceMs: 500,
|
|
118
|
+
// Candle WS teardown delay (milliseconds)
|
|
119
|
+
// When the last subscriber for a cacheKey unsubscribes, wait this long before
|
|
120
|
+
// tearing down the WS. A subsequent subscribe inside the window cancels the
|
|
121
|
+
// teardown so rapid back-and-forth switches do not churn the connection.
|
|
122
|
+
CandleTeardownDelayMs: 150,
|
|
123
|
+
// Perps REST coalesce TTL (milliseconds)
|
|
124
|
+
//
|
|
125
|
+
// Window in which identical GET-style REST calls (getOrderFills, getOrders,
|
|
126
|
+
// getFunding, historicalOrders) share a single in-flight promise / cached
|
|
127
|
+
// result. `forceRefresh` still bypasses the cache end-to-end (hooks →
|
|
128
|
+
// controller → MarketDataService → provider → HyperLiquidClientService), so
|
|
129
|
+
// pull-to-refresh always hits the network.
|
|
130
|
+
//
|
|
131
|
+
// Why 60 s: HyperLiquid's documented rate limit is 1200 weight / IP /
|
|
132
|
+
// rolling 60 s window. Sizing TTL = window length caps each endpoint-per-
|
|
133
|
+
// account at ≤1 REST hit per window under any UI activity pattern — rapid
|
|
134
|
+
// market switching, re-mounts (usePerpsMarketFills, usePerpsTransactionHistory),
|
|
135
|
+
// and multi-tab scans all share a single request. Live fills/orders/prices
|
|
136
|
+
// still flow via WS subscriptions, so REST is seed/backfill only — cache
|
|
137
|
+
// staleness inside the 60 s window is never user-visible.
|
|
138
|
+
PerpsRestCoalesceTtlMs: 60000,
|
|
139
|
+
// Candle snapshot REST coalesce TTL (milliseconds).
|
|
140
|
+
// Longer than PerpsRestCoalesceTtlMs because WS stream keeps live candles
|
|
141
|
+
// fresh — the REST snapshot only seeds the chart on initial subscribe. A
|
|
142
|
+
// 30 s window lets rapid market switching (pass 1 → pass 2 of a stress
|
|
143
|
+
// loop) share the same snapshot per (symbol, interval), cutting
|
|
144
|
+
// candleSnapshot REST weight roughly in half.
|
|
145
|
+
PerpsCandleCoalesceTtlMs: 30000,
|
|
118
146
|
// Navigation params delay (milliseconds)
|
|
119
147
|
// Required for React Navigation to complete state transitions before setting params
|
|
120
148
|
// This ensures navigation context is available when programmatically selecting tabs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpsConfig.mjs","sourceRoot":"","sources":["../../src/constants/perpsConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,4CAA4C,CAAC;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc,EAAE,cAAc;IAC9B,WAAW,EAAE,OAAO,EAAE,kFAAkF;IACxG,sGAAsG;IACtG,4BAA4B,EAAE,eAAe;IAC7C,uFAAuF;IACvF,uBAAuB,EAA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IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACjH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,SAAkB;IAElB,MAAM,gBAAgB,GACpB,UAAU,KAAK,KAAK;QAClB,CAAC,CAAC,eAAe,CAAC,gBAAgB,IAAI,SAAS;QAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,GAAG,UAAU,IAAI,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Perps feature constants - Controller layer (portable)\n *\n * This file contains only controller-portable configuration:\n * - Constants used by controller logic, providers, and services\n * - Calculation thresholds, API configs, and protocol constants\n *\n * UI-only constants (layout, display, navigation) live in:\n * app/components/UI/Perps/constants/perpsConfig.ts\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\nexport const ZERO_BALANCE = '0x0';\n\nexport const PERPS_CONSTANTS = {\n FeatureFlagKey: 'perpsEnabled',\n FeatureName: 'perps', // Constant for Sentry error filtering - enables \"feature:perps\" dashboard queries\n /** Token description used to identify the synthetic \"Perps balance\" option in pay-with token lists */\n PerpsBalanceTokenDescription: 'perps-balance',\n /** Symbol displayed for the synthetic \"Perps balance\" token in pay-with token lists */\n PerpsBalanceTokenSymbol: 'USD',\n WebsocketTimeout: 5000, // 5 seconds\n WebsocketCleanupDelay: 1000, // 1 second\n BackgroundDisconnectDelay: 20_000, // 20 seconds delay before disconnecting when app is backgrounded or when user exits perps UX\n ConnectionTimeoutMs: 10_000, // 10 seconds timeout for connection and position loading states\n DefaultMonitoringTimeoutMs: 10_000, // 10 seconds default timeout for data monitoring operations\n\n // Connection timing constants\n ConnectionGracePeriodMs: 20_000, // 20 seconds grace period before actual disconnection (same as BackgroundDisconnectDelay for semantic clarity)\n ConnectionAttemptTimeoutMs: 30_000, // 30 seconds timeout for connection attempts to prevent indefinite hanging\n WebsocketPingTimeoutMs: 5_000, // 5 seconds timeout for WebSocket health check ping\n ConnectRetryDelayMs: 200, // Delay before retrying connect() when connection isn't ready yet\n ForegroundPingRetryDelayMs: 500, // Delay before retrying ping in resumeFromForeground — JS thread may be sluggish right after foregrounding\n ReconnectionCleanupDelayMs: 500, // Platform-agnostic delay to ensure WebSocket is ready\n ReconnectionDelayAndroidMs: 300, // Android-specific reconnection delay for better reliability on slower devices\n ReconnectionDelayIosMs: 100, // iOS-specific reconnection delay for optimal performance\n ReconnectionRetryDelayMs: 5_000, // 5 seconds delay between reconnection attempts\n NetworkRestoreMaxRetries: 8, // Max retry attempts when reconnecting after WiFi/network restore\n NetworkRestoreRetryBaseMs: 1_500, // Base delay (ms) between network restore retries (multiplied by attempt number)\n\n // Connection manager timing constants\n BalanceUpdateThrottleMs: 15000, // Update at most every 15 seconds to reduce state updates in PerpsConnectionManager\n InitialDataDelayMs: 100, // Delay to allow initial data to load after connection establishment\n\n // Deposit toast timing\n DepositTakingLongerToastDelayMs: 30_000, // Delay before showing \"Deposit taking longer than usual\" toast\n\n DefaultAssetPreviewLimit: 5,\n DefaultMaxLeverage: 3 as number, // Default fallback max leverage when market data is unavailable - conservative default\n FallbackPriceDisplay: '$---', // Display when price data is unavailable\n FallbackPercentageDisplay: '--%', // Display when change data is unavailable\n FallbackDataDisplay: '--', // Display when non-price data is unavailable\n ZeroAmountDisplay: '$0', // Display for zero dollar amounts (e.g., no volume)\n ZeroAmountDetailedDisplay: '$0.00', // Display for zero dollar amounts with decimals\n\n RecentActivityLimit: 3,\n\n // Historical data fetching constants\n FillsLookbackMs: 90 * 24 * 60 * 60 * 1000, // 3 months in milliseconds - limits REST API fills fetch\n} as const;\n\n/**\n * Withdrawal-specific constants (protocol-agnostic)\n * Note: Protocol-specific values like estimated time should be defined in each protocol's config\n */\nexport const WITHDRAWAL_CONSTANTS = {\n DefaultMinAmount: '1.01', // Default minimum withdrawal amount in USDC\n DefaultFeeAmount: 1, // Default withdrawal fee in USDC\n DefaultFeeToken: 'USDC', // Default fee token\n} as const;\n\n/**\n * Validation thresholds for UI warnings and checks\n * These values control when warnings are shown to users\n */\nexport const VALIDATION_THRESHOLDS = {\n // Leverage threshold for warning users about high leverage\n HighLeverageWarning: 20, // Show warning when leverage > 20x\n\n // Limit price difference threshold (as decimal, 0.1 = 10%)\n LimitPriceDifferenceWarning: 0.1, // Warn if limit price differs by >10% from current price\n\n // Price deviation threshold (as decimal, 0.1 = 10%)\n PriceDeviation: 0.1, // Warn if perps price deviates by >10% from spot price\n} as const;\n\n/**\n * Order slippage configuration\n * Controls default slippage tolerance for different order types\n * Conservative defaults based on HyperLiquid platform interface\n * See: docs/perps/hyperliquid/ORDER-MATCHING-ERRORS.md\n */\nexport const ORDER_SLIPPAGE_CONFIG = {\n // Market order slippage (basis points)\n // 300 basis points = 3% = 0.03 decimal\n // Conservative default for measured rollout, prevents most IOC failures\n DefaultMarketSlippageBps: 300,\n\n // TP/SL order slippage (basis points)\n // 1000 basis points = 10% = 0.10 decimal\n // Aligns with HyperLiquid platform default for triggered orders\n DefaultTpslSlippageBps: 1000,\n\n // Limit order slippage (basis points)\n // 100 basis points = 1% = 0.01 decimal\n // Kept conservative as limit orders rest on book (not IOC/immediate execution)\n DefaultLimitSlippageBps: 100,\n} as const;\n\n/**\n * Max order amount buffer to reduce \"Insufficient margin\" rejections from the exchange.\n * When the user selects 100% (slider or Max), we cap the order at (1 - this) of the\n * theoretical max so that fees, rounding, and exchange-side margin checks are covered.\n * Value as decimal (e.g. 0.005 = 0.5%).\n */\nexport const MAX_ORDER_MARGIN_BUFFER = 0.005; // 0.5%\n\n/**\n * Performance optimization constants\n * These values control debouncing and throttling for better performance\n */\nexport const PERFORMANCE_CONFIG = {\n // Price updates debounce delay (milliseconds)\n // Batches rapid WebSocket price updates to reduce re-renders\n PriceUpdateDebounceMs: 1000,\n\n // Order validation debounce delay (milliseconds)\n // Prevents excessive validation calls during rapid form input changes\n ValidationDebounceMs: 300,\n\n // Liquidation price debounce delay (milliseconds)\n // Prevents excessive liquidation price calls during rapid form input changes\n LiquidationPriceDebounceMs: 500,\n\n // Candle subscription debounce delay (milliseconds)\n // Prevents WS subscription churn during rapid market switching (#28141)\n CandleConnectDebounceMs: 500,\n\n // Navigation params delay (milliseconds)\n // Required for React Navigation to complete state transitions before setting params\n // This ensures navigation context is available when programmatically selecting tabs\n NavigationParamsDelayMs: 200,\n\n // Tab control reset delay (milliseconds)\n // Delay to reset programmatic tab control after tab switching to prevent render loops\n TabControlResetDelayMs: 500,\n\n // Market data cache duration (milliseconds)\n // How long to cache market list data before fetching fresh data\n MarketDataCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n // Asset metadata cache duration (milliseconds)\n // How long to cache asset icon validation results\n AssetMetadataCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Max leverage cache duration (milliseconds)\n // How long to cache max leverage values per asset (leverage rarely changes)\n MaxLeverageCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Rewards cache durations (milliseconds)\n // How long to cache fee discount data from rewards API\n FeeDiscountCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n // How long to cache points calculation parameters from rewards API\n PointsCalculationCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n /**\n * Performance logging markers for filtering logs during development and debugging\n * These markers help isolate performance-related logs from general application logs\n * Usage: Use in DevLogger calls to easily filter specific performance areas\n * Impact: Development only (uses DevLogger) - zero production performance cost\n *\n * Examples:\n * - Filter Sentry performance logs: `adb logcat | grep PERPSMARK_SENTRY`\n * - Filter MetaMetrics events: `adb logcat | grep PERPSMARK_METRICS`\n * - Filter WebSocket performance: `adb logcat | grep PERPSMARK_WS`\n * - Filter all Perps performance: `adb logcat | grep PERPSMARK_`\n */\n LoggingMarkers: {\n // Sentry performance measurement logs (screen loads, bottom sheets, API timing)\n SentryPerformance: 'PERPSMARK_SENTRY',\n\n // MetaMetrics event tracking logs (user interactions, business analytics)\n MetametricsEvents: 'PERPSMARK_METRICS',\n\n // WebSocket performance logs (connection timing, data flow, reconnections)\n WebsocketPerformance: 'PERPSMARK_SENTRY_WS',\n } as const,\n} as const;\n\nexport const TP_SL_CONFIG = {\n UsePositionBoundTpsl: true,\n} as const;\n\n/**\n * HyperLiquid order limits based on leverage\n * From: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/contract-specifications\n */\nexport const HYPERLIQUID_ORDER_LIMITS = {\n // Market orders\n MarketOrderLimits: {\n // $15,000,000 for max leverage >= 25\n HighLeverage: 15_000_000,\n // $5,000,000 for max leverage in [20, 25)\n MediumHighLeverage: 5_000_000,\n // $2,000,000 for max leverage in [10, 20)\n MediumLeverage: 2_000_000,\n // $500,000 for max leverage < 10\n LowLeverage: 500_000,\n },\n // Limit orders are 10x market order limits\n LimitOrderMultiplier: 10,\n} as const;\n\n/**\n * Close position configuration\n * Controls behavior and constants specific to position closing\n */\nexport const CLOSE_POSITION_CONFIG = {\n // Decimal places for USD amount input display\n UsdDecimalPlaces: 2,\n\n // Default close percentage when opening the close position view\n DefaultClosePercentage: 100,\n\n // Precision for position size calculations to prevent rounding errors\n AmountCalculationPrecision: 6,\n\n // Throttle delay for real-time price updates during position closing\n PriceThrottleMs: 3000,\n\n // Fallback decimal places for tokens without metadata\n FallbackTokenDecimals: 18,\n} as const;\n\n/**\n * Margin adjustment configuration\n * Controls behavior for adding/removing margin from positions\n */\nexport const MARGIN_ADJUSTMENT_CONFIG = {\n // Risk thresholds for margin removal warnings\n // Threshold values represent ratio of (price distance to liquidation) / (liquidation price)\n // Values < 1.0 mean price is dangerously close to liquidation\n LiquidationRiskThreshold: 1.2, // 20% buffer before liquidation - triggers danger state\n LiquidationWarningThreshold: 1.5, // 50% buffer before liquidation - triggers warning state\n\n // Minimum margin adjustment amount (USD)\n // Prevents dust adjustments and ensures meaningful position changes\n MinAdjustmentAmount: 1,\n\n // Precision for margin calculations\n // Ensures accurate decimal handling in margin/leverage calculations\n CalculationPrecision: 6,\n\n // Safety buffer for margin removal to account for HyperLiquid's transfer margin requirement\n // HyperLiquid enforces: transfer_margin_required = max(initial_margin_required, 0.1 * total_position_value)\n // See: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/margin-and-pnl\n MarginRemovalSafetyBuffer: 0.1,\n\n // Fallback max leverage when market data is unavailable\n // Conservative value to prevent over-removal of margin\n // Most HyperLiquid assets support at least 50x leverage\n FallbackMaxLeverage: 50,\n} as const;\n\n/**\n * Data Lake API configuration\n * Endpoints for reporting perps trading activity for notifications\n */\nexport const DATA_LAKE_API_CONFIG = {\n // Order reporting endpoint - only used for mainnet perps trading\n OrdersEndpoint: 'https://perps.api.cx.metamask.io/api/v1/orders',\n} as const;\n\n/**\n * Decimal precision configuration\n * Controls maximum decimal places for price and input validation\n */\nexport const DECIMAL_PRECISION_CONFIG = {\n // Maximum decimal places for price input (matches Hyperliquid limit)\n // Used in TP/SL forms, limit price inputs, and price validation\n MaxPriceDecimals: 6,\n // Maximum significant figures allowed by HyperLiquid API\n // Orders with more than 5 significant figures will be rejected\n MaxSignificantFigures: 5,\n // Defensive fallback for size decimals when market data fails to load\n // Real szDecimals should always come from market data API (varies by asset)\n // Using 6 as safe maximum to prevent crashes (covers most assets)\n // NOTE: This is NOT semantically correct - just a defensive measure\n FallbackSizeDecimals: 6,\n} as const;\n\n/**\n * Market sorting configuration\n * Controls sorting behavior and presets for the trending markets view\n */\nexport const MARKET_SORTING_CONFIG = {\n // Default sort settings\n DefaultSortOptionId: 'volume' as const,\n DefaultDirection: 'desc' as const,\n\n // Available sort fields (only includes fields supported by PerpsMarketData)\n SortFields: {\n Volume: 'volume',\n PriceChange: 'priceChange',\n OpenInterest: 'openInterest',\n FundingRate: 'fundingRate',\n } as const,\n\n // Sort button presets for filter chips (simplified buttons without direction)\n SortButtonPresets: [\n { field: 'volume', labelKey: 'perps.sort.volume' },\n { field: 'priceChange', labelKey: 'perps.sort.price_change' },\n { field: 'fundingRate', labelKey: 'perps.sort.funding_rate' },\n ] as const,\n\n // Sort options for the bottom sheet\n // All options support direction toggle (high-to-low / low-to-high)\n SortOptions: [\n {\n id: 'volume',\n labelKey: 'perps.sort.volume',\n field: 'volume',\n direction: 'desc',\n },\n {\n id: 'priceChange',\n labelKey: 'perps.sort.price_change',\n field: 'priceChange',\n direction: 'desc',\n },\n {\n id: 'openInterest',\n labelKey: 'perps.sort.open_interest',\n field: 'openInterest',\n direction: 'desc',\n },\n {\n id: 'fundingRate',\n labelKey: 'perps.sort.funding_rate',\n field: 'fundingRate',\n direction: 'desc',\n },\n ] as const,\n} as const;\n\n/**\n * Type for valid sort option IDs\n * Derived from SORT_OPTIONS to ensure type safety\n * Valid values: 'volume' | 'priceChange' | 'openInterest' | 'fundingRate'\n */\nexport type SortOptionId =\n (typeof MARKET_SORTING_CONFIG.SortOptions)[number]['id'];\n\n/**\n * Funding rate display configuration\n * Controls how funding rates are formatted and displayed\n */\nexport const FUNDING_RATE_CONFIG = {\n // Number of decimal places to display for funding rates\n Decimals: 4,\n // Default display value when funding rate is zero or unavailable\n ZeroDisplay: '0.0000%',\n // Multiplier to convert decimal funding rate to percentage\n PercentageMultiplier: 100,\n} as const;\n\n/**\n * Provider configuration for multi-provider support\n */\nexport const PROVIDER_CONFIG = {\n /** Default perpetual DEX provider when no explicit selection exists */\n DefaultProvider: 'hyperliquid' as const,\n /** Force MYX to testnet only (mainnet credentials not yet available) */\n MYX_TESTNET_ONLY: false,\n} as const;\n\n// Disk-backed cold-start cache keys and throttle interval\nexport const PERPS_DISK_CACHE_MARKETS = 'PERPS_DISK_CACHE_MARKETS';\nexport const PERPS_DISK_CACHE_USER_DATA = 'PERPS_DISK_CACHE_USER_DATA';\nexport const PERPS_DISK_CACHE_THROTTLE_MS = 30_000;\n\n/**\n * Build the standard provider:network cache key from controller state.\n *\n * @param state - Controller state containing provider and network info.\n * @param state.activeProvider - Active perps provider name.\n * @param state.isTestnet - Whether testnet mode is active.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function getProviderNetworkKey(state: {\n activeProvider?: string;\n isTestnet?: boolean;\n}): string {\n return `${state.activeProvider ?? PROVIDER_CONFIG.DefaultProvider}:${state.isTestnet ? 'testnet' : 'mainnet'}`;\n}\n\n/**\n * Build a provider:network cache key for a specific provider id.\n * Accounts for MYX_TESTNET_ONLY: MYX is always on testnet regardless of the\n * global network flag.\n *\n * @param providerId - The provider identifier (e.g. \"hyperliquid\", \"myx\").\n * @param isTestnet - Global testnet flag from controller state.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function buildProviderCacheKey(\n providerId: string,\n isTestnet: boolean,\n): string {\n const effectiveTestnet =\n providerId === 'myx'\n ? PROVIDER_CONFIG.MYX_TESTNET_ONLY || isTestnet\n : isTestnet;\n return `${providerId}:${effectiveTestnet ? 'testnet' : 'mainnet'}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"perpsConfig.mjs","sourceRoot":"","sources":["../../src/constants/perpsConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,4CAA4C,CAAC;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc,EAAE,cAAc;IAC9B,WAAW,EAAE,OAAO,EAAE,kFAAkF;IACxG,sGAAsG;IACtG,4BAA4B,EAAE,eAAe;IAC7C,uFAAuF;IACvF,uBAAuB,EAAE,KAAK;IAC9B,gBAAgB,EAAE,IAAI,EAAE,YAAY;IACpC,qBAAqB,EAAE,IAAI,EAAE,WAAW;IACxC,yBAAyB,EAAE,KAAM,EAAE,6FAA6F;IAChI,mBAAmB,EAAE,KAAM,EAAE,gEAAgE;IAC7F,0BAA0B,EAAE,KAAM,EAAE,4DAA4D;IAEhG,8BAA8B;IAC9B,uBAAuB,EAAE,KAAM,EAAE,+GAA+G;IAChJ,0BAA0B,EAAE,KAAM,EAAE,2E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AM,4BAA4B,GAAG,KAAM,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAGrC;IACC,OAAO,GAAG,KAAK,CAAC,cAAc,IAAI,eAAe,CAAC,eAAe,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACjH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,SAAkB;IAElB,MAAM,gBAAgB,GACpB,UAAU,KAAK,KAAK;QAClB,CAAC,CAAC,eAAe,CAAC,gBAAgB,IAAI,SAAS;QAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO,GAAG,UAAU,IAAI,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Perps feature constants - Controller layer (portable)\n *\n * This file contains only controller-portable configuration:\n * - Constants used by controller logic, providers, and services\n * - Calculation thresholds, API configs, and protocol constants\n *\n * UI-only constants (layout, display, navigation) live in:\n * app/components/UI/Perps/constants/perpsConfig.ts\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\nexport const ZERO_BALANCE = '0x0';\n\nexport const PERPS_CONSTANTS = {\n FeatureFlagKey: 'perpsEnabled',\n FeatureName: 'perps', // Constant for Sentry error filtering - enables \"feature:perps\" dashboard queries\n /** Token description used to identify the synthetic \"Perps balance\" option in pay-with token lists */\n PerpsBalanceTokenDescription: 'perps-balance',\n /** Symbol displayed for the synthetic \"Perps balance\" token in pay-with token lists */\n PerpsBalanceTokenSymbol: 'USD',\n WebsocketTimeout: 5000, // 5 seconds\n WebsocketCleanupDelay: 1000, // 1 second\n BackgroundDisconnectDelay: 20_000, // 20 seconds delay before disconnecting when app is backgrounded or when user exits perps UX\n ConnectionTimeoutMs: 10_000, // 10 seconds timeout for connection and position loading states\n DefaultMonitoringTimeoutMs: 10_000, // 10 seconds default timeout for data monitoring operations\n\n // Connection timing constants\n ConnectionGracePeriodMs: 20_000, // 20 seconds grace period before actual disconnection (same as BackgroundDisconnectDelay for semantic clarity)\n ConnectionAttemptTimeoutMs: 30_000, // 30 seconds timeout for connection attempts to prevent indefinite hanging\n WebsocketPingTimeoutMs: 5_000, // 5 seconds timeout for WebSocket health check ping\n ConnectRetryDelayMs: 200, // Delay before retrying connect() when connection isn't ready yet\n ForegroundPingRetryDelayMs: 500, // Delay before retrying ping in resumeFromForeground — JS thread may be sluggish right after foregrounding\n ReconnectionCleanupDelayMs: 500, // Platform-agnostic delay to ensure WebSocket is ready\n ReconnectionDelayAndroidMs: 300, // Android-specific reconnection delay for better reliability on slower devices\n ReconnectionDelayIosMs: 100, // iOS-specific reconnection delay for optimal performance\n ReconnectionRetryDelayMs: 5_000, // 5 seconds delay between reconnection attempts\n NetworkRestoreMaxRetries: 8, // Max retry attempts when reconnecting after WiFi/network restore\n NetworkRestoreRetryBaseMs: 1_500, // Base delay (ms) between network restore retries (multiplied by attempt number)\n\n // Connection manager timing constants\n BalanceUpdateThrottleMs: 15000, // Update at most every 15 seconds to reduce state updates in PerpsConnectionManager\n InitialDataDelayMs: 100, // Delay to allow initial data to load after connection establishment\n\n // Deposit toast timing\n DepositTakingLongerToastDelayMs: 30_000, // Delay before showing \"Deposit taking longer than usual\" toast\n\n DefaultAssetPreviewLimit: 5,\n DefaultMaxLeverage: 3 as number, // Default fallback max leverage when market data is unavailable - conservative default\n FallbackPriceDisplay: '$---', // Display when price data is unavailable\n FallbackPercentageDisplay: '--%', // Display when change data is unavailable\n FallbackDataDisplay: '--', // Display when non-price data is unavailable\n ZeroAmountDisplay: '$0', // Display for zero dollar amounts (e.g., no volume)\n ZeroAmountDetailedDisplay: '$0.00', // Display for zero dollar amounts with decimals\n\n RecentActivityLimit: 3,\n\n // Historical data fetching constants\n FillsLookbackMs: 90 * 24 * 60 * 60 * 1000, // 3 months in milliseconds - limits REST API fills fetch\n} as const;\n\n/**\n * Withdrawal-specific constants (protocol-agnostic)\n * Note: Protocol-specific values like estimated time should be defined in each protocol's config\n */\nexport const WITHDRAWAL_CONSTANTS = {\n DefaultMinAmount: '1.01', // Default minimum withdrawal amount in USDC\n DefaultFeeAmount: 1, // Default withdrawal fee in USDC\n DefaultFeeToken: 'USDC', // Default fee token\n} as const;\n\n/**\n * Validation thresholds for UI warnings and checks\n * These values control when warnings are shown to users\n */\nexport const VALIDATION_THRESHOLDS = {\n // Leverage threshold for warning users about high leverage\n HighLeverageWarning: 20, // Show warning when leverage > 20x\n\n // Limit price difference threshold (as decimal, 0.1 = 10%)\n LimitPriceDifferenceWarning: 0.1, // Warn if limit price differs by >10% from current price\n\n // Price deviation threshold (as decimal, 0.1 = 10%)\n PriceDeviation: 0.1, // Warn if perps price deviates by >10% from spot price\n} as const;\n\n/**\n * Order slippage configuration\n * Controls default slippage tolerance for different order types\n * Conservative defaults based on HyperLiquid platform interface\n * See: docs/perps/hyperliquid/ORDER-MATCHING-ERRORS.md\n */\nexport const ORDER_SLIPPAGE_CONFIG = {\n // Market order slippage (basis points)\n // 300 basis points = 3% = 0.03 decimal\n // Conservative default for measured rollout, prevents most IOC failures\n DefaultMarketSlippageBps: 300,\n\n // TP/SL order slippage (basis points)\n // 1000 basis points = 10% = 0.10 decimal\n // Aligns with HyperLiquid platform default for triggered orders\n DefaultTpslSlippageBps: 1000,\n\n // Limit order slippage (basis points)\n // 100 basis points = 1% = 0.01 decimal\n // Kept conservative as limit orders rest on book (not IOC/immediate execution)\n DefaultLimitSlippageBps: 100,\n} as const;\n\n/**\n * Max order amount buffer to reduce \"Insufficient margin\" rejections from the exchange.\n * When the user selects 100% (slider or Max), we cap the order at (1 - this) of the\n * theoretical max so that fees, rounding, and exchange-side margin checks are covered.\n * Value as decimal (e.g. 0.005 = 0.5%).\n */\nexport const MAX_ORDER_MARGIN_BUFFER = 0.005; // 0.5%\n\n/**\n * Performance optimization constants\n * These values control debouncing and throttling for better performance\n */\nexport const PERFORMANCE_CONFIG = {\n // Price updates debounce delay (milliseconds)\n // Batches rapid WebSocket price updates to reduce re-renders\n PriceUpdateDebounceMs: 1000,\n\n // Order validation debounce delay (milliseconds)\n // Prevents excessive validation calls during rapid form input changes\n ValidationDebounceMs: 300,\n\n // Liquidation price debounce delay (milliseconds)\n // Prevents excessive liquidation price calls during rapid form input changes\n LiquidationPriceDebounceMs: 500,\n\n // Candle subscription debounce delay (milliseconds)\n // Prevents WS subscription churn during rapid market switching (#28141)\n CandleConnectDebounceMs: 500,\n\n // Candle WS teardown delay (milliseconds)\n // When the last subscriber for a cacheKey unsubscribes, wait this long before\n // tearing down the WS. A subsequent subscribe inside the window cancels the\n // teardown so rapid back-and-forth switches do not churn the connection.\n CandleTeardownDelayMs: 150,\n\n // Perps REST coalesce TTL (milliseconds)\n //\n // Window in which identical GET-style REST calls (getOrderFills, getOrders,\n // getFunding, historicalOrders) share a single in-flight promise / cached\n // result. `forceRefresh` still bypasses the cache end-to-end (hooks →\n // controller → MarketDataService → provider → HyperLiquidClientService), so\n // pull-to-refresh always hits the network.\n //\n // Why 60 s: HyperLiquid's documented rate limit is 1200 weight / IP /\n // rolling 60 s window. Sizing TTL = window length caps each endpoint-per-\n // account at ≤1 REST hit per window under any UI activity pattern — rapid\n // market switching, re-mounts (usePerpsMarketFills, usePerpsTransactionHistory),\n // and multi-tab scans all share a single request. Live fills/orders/prices\n // still flow via WS subscriptions, so REST is seed/backfill only — cache\n // staleness inside the 60 s window is never user-visible.\n PerpsRestCoalesceTtlMs: 60_000,\n\n // Candle snapshot REST coalesce TTL (milliseconds).\n // Longer than PerpsRestCoalesceTtlMs because WS stream keeps live candles\n // fresh — the REST snapshot only seeds the chart on initial subscribe. A\n // 30 s window lets rapid market switching (pass 1 → pass 2 of a stress\n // loop) share the same snapshot per (symbol, interval), cutting\n // candleSnapshot REST weight roughly in half.\n PerpsCandleCoalesceTtlMs: 30_000,\n\n // Navigation params delay (milliseconds)\n // Required for React Navigation to complete state transitions before setting params\n // This ensures navigation context is available when programmatically selecting tabs\n NavigationParamsDelayMs: 200,\n\n // Tab control reset delay (milliseconds)\n // Delay to reset programmatic tab control after tab switching to prevent render loops\n TabControlResetDelayMs: 500,\n\n // Market data cache duration (milliseconds)\n // How long to cache market list data before fetching fresh data\n MarketDataCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n // Asset metadata cache duration (milliseconds)\n // How long to cache asset icon validation results\n AssetMetadataCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Max leverage cache duration (milliseconds)\n // How long to cache max leverage values per asset (leverage rarely changes)\n MaxLeverageCacheDurationMs: 60 * 60 * 1000, // 1 hour\n\n // Rewards cache durations (milliseconds)\n // How long to cache fee discount data from rewards API\n FeeDiscountCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n // How long to cache points calculation parameters from rewards API\n PointsCalculationCacheDurationMs: 5 * 60 * 1000, // 5 minutes\n\n /**\n * Performance logging markers for filtering logs during development and debugging\n * These markers help isolate performance-related logs from general application logs\n * Usage: Use in DevLogger calls to easily filter specific performance areas\n * Impact: Development only (uses DevLogger) - zero production performance cost\n *\n * Examples:\n * - Filter Sentry performance logs: `adb logcat | grep PERPSMARK_SENTRY`\n * - Filter MetaMetrics events: `adb logcat | grep PERPSMARK_METRICS`\n * - Filter WebSocket performance: `adb logcat | grep PERPSMARK_WS`\n * - Filter all Perps performance: `adb logcat | grep PERPSMARK_`\n */\n LoggingMarkers: {\n // Sentry performance measurement logs (screen loads, bottom sheets, API timing)\n SentryPerformance: 'PERPSMARK_SENTRY',\n\n // MetaMetrics event tracking logs (user interactions, business analytics)\n MetametricsEvents: 'PERPSMARK_METRICS',\n\n // WebSocket performance logs (connection timing, data flow, reconnections)\n WebsocketPerformance: 'PERPSMARK_SENTRY_WS',\n } as const,\n} as const;\n\nexport const TP_SL_CONFIG = {\n UsePositionBoundTpsl: true,\n} as const;\n\n/**\n * HyperLiquid order limits based on leverage\n * From: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/contract-specifications\n */\nexport const HYPERLIQUID_ORDER_LIMITS = {\n // Market orders\n MarketOrderLimits: {\n // $15,000,000 for max leverage >= 25\n HighLeverage: 15_000_000,\n // $5,000,000 for max leverage in [20, 25)\n MediumHighLeverage: 5_000_000,\n // $2,000,000 for max leverage in [10, 20)\n MediumLeverage: 2_000_000,\n // $500,000 for max leverage < 10\n LowLeverage: 500_000,\n },\n // Limit orders are 10x market order limits\n LimitOrderMultiplier: 10,\n} as const;\n\n/**\n * Close position configuration\n * Controls behavior and constants specific to position closing\n */\nexport const CLOSE_POSITION_CONFIG = {\n // Decimal places for USD amount input display\n UsdDecimalPlaces: 2,\n\n // Default close percentage when opening the close position view\n DefaultClosePercentage: 100,\n\n // Precision for position size calculations to prevent rounding errors\n AmountCalculationPrecision: 6,\n\n // Throttle delay for real-time price updates during position closing\n PriceThrottleMs: 3000,\n\n // Fallback decimal places for tokens without metadata\n FallbackTokenDecimals: 18,\n} as const;\n\n/**\n * Margin adjustment configuration\n * Controls behavior for adding/removing margin from positions\n */\nexport const MARGIN_ADJUSTMENT_CONFIG = {\n // Risk thresholds for margin removal warnings\n // Threshold values represent ratio of (price distance to liquidation) / (liquidation price)\n // Values < 1.0 mean price is dangerously close to liquidation\n LiquidationRiskThreshold: 1.2, // 20% buffer before liquidation - triggers danger state\n LiquidationWarningThreshold: 1.5, // 50% buffer before liquidation - triggers warning state\n\n // Minimum margin adjustment amount (USD)\n // Prevents dust adjustments and ensures meaningful position changes\n MinAdjustmentAmount: 1,\n\n // Precision for margin calculations\n // Ensures accurate decimal handling in margin/leverage calculations\n CalculationPrecision: 6,\n\n // Safety buffer for margin removal to account for HyperLiquid's transfer margin requirement\n // HyperLiquid enforces: transfer_margin_required = max(initial_margin_required, 0.1 * total_position_value)\n // See: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/margin-and-pnl\n MarginRemovalSafetyBuffer: 0.1,\n\n // Fallback max leverage when market data is unavailable\n // Conservative value to prevent over-removal of margin\n // Most HyperLiquid assets support at least 50x leverage\n FallbackMaxLeverage: 50,\n} as const;\n\n/**\n * Data Lake API configuration\n * Endpoints for reporting perps trading activity for notifications\n */\nexport const DATA_LAKE_API_CONFIG = {\n // Order reporting endpoint - only used for mainnet perps trading\n OrdersEndpoint: 'https://perps.api.cx.metamask.io/api/v1/orders',\n} as const;\n\n/**\n * Decimal precision configuration\n * Controls maximum decimal places for price and input validation\n */\nexport const DECIMAL_PRECISION_CONFIG = {\n // Maximum decimal places for price input (matches Hyperliquid limit)\n // Used in TP/SL forms, limit price inputs, and price validation\n MaxPriceDecimals: 6,\n // Maximum significant figures allowed by HyperLiquid API\n // Orders with more than 5 significant figures will be rejected\n MaxSignificantFigures: 5,\n // Defensive fallback for size decimals when market data fails to load\n // Real szDecimals should always come from market data API (varies by asset)\n // Using 6 as safe maximum to prevent crashes (covers most assets)\n // NOTE: This is NOT semantically correct - just a defensive measure\n FallbackSizeDecimals: 6,\n} as const;\n\n/**\n * Market sorting configuration\n * Controls sorting behavior and presets for the trending markets view\n */\nexport const MARKET_SORTING_CONFIG = {\n // Default sort settings\n DefaultSortOptionId: 'volume' as const,\n DefaultDirection: 'desc' as const,\n\n // Available sort fields (only includes fields supported by PerpsMarketData)\n SortFields: {\n Volume: 'volume',\n PriceChange: 'priceChange',\n OpenInterest: 'openInterest',\n FundingRate: 'fundingRate',\n } as const,\n\n // Sort button presets for filter chips (simplified buttons without direction)\n SortButtonPresets: [\n { field: 'volume', labelKey: 'perps.sort.volume' },\n { field: 'priceChange', labelKey: 'perps.sort.price_change' },\n { field: 'fundingRate', labelKey: 'perps.sort.funding_rate' },\n ] as const,\n\n // Sort options for the bottom sheet\n // All options support direction toggle (high-to-low / low-to-high)\n SortOptions: [\n {\n id: 'volume',\n labelKey: 'perps.sort.volume',\n field: 'volume',\n direction: 'desc',\n },\n {\n id: 'priceChange',\n labelKey: 'perps.sort.price_change',\n field: 'priceChange',\n direction: 'desc',\n },\n {\n id: 'openInterest',\n labelKey: 'perps.sort.open_interest',\n field: 'openInterest',\n direction: 'desc',\n },\n {\n id: 'fundingRate',\n labelKey: 'perps.sort.funding_rate',\n field: 'fundingRate',\n direction: 'desc',\n },\n ] as const,\n} as const;\n\n/**\n * Type for valid sort option IDs\n * Derived from SORT_OPTIONS to ensure type safety\n * Valid values: 'volume' | 'priceChange' | 'openInterest' | 'fundingRate'\n */\nexport type SortOptionId =\n (typeof MARKET_SORTING_CONFIG.SortOptions)[number]['id'];\n\n/**\n * Funding rate display configuration\n * Controls how funding rates are formatted and displayed\n */\nexport const FUNDING_RATE_CONFIG = {\n // Number of decimal places to display for funding rates\n Decimals: 4,\n // Default display value when funding rate is zero or unavailable\n ZeroDisplay: '0.0000%',\n // Multiplier to convert decimal funding rate to percentage\n PercentageMultiplier: 100,\n} as const;\n\n/**\n * Provider configuration for multi-provider support\n */\nexport const PROVIDER_CONFIG = {\n /** Default perpetual DEX provider when no explicit selection exists */\n DefaultProvider: 'hyperliquid' as const,\n /** Force MYX to testnet only (mainnet credentials not yet available) */\n MYX_TESTNET_ONLY: false,\n} as const;\n\n// Disk-backed cold-start cache keys and throttle interval\nexport const PERPS_DISK_CACHE_MARKETS = 'PERPS_DISK_CACHE_MARKETS';\nexport const PERPS_DISK_CACHE_USER_DATA = 'PERPS_DISK_CACHE_USER_DATA';\nexport const PERPS_DISK_CACHE_THROTTLE_MS = 30_000;\n\n/**\n * Build the standard provider:network cache key from controller state.\n *\n * @param state - Controller state containing provider and network info.\n * @param state.activeProvider - Active perps provider name.\n * @param state.isTestnet - Whether testnet mode is active.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function getProviderNetworkKey(state: {\n activeProvider?: string;\n isTestnet?: boolean;\n}): string {\n return `${state.activeProvider ?? PROVIDER_CONFIG.DefaultProvider}:${state.isTestnet ? 'testnet' : 'mainnet'}`;\n}\n\n/**\n * Build a provider:network cache key for a specific provider id.\n * Accounts for MYX_TESTNET_ONLY: MYX is always on testnet regardless of the\n * global network flag.\n *\n * @param providerId - The provider identifier (e.g. \"hyperliquid\", \"myx\").\n * @param isTestnet - Global testnet flag from controller state.\n * @returns Cache key in the format \"provider:mainnet\" or \"provider:testnet\".\n */\nexport function buildProviderCacheKey(\n providerId: string,\n isTestnet: boolean,\n): string {\n const effectiveTestnet =\n providerId === 'myx'\n ? PROVIDER_CONFIG.MYX_TESTNET_ONLY || isTestnet\n : isTestnet;\n return `${providerId}:${effectiveTestnet ? 'testnet' : 'mainnet'}`;\n}\n"]}
|
|
@@ -137,9 +137,9 @@ class AggregatedPerpsProvider {
|
|
|
137
137
|
}));
|
|
138
138
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_extractSuccessfulResults).call(this, results, 'getMarketDataWithPrices').flat();
|
|
139
139
|
}
|
|
140
|
-
async getOrderFills(params) {
|
|
140
|
+
async getOrderFills(params, options) {
|
|
141
141
|
const results = await Promise.allSettled(__classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_getActiveProviders).call(this).map(async ([id, provider]) => {
|
|
142
|
-
const fills = await provider.getOrderFills(params);
|
|
142
|
+
const fills = await provider.getOrderFills(params, options);
|
|
143
143
|
return fills.map((fill) => ({ ...fill, providerId: id }));
|
|
144
144
|
}));
|
|
145
145
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_extractSuccessfulResults).call(this, results, 'getOrderFills').flat();
|
|
@@ -151,9 +151,9 @@ class AggregatedPerpsProvider {
|
|
|
151
151
|
}));
|
|
152
152
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_extractSuccessfulResults).call(this, results, 'getOrFetchFills').flat();
|
|
153
153
|
}
|
|
154
|
-
async getOrders(params) {
|
|
154
|
+
async getOrders(params, options) {
|
|
155
155
|
const results = await Promise.allSettled(__classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_getActiveProviders).call(this).map(async ([id, provider]) => {
|
|
156
|
-
const orders = await provider.getOrders(params);
|
|
156
|
+
const orders = await provider.getOrders(params, options);
|
|
157
157
|
return orders.map((order) => ({ ...order, providerId: id }));
|
|
158
158
|
}));
|
|
159
159
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_extractSuccessfulResults).call(this, results, 'getOrders').flat();
|
|
@@ -165,9 +165,9 @@ class AggregatedPerpsProvider {
|
|
|
165
165
|
}));
|
|
166
166
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_extractSuccessfulResults).call(this, results, 'getOpenOrders').flat();
|
|
167
167
|
}
|
|
168
|
-
async getFunding(params) {
|
|
168
|
+
async getFunding(params, options) {
|
|
169
169
|
const results = await Promise.allSettled(__classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_getActiveProviders).call(this).map(async ([_providerId, provider]) => {
|
|
170
|
-
const funding = await provider.getFunding(params);
|
|
170
|
+
const funding = await provider.getFunding(params, options);
|
|
171
171
|
// Funding type doesn't have providerId - we could add it if needed
|
|
172
172
|
return funding;
|
|
173
173
|
}));
|
|
@@ -190,6 +190,16 @@ class AggregatedPerpsProvider {
|
|
|
190
190
|
// Delegate to default provider (protocol-specific)
|
|
191
191
|
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_getDefaultProvider).call(this).getUserNonFundingLedgerUpdates(params);
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Resolve the currently selected CAIP account identifier. Accounts are
|
|
195
|
+
* shared across sub-providers (same InternalAccountController), so the
|
|
196
|
+
* default provider's view is authoritative.
|
|
197
|
+
*
|
|
198
|
+
* @returns Resolved CAIP account id from the default sub-provider.
|
|
199
|
+
*/
|
|
200
|
+
async getCurrentAccountId() {
|
|
201
|
+
return __classPrivateFieldGet(this, _AggregatedPerpsProvider_instances, "m", _AggregatedPerpsProvider_getDefaultProvider).call(this).getCurrentAccountId();
|
|
202
|
+
}
|
|
193
203
|
/**
|
|
194
204
|
* Get user history from all providers.
|
|
195
205
|
*
|