@lifi/perps-sdk-provider-lighter 7.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 (214) hide show
  1. package/dist/cjs/LighterProvider.d.ts.map +1 -1
  2. package/dist/cjs/LighterProvider.js +60 -27
  3. package/dist/cjs/LighterProvider.js.map +1 -1
  4. package/dist/cjs/accountSummary.d.ts.map +1 -1
  5. package/dist/cjs/accountSummary.js +33 -2
  6. package/dist/cjs/accountSummary.js.map +1 -1
  7. package/dist/cjs/constants.d.ts.map +1 -1
  8. package/dist/cjs/constants.js.map +1 -1
  9. package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -1
  10. package/dist/cjs/signers/LighterKeyStore.js.map +1 -1
  11. package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  12. package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -1
  13. package/dist/cjs/signers/LighterSigner.d.ts.map +1 -1
  14. package/dist/cjs/signers/LighterSigner.js.map +1 -1
  15. package/dist/cjs/signers/createAuthToken.d.ts.map +1 -1
  16. package/dist/cjs/signers/createAuthToken.js.map +1 -1
  17. package/dist/cjs/signers/wasmLoader.d.ts.map +1 -1
  18. package/dist/cjs/signers/wasmLoader.js.map +1 -1
  19. package/dist/cjs/types/account.d.ts +1 -0
  20. package/dist/cjs/types/account.d.ts.map +1 -1
  21. package/dist/cjs/types/action.d.ts.map +1 -1
  22. package/dist/cjs/types/action.js.map +1 -1
  23. package/dist/cjs/types/activity.d.ts.map +1 -1
  24. package/dist/cjs/types/asset.d.ts.map +1 -1
  25. package/dist/cjs/types/fill.d.ts.map +1 -1
  26. package/dist/cjs/types/order.d.ts.map +1 -1
  27. package/dist/cjs/types/submit.d.ts.map +1 -1
  28. package/dist/cjs/types/ws.d.ts +5 -0
  29. package/dist/cjs/types/ws.d.ts.map +1 -1
  30. package/dist/cjs/utils/decimal.d.ts +5 -0
  31. package/dist/cjs/utils/decimal.d.ts.map +1 -0
  32. package/dist/cjs/utils/decimal.js +38 -0
  33. package/dist/cjs/utils/decimal.js.map +1 -0
  34. package/dist/cjs/utils/index.d.ts +3 -1
  35. package/dist/cjs/utils/index.d.ts.map +1 -1
  36. package/dist/cjs/utils/index.js +7 -1
  37. package/dist/cjs/utils/index.js.map +1 -1
  38. package/dist/cjs/utils/lighterAsset.d.ts.map +1 -1
  39. package/dist/cjs/utils/lighterAsset.js.map +1 -1
  40. package/dist/cjs/utils/mapOpenPositions.d.ts +2 -2
  41. package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -1
  42. package/dist/cjs/utils/mapOpenPositions.js.map +1 -1
  43. package/dist/cjs/utils/mapPosition.d.ts +3 -2
  44. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  45. package/dist/cjs/utils/mapPosition.js +30 -9
  46. package/dist/cjs/utils/mapPosition.js.map +1 -1
  47. package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -1
  48. package/dist/cjs/utils/ohlcvInterval.js.map +1 -1
  49. package/dist/cjs/utils/transferMargin.d.ts +3 -0
  50. package/dist/cjs/utils/transferMargin.d.ts.map +1 -0
  51. package/dist/cjs/utils/transferMargin.js +16 -0
  52. package/dist/cjs/utils/transferMargin.js.map +1 -0
  53. package/dist/cjs/utils/wireEncoding.d.ts.map +1 -1
  54. package/dist/cjs/utils/wireEncoding.js.map +1 -1
  55. package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -1
  56. package/dist/cjs/websocket/LighterWsProvider.js +20 -9
  57. package/dist/cjs/websocket/LighterWsProvider.js.map +1 -1
  58. package/dist/esm/LighterProvider.d.ts.map +1 -1
  59. package/dist/esm/LighterProvider.js +49 -11
  60. package/dist/esm/LighterProvider.js.map +1 -1
  61. package/dist/esm/accountSummary.d.ts +5 -4
  62. package/dist/esm/accountSummary.d.ts.map +1 -1
  63. package/dist/esm/accountSummary.js +35 -6
  64. package/dist/esm/accountSummary.js.map +1 -1
  65. package/dist/esm/constants.d.ts +15 -2
  66. package/dist/esm/constants.d.ts.map +1 -1
  67. package/dist/esm/constants.js +15 -2
  68. package/dist/esm/constants.js.map +1 -1
  69. package/dist/esm/signers/LighterKeyStore.d.ts +31 -2
  70. package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -1
  71. package/dist/esm/signers/LighterKeyStore.js +24 -1
  72. package/dist/esm/signers/LighterKeyStore.js.map +1 -1
  73. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +23 -3
  74. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  75. package/dist/esm/signers/LighterReadOnlyTokenManager.js +4 -0
  76. package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -1
  77. package/dist/esm/signers/LighterSigner.d.ts +49 -7
  78. package/dist/esm/signers/LighterSigner.d.ts.map +1 -1
  79. package/dist/esm/signers/LighterSigner.js +11 -1
  80. package/dist/esm/signers/LighterSigner.js.map +1 -1
  81. package/dist/esm/signers/createAuthToken.d.ts +8 -2
  82. package/dist/esm/signers/createAuthToken.d.ts.map +1 -1
  83. package/dist/esm/signers/createAuthToken.js.map +1 -1
  84. package/dist/esm/signers/wasmLoader.d.ts +14 -2
  85. package/dist/esm/signers/wasmLoader.d.ts.map +1 -1
  86. package/dist/esm/signers/wasmLoader.js.map +1 -1
  87. package/dist/esm/types/account.d.ts +61 -8
  88. package/dist/esm/types/account.d.ts.map +1 -1
  89. package/dist/esm/types/action.d.ts +72 -18
  90. package/dist/esm/types/action.d.ts.map +1 -1
  91. package/dist/esm/types/action.js +72 -18
  92. package/dist/esm/types/action.js.map +1 -1
  93. package/dist/esm/types/activity.d.ts +64 -10
  94. package/dist/esm/types/activity.d.ts.map +1 -1
  95. package/dist/esm/types/asset.d.ts +72 -12
  96. package/dist/esm/types/asset.d.ts.map +1 -1
  97. package/dist/esm/types/fill.d.ts +14 -2
  98. package/dist/esm/types/fill.d.ts.map +1 -1
  99. package/dist/esm/types/order.d.ts +27 -4
  100. package/dist/esm/types/order.d.ts.map +1 -1
  101. package/dist/esm/types/submit.d.ts +26 -4
  102. package/dist/esm/types/submit.d.ts.map +1 -1
  103. package/dist/esm/types/ws.d.ts +65 -9
  104. package/dist/esm/types/ws.d.ts.map +1 -1
  105. package/dist/esm/utils/decimal.d.ts +15 -0
  106. package/dist/esm/utils/decimal.d.ts.map +1 -0
  107. package/dist/esm/utils/decimal.js +39 -0
  108. package/dist/esm/utils/decimal.js.map +1 -0
  109. package/dist/esm/utils/index.d.ts +3 -1
  110. package/dist/esm/utils/index.d.ts.map +1 -1
  111. package/dist/esm/utils/index.js +3 -1
  112. package/dist/esm/utils/index.js.map +1 -1
  113. package/dist/esm/utils/lighterAsset.d.ts +7 -1
  114. package/dist/esm/utils/lighterAsset.d.ts.map +1 -1
  115. package/dist/esm/utils/lighterAsset.js +7 -1
  116. package/dist/esm/utils/lighterAsset.js.map +1 -1
  117. package/dist/esm/utils/mapOpenPositions.d.ts +2 -2
  118. package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -1
  119. package/dist/esm/utils/mapOpenPositions.js.map +1 -1
  120. package/dist/esm/utils/mapPosition.d.ts +10 -2
  121. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  122. package/dist/esm/utils/mapPosition.js +32 -11
  123. package/dist/esm/utils/mapPosition.js.map +1 -1
  124. package/dist/esm/utils/ohlcvInterval.d.ts +6 -1
  125. package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -1
  126. package/dist/esm/utils/ohlcvInterval.js +6 -1
  127. package/dist/esm/utils/ohlcvInterval.js.map +1 -1
  128. package/dist/esm/utils/transferMargin.d.ts +11 -0
  129. package/dist/esm/utils/transferMargin.d.ts.map +1 -0
  130. package/dist/esm/utils/transferMargin.js +21 -0
  131. package/dist/esm/utils/transferMargin.js.map +1 -0
  132. package/dist/esm/utils/wireEncoding.d.ts +58 -23
  133. package/dist/esm/utils/wireEncoding.d.ts.map +1 -1
  134. package/dist/esm/utils/wireEncoding.js +58 -23
  135. package/dist/esm/utils/wireEncoding.js.map +1 -1
  136. package/dist/esm/websocket/LighterWsProvider.d.ts +6 -0
  137. package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -1
  138. package/dist/esm/websocket/LighterWsProvider.js +30 -13
  139. package/dist/esm/websocket/LighterWsProvider.js.map +1 -1
  140. package/dist/types/LighterProvider.d.ts.map +1 -1
  141. package/dist/types/accountSummary.d.ts +5 -4
  142. package/dist/types/accountSummary.d.ts.map +1 -1
  143. package/dist/types/constants.d.ts +15 -2
  144. package/dist/types/constants.d.ts.map +1 -1
  145. package/dist/types/signers/LighterKeyStore.d.ts +31 -2
  146. package/dist/types/signers/LighterKeyStore.d.ts.map +1 -1
  147. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +23 -3
  148. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -1
  149. package/dist/types/signers/LighterSigner.d.ts +49 -7
  150. package/dist/types/signers/LighterSigner.d.ts.map +1 -1
  151. package/dist/types/signers/createAuthToken.d.ts +8 -2
  152. package/dist/types/signers/createAuthToken.d.ts.map +1 -1
  153. package/dist/types/signers/wasmLoader.d.ts +14 -2
  154. package/dist/types/signers/wasmLoader.d.ts.map +1 -1
  155. package/dist/types/types/account.d.ts +61 -8
  156. package/dist/types/types/account.d.ts.map +1 -1
  157. package/dist/types/types/action.d.ts +72 -18
  158. package/dist/types/types/action.d.ts.map +1 -1
  159. package/dist/types/types/activity.d.ts +64 -10
  160. package/dist/types/types/activity.d.ts.map +1 -1
  161. package/dist/types/types/asset.d.ts +72 -12
  162. package/dist/types/types/asset.d.ts.map +1 -1
  163. package/dist/types/types/fill.d.ts +14 -2
  164. package/dist/types/types/fill.d.ts.map +1 -1
  165. package/dist/types/types/order.d.ts +27 -4
  166. package/dist/types/types/order.d.ts.map +1 -1
  167. package/dist/types/types/submit.d.ts +26 -4
  168. package/dist/types/types/submit.d.ts.map +1 -1
  169. package/dist/types/types/ws.d.ts +65 -9
  170. package/dist/types/types/ws.d.ts.map +1 -1
  171. package/dist/types/utils/decimal.d.ts +15 -0
  172. package/dist/types/utils/decimal.d.ts.map +1 -0
  173. package/dist/types/utils/index.d.ts +3 -1
  174. package/dist/types/utils/index.d.ts.map +1 -1
  175. package/dist/types/utils/lighterAsset.d.ts +7 -1
  176. package/dist/types/utils/lighterAsset.d.ts.map +1 -1
  177. package/dist/types/utils/mapOpenPositions.d.ts +2 -2
  178. package/dist/types/utils/mapOpenPositions.d.ts.map +1 -1
  179. package/dist/types/utils/mapPosition.d.ts +10 -2
  180. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  181. package/dist/types/utils/ohlcvInterval.d.ts +6 -1
  182. package/dist/types/utils/ohlcvInterval.d.ts.map +1 -1
  183. package/dist/types/utils/transferMargin.d.ts +11 -0
  184. package/dist/types/utils/transferMargin.d.ts.map +1 -0
  185. package/dist/types/utils/wireEncoding.d.ts +58 -23
  186. package/dist/types/utils/wireEncoding.d.ts.map +1 -1
  187. package/dist/types/websocket/LighterWsProvider.d.ts +6 -0
  188. package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -1
  189. package/package.json +3 -3
  190. package/src/LighterProvider.ts +75 -9
  191. package/src/accountSummary.ts +38 -6
  192. package/src/constants.ts +15 -2
  193. package/src/signers/LighterKeyStore.ts +31 -2
  194. package/src/signers/LighterReadOnlyTokenManager.ts +23 -3
  195. package/src/signers/LighterSigner.ts +49 -7
  196. package/src/signers/createAuthToken.ts +8 -2
  197. package/src/signers/wasmLoader.ts +14 -2
  198. package/src/types/account.ts +61 -8
  199. package/src/types/action.ts +72 -18
  200. package/src/types/activity.ts +64 -10
  201. package/src/types/asset.ts +72 -12
  202. package/src/types/fill.ts +14 -2
  203. package/src/types/order.ts +27 -4
  204. package/src/types/submit.ts +26 -4
  205. package/src/types/ws.ts +65 -9
  206. package/src/utils/decimal.ts +52 -0
  207. package/src/utils/index.ts +3 -1
  208. package/src/utils/lighterAsset.ts +7 -1
  209. package/src/utils/mapOpenPositions.ts +2 -2
  210. package/src/utils/mapPosition.ts +40 -14
  211. package/src/utils/ohlcvInterval.ts +6 -1
  212. package/src/utils/transferMargin.ts +31 -0
  213. package/src/utils/wireEncoding.ts +58 -23
  214. package/src/websocket/LighterWsProvider.ts +47 -11
