@lifi/perps-sdk-provider-lighter 8.0.0 → 8.0.1

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 (148) hide show
  1. package/dist/cjs/constants.d.ts.map +1 -1
  2. package/dist/cjs/constants.js.map +1 -1
  3. package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -1
  4. package/dist/cjs/signers/LighterKeyStore.js.map +1 -1
  5. package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  6. package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -1
  7. package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
  8. package/dist/cjs/signers/LighterSigner.js.map +1 -1
  9. package/dist/cjs/signers/createAuthToken.d.ts.map +1 -1
  10. package/dist/cjs/signers/createAuthToken.js.map +1 -1
  11. package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
  12. package/dist/cjs/signers/wasmLoader.js.map +1 -1
  13. package/dist/cjs/types/account.d.ts.map +1 -1
  14. package/dist/cjs/types/action.d.ts.map +1 -1
  15. package/dist/cjs/types/action.js.map +1 -1
  16. package/dist/cjs/types/activity.d.ts.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/order.d.ts.map +1 -1
  20. package/dist/cjs/types/submit.d.ts.map +1 -1
  21. package/dist/cjs/types/ws.d.ts.map +1 -1
  22. package/dist/cjs/utils/lighterAsset.d.ts.map +1 -1
  23. package/dist/cjs/utils/lighterAsset.js.map +1 -1
  24. package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -1
  25. package/dist/cjs/utils/ohlcvInterval.js.map +1 -1
  26. package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
  27. package/dist/cjs/utils/transferMargin.js +1 -2
  28. package/dist/cjs/utils/transferMargin.js.map +1 -1
  29. package/dist/cjs/utils/wireEncoding.d.ts.map +1 -1
  30. package/dist/cjs/utils/wireEncoding.js.map +1 -1
  31. package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
  32. package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
  33. package/dist/esm/constants.d.ts +15 -2
  34. package/dist/esm/constants.d.ts.map +1 -1
  35. package/dist/esm/constants.js +15 -2
  36. package/dist/esm/constants.js.map +1 -1
  37. package/dist/esm/signers/LighterKeyStore.d.ts +31 -2
  38. package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -1
  39. package/dist/esm/signers/LighterKeyStore.js +24 -1
  40. package/dist/esm/signers/LighterKeyStore.js.map +1 -1
  41. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +23 -3
  42. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  43. package/dist/esm/signers/LighterReadOnlyTokenManager.js +4 -0
  44. package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -1
  45. package/dist/esm/signers/LighterSigner.d.ts +49 -7
  46. package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
  47. package/dist/esm/signers/LighterSigner.js +11 -1
  48. package/dist/esm/signers/LighterSigner.js.map +1 -1
  49. package/dist/esm/signers/createAuthToken.d.ts +8 -2
  50. package/dist/esm/signers/createAuthToken.d.ts.map +1 -1
  51. package/dist/esm/signers/createAuthToken.js.map +1 -1
  52. package/dist/esm/signers/wasmLoader.d.ts +14 -2
  53. package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
  54. package/dist/esm/signers/wasmLoader.js.map +1 -1
  55. package/dist/esm/types/account.d.ts +58 -8
  56. package/dist/esm/types/account.d.ts.map +1 -1
  57. package/dist/esm/types/action.d.ts +72 -18
  58. package/dist/esm/types/action.d.ts.map +1 -1
  59. package/dist/esm/types/action.js +72 -18
  60. package/dist/esm/types/action.js.map +1 -1
  61. package/dist/esm/types/activity.d.ts +64 -10
  62. package/dist/esm/types/activity.d.ts.map +1 -1
  63. package/dist/esm/types/asset.d.ts +72 -12
  64. package/dist/esm/types/asset.d.ts.map +1 -1
  65. package/dist/esm/types/fill.d.ts +14 -2
  66. package/dist/esm/types/fill.d.ts.map +1 -1
  67. package/dist/esm/types/order.d.ts +27 -4
  68. package/dist/esm/types/order.d.ts.map +1 -1
  69. package/dist/esm/types/submit.d.ts +26 -4
  70. package/dist/esm/types/submit.d.ts.map +1 -1
  71. package/dist/esm/types/ws.d.ts +56 -8
  72. package/dist/esm/types/ws.d.ts.map +1 -1
  73. package/dist/esm/utils/lighterAsset.d.ts +7 -1
  74. package/dist/esm/utils/lighterAsset.d.ts.map +1 -1
  75. package/dist/esm/utils/lighterAsset.js +7 -1
  76. package/dist/esm/utils/lighterAsset.js.map +1 -1
  77. package/dist/esm/utils/ohlcvInterval.d.ts +6 -1
  78. package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -1
  79. package/dist/esm/utils/ohlcvInterval.js +6 -1
  80. package/dist/esm/utils/ohlcvInterval.js.map +1 -1
  81. package/dist/esm/utils/transferMargin.d.ts.map +1 -1
  82. package/dist/esm/utils/transferMargin.js +2 -3
  83. package/dist/esm/utils/transferMargin.js.map +1 -1
  84. package/dist/esm/utils/wireEncoding.d.ts +58 -23
  85. package/dist/esm/utils/wireEncoding.d.ts.map +1 -1
  86. package/dist/esm/utils/wireEncoding.js +58 -23
  87. package/dist/esm/utils/wireEncoding.js.map +1 -1
  88. package/dist/esm/websocket/LighterWsProvider.d.ts +6 -0
  89. package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
  90. package/dist/esm/websocket/LighterWsProvider.js +6 -0
  91. package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
  92. package/dist/types/constants.d.ts +15 -2
  93. package/dist/types/constants.d.ts.map +1 -1
  94. package/dist/types/signers/LighterKeyStore.d.ts +31 -2
  95. package/dist/types/signers/LighterKeyStore.d.ts.map +1 -1
  96. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +23 -3
  97. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  98. package/dist/types/signers/LighterSigner.d.ts +49 -7
  99. package/dist/types/signers/LighterSigner.d.ts.map +1 -1
  100. package/dist/types/signers/createAuthToken.d.ts +8 -2
  101. package/dist/types/signers/createAuthToken.d.ts.map +1 -1
  102. package/dist/types/signers/wasmLoader.d.ts +14 -2
  103. package/dist/types/signers/wasmLoader.d.ts.map +1 -1
  104. package/dist/types/types/account.d.ts +58 -8
  105. package/dist/types/types/account.d.ts.map +1 -1
  106. package/dist/types/types/action.d.ts +72 -18
  107. package/dist/types/types/action.d.ts.map +1 -1
  108. package/dist/types/types/activity.d.ts +64 -10
  109. package/dist/types/types/activity.d.ts.map +1 -1
  110. package/dist/types/types/asset.d.ts +72 -12
  111. package/dist/types/types/asset.d.ts.map +1 -1
  112. package/dist/types/types/fill.d.ts +14 -2
  113. package/dist/types/types/fill.d.ts.map +1 -1
  114. package/dist/types/types/order.d.ts +27 -4
  115. package/dist/types/types/order.d.ts.map +1 -1
  116. package/dist/types/types/submit.d.ts +26 -4
  117. package/dist/types/types/submit.d.ts.map +1 -1
  118. package/dist/types/types/ws.d.ts +56 -8
  119. package/dist/types/types/ws.d.ts.map +1 -1
  120. package/dist/types/utils/lighterAsset.d.ts +7 -1
  121. package/dist/types/utils/lighterAsset.d.ts.map +1 -1
  122. package/dist/types/utils/ohlcvInterval.d.ts +6 -1
  123. package/dist/types/utils/ohlcvInterval.d.ts.map +1 -1
  124. package/dist/types/utils/transferMargin.d.ts.map +1 -1
  125. package/dist/types/utils/wireEncoding.d.ts +58 -23
  126. package/dist/types/utils/wireEncoding.d.ts.map +1 -1
  127. package/dist/types/websocket/LighterWsProvider.d.ts +6 -0
  128. package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
  129. package/package.json +3 -3
  130. package/src/constants.ts +15 -2
  131. package/src/signers/LighterKeyStore.ts +31 -2
  132. package/src/signers/LighterReadOnlyTokenManager.ts +23 -3
  133. package/src/signers/LighterSigner.ts +49 -7
  134. package/src/signers/createAuthToken.ts +8 -2
  135. package/src/signers/wasmLoader.ts +14 -2
  136. package/src/types/account.ts +58 -8
  137. package/src/types/action.ts +72 -18
  138. package/src/types/activity.ts +64 -10
  139. package/src/types/asset.ts +72 -12
  140. package/src/types/fill.ts +14 -2
  141. package/src/types/order.ts +27 -4
  142. package/src/types/submit.ts +26 -4
  143. package/src/types/ws.ts +56 -8
  144. package/src/utils/lighterAsset.ts +7 -1
  145. package/src/utils/ohlcvInterval.ts +6 -1
  146. package/src/utils/transferMargin.ts +2 -6
  147. package/src/utils/wireEncoding.ts +58 -23
  148. package/src/websocket/LighterWsProvider.ts +6 -0
