@lifi/perps-sdk-provider-lighter 0.2.0-alpha.0

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 (405) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +176 -0
  3. package/dist/cjs/LighterProvider.d.ts +20 -0
  4. package/dist/cjs/LighterProvider.d.ts.map +1 -0
  5. package/dist/cjs/LighterProvider.js +592 -0
  6. package/dist/cjs/LighterProvider.js.map +1 -0
  7. package/dist/cjs/accountConfig.d.ts +3 -0
  8. package/dist/cjs/accountConfig.d.ts.map +1 -0
  9. package/dist/cjs/accountConfig.js +69 -0
  10. package/dist/cjs/accountConfig.js.map +1 -0
  11. package/dist/cjs/accountSummary.d.ts +3 -0
  12. package/dist/cjs/accountSummary.d.ts.map +1 -0
  13. package/dist/cjs/accountSummary.js +8 -0
  14. package/dist/cjs/accountSummary.js.map +1 -0
  15. package/dist/cjs/constants.d.ts +14 -0
  16. package/dist/cjs/constants.d.ts.map +1 -0
  17. package/dist/cjs/constants.js +18 -0
  18. package/dist/cjs/constants.js.map +1 -0
  19. package/dist/cjs/index.d.ts +11 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +35 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/package.json +1 -0
  24. package/dist/cjs/signers/LighterKeyStore.d.ts +18 -0
  25. package/dist/cjs/signers/LighterKeyStore.d.ts.map +1 -0
  26. package/dist/cjs/signers/LighterKeyStore.js +54 -0
  27. package/dist/cjs/signers/LighterKeyStore.js.map +1 -0
  28. package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts +56 -0
  29. package/dist/cjs/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
  30. package/dist/cjs/signers/LighterReadOnlyTokenManager.js +127 -0
  31. package/dist/cjs/signers/LighterReadOnlyTokenManager.js.map +1 -0
  32. package/dist/cjs/signers/LighterSigner.d.ts +41 -0
  33. package/dist/cjs/signers/LighterSigner.d.ts.map +1 -0
  34. package/dist/cjs/signers/LighterSigner.js +175 -0
  35. package/dist/cjs/signers/LighterSigner.js.map +1 -0
  36. package/dist/cjs/signers/createAuthToken.d.ts +12 -0
  37. package/dist/cjs/signers/createAuthToken.d.ts.map +1 -0
  38. package/dist/cjs/signers/createAuthToken.js +28 -0
  39. package/dist/cjs/signers/createAuthToken.js.map +1 -0
  40. package/dist/cjs/signers/index.d.ts +11 -0
  41. package/dist/cjs/signers/index.d.ts.map +1 -0
  42. package/dist/cjs/signers/index.js +19 -0
  43. package/dist/cjs/signers/index.js.map +1 -0
  44. package/dist/cjs/signers/signActions.d.ts +15 -0
  45. package/dist/cjs/signers/signActions.d.ts.map +1 -0
  46. package/dist/cjs/signers/signActions.js +142 -0
  47. package/dist/cjs/signers/signActions.js.map +1 -0
  48. package/dist/cjs/signers/wasmLoader.d.ts +42 -0
  49. package/dist/cjs/signers/wasmLoader.d.ts.map +1 -0
  50. package/dist/cjs/signers/wasmLoader.js +166 -0
  51. package/dist/cjs/signers/wasmLoader.js.map +1 -0
  52. package/dist/cjs/types/account.d.ts +97 -0
  53. package/dist/cjs/types/account.d.ts.map +1 -0
  54. package/dist/cjs/types/account.js +3 -0
  55. package/dist/cjs/types/account.js.map +1 -0
  56. package/dist/cjs/types/action.d.ts +72 -0
  57. package/dist/cjs/types/action.d.ts.map +1 -0
  58. package/dist/cjs/types/action.js +23 -0
  59. package/dist/cjs/types/action.js.map +1 -0
  60. package/dist/cjs/types/activity.d.ts +73 -0
  61. package/dist/cjs/types/activity.d.ts.map +1 -0
  62. package/dist/cjs/types/activity.js +3 -0
  63. package/dist/cjs/types/activity.js.map +1 -0
  64. package/dist/cjs/types/asset.d.ts +122 -0
  65. package/dist/cjs/types/asset.d.ts.map +1 -0
  66. package/dist/cjs/types/asset.js +3 -0
  67. package/dist/cjs/types/asset.js.map +1 -0
  68. package/dist/cjs/types/fill.d.ts +29 -0
  69. package/dist/cjs/types/fill.d.ts.map +1 -0
  70. package/dist/cjs/types/fill.js +3 -0
  71. package/dist/cjs/types/fill.js.map +1 -0
  72. package/dist/cjs/types/index.d.ts +9 -0
  73. package/dist/cjs/types/index.d.ts.map +1 -0
  74. package/dist/cjs/types/index.js +25 -0
  75. package/dist/cjs/types/index.js.map +1 -0
  76. package/dist/cjs/types/order.d.ts +57 -0
  77. package/dist/cjs/types/order.d.ts.map +1 -0
  78. package/dist/cjs/types/order.js +3 -0
  79. package/dist/cjs/types/order.js.map +1 -0
  80. package/dist/cjs/types/submit.d.ts +39 -0
  81. package/dist/cjs/types/submit.d.ts.map +1 -0
  82. package/dist/cjs/types/submit.js +3 -0
  83. package/dist/cjs/types/submit.js.map +1 -0
  84. package/dist/cjs/types/ws.d.ts +84 -0
  85. package/dist/cjs/types/ws.d.ts.map +1 -0
  86. package/dist/cjs/types/ws.js +3 -0
  87. package/dist/cjs/types/ws.js.map +1 -0
  88. package/dist/cjs/utils/activityCursor.d.ts +12 -0
  89. package/dist/cjs/utils/activityCursor.d.ts.map +1 -0
  90. package/dist/cjs/utils/activityCursor.js +85 -0
  91. package/dist/cjs/utils/activityCursor.js.map +1 -0
  92. package/dist/cjs/utils/apiClient.d.ts +26 -0
  93. package/dist/cjs/utils/apiClient.d.ts.map +1 -0
  94. package/dist/cjs/utils/apiClient.js +94 -0
  95. package/dist/cjs/utils/apiClient.js.map +1 -0
  96. package/dist/cjs/utils/fetchDetailedAccount.d.ts +5 -0
  97. package/dist/cjs/utils/fetchDetailedAccount.d.ts.map +1 -0
  98. package/dist/cjs/utils/fetchDetailedAccount.js +22 -0
  99. package/dist/cjs/utils/fetchDetailedAccount.js.map +1 -0
  100. package/dist/cjs/utils/index.d.ts +16 -0
  101. package/dist/cjs/utils/index.d.ts.map +1 -0
  102. package/dist/cjs/utils/index.js +45 -0
  103. package/dist/cjs/utils/index.js.map +1 -0
  104. package/dist/cjs/utils/lighterAsset.d.ts +3 -0
  105. package/dist/cjs/utils/lighterAsset.d.ts.map +1 -0
  106. package/dist/cjs/utils/lighterAsset.js +12 -0
  107. package/dist/cjs/utils/lighterAsset.js.map +1 -0
  108. package/dist/cjs/utils/liquidation.d.ts +4 -0
  109. package/dist/cjs/utils/liquidation.d.ts.map +1 -0
  110. package/dist/cjs/utils/liquidation.js +16 -0
  111. package/dist/cjs/utils/liquidation.js.map +1 -0
  112. package/dist/cjs/utils/mapFill.d.ts +4 -0
  113. package/dist/cjs/utils/mapFill.d.ts.map +1 -0
  114. package/dist/cjs/utils/mapFill.js +61 -0
  115. package/dist/cjs/utils/mapFill.js.map +1 -0
  116. package/dist/cjs/utils/mapOpenPositions.d.ts +4 -0
  117. package/dist/cjs/utils/mapOpenPositions.d.ts.map +1 -0
  118. package/dist/cjs/utils/mapOpenPositions.js +9 -0
  119. package/dist/cjs/utils/mapOpenPositions.js.map +1 -0
  120. package/dist/cjs/utils/mapOrder.d.ts +15 -0
  121. package/dist/cjs/utils/mapOrder.d.ts.map +1 -0
  122. package/dist/cjs/utils/mapOrder.js +164 -0
  123. package/dist/cjs/utils/mapOrder.js.map +1 -0
  124. package/dist/cjs/utils/mapPosition.d.ts +4 -0
  125. package/dist/cjs/utils/mapPosition.d.ts.map +1 -0
  126. package/dist/cjs/utils/mapPosition.js +30 -0
  127. package/dist/cjs/utils/mapPosition.js.map +1 -0
  128. package/dist/cjs/utils/ohlcvInterval.d.ts +2 -0
  129. package/dist/cjs/utils/ohlcvInterval.d.ts.map +1 -0
  130. package/dist/cjs/utils/ohlcvInterval.js +26 -0
  131. package/dist/cjs/utils/ohlcvInterval.js.map +1 -0
  132. package/dist/cjs/utils/orderFormatting.d.ts +4 -0
  133. package/dist/cjs/utils/orderFormatting.d.ts.map +1 -0
  134. package/dist/cjs/utils/orderFormatting.js +23 -0
  135. package/dist/cjs/utils/orderFormatting.js.map +1 -0
  136. package/dist/cjs/utils/time.d.ts +3 -0
  137. package/dist/cjs/utils/time.d.ts.map +1 -0
  138. package/dist/cjs/utils/time.js +8 -0
  139. package/dist/cjs/utils/time.js.map +1 -0
  140. package/dist/cjs/utils/wireEncoding.d.ts +9 -0
  141. package/dist/cjs/utils/wireEncoding.d.ts.map +1 -0
  142. package/dist/cjs/utils/wireEncoding.js +87 -0
  143. package/dist/cjs/utils/wireEncoding.js.map +1 -0
  144. package/dist/cjs/websocket/LighterWsProvider.d.ts +45 -0
  145. package/dist/cjs/websocket/LighterWsProvider.d.ts.map +1 -0
  146. package/dist/cjs/websocket/LighterWsProvider.js +396 -0
  147. package/dist/cjs/websocket/LighterWsProvider.js.map +1 -0
  148. package/dist/esm/LighterProvider.d.ts +105 -0
  149. package/dist/esm/LighterProvider.d.ts.map +1 -0
  150. package/dist/esm/LighterProvider.js +684 -0
  151. package/dist/esm/LighterProvider.js.map +1 -0
  152. package/dist/esm/accountConfig.d.ts +14 -0
  153. package/dist/esm/accountConfig.d.ts.map +1 -0
  154. package/dist/esm/accountConfig.js +135 -0
  155. package/dist/esm/accountConfig.js.map +1 -0
  156. package/dist/esm/accountSummary.d.ts +12 -0
  157. package/dist/esm/accountSummary.d.ts.map +1 -0
  158. package/dist/esm/accountSummary.js +14 -0
  159. package/dist/esm/accountSummary.js.map +1 -0
  160. package/dist/esm/constants.d.ts +74 -0
  161. package/dist/esm/constants.d.ts.map +1 -0
  162. package/dist/esm/constants.js +73 -0
  163. package/dist/esm/constants.js.map +1 -0
  164. package/dist/esm/index.d.ts +22 -0
  165. package/dist/esm/index.d.ts.map +1 -0
  166. package/dist/esm/index.js +22 -0
  167. package/dist/esm/index.js.map +1 -0
  168. package/dist/esm/package.json +1 -0
  169. package/dist/esm/signers/LighterKeyStore.d.ts +24 -0
  170. package/dist/esm/signers/LighterKeyStore.d.ts.map +1 -0
  171. package/dist/esm/signers/LighterKeyStore.js +55 -0
  172. package/dist/esm/signers/LighterKeyStore.js.map +1 -0
  173. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts +157 -0
  174. package/dist/esm/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
  175. package/dist/esm/signers/LighterReadOnlyTokenManager.js +194 -0
  176. package/dist/esm/signers/LighterReadOnlyTokenManager.js.map +1 -0
  177. package/dist/esm/signers/LighterSigner.d.ts +94 -0
  178. package/dist/esm/signers/LighterSigner.d.ts.map +1 -0
  179. package/dist/esm/signers/LighterSigner.js +228 -0
  180. package/dist/esm/signers/LighterSigner.js.map +1 -0
  181. package/dist/esm/signers/createAuthToken.d.ts +36 -0
  182. package/dist/esm/signers/createAuthToken.d.ts.map +1 -0
  183. package/dist/esm/signers/createAuthToken.js +42 -0
  184. package/dist/esm/signers/createAuthToken.js.map +1 -0
  185. package/dist/esm/signers/index.d.ts +11 -0
  186. package/dist/esm/signers/index.d.ts.map +1 -0
  187. package/dist/esm/signers/index.js +7 -0
  188. package/dist/esm/signers/index.js.map +1 -0
  189. package/dist/esm/signers/signActions.d.ts +54 -0
  190. package/dist/esm/signers/signActions.d.ts.map +1 -0
  191. package/dist/esm/signers/signActions.js +193 -0
  192. package/dist/esm/signers/signActions.js.map +1 -0
  193. package/dist/esm/signers/wasmLoader.d.ts +79 -0
  194. package/dist/esm/signers/wasmLoader.d.ts.map +1 -0
  195. package/dist/esm/signers/wasmLoader.js +180 -0
  196. package/dist/esm/signers/wasmLoader.js.map +1 -0
  197. package/dist/esm/types/account.d.ts +113 -0
  198. package/dist/esm/types/account.d.ts.map +1 -0
  199. package/dist/esm/types/account.js +4 -0
  200. package/dist/esm/types/account.js.map +1 -0
  201. package/dist/esm/types/action.d.ts +146 -0
  202. package/dist/esm/types/action.d.ts.map +1 -0
  203. package/dist/esm/types/action.js +50 -0
  204. package/dist/esm/types/action.js.map +1 -0
  205. package/dist/esm/types/activity.d.ts +83 -0
  206. package/dist/esm/types/activity.d.ts.map +1 -0
  207. package/dist/esm/types/activity.js +4 -0
  208. package/dist/esm/types/activity.js.map +1 -0
  209. package/dist/esm/types/asset.d.ts +134 -0
  210. package/dist/esm/types/asset.d.ts.map +1 -0
  211. package/dist/esm/types/asset.js +3 -0
  212. package/dist/esm/types/asset.js.map +1 -0
  213. package/dist/esm/types/fill.d.ts +31 -0
  214. package/dist/esm/types/fill.d.ts.map +1 -0
  215. package/dist/esm/types/fill.js +3 -0
  216. package/dist/esm/types/fill.js.map +1 -0
  217. package/dist/esm/types/index.d.ts +9 -0
  218. package/dist/esm/types/index.d.ts.map +1 -0
  219. package/dist/esm/types/index.js +12 -0
  220. package/dist/esm/types/index.js.map +1 -0
  221. package/dist/esm/types/order.d.ts +61 -0
  222. package/dist/esm/types/order.d.ts.map +1 -0
  223. package/dist/esm/types/order.js +3 -0
  224. package/dist/esm/types/order.js.map +1 -0
  225. package/dist/esm/types/submit.d.ts +76 -0
  226. package/dist/esm/types/submit.d.ts.map +1 -0
  227. package/dist/esm/types/submit.js +3 -0
  228. package/dist/esm/types/submit.js.map +1 -0
  229. package/dist/esm/types/ws.d.ts +124 -0
  230. package/dist/esm/types/ws.d.ts.map +1 -0
  231. package/dist/esm/types/ws.js +11 -0
  232. package/dist/esm/types/ws.js.map +1 -0
  233. package/dist/esm/utils/activityCursor.d.ts +51 -0
  234. package/dist/esm/utils/activityCursor.d.ts.map +1 -0
  235. package/dist/esm/utils/activityCursor.js +99 -0
  236. package/dist/esm/utils/activityCursor.js.map +1 -0
  237. package/dist/esm/utils/apiClient.d.ts +65 -0
  238. package/dist/esm/utils/apiClient.d.ts.map +1 -0
  239. package/dist/esm/utils/apiClient.js +131 -0
  240. package/dist/esm/utils/apiClient.js.map +1 -0
  241. package/dist/esm/utils/fetchDetailedAccount.d.ts +11 -0
  242. package/dist/esm/utils/fetchDetailedAccount.d.ts.map +1 -0
  243. package/dist/esm/utils/fetchDetailedAccount.js +24 -0
  244. package/dist/esm/utils/fetchDetailedAccount.js.map +1 -0
  245. package/dist/esm/utils/index.d.ts +16 -0
  246. package/dist/esm/utils/index.d.ts.map +1 -0
  247. package/dist/esm/utils/index.js +17 -0
  248. package/dist/esm/utils/index.js.map +1 -0
  249. package/dist/esm/utils/lighterAsset.d.ts +4 -0
  250. package/dist/esm/utils/lighterAsset.d.ts.map +1 -0
  251. package/dist/esm/utils/lighterAsset.js +9 -0
  252. package/dist/esm/utils/lighterAsset.js.map +1 -0
  253. package/dist/esm/utils/liquidation.d.ts +22 -0
  254. package/dist/esm/utils/liquidation.d.ts.map +1 -0
  255. package/dist/esm/utils/liquidation.js +31 -0
  256. package/dist/esm/utils/liquidation.js.map +1 -0
  257. package/dist/esm/utils/mapFill.d.ts +10 -0
  258. package/dist/esm/utils/mapFill.d.ts.map +1 -0
  259. package/dist/esm/utils/mapFill.js +72 -0
  260. package/dist/esm/utils/mapFill.js.map +1 -0
  261. package/dist/esm/utils/mapOpenPositions.d.ts +11 -0
  262. package/dist/esm/utils/mapOpenPositions.d.ts.map +1 -0
  263. package/dist/esm/utils/mapOpenPositions.js +12 -0
  264. package/dist/esm/utils/mapOpenPositions.js.map +1 -0
  265. package/dist/esm/utils/mapOrder.d.ts +72 -0
  266. package/dist/esm/utils/mapOrder.d.ts.map +1 -0
  267. package/dist/esm/utils/mapOrder.js +219 -0
  268. package/dist/esm/utils/mapOrder.js.map +1 -0
  269. package/dist/esm/utils/mapPosition.d.ts +9 -0
  270. package/dist/esm/utils/mapPosition.d.ts.map +1 -0
  271. package/dist/esm/utils/mapPosition.js +34 -0
  272. package/dist/esm/utils/mapPosition.js.map +1 -0
  273. package/dist/esm/utils/ohlcvInterval.d.ts +3 -0
  274. package/dist/esm/utils/ohlcvInterval.d.ts.map +1 -0
  275. package/dist/esm/utils/ohlcvInterval.js +30 -0
  276. package/dist/esm/utils/ohlcvInterval.js.map +1 -0
  277. package/dist/esm/utils/orderFormatting.d.ts +29 -0
  278. package/dist/esm/utils/orderFormatting.d.ts.map +1 -0
  279. package/dist/esm/utils/orderFormatting.js +41 -0
  280. package/dist/esm/utils/orderFormatting.js.map +1 -0
  281. package/dist/esm/utils/time.d.ts +5 -0
  282. package/dist/esm/utils/time.d.ts.map +1 -0
  283. package/dist/esm/utils/time.js +5 -0
  284. package/dist/esm/utils/time.js.map +1 -0
  285. package/dist/esm/utils/wireEncoding.d.ts +72 -0
  286. package/dist/esm/utils/wireEncoding.d.ts.map +1 -0
  287. package/dist/esm/utils/wireEncoding.js +129 -0
  288. package/dist/esm/utils/wireEncoding.js.map +1 -0
  289. package/dist/esm/websocket/LighterWsProvider.d.ts +97 -0
  290. package/dist/esm/websocket/LighterWsProvider.d.ts.map +1 -0
  291. package/dist/esm/websocket/LighterWsProvider.js +489 -0
  292. package/dist/esm/websocket/LighterWsProvider.js.map +1 -0
  293. package/dist/types/LighterProvider.d.ts +105 -0
  294. package/dist/types/LighterProvider.d.ts.map +1 -0
  295. package/dist/types/accountConfig.d.ts +14 -0
  296. package/dist/types/accountConfig.d.ts.map +1 -0
  297. package/dist/types/accountSummary.d.ts +12 -0
  298. package/dist/types/accountSummary.d.ts.map +1 -0
  299. package/dist/types/constants.d.ts +74 -0
  300. package/dist/types/constants.d.ts.map +1 -0
  301. package/dist/types/index.d.ts +22 -0
  302. package/dist/types/index.d.ts.map +1 -0
  303. package/dist/types/signers/LighterKeyStore.d.ts +24 -0
  304. package/dist/types/signers/LighterKeyStore.d.ts.map +1 -0
  305. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts +157 -0
  306. package/dist/types/signers/LighterReadOnlyTokenManager.d.ts.map +1 -0
  307. package/dist/types/signers/LighterSigner.d.ts +94 -0
  308. package/dist/types/signers/LighterSigner.d.ts.map +1 -0
  309. package/dist/types/signers/createAuthToken.d.ts +36 -0
  310. package/dist/types/signers/createAuthToken.d.ts.map +1 -0
  311. package/dist/types/signers/index.d.ts +11 -0
  312. package/dist/types/signers/index.d.ts.map +1 -0
  313. package/dist/types/signers/signActions.d.ts +54 -0
  314. package/dist/types/signers/signActions.d.ts.map +1 -0
  315. package/dist/types/signers/wasmLoader.d.ts +79 -0
  316. package/dist/types/signers/wasmLoader.d.ts.map +1 -0
  317. package/dist/types/types/account.d.ts +113 -0
  318. package/dist/types/types/account.d.ts.map +1 -0
  319. package/dist/types/types/action.d.ts +146 -0
  320. package/dist/types/types/action.d.ts.map +1 -0
  321. package/dist/types/types/activity.d.ts +83 -0
  322. package/dist/types/types/activity.d.ts.map +1 -0
  323. package/dist/types/types/asset.d.ts +134 -0
  324. package/dist/types/types/asset.d.ts.map +1 -0
  325. package/dist/types/types/fill.d.ts +31 -0
  326. package/dist/types/types/fill.d.ts.map +1 -0
  327. package/dist/types/types/index.d.ts +9 -0
  328. package/dist/types/types/index.d.ts.map +1 -0
  329. package/dist/types/types/order.d.ts +61 -0
  330. package/dist/types/types/order.d.ts.map +1 -0
  331. package/dist/types/types/submit.d.ts +76 -0
  332. package/dist/types/types/submit.d.ts.map +1 -0
  333. package/dist/types/types/ws.d.ts +124 -0
  334. package/dist/types/types/ws.d.ts.map +1 -0
  335. package/dist/types/utils/activityCursor.d.ts +51 -0
  336. package/dist/types/utils/activityCursor.d.ts.map +1 -0
  337. package/dist/types/utils/apiClient.d.ts +65 -0
  338. package/dist/types/utils/apiClient.d.ts.map +1 -0
  339. package/dist/types/utils/fetchDetailedAccount.d.ts +11 -0
  340. package/dist/types/utils/fetchDetailedAccount.d.ts.map +1 -0
  341. package/dist/types/utils/index.d.ts +16 -0
  342. package/dist/types/utils/index.d.ts.map +1 -0
  343. package/dist/types/utils/lighterAsset.d.ts +4 -0
  344. package/dist/types/utils/lighterAsset.d.ts.map +1 -0
  345. package/dist/types/utils/liquidation.d.ts +22 -0
  346. package/dist/types/utils/liquidation.d.ts.map +1 -0
  347. package/dist/types/utils/mapFill.d.ts +10 -0
  348. package/dist/types/utils/mapFill.d.ts.map +1 -0
  349. package/dist/types/utils/mapOpenPositions.d.ts +11 -0
  350. package/dist/types/utils/mapOpenPositions.d.ts.map +1 -0
  351. package/dist/types/utils/mapOrder.d.ts +72 -0
  352. package/dist/types/utils/mapOrder.d.ts.map +1 -0
  353. package/dist/types/utils/mapPosition.d.ts +9 -0
  354. package/dist/types/utils/mapPosition.d.ts.map +1 -0
  355. package/dist/types/utils/ohlcvInterval.d.ts +3 -0
  356. package/dist/types/utils/ohlcvInterval.d.ts.map +1 -0
  357. package/dist/types/utils/orderFormatting.d.ts +29 -0
  358. package/dist/types/utils/orderFormatting.d.ts.map +1 -0
  359. package/dist/types/utils/time.d.ts +5 -0
  360. package/dist/types/utils/time.d.ts.map +1 -0
  361. package/dist/types/utils/wireEncoding.d.ts +72 -0
  362. package/dist/types/utils/wireEncoding.d.ts.map +1 -0
  363. package/dist/types/websocket/LighterWsProvider.d.ts +97 -0
  364. package/dist/types/websocket/LighterWsProvider.d.ts.map +1 -0
  365. package/dist/wasm/lighter-signer.wasm +0 -0
  366. package/dist/wasm/wasm_exec.js +575 -0
  367. package/package.json +67 -0
  368. package/src/LighterProvider.ts +1167 -0
  369. package/src/accountConfig.ts +162 -0
  370. package/src/accountSummary.ts +22 -0
  371. package/src/constants.ts +89 -0
  372. package/src/index.ts +37 -0
  373. package/src/signers/LighterKeyStore.ts +79 -0
  374. package/src/signers/LighterReadOnlyTokenManager.ts +340 -0
  375. package/src/signers/LighterSigner.ts +400 -0
  376. package/src/signers/createAuthToken.ts +69 -0
  377. package/src/signers/index.ts +36 -0
  378. package/src/signers/signActions.ts +311 -0
  379. package/src/signers/wasmLoader.ts +293 -0
  380. package/src/types/account.ts +123 -0
  381. package/src/types/action.ts +163 -0
  382. package/src/types/activity.ts +94 -0
  383. package/src/types/asset.ts +146 -0
  384. package/src/types/fill.ts +42 -0
  385. package/src/types/index.ts +12 -0
  386. package/src/types/order.ts +65 -0
  387. package/src/types/submit.ts +83 -0
  388. package/src/types/ws.ts +136 -0
  389. package/src/utils/activityCursor.ts +150 -0
  390. package/src/utils/apiClient.ts +185 -0
  391. package/src/utils/fetchDetailedAccount.ts +46 -0
  392. package/src/utils/index.ts +38 -0
  393. package/src/utils/lighterAsset.ts +10 -0
  394. package/src/utils/liquidation.ts +39 -0
  395. package/src/utils/mapFill.ts +108 -0
  396. package/src/utils/mapOpenPositions.ts +18 -0
  397. package/src/utils/mapOrder.ts +258 -0
  398. package/src/utils/mapPosition.ts +42 -0
  399. package/src/utils/ohlcvInterval.ts +34 -0
  400. package/src/utils/orderFormatting.ts +46 -0
  401. package/src/utils/time.ts +6 -0
  402. package/src/utils/wireEncoding.ts +179 -0
  403. package/src/websocket/LighterWsProvider.ts +725 -0
  404. package/wasm/lighter-signer.wasm +0 -0
  405. package/wasm/wasm_exec.js +575 -0
