lighter-ts-sdk 1.0.8 → 1.0.9

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 (511) hide show
  1. package/README.md +743 -476
  2. package/dist/browser/index.html +20 -0
  3. package/dist/browser/lighter-ts-sdk.browser.js +33886 -0
  4. package/dist/browser/lighter-ts-sdk.browser.js.map +7 -0
  5. package/dist/cjs/api/account-api.d.ts +251 -0
  6. package/dist/cjs/api/account-api.d.ts.map +1 -0
  7. package/dist/cjs/api/account-api.js +203 -0
  8. package/dist/cjs/api/account-api.js.map +1 -0
  9. package/dist/cjs/api/announcement-api.d.ts.map +1 -0
  10. package/dist/cjs/api/announcement-api.js.map +1 -0
  11. package/dist/cjs/api/api-client.d.ts.map +1 -0
  12. package/dist/cjs/api/api-client.js +146 -0
  13. package/dist/cjs/api/api-client.js.map +1 -0
  14. package/dist/cjs/api/block-api.d.ts.map +1 -0
  15. package/dist/cjs/api/block-api.js.map +1 -0
  16. package/dist/{api → cjs/api}/bridge-api.d.ts +34 -0
  17. package/dist/cjs/api/bridge-api.d.ts.map +1 -0
  18. package/dist/cjs/api/bridge-api.js +173 -0
  19. package/dist/cjs/api/bridge-api.js.map +1 -0
  20. package/dist/{api → cjs/api}/candlestick-api.d.ts +3 -0
  21. package/dist/cjs/api/candlestick-api.d.ts.map +1 -0
  22. package/dist/cjs/api/candlestick-api.js +21 -0
  23. package/dist/cjs/api/candlestick-api.js.map +1 -0
  24. package/dist/cjs/api/explorer-api-client.d.ts +32 -0
  25. package/dist/cjs/api/explorer-api-client.d.ts.map +1 -0
  26. package/dist/cjs/api/explorer-api-client.js +138 -0
  27. package/dist/cjs/api/explorer-api-client.js.map +1 -0
  28. package/dist/cjs/api/funding-api.d.ts.map +1 -0
  29. package/dist/cjs/api/funding-api.js.map +1 -0
  30. package/dist/cjs/api/info-api.d.ts +43 -0
  31. package/dist/cjs/api/info-api.d.ts.map +1 -0
  32. package/dist/cjs/api/info-api.js +52 -0
  33. package/dist/cjs/api/info-api.js.map +1 -0
  34. package/dist/cjs/api/logs-api.d.ts +198 -0
  35. package/dist/cjs/api/logs-api.d.ts.map +1 -0
  36. package/dist/cjs/api/logs-api.js +256 -0
  37. package/dist/cjs/api/logs-api.js.map +1 -0
  38. package/dist/{api → cjs/api}/notification-api.d.ts +28 -0
  39. package/dist/cjs/api/notification-api.d.ts.map +1 -0
  40. package/dist/cjs/api/notification-api.js +108 -0
  41. package/dist/cjs/api/notification-api.js.map +1 -0
  42. package/dist/{api → cjs/api}/order-api.d.ts +22 -5
  43. package/dist/cjs/api/order-api.d.ts.map +1 -0
  44. package/dist/cjs/api/order-api.js +181 -0
  45. package/dist/cjs/api/order-api.js.map +1 -0
  46. package/dist/{api → cjs/api}/referral-api.d.ts +9 -0
  47. package/dist/cjs/api/referral-api.d.ts.map +1 -0
  48. package/dist/cjs/api/referral-api.js +53 -0
  49. package/dist/cjs/api/referral-api.js.map +1 -0
  50. package/dist/cjs/api/root-api.d.ts +15 -0
  51. package/dist/cjs/api/root-api.d.ts.map +1 -0
  52. package/dist/cjs/api/root-api.js +18 -0
  53. package/dist/cjs/api/root-api.js.map +1 -0
  54. package/dist/cjs/api/search-api.d.ts +211 -0
  55. package/dist/cjs/api/search-api.d.ts.map +1 -0
  56. package/dist/cjs/api/search-api.js +112 -0
  57. package/dist/cjs/api/search-api.js.map +1 -0
  58. package/dist/{api → cjs/api}/transaction-api.d.ts +4 -0
  59. package/dist/cjs/api/transaction-api.d.ts.map +1 -0
  60. package/dist/cjs/api/transaction-api.js +173 -0
  61. package/dist/cjs/api/transaction-api.js.map +1 -0
  62. package/dist/{api → cjs/api}/ws-client.d.ts +1 -0
  63. package/dist/cjs/api/ws-client.d.ts.map +1 -0
  64. package/dist/cjs/api/ws-client.js +139 -0
  65. package/dist/cjs/api/ws-client.js.map +1 -0
  66. package/dist/{api → cjs/api}/ws-order-client.d.ts +1 -0
  67. package/dist/cjs/api/ws-order-client.d.ts.map +1 -0
  68. package/dist/cjs/api/ws-order-client.js +451 -0
  69. package/dist/cjs/api/ws-order-client.js.map +1 -0
  70. package/dist/cjs/bridge/l1-bridge-client.d.ts.map +1 -0
  71. package/dist/cjs/bridge/l1-bridge-client.js.map +1 -0
  72. package/dist/{index.d.ts → cjs/index.d.ts} +19 -8
  73. package/dist/cjs/index.d.ts.map +1 -0
  74. package/dist/cjs/index.js +175 -0
  75. package/dist/cjs/index.js.map +1 -0
  76. package/dist/cjs/package.json +3 -0
  77. package/dist/{signer → cjs/signer}/wasm-signer-client.d.ts +91 -68
  78. package/dist/cjs/signer/wasm-signer-client.d.ts.map +1 -0
  79. package/dist/cjs/signer/wasm-signer-client.js +2263 -0
  80. package/dist/cjs/signer/wasm-signer-client.js.map +1 -0
  81. package/dist/{signer → cjs/signer}/wasm-signer.d.ts +8 -0
  82. package/dist/cjs/signer/wasm-signer.d.ts.map +1 -0
  83. package/dist/cjs/signer/wasm-signer.js +940 -0
  84. package/dist/cjs/signer/wasm-signer.js.map +1 -0
  85. package/dist/{types → cjs/types}/api.d.ts +13 -0
  86. package/dist/cjs/types/api.d.ts.map +1 -0
  87. package/dist/cjs/types/api.js.map +1 -0
  88. package/dist/cjs/types/config.d.ts.map +1 -0
  89. package/dist/cjs/types/config.js.map +1 -0
  90. package/dist/cjs/types/generated/openapi.d.ts.map +1 -0
  91. package/dist/cjs/types/generated/openapi.js.map +1 -0
  92. package/dist/cjs/types/index.d.ts.map +1 -0
  93. package/dist/cjs/types/index.js.map +1 -0
  94. package/dist/cjs/types/trading.d.ts.map +1 -0
  95. package/dist/cjs/types/trading.js.map +1 -0
  96. package/dist/cjs/types/transaction.d.ts.map +1 -0
  97. package/dist/cjs/types/transaction.js.map +1 -0
  98. package/dist/cjs/utils/configuration.d.ts.map +1 -0
  99. package/dist/cjs/utils/configuration.js.map +1 -0
  100. package/dist/cjs/utils/environment.d.ts +70 -0
  101. package/dist/cjs/utils/environment.d.ts.map +1 -0
  102. package/dist/cjs/utils/environment.js +214 -0
  103. package/dist/cjs/utils/environment.js.map +1 -0
  104. package/dist/cjs/utils/exceptions.d.ts.map +1 -0
  105. package/dist/cjs/utils/exceptions.js.map +1 -0
  106. package/dist/cjs/utils/index.d.ts.map +1 -0
  107. package/dist/cjs/utils/index.js.map +1 -0
  108. package/dist/cjs/utils/logger.d.ts.map +1 -0
  109. package/dist/cjs/utils/logger.js.map +1 -0
  110. package/dist/cjs/utils/market-helper.d.ts.map +1 -0
  111. package/dist/cjs/utils/market-helper.js.map +1 -0
  112. package/dist/cjs/utils/nonce-cache.d.ts.map +1 -0
  113. package/dist/cjs/utils/nonce-cache.js.map +1 -0
  114. package/dist/cjs/utils/nonce-manager.d.ts.map +1 -0
  115. package/dist/cjs/utils/nonce-manager.js.map +1 -0
  116. package/dist/cjs/utils/order-status-checker.d.ts.map +1 -0
  117. package/dist/cjs/utils/order-status-checker.js.map +1 -0
  118. package/dist/cjs/utils/price-utils.d.ts.map +1 -0
  119. package/dist/cjs/utils/price-utils.js.map +1 -0
  120. package/dist/cjs/utils/request-batcher.d.ts.map +1 -0
  121. package/dist/cjs/utils/request-batcher.js.map +1 -0
  122. package/dist/esm/api/account-api.d.ts +251 -0
  123. package/dist/esm/api/account-api.d.ts.map +1 -0
  124. package/dist/esm/api/account-api.js +199 -0
  125. package/dist/esm/api/account-api.js.map +1 -0
  126. package/dist/esm/api/announcement-api.d.ts +27 -0
  127. package/dist/esm/api/announcement-api.d.ts.map +1 -0
  128. package/dist/esm/api/announcement-api.js +21 -0
  129. package/dist/esm/api/announcement-api.js.map +1 -0
  130. package/dist/esm/api/api-client.d.ts +23 -0
  131. package/dist/esm/api/api-client.d.ts.map +1 -0
  132. package/dist/esm/api/api-client.js +139 -0
  133. package/dist/esm/api/api-client.js.map +1 -0
  134. package/dist/esm/api/block-api.d.ts +24 -0
  135. package/dist/esm/api/block-api.d.ts.map +1 -0
  136. package/dist/esm/api/block-api.js +18 -0
  137. package/dist/esm/api/block-api.js.map +1 -0
  138. package/dist/esm/api/bridge-api.d.ts +112 -0
  139. package/dist/esm/api/bridge-api.d.ts.map +1 -0
  140. package/dist/esm/api/bridge-api.js +169 -0
  141. package/dist/esm/api/bridge-api.js.map +1 -0
  142. package/dist/esm/api/candlestick-api.d.ts +30 -0
  143. package/dist/esm/api/candlestick-api.d.ts.map +1 -0
  144. package/dist/esm/api/candlestick-api.js +17 -0
  145. package/dist/esm/api/candlestick-api.js.map +1 -0
  146. package/dist/esm/api/explorer-api-client.d.ts +32 -0
  147. package/dist/esm/api/explorer-api-client.d.ts.map +1 -0
  148. package/dist/esm/api/explorer-api-client.js +131 -0
  149. package/dist/esm/api/explorer-api-client.js.map +1 -0
  150. package/dist/esm/api/funding-api.d.ts +28 -0
  151. package/dist/esm/api/funding-api.d.ts.map +1 -0
  152. package/dist/esm/api/funding-api.js +21 -0
  153. package/dist/esm/api/funding-api.js.map +1 -0
  154. package/dist/esm/api/info-api.d.ts +43 -0
  155. package/dist/esm/api/info-api.d.ts.map +1 -0
  156. package/dist/esm/api/info-api.js +48 -0
  157. package/dist/esm/api/info-api.js.map +1 -0
  158. package/dist/esm/api/logs-api.d.ts +198 -0
  159. package/dist/esm/api/logs-api.d.ts.map +1 -0
  160. package/dist/esm/api/logs-api.js +252 -0
  161. package/dist/esm/api/logs-api.js.map +1 -0
  162. package/dist/esm/api/notification-api.d.ts +55 -0
  163. package/dist/esm/api/notification-api.d.ts.map +1 -0
  164. package/dist/esm/api/notification-api.js +104 -0
  165. package/dist/esm/api/notification-api.js.map +1 -0
  166. package/dist/esm/api/order-api.d.ts +294 -0
  167. package/dist/esm/api/order-api.d.ts.map +1 -0
  168. package/dist/esm/api/order-api.js +177 -0
  169. package/dist/esm/api/order-api.js.map +1 -0
  170. package/dist/esm/api/referral-api.d.ts +46 -0
  171. package/dist/esm/api/referral-api.d.ts.map +1 -0
  172. package/dist/esm/api/referral-api.js +49 -0
  173. package/dist/esm/api/referral-api.js.map +1 -0
  174. package/dist/esm/api/root-api.d.ts +15 -0
  175. package/dist/esm/api/root-api.d.ts.map +1 -0
  176. package/dist/esm/api/root-api.js +14 -0
  177. package/dist/esm/api/root-api.js.map +1 -0
  178. package/dist/esm/api/search-api.d.ts +211 -0
  179. package/dist/esm/api/search-api.d.ts.map +1 -0
  180. package/dist/esm/api/search-api.js +108 -0
  181. package/dist/esm/api/search-api.js.map +1 -0
  182. package/dist/esm/api/transaction-api.d.ts +120 -0
  183. package/dist/esm/api/transaction-api.d.ts.map +1 -0
  184. package/dist/esm/api/transaction-api.js +169 -0
  185. package/dist/esm/api/transaction-api.js.map +1 -0
  186. package/dist/esm/api/ws-client.d.ts +22 -0
  187. package/dist/esm/api/ws-client.d.ts.map +1 -0
  188. package/dist/esm/api/ws-client.js +132 -0
  189. package/dist/esm/api/ws-client.js.map +1 -0
  190. package/dist/esm/api/ws-order-client.d.ts +84 -0
  191. package/dist/esm/api/ws-order-client.d.ts.map +1 -0
  192. package/dist/esm/api/ws-order-client.js +444 -0
  193. package/dist/esm/api/ws-order-client.js.map +1 -0
  194. package/dist/esm/bridge/l1-bridge-client.d.ts +49 -0
  195. package/dist/esm/bridge/l1-bridge-client.d.ts.map +1 -0
  196. package/dist/esm/bridge/l1-bridge-client.js +172 -0
  197. package/dist/esm/bridge/l1-bridge-client.js.map +1 -0
  198. package/dist/esm/browser-check.js +33637 -0
  199. package/dist/esm/index.d.ts +94 -0
  200. package/dist/esm/index.d.ts.map +1 -0
  201. package/dist/esm/index.js +100 -0
  202. package/dist/esm/index.js.map +1 -0
  203. package/dist/esm/signer/wasm-signer-client.d.ts +593 -0
  204. package/dist/esm/signer/wasm-signer-client.d.ts.map +1 -0
  205. package/dist/esm/signer/wasm-signer-client.js +2236 -0
  206. package/dist/esm/signer/wasm-signer-client.js.map +1 -0
  207. package/dist/esm/signer/wasm-signer.d.ts +373 -0
  208. package/dist/esm/signer/wasm-signer.d.ts.map +1 -0
  209. package/dist/esm/signer/wasm-signer.js +935 -0
  210. package/dist/esm/signer/wasm-signer.js.map +1 -0
  211. package/dist/esm/types/api.d.ts +198 -0
  212. package/dist/esm/types/api.d.ts.map +1 -0
  213. package/dist/esm/types/api.js +6 -0
  214. package/dist/esm/types/api.js.map +1 -0
  215. package/dist/esm/types/config.d.ts +66 -0
  216. package/dist/esm/types/config.d.ts.map +1 -0
  217. package/dist/esm/types/config.js +6 -0
  218. package/dist/{types → esm/types}/config.js.map +1 -1
  219. package/dist/esm/types/generated/openapi.d.ts +5007 -0
  220. package/dist/esm/types/generated/openapi.d.ts.map +1 -0
  221. package/dist/esm/types/generated/openapi.js +6 -0
  222. package/dist/esm/types/generated/openapi.js.map +1 -0
  223. package/dist/esm/types/index.d.ts +32 -0
  224. package/dist/esm/types/index.d.ts.map +1 -0
  225. package/dist/esm/types/index.js +8 -0
  226. package/dist/esm/types/index.js.map +1 -0
  227. package/dist/esm/types/trading.d.ts +43 -0
  228. package/dist/esm/types/trading.d.ts.map +1 -0
  229. package/dist/esm/types/trading.js +22 -0
  230. package/dist/esm/types/trading.js.map +1 -0
  231. package/dist/esm/types/transaction.d.ts +57 -0
  232. package/dist/esm/types/transaction.d.ts.map +1 -0
  233. package/dist/esm/types/transaction.js +26 -0
  234. package/dist/esm/types/transaction.js.map +1 -0
  235. package/dist/esm/utils/configuration.d.ts +19 -0
  236. package/dist/esm/utils/configuration.d.ts.map +1 -0
  237. package/dist/esm/utils/configuration.js +51 -0
  238. package/dist/esm/utils/configuration.js.map +1 -0
  239. package/dist/esm/utils/environment.d.ts +70 -0
  240. package/dist/esm/utils/environment.d.ts.map +1 -0
  241. package/dist/esm/utils/environment.js +198 -0
  242. package/dist/esm/utils/environment.js.map +1 -0
  243. package/dist/esm/utils/exceptions.d.ts +57 -0
  244. package/dist/esm/utils/exceptions.d.ts.map +1 -0
  245. package/dist/esm/utils/exceptions.js +105 -0
  246. package/dist/esm/utils/exceptions.js.map +1 -0
  247. package/dist/esm/utils/index.d.ts +14 -0
  248. package/dist/esm/utils/index.d.ts.map +1 -0
  249. package/dist/esm/utils/index.js +22 -0
  250. package/dist/esm/utils/index.js.map +1 -0
  251. package/dist/esm/utils/logger.d.ts +35 -0
  252. package/dist/esm/utils/logger.d.ts.map +1 -0
  253. package/dist/esm/utils/logger.js +92 -0
  254. package/dist/esm/utils/logger.js.map +1 -0
  255. package/dist/esm/utils/market-helper.d.ts +62 -0
  256. package/dist/esm/utils/market-helper.d.ts.map +1 -0
  257. package/dist/esm/utils/market-helper.js +96 -0
  258. package/dist/esm/utils/market-helper.js.map +1 -0
  259. package/dist/esm/utils/nonce-cache.d.ts +37 -0
  260. package/dist/esm/utils/nonce-cache.d.ts.map +1 -0
  261. package/dist/esm/utils/nonce-cache.js +132 -0
  262. package/dist/esm/utils/nonce-cache.js.map +1 -0
  263. package/dist/esm/utils/nonce-manager.d.ts +79 -0
  264. package/dist/esm/utils/nonce-manager.d.ts.map +1 -0
  265. package/dist/esm/utils/nonce-manager.js +123 -0
  266. package/dist/esm/utils/nonce-manager.js.map +1 -0
  267. package/dist/esm/utils/order-status-checker.d.ts +29 -0
  268. package/dist/esm/utils/order-status-checker.d.ts.map +1 -0
  269. package/dist/esm/utils/order-status-checker.js +93 -0
  270. package/dist/esm/utils/order-status-checker.js.map +1 -0
  271. package/dist/esm/utils/price-utils.d.ts +86 -0
  272. package/dist/esm/utils/price-utils.d.ts.map +1 -0
  273. package/dist/esm/utils/price-utils.js +206 -0
  274. package/dist/esm/utils/price-utils.js.map +1 -0
  275. package/dist/esm/utils/request-batcher.d.ts +45 -0
  276. package/dist/esm/utils/request-batcher.d.ts.map +1 -0
  277. package/dist/esm/utils/request-batcher.js +161 -0
  278. package/dist/esm/utils/request-batcher.js.map +1 -0
  279. package/dist/examples/examples/cancel_order.js +90 -0
  280. package/dist/examples/examples/create_limit_order.js +213 -0
  281. package/dist/examples/examples/create_market_order.js +191 -0
  282. package/dist/examples/examples/explorer_logs_example.js +228 -0
  283. package/dist/examples/examples/explorer_search_example.js +196 -0
  284. package/dist/examples/examples/market_data.js +183 -0
  285. package/dist/examples/public_pool_deposit.js +67 -0
  286. package/dist/examples/public_pool_info.js +75 -0
  287. package/dist/{api → examples/src/api}/account-api.js +34 -3
  288. package/dist/examples/src/api/announcement-api.js +24 -0
  289. package/dist/{api → examples/src/api}/api-client.js +0 -1
  290. package/dist/examples/src/api/block-api.js +21 -0
  291. package/dist/{api → examples/src/api}/bridge-api.js +0 -1
  292. package/dist/{api → examples/src/api}/candlestick-api.js +5 -3
  293. package/dist/examples/src/api/explorer-api-client.js +127 -0
  294. package/dist/examples/src/api/funding-api.js +24 -0
  295. package/dist/examples/src/api/info-api.js +43 -0
  296. package/dist/examples/src/api/logs-api.js +255 -0
  297. package/dist/{api → examples/src/api}/notification-api.js +0 -1
  298. package/dist/{api → examples/src/api}/order-api.js +40 -7
  299. package/dist/{api → examples/src/api}/referral-api.js +0 -1
  300. package/dist/{api → examples/src/api}/root-api.js +4 -1
  301. package/dist/examples/src/api/search-api.js +111 -0
  302. package/dist/{api → examples/src/api}/transaction-api.js +7 -1
  303. package/dist/{api → examples/src/api}/ws-client.js +0 -1
  304. package/dist/{api → examples/src/api}/ws-order-client.js +1 -1
  305. package/dist/examples/src/bridge/l1-bridge-client.js +175 -0
  306. package/dist/{index.js → examples/src/index.js} +28 -3
  307. package/dist/{signer → examples/src/signer}/wasm-signer-client.js +52 -1
  308. package/dist/{signer → examples/src/signer}/wasm-signer.js +0 -1
  309. package/dist/examples/src/types/api.js +6 -0
  310. package/dist/examples/src/types/config.js +6 -0
  311. package/dist/examples/src/types/generated/openapi.js +6 -0
  312. package/dist/examples/src/types/index.js +23 -0
  313. package/dist/examples/src/types/trading.js +24 -0
  314. package/dist/examples/src/types/transaction.js +28 -0
  315. package/dist/examples/src/utils/configuration.js +54 -0
  316. package/dist/examples/src/utils/environment.js +213 -0
  317. package/dist/examples/src/utils/exceptions.js +122 -0
  318. package/dist/examples/src/utils/logger.js +95 -0
  319. package/dist/examples/src/utils/market-helper.js +99 -0
  320. package/dist/examples/src/utils/nonce-cache.js +135 -0
  321. package/dist/examples/src/utils/nonce-manager.js +129 -0
  322. package/dist/examples/src/utils/order-status-checker.js +98 -0
  323. package/dist/examples/src/utils/price-utils.js +228 -0
  324. package/dist/examples/src/utils/request-batcher.js +167 -0
  325. package/dist/umd/index.html +63 -0
  326. package/dist/umd/lighter-signer.wasm +0 -0
  327. package/dist/umd/lighter-ts-sdk.js +33894 -0
  328. package/dist/umd/lighter-ts-sdk.js.map +7 -0
  329. package/dist/umd/lighter-ts-sdk.min.js +25 -0
  330. package/dist/umd/lighter-ts-sdk.min.js.map +7 -0
  331. package/dist/umd/package.json +13 -0
  332. package/dist/umd/signer-import-check.html +29 -0
  333. package/dist/umd/signer-umd-check.html +29 -0
  334. package/dist/umd/wasm_exec.js +575 -0
  335. package/docs/API.md +191 -207
  336. package/docs/AccountApi.md +278 -278
  337. package/docs/ExplorerApi.md +536 -0
  338. package/docs/GettingStarted.md +388 -361
  339. package/docs/MarginManagement.md +628 -0
  340. package/docs/MarketHelper.md +1 -1
  341. package/docs/MigrationGuide.md +17 -14
  342. package/docs/OrderApi.md +353 -353
  343. package/docs/SignerClient.md +628 -626
  344. package/docs/TransactionApi.md +474 -474
  345. package/docs/TransactionMonitoring.md +520 -0
  346. package/docs/Utilities.md +9 -10
  347. package/docs/WsClient.md +1 -2
  348. package/docs/types/SignerConfig.md +40 -40
  349. package/docs/types/WasmSignerConfig.md +2 -2
  350. package/examples/README.md +247 -242
  351. package/examples/cancel_all_orders.ts +17 -4
  352. package/examples/cancel_order.ts +78 -76
  353. package/examples/close_all_positions.ts +405 -403
  354. package/examples/close_position.ts +166 -164
  355. package/examples/create_auth_token.ts +59 -57
  356. package/examples/create_grouped_ioc_with_attached_sl_tp.ts +180 -178
  357. package/examples/create_grouped_orders.ts +205 -203
  358. package/examples/create_limit_order.ts +23 -135
  359. package/examples/create_market_order.ts +124 -179
  360. package/examples/create_market_order_max_slippage.ts +121 -119
  361. package/examples/create_position_tied_sl_tp.ts +210 -208
  362. package/examples/create_subaccount.ts +3 -1
  363. package/examples/create_twap_order.ts +24 -41
  364. package/examples/create_with_multiple_keys.ts +35 -20
  365. package/examples/live_smoke.ts +253 -0
  366. package/examples/margin_eth_add_collateral_http.ts +75 -0
  367. package/examples/margin_eth_remove_collateral_http.ts +76 -0
  368. package/examples/market_data.ts +172 -175
  369. package/examples/modify_order.ts +22 -13
  370. package/examples/multi_client_advanced.ts +256 -254
  371. package/examples/onboarding.ts +455 -0
  372. package/examples/public_pool_deposit.ts +80 -0
  373. package/examples/public_pool_info.ts +83 -0
  374. package/examples/public_pool_operations.ts +152 -150
  375. package/examples/public_pool_withdraw.ts +78 -0
  376. package/examples/revoke_api_key.ts +132 -130
  377. package/examples/send_tx_batch.ts +110 -110
  378. package/examples/spot/README.md +99 -99
  379. package/examples/spot/cancel_spot_order.ts +89 -89
  380. package/examples/spot/create_market_spot_orders.ts +196 -259
  381. package/examples/spot/create_spot_limit_order.ts +122 -122
  382. package/examples/spot/create_spot_limit_order_with_sltp.ts +157 -193
  383. package/examples/spot/create_spot_twap_order.ts +110 -110
  384. package/examples/spot/modify_spot_order.ts +146 -146
  385. package/examples/spot_get_account_assets_http.ts +86 -0
  386. package/examples/system_setup.ts +225 -223
  387. package/examples/transfer_spot_perp.ts +167 -165
  388. package/examples/update_margin.ts +5 -3
  389. package/examples/update_margin_leverage.ts +2 -2
  390. package/examples/withdraw_fast.ts +198 -196
  391. package/examples/withdraw_to_l1.ts +3 -1
  392. package/package.json +29 -15
  393. package/wasm/wasm_exec.js +575 -575
  394. package/dist/api/account-api.d.ts +0 -124
  395. package/dist/api/account-api.d.ts.map +0 -1
  396. package/dist/api/account-api.js.map +0 -1
  397. package/dist/api/announcement-api.d.ts.map +0 -1
  398. package/dist/api/announcement-api.js.map +0 -1
  399. package/dist/api/api-client.d.ts.map +0 -1
  400. package/dist/api/api-client.js.map +0 -1
  401. package/dist/api/block-api.d.ts.map +0 -1
  402. package/dist/api/block-api.js.map +0 -1
  403. package/dist/api/bridge-api.d.ts.map +0 -1
  404. package/dist/api/bridge-api.js.map +0 -1
  405. package/dist/api/candlestick-api.d.ts.map +0 -1
  406. package/dist/api/candlestick-api.js.map +0 -1
  407. package/dist/api/funding-api.d.ts.map +0 -1
  408. package/dist/api/funding-api.js.map +0 -1
  409. package/dist/api/notification-api.d.ts.map +0 -1
  410. package/dist/api/notification-api.js.map +0 -1
  411. package/dist/api/order-api.d.ts.map +0 -1
  412. package/dist/api/order-api.js.map +0 -1
  413. package/dist/api/referral-api.d.ts.map +0 -1
  414. package/dist/api/referral-api.js.map +0 -1
  415. package/dist/api/root-api.d.ts +0 -8
  416. package/dist/api/root-api.d.ts.map +0 -1
  417. package/dist/api/root-api.js.map +0 -1
  418. package/dist/api/transaction-api.d.ts.map +0 -1
  419. package/dist/api/transaction-api.js.map +0 -1
  420. package/dist/api/ws-client.d.ts.map +0 -1
  421. package/dist/api/ws-client.js.map +0 -1
  422. package/dist/api/ws-order-client.d.ts.map +0 -1
  423. package/dist/api/ws-order-client.js.map +0 -1
  424. package/dist/bridge/l1-bridge-client.d.ts.map +0 -1
  425. package/dist/bridge/l1-bridge-client.js.map +0 -1
  426. package/dist/index.d.ts.map +0 -1
  427. package/dist/index.js.map +0 -1
  428. package/dist/signer/wasm-manager.d.ts +0 -29
  429. package/dist/signer/wasm-manager.d.ts.map +0 -1
  430. package/dist/signer/wasm-manager.js +0 -104
  431. package/dist/signer/wasm-manager.js.map +0 -1
  432. package/dist/signer/wasm-signer-client.d.ts.map +0 -1
  433. package/dist/signer/wasm-signer-client.js.map +0 -1
  434. package/dist/signer/wasm-signer.d.ts.map +0 -1
  435. package/dist/signer/wasm-signer.js.map +0 -1
  436. package/dist/types/api.d.ts.map +0 -1
  437. package/dist/types/api.js.map +0 -1
  438. package/dist/types/config.d.ts.map +0 -1
  439. package/dist/types/generated/openapi.d.ts.map +0 -1
  440. package/dist/types/generated/openapi.js.map +0 -1
  441. package/dist/types/index.d.ts.map +0 -1
  442. package/dist/types/index.js.map +0 -1
  443. package/dist/types/trading.d.ts.map +0 -1
  444. package/dist/types/trading.js.map +0 -1
  445. package/dist/types/transaction.d.ts.map +0 -1
  446. package/dist/types/transaction.js.map +0 -1
  447. package/dist/utils/configuration.d.ts.map +0 -1
  448. package/dist/utils/configuration.js.map +0 -1
  449. package/dist/utils/exceptions.d.ts.map +0 -1
  450. package/dist/utils/exceptions.js.map +0 -1
  451. package/dist/utils/index.d.ts.map +0 -1
  452. package/dist/utils/index.js.map +0 -1
  453. package/dist/utils/logger.d.ts.map +0 -1
  454. package/dist/utils/logger.js.map +0 -1
  455. package/dist/utils/market-helper.d.ts.map +0 -1
  456. package/dist/utils/market-helper.js.map +0 -1
  457. package/dist/utils/nonce-cache.d.ts.map +0 -1
  458. package/dist/utils/nonce-cache.js.map +0 -1
  459. package/dist/utils/nonce-manager.d.ts.map +0 -1
  460. package/dist/utils/nonce-manager.js.map +0 -1
  461. package/dist/utils/order-status-checker.d.ts.map +0 -1
  462. package/dist/utils/order-status-checker.js.map +0 -1
  463. package/dist/utils/price-utils.d.ts.map +0 -1
  464. package/dist/utils/price-utils.js.map +0 -1
  465. package/dist/utils/request-batcher.d.ts.map +0 -1
  466. package/dist/utils/request-batcher.js.map +0 -1
  467. package/examples/ws.ts +0 -50
  468. package/examples/ws_async.ts +0 -112
  469. package/examples/ws_ping_pong.ts +0 -267
  470. package/examples/ws_send_batch_tx.ts +0 -229
  471. package/examples/ws_send_tx.ts +0 -154
  472. /package/dist/{api → cjs/api}/announcement-api.d.ts +0 -0
  473. /package/dist/{api → cjs/api}/announcement-api.js +0 -0
  474. /package/dist/{api → cjs/api}/api-client.d.ts +0 -0
  475. /package/dist/{api → cjs/api}/block-api.d.ts +0 -0
  476. /package/dist/{api → cjs/api}/block-api.js +0 -0
  477. /package/dist/{api → cjs/api}/funding-api.d.ts +0 -0
  478. /package/dist/{api → cjs/api}/funding-api.js +0 -0
  479. /package/dist/{bridge → cjs/bridge}/l1-bridge-client.d.ts +0 -0
  480. /package/dist/{bridge → cjs/bridge}/l1-bridge-client.js +0 -0
  481. /package/dist/{types → cjs/types}/api.js +0 -0
  482. /package/dist/{types → cjs/types}/config.d.ts +0 -0
  483. /package/dist/{types → cjs/types}/config.js +0 -0
  484. /package/dist/{types → cjs/types}/generated/openapi.d.ts +0 -0
  485. /package/dist/{types → cjs/types}/generated/openapi.js +0 -0
  486. /package/dist/{types → cjs/types}/index.d.ts +0 -0
  487. /package/dist/{types → cjs/types}/index.js +0 -0
  488. /package/dist/{types → cjs/types}/trading.d.ts +0 -0
  489. /package/dist/{types → cjs/types}/trading.js +0 -0
  490. /package/dist/{types → cjs/types}/transaction.d.ts +0 -0
  491. /package/dist/{types → cjs/types}/transaction.js +0 -0
  492. /package/dist/{utils → cjs/utils}/configuration.d.ts +0 -0
  493. /package/dist/{utils → cjs/utils}/configuration.js +0 -0
  494. /package/dist/{utils → cjs/utils}/exceptions.d.ts +0 -0
  495. /package/dist/{utils → cjs/utils}/exceptions.js +0 -0
  496. /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
  497. /package/dist/{utils → cjs/utils}/index.js +0 -0
  498. /package/dist/{utils → cjs/utils}/logger.d.ts +0 -0
  499. /package/dist/{utils → cjs/utils}/logger.js +0 -0
  500. /package/dist/{utils → cjs/utils}/market-helper.d.ts +0 -0
  501. /package/dist/{utils → cjs/utils}/market-helper.js +0 -0
  502. /package/dist/{utils → cjs/utils}/nonce-cache.d.ts +0 -0
  503. /package/dist/{utils → cjs/utils}/nonce-cache.js +0 -0
  504. /package/dist/{utils → cjs/utils}/nonce-manager.d.ts +0 -0
  505. /package/dist/{utils → cjs/utils}/nonce-manager.js +0 -0
  506. /package/dist/{utils → cjs/utils}/order-status-checker.d.ts +0 -0
  507. /package/dist/{utils → cjs/utils}/order-status-checker.js +0 -0
  508. /package/dist/{utils → cjs/utils}/price-utils.d.ts +0 -0
  509. /package/dist/{utils → cjs/utils}/price-utils.js +0 -0
  510. /package/dist/{utils → cjs/utils}/request-batcher.d.ts +0 -0
  511. /package/dist/{utils → cjs/utils}/request-batcher.js +0 -0
