@lifi/perps-sdk-provider-hyperliquid 6.0.0 → 6.0.2

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.
Files changed (203) hide show
  1. package/dist/cjs/HyperliquidProvider.d.ts.map +1 -1
  2. package/dist/cjs/HyperliquidProvider.js.map +1 -1
  3. package/dist/cjs/services/getActivity.d.ts.map +1 -1
  4. package/dist/cjs/services/getActivity.js.map +1 -1
  5. package/dist/cjs/services/getFills.d.ts.map +1 -1
  6. package/dist/cjs/services/getFills.js.map +1 -1
  7. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  8. package/dist/cjs/services/getOrders.js.map +1 -1
  9. package/dist/cjs/signers/HyperliquidAgentStore.d.ts.map +1 -1
  10. package/dist/cjs/signers/HyperliquidAgentStore.js.map +1 -1
  11. package/dist/cjs/signers/signActions.d.ts.map +1 -1
  12. package/dist/cjs/signers/signActions.js.map +1 -1
  13. package/dist/cjs/types/account.d.ts.map +1 -1
  14. package/dist/cjs/types/account.js.map +1 -1
  15. package/dist/cjs/types/action.d.ts.map +1 -1
  16. package/dist/cjs/types/action.js.map +1 -1
  17. package/dist/cjs/types/asset.d.ts.map +1 -1
  18. package/dist/cjs/types/fill.d.ts.map +1 -1
  19. package/dist/cjs/types/ledger.d.ts.map +1 -1
  20. package/dist/cjs/types/ledger.js.map +1 -1
  21. package/dist/cjs/types/order.d.ts.map +1 -1
  22. package/dist/cjs/types/ws.d.ts.map +1 -1
  23. package/dist/cjs/utils/assetId.d.ts.map +1 -1
  24. package/dist/cjs/utils/assetId.js.map +1 -1
  25. package/dist/cjs/utils/assetLogo.d.ts.map +1 -1
  26. package/dist/cjs/utils/assetLogo.js.map +1 -1
  27. package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  28. package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -1
  29. package/dist/cjs/utils/infoClient.d.ts.map +1 -1
  30. package/dist/cjs/utils/infoClient.js.map +1 -1
  31. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  32. package/dist/cjs/utils/mapActivity.js +13 -10
  33. package/dist/cjs/utils/mapActivity.js.map +1 -1
  34. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  35. package/dist/cjs/utils/mapFill.js.map +1 -1
  36. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  37. package/dist/cjs/utils/mapOrder.js.map +1 -1
  38. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  39. package/dist/cjs/utils/mapPosition.js.map +1 -1
  40. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  41. package/dist/cjs/utils/spotBalance.js.map +1 -1
  42. package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
  43. package/dist/cjs/utils/spotCollateral.js.map +1 -1
  44. package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
  45. package/dist/cjs/utils/transferMargin.js +1 -2
  46. package/dist/cjs/utils/transferMargin.js.map +1 -1
  47. package/dist/esm/HyperliquidProvider.d.ts +14 -4
  48. package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
  49. package/dist/esm/HyperliquidProvider.js.map +1 -1
  50. package/dist/esm/services/getActivity.d.ts +5 -1
  51. package/dist/esm/services/getActivity.d.ts.map +1 -1
  52. package/dist/esm/services/getActivity.js.map +1 -1
  53. package/dist/esm/services/getFills.d.ts +4 -3
  54. package/dist/esm/services/getFills.d.ts.map +1 -1
  55. package/dist/esm/services/getFills.js.map +1 -1
  56. package/dist/esm/services/getOrders.d.ts +2 -1
  57. package/dist/esm/services/getOrders.d.ts.map +1 -1
  58. package/dist/esm/services/getOrders.js.map +1 -1
  59. package/dist/esm/services/getPositions.d.ts +2 -2
  60. package/dist/esm/services/getPositions.d.ts.map +1 -1
  61. package/dist/esm/signers/HyperliquidAgentStore.d.ts +3 -3
  62. package/dist/esm/signers/HyperliquidAgentStore.d.ts.map +1 -1
  63. package/dist/esm/signers/HyperliquidAgentStore.js +1 -0
  64. package/dist/esm/signers/HyperliquidAgentStore.js.map +1 -1
  65. package/dist/esm/signers/signActions.d.ts +8 -6
  66. package/dist/esm/signers/signActions.d.ts.map +1 -1
  67. package/dist/esm/signers/signActions.js +8 -6
  68. package/dist/esm/signers/signActions.js.map +1 -1
  69. package/dist/esm/types/account.d.ts +51 -8
  70. package/dist/esm/types/account.d.ts.map +1 -1
  71. package/dist/esm/types/account.js.map +1 -1
  72. package/dist/esm/types/action.d.ts +28 -10
  73. package/dist/esm/types/action.d.ts.map +1 -1
  74. package/dist/esm/types/action.js +7 -7
  75. package/dist/esm/types/action.js.map +1 -1
  76. package/dist/esm/types/asset.d.ts +60 -15
  77. package/dist/esm/types/asset.d.ts.map +1 -1
  78. package/dist/esm/types/fill.d.ts +9 -3
  79. package/dist/esm/types/fill.d.ts.map +1 -1
  80. package/dist/esm/types/ledger.d.ts +24 -6
  81. package/dist/esm/types/ledger.d.ts.map +1 -1
  82. package/dist/esm/types/ledger.js.map +1 -1
  83. package/dist/esm/types/order.d.ts +19 -5
  84. package/dist/esm/types/order.d.ts.map +1 -1
  85. package/dist/esm/types/ws.d.ts +43 -14
  86. package/dist/esm/types/ws.d.ts.map +1 -1
  87. package/dist/esm/utils/assetId.d.ts +7 -7
  88. package/dist/esm/utils/assetId.d.ts.map +1 -1
  89. package/dist/esm/utils/assetId.js +7 -7
  90. package/dist/esm/utils/assetId.js.map +1 -1
  91. package/dist/esm/utils/assetLogo.d.ts +15 -13
  92. package/dist/esm/utils/assetLogo.d.ts.map +1 -1
  93. package/dist/esm/utils/assetLogo.js +15 -13
  94. package/dist/esm/utils/assetLogo.js.map +1 -1
  95. package/dist/esm/utils/decodeFastAssetCtxs.d.ts +7 -1
  96. package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  97. package/dist/esm/utils/decodeFastAssetCtxs.js +7 -1
  98. package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -1
  99. package/dist/esm/utils/infoClient.d.ts +6 -1
  100. package/dist/esm/utils/infoClient.d.ts.map +1 -1
  101. package/dist/esm/utils/infoClient.js.map +1 -1
  102. package/dist/esm/utils/mapActivity.d.ts +10 -1
  103. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  104. package/dist/esm/utils/mapActivity.js +23 -11
  105. package/dist/esm/utils/mapActivity.js.map +1 -1
  106. package/dist/esm/utils/mapFill.d.ts +1 -0
  107. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  108. package/dist/esm/utils/mapFill.js +1 -0
  109. package/dist/esm/utils/mapFill.js.map +1 -1
  110. package/dist/esm/utils/mapOrder.d.ts +15 -4
  111. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  112. package/dist/esm/utils/mapOrder.js +15 -4
  113. package/dist/esm/utils/mapOrder.js.map +1 -1
  114. package/dist/esm/utils/mapPosition.d.ts +6 -1
  115. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  116. package/dist/esm/utils/mapPosition.js +6 -1
  117. package/dist/esm/utils/mapPosition.js.map +1 -1
  118. package/dist/esm/utils/spotBalance.d.ts +9 -10
  119. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  120. package/dist/esm/utils/spotBalance.js +9 -10
  121. package/dist/esm/utils/spotBalance.js.map +1 -1
  122. package/dist/esm/utils/spotCollateral.d.ts +9 -5
  123. package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
  124. package/dist/esm/utils/spotCollateral.js +4 -4
  125. package/dist/esm/utils/spotCollateral.js.map +1 -1
  126. package/dist/esm/utils/transferMargin.d.ts.map +1 -1
  127. package/dist/esm/utils/transferMargin.js +2 -3
  128. package/dist/esm/utils/transferMargin.js.map +1 -1
  129. package/dist/types/HyperliquidProvider.d.ts +14 -4
  130. package/dist/types/HyperliquidProvider.d.ts.map +1 -1
  131. package/dist/types/services/getActivity.d.ts +5 -1
  132. package/dist/types/services/getActivity.d.ts.map +1 -1
  133. package/dist/types/services/getFills.d.ts +4 -3
  134. package/dist/types/services/getFills.d.ts.map +1 -1
  135. package/dist/types/services/getOrders.d.ts +2 -1
  136. package/dist/types/services/getOrders.d.ts.map +1 -1
  137. package/dist/types/services/getPositions.d.ts +2 -2
  138. package/dist/types/services/getPositions.d.ts.map +1 -1
  139. package/dist/types/signers/HyperliquidAgentStore.d.ts +3 -3
  140. package/dist/types/signers/HyperliquidAgentStore.d.ts.map +1 -1
  141. package/dist/types/signers/signActions.d.ts +8 -6
  142. package/dist/types/signers/signActions.d.ts.map +1 -1
  143. package/dist/types/types/account.d.ts +51 -8
  144. package/dist/types/types/account.d.ts.map +1 -1
  145. package/dist/types/types/action.d.ts +28 -10
  146. package/dist/types/types/action.d.ts.map +1 -1
  147. package/dist/types/types/asset.d.ts +60 -15
  148. package/dist/types/types/asset.d.ts.map +1 -1
  149. package/dist/types/types/fill.d.ts +9 -3
  150. package/dist/types/types/fill.d.ts.map +1 -1
  151. package/dist/types/types/ledger.d.ts +24 -6
  152. package/dist/types/types/ledger.d.ts.map +1 -1
  153. package/dist/types/types/order.d.ts +19 -5
  154. package/dist/types/types/order.d.ts.map +1 -1
  155. package/dist/types/types/ws.d.ts +43 -14
  156. package/dist/types/types/ws.d.ts.map +1 -1
  157. package/dist/types/utils/assetId.d.ts +7 -7
  158. package/dist/types/utils/assetId.d.ts.map +1 -1
  159. package/dist/types/utils/assetLogo.d.ts +15 -13
  160. package/dist/types/utils/assetLogo.d.ts.map +1 -1
  161. package/dist/types/utils/decodeFastAssetCtxs.d.ts +7 -1
  162. package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  163. package/dist/types/utils/infoClient.d.ts +6 -1
  164. package/dist/types/utils/infoClient.d.ts.map +1 -1
  165. package/dist/types/utils/mapActivity.d.ts +10 -1
  166. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  167. package/dist/types/utils/mapFill.d.ts +1 -0
  168. package/dist/types/utils/mapFill.d.ts.map +1 -1
  169. package/dist/types/utils/mapOrder.d.ts +15 -4
  170. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  171. package/dist/types/utils/mapPosition.d.ts +6 -1
  172. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  173. package/dist/types/utils/spotBalance.d.ts +9 -10
  174. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  175. package/dist/types/utils/spotCollateral.d.ts +9 -5
  176. package/dist/types/utils/spotCollateral.d.ts.map +1 -1
  177. package/dist/types/utils/transferMargin.d.ts.map +1 -1
  178. package/package.json +3 -3
  179. package/src/HyperliquidProvider.ts +14 -4
  180. package/src/services/getActivity.ts +5 -1
  181. package/src/services/getFills.ts +4 -3
  182. package/src/services/getOrders.ts +2 -1
  183. package/src/services/getPositions.ts +2 -2
  184. package/src/signers/HyperliquidAgentStore.ts +3 -3
  185. package/src/signers/signActions.ts +8 -6
  186. package/src/types/account.ts +51 -8
  187. package/src/types/action.ts +28 -10
  188. package/src/types/asset.ts +60 -15
  189. package/src/types/fill.ts +9 -3
  190. package/src/types/ledger.ts +24 -6
  191. package/src/types/order.ts +19 -5
  192. package/src/types/ws.ts +43 -14
  193. package/src/utils/assetId.ts +7 -7
  194. package/src/utils/assetLogo.ts +15 -13
  195. package/src/utils/decodeFastAssetCtxs.ts +7 -1
  196. package/src/utils/infoClient.ts +6 -1
  197. package/src/utils/mapActivity.ts +23 -11
  198. package/src/utils/mapFill.ts +1 -0
  199. package/src/utils/mapOrder.ts +15 -4
  200. package/src/utils/mapPosition.ts +6 -1
  201. package/src/utils/spotBalance.ts +9 -10
  202. package/src/utils/spotCollateral.ts +9 -5
  203. package/src/utils/transferMargin.ts +2 -6