@@ -1,49 +1,84 @@
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
- * Lighter uses basis-points (1/10000) for margin fractions.
8
- * Convert to a decimal multiplier: 1000 → 0.1 (10x leverage).
6
+ * Convert Lighter's initial-margin fraction to the largest whole-number
7
+ * leverage exposed by the provider.
8
+ *
9
+ * Lighter expresses margin fractions in basis points (`10_000` = 100%), so
10
+ * the conversion is `floor(10_000 / fraction)`. Non-finite or non-positive
11
+ * input uses the safe `1x` fallback.
12
+ *
13
+ * @param fraction - Lighter's basis-point initial-margin fraction.
14
+ * @returns The floored maximum leverage, or `1` for invalid input.
9
15
  * @public
10
16
  */
11
17
  export declare const marginFractionToMaxLeverage: (fraction: number) => number;
12
18
  /**
13
- * Convert leverage to margin fraction in basis points for WASM signer.
19
+ * Convert requested leverage to Lighter's basis-point margin fraction.
20
+ *
21
+ * The signer expects `round(10_000 / leverage)`, where the result is the
22
+ * margin requirement in basis points.
23
+ *
24
+ * @param leverage - Requested leverage multiplier.
25
+ * @returns The rounded basis-point margin fraction.
26
+ * @throws {PerpsError} With `ValidationError` when leverage is less than
27
+ * or equal to zero.
14
28
  * @public
15
29
  */
