lighter-ts-sdk 1.0.5 → 1.0.7
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.
- package/README.md +476 -487
- package/dist/api/account-api.d.ts +24 -2
- package/dist/api/account-api.d.ts.map +1 -1
- package/dist/api/account-api.js +11 -0
- package/dist/api/account-api.js.map +1 -1
- package/dist/api/announcement-api.d.ts +27 -0
- package/dist/api/announcement-api.d.ts.map +1 -0
- package/dist/api/announcement-api.js +25 -0
- package/dist/api/announcement-api.js.map +1 -0
- package/dist/api/api-client.d.ts.map +1 -1
- package/dist/api/api-client.js +15 -0
- package/dist/api/api-client.js.map +1 -1
- package/dist/api/bridge-api.d.ts +78 -0
- package/dist/api/bridge-api.d.ts.map +1 -0
- package/dist/api/bridge-api.js +137 -0
- package/dist/api/bridge-api.js.map +1 -0
- package/dist/api/funding-api.d.ts +28 -0
- package/dist/api/funding-api.d.ts.map +1 -0
- package/dist/api/funding-api.js +25 -0
- package/dist/api/funding-api.js.map +1 -0
- package/dist/api/notification-api.d.ts +27 -0
- package/dist/api/notification-api.d.ts.map +1 -0
- package/dist/api/notification-api.js +49 -0
- package/dist/api/notification-api.js.map +1 -0
- package/dist/api/order-api.d.ts +97 -14
- package/dist/api/order-api.d.ts.map +1 -1
- package/dist/api/order-api.js +15 -9
- package/dist/api/order-api.js.map +1 -1
- package/dist/api/referral-api.d.ts +37 -0
- package/dist/api/referral-api.d.ts.map +1 -0
- package/dist/api/referral-api.js +45 -0
- package/dist/api/referral-api.js.map +1 -0
- package/dist/api/transaction-api.d.ts +49 -6
- package/dist/api/transaction-api.d.ts.map +1 -1
- package/dist/api/transaction-api.js +58 -10
- package/dist/api/transaction-api.js.map +1 -1
- package/dist/api/ws-client.d.ts.map +1 -1
- package/dist/api/ws-client.js +7 -9
- package/dist/api/ws-client.js.map +1 -1
- package/dist/api/ws-order-client.d.ts +8 -2
- package/dist/api/ws-order-client.d.ts.map +1 -1
- package/dist/api/ws-order-client.js +249 -62
- package/dist/api/ws-order-client.js.map +1 -1
- package/dist/bridge/l1-bridge-client.d.ts +49 -0
- package/dist/bridge/l1-bridge-client.d.ts.map +1 -0
- package/dist/bridge/l1-bridge-client.js +187 -0
- package/dist/bridge/l1-bridge-client.js.map +1 -0
- package/dist/index.d.ts +27 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -18
- package/dist/index.js.map +1 -1
- package/dist/{utils → signer}/wasm-manager.d.ts +1 -2
- package/dist/signer/wasm-manager.d.ts.map +1 -0
- package/dist/{utils → signer}/wasm-manager.js +1 -2
- package/dist/signer/wasm-manager.js.map +1 -0
- package/dist/signer/wasm-signer-client.d.ts +328 -36
- package/dist/signer/wasm-signer-client.d.ts.map +1 -1
- package/dist/signer/wasm-signer-client.js +1713 -367
- package/dist/signer/wasm-signer-client.js.map +1 -1
- package/dist/signer/wasm-signer.d.ts +361 -0
- package/dist/signer/wasm-signer.d.ts.map +1 -0
- package/dist/signer/wasm-signer.js +814 -0
- package/dist/signer/wasm-signer.js.map +1 -0
- package/dist/types/api.d.ts +181 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +7 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/config.d.ts +66 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +7 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/generated/openapi.d.ts +5008 -0
- package/dist/types/generated/openapi.d.ts.map +1 -0
- package/dist/types/generated/openapi.js +7 -0
- package/dist/types/generated/openapi.js.map +1 -0
- package/dist/types/index.d.ts +31 -129
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/trading.d.ts +43 -0
- package/dist/types/trading.d.ts.map +1 -0
- package/dist/types/trading.js +25 -0
- package/dist/types/trading.js.map +1 -0
- package/dist/types/transaction.d.ts +57 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/transaction.js +29 -0
- package/dist/types/transaction.js.map +1 -0
- package/dist/utils/exceptions.js +1 -1
- package/dist/utils/exceptions.js.map +1 -1
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +38 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.js +3 -3
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/market-helper.d.ts +62 -0
- package/dist/utils/market-helper.d.ts.map +1 -0
- package/dist/utils/market-helper.js +100 -0
- package/dist/utils/market-helper.js.map +1 -0
- package/dist/utils/nonce-cache.d.ts +9 -1
- package/dist/utils/nonce-cache.d.ts.map +1 -1
- package/dist/utils/nonce-cache.js +28 -1
- package/dist/utils/nonce-cache.js.map +1 -1
- package/dist/utils/nonce-manager.d.ts +79 -0
- package/dist/utils/nonce-manager.d.ts.map +1 -0
- package/dist/utils/nonce-manager.js +130 -0
- package/dist/utils/nonce-manager.js.map +1 -0
- package/dist/utils/order-status-checker.d.ts +29 -0
- package/dist/utils/order-status-checker.d.ts.map +1 -0
- package/dist/utils/order-status-checker.js +101 -0
- package/dist/utils/order-status-checker.js.map +1 -0
- package/dist/utils/price-utils.d.ts +86 -0
- package/dist/utils/price-utils.d.ts.map +1 -0
- package/dist/utils/price-utils.js +229 -0
- package/dist/utils/price-utils.js.map +1 -0
- package/dist/utils/request-batcher.d.ts.map +1 -1
- package/dist/utils/request-batcher.js +4 -7
- package/dist/utils/request-batcher.js.map +1 -1
- package/docs/API.md +207 -195
- package/docs/AccountApi.md +278 -220
- package/docs/GettingStarted.md +361 -262
- package/docs/MarketHelper.md +214 -0
- package/docs/MigrationGuide.md +401 -0
- package/docs/OrderApi.md +353 -199
- package/docs/SignerClient.md +626 -326
- package/docs/TransactionApi.md +474 -312
- package/docs/Utilities.md +268 -0
- package/docs/WsClient.md +219 -164
- package/docs/types/SignerConfig.md +40 -40
- package/docs/types/WasmSignerConfig.md +9 -8
- package/examples/README.md +202 -216
- package/examples/cancel_all_orders.ts +112 -79
- package/examples/cancel_order.ts +44 -124
- package/examples/change_account_tier.ts +82 -0
- package/examples/close_all_positions.ts +378 -43
- package/examples/close_position.ts +164 -164
- package/examples/create_auth_token.ts +57 -121
- package/examples/create_limit_order.ts +178 -67
- package/examples/create_market_order.ts +159 -48
- package/examples/create_subaccount.ts +78 -0
- package/examples/create_twap_order.ts +101 -0
- package/examples/create_with_multiple_keys.ts +101 -76
- package/examples/deposit_to_subaccount.ts +104 -0
- package/examples/market_data.ts +174 -0
- package/examples/modify_order.ts +250 -0
- package/examples/multi_client_advanced.ts +251 -0
- package/examples/public_pool_operations.ts +150 -0
- package/examples/send_tx_batch.ts +92 -67
- package/examples/spot/README.md +85 -0
- package/examples/spot/cancel_spot_order.ts +89 -0
- package/examples/spot/create_market_spot_orders.ts +259 -0
- package/examples/spot/create_spot_limit_order.ts +122 -0
- package/examples/spot/create_spot_twap_order.ts +102 -0
- package/examples/system_setup.ts +168 -159
- package/examples/update_margin.ts +99 -0
- package/examples/update_margin_leverage.ts +110 -0
- package/examples/withdraw_to_l1.ts +68 -0
- package/examples/ws.ts +67 -64
- package/examples/ws_async.ts +107 -40
- package/examples/ws_ping_pong.ts +260 -0
- package/examples/ws_send_batch_tx.ts +211 -94
- package/examples/ws_send_tx.ts +137 -76
- package/package.json +1 -1
- package/wasm/lighter-signer.wasm +0 -0
- package/dist/signer/signer-client.d.ts +0 -79
- package/dist/signer/signer-client.d.ts.map +0 -1
- package/dist/signer/signer-client.js +0 -212
- package/dist/signer/signer-client.js.map +0 -1
- package/dist/utils/advanced-cache.d.ts +0 -66
- package/dist/utils/advanced-cache.d.ts.map +0 -1
- package/dist/utils/advanced-cache.js +0 -199
- package/dist/utils/advanced-cache.js.map +0 -1
- package/dist/utils/api-key-utils.d.ts +0 -7
- package/dist/utils/api-key-utils.d.ts.map +0 -1
- package/dist/utils/api-key-utils.js +0 -31
- package/dist/utils/api-key-utils.js.map +0 -1
- package/dist/utils/memory-pool.d.ts +0 -98
- package/dist/utils/memory-pool.d.ts.map +0 -1
- package/dist/utils/memory-pool.js +0 -190
- package/dist/utils/memory-pool.js.map +0 -1
- package/dist/utils/node-wasm-signer.d.ts +0 -163
- package/dist/utils/node-wasm-signer.d.ts.map +0 -1
- package/dist/utils/node-wasm-signer.js +0 -409
- package/dist/utils/node-wasm-signer.js.map +0 -1
- package/dist/utils/optimized-http-client.d.ts +0 -29
- package/dist/utils/optimized-http-client.d.ts.map +0 -1
- package/dist/utils/optimized-http-client.js +0 -142
- package/dist/utils/optimized-http-client.js.map +0 -1
- package/dist/utils/performance-monitor.d.ts +0 -41
- package/dist/utils/performance-monitor.d.ts.map +0 -1
- package/dist/utils/performance-monitor.js +0 -168
- package/dist/utils/performance-monitor.js.map +0 -1
- package/dist/utils/signer-server.d.ts +0 -18
- package/dist/utils/signer-server.d.ts.map +0 -1
- package/dist/utils/signer-server.js +0 -78
- package/dist/utils/signer-server.js.map +0 -1
- package/dist/utils/transaction-helper.d.ts +0 -37
- package/dist/utils/transaction-helper.d.ts.map +0 -1
- package/dist/utils/transaction-helper.js +0 -174
- package/dist/utils/transaction-helper.js.map +0 -1
- package/dist/utils/wasm-manager.d.ts.map +0 -1
- package/dist/utils/wasm-manager.js.map +0 -1
- package/dist/utils/wasm-signer.d.ts +0 -158
- package/dist/utils/wasm-signer.d.ts.map +0 -1
- package/dist/utils/wasm-signer.js +0 -214
- package/dist/utils/wasm-signer.js.map +0 -1
- package/examples/account_info.ts +0 -15
- package/examples/check_transaction_status.ts +0 -159
- package/examples/create_cancel_order.ts +0 -113
- package/examples/create_market_order_if_slippage.ts +0 -68
- package/examples/create_market_order_max_slippage.ts +0 -42
- package/examples/create_sl_tp.ts +0 -165
- package/examples/deposit_to_subaccounts.ts +0 -146
- package/examples/get_info.ts +0 -63
- package/examples/get_points.ts +0 -61
- package/examples/market_data_json.ts +0 -80
- package/examples/nonce_manager.ts +0 -264
- package/examples/transfer_update_leverage.ts +0 -52
- package/examples/wait_for_transaction.ts +0 -100
- package/examples/withdraw.ts +0 -118
package/README.md
CHANGED
|
@@ -1,487 +1,476 @@
|
|
|
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
|
-
TypeScript SDK for Lighter Protocol -
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
yarn add lighter-ts-sdk
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
- ✅
|
|
403
|
-
- ✅
|
|
404
|
-
- ✅
|
|
405
|
-
- ✅
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
###
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
-
|
|
436
|
-
-
|
|
437
|
-
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
-
|
|
447
|
-
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
-
|
|
472
|
-
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
- All core trading functionality implemented and tested
|
|
478
|
-
- Complete API coverage matching Python SDK
|
|
479
|
-
- Cross-platform compatibility verified
|
|
480
|
-
- Comprehensive documentation and examples
|
|
481
|
-
- TypeScript support with full type definitions
|
|
482
|
-
|
|
483
|
-
**Installation**: `npm install lighter-ts-sdk`
|
|
484
|
-
|
|
485
|
-
**Documentation**: Complete API reference and getting started guides included
|
|
486
|
-
|
|
487
|
-
**Support**: Full feature parity with Python SDK, ready for production trading
|
|
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.
|