@@ -47,7 +47,12 @@ const UNIT_UNDERLYING_SYMBOL: Readonly<Record<string, string>> = {
47
47
  UANSEM: 'ANSEM',
48
48
  }
49
49
 
50
- /** Token `name`s of the Unit-bridged HL spot assets. */
50
+ /**
51
+ * Names of Unit-bridged Hyperliquid spot tokens recognized by the logo
52
+ * resolver. The set is read-only and is intended for callers that need to
53
+ * distinguish Unit balances before resolving their icons.
54
+ * @public
55
+ */
51
56
  export const UNIT_TOKEN_NAMES: ReadonlySet<string> = new Set(
52
57
  Object.keys(UNIT_UNDERLYING_SYMBOL)
53
58
  )
@@ -58,24 +63,21 @@ const unitSpotLogoURI = (name: string): string => {
58
63
  return underlying === undefined ? '' : `${HL_COIN_CDN}/${underlying}.svg`
59
64
  }
60
65
 
61
- /** Return `asset` with its `logoURI` replaced when a display-symbol override exists. */
66
+ /**
67
+ * Apply the provider's known symbol-specific logo corrections to an asset.
68
+ * Returns the original object when no override exists.
69
+ * @public
70
+ */
62
71
  export const applyLogoOverride = (asset: Asset): Asset => {
63
72
  const override = BASE_ASSET_LOGO_OVERRIDES[asset.displaySymbol]
64
73
  return override === undefined ? asset : { ...asset, logoURI: override }
65
74
  }