16
30
  export declare const leverageToFraction: (leverage: number) => number;
17
31
  /**
18
- * Map our OrderType enum to Lighter's integer order type.
32
+ * Map a LI.FI `OrderType` value to Lighter's integer wire type.
33
+ *
34
+ * Supported mappings are LIMIT → 0, MARKET → 1, STOP_MARKET → 2,
35
+ * STOP_LIMIT → 3, TAKE_PROFIT_MARKET → 4, and TAKE_PROFIT_LIMIT → 5.
36
+ * Omitted or unknown values fall back to LIMIT.
37
+ *
38
+ * @param type - LI.FI order type value.
39
+ * @returns The corresponding Lighter order-type integer.
19
40
  * @public
20
41
  */
21
42
  export declare const mapOrderTypeToInt: (type?: string) => number;
22
43
  /**
23
- * Lighter pairs each `order_type` with a permitted set of `time_in_force`
24
- * values: market-style orders (MARKET, STOP_MARKET, TAKE_PROFIT_MARKET) are
25
- * IOC by definition; limit-style orders may carry any TIF. The Go WASM
26
- * signer rejects mismatches with `OrderTimeInForce is not valid`. Resolve
27
- * the caller's optional `timeInForce` against the order type so unspecified
28
- * values land on the correct default and explicit values are validated up
29
- * front.
44
+ * Resolve a Lighter `time_in_force` value that is valid for an order type.
45
+ *
46
+ * Market-style orders (MARKET, STOP_MARKET, TAKE_PROFIT_MARKET) are IOC-only.
47
+ * Limit-style orders default to GTC when no TIF is supplied. An explicit
48
+ * non-IOC TIF on a market-style order raises a validation error. For
49
+ * limit-style orders, unknown TIF strings use the GTC fallback from
50
+ * {@link mapTimeInForceToInt}.
51
+ *
52
+ * @param orderTypeInt - Lighter order-type integer.
53
+ * @param tif - Optional LI.FI time-in-force value.
54
+ * @returns The validated Lighter time-in-force integer.
55
+ * @throws {PerpsError} With `ValidationError` for a market-style/TIF mismatch.
30
56
  * @public
31
57
  */