@@ -0,0 +1,400 @@
1
+ import { ActionType } from '@lifi/perps-types'
2
+ import {
3
+ type LighterWasmExports,
4
+ type LoadLighterWasmOptions,
5
+ loadLighterWasm,
6
+ type SignResult,
7
+ } from './wasmLoader.js'
8
+
9
+ // Every Sign* call needs the Go signer initialized with the API private key
10
+ // for a given (apiKeyIndex, accountIndex) pair via CreateClient. The context
11
+ // is process-global inside the Go runtime; we track which keys are already
12
+ // initialized so CreateClient runs once per keypair.
13
+
14
+ /** @public */
15
+ export interface LighterSignerContext {
16
+ /** Lighter-native private key (from GenerateAPIKey, NOT an Ethereum key). */
17
+ apiKeyPrivateKey: string
18
+ /** API key slot registered on-chain (0-255). */
19
+ apiKeyIndex: number
20
+ /** Lighter account index — looked up from the user's L1 Ethereum address. */
21
+ accountIndex: number
22
+ }
23
+
24
+ /** @public */
25
+ export interface LighterSignerConfig extends LoadLighterWasmOptions {
26
+ /** Lighter REST API base URL. */
27
+ apiUrl?: string
28
+ /** Lighter chain ID (304 = mainnet). */
29
+ chainId?: number
30
+ }
31
+
32
+ /** @public */
33
+ export interface LighterSignedBlob {
34
+ txType: number
35
+ txInfo: string
36
+ txHash: string
37
+ }
38
+
39
+ /** @public */
40
+ export interface ChangePubKeyResult extends LighterSignedBlob {
41
+ /** EIP-191 message the L1 Ethereum wallet must sign to authorize the key rotation. */
42
+ messageToSign: string
43
+ }
44
+
45
+ /** @public */
46
+ export interface ApiKeyPair {
47
+ publicKey: string
48
+ privateKey: string
49
+ }
50
+
51
+ const DEFAULT_API_URL = 'https://mainnet.zklighter.elliot.ai'
52
+ const DEFAULT_CHAIN_ID = 304
53
+
54
+ /** @public */
55
+ export class LighterSigner {
56
+ private readonly apiUrl: string
57
+ private readonly chainId: number
58
+ private readonly loaderOptions: LoadLighterWasmOptions
59
+ private wasm: LighterWasmExports | undefined
60
+ private readonly registeredClients = new Set<string>()
61
+
62
+ constructor(config: LighterSignerConfig = {}) {
63
+ this.apiUrl = config.apiUrl ?? DEFAULT_API_URL
64
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID
65
+ this.loaderOptions = {
66
+ wasmBinaryUrl: config.wasmBinaryUrl,
67
+ wasmExecJsUrl: config.wasmExecJsUrl,
68
+ wasmExecJsSource: config.wasmExecJsSource,
69
+ }
70
+ }
71
+
72
+ async initialize(): Promise<void> {
73
+ if (!this.wasm) {
74
+ this.wasm = await loadLighterWasm(this.loaderOptions)
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Generate a fresh Lighter API keypair. Pass an optional 32-byte hex seed
80
+ * for deterministic generation (used in tests); omit for a random key.
81
+ */
82
+ async generateAPIKey(seed?: string): Promise<ApiKeyPair> {
83
+ const wasm = await this.ensureLoaded()
84
+ const result = wasm.GenerateAPIKey(seed ?? '')
85
+ if (result.error) {
86
+ throw new Error(`Lighter GenerateAPIKey failed: ${result.error}`)
87
+ }
88
+ if (!result.publicKey || !result.privateKey) {
89
+ throw new Error('Lighter GenerateAPIKey returned an incomplete result')
90
+ }
91
+ return { publicKey: result.publicKey, privateKey: result.privateKey }
92
+ }
93
+
94
+ /**
95
+ * Sign an action blob with the provided (apiKeyPrivateKey, apiKeyIndex,
96
+ * accountIndex) context. `wasmSignParams` comes straight from the backend's
97
+ * `WasmBlobActionStep`. Returns the signed `{ txType, txInfo, txHash }`
98
+ * triple the backend forwards to Lighter's `sendTx` endpoint.
99
+ *
100
+ * For REGISTER_API_KEY use `signChangePubKey` instead — it returns an
101
+ * additional `messageToSign` the L1 wallet must countersign.
102
+ */
103
+ async sign(
104
+ action: ActionType,
105
+ wasmSignParams: Record<string, unknown>,
106
+ context: LighterSignerContext
107
+ ): Promise<LighterSignedBlob> {
108
+ if (action === ActionType.REGISTER_API_KEY) {
109
+ throw new Error(
110
+ 'Use signChangePubKey() for REGISTER_API_KEY — the L1 eth_sign hop ' +
111
+ 'must be coordinated by the caller.'
112
+ )
113
+ }
114
+ const wasm = await this.ensureLoaded()
115
+ await this.ensureClient(context)
116
+ const result = this.dispatch(wasm, action, wasmSignParams, context)
117
+ return unwrap(result, action)
118
+ }
119
+
120
+ /**
121
+ * Step 1 of the REGISTER_API_KEY flow. Generates the WASM blob for a
122
+ * ChangePubKey tx with `L1Sig` left empty, plus the canonical EIP-191
123
+ * message the L1 Ethereum wallet must sign next.
124
+ *
125
+ * Requires the freshly-generated `privateKey` (returned by
126
+ * {@link generateAPIKey}) — the Go WASM signer registers a per-slot client
127
+ * keyed on `(apiKeyIndex, accountIndex)` before it'll sign anything for
128
+ * that slot, including the ChangePubKey that's about to register the key
129
+ * on-chain. This is purely client-side bookkeeping; it does not touch the
130
+ * Lighter API.
131
+ */
132
+ async signChangePubKey(
133
+ pubKeyHex: string,
134
+ privateKey: string,
135
+ nonce: number,
136
+ apiKeyIndex: number,
137
+ accountIndex: number,
138
+ skipNonce: 0 | 1 = 0
139
+ ): Promise<ChangePubKeyResult> {
140
+ const wasm = await this.ensureLoaded()
141
+ await this.ensureClient({
142
+ apiKeyPrivateKey: privateKey,
143
+ apiKeyIndex,
144
+ accountIndex,
145
+ })
146
+ // 5-arg call (matches lighter-python's signer wrapper). `skipNonce`:
147
+ // 0 — embed the supplied nonce and have Lighter enforce it on submit.
148
+ // 1 — embed the nonce but let Lighter pick / not enforce; used for
149
+ // ChangePubKey to sidestep `/nextNonce` vs `/sendTx` disagreement
150
+ // on slot re-claims.
151
+ const result = wasm.SignChangePubKey(
152
+ pubKeyHex,
153
+ skipNonce,
154
+ nonce,
155
+ apiKeyIndex,
156
+ accountIndex
157
+ )
158
+ if (result.error) {
159
+ throw new Error(`Lighter SignChangePubKey failed: ${result.error}`)
160
+ }
161
+ if (
162
+ result.txType === undefined ||
163
+ result.txInfo === undefined ||
164
+ result.txHash === undefined ||
165
+ !result.messageToSign
166
+ ) {
167
+ throw new Error('Lighter SignChangePubKey returned incomplete result')
168
+ }
169
+ return {
170
+ txType: result.txType,
171
+ txInfo: result.txInfo,
172
+ txHash: result.txHash,
173
+ messageToSign: result.messageToSign,
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Step 2 of REGISTER_API_KEY — inject the L1 signature produced by the
179
+ * user's Ethereum wallet into the ChangePubKey txInfo JSON. `L1Sig` is the
180
+ * only field in txInfo that depends on the L1 signature; txHash does NOT
181
+ * include it (so we do not recompute it).
182
+ */
183
+ embedL1Signature(txInfo: string, l1Signature: string): string {
184
+ let parsed: Record<string, unknown>
185
+ try {
186
+ parsed = JSON.parse(txInfo) as Record<string, unknown>
187
+ } catch (err) {
188
+ throw new Error(
189
+ `Failed to parse ChangePubKey txInfo as JSON: ${(err as Error).message}`
190
+ )
191
+ }
192
+ parsed.L1Sig = l1Signature
193
+ return JSON.stringify(parsed)
194
+ }
195
+
196
+ /**
197
+ * Create an auth token for authenticated WebSocket subscriptions.
198
+ * `deadline` is a Unix timestamp in seconds — tokens have an 8h hard cap.
199
+ */
200
+ async createAuthToken(
201
+ deadline: number,
202
+ context: LighterSignerContext
203
+ ): Promise<string> {
204
+ const wasm = await this.ensureLoaded()
205
+ await this.ensureClient(context)
206
+ const result = wasm.CreateAuthToken(
207
+ deadline,
208
+ context.apiKeyIndex,
209
+ context.accountIndex
210
+ )
211
+ if (result.error) {
212
+ throw new Error(`Lighter CreateAuthToken failed: ${result.error}`)
213
+ }
214
+ if (!result.authToken) {
215
+ throw new Error('Lighter CreateAuthToken returned no token')
216
+ }
217
+ return result.authToken
218
+ }
219
+
220
+ private async ensureLoaded(): Promise<LighterWasmExports> {
221
+ if (!this.wasm) {
222
+ await this.initialize()
223
+ }
224
+ return this.wasm as LighterWasmExports
225
+ }
226
+
227
+ private async ensureClient(context: LighterSignerContext): Promise<void> {
228
+ const key = `${context.apiKeyIndex}:${context.accountIndex}:${context.apiKeyPrivateKey}`
229
+ if (this.registeredClients.has(key)) {
230
+ return
231
+ }
232
+ const wasm = await this.ensureLoaded()
233
+ const result = wasm.CreateClient(
234
+ this.apiUrl,
235
+ context.apiKeyPrivateKey,
236
+ this.chainId,
237
+ context.apiKeyIndex,
238
+ context.accountIndex
239
+ )
240
+ if (result.error) {
241
+ throw new Error(`Lighter CreateClient failed: ${result.error}`)
242
+ }
243
+ this.registeredClients.add(key)
244
+ }
245
+
246
+ /**
247
+ * Map an ActionType + backend-provided params object to the positional-arg
248
+ * WASM call. The Go signer exports take primitives in order, not an object
249
+ * — so we pick fields in the exact order the Go side expects. Unknown
250
+ * fields (e.g. backend's integrator_* hints) are ignored.
251
+ */
252
+ private dispatch(
253
+ wasm: LighterWasmExports,
254
+ action: ActionType,
255
+ p: Record<string, unknown>,
256
+ ctx: LighterSignerContext
257
+ ): SignResult {
258
+ const nonce = numberField(p, 'nonce')
259
+ switch (action) {
260
+ case ActionType.PLACE_ORDER:
261
+ case ActionType.PLACE_TRIGGER_ORDER:
262
+ return wasm.SignCreateOrder(
263
+ numberField(p, 'market_index'),
264
+ numberField(p, 'client_order_index'),
265
+ numberField(p, 'base_amount'),
266
+ numberField(p, 'price'),
267
+ numberField(p, 'is_ask'),
268
+ numberField(p, 'order_type'),
269
+ numberField(p, 'time_in_force'),
270
+ // WASM's error message lists "reduceOnly" as bool-like, but Go
271
+ // actually calls Value.Int() on every arg — passing an actual bool
272
+ // panics. Coerce to 0/1.
273
+ numberField(p, 'reduce_only'),
274
+ numberField(p, 'trigger_price'),
275
+ numberField(p, 'order_expiry'),
276
+ nonce,
277
+ ctx.apiKeyIndex,
278
+ ctx.accountIndex
279
+ )
280
+ case ActionType.CANCEL_ORDER:
281
+ return wasm.SignCancelOrder(
282
+ numberField(p, 'market_index'),
283
+ numberField(p, 'order_index'),
284
+ nonce,
285
+ ctx.apiKeyIndex,
286
+ ctx.accountIndex
287
+ )
288
+ case ActionType.CANCEL_ALL_ORDERS:
289
+ return wasm.SignCancelAllOrders(
290
+ numberField(p, 'time_in_force'),
291
+ numberField(p, 'timestamp_ms'),
292
+ nonce,
293
+ ctx.apiKeyIndex,
294
+ ctx.accountIndex
295
+ )
296
+ case ActionType.MODIFY_ORDER:
297
+ return wasm.SignModifyOrder(
298
+ numberField(p, 'market_index'),
299
+ numberField(p, 'order_index'),
300
+ numberField(p, 'base_amount'),
301
+ numberField(p, 'price'),
302
+ numberField(p, 'trigger_price'),
303
+ nonce,
304
+ ctx.apiKeyIndex,
305
+ ctx.accountIndex
306
+ )
307
+ case ActionType.UPDATE_LEVERAGE:
308
+ return wasm.SignUpdateLeverage(
309
+ numberField(p, 'market_index'),
310
+ numberField(p, 'fraction'),
311
+ numberField(p, 'margin_mode'),
312
+ nonce,
313
+ ctx.apiKeyIndex,
314
+ ctx.accountIndex
315
+ )
316
+ case ActionType.UPDATE_POSITION_MARGIN:
317
+ return wasm.SignUpdateMargin(
318
+ numberField(p, 'market_index'),
319
+ numberField(p, 'usdc_amount'),
320
+ numberField(p, 'direction'),
321
+ nonce,
322
+ ctx.apiKeyIndex,
323
+ ctx.accountIndex
324
+ )
325
+ case ActionType.WITHDRAWAL:
326
+ return wasm.SignWithdraw(
327
+ numberField(p, 'amount'),
328
+ nonce,
329
+ ctx.apiKeyIndex,
330
+ ctx.accountIndex
331
+ )
332
+ case ActionType.TRANSFER:
333
+ // SignTransfer's 7 positional args follow the Go binding order:
334
+ // `toAccount, usdcAmount, fee, memo, nonce, apiKeyIndex,
335
+ // accountIndex`. `memo` is copied directly into a `[32]byte`, so the
336
+ // backend MUST send a JS string whose UTF-8 byte length is exactly
337
+ // 32 (in practice: 32 ASCII characters) — anything else fails with
338
+ // "memo expected to be 32 bytes long".
339
+ return wasm.SignTransfer(
340
+ numberField(p, 'to_account'),
341
+ numberField(p, 'usdc_amount'),
342
+ numberField(p, 'fee'),
343
+ stringField(p, 'memo'),
344
+ nonce,
345
+ ctx.apiKeyIndex,
346
+ ctx.accountIndex
347
+ )
348
+ default:
349
+ throw new Error(
350
+ `Lighter WASM signer does not support action: ${action}`
351
+ )
352
+ }
353
+ }
354
+ }
355
+
356
+ function unwrap(result: SignResult, action: ActionType): LighterSignedBlob {
357
+ if (result.error) {
358
+ throw new Error(`Lighter sign(${action}) failed: ${result.error}`)
359
+ }
360
+ if (
361
+ result.txType === undefined ||
362
+ result.txInfo === undefined ||
363
+ result.txHash === undefined
364
+ ) {
365
+ throw new Error(
366
+ `Lighter sign(${action}) returned an incomplete signed blob`
367
+ )
368
+ }
369
+ return {
370
+ txType: result.txType,
371
+ txInfo: result.txInfo,
372
+ txHash: result.txHash,
373
+ }
374
+ }
375
+
376
+ function numberField(p: Record<string, unknown>, key: string): number {
377
+ const v = p[key]
378
+ if (typeof v === 'number') {
379
+ return v
380
+ }
381
+ if (typeof v === 'boolean') {
382
+ return v ? 1 : 0
383
+ }
384
+ if (typeof v === 'string' && v !== '' && !Number.isNaN(Number(v))) {
385
+ return Number(v)
386
+ }
387
+ throw new Error(
388
+ `Lighter sign params missing numeric field '${key}' (got ${typeof v})`
389
+ )
390
+ }
391
+
392
+ function stringField(p: Record<string, unknown>, key: string): string {
393
+ const v = p[key]
394
+ if (typeof v === 'string' && v !== '') {
395
+ return v
396
+ }
397
+ throw new Error(
398
+ `Lighter sign params missing string field '${key}' (got ${typeof v})`
399
+ )
400
+ }
@@ -0,0 +1,69 @@
1
+ import type { LighterApiKey } from './LighterKeyStore.js'
2
+ import type { LighterReadOnlyToken } from './LighterReadOnlyTokenManager.js'
3
+ import type { LighterSigner } from './LighterSigner.js'
4
+
5
+ const DEFAULT_LIFETIME_SECONDS = 60 * 60
6
+ const DEFAULT_THRESHOLD_SECONDS = 30 * 86_400
7
+
8
+ /** @public */
9
+ export interface CreateAuthTokenInputs {
10
+ signer: LighterSigner
11
+ apiKey: Pick<
12
+ LighterApiKey,
13
+ 'apiKeyPrivateKey' | 'apiKeyIndex' | 'accountIndex'
14
+ >
15
+ /**
16
+ * Token lifetime in seconds. Lighter caps standard tokens at 8 hours.
17
+ * Defaults to 1 hour, matching the previous `PerpsClient` behaviour.
18
+ */
19
+ lifetimeSeconds?: number
20
+ /** Optional clock injection for tests. */
21
+ now?: () => number
22
+ }
23
+
24
+ /**
25
+ * Create a fresh Lighter standard auth token via the WASM signer. Returns the
26
+ * opaque bearer string Lighter will accept on its authenticated read
27
+ * endpoints (`getOrders`, `getOrder`, `getActivity`, etc.).
28
+ *
29
+ * This utility carries no SDK-wide coupling — pass an explicit `signer` +
30
+ * `apiKey` and consume the returned bearer however the caller likes
31
+ * (per-call `options.lighterAuthToken`, persisted cache, etc.).
32
+ * @public
33
+ */
34
+ export async function createAuthToken(
35
+ inputs: CreateAuthTokenInputs
36
+ ): Promise<string> {
37
+ const { signer, apiKey } = inputs
38
+ const lifetime = inputs.lifetimeSeconds ?? DEFAULT_LIFETIME_SECONDS
39
+ const now = inputs.now ?? (() => Date.now())
40
+ const deadline = Math.floor(now() / 1000) + lifetime
41
+ return signer.createAuthToken(deadline, {
42
+ apiKeyPrivateKey: apiKey.apiKeyPrivateKey,
43
+ apiKeyIndex: apiKey.apiKeyIndex,
44
+ accountIndex: apiKey.accountIndex,
45
+ })
46
+ }
47
+
48
+ /**
49
+ * True when `token` exists, has not already expired, and is within
50
+ * `thresholdSeconds` of its recorded `expiry`. Intended for widget renewal
51
+ * banners — `thresholdSeconds` defaults to 30 days. Returns `false` for an
52
+ * undefined or already-expired token, so callers may treat that as "no
53
+ * token / renewal not needed (yet)".
54
+ * @public
55
+ */
56
+ export function isReadOnlyTokenExpiringSoon(
57
+ token: LighterReadOnlyToken | undefined | null,
58
+ thresholdSeconds: number = DEFAULT_THRESHOLD_SECONDS,
59
+ now: () => number = () => Date.now()
60
+ ): boolean {
61
+ if (!token) {
62
+ return false
63
+ }
64
+ const remaining = token.expiry - Math.floor(now() / 1000)
65
+ if (remaining <= 0) {
66
+ return false
67
+ }
68
+ return remaining <= thresholdSeconds
69
+ }
@@ -0,0 +1,36 @@
1
+ // biome-ignore-all lint/performance/noBarrelFile: package-internal barrel.
2
+
3
+ export type { CreateAuthTokenInputs } from './createAuthToken.js'
4
+ export {
5
+ createAuthToken,
6
+ isReadOnlyTokenExpiringSoon,
7
+ } from './createAuthToken.js'
8
+ export type { LighterApiKey } from './LighterKeyStore.js'
9
+ export { LighterKeyStore } from './LighterKeyStore.js'
10
+ export type {
11
+ ApproveReadOnlyTokenInputs,
12
+ ApproveReadOnlyTokenResult,
13
+ LighterCreateTokenResponse,
14
+ LighterReadOnlyToken,
15
+ LighterReadOnlyTokenManagerOptions,
16
+ LighterTokenFetcher,
17
+ } from './LighterReadOnlyTokenManager.js'
18
+ export {
19
+ DEFAULT_LIGHTER_API_URL,
20
+ DEFAULT_READ_ONLY_TOKEN_NAME,
21
+ defaultLighterTokenFetcher,
22
+ LighterReadOnlyTokenManager,
23
+ } from './LighterReadOnlyTokenManager.js'
24
+ export type {
25
+ ApiKeyPair,
26
+ ChangePubKeyResult,
27
+ LighterSignedBlob,
28
+ LighterSignerConfig,
29
+ LighterSignerContext,
30
+ } from './LighterSigner.js'
31
+ export { LighterSigner } from './LighterSigner.js'
32
+ export type {
33
+ LighterWasmExports,
34
+ LoadLighterWasmOptions,
35
+ } from './wasmLoader.js'
36
+ export { loadLighterWasm, resetLighterWasmCache } from './wasmLoader.js'