package/src/types/fill.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  // Trade (fill) shapes returned by Lighter's `/api/v1/trades` endpoint.
2
2
 
3
- /** @public */
3
+ /**
4
+ * Public trade/fill row returned by Lighter's `/api/v1/trades` endpoint.
5
+ * Size, price, and notional fields are decimal strings in market precision;
6
+ * `timestamp` and `transaction_time` are Unix millisecond timestamps. The
7
+ * optional fee fields are integer fee ticks and may be absent on older rows.
8
+ *
9
+ * @public
10
+ */
4
11
  export type LtTrade = {
5
12
  trade_id: number
6
13
  tx_hash: string
@@ -34,7 +41,12 @@ export type LtTrade = {
34
41
  maker_entry_quote_before?: string
35
42
  }
36
43
 
37
- /** @public */
44
+ /**
45
+ * Paginated trade-history response from Lighter. `next_cursor` is an opaque
46
+ * continuation value for the next page.
47
+ *
48
+ * @public
49
+ */
38
50
  export interface LtTradesResponse {
39
51
  code: number
40
52
  next_cursor: string
@@ -1,6 +1,14 @@
1
1
  // Order shapes returned by Lighter's REST API.
2
2
 
3
- /** @public */
3
+ /**
4
+ * Order payload returned by Lighter's REST API. Amounts and prices are decimal
5
+ * strings in market precision. `order_expiry` is an absolute Unix-millisecond
6
+ * expiry; `created_at`, `updated_at`, and `transaction_time` are Unix seconds.
7
+ * Enum-like side, type, time-in-force, status, and trigger fields retain
8
+ * Lighter's wire strings.
9
+ *
10
+ * @public
11
+ */
4
12
  export type LtOrder = {
5
13
  order_index: number
6
14
  client_order_index: number
@@ -36,14 +44,25 @@ export type LtOrder = {
36
44
  transaction_time: number
37
45
  }
38
46
 
39
- /** @public */
47
+ /**
48
+ * Paginated order-history response from Lighter. `next_cursor` is an opaque
49
+ * continuation value for the next page.
50
+ *
51
+ * @public
52
+ */
40
53
  export interface LtOrdersResponse {
41
54
  code: number
42
55
  next_cursor: string
43
56
  orders: LtOrder[]
44
57
  }
45
58
 
46
- /** @public */
59
+ /**
60
+ * Single order-book level returned by Lighter. Amounts and prices are decimal
61
+ * strings in the market's native precision; expiry and transaction time are
62
+ * Unix milliseconds.
63
+ *
64
+ * @public
65
+ */
47
66
  export interface LtOrderBookOrder {
48
67
  order_index: number
49
68
  order_id: string
@@ -55,7 +74,11 @@ export interface LtOrderBookOrder {
55
74
  transaction_time: number
56
75
  }
57
76
 
58
- /** @public */
77
+ /**
78
+ * Order-book response containing separate ask and bid levels plus their counts.
79
+ *
80
+ * @public
81
+ */
59
82
  export interface LtOrderBookOrdersResponse {
60
83
  code: number
61
84
  total_asks: number
@@ -1,13 +1,24 @@
1
1
  // Lighter submit/execute-path wire shapes (sendTx, fastwithdraw, changeAccountTier).
2
2
 
3
- /** @public */
3
+ /**
4
+ * Request body for Lighter's `/api/v1/sendTx` endpoint. `tx_type` and
5
+ * `tx_info` are the signed WASM transaction envelope; `price_protection` is an
6
+ * optional venue-side execution guard.
7
+ *
8
+ * @public
9
+ */
4
10
  export interface LtSendTxRequest {
5
11
  tx_type: number
6
12
  tx_info: string
7
13
  price_protection?: boolean
8
14
  }
9
15
 
10
- /** @public */
16
+ /**
17
+ * Response from Lighter's `/api/v1/sendTx` endpoint. `tx_hash` identifies the
18
+ * submitted transaction; timing and quota fields are optional venue estimates.
19
+ *
20
+ * @public
21
+ */
11
22
  export interface LtSendTxResponse {
12
23
  code: number
13
24
  message: string
@@ -16,13 +27,24 @@ export interface LtSendTxResponse {
16
27
  volume_quota_remaining?: number
17
28
  }
18
29
 
19
- /** @public */
30
+ /**
31
+ * Batch request body for Lighter's transaction submission endpoint.
32
+ * `tx_types` is a JSON-encoded number array and `tx_infos` a JSON-encoded
33
+ * string array; corresponding entries are submitted in array order.
34
+ *
35
+ * @public
36
+ */
20
37
  export interface LtSendTxBatchRequest {
21
38
  tx_types: string // JSON-encoded number[]
22
39
  tx_infos: string // JSON-encoded string[]
23
40
  }
24
41
 
25
- /** @public */
42
+ /**
43
+ * Batch submission response from Lighter. Each `tx_hash` corresponds to the
44
+ * transaction at the same index in the submitted batch.
45
+ *
46
+ * @public
47
+ */
26
48
  export interface LtSendTxBatchResponse {
27
49
  code: number
28
50
  message: string
package/src/types/ws.ts CHANGED
@@ -10,16 +10,33 @@
10
10
  // - spot_market_stats/{id} → context for one spot market
11
11
  // - order_book/{market_id} → bids/asks per market (stateful with deltas)
12
12
 
13
- /** @public */
13
+ /**
14
+ * Common envelope fields on every Lighter WebSocket frame.
15
+ *
16
+ * `channel` identifies the subscribed stream when present; `type` is the
17
+ * subscription, update, or control-frame discriminator.
18
+ *
19
+ * @public
20
+ */
14
21
  export type LtWsMessage = {
15
22
  channel?: string
16
23
  type: string
17
24
  }
18
25
 
19
- /** @public */
26
+ /**
27
+ * Lighter WebSocket keepalive frame.
28
+ *
29
+ * @public
30
+ */
20
31
  export type LtWsPingMessage = LtWsMessage & { type: 'ping' }
21
32
 
22
- /** @public */
33
+ /**
34
+ * Perpetual-market statistics pushed by Lighter's `market_stats` channels.
35
+ * Price, interest, volume, and funding values are decimal strings; the funding
36
+ * timestamp is a Unix timestamp in milliseconds.
37
+ *
38
+ * @public
39
+ */
23
40
  export type LtWsMarketStats = {
24
41
  market_id: number
25
42
  index_price: string
@@ -75,20 +92,34 @@ export type LtWsSpotMarketStatsAllMessage = LtWsMessage & {
75
92
  spot_market_stats?: LtWsSpotMarketStats | Record<string, LtWsSpotMarketStats>
76
93
  }
77
94
 
78
- /** @public */
95
+ /**
96
+ * One bid or ask level in a Lighter order-book snapshot or delta. Price and
97
+ * size are decimal strings in the market's native precision.
98
+ *
99
+ * @public
100
+ */
79
101
  export type LtWsOrderBookLevel = {
80
102
  price: string
81
103
  size: string
82
104
  }
83
105
 
84
- /** @public */
106
+ /**
107
+ * Lighter order-book state containing ask and bid levels. `offset`, when
108
+ * present, identifies the sequence offset used for stateful delta updates.
109
+ *
110
+ * @public
111
+ */
85
112
  export type LtWsOrderBook = {
86
113
  asks: LtWsOrderBookLevel[]
87
114
  bids: LtWsOrderBookLevel[]
88
115
  offset?: number
89
116
  }
90
117
 
91
- /** @public */
118
+ /**
119
+ * Subscription or update frame carrying a Lighter order-book snapshot/delta.
120
+ *
121
+ * @public
122
+ */
92
123
  export type LtWsOrderBookMessage = LtWsMessage & {
93
124
  type: 'subscribed/order_book' | 'update/order_book'
94
125
  order_book: LtWsOrderBook
@@ -109,7 +140,11 @@ export type LtWsTrade = {
109
140
  timestamp: number
110
141
  }
111
142
 
112
- /** @public */
143
+ /**
144
+ * Subscription or update frame carrying public trades from a Lighter market.
145
+ *
146
+ * @public
147
+ */
113
148
  export type LtWsTradeMessage = LtWsMessage & {
114
149
  type: 'subscribed/trade' | 'update/trade'
115
150
  trades?: LtWsTrade[]
@@ -138,7 +173,13 @@ export type LtWsAccountAllOrdersMessage = LtWsMessage & {
138
173
  data?: { orders?: Record<string, unknown[]> | unknown[] }
139
174
  }
140
175
 
141
- /** @public */
176
+ /**
177
+ * Authenticated account trade-history frame. Trade arrays may be flat or
178
+ * market-indexed depending on whether the frame is an initial snapshot or
179
+ * update.
180
+ *
181
+ * @public
182
+ */
142
183
  export type LtWsAccountAllTradesMessage = LtWsMessage & {
143
184
  type: 'subscribed/account_all_trades' | 'update/account_all_trades'
144
185
  trades?: Record<string, unknown[]> | unknown[]
@@ -169,6 +210,13 @@ export type LtWsUserStatsMessage = LtWsMessage & {
169
210
  }
170
211
  }
171
212
 
213
+ /**
214
+ * Authenticated account-position frame. Position and funding maps are keyed
215
+ * by Lighter market index; the provider normalizes the payload before emitting
216
+ * account updates.
217
+ *
218
+ * @public
219
+ */
172
220
  export type LtWsAccountAllPositionsMessage = LtWsMessage & {
173
221
  type: 'subscribed/account_all_positions' | 'update/account_all_positions'
174
222
  positions?: Record<string, unknown>
@@ -1,7 +1,13 @@
1
1
  import type { Asset } from '@lifi/perps-types'
2
2
  import { LIGHTER_PROVIDER_KEY } from '../constants.js'
3
3
 
4
- /** @public */
4
+ /**
5
+ * Create the SDK asset descriptor for a Lighter asset identifier and display
6
+ * symbol. Lighter assets do not provide a package-level logo URI, so this
7
+ * helper leaves that field empty.
8
+ *
9
+ * @public
10
+ */
5
11
  export const lighterAsset = (id: string, displaySymbol: string): Asset => ({
6
12
  providerId: LIGHTER_PROVIDER_KEY,
7
13
  id,
@@ -20,7 +20,12 @@ const LIGHTER_SUPPORTED_INTERVALS: Record<string, string> = {
20
20
  '1w': '1w',
21
21
  }
22
22
 
23
- /** @public */
23
+ /**
24
+ * Validate and map an SDK OHLCV interval to Lighter's resolution string.
25
+ * Unsupported intervals raise a validation error instead of being rounded.
26
+ *
27
+ * @public
28
+ */
24
29
  export const mapInterval = (interval: string): string => {
25
30
  const resolution = LIGHTER_SUPPORTED_INTERVALS[interval]
26
31
  if (!resolution) {
@@ -1,8 +1,7 @@
1
1
  import {
2
- MarginMode,
3
2
  type Position,
4
- PositionMarginAdjustment,
5
3
  type PositionMarginConstraints,
4
+ positionSupportsMarginAdjustment,
6
5
  } from '@lifi/perps-types'
7
6
  import { toPositiveRequiredBig } from './decimal.js'
8
7
 
@@ -19,10 +18,7 @@ const AMOUNT_INCREMENT = '0.000001'
19
18
  export function positionMarginConstraints(
20
19
  position: Position
21
20
  ): PositionMarginConstraints | undefined {
22
- if (
23
- position.marginMode !== MarginMode.ISOLATED ||
24
- position.market.positionMarginAdjustment === PositionMarginAdjustment.NONE
25
- ) {
21
+ if (!positionSupportsMarginAdjustment(position)) {
26
22
  return undefined
27
23
  }
28
24
  return {
@@ -1,7 +1,6 @@
1
1
  /**
2
- * Lighter wire encoding for the WASM signer: scaled-integer decimal values,
3
- * basis-point margin fractions, and order-type/TIF/expiry resolution
4
- * mirroring the lighter-go signer's rules.
2
+ * Lighter wire encoding for the WASM signer: basis-point margin fractions and
3
+ * order-type/time-in-force/expiry resolution mirroring lighter-go's rules.
5
4
  */
6
5
 
7
6
  import { PerpsError } from '@lifi/perps-sdk'
@@ -20,8 +19,15 @@ import {
20
19
  } from '../types/action.js'
21
20
 
22
21
  /**
23
- * Lighter uses basis-points (1/10000) for margin fractions.
24
- * Convert to a decimal multiplier: 1000 → 0.1 (10x leverage).
22
+ * Convert Lighter's initial-margin fraction to the largest whole-number
23
+ * leverage exposed by the provider.
24
+ *
25
+ * Lighter expresses margin fractions in basis points (`10_000` = 100%), so
26
+ * the conversion is `floor(10_000 / fraction)`. Non-finite or non-positive
27
+ * input uses the safe `1x` fallback.
28
+ *
29
+ * @param fraction - Lighter's basis-point initial-margin fraction.
30
+ * @returns The floored maximum leverage, or `1` for invalid input.
25
31
  * @public
26
32
  */
27
33
  export const marginFractionToMaxLeverage = (fraction: number): number => {
@@ -32,7 +38,15 @@ export const marginFractionToMaxLeverage = (fraction: number): number => {
32
38
  }
33
39
 
34
40
  /**
35
- * Convert leverage to margin fraction in basis points for WASM signer.
41
+ * Convert requested leverage to Lighter's basis-point margin fraction.
42
+ *
43
+ * The signer expects `round(10_000 / leverage)`, where the result is the
44
+ * margin requirement in basis points.
45
+ *
46
+ * @param leverage - Requested leverage multiplier.
47
+ * @returns The rounded basis-point margin fraction.
48
+ * @throws {PerpsError} With `ValidationError` when leverage is less than
49
+ * or equal to zero.
36
50
  * @public
37
51
  */
38
52
  export const leverageToFraction = (leverage: number): number => {
@@ -46,7 +60,14 @@ export const leverageToFraction = (leverage: number): number => {
46
60
  }
47
61
 
48
62
  /**
49
- * Map our OrderType enum to Lighter's integer order type.
63
+ * Map a LI.FI `OrderType` value to Lighter's integer wire type.
64
+ *
65
+ * Supported mappings are LIMIT → 0, MARKET → 1, STOP_MARKET → 2,
66
+ * STOP_LIMIT → 3, TAKE_PROFIT_MARKET → 4, and TAKE_PROFIT_LIMIT → 5.
67
+ * Omitted or unknown values fall back to LIMIT.
68
+ *
69
+ * @param type - LI.FI order type value.
70
+ * @returns The corresponding Lighter order-type integer.
50
71
  * @public
51
72
  */
52
73
  export const mapOrderTypeToInt = (type?: string): number => {
@@ -62,13 +83,18 @@ export const mapOrderTypeToInt = (type?: string): number => {
62
83
  }
63
84
 
64
85
  /**
65
- * Lighter pairs each `order_type` with a permitted set of `time_in_force`
66
- * values: market-style orders (MARKET, STOP_MARKET, TAKE_PROFIT_MARKET) are
67
- * IOC by definition; limit-style orders may carry any TIF. The Go WASM
68
- * signer rejects mismatches with `OrderTimeInForce is not valid`. Resolve
69
- * the caller's optional `timeInForce` against the order type so unspecified
70
- * values land on the correct default and explicit values are validated up
71
- * front.
86
+ * Resolve a Lighter `time_in_force` value that is valid for an order type.
87
+ *
88
+ * Market-style orders (MARKET, STOP_MARKET, TAKE_PROFIT_MARKET) are IOC-only.
89
+ * Limit-style orders default to GTC when no TIF is supplied. An explicit
90
+ * non-IOC TIF on a market-style order raises a validation error. For
91
+ * limit-style orders, unknown TIF strings use the GTC fallback from
92
+ * {@link mapTimeInForceToInt}.
93
+ *
94
+ * @param orderTypeInt - Lighter order-type integer.
95
+ * @param tif - Optional LI.FI time-in-force value.
96
+ * @returns The validated Lighter time-in-force integer.
97
+ * @throws {PerpsError} With `ValidationError` for a market-style/TIF mismatch.
72
98
  * @public
73
99
  */
74
100
  export const resolveTimeInForce = (
@@ -93,7 +119,13 @@ export const resolveTimeInForce = (
93
119
  }
94
120
 
95
121
  /**
96
- * Map our TimeInForce enum to Lighter's integer time-in-force.
122
+ * Map a LI.FI time-in-force value to Lighter's integer wire value.
123
+ *
124
+ * IOC maps to 0, GTC maps to 1, and POST_ONLY maps to 2. Omitted or unknown
125
+ * values fall back to GTC.
126
+ *
127
+ * @param tif - LI.FI time-in-force value.
128
+ * @returns The corresponding Lighter time-in-force integer.
97
129
  * @public
98
130
  */
99
131
  export const mapTimeInForceToInt = (tif?: string): number => {
@@ -106,14 +138,17 @@ export const mapTimeInForceToInt = (tif?: string): number => {
106
138
  }
107
139
 
108
140
  /**
109
- * Pick the `order_expiry` value Lighter expects for a given TIF on a
110
- * regular limit order. `lighter-go/types/txtypes/create_order.go:121-128`
111
- * enforces:
112
- * - IOC limit orders → `OrderExpiry == NilOrderExpiry (0)`
113
- * - non-IOC limit orders → `OrderExpiry != NilOrderExpiry`
114
- * For non-IOC we pass the `-1` sentinel, which the WASM signer rewrites
115
- * to `now + 28d` (absolute ms). Trigger orders take a different rule —
116
- * see {@link LT_DEFAULT_ORDER_EXPIRY} call sites.
141
+ * Select the `order_expiry` sentinel required for a regular Lighter limit
142
+ * order from its resolved time-in-force.
143
+ *
144
+ * IOC uses Lighter's nil expiry (`0`). Every other TIF uses
145
+ * `LT_DEFAULT_ORDER_EXPIRY` (`-1`), which the WASM signer expands to its
146
+ * canonical future expiry (`now + 28d`) as an absolute Unix-millisecond
147
+ * timestamp. Trigger-order expiry handling is provider-specific; see
148
+ * {@link LT_DEFAULT_ORDER_EXPIRY} and its call sites.
149
+ *
150
+ * @param tifInt - Lighter time-in-force integer.
151
+ * @returns `0` for IOC, otherwise the default-expiry sentinel.
117
152
  * @public
118
153
  */
119
154
  export const orderExpiryForTif = (tifInt: number): number => {
@@ -227,6 +227,12 @@ export class LighterWsProvider extends WsProviderBase<SubState> {
227
227
  return undefined
228
228
  }
229
229
 
230
+ /**
231
+ * Subscribe to a live quote stream resolved through the registered Lighter
232
+ * market registry. Returns an unsubscribe function; quote subscription
233
+ * requires the provider to be constructed through `lighterWsProvider` with a
234
+ * bound {@link PerpsSDKClient}.
235
+ */
230
236
  async subscribeQuote(
231
237
  params: ProviderGetQuoteParams,
232
238
  onQuote: QuoteListener