lighter-ts-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +440 -0
  3. package/dist/api/account-api.d.ts +89 -0
  4. package/dist/api/account-api.d.ts.map +1 -0
  5. package/dist/api/account-api.js +61 -0
  6. package/dist/api/account-api.js.map +1 -0
  7. package/dist/api/api-client.d.ts +23 -0
  8. package/dist/api/api-client.d.ts.map +1 -0
  9. package/dist/api/api-client.js +129 -0
  10. package/dist/api/api-client.js.map +1 -0
  11. package/dist/api/block-api.d.ts +24 -0
  12. package/dist/api/block-api.d.ts.map +1 -0
  13. package/dist/api/block-api.js +22 -0
  14. package/dist/api/block-api.js.map +1 -0
  15. package/dist/api/candlestick-api.d.ts +27 -0
  16. package/dist/api/candlestick-api.d.ts.map +1 -0
  17. package/dist/api/candlestick-api.js +18 -0
  18. package/dist/api/candlestick-api.js.map +1 -0
  19. package/dist/api/order-api.d.ts +76 -0
  20. package/dist/api/order-api.d.ts.map +1 -0
  21. package/dist/api/order-api.js +102 -0
  22. package/dist/api/order-api.js.map +1 -0
  23. package/dist/api/root-api.d.ts +8 -0
  24. package/dist/api/root-api.d.ts.map +1 -0
  25. package/dist/api/root-api.js +14 -0
  26. package/dist/api/root-api.js.map +1 -0
  27. package/dist/api/transaction-api.d.ts +58 -0
  28. package/dist/api/transaction-api.d.ts.map +1 -0
  29. package/dist/api/transaction-api.js +141 -0
  30. package/dist/api/transaction-api.js.map +1 -0
  31. package/dist/api/ws-client.d.ts +21 -0
  32. package/dist/api/ws-client.d.ts.map +1 -0
  33. package/dist/api/ws-client.js +139 -0
  34. package/dist/api/ws-client.js.map +1 -0
  35. package/dist/index.d.ts +62 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +99 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/signer/signer-client.d.ts +79 -0
  40. package/dist/signer/signer-client.d.ts.map +1 -0
  41. package/dist/signer/signer-client.js +213 -0
  42. package/dist/signer/signer-client.js.map +1 -0
  43. package/dist/signer/wasm-signer-client.d.ts +129 -0
  44. package/dist/signer/wasm-signer-client.d.ts.map +1 -0
  45. package/dist/signer/wasm-signer-client.js +607 -0
  46. package/dist/signer/wasm-signer-client.js.map +1 -0
  47. package/dist/types/index.d.ts +130 -0
  48. package/dist/types/index.d.ts.map +1 -0
  49. package/dist/types/index.js +3 -0
  50. package/dist/types/index.js.map +1 -0
  51. package/dist/utils/api-key-utils.d.ts +7 -0
  52. package/dist/utils/api-key-utils.d.ts.map +1 -0
  53. package/dist/utils/api-key-utils.js +31 -0
  54. package/dist/utils/api-key-utils.js.map +1 -0
  55. package/dist/utils/configuration.d.ts +19 -0
  56. package/dist/utils/configuration.d.ts.map +1 -0
  57. package/dist/utils/configuration.js +55 -0
  58. package/dist/utils/configuration.js.map +1 -0
  59. package/dist/utils/exceptions.d.ts +33 -0
  60. package/dist/utils/exceptions.d.ts.map +1 -0
  61. package/dist/utils/exceptions.js +76 -0
  62. package/dist/utils/exceptions.js.map +1 -0
  63. package/dist/utils/node-wasm-signer.d.ts +126 -0
  64. package/dist/utils/node-wasm-signer.d.ts.map +1 -0
  65. package/dist/utils/node-wasm-signer.js +286 -0
  66. package/dist/utils/node-wasm-signer.js.map +1 -0
  67. package/dist/utils/signer-server.d.ts +18 -0
  68. package/dist/utils/signer-server.d.ts.map +1 -0
  69. package/dist/utils/signer-server.js +79 -0
  70. package/dist/utils/signer-server.js.map +1 -0
  71. package/dist/utils/signer.d.ts +15 -0
  72. package/dist/utils/signer.d.ts.map +1 -0
  73. package/dist/utils/signer.js +68 -0
  74. package/dist/utils/signer.js.map +1 -0
  75. package/dist/utils/wasm-signer.d.ts +130 -0
  76. package/dist/utils/wasm-signer.d.ts.map +1 -0
  77. package/dist/utils/wasm-signer.js +178 -0
  78. package/dist/utils/wasm-signer.js.map +1 -0
  79. package/docs/API.md +195 -0
  80. package/docs/AccountApi.md +220 -0
  81. package/docs/GettingStarted.md +261 -0
  82. package/docs/OrderApi.md +199 -0
  83. package/docs/SignerClient.md +326 -0
  84. package/docs/TransactionApi.md +312 -0
  85. package/docs/WsClient.md +275 -0
  86. package/docs/types/Account.md +67 -0
  87. package/docs/types/ApiKeyPair.md +33 -0
  88. package/docs/types/CreateOrderParams.md +47 -0
  89. package/docs/types/MarketOrderParams.md +36 -0
  90. package/docs/types/SignerConfig.md +40 -0
  91. package/docs/types/WasmSignerConfig.md +30 -0
  92. package/examples/README.md +171 -0
  93. package/examples/account_info.ts +12 -0
  94. package/examples/create_cancel_order.ts +74 -0
  95. package/examples/create_market_order.ts +42 -0
  96. package/examples/create_market_order_max_slippage.ts +43 -0
  97. package/examples/create_sl_tp.ts +61 -0
  98. package/examples/create_with_multiple_keys.ts +58 -0
  99. package/examples/get_info.ts +58 -0
  100. package/examples/send_tx_batch.ts +87 -0
  101. package/examples/system_setup.ts +96 -0
  102. package/examples/transfer_update_leverage.ts +53 -0
  103. package/examples/ws.ts +24 -0
  104. package/examples/ws_async.ts +39 -0
  105. package/examples/ws_send_batch_tx.ts +113 -0
  106. package/examples/ws_send_tx.ts +94 -0
  107. package/package.json +71 -0
  108. package/wasm/lighter-signer.wasm +0 -0
  109. package/wasm/wasm_exec.js +402 -0
  110. package/wasm/wasm_exec_nodejs.js +402 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lighter Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,440 @@
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 - A decentralized perpetual exchange built on zkSync.
6
+
7
+ ## Requirements
8
+
9
+ - Node.js 16+
10
+ - TypeScript 4.5+
11
+
12
+ ## Installation & Usage
13
+
14
+ ### npm install
15
+
16
+ ```sh
17
+ npm install lighter-ts-sdk
18
+ ```
19
+
20
+ ### yarn install
21
+
22
+ ```sh
23
+ yarn add lighter-ts-sdk
24
+ ```
25
+
26
+ Then import the package:
27
+
28
+ ```typescript
29
+ import { SignerClient, ApiClient } from 'lighter-ts-sdk';
30
+ ```
31
+
32
+ ## Quick Start Examples
33
+
34
+ ### 1. Basic API Usage
35
+
36
+ ```typescript
37
+ import { ApiClient, AccountApi } from 'lighter-protocol-sdk';
38
+
39
+ async function getAccountInfo() {
40
+ const client = new ApiClient({ host: 'https://mainnet.zklighter.elliot.ai' });
41
+ const accountApi = new AccountApi(client);
42
+
43
+ const account = await accountApi.getAccount({ by: 'index', value: '1' });
44
+ console.log('Account:', account);
45
+ }
46
+
47
+ getAccountInfo().catch(console.error);
48
+ ```
49
+
50
+ ### 2. Create Market Order
51
+
52
+ ```typescript
53
+ import { SignerClient } from 'lighter-protocol-sdk';
54
+
55
+ async function createMarketOrder() {
56
+ const client = new SignerClient({
57
+ url: 'https://mainnet.zklighter.elliot.ai',
58
+ privateKey: 'your-api-key-private-key',
59
+ accountIndex: 123,
60
+ apiKeyIndex: 0,
61
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
62
+ });
63
+
64
+ await client.initialize();
65
+ await client.ensureWasmClient();
66
+
67
+ const [tx, txHash, err] = await client.createMarketOrder({
68
+ marketIndex: 0,
69
+ clientOrderIndex: Date.now(),
70
+ baseAmount: 1000000, // 1 BTC in satoshis
71
+ avgExecutionPrice: 300000000, // $30,000 in cents
72
+ isAsk: true // Sell order
73
+ });
74
+
75
+ if (err) {
76
+ console.error('Order failed:', err);
77
+ } else {
78
+ console.log('Market order created:', { tx, txHash });
79
+ }
80
+ }
81
+
82
+ createMarketOrder().catch(console.error);
83
+ ```
84
+
85
+ ### 3. Create Limit Order
86
+
87
+ ```typescript
88
+ import { SignerClient } from 'lighter-protocol-sdk';
89
+
90
+ async function createLimitOrder() {
91
+ const client = new SignerClient({
92
+ url: 'https://mainnet.zklighter.elliot.ai',
93
+ privateKey: 'your-api-key-private-key',
94
+ accountIndex: 123,
95
+ apiKeyIndex: 0,
96
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
97
+ });
98
+
99
+ await client.initialize();
100
+ await client.ensureWasmClient();
101
+
102
+ const [tx, txHash, err] = await client.createOrder({
103
+ marketIndex: 0,
104
+ clientOrderIndex: Date.now(),
105
+ baseAmount: 500000, // 0.5 BTC
106
+ price: 295000000, // $29,500
107
+ isAsk: false, // Buy order
108
+ timeInForce: SignerClient.TIME_IN_FORCE_GTC // Good Till Cancel
109
+ });
110
+
111
+ if (err) {
112
+ console.error('Order failed:', err);
113
+ } else {
114
+ console.log('Limit order created:', { tx, txHash });
115
+ }
116
+ }
117
+
118
+ createLimitOrder().catch(console.error);
119
+ ```
120
+
121
+ ### 4. Cancel Order
122
+
123
+ ```typescript
124
+ import { SignerClient } from 'lighter-protocol-sdk';
125
+
126
+ async function cancelOrder() {
127
+ const client = new SignerClient({
128
+ url: 'https://mainnet.zklighter.elliot.ai',
129
+ privateKey: 'your-api-key-private-key',
130
+ accountIndex: 123,
131
+ apiKeyIndex: 0,
132
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
133
+ });
134
+
135
+ await client.initialize();
136
+ await client.ensureWasmClient();
137
+
138
+ const [tx, txHash, err] = await client.cancelOrder({
139
+ marketIndex: 0,
140
+ orderIndex: 12345
141
+ });
142
+
143
+ if (err) {
144
+ console.error('Cancel failed:', err);
145
+ } else {
146
+ console.log('Order cancelled:', { tx, txHash });
147
+ }
148
+ }
149
+
150
+ cancelOrder().catch(console.error);
151
+ ```
152
+
153
+ ### 5. Transfer USDC
154
+
155
+ ```typescript
156
+ import { SignerClient } from 'lighter-protocol-sdk';
157
+
158
+ async function transferUSDC() {
159
+ const client = new SignerClient({
160
+ url: 'https://mainnet.zklighter.elliot.ai',
161
+ privateKey: 'your-api-key-private-key',
162
+ accountIndex: 123,
163
+ apiKeyIndex: 0,
164
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
165
+ });
166
+
167
+ await client.initialize();
168
+ await client.ensureWasmClient();
169
+
170
+ const [tx, txHash, err] = await client.transfer({
171
+ toAccountIndex: 456,
172
+ usdcAmount: 1000000, // $10,000 in cents
173
+ fee: 0,
174
+ memo: 'a'.repeat(32) // 32-byte memo required
175
+ });
176
+
177
+ if (err) {
178
+ console.error('Transfer failed:', err);
179
+ } else {
180
+ console.log('USDC transferred:', { tx, txHash });
181
+ }
182
+ }
183
+
184
+ transferUSDC().catch(console.error);
185
+ ```
186
+
187
+ ### 6. Update Leverage
188
+
189
+ ```typescript
190
+ import { SignerClient } from 'lighter-protocol-sdk';
191
+
192
+ async function updateLeverage() {
193
+ const client = new SignerClient({
194
+ url: 'https://mainnet.zklighter.elliot.ai',
195
+ privateKey: 'your-api-key-private-key',
196
+ accountIndex: 123,
197
+ apiKeyIndex: 0,
198
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
199
+ });
200
+
201
+ await client.initialize();
202
+ await client.ensureWasmClient();
203
+
204
+ const [tx, txHash, err] = await client.updateLeverage({
205
+ marketIndex: 0,
206
+ fraction: 10, // 10x leverage
207
+ marginMode: SignerClient.CROSS_MARGIN_MODE
208
+ });
209
+
210
+ if (err) {
211
+ console.error('Leverage update failed:', err);
212
+ } else {
213
+ console.log('Leverage updated:', { tx, txHash });
214
+ }
215
+ }
216
+
217
+ updateLeverage().catch(console.error);
218
+ ```
219
+
220
+ ### 7. Cancel All Orders
221
+
222
+ ```typescript
223
+ import { SignerClient } from 'lighter-protocol-sdk';
224
+
225
+ async function cancelAllOrders() {
226
+ const client = new SignerClient({
227
+ url: 'https://mainnet.zklighter.elliot.ai',
228
+ privateKey: 'your-api-key-private-key',
229
+ accountIndex: 123,
230
+ apiKeyIndex: 0,
231
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
232
+ });
233
+
234
+ await client.initialize();
235
+ await client.ensureWasmClient();
236
+
237
+ const [tx, txHash, err] = await client.cancelAllOrders({
238
+ timeInForce: SignerClient.TIME_IN_FORCE_GTC,
239
+ time: Date.now()
240
+ });
241
+
242
+ if (err) {
243
+ console.error('Cancel all failed:', err);
244
+ } else {
245
+ console.log('All orders cancelled:', { tx, txHash });
246
+ }
247
+ }
248
+
249
+ cancelAllOrders().catch(console.error);
250
+ ```
251
+
252
+ ### 8. WebSocket Real-time Data
253
+
254
+ ```typescript
255
+ import { WsClient } from 'lighter-protocol-sdk';
256
+
257
+ async function connectWebSocket() {
258
+ const wsClient = new WsClient({
259
+ url: 'wss://mainnet.zklighter.elliot.ai/ws',
260
+ onOpen: () => console.log('WebSocket connected'),
261
+ onMessage: (message) => console.log('Received:', message),
262
+ onClose: () => console.log('WebSocket closed'),
263
+ onError: (error) => console.error('WebSocket error:', error)
264
+ });
265
+
266
+ await wsClient.connect();
267
+
268
+ // Subscribe to order book updates
269
+ wsClient.subscribe('orderbook', { market_id: 0 });
270
+
271
+ // Subscribe to account updates
272
+ wsClient.subscribe('account', { account_index: 123 });
273
+ }
274
+
275
+ connectWebSocket().catch(console.error);
276
+ ```
277
+
278
+ ## Signer Client Configuration
279
+
280
+ The `SignerClient` requires the following configuration:
281
+
282
+ ```typescript
283
+ interface SignerConfig {
284
+ url: string; // API endpoint
285
+ privateKey: string; // API key private key
286
+ accountIndex: number; // Your account index
287
+ apiKeyIndex: number; // API key index (usually 0)
288
+ wasmConfig: {
289
+ wasmPath: string; // Path to WASM file
290
+ };
291
+ }
292
+ ```
293
+
294
+ ## Available Constants
295
+
296
+ ```typescript
297
+ // Order Types
298
+ SignerClient.ORDER_TYPE_LIMIT = 0
299
+ SignerClient.ORDER_TYPE_MARKET = 1
300
+
301
+ // Time in Force
302
+ SignerClient.TIME_IN_FORCE_GTC = 0 // Good Till Cancel
303
+ SignerClient.TIME_IN_FORCE_IOC = 1 // Immediate or Cancel
304
+ SignerClient.TIME_IN_FORCE_FOK = 2 // Fill or Kill
305
+
306
+ // Margin Modes
307
+ SignerClient.CROSS_MARGIN_MODE = 0
308
+ SignerClient.ISOLATED_MARGIN_MODE = 1
309
+ ```
310
+
311
+ ## Documentation
312
+
313
+ - [Getting Started Guide](docs/GettingStarted.md)
314
+ - [API Reference](docs/API.md)
315
+ - [SignerClient Documentation](docs/SignerClient.md)
316
+ - [WebSocket Client](docs/WsClient.md)
317
+ - [Type Definitions](docs/types/)
318
+
319
+ ## Examples
320
+
321
+ Check the `examples/` directory for comprehensive usage examples:
322
+
323
+ - `create_market_order.ts` - Basic market order creation
324
+ - `create_cancel_order.ts` - Order management
325
+ - `transfer_update_leverage.ts` - Account operations
326
+ - `system_setup.ts` - API key management
327
+ - `ws_*.ts` - WebSocket examples
328
+
329
+ ## SDK Status Report
330
+
331
+ ### ✅ **Currently Working & Released**
332
+
333
+ #### **Core Trading Functionality**
334
+ - ✅ **Market Orders** - Create market buy/sell orders with price limits
335
+ - ✅ **Limit Orders** - Create limit orders with GTC/IOC/FOK time in force
336
+ - ✅ **Order Cancellation** - Cancel individual orders by market and order index
337
+ - ✅ **Cancel All Orders** - Cancel all orders for an account
338
+ - ✅ **USDC Transfers** - Transfer USDC between accounts with memo support
339
+ - ✅ **Leverage Updates** - Update leverage for cross/isolated margin modes
340
+
341
+ #### **Account Management**
342
+ - ✅ **API Key Generation** - Generate new API keys for trading
343
+ - ✅ **API Key Management** - Change API keys and manage permissions
344
+ - ✅ **Account Information** - Retrieve account details, positions, and balances
345
+ - ✅ **Nonce Management** - Automatic nonce handling for transactions
346
+
347
+ #### **Real-time Data**
348
+ - ✅ **WebSocket Client** - Real-time order book, trades, and account updates
349
+ - ✅ **Order Book Data** - Live market depth and price levels
350
+ - ✅ **Trade Data** - Recent trades and execution information
351
+ - ✅ **Account Updates** - Real-time position and balance updates
352
+
353
+ #### **API Coverage**
354
+ - ✅ **AccountApi** - Complete account management endpoints
355
+ - ✅ **OrderApi** - Order book, trades, and exchange statistics
356
+ - ✅ **TransactionApi** - Transaction history and nonce management
357
+ - ✅ **BlockApi** - Block information and current height
358
+ - ✅ **CandlestickApi** - Historical price data and funding rates
359
+
360
+ #### **Technical Features**
361
+ - ✅ **WASM Signer** - Go-compiled WebAssembly for cryptographic operations
362
+ - ✅ **Cross-Platform** - Windows, Linux, macOS support
363
+ - ✅ **TypeScript Support** - Complete type definitions and IntelliSense
364
+ - ✅ **Error Handling** - Comprehensive error handling and validation
365
+ - ✅ **Chain ID Support** - Correct mainnet chain ID (304) integration
366
+
367
+ ### 🔧 **Technical Implementation**
368
+
369
+ #### **WASM Signer Capabilities**
370
+ - ✅ **Transaction Signing** - All transaction types properly signed
371
+ - ✅ **Signature Validation** - Server-side signature verification working
372
+ - ✅ **Order Expiry Handling** - Correct OrderExpiry and ExpiredAt management
373
+ - ✅ **Field Validation** - Proper field names and types (MarketIndex, USDCAmount, etc.)
374
+ - ✅ **Memo Support** - 32-byte memo field for transfers
375
+ - ✅ **Margin Mode Support** - Cross and isolated margin mode handling
376
+
377
+ #### **API Integration**
378
+ - ✅ **sendTxWithIndices** - Correct API endpoint for transaction submission
379
+ - ✅ **Authentication** - API key-based authentication working
380
+ - ✅ **Rate Limiting** - Proper request handling and retry logic
381
+ - ✅ **Error Codes** - Complete error code handling (21120, 21505, etc.)
382
+
383
+ ### 📋 **What's Working in Production**
384
+
385
+ 1. **Complete Trading Flow**
386
+ - Generate API keys → Create orders → Monitor positions → Cancel orders
387
+ - All order types (market, limit) with proper time in force
388
+ - Real-time order book and trade data via WebSocket
389
+
390
+ 2. **Account Operations**
391
+ - USDC transfers between accounts
392
+ - Leverage updates for risk management
393
+ - API key rotation and management
394
+
395
+ 3. **Cross-Platform Compatibility**
396
+ - Node.js 16+ support across all platforms
397
+ - Browser compatibility with WebAssembly
398
+ - TypeScript 4.5+ support
399
+
400
+ ### 🚀 **Next Release Features**
401
+
402
+ #### **Planned Enhancements**
403
+ - 🔄 **Stop Loss/Take Profit Orders** - Advanced order types with trigger prices
404
+ - 🔄 **Batch Operations** - Multiple order creation in single transaction
405
+ - 🔄 **Advanced Slippage Protection** - Enhanced slippage control mechanisms
406
+ - 🔄 **Position Management** - Enhanced position tracking and management
407
+ - 🔄 **Risk Management** - Additional risk controls and position limits
408
+
409
+ #### **API Extensions**
410
+ - 🔄 **Funding Rate API** - Historical and current funding rates
411
+ - 🔄 **Announcement API** - System announcements and updates
412
+ - 🔄 **Referral API** - Referral program integration
413
+ - 🔄 **Notification API** - Push notifications for important events
414
+
415
+ #### **Developer Experience**
416
+ - 🔄 **Enhanced Error Messages** - More descriptive error handling
417
+ - 🔄 **Rate Limit Headers** - Better rate limiting information
418
+ - 🔄 **Request/Response Logging** - Debug logging capabilities
419
+ - 🔄 **Mock Testing** - Testing utilities and mock data
420
+
421
+ ### 🎯 **Current Version: 1.0.0 (Unofficial Release)**
422
+
423
+ **⚠️ Community-Built SDK**
424
+ - This is an **unofficial** TypeScript SDK built by the community
425
+ - Not officially maintained by Lighter Protocol team
426
+ - Built with full feature parity to the official Python SDK
427
+ - Ready for production use with comprehensive testing
428
+
429
+ **Ready for Production Use**
430
+ - All core trading functionality implemented and tested
431
+ - Complete API coverage matching Python SDK
432
+ - Cross-platform compatibility verified
433
+ - Comprehensive documentation and examples
434
+ - TypeScript support with full type definitions
435
+
436
+ **Installation**: `npm install lighter-protocol-sdk`
437
+
438
+ **Documentation**: Complete API reference and getting started guides included
439
+
440
+ **Support**: Full feature parity with Python SDK, ready for production trading
@@ -0,0 +1,89 @@
1
+ import { ApiClient } from './api-client';
2
+ import { AccountParams, PaginationParams } from '../types';
3
+ export interface Account {
4
+ index: string;
5
+ l1_address: string;
6
+ l2_address: string;
7
+ nonce: string;
8
+ balance: string;
9
+ margin_balance: string;
10
+ free_margin: string;
11
+ margin_used: string;
12
+ margin_ratio: string;
13
+ positions: AccountPosition[];
14
+ orders: Order[];
15
+ trades: Trade[];
16
+ }
17
+ export interface AccountPosition {
18
+ market_id: number;
19
+ side: 'long' | 'short';
20
+ size: string;
21
+ entry_price: string;
22
+ mark_price: string;
23
+ unrealized_pnl: string;
24
+ realized_pnl: string;
25
+ margin_used: string;
26
+ }
27
+ export interface Order {
28
+ id: string;
29
+ market_id: number;
30
+ side: 'buy' | 'sell';
31
+ type: 'limit' | 'market';
32
+ size: string;
33
+ price: string;
34
+ filled_size: string;
35
+ remaining_size: string;
36
+ status: 'open' | 'filled' | 'cancelled' | 'rejected';
37
+ created_at: string;
38
+ updated_at: string;
39
+ }
40
+ export interface Trade {
41
+ id: string;
42
+ market_id: number;
43
+ side: 'buy' | 'sell';
44
+ size: string;
45
+ price: string;
46
+ fee: string;
47
+ timestamp: string;
48
+ }
49
+ export interface AccountApiKeys {
50
+ api_keys: ApiKey[];
51
+ }
52
+ export interface ApiKey {
53
+ index: number;
54
+ name: string;
55
+ permissions: string[];
56
+ created_at: string;
57
+ last_used_at?: string;
58
+ }
59
+ export interface PublicPool {
60
+ id: string;
61
+ name: string;
62
+ description: string;
63
+ total_value_locked: string;
64
+ apy: string;
65
+ shares: PublicPoolShare[];
66
+ }
67
+ export interface PublicPoolShare {
68
+ token: string;
69
+ amount: string;
70
+ value: string;
71
+ }
72
+ export declare class AccountApi {
73
+ private client;
74
+ constructor(client: ApiClient);
75
+ getAccount(params: AccountParams): Promise<Account>;
76
+ getAccounts(params?: PaginationParams): Promise<Account[]>;
77
+ getAccountsByL1Address(l1Address: string): Promise<Account[]>;
78
+ getApiKeys(accountIndex: number, apiKeyIndex: number): Promise<AccountApiKeys>;
79
+ getFeeBucket(accountIndex: number): Promise<any>;
80
+ isWhitelisted(accountIndex: number): Promise<{
81
+ is_whitelisted: boolean;
82
+ }>;
83
+ getPnL(accountIndex: number, params?: {
84
+ start_time?: number;
85
+ end_time?: number;
86
+ }): Promise<any>;
87
+ getPublicPools(filter?: string, limit?: number, index?: number): Promise<PublicPool[]>;
88
+ }
89
+ //# sourceMappingURL=account-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-api.d.ts","sourceRoot":"","sources":["../../src/api/account-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9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ccountApi {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ async getAccount(params) {
9
+ const response = await this.client.get('/api/v1/account', {
10
+ by: params.by,
11
+ value: params.value,
12
+ });
13
+ return response.data;
14
+ }
15
+ async getAccounts(params) {
16
+ const response = await this.client.get('/api/v1/accounts', params);
17
+ return response.data;
18
+ }
19
+ async getAccountsByL1Address(l1Address) {
20
+ const response = await this.client.get('/api/v1/accountsByL1Address', {
21
+ l1_address: l1Address,
22
+ });
23
+ return response.data;
24
+ }
25
+ async getApiKeys(accountIndex, apiKeyIndex) {
26
+ const response = await this.client.get('/api/v1/apikeys', {
27
+ account_index: accountIndex,
28
+ api_key_index: apiKeyIndex,
29
+ });
30
+ return response.data;
31
+ }
32
+ async getFeeBucket(accountIndex) {
33
+ const response = await this.client.get('/api/v1/feeBucket', {
34
+ account_index: accountIndex,
35
+ });
36
+ return response.data;
37
+ }
38
+ async isWhitelisted(accountIndex) {
39
+ const response = await this.client.get('/api/v1/isWhitelisted', {
40
+ account_index: accountIndex,
41
+ });
42
+ return response.data;
43
+ }
44
+ async getPnL(accountIndex, params) {
45
+ const response = await this.client.get('/api/v1/pnl', {
46
+ account_index: accountIndex,
47
+ ...params,
48
+ });
49
+ return response.data;
50
+ }
51
+ async getPublicPools(filter = 'all', limit = 10, index = 0) {
52
+ const response = await this.client.get('/api/v1/publicPools', {
53
+ filter,
54
+ limit,
55
+ index,
56
+ });
57
+ return response.data;
58
+ }
59
+ }
60
+ exports.AccountApi = AccountApi;
61
+ //# sourceMappingURL=account-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-api.js","sourceRoot":"","sources":["../../src/api/account-api.ts"],"names":[],"mappings":";;;AAgFA,MAAa,UAAU;IAGrB,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAqB;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,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AAC;IACvB,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,YAAoB,EAAE,MAAmD;QAC3F,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE;YACpD,aAAa,EAAE,YAAY;YAC3B,GAAG,MAAM;SACV,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,SAAiB,KAAK,EAAE,QAAgB,EAAE,EAAE,QAAgB,CAAC;QACvF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAe,qBAAqB,EAAE;YAC1E,MAAM;YACN,KAAK;YACL,KAAK;SACN,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AAjED,gCAiEC"}
@@ -0,0 +1,23 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { Config } from '../utils/configuration';
3
+ import { ApiResponse, Configuration } from '../types';
4
+ export declare class ApiClient {
5
+ private config;
6
+ private axiosInstance;
7
+ private defaultHeaders;
8
+ constructor(config?: Partial<Configuration>);
9
+ private setupInterceptors;
10
+ private handleError;
11
+ setDefaultHeader(name: string, value: string): void;
12
+ removeDefaultHeader(name: string): void;
13
+ request<T = any>(method: string, url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
14
+ get<T = any>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
15
+ post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
16
+ put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
17
+ delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
18
+ patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
19
+ getConfig(): Config;
20
+ setConfig(config: Partial<Configuration>): void;
21
+ close(): void;
22
+ }
23
+ //# sourceMappingURL=api-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/api/api-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAWtD,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,cAAc,CAA8B;gBAExC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;IAc3C,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,WAAW;IAkCZ,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAInD,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIjC,OAAO,CAAC,CAAC,GAAG,GAAG,EAC1B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAqBb,GAAG,CAAC,CAAC,GAAG,GAAG,EACtB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIb,IAAI,CAAC,CAAC,GAAG,GAAG,EACvB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIb,GAAG,CAAC,CA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