@andy-liquid-labs/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.
- package/README.md +381 -0
- package/dist/index.d.mts +3686 -0
- package/dist/index.d.ts +3686 -0
- package/dist/index.js +6168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5939 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/api/exchange/change-account-tier.ts +38 -0
- package/src/api/exchange/fastwithdraw.ts +38 -0
- package/src/api/exchange/index.ts +7 -0
- package/src/api/exchange/notification-ack.ts +36 -0
- package/src/api/exchange/send-tx-batch.ts +53 -0
- package/src/api/exchange/send-tx.ts +105 -0
- package/src/api/exchange/tokens-create.ts +50 -0
- package/src/api/exchange/tokens-revoke.ts +38 -0
- package/src/api/index.ts +3 -0
- package/src/api/info/account-by-l1-address.ts +23 -0
- package/src/api/info/account.ts +80 -0
- package/src/api/info/announcement.ts +24 -0
- package/src/api/info/api-keys.ts +32 -0
- package/src/api/info/asset-details.ts +42 -0
- package/src/api/info/candles.ts +31 -0
- package/src/api/info/exchange-stats.ts +16 -0
- package/src/api/info/fastbridge-info.ts +15 -0
- package/src/api/info/funding-rates.ts +22 -0
- package/src/api/info/fundings.ts +29 -0
- package/src/api/info/index.ts +20 -0
- package/src/api/info/next-nonce.ts +26 -0
- package/src/api/info/order-book-details.ts +125 -0
- package/src/api/info/order-books.ts +23 -0
- package/src/api/info/recent-trades.ts +24 -0
- package/src/api/info/root-info.ts +13 -0
- package/src/api/info/root-status.ts +13 -0
- package/src/api/info/tx-from-l1-hash.ts +20 -0
- package/src/api/info/tx.ts +45 -0
- package/src/api/info/txs.ts +19 -0
- package/src/api/info/withdrawal-delay.ts +13 -0
- package/src/api/info-private/account-active-orders.ts +31 -0
- package/src/api/info-private/account-inactive-orders.ts +83 -0
- package/src/api/info-private/account-limits.ts +35 -0
- package/src/api/info-private/account-metadata.ts +43 -0
- package/src/api/info-private/deposit-history.ts +49 -0
- package/src/api/info-private/export.ts +41 -0
- package/src/api/info-private/fastwithdraw-info.ts +35 -0
- package/src/api/info-private/index.ts +18 -0
- package/src/api/info-private/l1-metadata.ts +35 -0
- package/src/api/info-private/liquidations.ts +96 -0
- package/src/api/info-private/pnl.ts +52 -0
- package/src/api/info-private/position-funding.ts +54 -0
- package/src/api/info-private/public-pools-metadata.ts +46 -0
- package/src/api/info-private/referral-points.ts +43 -0
- package/src/api/info-private/tokens.ts +44 -0
- package/src/api/info-private/trades.ts +66 -0
- package/src/api/info-private/transfer-fee-info.ts +37 -0
- package/src/api/info-private/transfer-history.ts +54 -0
- package/src/api/info-private/withdraw-history.ts +49 -0
- package/src/client/clientManager.ts +121 -0
- package/src/client/exchange-client.ts +637 -0
- package/src/client/http/client.ts +137 -0
- package/src/client/http/index.ts +6 -0
- package/src/client/http/interface.ts +89 -0
- package/src/client/index.ts +11 -0
- package/src/client/info-client.ts +383 -0
- package/src/client/info-private-client.ts +444 -0
- package/src/client/txClient.ts +597 -0
- package/src/client/ws-client.ts +457 -0
- package/src/crypto/ecgfp5.ts +722 -0
- package/src/crypto/goldilocks.ts +136 -0
- package/src/crypto/gorand.ts +777 -0
- package/src/crypto/index.ts +6 -0
- package/src/crypto/poseidon2.ts +365 -0
- package/src/crypto/scalar.ts +375 -0
- package/src/index.ts +112 -0
- package/src/signer/index.ts +5 -0
- package/src/signer/keyManager.ts +132 -0
- package/src/types/bridge.ts +24 -0
- package/src/types/constants.ts +252 -0
- package/src/types/errors.ts +168 -0
- package/src/types/index.ts +12 -0
- package/src/types/requests.ts +197 -0
- package/src/types/txInfo.ts +1277 -0
- package/src/types/txInfoPools.ts +502 -0
- package/src/types/txInfoSerializer.ts +348 -0
- package/src/types/ws.ts +407 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client Manager for handling multiple TxClients
|
|
3
|
+
* Similar to the Go SDK's SharedClientManager
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TxClient } from './txClient';
|
|
7
|
+
import { MinimalHTTPClient } from './http';
|
|
8
|
+
import { generateApiKey } from '../signer/keyManager';
|
|
9
|
+
|
|
10
|
+
// Global client storage
|
|
11
|
+
let defaultTxClient: TxClient | null = null;
|
|
12
|
+
const defaultClientPerAccount: Map<bigint, TxClient> = new Map();
|
|
13
|
+
const allTxClients: Map<bigint, Map<number, TxClient>> = new Map();
|
|
14
|
+
|
|
15
|
+
// Default values for optional parameters
|
|
16
|
+
export const DEFAULT_API_KEY_INDEX = 255;
|
|
17
|
+
export const DEFAULT_ACCOUNT_INDEX = -1n;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get a client for specific account and API key
|
|
21
|
+
*/
|
|
22
|
+
export function getClient(
|
|
23
|
+
apiKeyIndex: number = DEFAULT_API_KEY_INDEX,
|
|
24
|
+
accountIndex: bigint = DEFAULT_ACCOUNT_INDEX
|
|
25
|
+
): TxClient {
|
|
26
|
+
// If apiKeyIndex==255 && accountIndex!=-1, return default client for that account
|
|
27
|
+
if (apiKeyIndex === DEFAULT_API_KEY_INDEX && accountIndex !== DEFAULT_ACCOUNT_INDEX) {
|
|
28
|
+
const client = defaultClientPerAccount.get(accountIndex);
|
|
29
|
+
if (client) {
|
|
30
|
+
return client;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Special case: return default client
|
|
35
|
+
if (apiKeyIndex === DEFAULT_API_KEY_INDEX && accountIndex === DEFAULT_ACCOUNT_INDEX) {
|
|
36
|
+
if (!defaultTxClient) {
|
|
37
|
+
throw new Error('Client is not created, call createClient() first');
|
|
38
|
+
}
|
|
39
|
+
return defaultTxClient;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Look up client in double map
|
|
43
|
+
const accountClients = allTxClients.get(accountIndex);
|
|
44
|
+
const client = accountClients?.get(apiKeyIndex);
|
|
45
|
+
|
|
46
|
+
if (!client) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Client is not created for apiKeyIndex: ${apiKeyIndex} accountIndex: ${accountIndex}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a new TxClient and store it
|
|
57
|
+
*/
|
|
58
|
+
export function createClient(
|
|
59
|
+
httpClient: MinimalHTTPClient | null,
|
|
60
|
+
privateKey: string,
|
|
61
|
+
chainId: number,
|
|
62
|
+
apiKeyIndex: number,
|
|
63
|
+
accountIndex: bigint
|
|
64
|
+
): TxClient {
|
|
65
|
+
if (accountIndex <= 0n) {
|
|
66
|
+
throw new Error('Invalid account index');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const txClientInstance = new TxClient(
|
|
70
|
+
httpClient,
|
|
71
|
+
privateKey,
|
|
72
|
+
accountIndex,
|
|
73
|
+
apiKeyIndex,
|
|
74
|
+
chainId
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Store in allTxClients map
|
|
78
|
+
if (!allTxClients.has(accountIndex)) {
|
|
79
|
+
allTxClients.set(accountIndex, new Map());
|
|
80
|
+
}
|
|
81
|
+
allTxClients.get(accountIndex)!.set(apiKeyIndex, txClientInstance);
|
|
82
|
+
|
|
83
|
+
// Update default client (most recently created becomes default)
|
|
84
|
+
defaultTxClient = txClientInstance;
|
|
85
|
+
defaultClientPerAccount.set(accountIndex, txClientInstance);
|
|
86
|
+
|
|
87
|
+
return txClientInstance;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check that a client exists and the API key matches the one on the server
|
|
92
|
+
*/
|
|
93
|
+
export async function checkClient(
|
|
94
|
+
apiKeyIndex: number = DEFAULT_API_KEY_INDEX,
|
|
95
|
+
accountIndex: bigint = DEFAULT_ACCOUNT_INDEX
|
|
96
|
+
): Promise<void> {
|
|
97
|
+
const client = getClient(apiKeyIndex, accountIndex);
|
|
98
|
+
await client.check();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generate a new API key pair
|
|
103
|
+
* Returns [privateKey, publicKey] as hex strings
|
|
104
|
+
*/
|
|
105
|
+
export { generateApiKey };
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Clear all stored clients (useful for testing)
|
|
109
|
+
*/
|
|
110
|
+
export function clearClients(): void {
|
|
111
|
+
defaultTxClient = null;
|
|
112
|
+
defaultClientPerAccount.clear();
|
|
113
|
+
allTxClients.clear();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get the default client
|
|
118
|
+
*/
|
|
119
|
+
export function getDefaultClient(): TxClient | null {
|
|
120
|
+
return defaultTxClient;
|
|
121
|
+
}
|