@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,1167 @@
1
+ import {
2
+ ExplorerChainId,
3
+ explorerTxUrl,
4
+ getAssetRegistry,
5
+ getMarketRegistry,
6
+ PerpsError,
7
+ type PerpsProviderPlugin,
8
+ type PerpsSDKClient,
9
+ type ProviderGetAccountParams,
10
+ type ProviderGetActivityParams,
11
+ type ProviderGetFillsParams,
12
+ type ProviderGetOrderParams,
13
+ type ProviderGetOrdersParams,
14
+ type ProviderGetPositionsParams,
15
+ type ProviderGetQuoteParams,
16
+ resolveQuote,
17
+ resolveRetryPolicy,
18
+ type SDKRequestOptions,
19
+ type SignActionsContext,
20
+ } from '@lifi/perps-sdk'
21
+ import type {
22
+ AccountConfig,
23
+ AccountConfigSetting,
24
+ AccountResponse,
25
+ AccountSummary,
26
+ ActionStep,
27
+ ActivitiesResponse,
28
+ ActivityItem,
29
+ Balance,
30
+ FillsResponse,
31
+ LighterAccountConfig,
32
+ Order,
33
+ OrdersResponse,
34
+ Position,
35
+ PositionsResponse,
36
+ ProviderAction,
37
+ Quote,
38
+ SignedActionStep,
39
+ SigningMethod,
40
+ } from '@lifi/perps-types'
41
+ import { ActionType, ActivityType, PerpsErrorCode } from '@lifi/perps-types'
42
+ import type { Address } from 'viem'
43
+ import { projectLighterConfigSettings } from './accountConfig.js'
44
+ import { summarizeLighterAccount } from './accountSummary.js'
45
+ import {
46
+ DEFAULT_API_KEY_INDEX,
47
+ DEFAULT_LIGHTER_REST_URL,
48
+ DEFAULT_TRADES_LIMIT,
49
+ LIGHTER_ALL_MARKETS_WILDCARD,
50
+ LIGHTER_BASE_FEE_TIER,
51
+ LIGHTER_FEE_TICK_SCALE,
52
+ LIGHTER_HISTORY_PAGE_SIZE,
53
+ LIGHTER_PROVIDER_KEY,
54
+ } from './constants.js'
55
+ import { createAuthToken } from './signers/createAuthToken.js'
56
+ import type { LighterKeyStore } from './signers/LighterKeyStore.js'
57
+ import type { LighterReadOnlyTokenManagerOptions } from './signers/LighterReadOnlyTokenManager.js'
58
+ import { LighterReadOnlyTokenManager } from './signers/LighterReadOnlyTokenManager.js'
59
+ import type { LighterSigner } from './signers/LighterSigner.js'
60
+ import { lighterSignActions } from './signers/signActions.js'
61
+ import type {
62
+ LtAccountLimits,
63
+ LtDepositHistoryResponse,
64
+ LtDetailedAccount,
65
+ LtDetailedAccountPosition,
66
+ LtLiquidationsResponse,
67
+ LtOrdersResponse,
68
+ LtPositionFundingsResponse,
69
+ LtTradesResponse,
70
+ LtTransferHistoryResponse,
71
+ LtWithdrawHistoryResponse,
72
+ } from './types/index.js'
73
+ import {
74
+ decodeActivityCursor,
75
+ encodeActivityCursor,
76
+ type LighterActivityCursor,
77
+ } from './utils/activityCursor.js'
78
+ import {
79
+ LIGHTER_RETRY_DEFAULTS,
80
+ LighterApiClient,
81
+ LighterAuthRejectedError,
82
+ } from './utils/apiClient.js'
83
+ import {
84
+ classifyAndMapOrders,
85
+ estimateLiquidationPrice,
86
+ fetchDetailedAccount,
87
+ formatOrderPrice,
88
+ formatOrderSize,
89
+ lighterAsset,
90
+ mapFill,
91
+ mapOpenPositions,
92
+ mapOrderDetail,
93
+ toIsoFromMs,
94
+ toIsoFromSeconds,
95
+ } from './utils/index.js'
96
+
97
+ const ZERO_FEE_TIER = { maker: '0', taker: '0' }
98
+
99
+ const tickToFeeString = (tick: number): string =>
100
+ String(tick / LIGHTER_FEE_TICK_SCALE)
101
+
102
+ const projectFeeTier = (
103
+ limits: LtAccountLimits
104
+ ): { maker: string; taker: string } => ({
105
+ maker: tickToFeeString(limits.current_maker_fee_tick),
106
+ taker: tickToFeeString(limits.current_taker_fee_tick),
107
+ })
108
+
109
+ const orderCountFor = (p: LtDetailedAccountPosition): number =>
110
+ (p.open_order_count ?? 0) +
111
+ (p.pending_order_count ?? 0) +
112
+ (p.position_tied_order_count ?? 0)
113
+
114
+ /**
115
+ * Lighter `sendTx` returns a bare lowercase-hex tx hash (40 bytes → 80 hex
116
+ * chars). `Order.order_id` is a different identifier the matching engine
117
+ * assigns later. The strict 80-char shape lets `getOrder` route freshly
118
+ * submitted IDs to the tx-hash branch without false positives.
119
+ */
120
+ const TX_HASH_PATTERN = /^[0-9a-f]{80}$/
121
+
122
+ const INACTIVE_ORDERS_LOOKUP_LIMIT = 100
123
+
124
+ /**
125
+ * Expiry requested when the SDK lazily creates a Lighter read-only token for
126
+ * authenticated reads. 10 years — Lighter caps read-only tokens at the
127
+ * venue's maximum, so a single token covers the account's lifetime.
128
+ */
129
+ const DEFAULT_READ_ONLY_TOKEN_LIFETIME_SECONDS = 10 * 365 * 24 * 60 * 60
130
+
131
+ /** Compare Lighter public keys irrespective of `0x` prefix / casing. */
132
+ const normalizeLighterPublicKey = (key: string): string =>
133
+ key.replace(/^0x/i, '').toLowerCase()
134
+
135
+ /**
136
+ * Construction options for the Lighter {@link PerpsProviderPlugin}.
137
+ *
138
+ * `restUrl` defaults to Lighter mainnet; pass a testnet URL or a self-hosted
139
+ * mirror to override.
140
+ *
141
+ * Auth-token resolution order for the auth-gated reads:
142
+ * 1. Per-call `options.lighterAuthToken`
143
+ * 2. Constructor `authToken` (string or async factory)
144
+ * 3. Persisted long-lived read-only token (via `readOnlyTokenOptions`'s
145
+ * storage), keyed on the resolved Lighter `accountIndex`
146
+ * 4. Fresh 1h create via the WASM signer + the user's registered API key
147
+ * from `keyStore`
148
+ *
149
+ * When none of these yields a token the auth-gated reads degrade gracefully:
150
+ * - `getOrders`, `getActivity` return empty results (mirrors backend behaviour)
151
+ * - `getOrder` throws `Unauthorized`
152
+ * - `getAccount` returns zero fee tier rather than failing
153
+ *
154
+ * Write actions (`signActions` for the WASM_BLOB / EVM_TX arms) require
155
+ * `signer` and `keyStore` to be supplied.
156
+ *
157
+ * @public
158
+ */
159
+ export interface LighterProviderOptions {
160
+ /** Lighter REST base URL. Defaults to mainnet. */
161
+ restUrl?: string
162
+ /** Pre-created Lighter read-only bearer. */
163
+ authToken?: string | (() => string | Promise<string>)
164
+ /**
165
+ * WASM signer instance. Required for `signActions` (write actions) and
166
+ * for on-demand auth-token creating from the user's API key. The default
167
+ * configuration loads the WASM blob shipped with this package.
168
+ */
169
+ signer?: LighterSigner
170
+ /**
171
+ * Store for the user's per-address Lighter API keypair. Required for
172
+ * `signActions` (write actions) and for on-demand auth-token creating.
173
+ */
174
+ keyStore?: LighterKeyStore
175
+ /**
176
+ * Injection overrides (storage, fetcher, clock, host) for the read-only
177
+ * token manager, which is always active — Lighter reads create a long-lived
178
+ * read-only token on first use and reuse it thereafter. The host defaults to
179
+ * `restUrl`. This does not enable or disable the manager; it only overrides
180
+ * its dependencies (primarily for tests / non-browser storage).
181
+ */
182
+ readOnlyTokenOptions?: LighterReadOnlyTokenManagerOptions
183
+ /** Token lifetime for on-demand standard-token creates (Lighter caps at 8h). Default 1h. */
184
+ tokenLifetimeSeconds?: number
185
+ /** Re-create when the cached standard token's remaining life is below this. Default 60s. */
186
+ tokenRenewBufferSeconds?: number
187
+ }
188
+
189
+ interface CachedStandardToken {
190
+ token: string
191
+ /** Unix seconds — re-create when `Date.now()/1000 + renewBuffer >= expiresAt`. */
192
+ expiresAt: number
193
+ }
194
+
195
+ /**
196
+ * Lighter provider plugin extended with a public `resolveAuthToken` so the
197
+ * WS layer can share the same token-resolution closure that the read methods
198
+ * use internally. The base {@link PerpsProviderPlugin} contract stays
199
+ * provider-agnostic — this extension is opt-in for callers that explicitly
200
+ * type against it.
201
+ *
202
+ * @public
203
+ */
204
+ export interface LighterPerpsProvider extends PerpsProviderPlugin {
205
+ /**
206
+ * Resolve a Lighter auth token for `address`, following the resolution order
207
+ * documented on {@link LighterProviderOptions} (the per-call override does not
208
+ * apply here). Returns `undefined` when no source can produce a token —
209
+ * callers degrade gracefully.
210
+ */
211
+ resolveAuthToken(address: Address): Promise<string | undefined>
212
+ }
213
+
214
+ /**
215
+ * Lighter provider plugin factory. Returns an object implementing
216
+ * {@link PerpsProviderPlugin}, mirroring the `EthereumProvider()` / `hyperliquidProvider()`
217
+ * shape used by the rest of the LI.FI SDK family.
218
+ *
219
+ * Read functions call Lighter's REST API directly with no LI.FI backend hop.
220
+ * Auth-gated reads resolve their token via the order documented on
221
+ * {@link LighterProviderOptions}.
222
+ *
223
+ * Write actions (`WASM_BLOB` and `EVM_TX` signing) are dispatched via
224
+ * `signActions` — `PerpsClient.execute` delegates those arms here.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * const client = createPerpsClient({
229
+ * integrator: 'my-app',
230
+ * providers: [lighterProvider()],
231
+ * })
232
+ * ```
233
+ * @public
234
+ */
235
+ export const lighterProvider = (
236
+ options: LighterProviderOptions = {}
237
+ ): LighterPerpsProvider => {
238
+ // Late-bind slot: the factory runs before the client exists, so `bind`
239
+ // assigns this once during createPerpsClient and the read methods read it.
240
+ let boundClient: PerpsSDKClient | undefined
241
+
242
+ const requireClient = (): PerpsSDKClient => {
243
+ if (boundClient === undefined) {
244
+ throw new PerpsError(
245
+ PerpsErrorCode.SDKError,
246
+ 'lighterProvider used before binding. Register it via ' +
247
+ 'createPerpsClient({ providers: [lighterProvider()] }).'
248
+ )
249
+ }
250
+ return boundClient
251
+ }
252
+
253
+ const restUrl = options.restUrl ?? DEFAULT_LIGHTER_REST_URL
254
+ const authTokenSource: (() => string | Promise<string>) | undefined =
255
+ typeof options.authToken === 'function'
256
+ ? options.authToken
257
+ : options.authToken !== undefined
258
+ ? () => options.authToken as string
259
+ : undefined
260
+ const signer = options.signer
261
+ const keyStore = options.keyStore
262
+ const readOnlyTokenManager = new LighterReadOnlyTokenManager({
263
+ lighterApiUrl: restUrl,
264
+ ...options.readOnlyTokenOptions,
265
+ })
266
+ const tokenLifetimeSeconds = options.tokenLifetimeSeconds ?? 60 * 60
267
+ const tokenRenewBufferSeconds = options.tokenRenewBufferSeconds ?? 60
268
+ const standardTokenByAddress: Map<string, CachedStandardToken> = new Map()
269
+ // Single-flight + failure-cache for lazy read-only token creation. Without
270
+ // these, concurrent reads on first load all race `tokens/create`, and any
271
+ // sustained failure (CORS preflight, body validation, etc.) is retried on
272
+ // every subsequent read — flooding the endpoint. Keyed by lowercase address.
273
+ const readOnlyCreationInFlight: Map<string, Promise<string>> = new Map()
274
+ const readOnlyCreationFailed: Set<string> = new Set()
275
+
276
+ const apiClient = (opts?: SDKRequestOptions): LighterApiClient => {
277
+ const client = requireClient()
278
+ return new LighterApiClient(restUrl, {
279
+ signal: opts?.signal,
280
+ policy: resolveRetryPolicy(
281
+ LIGHTER_RETRY_DEFAULTS,
282
+ client.config.retry,
283
+ LIGHTER_PROVIDER_KEY
284
+ ),
285
+ fetchImpl: client.config.fetch,
286
+ })
287
+ }
288
+
289
+ const getStandardAuthToken = async (
290
+ address: Address,
291
+ apiKeyPrivateKey: string,
292
+ indices: { apiKeyIndex: number; accountIndex: number }
293
+ ): Promise<string> => {
294
+ if (signer === undefined) {
295
+ throw new PerpsError(
296
+ PerpsErrorCode.SDKError,
297
+ 'lighterProvider: getStandardAuthToken called without a configured signer.'
298
+ )
299
+ }
300
+ const cacheKey = address.toLowerCase()
301
+ const nowSec = Math.floor(Date.now() / 1000)
302
+ const cached = standardTokenByAddress.get(cacheKey)
303
+ if (
304
+ cached !== undefined &&
305
+ cached.expiresAt - nowSec > tokenRenewBufferSeconds
306
+ ) {
307
+ return cached.token
308
+ }
309
+ const token = await createAuthToken({
310
+ signer,
311
+ apiKey: {
312
+ apiKeyPrivateKey,
313
+ apiKeyIndex: indices.apiKeyIndex,
314
+ accountIndex: indices.accountIndex,
315
+ },
316
+ lifetimeSeconds: tokenLifetimeSeconds,
317
+ })
318
+ const expiresAt = nowSec + tokenLifetimeSeconds
319
+ standardTokenByAddress.set(cacheKey, { token, expiresAt })
320
+ return token
321
+ }
322
+
323
+ /**
324
+ * Resolve the bearer token for auth-gated reads. Priority:
325
+ * 1. Per-call override (`options.lighterAuthToken`).
326
+ * 2. Constructor-supplied token source.
327
+ * 3. A stored read-only token — preferred for reads: it is read-only, so
328
+ * forwarding it (incl. to the backend) cannot authorise writes.
329
+ * 4. A read-only token created on first use (via signer + registered API
330
+ * key) and persisted for reuse.
331
+ * 5. A standard auth token (read+write, 8h max) as a last resort — used
332
+ * both as the fallback when creation is unavailable/failed and as the
333
+ * credential that authorises read-only token creation.
334
+ * Returns `undefined` when no source can produce a token — reads degrade
335
+ * gracefully.
336
+ */
337
+ const resolveAuthToken = async (
338
+ opts: SDKRequestOptions | undefined,
339
+ address?: Address
340
+ ): Promise<string | undefined> => {
341
+ if (opts?.lighterAuthToken !== undefined) {
342
+ return opts.lighterAuthToken
343
+ }
344
+ if (authTokenSource !== undefined) {
345
+ return authTokenSource()
346
+ }
347
+ if (address === undefined || keyStore === undefined) {
348
+ return undefined
349
+ }
350
+ const apiKey = await keyStore.get(address)
351
+ if (apiKey === null || signer === undefined) {
352
+ return undefined
353
+ }
354
+
355
+ const standardToken = (): Promise<string> =>
356
+ getStandardAuthToken(address, apiKey.apiKeyPrivateKey, {
357
+ apiKeyIndex: apiKey.apiKeyIndex,
358
+ accountIndex: apiKey.accountIndex,
359
+ })
360
+
361
+ const stored = await readOnlyTokenManager.get(address, apiKey.accountIndex)
362
+ if (stored !== undefined) {
363
+ return stored.token
364
+ }
365
+
366
+ const flightKey = address.toLowerCase()
367
+ if (readOnlyCreationFailed.has(flightKey)) {
368
+ return standardToken()
369
+ }
370
+ const inFlight = readOnlyCreationInFlight.get(flightKey)
371
+ if (inFlight !== undefined) {
372
+ return inFlight
373
+ }
374
+
375
+ // No read-only token yet — create and persist one. The standard token
376
+ // (API-key-signed) authorises Lighter's `tokens/create`; the returned
377
+ // read-only bearer is what we forward on reads. On failure we mark this
378
+ // address as "skip ro creation for the session" so subsequent reads use
379
+ // the standard token directly instead of hammering `tokens/create`.
380
+ const attempt = (async (): Promise<string> => {
381
+ try {
382
+ const { token } = await readOnlyTokenManager.approve(
383
+ await standardToken(),
384
+ {
385
+ address,
386
+ accountIndex: apiKey.accountIndex,
387
+ expirySeconds:
388
+ Math.floor(Date.now() / 1000) +
389
+ DEFAULT_READ_ONLY_TOKEN_LIFETIME_SECONDS,
390
+ scope: 'all',
391
+ }
392
+ )
393
+ return token.token
394
+ } catch (err) {
395
+ readOnlyCreationFailed.add(flightKey)
396
+ console.warn(
397
+ '[lighter] read-only token creation failed; ' +
398
+ 'falling back to standard auth tokens for this session.',
399
+ err
400
+ )
401
+ return standardToken()
402
+ } finally {
403
+ readOnlyCreationInFlight.delete(flightKey)
404
+ }
405
+ })()
406
+ readOnlyCreationInFlight.set(flightKey, attempt)
407
+ return attempt
408
+ }
409
+
410
+ const evictReadOnlyToken = async (address: Address): Promise<void> => {
411
+ readOnlyCreationFailed.delete(address.toLowerCase())
412
+ const apiKey = keyStore ? await keyStore.get(address) : null
413
+ if (apiKey !== null) {
414
+ await readOnlyTokenManager.remove(address, apiKey.accountIndex)
415
+ }
416
+ }
417
+
418
+ /**
419
+ * Run an auth-gated read; if Lighter rejects the token (revoked server-side —
420
+ * invisible to `checkSetup`, since the read-only token is a client-only
421
+ * concern), evict the stored read-only token and retry once with a freshly
422
+ * resolved one. Only self-heals tokens the SDK itself resolved — a
423
+ * caller-supplied `lighterAuthToken`/`authToken` source is the caller's to fix.
424
+ */
425
+ const retryOnRevoked = async <T>(
426
+ opts: SDKRequestOptions | undefined,
427
+ address: Address,
428
+ token: string,
429
+ run: (token: string) => Promise<T>
430
+ ): Promise<T> => {
431
+ try {
432
+ return await run(token)
433
+ } catch (err) {
434
+ const sdkOwnsToken =
435
+ opts?.lighterAuthToken === undefined && authTokenSource === undefined
436
+ if (!(err instanceof LighterAuthRejectedError) || !sdkOwnsToken) {
437
+ throw err
438
+ }
439
+ await evictReadOnlyToken(address)
440
+ const fresh = await resolveAuthToken(opts, address)
441
+ if (fresh === undefined || fresh === token) {
442
+ throw err
443
+ }
444
+ return await run(fresh)
445
+ }
446
+ }
447
+
448
+ const fetchRegisteredApiKey = async (
449
+ client: LighterApiClient,
450
+ accountIndex: number,
451
+ apiKeyIndex: number
452
+ ): Promise<{ api_key_index: number; public_key: string } | undefined> => {
453
+ const response = await client.get<{
454
+ code: number
455
+ api_keys: Array<{ api_key_index: number; public_key: string }>
456
+ }>('/api/v1/apikeys', { account_index: accountIndex })
457
+ return response.api_keys?.find((k) => k.api_key_index === apiKeyIndex)
458
+ }
459
+
460
+ const fetchAccountLimits = (
461
+ client: LighterApiClient,
462
+ accountIndex: number,
463
+ authToken: string
464
+ ): Promise<LtAccountLimits> =>
465
+ client.getAuthed<LtAccountLimits>('/api/v1/accountLimits', authToken, {
466
+ account_index: accountIndex,
467
+ })
468
+
469
+ const fetchActiveOrdersForMarket = (
470
+ client: LighterApiClient,
471
+ authToken: string,
472
+ accountIndex: number,
473
+ marketId: number
474
+ ): Promise<LtOrdersResponse> =>
475
+ client.getAuthed<LtOrdersResponse>(
476
+ '/api/v1/accountActiveOrders',
477
+ authToken,
478
+ { account_index: accountIndex, market_id: marketId }
479
+ )
480
+
481
+ const deriveOrderBearingMarketIds = (account: LtDetailedAccount): number[] =>
482
+ account.positions
483
+ .filter((p) => orderCountFor(p) > 0)
484
+ .map((p) => p.market_id)
485
+
486
+ const fetchAllHistory = async (
487
+ client: LighterApiClient,
488
+ token: string,
489
+ accountIndex: number,
490
+ l1Address: string,
491
+ requested: ActivityType[] | undefined,
492
+ inputCursor: LighterActivityCursor | undefined
493
+ ): Promise<{
494
+ deposits: LtDepositHistoryResponse
495
+ withdraws: LtWithdrawHistoryResponse
496
+ fundings: LtPositionFundingsResponse
497
+ liquidations: LtLiquidationsResponse
498
+ transfers: LtTransferHistoryResponse
499
+ }> => {
500
+ const wantsType = (t: ActivityType): boolean =>
501
+ requested === undefined || requested.includes(t)
502
+
503
+ const shouldFetch = (
504
+ t: ActivityType,
505
+ key: keyof LighterActivityCursor
506
+ ): boolean => {
507
+ if (!wantsType(t)) {
508
+ return false
509
+ }
510
+ if (inputCursor === undefined) {
511
+ return true
512
+ }
513
+ const v = inputCursor[key]
514
+ return typeof v === 'string' && v.length > 0
515
+ }
516
+
517
+ const cursorParam = (
518
+ key: keyof LighterActivityCursor
519
+ ): { cursor: string } | Record<string, never> => {
520
+ const v = inputCursor?.[key]
521
+ return typeof v === 'string' && v.length > 0 ? { cursor: v } : {}
522
+ }
523
+
524
+ const empty = <T>(payload: T): T => payload
525
+
526
+ const [deposits, withdraws, fundings, liquidations, transfers] =
527
+ await Promise.all([
528
+ shouldFetch(ActivityType.DEPOSIT, 'deposits')
529
+ ? client.getAuthed<LtDepositHistoryResponse>(
530
+ '/api/v1/deposit/history',
531
+ token,
532
+ {
533
+ account_index: accountIndex,
534
+ l1_address: l1Address,
535
+ ...cursorParam('deposits'),
536
+ }
537
+ )
538
+ : Promise.resolve(empty({ code: 0, deposits: [] })),
539
+ shouldFetch(ActivityType.WITHDRAWAL, 'withdraws')
540
+ ? client.getAuthed<LtWithdrawHistoryResponse>(
541
+ '/api/v1/withdraw/history',
542
+ token,
543
+ { account_index: accountIndex, ...cursorParam('withdraws') }
544
+ )
545
+ : Promise.resolve(empty({ code: 0, withdraws: [] })),
546
+ shouldFetch(ActivityType.FUNDING, 'fundings')
547
+ ? client.getAuthed<LtPositionFundingsResponse>(
548
+ '/api/v1/positionFunding',
549
+ token,
550
+ {
551
+ account_index: accountIndex,
552
+ market_id: LIGHTER_ALL_MARKETS_WILDCARD,
553
+ limit: LIGHTER_HISTORY_PAGE_SIZE,
554
+ ...cursorParam('fundings'),
555
+ }
556
+ )
557
+ : Promise.resolve(empty({ code: 0, position_fundings: [] })),
558
+ shouldFetch(ActivityType.LIQUIDATION, 'liquidations')
559
+ ? client.getAuthed<LtLiquidationsResponse>(
560
+ '/api/v1/liquidations',
561
+ token,
562
+ {
563
+ account_index: accountIndex,
564
+ market_id: LIGHTER_ALL_MARKETS_WILDCARD,
565
+ limit: LIGHTER_HISTORY_PAGE_SIZE,
566
+ ...cursorParam('liquidations'),
567
+ }
568
+ )
569
+ : Promise.resolve(empty({ code: 0, liquidations: [] })),
570
+ shouldFetch(ActivityType.TRANSFER, 'transfers')
571
+ ? client.getAuthed<LtTransferHistoryResponse>(
572
+ '/api/v1/transfer/history',
573
+ token,
574
+ { account_index: accountIndex, ...cursorParam('transfers') }
575
+ )
576
+ : Promise.resolve(empty({ code: 0, transfers: [] })),
577
+ ])
578
+
579
+ return { deposits, withdraws, fundings, liquidations, transfers }
580
+ }
581
+
582
+ return {
583
+ type: LIGHTER_PROVIDER_KEY,
584
+
585
+ bind(client: PerpsSDKClient): void {
586
+ boundClient = client
587
+ },
588
+
589
+ resolveAuthToken(address: Address): Promise<string | undefined> {
590
+ return resolveAuthToken(undefined, address)
591
+ },
592
+
593
+ async getAccount(
594
+ params: ProviderGetAccountParams,
595
+ opts?: SDKRequestOptions
596
+ ): Promise<AccountResponse> {
597
+ const client = apiClient(opts)
598
+ const [account, token] = await Promise.all([
599
+ fetchDetailedAccount(client, params.address),
600
+ resolveAuthToken(opts, params.address),
601
+ ])
602
+
603
+ const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY)
604
+ const [, registeredKey, limitsResult, localKey, storedReadOnlyToken] =
605
+ await Promise.all([
606
+ registry.sync(),
607
+ fetchRegisteredApiKey(client, account.index, DEFAULT_API_KEY_INDEX),
608
+ // No token is a legitimate unauthenticated read → undefined → zero fee
609
+ // tier. A fetch error is NOT: it must propagate, never be coerced to a
610
+ // fabricated 0%/0% fee tier.
611
+ token === undefined
612
+ ? Promise.resolve(undefined)
613
+ : retryOnRevoked(opts, params.address, token, (t) =>
614
+ fetchAccountLimits(client, account.index, t)
615
+ ),
616
+ keyStore ? keyStore.get(params.address) : Promise.resolve(null),
617
+ readOnlyTokenManager.get(params.address, account.index),
618
+ ])
619
+
620
+ // REGISTER_API_KEY is satisfied only when the locally-held keypair
621
+ // matches the key registered on-chain at this slot — existence alone is
622
+ // insufficient (a stale/rotated local key can't sign valid auth tokens).
623
+ const apiKeyRegistered =
624
+ registeredKey !== undefined &&
625
+ localKey !== null &&
626
+ normalizeLighterPublicKey(localKey.apiKeyPublicKey) ===
627
+ normalizeLighterPublicKey(registeredKey.public_key)
628
+
629
+ const positions: Position[] = mapOpenPositions(account.positions, (id) =>
630
+ registry.require(String(id))
631
+ )
632
+
633
+ const totalMarginUsed = positions.reduce(
634
+ (sum, p) => sum + Number.parseFloat(p.marginUsed),
635
+ 0
636
+ )
637
+ const totalUnrealizedPnl = positions.reduce(
638
+ (sum, p) => sum + Number.parseFloat(p.unrealizedPnl),
639
+ 0
640
+ )
641
+
642
+ // USDC collateral is the category quote asset → collateralBalances.
643
+ // `available_balance` is the free collateral (Lighter's `collateral` is
644
+ // gross, i.e. includes margin locked in positions); the locked portion is
645
+ // carried by the positions' `marginUsed`.
646
+ const collateralBalances: Balance[] = [
647
+ {
648
+ categoryId: LIGHTER_PROVIDER_KEY,
649
+ asset: lighterAsset('USDC', 'USDC'),
650
+ units: account.available_balance,
651
+ valueUsd: account.available_balance,
652
+ },
653
+ ]
654
+ // Spot token holdings — non-collateral. USDC value is 1:1; other tokens
655
+ // have no price source at this boundary, so their USD value is unknown.
656
+ const balances: Balance[] = account.assets.map((a) => ({
657
+ categoryId: LIGHTER_PROVIDER_KEY,
658
+ asset: lighterAsset(String(a.asset_id), a.symbol),
659
+ units: a.balance,
660
+ valueUsd: a.symbol === 'USDC' ? a.balance : '0',
661
+ }))
662
+
663
+ const config: LighterAccountConfig = {
664
+ provider: LIGHTER_PROVIDER_KEY,
665
+ accountIndex: account.index,
666
+ apiKeyIndex: DEFAULT_API_KEY_INDEX,
667
+ apiKeyRegistered,
668
+ accountType: account.account_type,
669
+ // Satisfied when a non-expired read-only token is stored locally
670
+ // (`readOnlyTokenManager.get` filters out expired ones).
671
+ readOnlyTokenApproved: storedReadOnlyToken !== undefined,
672
+ readOnlyTokenExpiry: storedReadOnlyToken?.expiry,
673
+ readOnlyTokenScope: storedReadOnlyToken?.scope,
674
+ }
675
+
676
+ return {
677
+ provider: LIGHTER_PROVIDER_KEY,
678
+ address: params.address,
679
+ balances,
680
+ collateralBalances,
681
+ marginUsed: totalMarginUsed.toString(),
682
+ unrealizedPnl: totalUnrealizedPnl.toString(),
683
+ feeTier:
684
+ limitsResult === undefined
685
+ ? ZERO_FEE_TIER
686
+ : projectFeeTier(limitsResult),
687
+ config,
688
+ }
689
+ },
690
+
691
+ async getPositions(
692
+ params: ProviderGetPositionsParams,
693
+ opts?: SDKRequestOptions
694
+ ): Promise<PositionsResponse> {
695
+ const client = apiClient(opts)
696
+ const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY)
697
+ const [account] = await Promise.all([
698
+ fetchDetailedAccount(client, params.address),
699
+ registry.sync(),
700
+ ])
701
+
702
+ let positions: Position[] = mapOpenPositions(account.positions, (id) =>
703
+ registry.require(String(id))
704
+ )
705
+
706
+ if (params.marketId !== undefined) {
707
+ positions = positions.filter((p) => p.market.id === params.marketId)
708
+ }
709
+
710
+ return {
711
+ provider: LIGHTER_PROVIDER_KEY,
712
+ positions,
713
+ pagination: { limit: params.limit ?? positions.length, hasMore: false },
714
+ }
715
+ },
716
+
717
+ async getOrders(
718
+ params: ProviderGetOrdersParams,
719
+ opts?: SDKRequestOptions
720
+ ): Promise<OrdersResponse> {
721
+ const token = await resolveAuthToken(opts, params.address)
722
+ if (token === undefined) {
723
+ return {
724
+ provider: LIGHTER_PROVIDER_KEY,
725
+ openOrders: [],
726
+ triggerOrders: [],
727
+ pagination: { limit: params.limit ?? 0, hasMore: false },
728
+ }
729
+ }
730
+
731
+ const client = apiClient(opts)
732
+ const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY)
733
+ const [account] = await Promise.all([
734
+ fetchDetailedAccount(client, params.address),
735
+ registry.sync(),
736
+ ])
737
+
738
+ const marketIds =
739
+ params.marketId === undefined
740
+ ? deriveOrderBearingMarketIds(account)
741
+ : [Number(params.marketId)]
742
+
743
+ const responses = await retryOnRevoked(opts, params.address, token, (t) =>
744
+ Promise.all(
745
+ marketIds.map((id) =>
746
+ fetchActiveOrdersForMarket(client, t, account.index, id)
747
+ )
748
+ )
749
+ )
750
+
751
+ const { openOrders, triggerOrders } = classifyAndMapOrders(
752
+ responses.flatMap((r) => r.orders),
753
+ (marketIndex) => registry.require(String(marketIndex))
754
+ )
755
+
756
+ const total = openOrders.length + triggerOrders.length
757
+ const limit = params.limit ?? total
758
+ return {
759
+ provider: LIGHTER_PROVIDER_KEY,
760
+ openOrders,
761
+ triggerOrders,
762
+ pagination: { limit, hasMore: total > limit },
763
+ }
764
+ },
765
+
766
+ async getOrder(
767
+ params: ProviderGetOrderParams,
768
+ opts?: SDKRequestOptions
769
+ ): Promise<Order> {
770
+ const token = await resolveAuthToken(opts, params.address)
771
+ if (token === undefined) {
772
+ throw new PerpsError(
773
+ PerpsErrorCode.SDKError,
774
+ 'Lighter order lookup requires an auth token. Pass `authToken` to ' +
775
+ 'lighterProvider, register an API key + signer for on-demand creation, or ' +
776
+ 'forward `options.lighterAuthToken` on the call.'
777
+ )
778
+ }
779
+
780
+ const client = apiClient(opts)
781
+ const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY)
782
+ const [account] = await Promise.all([
783
+ fetchDetailedAccount(client, params.address),
784
+ registry.sync(),
785
+ ])
786
+
787
+ // Native `order_index` route only. The cross-provider `Order.orderId`
788
+ // for Lighter is `String(order_index)` — see `mapOrder`. A tx-hash route
789
+ // would require mapping the caller's executeAction tx hash → wasm nonce
790
+ // → matching order, which the LI.FI backend did via its `UserAction`
791
+ // table; the SDK has no equivalent persistence, so we refuse rather
792
+ // than mis-resolve.
793
+ if (TX_HASH_PATTERN.test(params.id)) {
794
+ throw new PerpsError(
795
+ PerpsErrorCode.OrderNotFound,
796
+ `Lighter order id "${params.id}" looks like a tx hash. The SDK ` +
797
+ `resolves orders by Lighter \`order_index\` only — surface the orderId ` +
798
+ `from the orderUpdates / fills WS stream and pass it here.`
799
+ )
800
+ }
801
+ const predicate: (o: { order_index: number }) => boolean = (o) =>
802
+ String(o.order_index) === params.id
803
+
804
+ const marketIds = deriveOrderBearingMarketIds(account)
805
+ const activeResponses = await retryOnRevoked(
806
+ opts,
807
+ params.address,
808
+ token,
809
+ (t) =>
810
+ Promise.all(
811
+ marketIds.map((id) =>
812
+ fetchActiveOrdersForMarket(client, t, account.index, id)
813
+ )
814
+ )
815
+ )
816
+
817
+ for (const response of activeResponses) {
818
+ const hit = response.orders.find(predicate as (o: unknown) => boolean)
819
+ if (hit !== undefined) {
820
+ return mapOrderDetail(hit, registry.require(String(hit.market_index)))
821
+ }
822
+ }
823
+
824
+ const inactive = await retryOnRevoked(opts, params.address, token, (t) =>
825
+ client.getAuthed<LtOrdersResponse>('/api/v1/accountInactiveOrders', t, {
826
+ account_index: account.index,
827
+ market_id: LIGHTER_ALL_MARKETS_WILDCARD,
828
+ limit: INACTIVE_ORDERS_LOOKUP_LIMIT,
829
+ })
830
+ )
831
+ const hit = inactive.orders.find(predicate as (o: unknown) => boolean)
832
+ if (hit !== undefined) {
833
+ return mapOrderDetail(hit, registry.require(String(hit.market_index)))
834
+ }
835
+
836
+ throw new PerpsError(
837
+ PerpsErrorCode.OrderNotFound,
838
+ `Lighter order ${params.id} not found for ${params.address}`
839
+ )
840
+ },
841
+
842
+ async getFills(
843
+ params: ProviderGetFillsParams,
844
+ opts?: SDKRequestOptions
845
+ ): Promise<FillsResponse> {
846
+ const token = await resolveAuthToken(opts, params.address)
847
+ if (token === undefined) {
848
+ return {
849
+ provider: LIGHTER_PROVIDER_KEY,
850
+ items: [],
851
+ pagination: { limit: params.limit ?? 0, hasMore: false },
852
+ }
853
+ }
854
+
855
+ const client = apiClient(opts)
856
+ const registry = getMarketRegistry(requireClient(), LIGHTER_PROVIDER_KEY)
857
+ const [account] = await Promise.all([
858
+ fetchDetailedAccount(client, params.address),
859
+ registry.sync(),
860
+ ])
861
+
862
+ const queryParams: Record<string, string | number | boolean> = {
863
+ account_index: account.index,
864
+ sort_by: 'timestamp',
865
+ sort_dir: 'desc',
866
+ limit: params.limit ?? DEFAULT_TRADES_LIMIT,
867
+ }
868
+ if (params.cursor !== undefined) {
869
+ queryParams.cursor = params.cursor
870
+ }
871
+
872
+ const response = await retryOnRevoked(
873
+ opts,
874
+ params.address,
875
+ token,
876
+ (tok) =>
877
+ client.getAuthed<LtTradesResponse>('/api/v1/trades', tok, queryParams)
878
+ )
879
+
880
+ const items = response.trades.map((t) =>
881
+ mapFill(t, account.index, registry.require(String(t.market_id)))
882
+ )
883
+
884
+ return {
885
+ provider: LIGHTER_PROVIDER_KEY,
886
+ items,
887
+ pagination: {
888
+ limit: params.limit ?? items.length,
889
+ hasMore: (response.next_cursor ?? '') !== '',
890
+ cursor: response.next_cursor || undefined,
891
+ },
892
+ }
893
+ },
894
+
895
+ async getActivity(
896
+ params: ProviderGetActivityParams,
897
+ opts?: SDKRequestOptions
898
+ ): Promise<ActivitiesResponse> {
899
+ const token = await resolveAuthToken(opts, params.address)
900
+ if (token === undefined) {
901
+ return {
902
+ provider: LIGHTER_PROVIDER_KEY,
903
+ items: [],
904
+ pagination: { limit: params.limit ?? 0, hasMore: false },
905
+ }
906
+ }
907
+
908
+ const inputCursor = decodeActivityCursor(params.cursor)
909
+ const client = apiClient(opts)
910
+ const account = await fetchDetailedAccount(client, params.address)
911
+ const marketRegistry = getMarketRegistry(
912
+ requireClient(),
913
+ LIGHTER_PROVIDER_KEY
914
+ )
915
+ const assetRegistry = getAssetRegistry(
916
+ requireClient(),
917
+ LIGHTER_PROVIDER_KEY
918
+ )
919
+ const [history] = await Promise.all([
920
+ retryOnRevoked(opts, params.address, token, (t) =>
921
+ fetchAllHistory(
922
+ client,
923
+ t,
924
+ account.index,
925
+ params.address,
926
+ params.type,
927
+ inputCursor
928
+ )
929
+ ),
930
+ marketRegistry.sync(),
931
+ assetRegistry.sync(),
932
+ ])
933
+
934
+ const items: ActivityItem[] = [
935
+ ...history.deposits.deposits.map(
936
+ (d): ActivityItem => ({
937
+ id: d.id,
938
+ provider: LIGHTER_PROVIDER_KEY,
939
+ timestamp: toIsoFromMs(d.timestamp),
940
+ type: ActivityType.DEPOSIT,
941
+ amount: d.amount,
942
+ explorerLink: d.l1_tx_hash
943
+ ? `https://scan.li.fi/tx/${d.l1_tx_hash}`
944
+ : undefined,
945
+ })
946
+ ),
947
+ ...history.withdraws.withdraws.map(
948
+ (w): ActivityItem => ({
949
+ id: w.id,
950
+ provider: LIGHTER_PROVIDER_KEY,
951
+ timestamp: toIsoFromMs(w.timestamp),
952
+ type: ActivityType.WITHDRAWAL,
953
+ amount: w.amount,
954
+ fee: '0',
955
+ explorerLink: w.l1_tx_hash
956
+ ? `https://scan.li.fi/tx/${w.l1_tx_hash}`
957
+ : undefined,
958
+ })
959
+ ),
960
+ ...history.fundings.position_fundings.map(
961
+ (f): ActivityItem => ({
962
+ id: `funding-${f.funding_id}`,
963
+ provider: LIGHTER_PROVIDER_KEY,
964
+ timestamp: toIsoFromSeconds(f.timestamp),
965
+ type: ActivityType.FUNDING,
966
+ market: marketRegistry.require(String(f.market_id)),
967
+ amount: f.change,
968
+ positionSize: f.position_size,
969
+ fundingRate: f.rate,
970
+ })
971
+ ),
972
+ ...history.liquidations.liquidations.map(
973
+ (l): ActivityItem => ({
974
+ id: `liquidation-${l.id}`,
975
+ provider: LIGHTER_PROVIDER_KEY,
976
+ timestamp: toIsoFromMs(l.executed_at),
977
+ type: ActivityType.LIQUIDATION,
978
+ liquidatedNotionalPosition: '0',
979
+ accountValue: '0',
980
+ leverageType: l.type,
981
+ liquidatedPositions: [
982
+ {
983
+ market: marketRegistry.require(String(l.market_id)),
984
+ size: '0',
985
+ },
986
+ ],
987
+ })
988
+ ),
989
+ ...history.transfers.transfers.map((t): ActivityItem => {
990
+ const direction: 'IN' | 'OUT' =
991
+ t.from_account_index === account.index ? 'OUT' : 'IN'
992
+ const counterpartyAccountIndex =
993
+ direction === 'OUT' ? t.to_account_index : t.from_account_index
994
+ return {
995
+ id: t.id,
996
+ provider: LIGHTER_PROVIDER_KEY,
997
+ timestamp: toIsoFromMs(t.timestamp),
998
+ type: ActivityType.TRANSFER,
999
+ direction,
1000
+ counterpartyAccountIndex,
1001
+ asset:
1002
+ assetRegistry.get(String(t.asset_id))?.displaySymbol ??
1003
+ String(t.asset_id),
1004
+ amount: t.amount,
1005
+ explorerLink: explorerTxUrl(ExplorerChainId.LIGHTER, t.tx_hash),
1006
+ meta: {
1007
+ transferType: t.type,
1008
+ txHash: t.tx_hash,
1009
+ fromRoute: t.from_route,
1010
+ toRoute: t.to_route,
1011
+ fee: t.fee,
1012
+ },
1013
+ }
1014
+ }),
1015
+ ]
1016
+
1017
+ const merged = [...(inputCursor?.overflow ?? []), ...items]
1018
+
1019
+ const filtered = merged.filter((it) => {
1020
+ const ts = new Date(it.timestamp).getTime()
1021
+ if (params.startTime !== undefined && ts < params.startTime) {
1022
+ return false
1023
+ }
1024
+ if (params.endTime !== undefined && ts > params.endTime) {
1025
+ return false
1026
+ }
1027
+ return true
1028
+ })
1029
+
1030
+ filtered.sort(
1031
+ (a, b) =>
1032
+ new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
1033
+ )
1034
+
1035
+ const limit = params.limit ?? filtered.length
1036
+ const emitted = filtered.slice(0, limit)
1037
+ const overflow = filtered.slice(limit)
1038
+
1039
+ const nextCursorEnvelope: LighterActivityCursor = {
1040
+ deposits: history.deposits.cursor,
1041
+ withdraws: history.withdraws.cursor,
1042
+ fundings: history.fundings.next_cursor,
1043
+ liquidations: history.liquidations.next_cursor,
1044
+ transfers: history.transfers.cursor,
1045
+ overflow,
1046
+ }
1047
+ const responseCursor = encodeActivityCursor(nextCursorEnvelope)
1048
+ const hasMore = responseCursor !== undefined
1049
+
1050
+ return {
1051
+ provider: LIGHTER_PROVIDER_KEY,
1052
+ items: emitted,
1053
+ pagination: {
1054
+ limit,
1055
+ hasMore,
1056
+ ...(responseCursor === undefined ? {} : { cursor: responseCursor }),
1057
+ },
1058
+ }
1059
+ },
1060
+
1061
+ getQuote(
1062
+ params: ProviderGetQuoteParams,
1063
+ opts?: SDKRequestOptions
1064
+ ): Promise<Quote> {
1065
+ return resolveQuote(
1066
+ requireClient(),
1067
+ LIGHTER_PROVIDER_KEY,
1068
+ params,
1069
+ LIGHTER_BASE_FEE_TIER,
1070
+ opts
1071
+ )
1072
+ },
1073
+
1074
+ getPortfolioSummary(
1075
+ account: AccountResponse,
1076
+ positions: Position[]
1077
+ ): AccountSummary {
1078
+ return summarizeLighterAccount(account, positions)
1079
+ },
1080
+
1081
+ formatOrderPrice,
1082
+
1083
+ formatOrderSize,
1084
+
1085
+ estimateLiquidationPrice,
1086
+
1087
+ projectConfig(
1088
+ config: AccountConfig,
1089
+ setup: ProviderAction[],
1090
+ options: ProviderAction[]
1091
+ ): AccountConfigSetting[] {
1092
+ if (config.provider !== LIGHTER_PROVIDER_KEY) {
1093
+ throw new PerpsError(
1094
+ PerpsErrorCode.SDKError,
1095
+ `lighterProvider.projectConfig received config for provider ` +
1096
+ `'${config.provider}'.`
1097
+ )
1098
+ }
1099
+ return projectLighterConfigSettings(config, setup, options)
1100
+ },
1101
+
1102
+ /**
1103
+ * Hand the backend the local pubkey for REGISTER_API_KEY so its
1104
+ * idempotency check can compare against the on-chain slot. No keystore
1105
+ * configured, or no key stored for this address → omit the field;
1106
+ * backend stages a fresh registration.
1107
+ */
1108
+ async resolveSetupParams(
1109
+ action: ActionType,
1110
+ address: Address
1111
+ ): Promise<Record<string, unknown>> {
1112
+ if (action !== ActionType.REGISTER_API_KEY) {
1113
+ return {}
1114
+ }
1115
+ if (keyStore === undefined) {
1116
+ return {}
1117
+ }
1118
+ const local = await keyStore.get(address)
1119
+ if (local === null) {
1120
+ return {}
1121
+ }
1122
+ return { knownPublicKey: local.apiKeyPublicKey }
1123
+ },
1124
+
1125
+ async signActions(
1126
+ method: SigningMethod,
1127
+ steps: ActionStep[],
1128
+ address: Address,
1129
+ ctx?: SignActionsContext
1130
+ ): Promise<SignedActionStep[]> {
1131
+ if (signer === undefined || keyStore === undefined) {
1132
+ throw new PerpsError(
1133
+ PerpsErrorCode.SDKError,
1134
+ 'lighterProvider.signActions requires `signer` and `keyStore` to be ' +
1135
+ 'configured at construction.'
1136
+ )
1137
+ }
1138
+ const signerRef = signer
1139
+ const keyStoreRef = keyStore
1140
+ return lighterSignActions(
1141
+ {
1142
+ signer: signerRef,
1143
+ keyStore: keyStoreRef,
1144
+ resolveAccountIndex: async (addr) => {
1145
+ const apiKey = await keyStoreRef.get(addr)
1146
+ if (apiKey !== null) {
1147
+ return apiKey.accountIndex
1148
+ }
1149
+ const account = await fetchDetailedAccount(apiClient(), addr)
1150
+ return account.index
1151
+ },
1152
+ },
1153
+ method,
1154
+ steps,
1155
+ address,
1156
+ ctx
1157
+ )
1158
+ },
1159
+ }
1160
+ }
1161
+
1162
+ /**
1163
+ * Alias matching `@lifi/sdk`'s capitalised factory naming (`EVM()`, `EthereumProvider()`).
1164
+ *
1165
+ * @public
1166
+ */
1167
+ export const Lighter = lighterProvider