32
58
  export declare const resolveTimeInForce: (orderTypeInt: number, tif?: string) => number;
33
59
  /**
34
- * Map our TimeInForce enum to Lighter's integer time-in-force.
60
+ * Map a LI.FI time-in-force value to Lighter's integer wire value.
61
+ *
62
+ * IOC maps to 0, GTC maps to 1, and POST_ONLY maps to 2. Omitted or unknown
63
+ * values fall back to GTC.
64
+ *
65
+ * @param tif - LI.FI time-in-force value.
66
+ * @returns The corresponding Lighter time-in-force integer.
35
67
  * @public
36
68
  */
37
69
  export declare const mapTimeInForceToInt: (tif?: string) => number;
38
70
  /**
39
- * Pick the `order_expiry` value Lighter expects for a given TIF on a
40
- * regular limit order. `lighter-go/types/txtypes/create_order.go:121-128`
41
- * enforces:
42
- * - IOC limit orders → `OrderExpiry == NilOrderExpiry (0)`
43
- * - non-IOC limit orders → `OrderExpiry != NilOrderExpiry`
44
- * For non-IOC we pass the `-1` sentinel, which the WASM signer rewrites
45
- * to `now + 28d` (absolute ms). Trigger orders take a different rule —
46
- * see {@link LT_DEFAULT_ORDER_EXPIRY} call sites.
71
+ * Select the `order_expiry` sentinel required for a regular Lighter limit
72
+ * order from its resolved time-in-force.
73
+ *
74
+ * IOC uses Lighter's nil expiry (`0`). Every other TIF uses
75
+ * `LT_DEFAULT_ORDER_EXPIRY` (`-1`), which the WASM signer expands to its
76
+ * canonical future expiry (`now + 28d`) as an absolute Unix-millisecond
77
+ * timestamp. Trigger-order expiry handling is provider-specific; see
78
+ * {@link LT_DEFAULT_ORDER_EXPIRY} and its call sites.
79
+ *
80
+ * @param tifInt - Lighter time-in-force integer.
81
+ * @returns `0` for IOC, otherwise the default-expiry sentinel.
47
82
  * @public
48
83
  */
49
84
  export declare const orderExpiryForTif: (tifInt: number) => number;