package/README.md CHANGED
@@ -1,476 +1,743 @@
1
- # Lighter Protocol TypeScript SDK (Unofficial)
2
-
3
- > **⚠️ Disclaimer**: This is an **unofficial** TypeScript SDK for Lighter Protocol, built by the community. It is not officially maintained by the Lighter Protocol team.
4
-
5
- A complete TypeScript SDK for Lighter Protocol - trade perpetual futures with built-in stop-loss and take-profit orders, position management, and comprehensive error handling.
6
-
7
- ## 🔐 Signer Integration
8
-
9
- This SDK uses the **official lighter-go WASM signer** from [elliottech/lighter-go](https://github.com/elliottech/lighter-go) for all cryptographic operations. The WASM signer is automatically compiled from the GitHub repository during the build process.
10
-
11
- **Key Features:**
12
- - ✅ Uses official lighter-go signer (reference implementation)
13
- - ✅ Automatic error recovery and nonce management
14
- - ✅ Support for all transaction types
15
- - ✅ Multiple API key support
16
- - Production-ready and battle-tested
17
-
18
- ## 📦 Installation
19
-
20
- ```bash
21
- npm install lighter-ts-sdk
22
- # or
23
- yarn add lighter-ts-sdk
24
- ```
25
-
26
- ## 🚀 What Does This SDK Do?
27
-
28
- The Lighter TypeScript SDK provides everything you need to:
29
- - **Trade perpetual futures** on Lighter Protocol
30
- - **Create orders** (Market, Limit, TWAP) with automatic SL/TP
31
- - **Manage positions** (open, close, update leverage)
32
- - **Transfer funds** between accounts
33
- - **Monitor transactions** with built-in status tracking
34
- - **Handle errors** automatically with retry logic
35
-
36
- ## 🎯 Getting Started
37
-
38
- ### Step 1: Set Up Your Environment
39
-
40
- Create a `.env` file in your project root:
41
-
42
- ```bash
43
- # Required credentials
44
- API_PRIVATE_KEY=your_private_key_here
45
- ACCOUNT_INDEX=0
46
- API_KEY_INDEX=0
47
- BASE_URL=https://mainnet.zklighter.elliot.ai
48
-
49
- # Optional: for specific examples
50
- MARKET_ID=0
51
- SUB_ACCOUNT_INDEX=1
52
- DEPOSIT_AMOUNT=1
53
- ```
54
-
55
- ### Step 2: Install the SDK
56
-
57
- ```bash
58
- npm install lighter-ts-sdk
59
- ```
60
-
61
- ### Step 3: Your First Trade
62
-
63
- ```typescript
64
- import { SignerClient, OrderType } from 'lighter-ts-sdk';
65
- import dotenv from 'dotenv';
66
-
67
- dotenv.config();
68
-
69
- async function placeOrder() {
70
- // Initialize the client
71
- const signerClient = new SignerClient({
72
- url: process.env.BASE_URL!,
73
- privateKey: process.env.API_PRIVATE_KEY!,
74
- accountIndex: parseInt(process.env.ACCOUNT_INDEX!),
75
- apiKeyIndex: parseInt(process.env.API_KEY_INDEX!)
76
- });
77
-
78
- // Initialize WASM signer (required)
79
- await signerClient.initialize();
80
- await signerClient.ensureWasmClient();
81
-
82
- // Create a market order with SL/TP
83
- const result = await signerClient.createUnifiedOrder({
84
- marketIndex: 0, // ETH market
85
- clientOrderIndex: Date.now(), // Unique ID
86
- baseAmount: 10000, // 0.01 ETH (scaled: 1 ETH = 1,000,000)
87
- isAsk: false, // BUY (true = SELL)
88
- orderType: OrderType.MARKET,
89
-
90
- // Slip page protection
91
- idealPrice: 400000, // Ideal price ($4000)
92
- maxSlippage: 0.001, // Max 0.1% slippage
93
-
94
- // Automatic stop-loss and take-profit
95
- stopLoss: {
96
- triggerPrice: 380000, // Stop loss at $3800
97
- isLimit: false // Market SL
98
- },
99
- takeProfit: {
100
- triggerPrice: 420000, // Take profit at $4200
101
- isLimit: false // Market TP
102
- }
103
- });
104
-
105
- // Check if order succeeded
106
- if (!result.success) {
107
- console.error('❌ Order failed:', result.mainOrder.error);
108
- return;
109
- }
110
-
111
- console.log('✅ Order created!');
112
- console.log('Main order hash:', result.mainOrder.hash);
113
- console.log('SL order hash:', result.stopLoss?.hash);
114
- console.log('TP order hash:', result.takeProfit?.hash);
115
-
116
- // Wait for transaction confirmation
117
- await signerClient.waitForTransaction(result.mainOrder.hash, 30000);
118
-
119
- await signerClient.close();
120
- }
121
-
122
- placeOrder().catch(console.error);
123
- ```
124
-
125
- ## 📚 Core Concepts
126
-
127
- ### Understanding Price Units
128
-
129
- Lighter uses fixed decimal scaling:
130
- - **ETH amounts**: 1 ETH = 1,000,000 units
131
- - **Prices**: $1 = 100 units
132
-
133
- ```typescript
134
- // To buy 0.01 ETH at $4000:
135
- baseAmount: 10000 // 0.01 ETH (10,000 / 1,000,000)
136
- price: 400000 // $4000 (400,000 / 100)
137
- ```
138
-
139
- ### Order Types
140
-
141
- ```typescript
142
- OrderType.MARKET // Executes immediately at market price
143
- OrderType.LIMIT // Executes at your specified price
144
- OrderType.TWAP // Executes gradually over time
145
- ```
146
-
147
- ### Direction (isAsk)
148
-
149
- ```typescript
150
- isAsk: false // BUY - You're buying ETH
151
- isAsk: true // SELL - You're selling ETH
152
- ```
153
-
154
- ### Stop-Loss and Take-Profit
155
-
156
- SL/TP orders are **automatically reduce-only** - they only close positions:
157
-
158
- ```typescript
159
- stopLoss: {
160
- triggerPrice: 380000, // When price hits this, close position
161
- isLimit: false // false = market SL, true = limit SL
162
- },
163
- takeProfit: {
164
- triggerPrice: 420000, // When price hits this, take profit
165
- isLimit: false // false = market TP, true = limit TP
166
- }
167
- ```
168
-
169
- **Important**: SL/TP orders require an existing position. For Market orders, this works immediately. For Limit orders, SL/TP are created in the same batch.
170
-
171
- **Note for TWAP orders**: TWAP orders execute over time, creating positions gradually. SL/TP cannot be created in the same batch as TWAP orders. You should create SL/TP orders separately after the TWAP has started creating positions.
172
-
173
- ## 🔧 Common Operations
174
-
175
- ### Create a Market Order
176
-
177
- ```typescript
178
- const result = await signerClient.createUnifiedOrder({
179
- marketIndex: 0,
180
- clientOrderIndex: Date.now(),
181
- baseAmount: 10000, // Amount (0.01 ETH)
182
- idealPrice: 400000, // Your target price ($4000)
183
- maxSlippage: 0.001, // 0.1% max slippage
184
- isAsk: false, // BUY
185
- orderType: OrderType.MARKET
186
- });
187
-
188
- if (!result.success) {
189
- console.error('Failed:', result.mainOrder.error);
190
- return;
191
- }
192
- ```
193
-
194
- ### Create a Limit Order
195
-
196
- ```typescript
197
- const result = await signerClient.createUnifiedOrder({
198
- marketIndex: 0,
199
- clientOrderIndex: Date.now(),
200
- baseAmount: 10000, // Amount (0.01 ETH)
201
- price: 400000, // Limit price ($4000)
202
- isAsk: false, // BUY
203
- orderType: OrderType.LIMIT,
204
- orderExpiry: Date.now() + (60 * 60 * 1000) // Expires in 1 hour
205
- });
206
-
207
- // Wait for it to fill
208
- if (result.success) {
209
- await signerClient.waitForTransaction(result.mainOrder.hash);
210
- }
211
- ```
212
-
213
- ### Cancel an Order
214
-
215
- ```typescript
216
- const [tx, hash, error] = await signerClient.cancelOrder({
217
- marketIndex: 0,
218
- orderIndex: 12345 // Your order's index
219
- });
220
-
221
- if (error) {
222
- console.error('Cancel failed:', error);
223
- return;
224
- }
225
-
226
- await signerClient.waitForTransaction(hash);
227
- console.log('✅ Order cancelled');
228
- ```
229
-
230
- ### Close a Position
231
-
232
- ```typescript
233
- const [tx, hash, error] = await signerClient.createMarketOrder({
234
- marketIndex: 0,
235
- clientOrderIndex: Date.now(),
236
- baseAmount: 10000, // Position size to close
237
- avgExecutionPrice: 400000,
238
- isAsk: false, // Opposite of position
239
- reduceOnly: true // IMPORTANT: Only closes, doesn't open new
240
- });
241
-
242
- if (error) {
243
- console.error('Close failed:', error);
244
- return;
245
- }
246
-
247
- await signerClient.waitForTransaction(hash);
248
- console.log('✅ Position closed');
249
- ```
250
-
251
- ### Check Order Status
252
-
253
- ```typescript
254
- const status = await signerClient.getTransaction(txHash);
255
- console.log('Status:', status.status); // 0=pending, 1=queued, 2=committed, 3=executed
256
- ```
257
-
258
- ## 🛠️ API Reference
259
-
260
- ### SignerClient Methods
261
-
262
- #### Order Management
263
- ```typescript
264
- // Create a unified order (main order + SL/TP)
265
- createUnifiedOrder(params) -> Promise<UnifiedOrderResult>
266
-
267
- // Create a single order
268
- createOrder(params) -> Promise<[txInfo, txHash, error]>
269
-
270
- // Cancel a specific order
271
- cancelOrder(params) -> Promise<[txInfo, txHash, error]>
272
-
273
- // Cancel all orders
274
- cancelAllOrders(timeInForce, time) -> Promise<[txInfo, txHash, error]>
275
- ```
276
-
277
- #### Position Management
278
- ```typescript
279
- // Close specific position
280
- createMarketOrder({ reduceOnly: true }) -> Promise<[txInfo, txHash, error]>
281
-
282
- // Close all positions
283
- closeAllPositions() -> Promise<[txs[], responses[], errors[]]>
284
- ```
285
-
286
- #### Transaction Monitoring
287
- ```typescript
288
- // Get transaction details
289
- getTransaction(txHash) -> Promise<Transaction>
290
-
291
- // Wait for transaction (with timeout)
292
- waitForTransaction(txHash, maxWaitTime, pollInterval) -> Promise<Transaction>
293
- ```
294
-
295
- ### Order Parameters
296
-
297
- ```typescript
298
- interface UnifiedOrderParams {
299
- marketIndex: number; // Market ID (0 = ETH)
300
- clientOrderIndex: number; // Unique ID (use Date.now())
301
- baseAmount: number; // Amount in units (1 ETH = 1,000,000)
302
- isAsk: boolean; // true = SELL, false = BUY
303
- orderType: OrderType; // MARKET, LIMIT, or TWAP
304
-
305
- // For market orders
306
- idealPrice?: number; // Target price
307
- maxSlippage?: number; // Max slippage (e.g., 0.001 = 0.1%)
308
-
309
- // For limit orders
310
- price?: number; // Limit price
311
-
312
- // Optional SL/TP (automatically reduce-only)
313
- stopLoss?: {
314
- triggerPrice: number;
315
- isLimit?: boolean;
316
- };
317
- takeProfit?: {
318
- triggerPrice: number;
319
- isLimit?: boolean;
320
- };
321
-
322
- // Optional
323
- orderExpiry?: number; // Expiry timestamp (milliseconds)
324
- }
325
- ```
326
-
327
- ## 💡 Tips for Beginners
328
-
329
- ### 1. Always Use Environment Variables
330
-
331
- ```typescript
332
- // DON'T hardcode credentials
333
- const privateKey = '0xabc123...';
334
-
335
- // ✅ DO use environment variables
336
- const privateKey = process.env.API_PRIVATE_KEY;
337
- ```
338
-
339
- ### 2. Handle Errors Properly
340
-
341
- ```typescript
342
- try {
343
- const result = await signerClient.createUnifiedOrder(params);
344
-
345
- if (!result.success) {
346
- console.error('Order failed:', result.mainOrder.error);
347
- return; // Exit early
348
- }
349
-
350
- // Success path
351
- console.log('Order created:', result.mainOrder.hash);
352
- } catch (error) {
353
- console.error('Unexpected error:', error);
354
- }
355
- ```
356
-
357
- ### 3. Check Transaction Status
358
-
359
- ```typescript
360
- // Wait for transaction to be confirmed
361
- try {
362
- await signerClient.waitForTransaction(txHash, 30000, 2000);
363
- console.log('✅ Transaction confirmed');
364
- } catch (error) {
365
- console.error('❌ Transaction failed:', error.message);
366
- }
367
- ```
368
-
369
- ### 4. Close Resources
370
-
371
- ```typescript
372
- try {
373
- // ... use signerClient
374
- } finally {
375
- await signerClient.close(); // Always close when done
376
- }
377
- ```
378
-
379
- ## 📖 Examples
380
-
381
- The `examples/` directory contains working examples for every feature:
382
-
383
- ```bash
384
- # Run examples
385
- npx ts-node examples/create_market_order.ts # Market order with SL/TP
386
- npx ts-node examples/create_limit_order.ts # Limit order with SL/TP
387
- npx ts-node examples/cancel_order.ts # Cancel orders
388
- npx ts-node examples/close_position.ts # Close positions
389
- npx ts-node examples/deposit_to_subaccount.ts # Fund transfers
390
- ```
391
-
392
- ## 🎓 Learning Path
393
-
394
- 1. **Start Here**: `examples/create_market_order.ts` - Simplest order creation
395
- 2. **Next**: `examples/create_limit_order.ts` - Learn about limit orders
396
- 3. **Then**: `examples/cancel_order.ts` - Learn about order management
397
- 4. **Advanced**: `examples/send_tx_batch.ts` - Batch transactions
398
-
399
- ## 🔒 Security
400
-
401
- - ✅ Never commit `.env` files
402
- - Use environment variables for all credentials
403
- - ✅ Test with small amounts first
404
- - ✅ Monitor all transactions
405
- - ✅ Use proper error handling
406
-
407
- ## 🔧 Building from Source
408
-
409
- If you want to build the SDK from source or rebuild the WASM signer:
410
-
411
- ```bash
412
- # Clone the repository
413
- git clone https://github.com/bvvvp009/lighter-ts.git
414
- cd lighter-ts
415
-
416
- # Install dependencies
417
- npm install
418
-
419
- # Build WASM signer from lighter-go GitHub repo
420
- npm run build:wasm
421
-
422
- # Build TypeScript
423
- npm run build
424
- ```
425
-
426
- **Note**: The build script automatically clones/updates the lighter-go repository from GitHub and compiles the WASM signer. No local lighter-go folder is required.
427
-
428
- ## 🔄 Migration from Previous Versions
429
-
430
- If you're upgrading from an older version that used `temp-lighter-go`:
431
-
432
- ### What Changed
433
-
434
- - ✅ **Signer**: Now uses official `lighter-go` from GitHub instead of local `temp-lighter-go`
435
- - **Build Process**: WASM is compiled directly from GitHub repo
436
- - **Functions**: All transaction types now supported via lighter-go
437
- - ✅ **Error Handling**: Improved error recovery and nonce management
438
-
439
- ### Breaking Changes
440
-
441
- **None!** The API remains the same. The only change is internal - the SDK now uses the official lighter-go signer.
442
-
443
- ### Removed Functions
444
-
445
- These functions were never officially supported and have been removed:
446
- - `getPublicKey()` - Use `generateAPIKey()` instead (returns both keys)
447
- - `switchAPIKey()` - Use `createClient()` with different `apiKeyIndex` values instead
448
-
449
- ### Migration Steps
450
-
451
- 1. **Update your code** (if using removed functions):
452
- ```typescript
453
- // Old (removed)
454
- const publicKey = await client.getPublicKey(privateKey);
455
-
456
- // New (use generateAPIKey)
457
- const { privateKey, publicKey } = await client.generateAPIKey();
458
- ```
459
-
460
- 2. **Rebuild WASM** (if building from source):
461
- ```bash
462
- npm run build:wasm
463
- ```
464
-
465
- 3. **Test your integration** - All existing code should work without changes.
466
-
467
- ## 📞 Getting Help
468
-
469
- - Check the examples in `examples/` directory
470
- - Read error messages carefully - they're informative
471
- - Ensure environment variables are set correctly
472
- - Start with `examples/create_market_order.ts`
473
-
474
- ## License
475
-
476
- MIT License - see LICENSE file for details.
1
+ # Lighter Protocol TypeScript SDK
2
+
3
+ A complete TypeScript SDK for Lighter Protocol - trade perpetual futures with built-in stop-loss and take-profit orders, position management, and comprehensive error handling.
4
+
5
+ ## 🔐 Signer Integration
6
+
7
+ This SDK uses a WASM signer for cryptographic operations. The signer is compiled during the build process.
8
+
9
+ **Key Features:**
10
+ - ✅ Uses a WASM signer for transaction signing
11
+ - ✅ Automatic error recovery and nonce management
12
+ - ✅ Support for all transaction types
13
+ - ✅ Multiple API key support
14
+ - ✅ Production-ready and battle-tested
15
+
16
+ ## 📦 Installation
17
+
18
+ ```bash
19
+ npm install lighter-ts-sdk
20
+ # or
21
+ yarn add lighter-ts-sdk
22
+ ```
23
+
24
+ ## 🚀 What Does This SDK Do?
25
+
26
+ The Lighter TypeScript SDK provides everything you need to:
27
+ - **Trade perpetual futures and SPOT Markets** on Lighter Protocol
28
+ - **Create orders** (Market, Limit, TWAP) with automatic SL/TP
29
+ - **Manage positions** (open, close, update leverage)
30
+ - **Transfer funds** between accounts
31
+ - **Monitor transactions** with built-in status tracking
32
+ - **Handle errors** automatically with retry logic
33
+
34
+ ## 🎯 Getting Started
35
+
36
+ ### Step 1: Set Up Your Environment
37
+
38
+ Create a `.env` file in your project root:
39
+
40
+ ```bash
41
+ # Required credentials
42
+ API_PRIVATE_KEY=your_private_key_here
43
+ ACCOUNT_INDEX=0
44
+ API_KEY_INDEX=0
45
+ BASE_URL=https://mainnet.zklighter.elliot.ai
46
+
47
+ # Optional: for specific examples
48
+ MARKET_ID=0
49
+ SUB_ACCOUNT_INDEX=1
50
+ DEPOSIT_AMOUNT=1
51
+ ```
52
+
53
+ ### Step 2: Install the SDK
54
+
55
+ ```bash
56
+ npm install lighter-ts-sdk
57
+ ```
58
+
59
+ ### Step 3: Your First Trade
60
+
61
+ ```typescript
62
+ import { SignerClient, OrderType } from 'lighter-ts-sdk';
63
+ import dotenv from 'dotenv';
64
+
65
+ dotenv.config();
66
+
67
+ async function placeOrder() {
68
+ // Initialize the client
69
+ const signerClient = new SignerClient({
70
+ url: process.env.BASE_URL!,
71
+ privateKey: process.env.API_PRIVATE_KEY!,
72
+ accountIndex: parseInt(process.env.ACCOUNT_INDEX!),
73
+ apiKeyIndex: parseInt(process.env.API_KEY_INDEX!)
74
+ });
75
+
76
+ // Initialize WASM signer (required)
77
+ await signerClient.initialize();
78
+ await signerClient.ensureWasmClient();
79
+
80
+ // Create a market order with SL/TP using OTOCO
81
+ const result = await signerClient.createOtocoOrder({
82
+ mainOrder: {
83
+ marketIndex: 0, // ETH market
84
+ clientOrderIndex: Date.now(), // Unique ID
85
+ baseAmount: 10000, // 0.01 ETH (scaled: 1 ETH = 1,000,000)
86
+ isAsk: false, // BUY (true = SELL)
87
+ orderType: OrderType.MARKET,
88
+
89
+ // Slippage protection
90
+ idealPrice: 400000, // Ideal price ($4000)
91
+ maxSlippage: 0.001 // Max 0.1% slippage
92
+ },
93
+ // Automatic stop-loss
94
+ stopLoss: {
95
+ triggerPrice: 380000, // Stop loss at $3800
96
+ isLimit: false // Market SL
97
+ },
98
+ // Automatic take-profit
99
+ takeProfit: {
100
+ triggerPrice: 420000, // Take profit at $4200
101
+ isLimit: false // Market TP
102
+ }
103
+ });
104
+
105
+ // Check if order succeeded
106
+ if (result.error || !result.hash) {
107
+ console.error('❌ Order failed:', result.error);
108
+ return;
109
+ }
110
+
111
+ console.log('✅ OTOCO order created!');
112
+ console.log('Grouped order hash:', result.hash);
113
+
114
+ // Wait for transaction confirmation
115
+ await signerClient.waitForTransaction(result.hash, 30000);
116
+
117
+ await signerClient.close();
118
+ }
119
+
120
+ placeOrder().catch(console.error);
121
+ ```
122
+
123
+ ## 📚 Core Concepts
124
+
125
+ ### Understanding Price Units
126
+
127
+ Lighter uses fixed decimal scaling:
128
+ - **ETH amounts**: 1 ETH = 1,000,000 units
129
+ - **Prices**: $1 = 100 units
130
+
131
+ ```typescript
132
+ // To buy 0.01 ETH at $4000:
133
+ baseAmount: 10000 // 0.01 ETH (10,000 / 1,000,000)
134
+ price: 400000 // $4000 (400,000 / 100)
135
+ ```
136
+
137
+ ### Order Types
138
+
139
+ ```typescript
140
+ OrderType.MARKET // Executes immediately at market price
141
+ OrderType.LIMIT // Executes at your specified price
142
+ OrderType.TWAP // Executes gradually over time
143
+ ```
144
+
145
+ ### Direction (isAsk)
146
+
147
+ ```typescript
148
+ isAsk: false // BUY - You're buying ETH
149
+ isAsk: true // SELL - You're selling ETH
150
+ ```
151
+
152
+ ### Stop-Loss and Take-Profit
153
+
154
+ SL/TP orders are **automatically reduce-only** - they only close positions:
155
+
156
+ ```typescript
157
+ stopLoss: {
158
+ triggerPrice: 380000, // When price hits this, close position
159
+ isLimit: false // false = market SL, true = limit SL
160
+ },
161
+ takeProfit: {
162
+ triggerPrice: 420000, // When price hits this, take profit
163
+ isLimit: false // false = market TP, true = limit TP
164
+ }
165
+ ```
166
+
167
+ **Important**: SL/TP orders require an existing position. For Market orders, this works immediately. For Limit orders, SL/TP are created in the same batch.
168
+
169
+ **Note for TWAP orders**: TWAP orders execute over time, creating positions gradually. SL/TP cannot be created in the same batch as TWAP orders. You should create SL/TP orders separately after the TWAP has started creating positions.
170
+
171
+ ## 🌐 Network-Aware Transaction Status Monitoring
172
+
173
+ Lighter Protocol transactions go through multiple network states. Use `waitForTransaction()` to monitor status changes with automatic error handling and recovery:
174
+
175
+ ```typescript
176
+ // Transaction status constants
177
+ enum TransactionStatus {
178
+ PENDING = 0, // Initial state, not yet queued
179
+ QUEUED = 1, // Queued for processing
180
+ COMMITTED = 2, // Committed to block
181
+ EXECUTED = 3, // Successfully executed
182
+ FAILED = 4, // Execution failed
183
+ REJECTED = 5 // Transaction rejected
184
+ }
185
+
186
+ // Monitor transaction with built-in retry logic
187
+ try {
188
+ const txResult = await signerClient.waitForTransaction(
189
+ txHash,
190
+ 30000, // maxWaitTime: wait up to 30 seconds
191
+ 2000 // pollInterval: check status every 2 seconds
192
+ );
193
+
194
+ console.log('Status:', txResult.status); // Will be EXECUTED (3) if successful
195
+ console.log('✅ Transaction confirmed on-chain');
196
+ } catch (error) {
197
+ // Error handling is centralized here
198
+ if (error.message.includes('timeout')) {
199
+ console.error('❌ Transaction didn\'t confirm within timeout');
200
+ } else if (error.message.includes('FAILED') || error.message.includes('REJECTED')) {
201
+ console.error('❌ Transaction failed:', error.message);
202
+ } else {
203
+ console.error('❌ Unexpected error:', error.message);
204
+ }
205
+ }
206
+
207
+ // Advanced: Manual status polling for fine-grained control
208
+ const checkStatus = async (hash: string) => {
209
+ const txResult = await signerClient.getTransaction(hash);
210
+
211
+ switch (txResult.status) {
212
+ case SignerClient.TX_STATUS_PENDING:
213
+ console.log('⏳ Still pending...');
214
+ break;
215
+ case SignerClient.TX_STATUS_QUEUED:
216
+ console.log('📋 Queued for processing');
217
+ break;
218
+ case SignerClient.TX_STATUS_COMMITTED:
219
+ console.log('✍️ Committed to block');
220
+ break;
221
+ case SignerClient.TX_STATUS_EXECUTED:
222
+ console.log(' Transaction executed successfully');
223
+ break;
224
+ case SignerClient.TX_STATUS_FAILED:
225
+ console.error('❌ Transaction execution failed');
226
+ break;
227
+ case SignerClient.TX_STATUS_REJECTED:
228
+ console.error('❌ Transaction was rejected');
229
+ break;
230
+ }
231
+
232
+ return txResult;
233
+ };
234
+
235
+ // Pattern: Fire-and-forget with error handling
236
+ const result = await signerClient.createOrder(orderParams);
237
+ if (result.hash) {
238
+ // Schedule async confirmation check (don't block)
239
+ signerClient.waitForTransaction(result.hash, 60000).catch(err => {
240
+ console.error('Transaction confirmation failed:', err);
241
+ // Handle error (alert user, retry, etc.)
242
+ });
243
+ }
244
+ ```
245
+
246
+ **Key Points:**
247
+ - `waitForTransaction()` centralizes error handling and automatic retries
248
+ - No need to parse transaction status manually after wait
249
+ - Throw errors are detected and propagated with context
250
+ - Use timeout to prevent indefinite waits in production systems
251
+
252
+ ## 💰 Margin Management with Direction Constants
253
+
254
+ Lighter Protocol supports both cross-margin and isolated-margin modes. Margin direction constants determine whether you're adding or removing collateral:
255
+
256
+ ### Margin Mode Constants
257
+
258
+ ```typescript
259
+ // Margin mode
260
+ SignerClient.CROSS_MARGIN_MODE = 0 // Shared collateral across markets
261
+ SignerClient.ISOLATED_MARGIN_MODE = 1 // Per-market collateral
262
+
263
+ // Margin direction (when updating isolated margin)
264
+ SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL = 0 // Remove collateral from position
265
+ SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL = 1 // Add collateral to position
266
+ ```
267
+
268
+ ### Adding Margin (Collateral) to Isolated Position
269
+
270
+ ```typescript
271
+ // Add 100 USDC collateral to ETH position in isolated mode
272
+ const [marginInfo, txHash, error] = await signerClient.updateMargin(
273
+ 0, // marketIndex: 0 = ETH/USDC
274
+ 100, // usdcAmount: 100 USDC to add
275
+ SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL // direction: 1
276
+ );
277
+
278
+ if (error) {
279
+ console.error('Failed to add margin:', error);
280
+ } else {
281
+ console.log('✅ Margin added:', txHash);
282
+
283
+ // Wait for confirmation
284
+ await signerClient.waitForTransaction(txHash, 30000);
285
+ console.log('✅ Margin update confirmed');
286
+ }
287
+ ```
288
+
289
+ ### Removing Margin (Collateral) from Isolated Position
290
+
291
+ ```typescript
292
+ // Remove 50 USDC collateral from ETH position
293
+ const [marginInfo, txHash, error] = await signerClient.updateMargin(
294
+ 0, // marketIndex: 0 = ETH/USDC
295
+ 50, // usdcAmount: 50 USDC to remove
296
+ SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL // direction: 0
297
+ );
298
+
299
+ if (error) {
300
+ console.error('Failed to remove margin:', error);
301
+ } else {
302
+ console.log('✅ Margin removed:', txHash);
303
+
304
+ // Wait for confirmation
305
+ await signerClient.waitForTransaction(txHash, 30000);
306
+ console.log('✅ Margin removal confirmed');
307
+ }
308
+ ```
309
+
310
+ ### Cross-Margin vs Isolated-Margin Workflows
311
+
312
+ ```typescript
313
+ // === CROSS-MARGIN MODE ===
314
+ // Step 1: Update leverage to cross-margin
315
+ const [crossInfo1, crossHash1, crossErr1] = await signerClient.updateLeverage(
316
+ 0, // marketIndex
317
+ SignerClient.CROSS_MARGIN_MODE, // mode: 0
318
+ 5 // leverage: 5x
319
+ );
320
+
321
+ // Step 2: Create order (no margin updates needed - uses account balance)
322
+ const result = await signerClient.createMarketOrder({
323
+ marketIndex: 0,
324
+ baseAmount: 10000,
325
+ isAsk: false
326
+ });
327
+
328
+ // === ISOLATED-MARGIN MODE ===
329
+ // Step 1: Update leverage to isolated-margin
330
+ const [isolatedInfo1, isolatedHash1, isolatedErr1] = await signerClient.updateLeverage(
331
+ 0, // marketIndex
332
+ SignerClient.ISOLATED_MARGIN_MODE, // mode: 1
333
+ 20 // leverage: 20x (IMF = 10000/20 = 500)
334
+ );
335
+
336
+ // Step 2: Create order
337
+ const result = await signerClient.createMarketOrder({
338
+ marketIndex: 0,
339
+ baseAmount: 10000,
340
+ isAsk: false
341
+ });
342
+
343
+ // Step 3: Manage collateral dynamically
344
+ // Add more collateral if position grows risky
345
+ await signerClient.updateMargin(
346
+ 0,
347
+ 200, // Add 200 USDC
348
+ SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL
349
+ );
350
+
351
+ // Remove collateral if position has buffer
352
+ await signerClient.updateMargin(
353
+ 0,
354
+ 100, // Remove 100 USDC
355
+ SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL
356
+ );
357
+ ```
358
+
359
+ **Important:**
360
+ - Cross-margin pools collateral across all markets
361
+ - Isolated margin requires explicit collateral management per-market
362
+ - `direction` parameter is only used for isolated-margin positions
363
+ - Always verify sufficient collateral before removing it
364
+
365
+ ## �🔧 Common Operations
366
+
367
+ ### Create a Market Order
368
+
369
+ ```typescript
370
+ const [tx, hash, error] = await signerClient.createMarketOrder({
371
+ marketIndex: 0,
372
+ clientOrderIndex: Date.now(),
373
+ baseAmount: 10000, // Amount (0.01 ETH)
374
+ avgExecutionPrice: 400000, // Max execution price ($4000)
375
+ isAsk: false // BUY
376
+ });
377
+
378
+ if (error || !hash) {
379
+ console.error('Failed:', error);
380
+ return;
381
+ }
382
+ ```
383
+
384
+ ### Create a Limit Order
385
+
386
+ ```typescript
387
+ const [tx, hash, error] = await signerClient.createOrder({
388
+ marketIndex: 0,
389
+ clientOrderIndex: Date.now(),
390
+ baseAmount: 10000, // Amount (0.01 ETH)
391
+ price: 400000, // Limit price ($4000)
392
+ isAsk: false, // BUY
393
+ orderType: OrderType.LIMIT,
394
+ orderExpiry: Date.now() + (60 * 60 * 1000) // Expires in 1 hour
395
+ });
396
+
397
+ if (error || !hash) {
398
+ console.error('Failed:', error);
399
+ return;
400
+ }
401
+
402
+ // Wait for it to fill
403
+ await signerClient.waitForTransaction(hash);
404
+ ```
405
+
406
+ ### Cancel an Order
407
+
408
+ ```typescript
409
+ const [tx, hash, error] = await signerClient.cancelOrder({
410
+ marketIndex: 0,
411
+ orderIndex: 12345 // Your order's index
412
+ });
413
+
414
+ if (error) {
415
+ console.error('Cancel failed:', error);
416
+ return;
417
+ }
418
+
419
+ await signerClient.waitForTransaction(hash);
420
+ console.log('✅ Order cancelled');
421
+ ```
422
+
423
+ ### Close a Position
424
+
425
+ ```typescript
426
+ const [tx, hash, error] = await signerClient.createMarketOrder({
427
+ marketIndex: 0,
428
+ clientOrderIndex: Date.now(),
429
+ baseAmount: 10000, // Position size to close
430
+ avgExecutionPrice: 400000,
431
+ isAsk: false, // Opposite of position
432
+ reduceOnly: true // IMPORTANT: Only closes, doesn't open new
433
+ });
434
+
435
+ if (error) {
436
+ console.error('Close failed:', error);
437
+ return;
438
+ }
439
+
440
+ await signerClient.waitForTransaction(hash);
441
+ console.log('✅ Position closed');
442
+ ```
443
+
444
+ ### Check Order Status
445
+
446
+ ```typescript
447
+ const status = await signerClient.getTransaction(txHash);
448
+ console.log('Status:', status.status); // 0=pending, 1=queued, 2=committed, 3=executed
449
+ ```
450
+
451
+ ## 🛠️ API Reference
452
+
453
+ ### SignerClient Methods
454
+
455
+ #### Order Management
456
+ ```typescript
457
+ // Create an OTOCO order (entry + SL + TP)
458
+ createOtocoOrder(params) -> Promise<{ tx, hash, error }>
459
+
460
+ // Create an OCO order (one cancels other)
461
+ createOcoOrder(params) -> Promise<{ tx, hash, error }>
462
+
463
+ // Create a single order
464
+ createOrder(params) -> Promise<[txInfo, txHash, error]>
465
+
466
+ // Cancel a specific order
467
+ cancelOrder(params) -> Promise<[txInfo, txHash, error]>
468
+
469
+ // Cancel all orders
470
+ cancelAllOrders(timeInForce, time) -> Promise<[txInfo, txHash, error]>
471
+ ```
472
+
473
+ #### Position Management
474
+ ```typescript
475
+ // Close specific position
476
+ createMarketOrder({ reduceOnly: true }) -> Promise<[txInfo, txHash, error]>
477
+
478
+ // Close all positions
479
+ closeAllPositions() -> Promise<[txs[], responses[], errors[]]>
480
+ ```
481
+
482
+ #### Transaction Monitoring
483
+ ```typescript
484
+ // Get transaction details
485
+ getTransaction(txHash) -> Promise<Transaction>
486
+
487
+ // Wait for transaction (with timeout)
488
+ waitForTransaction(txHash, maxWaitTime, pollInterval) -> Promise<Transaction>
489
+ ```
490
+
491
+ ### Order Parameters
492
+
493
+ ```typescript
494
+ // For OTOCO orders (entry + SL/TP)
495
+ interface OtocoOrderParams {
496
+ mainOrder: {
497
+ marketIndex: number; // Market ID (0 = ETH)
498
+ baseAmount: number; // Amount in units
499
+ isAsk: boolean; // true = SELL, false = BUY
500
+ orderType: OrderType.LIMIT | OrderType.MARKET;
501
+ price?: number; // For LIMIT orders
502
+ avgExecutionPrice?: number; // For MARKET orders
503
+ maxSlippage?: number; // Max slippage (0.001 = 0.1%)
504
+ idealPrice?: number; // Target price
505
+ };
506
+ stopLoss: {
507
+ triggerPrice: number;
508
+ price?: number;
509
+ isLimit?: boolean;
510
+ };
511
+ takeProfit: {
512
+ triggerPrice: number;
513
+ price?: number;
514
+ isLimit?: boolean;
515
+ };
516
+ nonce?: number;
517
+ }
518
+
519
+ // For single orders
520
+ interface CreateOrderParams {
521
+ marketIndex: number;
522
+ clientOrderIndex: number;
523
+ baseAmount: number;
524
+ price: number;
525
+ isAsk: boolean;
526
+ orderType?: OrderType;
527
+ timeInForce?: TimeInForce;
528
+ reduceOnly?: boolean;
529
+ orderExpiry?: number;
530
+ }
531
+ ```
532
+
533
+ ## 💡 Tips for Beginners
534
+
535
+ ### 1. Always Use Environment Variables
536
+
537
+ ```typescript
538
+ // ❌ DON'T hardcode credentials
539
+ const privateKey = '0xabc123...';
540
+
541
+ // ✅ DO use environment variables
542
+ const privateKey = process.env.API_PRIVATE_KEY;
543
+ ```
544
+
545
+ ### 2. Handle Errors Properly
546
+
547
+ ```typescript
548
+ try {
549
+ const [tx, hash, error] = await signerClient.createOrder(params);
550
+
551
+ if (error || !hash) {
552
+ console.error('Order failed:', error);
553
+ return; // Exit early
554
+ }
555
+
556
+ // Success path
557
+ console.log('Order created:', hash);
558
+ } catch (error) {
559
+ console.error('Unexpected error:', error);
560
+ }
561
+ ```
562
+
563
+ ### 3. Check Transaction Status
564
+
565
+ ```typescript
566
+ // Wait for transaction to be confirmed
567
+ try {
568
+ await signerClient.waitForTransaction(txHash, 30000, 2000);
569
+ console.log('✅ Transaction confirmed');
570
+ } catch (error) {
571
+ console.error('❌ Transaction failed:', error.message);
572
+ }
573
+ ```
574
+
575
+ ### 4. Close Resources
576
+
577
+ ```typescript
578
+ try {
579
+ // ... use signerClient
580
+ } finally {
581
+ await signerClient.close(); // Always close when done
582
+ }
583
+ ```
584
+
585
+ ## 📖 Examples
586
+
587
+ The `examples/` directory contains working examples for every feature:
588
+
589
+ ```bash
590
+ # Run examples
591
+ npx tsx examples/create_market_order.ts # Market order with SL/TP
592
+ npx tsx examples/create_limit_order.ts # Limit order with SL/TP
593
+ npx tsx examples/cancel_order.ts # Cancel orders
594
+ npx tsx examples/close_position.ts # Close positions
595
+ npx tsx examples/deposit_to_subaccount.ts # Fund transfers
596
+ ```
597
+
598
+ ## 🎓 Learning Path
599
+
600
+ 1. **Start Here**: `examples/create_market_order.ts` - Simplest order creation
601
+ 2. **Next**: `examples/create_limit_order.ts` - Learn about limit orders
602
+ 3. **Then**: `examples/cancel_order.ts` - Learn about order management
603
+ 4. **Advanced**: `examples/send_tx_batch.ts` - Batch transactions
604
+
605
+ ## ✅ Live Executed Transactions (Testnet)
606
+
607
+ The SDK has been thoroughly tested with real transactions on Lighter Protocol testnet. Here are verified transaction hashes from live example execution:
608
+
609
+ ### Real Transaction Examples
610
+
611
+ **1. Market Order with OTOCO (SL/TP)**
612
+ ```
613
+ Transaction Hash: c622140d6d15760bbf5462e3f472a97b0eac8fb138becc00cb7ce24b223c19e352fe7e15098337c5
614
+ Example: examples/create_market_order.ts
615
+ Details: 60 ETH order with $2800 SL / $3100 TP
616
+ Status: ✅ Submitted to testnet
617
+ ```
618
+
619
+ **2. Limit Order with Grouping**
620
+ ```
621
+ Transaction Hash: 4349b469fa8d71161fc012a9d3224e1f4eda355527e91e83bb193ab9345bc19bfba22d7ab64721d1
622
+ Example: examples/create_limit_order.ts
623
+ Details: Limit entry with automatic SL/TP attachment
624
+ Status: ✅ Submitted to testnet
625
+ ```
626
+
627
+ **3. Market Order with Max Slippage (1%)**
628
+ ```
629
+ Transaction Hash: f1d2ab2ca65f77310502298961c6e738e21a2b9f2e8e4614a75d2bbf5a4168d225bec7708675cdca
630
+ Example: examples/create_market_order_max_slippage.ts
631
+ Details: Market order with 1% slippage protection
632
+ Status: ✅ Submitted to testnet
633
+ ```
634
+
635
+ **4. IOC Order with Attached SL/TP**
636
+ ```
637
+ Transaction Hash: 1d64b0bab34e2469a190558e53d13c8614ebd5075d4ed2eca079aab551a259b92343ad1c5d1fbed8
638
+ Example: examples/create_grouped_ioc_with_attached_sl_tp.ts
639
+ Details: Immediate-or-cancel with grouped exits
640
+ Status: ✅ Submitted to testnet
641
+ ```
642
+
643
+ ### Running Your Own Transactions
644
+
645
+ To execute transactions yourself:
646
+
647
+ ```typescript
648
+ // All credentials loaded from .env
649
+ const signerClient = new SignerClient({
650
+ url: process.env.BASE_URL!,
651
+ privateKey: process.env.API_PRIVATE_KEY!,
652
+ accountIndex: parseInt(process.env.ACCOUNT_INDEX!),
653
+ apiKeyIndex: parseInt(process.env.API_KEY_INDEX!)
654
+ });
655
+
656
+ await signerClient.initialize();
657
+ await signerClient.ensureWasmClient();
658
+
659
+ // Create your order (any example will generate a real hash)
660
+ const result = await signerClient.createMarketOrder({...});
661
+ console.log('Your transaction hash:', result.hash);
662
+ ```
663
+
664
+ All example files in `examples/` directory will generate valid transaction hashes when run with proper credentials.
665
+
666
+ ## 🔒 Security
667
+
668
+ - ✅ Never commit `.env` files
669
+ - ✅ Use environment variables for all credentials
670
+ - ✅ Test with small amounts first
671
+ - ✅ Monitor all transactions
672
+ - ✅ Use proper error handling
673
+
674
+ ## 🔧 Building from Source
675
+
676
+ If you want to build the SDK from source or rebuild the WASM signer:
677
+
678
+ ```bash
679
+ # Clone the repository
680
+ git clone https://github.com/bvvvp009/lighter-ts.git
681
+ cd lighter-ts
682
+
683
+ # Install dependencies
684
+ npm install
685
+
686
+ # Build WASM signer assets
687
+ npm run build:wasm
688
+
689
+ # Build TypeScript
690
+ npm run build
691
+ ```
692
+
693
+ **Note**: The build script automatically prepares and compiles WASM signer assets. No extra local signer repository is required.
694
+
695
+ ## 🔄 Migration from Previous Versions
696
+
697
+ If you're upgrading from an older version that used `temp-lighter-go`:
698
+
699
+ ### What Changed
700
+
701
+ - ✅ **Signer**: Uses the current WASM signer workflow instead of local `temp-lighter-go`
702
+ - ✅ **Build Process**: WASM is compiled directly from GitHub repo
703
+ - ✅ **Functions**: All transaction types are supported by the WASM signer flow
704
+ - ✅ **Error Handling**: Improved error recovery and nonce management
705
+
706
+ ### Breaking Changes
707
+
708
+ **None!** The API remains the same. The change is internal to signer implementation.
709
+
710
+ ### Removed Functions
711
+
712
+ These functions are no longer supported and have been removed:
713
+ - `getPublicKey()` - Use `generateAPIKey()` instead (returns both keys)
714
+ - `switchAPIKey()` - Use `createClient()` with different `apiKeyIndex` values instead
715
+
716
+ ### Migration Steps
717
+
718
+ 1. **Update your code** (if using removed functions):
719
+ ```typescript
720
+ // Old (removed)
721
+ const publicKey = await client.getPublicKey(privateKey);
722
+
723
+ // New (use generateAPIKey)
724
+ const { privateKey, publicKey } = await client.generateAPIKey();
725
+ ```
726
+
727
+ 2. **Rebuild WASM** (if building from source):
728
+ ```bash
729
+ npm run build:wasm
730
+ ```
731
+
732
+ 3. **Test your integration** - All existing code should work without changes.
733
+
734
+ ## 📞 Getting Help
735
+
736
+ - Check the examples in `examples/` directory
737
+ - Read error messages carefully - they're informative
738
+ - Ensure environment variables are set correctly
739
+ - Start with `examples/create_market_order.ts`
740
+
741
+ ## License
742
+
743
+ MIT License - see LICENSE file for details.