@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,162 @@
1
+ import { PerpsError } from '@lifi/perps-sdk'
2
+ import type {
3
+ AccountConfigSetting,
4
+ LighterAccountConfig,
5
+ ProviderAction,
6
+ } from '@lifi/perps-types'
7
+ import { ActionType, PerpsErrorCode } from '@lifi/perps-types'
8
+
9
+ function assertNever(value: never): never {
10
+ throw new Error(
11
+ `Unreachable: exhaustiveness check failed for value ${JSON.stringify(value)}`
12
+ )
13
+ }
14
+
15
+ /**
16
+ * `account_type` on Lighter's `DetailedAccount` is a `StrictInt` in the
17
+ * public OpenAPI schema (`lighter-python/lighter/models/detailed_account.py`)
18
+ * with no documented integer ↔ name mapping in the Python or Go SDKs.
19
+ *
20
+ * The empirical mapping below follows the public docs' tier ordering
21
+ * (apidocs.lighter.xyz/docs/account-types lists Standard → Premium → Plus)
22
+ * and the Python paper client's `AccountTier` enum ordering (STANDARD
23
+ * first, PREMIUM next). The write side of `/changeAccountTier` accepts the
24
+ * lowercase strings `'standard' | 'premium'` — these are what the
25
+ * descriptor's `ParamOption.value` declarations carry, so this mapping
26
+ * round-trips cleanly with the OptionsModal selection.
27
+ *
28
+ * Lighter publishes a third "Plus" tier (likely integer `2`), but it is
29
+ * not currently settable via the public API, so we deliberately do not
30
+ * map it — a Plus account surfaces as "tier not detected" in the widget
31
+ * rather than offering an option that would 400 on submit. Add
32
+ * `LIGHTER_ACCOUNT_TYPE_PLUS` here (and to the backend descriptor) if
33
+ * Lighter exposes it later.
34
+ *
35
+ * Each integer is a named constant so a correction (e.g. Lighter publishing
36
+ * an authoritative table) is a one-line edit. An unmapped integer projects
37
+ * to `null` and surfaces as "tier not detected" in the widget, so drift is
38
+ * observable rather than silent.
39
+ */
40
+ const LIGHTER_ACCOUNT_TYPE_STANDARD = 0
41
+ const LIGHTER_ACCOUNT_TYPE_PREMIUM = 1
42
+
43
+ const ACCOUNT_TYPE_INT_TO_WIRE: Readonly<Record<number, string>> = {
44
+ [LIGHTER_ACCOUNT_TYPE_STANDARD]: 'standard',
45
+ [LIGHTER_ACCOUNT_TYPE_PREMIUM]: 'premium',
46
+ }
47
+
48
+ /**
49
+ * Project a single Lighter descriptor against the typed
50
+ * `LighterAccountConfig` into an `AccountConfigSetting`.
51
+ *
52
+ * Mapping table:
53
+ *
54
+ * | descriptor.type | projected values
55
+ * |---------------------------|--------------------------------------------------
56
+ * | REGISTER_API_KEY | [] (no parameters)
57
+ * | APPROVE_READ_ONLY_TOKEN | [] (no parameters)
58
+ * | ACCOUNT_MODE | [{ name: 'mode', value: null }] (Lighter has no
59
+ * | | abstraction-mode equivalent; read-only here)
60
+ * | ACCOUNT_TYPE | [{ name: 'tier', value: config.accountType }]
61
+ *
62
+ * The switch is exhaustive over `ActionType` so enum additions force a
63
+ * compile error in the `default` arm. ActionTypes that are not valid on
64
+ * `Provider.setup` / `Provider.options` throw at runtime.
65
+ */
66
+ function projectLighterDescriptor(
67
+ descriptor: ProviderAction,
68
+ config: LighterAccountConfig
69
+ ): AccountConfigSetting {
70
+ switch (descriptor.type) {
71
+ // `REGISTER_API_KEY` is satisfied only when the locally-held keypair
72
+ // matches the key registered on-chain at this slot — computed client-side
73
+ // in `getAccount` (the SDK owns account reads + the keystore). Backend
74
+ // staging is mutation-only; it never decides satisfaction.
75
+ case ActionType.REGISTER_API_KEY:
76
+ return {
77
+ type: descriptor.type,
78
+ values: [],
79
+ satisfied: config.apiKeyRegistered,
80
+ }
81
+ // `APPROVE_READ_ONLY_TOKEN` is a client-only flow that never reaches
82
+ // the backend, so its satisfaction state lives entirely in the typed
83
+ // `LighterAccountConfig` projection.
84
+ case ActionType.APPROVE_READ_ONLY_TOKEN:
85
+ return {
86
+ type: descriptor.type,
87
+ values: [],
88
+ satisfied: config.readOnlyTokenApproved,
89
+ }
90
+
91
+ // Lighter exposes no abstraction-mode equivalent; if a backend descriptor
92
+ // surfaces ACCOUNT_MODE on Lighter it always projects `null` and callers
93
+ // fall back to the descriptor's `default` ParamOption.
94
+ case ActionType.ACCOUNT_MODE:
95
+ return {
96
+ type: descriptor.type,
97
+ values: [{ name: 'mode', value: null }],
98
+ }
99
+
100
+ // `tier` is the wire string `/changeAccountTier` accepts; we decode the
101
+ // raw integer `config.accountType` Lighter publishes via the mapping
102
+ // above so the projection matches the descriptor's enumerated values.
103
+ // Unrecognised integers project to `null` (surfaces as "tier not
104
+ // detected" — the widget still lets the user pick a value).
105
+ case ActionType.ACCOUNT_TYPE:
106
+ return {
107
+ type: descriptor.type,
108
+ values: [
109
+ {
110
+ name: 'tier',
111
+ value: ACCOUNT_TYPE_INT_TO_WIRE[config.accountType] ?? null,
112
+ },
113
+ ],
114
+ }
115
+
116
+ case ActionType.APPROVE_AGENT:
117
+ case ActionType.APPROVE_BUILDER_FEE:
118
+ case ActionType.SEND_ASSET:
119
+ case ActionType.WITHDRAWAL:
120
+ case ActionType.TRANSFER:
121
+ case ActionType.PLACE_ORDER:
122
+ case ActionType.PLACE_TRIGGER_ORDER:
123
+ case ActionType.CANCEL_ORDER:
124
+ case ActionType.CANCEL_ALL_ORDERS:
125
+ case ActionType.MODIFY_ORDER:
126
+ case ActionType.UPDATE_LEVERAGE:
127
+ case ActionType.UPDATE_POSITION_MARGIN:
128
+ case ActionType.DEPOSIT:
129
+ case ActionType.META_VOTE:
130
+ case ActionType.META_ACCEPT_TERMS:
131
+ throw new PerpsError(
132
+ PerpsErrorCode.SDKError,
133
+ `Lighter account-config mapper has no projection for ` +
134
+ `descriptor type '${descriptor.type}' — this ActionType is not ` +
135
+ `valid on Provider.setup / Provider.options for Lighter.`
136
+ )
137
+
138
+ default:
139
+ return assertNever(descriptor.type)
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Project the union of Lighter setup + options descriptors against the typed
145
+ * `LighterAccountConfig`. Produces exactly one `AccountConfigSetting` per
146
+ * descriptor, in `setup`-then-`options` order (preserving the order in which
147
+ * the backend emits them).
148
+ *
149
+ * @param config Typed account state for the Lighter account.
150
+ * @param setup `Provider.setup` array as emitted by `/providers`.
151
+ * @param options `Provider.options` array as emitted by `/providers`.
152
+ * @public
153
+ */
154
+ export function projectLighterConfigSettings(
155
+ config: LighterAccountConfig,
156
+ setup: ProviderAction[],
157
+ options: ProviderAction[]
158
+ ): AccountConfigSetting[] {
159
+ return [...setup, ...options].map((descriptor) =>
160
+ projectLighterDescriptor(descriptor, config)
161
+ )
162
+ }
@@ -0,0 +1,22 @@
1
+ import { summarizeAccount } from '@lifi/perps-sdk'
2
+ import type {
3
+ AccountResponse,
4
+ AccountSummary,
5
+ Position,
6
+ } from '@lifi/perps-types'
7
+
8
+ /**
9
+ * 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` (free margin), so available margin
12
+ * is the collateral as-is and the locked margin (carried by the positions'
13
+ * `marginUsed`) is added back for the gross portfolio value.
14
+ *
15
+ * @public
16
+ */
17
+ export function summarizeLighterAccount(
18
+ account: AccountResponse,
19
+ positions: Position[]
20
+ ): AccountSummary {
21
+ return summarizeAccount(account, positions, false)
22
+ }
@@ -0,0 +1,89 @@
1
+ import type { FeeTier } from '@lifi/perps-types'
2
+
3
+ /**
4
+ * Lighter provider key as it appears on `Provider.key` from the backend.
5
+ *
6
+ * @public
7
+ */
8
+ export const LIGHTER_PROVIDER_KEY = 'lighter'
9
+
10
+ /**
11
+ * Default mainnet REST base URL for Lighter.
12
+ *
13
+ * @public
14
+ */
15
+ export const DEFAULT_LIGHTER_REST_URL = 'https://mainnet.zklighter.elliot.ai'
16
+
17
+ /** @internal */
18
+ export const DEFAULT_TRADES_LIMIT = 50
19
+
20
+ /**
21
+ * Lighter pairs each maker/taker fee with a 1e6 integer tick:
22
+ * fee_fraction = current_*_fee_tick / 1_000_000
23
+ *
24
+ * See lighter-python `paper_client/types.py:_FEE_TICK` for the canonical scale.
25
+ *
26
+ * @internal
27
+ */
28
+ export const LIGHTER_FEE_TICK_SCALE = 1_000_000
29
+
30
+ /**
31
+ * Lighter's public base fee tier (Standard Account): 0% maker / 0% taker on all
32
+ * perps markets. Per-account Premium tiers exist but require auth to resolve;
33
+ * unauthenticated quotes use this public base. Fractions, not basis points.
34
+ *
35
+ * @public
36
+ */
37
+ export const LIGHTER_BASE_FEE_TIER: FeeTier = { maker: '0', taker: '0' }
38
+
39
+ /**
40
+ * Wildcard `market_id` accepted by Lighter's per-market account endpoints to
41
+ * indicate "every market". Used on `accountInactiveOrders`, `positionFunding`,
42
+ * `liquidations`.
43
+ *
44
+ * @internal
45
+ */
46
+ export const LIGHTER_ALL_MARKETS_WILDCARD = 255
47
+
48
+ /**
49
+ * Lighter caps `limit` at 100 on positionFunding/liquidations endpoints.
50
+ *
51
+ * @internal
52
+ */
53
+ export const LIGHTER_HISTORY_PAGE_SIZE = 100
54
+
55
+ /**
56
+ * Default API key slot — reused per account. Lighter's docs reserve indexes
57
+ * `{0,1,2,3}` for its own desktop/mobile interfaces; user keys start at 4
58
+ * (max 254, with 255 reserved as `NilApiKeyIndex`). 42 is the LI.FI-wide
59
+ * identifier so a user running both the Lighter app and the widget never
60
+ * collides with the app's session key.
61
+ *
62
+ * @public
63
+ */
64
+ export const DEFAULT_API_KEY_INDEX = 42
65
+
66
+ /** @internal */
67
+ const LIGHTER_CODE_ACCOUNT_NOT_FOUND = 21100
68
+
69
+ /**
70
+ * Lighter body `code` for a rejected/invalid auth token ("invalid auth string").
71
+ *
72
+ * @internal
73
+ */
74
+ const LIGHTER_INVALID_AUTH_CODE = 20013
75
+
76
+ /**
77
+ * Lighter body `code` values that mean success. Lighter is inconsistent per
78
+ * endpoint: `/api/v1/account` returns `code: 200`, most others return `code: 0`.
79
+ * A body with no `code` field is also success (no error channel present).
80
+ *
81
+ * @internal
82
+ */
83
+ const LIGHTER_SUCCESS_CODES = new Set([0, 200])
84
+
85
+ export {
86
+ LIGHTER_CODE_ACCOUNT_NOT_FOUND,
87
+ LIGHTER_INVALID_AUTH_CODE,
88
+ LIGHTER_SUCCESS_CODES,
89
+ }
package/src/index.ts ADDED
@@ -0,0 +1,37 @@
1
+ // biome-ignore-all lint/performance/noBarrelFile: package public entry point.
2
+ // biome-ignore-all lint/performance/noReExportAll: package public entry point.
3
+
4
+ /**
5
+ * Lighter provider plugin for `@lifi/perps-sdk`. Serves `PerpsProvider` reads
6
+ * directly from Lighter's REST API (no LI.FI backend hop); auth-gated reads
7
+ * use the user's Lighter read-only token. Also owns `signActions` (the
8
+ * `WASM_BLOB` / `EVM_TX` arms of `PerpsClient.execute`) — `LighterSigner`,
9
+ * `LighterKeyStore`, `LighterReadOnlyTokenManager`, and the WASM blob ship
10
+ * with this package.
11
+ *
12
+ * @packageDocumentation
13
+ * @public
14
+ */
15
+
16
+ export { projectLighterConfigSettings } from './accountConfig.js'
17
+ export { summarizeLighterAccount } from './accountSummary.js'
18
+ export {
19
+ DEFAULT_API_KEY_INDEX,
20
+ DEFAULT_LIGHTER_REST_URL,
21
+ LIGHTER_PROVIDER_KEY,
22
+ } from './constants.js'
23
+ export type {
24
+ LighterPerpsProvider,
25
+ LighterProviderOptions,
26
+ } from './LighterProvider.js'
27
+ export { Lighter, lighterProvider } from './LighterProvider.js'
28
+
29
+ export * from './signers/index.js'
30
+ export * from './types/index.js'
31
+ export * from './utils/index.js'
32
+ export type { LighterAuthProvider } from './websocket/LighterWsProvider.js'
33
+ export {
34
+ LighterWsProvider,
35
+ type LighterWsProviderOptions,
36
+ lighterWsProvider,
37
+ } from './websocket/LighterWsProvider.js'
@@ -0,0 +1,79 @@
1
+ import { readValidatedRecord, type StorageAdapter } from '@lifi/perps-sdk'
2
+ import type { Address } from 'viem'
3
+
4
+ // The private key here is a Lighter custom keypair — generated via WASM
5
+ // GenerateAPIKey — not an Ethereum private key. The storage key is namespaced
6
+ // by provider (`lighter`) so the same user can hold credentials for other
7
+ // WASM-blob providers without collision.
8
+
9
+ const STORAGE_PREFIX = 'lifi-perps-lighter-key'
10
+
11
+ /** @public */
12
+ export interface LighterApiKey {
13
+ /** Lighter account index, looked up once via accountsByL1Address. */
14
+ accountIndex: number
15
+ /** API key slot (0-255). Defaults to {@link DEFAULT_API_KEY_INDEX}. */
16
+ apiKeyIndex: number
17
+ /** Lighter-native private key (0x-prefixed hex). */
18
+ apiKeyPrivateKey: string
19
+ /** Corresponding public key, registered via ChangePubKey. */
20
+ apiKeyPublicKey: string
21
+ }
22
+
23
+ const isLighterApiKey = (value: unknown): value is LighterApiKey => {
24
+ if (typeof value !== 'object' || value === null) {
25
+ return false
26
+ }
27
+ const { accountIndex, apiKeyIndex, apiKeyPrivateKey, apiKeyPublicKey } =
28
+ value as Record<string, unknown>
29
+ return (
30
+ typeof accountIndex === 'number' &&
31
+ Number.isFinite(accountIndex) &&
32
+ typeof apiKeyIndex === 'number' &&
33
+ Number.isFinite(apiKeyIndex) &&
34
+ typeof apiKeyPrivateKey === 'string' &&
35
+ apiKeyPrivateKey.length > 0 &&
36
+ typeof apiKeyPublicKey === 'string' &&
37
+ apiKeyPublicKey.length > 0
38
+ )
39
+ }
40
+
41
+ /** @public */
42
+ export class LighterKeyStore {
43
+ private readonly storage: StorageAdapter
44
+ private readonly cache = new Map<string, LighterApiKey>()
45
+
46
+ constructor(storage: StorageAdapter) {
47
+ this.storage = storage
48
+ }
49
+
50
+ private storageKey(address: Address): string {
51
+ return `${STORAGE_PREFIX}:${address.toLowerCase()}`
52
+ }
53
+
54
+ async get(address: Address): Promise<LighterApiKey | null> {
55
+ const key = this.storageKey(address)
56
+ const cached = this.cache.get(key)
57
+ if (cached) {
58
+ return cached
59
+ }
60
+ const parsed = await readValidatedRecord(this.storage, key, isLighterApiKey)
61
+ if (!parsed) {
62
+ return null
63
+ }
64
+ this.cache.set(key, parsed)
65
+ return parsed
66
+ }
67
+
68
+ async set(address: Address, value: LighterApiKey): Promise<void> {
69
+ const key = this.storageKey(address)
70
+ this.cache.set(key, value)
71
+ await this.storage.set(key, JSON.stringify(value))
72
+ }
73
+
74
+ async remove(address: Address): Promise<void> {
75
+ const key = this.storageKey(address)
76
+ this.cache.delete(key)
77
+ await this.storage.remove(key)
78
+ }
79
+ }