@metamask-previews/perps-controller 25.0.0-preview-2a2b320ba → 25.0.0-preview-4046c2f69

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.
@@ -130,7 +130,7 @@ Code: `src/services/`; `src/PerpsController.ts` constructor.
130
130
 
131
131
  Aggregated reads return the original venue rows. A market served directly from a v4 snapshot carries the provider ID that Core validated. Clients can call `groupMarketsByMarketKey(rows, defaultProvider)` for display. Rows group when they share a backend key and each explicitly has `priceScale: 1`. Each group puts the default venue first when present. Use `rowId` as the display row identity and the selected venue's `providerId` and `symbol` for charts and trading. Rows with missing keys or with missing or non-unit scales remain separate and omit `marketKey`. Saving one stores its bare symbol when it is on the legacy venue, otherwise `venue:<provider>:<symbol>`, never a backend key.
132
132
 
133
- `toggleWatchlistMarket`, `isWatchlistMarket` and `recordMarketViewed` take an optional backend key from a unit-scale row. Pass the original group's `venues` as the third argument and the venue that owned saved symbols as the fourth (`legacyProvider`, default HyperLiquid, the same default as `resolveSavedPerpsMarkets`). These actions also match each tagged group row with the same backend key and `priceScale: 1` by the entry it would have saved ungrouped: its symbol on the legacy venue, otherwise `venue:<provider>:<symbol>`. A favorite or recent saved before the row grouped is replaced with the keyed entry. When opening a saved item, pass the saved strings and ungrouped venue rows to `resolveSavedPerpsMarkets`. A legacy symbol requires an exact match on its original venue and stays unresolved while that row is unavailable. A `venue:` reference opens only that venue's row with the same symbol. The resolver defaults legacy ownership to HyperLiquid and accepts the prior venue for entries saved on Lighter. New keyed entries look for unit-scale rows and prefer the configured default venue.
133
+ `toggleWatchlistMarket`, `isWatchlistMarket` and `recordMarketViewed` take an optional backend key from a unit-scale row. Pass the original group's `venues` as the third argument and the venue that owned saved symbols as the fourth (`legacyProvider`, default HyperLiquid, the same default as `resolveSavedPerpsMarkets`). These actions also match each tagged group row with the same backend key and `priceScale: 1` by the entry it would have saved ungrouped: its symbol on the legacy venue, otherwise `venue:<provider>:<symbol>`. A favorite or recent saved before the row grouped is replaced with the keyed entry. When opening a saved item, pass the saved strings and ungrouped venue rows to `resolveSavedPerpsMarkets`. A legacy symbol requires an exact match on its original venue and stays unresolved while that row is unavailable. A `venue:` reference opens only that venue's row with the same symbol. The resolver defaults legacy ownership to HyperLiquid and accepts the prior venue for entries saved on Lighter. New keyed entries look for unit-scale rows and prefer the configured default venue. The HyperLiquid watchlist syncs to AuthenticatedUserStorageService, where Mobile and Extension match entries by symbol, so in that mode a grouped favorite is saved by its venue symbol and keeps the backend key only as an alias. `market-key:` and `venue:` entries stay local and are never written to AUS.
134
134
 
135
135
  With snapshots configured, a missing or expired venue slice invalidates the aggregated preload. The client can fetch a fresh list from Core.
136
136
 
@@ -75,6 +75,10 @@ Pass tiers from `resolveHyperLiquidMarginTiers`; do not assume a default max lev
75
75
  - For an existing position, `maintenanceMargin` is `crossMarginSummary.maintenanceMargin` (it already includes the position) or `estimateCrossMaintenanceMargin` over every cross position.
76
76
  - For an opening order preview, require a current position snapshot confirming there is no existing position in the target market. Keep Mobile's guard for an existing position and for Scale orders. Pass the order price as `markPrice` and the order size as `positionSize`, and add the new position's maintenance at that price to the account's existing maintenance. Show the preview as unavailable when the snapshot is missing or the order adds to, reduces, or flips an existing position.
77
77
 
78
+ ### Open position liquidation price
79
+
80
+ `Position.liquidationPrice` is the venue's figure. `null` on a Cross position means no price reachable at the current account value liquidates it: the cross collateral covers the position's maintenance margin at every positive price. Render it as no liquidation risk (for example "None" or an em dash), never as 0 and never as a loading or error state. It can become a price again when account value falls or the position grows.
81
+
78
82
  ### Controller liquidation previews
79
83
 
80
84
  `PerpsController.calculateLiquidationPrice` and `PerpsController:calculateLiquidationPrice` return `Promise<string>`. For a HyperLiquid cross opening, pass `marginType: 'cross'`, `asset`, `entryPrice`, `direction`, `leverage` and a positive `positionSize` in base units. In aggregated mode include `providerId: 'hyperliquid'`. The provider reads the selected wallet's current positions and market tiers. Unified uses shared cross equity and spot USDC. Standard uses only the main DEX's cross pool. Standard HIP-3 openings and other account modes are unavailable in this preview.
@@ -53,9 +53,9 @@ Code: `src/providers/HyperLiquidProvider.ts` `validateOrder`, `#placeOrder`, `#p
53
53
  | Then at most 5 significant figures | `DECIMAL_PRECISION_CONFIG.MaxSignificantFigures` (5) |
54
54
  | Sizes keep `szDecimals`, trailing zeros removed; TP/SL and reduce-only sizes are floored | |
55
55
 
56
- `formatHyperLiquidPrice` does not check tick divisibility. It is exported from the package.
56
+ Both price caps round half up on the price's decimal form, as hyperliquid.xyz does: `69.9425` becomes `69.943`. `formatHyperLiquidPrice` and `roundPerpsPrice` share this rounding. `formatHyperLiquidPrice` does not check tick divisibility. It is exported from the package.
57
57
 
58
- Code: `src/utils/hyperLiquidAdapter.ts` `formatHyperLiquidPrice`, `formatHyperLiquidSize`; `src/utils/orderCalculations.ts` `floorToSizeDecimals`, `formatPartialTpslSize`.
58
+ Code: `src/utils/hyperLiquidAdapter.ts` `formatHyperLiquidPrice`, `formatHyperLiquidSize`; `src/utils/pricePrecision.ts` `roundToSignificantFiguresGrid`; `src/utils/orderCalculations.ts` `floorToSizeDecimals`, `formatPartialTpslSize`.
59
59
 
60
60
  ## Asset IDs
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/perps-controller",
3
- "version": "25.0.0-preview-2a2b320ba",
3
+ "version": "25.0.0-preview-4046c2f69",
4
4
  "description": "Controller for perpetual trading functionality in MetaMask",
5
5
  "keywords": [
6
6
  "Ethereum",