66
75
 
67
76
  /**
68
- * Override-aware logo URI for a Hyperliquid spot token. Base rule is
69
- * `coins/${name}_spot.svg`; a Unit-bridged token (`fullName` starts with
70
- * "Unit") resolves to its underlying's icon instead; the override table wins
71
- * over both.
72
- *
73
- * When `fullName` is absent — spot *balances* (`HlSpotBalance`) carry no
74
- * `fullName` and this issue deliberately does not fetch `spotMeta` on the
75
- * account path — the derivation degrades to the symbol-keyed override + base
76
- * `_spot` rule, so a Unit-bridged balance uses the base rule rather than its
77
- * underlying's icon. The registry path (which has `fullName`) keeps full Unit
78
- * resolution.
77
+ * Resolve the logo URI for a Hyperliquid spot token. Unit-bridged tokens use
78
+ * the underlying symbol's icon when `fullName` starts with `'Unit'`; otherwise
79
+ * the base URI is `coins/${name}_spot.svg`. Known symbol overrides win.
80
+ * @public
79
81
  */
80
82
  export const spotLogoURI = (name: string, fullName?: string | null): string => {
81
83
  const base = fullName?.startsWith('Unit')
@@ -1,6 +1,11 @@
1
1
  import type { HlWsFastAssetCtx } from '../types/index.js'
2
2
 
3
- /** Decode a base64 + raw-DEFLATE (RFC 1951) payload into parsed JSON. */
3
+ /**
4
+ * Decode a base64-encoded raw-DEFLATE payload and parse its UTF-8 JSON body.
5
+ * @typeParam T - Expected shape of the decoded JSON value.
6
+ * @throws If decompression or JSON parsing fails.
7
+ * @public
8
+ */
4
9
  export async function decodeCompressedJson<T>(base64: string): Promise<T> {
5
10
  const binary = atob(base64)
6
11
  const bytes = new Uint8Array(binary.length)
@@ -24,6 +29,7 @@ export async function decodeCompressedJson<T>(base64: string): Promise<T> {
24
29
  * (Node 18+, modern browsers), so no dependency is needed.
25
30
  *
26
31
  * @throws If the input is not valid base64 / raw-DEFLATE / JSON.
32
+ * @public
27
33
  */
28
34
  export async function decodeFastAssetCtxs(
29
35
  base64: string
@@ -50,7 +50,12 @@ export const HYPERLIQUID_RETRY_DEFAULTS: ResolvedRetryPolicy = {
50
50
  },
51
51
  }
52
52
 
53
- /** @public */
53
+ /**
54
+ * Transport options for a direct Hyperliquid `/info` request. `policy`
55
+ * controls retries, `signal` cancels the request, and `fetchImpl` overrides
56
+ * the runtime's global `fetch` implementation.
57
+ * @public
58
+ */
54
59
  export interface InfoRequestOptions {
55
60
  signal?: AbortSignal
56
61
  policy?: ResolvedRetryPolicy
@@ -165,18 +165,30 @@ export const mapLedgerEntry = (
165
165
  }
166
166
  }
167
167
 
168
- /** @public */
168
+ /**
169
+ * Map a Hyperliquid funding ledger update to a normalized funding activity.
170
+ * `amount`, `positionSize`, and `fundingRate` retain the upstream decimal
171
+ * strings; `resolveMarket` supplies the provider-agnostic market metadata.
172
+ *
173
+ * `userFunding` entries all carry the zero hash, so a deterministic
174
+ * `funding:<coin>:<ISO time>` id is synthesized — funding accrues at most
175
+ * once per coin per hourly settlement, so the pair is unique per account.
176
+ * @public
177
+ */
169
178
  export const mapFundingActivity = (
170
179
  entry: HlFundingUpdate,
171
180
  providerKey: string,
172
181
  resolveMarket: (coin: string) => MarketDisplay
173
- ): FundingActivity => ({
174
- id: entry.hash,
175
- provider: providerKey,
176
- timestamp: new Date(entry.time).toISOString(),
177
- type: ActivityType.FUNDING,
178
- market: resolveMarket(entry.delta.coin),
179
- amount: entry.delta.usdc,
180
- positionSize: entry.delta.szi,
181
- fundingRate: entry.delta.fundingRate,
182
- })
182
+ ): FundingActivity => {
183
+ const timestamp = new Date(entry.time).toISOString()
184
+ return {
185
+ id: `funding:${entry.delta.coin}:${timestamp}`,
186
+ provider: providerKey,
187
+ timestamp,
188
+ type: ActivityType.FUNDING,
189
+ market: resolveMarket(entry.delta.coin),
190
+ amount: entry.delta.usdc,
191
+ positionSize: entry.delta.szi,
192
+ fundingRate: entry.delta.fundingRate,
193
+ }
194
+ }
@@ -14,6 +14,7 @@ import {
14
14
  import { SPOT_MARKET_ID } from '../constants.js'
15
15
  import type { HlUserFill } from '../types/index.js'
16
16
 
17
+ /** Re-export the shared fill-position classifier used by Hyperliquid mappings. @public */
17
18
  export { classifyFillFromPosition }
18
19
 
19
20
  /**
@@ -34,7 +34,7 @@ export const mapOrderType = (orderType: string): OrderType => {
34
34
  }
35
35
  }
36
36
 
37
- /** @public */
37
+ /** Return whether an SDK order type represents a take-profit or stop trigger. @public */
38
38
  export const isTriggerType = (type: OrderType): boolean =>
39
39
  type === OrderType.TAKE_PROFIT_MARKET ||
40
40
  type === OrderType.TAKE_PROFIT_LIMIT ||
@@ -83,7 +83,11 @@ export const isTriggerOrder = (
83
83
  return isTriggerType(mapOrderType(o.orderType))
84
84
  }
85
85
 
86
- /** @public */
86
+ /**
87
+ * Map an open Hyperliquid order to the SDK's normalized open-order shape.
88
+ * Numeric IDs become strings and wire millisecond timestamps become ISO dates.
89
+ * @public
90
+ */
87
91
  export const mapOpenOrder = (
88
92
  o: HlFrontendOpenOrder,
89
93
  market: MarketDisplay
@@ -102,7 +106,10 @@ export const mapOpenOrder = (
102
106
  createdAt: new Date(o.timestamp).toISOString(),
103
107
  })
104
108
 
105
- /** @public */
109
+ /**
110
+ * Map a Hyperliquid trigger/TP-SL order to the SDK's trigger-order shape.
111
+ * @public
112
+ */
106
113
  export const mapTriggerOrder = (
107
114
  o: HlFrontendOpenOrder,
108
115
  market: MarketDisplay
@@ -232,7 +239,11 @@ const mapTimeInForce = (tif: string | undefined): TimeInForce | undefined => {
232
239
  }
233
240
  }
234
241
 
235
- /** @public */
242
+ /**
243
+ * Map an `orderStatus` detail to the SDK's normalized order shape, preserving
244
+ * decimal size/price strings and translating status, side, and time-in-force.
245
+ * @public
246
+ */
236
247
  export const mapOrder = (
237
248
  detail: HlOrderDetail,
238
249
  market: MarketDisplay
@@ -12,7 +12,12 @@ import type { HlAssetPosition } from '../types/index.js'
12
12
  export const isOpenAssetPosition = (ap: HlAssetPosition): boolean =>
13
13
  Number.parseFloat(ap.position.szi) !== 0
14
14
 
15
- /** @public */
15
+ /**
16
+ * Map a non-zero Hyperliquid position payload to the SDK's normalized
17
+ * position. Signed wire size determines side; decimal strings remain strings
18
+ * in the normalized response.
19
+ * @public
20
+ */
16
21
  export const mapPosition = (
17
22
  ap: HlAssetPosition,
18
23
  market: PerpsMarketDisplay
@@ -6,10 +6,10 @@ import { spotLogoURI } from './assetLogo.js'
6
6
  import { coinAsset } from './marketDisplay.js'
7
7
 
8
8
  /**
9
- * USD price keyed by spot token index: each spot market's live USD price
10
- * (from `priceByMarketId`, keyed by `Market.id`) under its base-asset id, and
11
- * every market's quote-asset id at $1. A spot market absent from
12
- * `priceByMarketId` values its token at 0.
9
+ * Build USD prices keyed by spot token asset ID. Base tokens use the supplied
10
+ * market mark price; quote tokens default to exactly `$1`; missing base prices
11
+ * default to `0`.
12
+ * @public
13
13
  */
14
14
  export const spotPriceById = (
15
15
  markets: readonly Market[],
@@ -30,11 +30,10 @@ export const spotPriceById = (
30
30
  }
31
31
 
32
32
  /**
33
- * The held spot {@link Asset} for an HL balance: the venue token index
34
- * (`b.token`) as `Asset.id` equal to that token's spot `Market.baseAsset.id`
35
- * with display fields derived from the coin and the override-aware spot logo.
36
- * `HlSpotBalance` carries no `fullName`, so Unit-bridged balances take the base
37
- * `_spot` rule (see {@link spotLogoURI}).
33
+ * Convert a Hyperliquid spot balance's numeric token index into an SDK asset.
34
+ * The balance payload has no `fullName`, so logo resolution uses the base
35
+ * `_spot` URI rule rather than Unit-underlying lookup.
36
+ * @public
38
37
  */
39
38
  export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
40
39
  ...coinAsset(b.coin),
@@ -42,7 +41,7 @@ export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
42
41
  logoURI: spotLogoURI(b.coin),
43
42
  })
44
43
 
45
- /** Assemble a typed spot {@link Balance} from its resolved asset and raw size. */
44
+ /** Assemble a typed spot {@link Balance}; `total` is native token units and its USD value uses `priceById`. @public */
46
45
  export const spotBalance = (
47
46
  asset: Asset,
48
47
  total: string,
@@ -13,17 +13,21 @@ const PORTFOLIO_MARGIN_LTV: Readonly<Record<string, number>> = {
13
13
  UBTC: 0.5,
14
14
  }
15
15
 
16
- /** @internal */
16
+ /**
17
+ * Result of {@link partitionSpotBalances}: balances that count toward
18
+ * collateral and balances treated as ordinary holdings.
19
+ * @public
20
+ */
17
21
  export interface SpotPartition {
18
22
  collateralBalances: Balance[]
19
23
  balances: Balance[]
20
24
  }
21
25
 
22
26
  /**
23
- * Split spot balances into margin collateral and flat holdings. A balance is
24
- * collateral when its token is a category quote asset (full value) or, under
25
- * portfolio margin, an LTV-weighted asset (HYPE/BTC); everything else is a
26
- * flat holding.
27
+ * Partition spot balances into collateral and ordinary holdings. Quote assets
28
+ * are full-value collateral; portfolio-margin-supported assets retain their
29
+ * LTV as `collateralWeight`.
30
+ * @public
27
31
  */
28
32
  export const partitionSpotBalances = (
29
33
  spotBalances: readonly Balance[],
@@ -1,10 +1,9 @@
1
1
  import { PerpsError } from '@lifi/perps-sdk'
2
2
  import {
3
- MarginMode,
4
3
  PerpsErrorCode,
5
4
  type Position,
6
- PositionMarginAdjustment,
7
5
  type PositionMarginConstraints,
6
+ positionSupportsMarginAdjustment,
8
7
  } from '@lifi/perps-types'
9
8
  import Big from 'big.js'
10
9
 
@@ -44,10 +43,7 @@ function positivePositionAmount(value: string, field: string): Big {
44
43
  export function positionMarginConstraints(
45
44
  position: Position
46
45
  ): PositionMarginConstraints | undefined {
47
- if (
48
- position.marginMode !== MarginMode.ISOLATED ||
49
- position.market.positionMarginAdjustment === PositionMarginAdjustment.NONE
50
- ) {
46
+ if (!positionSupportsMarginAdjustment(position)) {
51
47
  return undefined
52
48
  }
53
49
  const initialMargin = positivePositionAmount(