@@ -1 +1 @@
1
- {"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiBH;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,KAAG,MAK9D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,MAQrD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,MAUjD,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,MAAM,EACpB,MAAM,MAAM,KACX,MAgBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,MAOlD,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAKlD,CAAA"}
1
+ {"version":3,"file":"wireEncoding.d.ts","sourceRoot":"","sources":["../../../src/utils/wireEncoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,KAAG,MAK9D,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,MAQrD,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,MAUjD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,MAAM,EACpB,MAAM,MAAM,KACX,MAgBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,MAOlD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAKlD,CAAA"}
@@ -69,6 +69,12 @@ export declare class LighterWsProvider extends WsProviderBase<SubState> {
69
69
  * `resolveAuthToken`. `undefined` when neither is available.
70
70
  */
71
71
  private authTokenResolver;
72
+ /**
73
+ * Subscribe to a live quote stream resolved through the registered Lighter
74
+ * market registry. Returns an unsubscribe function; quote subscription
75
+ * requires the provider to be constructed through `lighterWsProvider` with a
76
+ * bound {@link PerpsSDKClient}.
77
+ */
72
78
  subscribeQuote(params: ProviderGetQuoteParams, onQuote: QuoteListener): Promise<() => void>;
73
79
  protected openChannel(sub: Subscription): Promise<() => void>;
74
80
  protected onClose(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"LighterWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/LighterWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAA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WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;cA4ChD,OAAO,IAAI,IAAI;cAMlB,aAAa,CAAC,EAC5B,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3B,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM;YA2B5B,cAAc;YAsFd,mBAAmB;YAqBnB,iBAAiB;IAK/B,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAqB1C,OAAO,CAAC,QAAQ;IAkFhB,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,eAAe;IAuDvB,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,sBAAsB;IAiC9B;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,mBAAmB;CAc5B;AAkID;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAC3B,UAAU,wBAAwB,KAAG,iBAEmB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk-provider-lighter",
3
- "version": "7.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Lighter provider plugin for @lifi/perps-sdk",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -46,10 +46,10 @@
46
46
  "dependencies": {
47
47
  "big.js": "^7.0.1",
48
48
  "viem": "^2.48.8",
49
- "@lifi/perps-types": "^3.3.2"
49
+ "@lifi/perps-types": "^4.1.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@lifi/perps-sdk": "^5.0.0"
52
+ "@lifi/perps-sdk": "^6.1.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"
@@ -12,6 +12,7 @@ import {
12
12
  type ProviderGetActivityParams,
13
13
  type ProviderGetDepositFlowParams,
14
14
  type ProviderGetFillsParams,
15
+ type ProviderGetMarketSettingsParams,
15
16
  type ProviderGetOrderParams,
16
17
  type ProviderGetOrdersParams,
17
18
  type ProviderGetPositionsParams,
@@ -20,6 +21,7 @@ import {
20
21
  resolveRetryPolicy,
21
22
  type SDKRequestOptions,
22
23
  type SignActionsContext,
24
+ toPerpsMarketDisplay,
23
25
  } from '@lifi/perps-sdk'
24
26
  import type {
25
27
  AccountConfig,
@@ -33,6 +35,7 @@ import type {
33
35
  FillsResponse,
34
36
  LighterAccountConfig,
35
37
  LighterProviderKey,
38
+ MarketSettings,
36
39
  Order,
37
40
  OrdersResponse,
38
41
  Position,
@@ -42,7 +45,12 @@ import type {
42
45
  SignedActionStep,
43
46
  SigningMethod,
44
47
  } from '@lifi/perps-types'
45
- import { ActionType, ActivityType, PerpsErrorCode } from '@lifi/perps-types'
48
+ import {
49
+ ActionType,
50
+ ActivityType,
51
+ MarginMode,
52
+ PerpsErrorCode,
53
+ } from '@lifi/perps-types'
46
54
  import type { Address } from 'viem'
47
55
  import { projectLighterConfigSettings } from './accountConfig.js'
48
56
  import { getAccountSummary } from './accountSummary.js'
@@ -77,6 +85,7 @@ import type {
77
85
  LtTransferHistoryResponse,
78
86
  LtWithdrawHistoryResponse,
79
87
  } from './types/index.js'
88
+ import { LT_MARGIN_MODE_ISOLATED } from './types/index.js'
80
89
  import {
81
90
  decodeActivityCursor,
82
91
  encodeActivityCursor,
@@ -94,12 +103,15 @@ import {
94
103
  fetchDetailedAccount,
95
104
  formatOrderPrice,
96
105
  formatOrderSize,
106
+ leverageFromImf,
97
107
  lighterAsset,
98
108
  mapFill,
99
109
  mapOpenPositions,
100
110
  mapOrderDetail,
111
+ positionMarginConstraints,
101
112
  toIsoFromMs,
102
113
  toIsoFromSeconds,
114
+ toRequiredBig,
103
115
  } from './utils/index.js'
104
116
 
105
117
  const ZERO_FEE_TIER = { maker: '0', taker: '0' }
@@ -755,7 +767,7 @@ export const lighterProvider = (
755
767
  normalizeLighterPublicKey(registeredKey.public_key)
756
768
 
757
769
  const positions: Position[] = mapOpenPositions(account.positions, (id) =>
758
- registry.require(String(id))
770
+ toPerpsMarketDisplay(registry.require(String(id)))
759
771
  )
760
772
 
761
773
  const totalMarginUsed = positions.reduce(
@@ -774,16 +786,24 @@ export const lighterProvider = (
774
786
  categories.find((c) => c.quoteAsset === null)?.id ??
775
787
  LIGHTER_SPOT_CATEGORY_ID
776
788
 
777
- // USDC collateral is the category quote asset → collateralBalances.
778
- // `available_balance` is the free collateral (Lighter's `collateral` is
779
- // gross, i.e. includes margin locked in positions); the locked portion is
780
- // carried by the positions' `marginUsed`.
789
+ // Cross buying power is isolated from per-position allocations. Lighter
790
+ // reports cross equity (already marked by cross uPnL) separately from
791
+ // the initial margin locked by cross positions.
792
+ const availableMargin = toRequiredBig(
793
+ account.cross_asset_value,
794
+ 'cross_asset_value'
795
+ ).minus(
796
+ toRequiredBig(
797
+ account.cross_initial_margin_requirement,
798
+ 'cross_initial_margin_requirement'
799
+ )
800
+ )
781
801
  const collateralBalances: Balance[] = [
782
802
  {
783
803
  categoryId: perpsCategory?.id ?? providerKey,
784
804
  asset: perpsCategory?.quoteAsset ?? lighterAsset('USDC', 'USDC'),
785
- units: account.available_balance,
786
- valueUsd: account.available_balance,
805
+ units: availableMargin.toString(),
806
+ valueUsd: availableMargin.toString(),
787
807
  },
788
808
  ]
789
809
  // Spot token holdings — non-collateral. USDC value is 1:1; other tokens
@@ -872,7 +892,7 @@ export const lighterProvider = (
872
892
  ])
873
893
 
874
894
  let positions: Position[] = mapOpenPositions(account.positions, (id) =>
875
- registry.require(String(id))
895
+ toPerpsMarketDisplay(registry.require(String(id)))
876
896
  )
877
897
 
878
898
  if (params.marketId !== undefined) {
@@ -886,6 +906,50 @@ export const lighterProvider = (
886
906
  }
887
907
  },
888
908
 
909
+ /**
910
+ * Lighter reports a market's margin mode and leverage only on the
911
+ * account's position row, so a market the account never touched (or a
912
+ * missing account) resolves `undefined` rather than a venue default.
913
+ */
914
+ async getMarketSettings(
915
+ params: ProviderGetMarketSettingsParams,
916
+ opts?: SDKRequestOptions
917
+ ): Promise<MarketSettings | undefined> {
918
+ // Spot markets carry no margin mode or leverage.
919
+ if (params.market.categoryId === LIGHTER_SPOT_CATEGORY_ID) {
920
+ return undefined
921
+ }
922
+ let account: LtDetailedAccount
923
+ try {
924
+ account = await fetchDetailedAccount(apiClient(opts), params.address)
925
+ } catch (err) {
926
+ if (
927
+ err instanceof PerpsError &&
928
+ err.code === PerpsErrorCode.AccountNotFound
929
+ ) {
930
+ return undefined
931
+ }
932
+ throw err
933
+ }
934
+ const row = account.positions.find(
935
+ (p) => String(p.market_id) === params.market.marketId
936
+ )
937
+ if (!row) {
938
+ return undefined
939
+ }
940
+ const leverage = leverageFromImf(row.initial_margin_fraction)
941
+ if (leverage === undefined) {
942
+ return undefined
943
+ }
944
+ return {
945
+ marginMode:
946
+ row.margin_mode === LT_MARGIN_MODE_ISOLATED
947
+ ? MarginMode.ISOLATED
948
+ : MarginMode.CROSS,
949
+ leverage,
950
+ }
951
+ },
952
+
889
953
  /**
890
954
  * Lighter's `accountActiveOrders` endpoint takes no limit/cursor and
891
955
  * returns every active order for the account, so the response is always
@@ -1255,6 +1319,8 @@ export const lighterProvider = (
1255
1319
 
1256
1320
  estimateLiquidationPrice,
1257
1321
 
1322
+ positionMarginConstraints,
1323
+
1258
1324
  projectConfig(
1259
1325
  config: AccountConfig,
1260
1326
  setup: ProviderAction[],
@@ -1,16 +1,18 @@
1
- import { summarizeAccount } from '@lifi/perps-sdk'
2
1
  import type {
3
2
  AccountResponse,
4
3
  AccountSummary,
5
4
  Position,
6
5
  } from '@lifi/perps-types'
6
+ import { MarginMode } from '@lifi/perps-types'
7
+ import Big from 'big.js'
7
8
 
8
9
  /**
9
10
  * Roll a Lighter {@link AccountResponse} up into an {@link AccountSummary}.
10
- * Lighter has a single flat collateral model with no abstraction modes: the
11
- * collateral rows hold `available_balance`, which nets locked margin out but
12
- * marks unrealized PnL in — so only the positions' `marginUsed` is added
13
- * back for the portfolio value, never their PnL.
11
+ *
12
+ * Lighter's cross available balance is already marked to market, while an
13
+ * isolated position's unrealized PnL remains inside that position's isolated
14
+ * sub-account. Reconciliation therefore adds every position's locked margin,
15
+ * but adds unrealized PnL only for isolated positions.
14
16
  *
15
17
  * @public
16
18
  */
@@ -18,5 +20,35 @@ export function getAccountSummary(
18
20
  account: AccountResponse,
19
21
  positions: Position[]
20
22
  ): AccountSummary {
21
- return summarizeAccount(account, positions, 'net')
23
+ let availableMargin = new Big(0)
24
+ for (const balance of account.collateralBalances) {
25
+ availableMargin = availableMargin.plus(balance.valueUsd)
26
+ }
27
+
28
+ let nonCollateralValue = new Big(0)
29
+ for (const balance of account.balances) {
30
+ nonCollateralValue = nonCollateralValue.plus(balance.valueUsd)
31
+ }
32
+
33
+ let marginUsed = new Big(0)
34
+ let unrealizedPnl = new Big(0)
35
+ let isolatedUnrealizedPnl = new Big(0)
36
+ for (const position of positions) {
37
+ marginUsed = marginUsed.plus(position.marginUsed)
38
+ unrealizedPnl = unrealizedPnl.plus(position.unrealizedPnl)
39
+ if (position.marginMode === MarginMode.ISOLATED) {
40
+ isolatedUnrealizedPnl = isolatedUnrealizedPnl.plus(position.unrealizedPnl)
41
+ }
42
+ }
43
+
44
+ return {
45
+ portfolioValue: nonCollateralValue
46
+ .plus(availableMargin)
47
+ .plus(marginUsed)
48
+ .plus(isolatedUnrealizedPnl)
49
+ .toString(),
50
+ availableMargin: availableMargin.toString(),
51
+ marginUsed: marginUsed.toString(),
52
+ unrealizedPnl: unrealizedPnl.toString(),
53
+ }
22
54
  }
package/src/constants.ts CHANGED
@@ -22,6 +22,11 @@ export const LIGHTER_SPOT_CATEGORY_ID = 'spot'
22
22
  * @public
23
23
  */
24
24
  export const DEFAULT_LIGHTER_REST_URL = 'https://mainnet.zklighter.elliot.ai'
25
+ /**
26
+ * Default mainnet WebSocket stream URL for Lighter.
27
+ *
28
+ * @public
29
+ */
25
30
  export const DEFAULT_LIGHTER_WS_URL = 'wss://mainnet.zklighter.elliot.ai/stream'
26
31
 
27
32
  /**
@@ -85,9 +90,17 @@ export const LIGHTER_MAINNET_INSTANCE: LighterInstanceConfig = {
85
90
  */
86
91
  export const LIGHTER_RH_PROVIDER_KEY = 'lighter-rh'
87
92
 
88
- /** @public */
93
+ /**
94
+ * Default REST base URL for the Lighter Robinhood deployment.
95
+ *
96
+ * @public
97
+ */
89
98
  export const LIGHTER_RH_REST_URL = 'https://api.rh.lighter.xyz'
90
- /** @public */
99
+ /**
100
+ * Default WebSocket URL for the Lighter Robinhood deployment.
101
+ *
102
+ * @public
103
+ */
91
104
  export const LIGHTER_RH_WS_URL = 'wss://api.rh.lighter.xyz/stream'
92
105
 
93
106
  /**
@@ -11,7 +11,13 @@ import { LIGHTER_PROVIDER_KEY } from '../constants.js'
11
11
 
12
12
  const STORAGE_PREFIX = 'lifi-perps-lighter-key'
13
13
 
14
- /** @public */
14
+ /**
15
+ * Persisted Lighter API-key material associated with one L2 account.
16
+ * `apiKeyPrivateKey` is a Lighter-native signing key, not an Ethereum key;
17
+ * `apiKeyIndex` identifies its registered on-chain slot.
18
+ *
19
+ * @public
20
+ */
15
21
  export interface LighterApiKey {
16
22
  /** Lighter account index, looked up once via accountsByL1Address. */
17
23
  accountIndex: number
@@ -41,12 +47,23 @@ const isLighterApiKey = (value: unknown): value is LighterApiKey => {
41
47
  )
42
48
  }
43
49
 
44
- /** @public */
50
+ /**
51
+ * Storage-backed cache for Lighter API keys. Records are namespaced by L1
52
+ * address and provider instance so multiple Lighter deployments can share one
53
+ * {@link StorageAdapter} without collisions.
54
+ *
55
+ * @public
56
+ */
45
57
  export class LighterKeyStore {
46
58
  private readonly storage: StorageAdapter
47
59
  private readonly cache = new Map<string, LighterApiKey>()
48
60
  private providerKey: LighterProviderKey
49
61
 
62
+ /**
63
+ * Create a key store using `storage` and the optional provider namespace.
64
+ * The default provider key preserves the package's standard Lighter storage
65
+ * namespace.
66
+ */
50
67
  constructor(
51
68
  storage: StorageAdapter,
52
69
  providerKey: LighterProviderKey = LIGHTER_PROVIDER_KEY
@@ -74,6 +91,10 @@ export class LighterKeyStore {
74
91
  : `${STORAGE_PREFIX}:${this.providerKey}:${lower}`
75
92
  }
76
93
 
94
+ /**
95
+ * Load the API key for an L1 address, or `null` when no valid record exists.
96
+ * Invalid persisted records are ignored by the storage validation boundary.
97
+ */
77
98
  async get(address: Address): Promise<LighterApiKey | null> {
78
99
  const key = this.storageKey(address)
79
100
  const cached = this.cache.get(key)
@@ -88,12 +109,20 @@ export class LighterKeyStore {
88
109
  return parsed
89
110
  }
90
111
 
112
+ /**
113
+ * Persist an API key for an L1 address, replacing any existing record under
114
+ * that provider namespace.
115
+ */
91
116
  async set(address: Address, value: LighterApiKey): Promise<void> {
92
117
  const key = this.storageKey(address)
93
118
  this.cache.set(key, value)
94
119
  await this.storage.set(key, JSON.stringify(value))
95
120
  }
96
121
 
122
+ /**
123
+ * Remove the persisted API key for an L1 address and clear its in-memory
124
+ * cache entry.
125
+ */
97
126
  async remove(address: Address): Promise<void> {
98
127
  const key = this.storageKey(address)
99
128
  this.cache.delete(key)
@@ -69,7 +69,13 @@ export type LighterTokenFetcher = (params: {
69
69
  scopes: string
70
70
  }) => Promise<LighterCreateTokenResponse>
71
71
 
72
- /** @public */
72
+ /**
73
+ * Dependencies and overrides for {@link LighterReadOnlyTokenManager}.
74
+ * Storage and token-fetching defaults target the browser's local storage and
75
+ * Lighter's mainnet REST API.
76
+ *
77
+ * @public
78
+ */
73
79
  export interface LighterReadOnlyTokenManagerOptions {
74
80
  storage?: StorageAdapter
75
81
  /**
@@ -87,13 +93,23 @@ export interface LighterReadOnlyTokenManagerOptions {
87
93
  now?: () => number
88
94
  }
89
95
 
90
- /** @public */
96
+ /**
97
+ * Input to the read-only-token approval flow. Extends the shared approval
98
+ * parameters with the L1 address whose wallet authorizes token creation.
99
+ *
100
+ * @public
101
+ */
91
102
  export interface ApproveReadOnlyTokenInputs extends ApproveReadOnlyTokenParams {
92
103
  /** L1 wallet address that signs the create message. */
93
104
  address: Address
94
105
  }
95
106
 
96
- /** @public */
107
+ /**
108
+ * Result of approving or creating a Lighter read-only token. `config` is the
109
+ * account-state projection callers can persist alongside the token.
110
+ *
111
+ * @public
112
+ */
97
113
  export interface ApproveReadOnlyTokenResult {
98
114
  token: LighterReadOnlyToken
99
115
  /** Projection of the post-create Lighter account state. */
@@ -239,6 +255,10 @@ export class LighterReadOnlyTokenManager {
239
255
  await this.storage.set(key, JSON.stringify(token))
240
256
  }
241
257
 
258
+ /**
259
+ * Remove the stored token for an `(address, accountIndex)` pair and clear
260
+ * the corresponding cache entry.
261
+ */
242
262
  async remove(address: Address, accountIndex: number): Promise<void> {
243
263
  const key = this.storageKey(address, accountIndex)
244
264
  this.cache.delete(key)
@@ -21,7 +21,13 @@ import {
21
21
  // is process-global inside the Go runtime; we track which keys are already
22
22
  // initialized so CreateClient runs once per keypair.
23
23
 
24
- /** @public */
24
+ /**
25
+ * Credentials needed to initialize the Lighter WASM client for one account
26
+ * and API-key slot. The private key is Lighter-native signing material; the
27
+ * account and slot indexes select the registered L2 key.
28
+ *
29
+ * @public
30
+ */
25
31
  export interface LighterSignerContext {
26
32
  /** Lighter-native private key (from GenerateAPIKey, NOT an Ethereum key). */
27
33
  apiKeyPrivateKey: string
@@ -31,7 +37,12 @@ export interface LighterSignerContext {
31
37
  accountIndex: number
32
38
  }
33
39
 
34
- /** @public */
40
+ /**
41
+ * Configuration for {@link LighterSigner}, including optional WASM asset
42
+ * overrides and the Lighter REST base URL and signing chain ID.
43
+ *
44
+ * @public
45
+ */
35
46
  export interface LighterSignerConfig extends LoadLighterWasmOptions {
36
47
  /** Lighter REST API base URL. */
37
48
  apiUrl?: string
@@ -39,26 +50,47 @@ export interface LighterSignerConfig extends LoadLighterWasmOptions {
39
50
  chainId?: number
40
51
  }
41
52
 
42
- /** @public */
53
+ /**
54
+ * Signed Lighter transaction blob returned by the WASM signer. `txType`,
55
+ * `txInfo`, and `txHash` are passed to the venue's transaction submission
56
+ * endpoint; `txInfo` is an encoded transaction payload.
57
+ *
58
+ * @public
59
+ */
43
60
  export interface LighterSignedBlob {
44
61
  txType: number
45
62
  txInfo: string
46
63
  txHash: string
47
64
  }
48
65
 
49
- /** @public */
66
+ /**
67
+ * Signed REGISTER_API_KEY (ChangePubKey) result, including the EIP-191 message
68
+ * that the user's L1 wallet must countersign before submission.
69
+ *
70
+ * @public
71
+ */
50
72
  export interface ChangePubKeyResult extends LighterSignedBlob {
51
73
  /** EIP-191 message the L1 Ethereum wallet must sign to authorize the key rotation. */
52
74
  messageToSign: string
53
75
  }
54
76
 
55
- /** @public */
77
+ /**
78
+ * Signed APPROVE_INTEGRATOR result, including the EIP-191 L1 message required
79
+ * to authorize the integrator approval.
80
+ *
81
+ * @public
82
+ */
56
83
  export interface ApproveIntegratorResult extends LighterSignedBlob {
57
84
  /** EIP-191 `L2ApproveIntegrator` L1 body the user's wallet must countersign to authorize the integrator approval. */
58
85
  messageToSign: string
59
86
  }
60
87
 
61
- /** @public */
88
+ /**
89
+ * Lighter-native API keypair generated by the WASM signer. These keys are
90
+ * distinct from an Ethereum wallet keypair.
91
+ *
92
+ * @public
93
+ */
62
94
  export interface ApiKeyPair {
63
95
  publicKey: string
64
96
  privateKey: string
@@ -94,7 +126,13 @@ const LIGHTER_ROUTE_BY_DEX: Record<string, number> = {
94
126
  spot: LT_ROUTE_SPOT,
95
127
  }
96
128
 
97
- /** @public */
129
+ /**
130
+ * WASM-backed signer for Lighter API-key transactions and L1-countersigned
131
+ * hybrid flows. The instance memoizes WASM initialization and registered
132
+ * `(apiKeyIndex, accountIndex)` clients.
133
+ *
134
+ * @public
135
+ */
98
136
  export class LighterSigner {
99
137
  private readonly apiUrl: string
100
138
  private readonly chainId: number
@@ -112,6 +150,10 @@ export class LighterSigner {
112
150
  }
113
151
  }
114
152
 
153
+ /**
154
+ * Load and cache the Go WASM signer exports. Most signing methods initialize
155
+ * lazily, so callers only need this method when they want an explicit warm-up.
156
+ */
115
157
  async initialize(): Promise<void> {
116
158
  if (!this.wasm) {
117
159
  this.wasm = await loadLighterWasm(this.loaderOptions)