@luxfi/dex 1.2.1 → 2.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 (74) hide show
  1. package/dist/client/clob.d.ts +52 -0
  2. package/dist/client/clob.d.ts.map +1 -0
  3. package/dist/client/clob.js +196 -0
  4. package/dist/client/index.d.ts +7 -0
  5. package/dist/client/index.d.ts.map +1 -0
  6. package/dist/client/index.js +6 -0
  7. package/dist/client/types.d.ts +126 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +5 -0
  10. package/dist/hooks/index.d.ts +22 -0
  11. package/dist/hooks/index.d.ts.map +1 -0
  12. package/dist/hooks/index.js +25 -0
  13. package/dist/hooks/use-lxbook.d.ts +95 -0
  14. package/dist/hooks/use-lxbook.d.ts.map +1 -0
  15. package/dist/hooks/use-lxbook.js +213 -0
  16. package/dist/hooks/use-lxfeed.d.ts +111 -0
  17. package/dist/hooks/use-lxfeed.d.ts.map +1 -0
  18. package/dist/hooks/use-lxfeed.js +152 -0
  19. package/dist/hooks/use-lxvault.d.ts +137 -0
  20. package/dist/hooks/use-lxvault.d.ts.map +1 -0
  21. package/dist/hooks/use-lxvault.js +227 -0
  22. package/dist/hooks/use-quote.d.ts +18 -0
  23. package/dist/hooks/use-quote.d.ts.map +1 -0
  24. package/dist/hooks/use-quote.js +65 -0
  25. package/dist/hooks/use-swap.d.ts +17 -0
  26. package/dist/hooks/use-swap.d.ts.map +1 -0
  27. package/dist/hooks/use-swap.js +75 -0
  28. package/dist/index.d.ts +50 -115
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +72 -225
  31. package/dist/precompile/abis.d.ts +991 -0
  32. package/dist/precompile/abis.d.ts.map +1 -0
  33. package/dist/precompile/abis.js +743 -0
  34. package/dist/precompile/addresses.d.ts +129 -0
  35. package/dist/precompile/addresses.d.ts.map +1 -0
  36. package/dist/precompile/addresses.js +117 -0
  37. package/dist/precompile/index.d.ts +19 -0
  38. package/dist/precompile/index.d.ts.map +1 -0
  39. package/dist/precompile/index.js +18 -0
  40. package/dist/precompile/types.d.ts +246 -0
  41. package/dist/precompile/types.d.ts.map +1 -0
  42. package/dist/precompile/types.js +84 -0
  43. package/dist/router/index.d.ts +7 -0
  44. package/dist/router/index.d.ts.map +1 -0
  45. package/dist/router/index.js +6 -0
  46. package/dist/router/router.d.ts +58 -0
  47. package/dist/router/router.d.ts.map +1 -0
  48. package/dist/router/router.js +272 -0
  49. package/dist/router/types.d.ts +76 -0
  50. package/dist/router/types.d.ts.map +1 -0
  51. package/dist/router/types.js +1 -0
  52. package/package.json +55 -29
  53. package/src/client/clob.ts +256 -0
  54. package/src/client/index.ts +6 -0
  55. package/src/client/types.ts +148 -0
  56. package/src/hooks/index.ts +29 -0
  57. package/src/hooks/use-lxbook.ts +343 -0
  58. package/src/hooks/use-lxfeed.ts +179 -0
  59. package/src/hooks/use-lxvault.ts +318 -0
  60. package/src/hooks/use-quote.ts +92 -0
  61. package/src/hooks/use-swap.ts +103 -0
  62. package/src/index.ts +142 -309
  63. package/src/precompile/abis.ts +755 -0
  64. package/src/precompile/addresses.ts +153 -0
  65. package/src/precompile/index.ts +18 -0
  66. package/src/precompile/types.ts +295 -0
  67. package/src/router/index.ts +6 -0
  68. package/src/router/router.ts +338 -0
  69. package/src/router/types.ts +87 -0
  70. package/dist/marketData.d.ts +0 -152
  71. package/dist/marketData.d.ts.map +0 -1
  72. package/dist/marketData.js +0 -253
  73. package/src/marketData.ts +0 -351
  74. package/tsconfig.json +0 -19
@@ -0,0 +1,227 @@
1
+ /**
2
+ * LXVault Hooks (LP-9030)
3
+ * React hooks for custody, margin, and positions via LXVault precompile
4
+ */
5
+ import { useCallback } from 'react';
6
+ import { useReadContract, useWriteContract, useWaitForTransactionReceipt, useAccount } from 'wagmi';
7
+ import { LX } from '../precompile/addresses';
8
+ import { LX_VAULT_ABI } from '../precompile/abis';
9
+ /**
10
+ * Build account tuple from address and subaccount
11
+ */
12
+ function buildAccount(main, subaccountId = 0) {
13
+ return { main, subaccountId };
14
+ }
15
+ /**
16
+ * Hook to get token balance in vault
17
+ */
18
+ export function useLXVaultBalance(token, subaccountId = 0) {
19
+ const { address } = useAccount();
20
+ const { data, isLoading, error, refetch } = useReadContract({
21
+ address: LX.LX_VAULT,
22
+ abi: LX_VAULT_ABI,
23
+ functionName: 'getBalance',
24
+ args: address ? [buildAccount(address, subaccountId), token] : undefined,
25
+ query: { enabled: !!address },
26
+ });
27
+ return {
28
+ balance: data,
29
+ isLoading,
30
+ error,
31
+ refetch,
32
+ };
33
+ }
34
+ /**
35
+ * Hook to get position for a market
36
+ */
37
+ export function useLXVaultPosition(marketId, subaccountId = 0) {
38
+ const { address } = useAccount();
39
+ const { data, isLoading, error, refetch } = useReadContract({
40
+ address: LX.LX_VAULT,
41
+ abi: LX_VAULT_ABI,
42
+ functionName: 'getPosition',
43
+ args: address ? [buildAccount(address, subaccountId), marketId] : undefined,
44
+ query: { enabled: !!address },
45
+ });
46
+ return {
47
+ position: data,
48
+ isLoading,
49
+ error,
50
+ refetch,
51
+ };
52
+ }
53
+ /**
54
+ * Hook to get margin info (free margin, used margin, etc.)
55
+ */
56
+ export function useLXVaultMargin(subaccountId = 0) {
57
+ const { address } = useAccount();
58
+ const { data, isLoading, error, refetch } = useReadContract({
59
+ address: LX.LX_VAULT,
60
+ abi: LX_VAULT_ABI,
61
+ functionName: 'getMargin',
62
+ args: address ? [buildAccount(address, subaccountId)] : undefined,
63
+ query: { enabled: !!address },
64
+ });
65
+ return {
66
+ margin: data,
67
+ isLoading,
68
+ error,
69
+ refetch,
70
+ };
71
+ }
72
+ /**
73
+ * Hook to check if account is liquidatable
74
+ */
75
+ export function useLXVaultLiquidatable(account, subaccountId = 0) {
76
+ const { address: connectedAddress } = useAccount();
77
+ const targetAddress = account ?? connectedAddress;
78
+ const { data, isLoading, error, refetch } = useReadContract({
79
+ address: LX.LX_VAULT,
80
+ abi: LX_VAULT_ABI,
81
+ functionName: 'isLiquidatable',
82
+ args: targetAddress ? [buildAccount(targetAddress, subaccountId)] : undefined,
83
+ query: { enabled: !!targetAddress },
84
+ });
85
+ const result = data;
86
+ return {
87
+ liquidatable: result?.[0],
88
+ shortfall: result?.[1],
89
+ isLoading,
90
+ error,
91
+ refetch,
92
+ };
93
+ }
94
+ /**
95
+ * Hook to get funding rate for a market
96
+ */
97
+ export function useLXVaultFundingRate(marketId) {
98
+ const { data, isLoading, error, refetch } = useReadContract({
99
+ address: LX.LX_VAULT,
100
+ abi: LX_VAULT_ABI,
101
+ functionName: 'getFundingRate',
102
+ args: [marketId],
103
+ });
104
+ const result = data;
105
+ return {
106
+ rateX18: result?.[0],
107
+ nextFundingTime: result?.[1],
108
+ isLoading,
109
+ error,
110
+ refetch,
111
+ };
112
+ }
113
+ /**
114
+ * Hook for depositing tokens into vault
115
+ */
116
+ export function useLXVaultDeposit() {
117
+ const { writeContract, data: hash, isPending, error } = useWriteContract();
118
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
119
+ const deposit = useCallback((token, amount, subaccountId = 0) => {
120
+ writeContract({
121
+ address: LX.LX_VAULT,
122
+ abi: LX_VAULT_ABI,
123
+ functionName: 'deposit',
124
+ args: [token, amount, subaccountId],
125
+ });
126
+ }, [writeContract]);
127
+ return {
128
+ deposit,
129
+ hash,
130
+ isPending,
131
+ isConfirming,
132
+ isSuccess,
133
+ error,
134
+ };
135
+ }
136
+ /**
137
+ * Hook for withdrawing tokens from vault
138
+ */
139
+ export function useLXVaultWithdraw() {
140
+ const { writeContract, data: hash, isPending, error } = useWriteContract();
141
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
142
+ const withdraw = useCallback((token, amount, subaccountId = 0) => {
143
+ writeContract({
144
+ address: LX.LX_VAULT,
145
+ abi: LX_VAULT_ABI,
146
+ functionName: 'withdraw',
147
+ args: [token, amount, subaccountId],
148
+ });
149
+ }, [writeContract]);
150
+ return {
151
+ withdraw,
152
+ hash,
153
+ isPending,
154
+ isConfirming,
155
+ isSuccess,
156
+ error,
157
+ };
158
+ }
159
+ /**
160
+ * Hook for transferring between subaccounts
161
+ */
162
+ export function useLXVaultTransfer() {
163
+ const { writeContract, data: hash, isPending, error } = useWriteContract();
164
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
165
+ const transfer = useCallback((token, amount, fromSubaccount, toSubaccount) => {
166
+ writeContract({
167
+ address: LX.LX_VAULT,
168
+ abi: LX_VAULT_ABI,
169
+ functionName: 'transfer',
170
+ args: [token, amount, fromSubaccount, toSubaccount],
171
+ });
172
+ }, [writeContract]);
173
+ return {
174
+ transfer,
175
+ hash,
176
+ isPending,
177
+ isConfirming,
178
+ isSuccess,
179
+ error,
180
+ };
181
+ }
182
+ /**
183
+ * Hook for liquidating underwater positions
184
+ */
185
+ export function useLXVaultLiquidate() {
186
+ const { writeContract, data: hash, isPending, error } = useWriteContract();
187
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
188
+ const liquidate = useCallback((targetAccount, targetSubaccount, marketId, sizeX18) => {
189
+ writeContract({
190
+ address: LX.LX_VAULT,
191
+ abi: LX_VAULT_ABI,
192
+ functionName: 'liquidate',
193
+ args: [buildAccount(targetAccount, targetSubaccount), marketId, sizeX18],
194
+ });
195
+ }, [writeContract]);
196
+ return {
197
+ liquidate,
198
+ hash,
199
+ isPending,
200
+ isConfirming,
201
+ isSuccess,
202
+ error,
203
+ };
204
+ }
205
+ /**
206
+ * Combined hook for common vault operations
207
+ */
208
+ export function useLXVault(subaccountId = 0) {
209
+ const { address } = useAccount();
210
+ const margin = useLXVaultMargin(subaccountId);
211
+ const { deposit, isPending: isDepositing } = useLXVaultDeposit();
212
+ const { withdraw, isPending: isWithdrawing } = useLXVaultWithdraw();
213
+ const { transfer, isPending: isTransferring } = useLXVaultTransfer();
214
+ return {
215
+ address,
216
+ subaccountId,
217
+ margin: margin.margin,
218
+ isLoadingMargin: margin.isLoading,
219
+ deposit,
220
+ withdraw,
221
+ transfer,
222
+ isDepositing,
223
+ isWithdrawing,
224
+ isTransferring,
225
+ refetchMargin: margin.refetch,
226
+ };
227
+ }
@@ -0,0 +1,18 @@
1
+ import type { Address } from 'viem';
2
+ import { type Quote } from '../router';
3
+ interface UseQuoteOptions {
4
+ refreshInterval?: number;
5
+ enabled?: boolean;
6
+ }
7
+ interface UseQuoteResult {
8
+ quote: Quote | null;
9
+ isLoading: boolean;
10
+ error: Error | null;
11
+ refetch: () => Promise<void>;
12
+ }
13
+ /**
14
+ * Hook to get swap quotes from the omnichain router
15
+ */
16
+ export declare function useQuote(tokenIn: Address | undefined, tokenOut: Address | undefined, amountIn: bigint | undefined, options?: UseQuoteOptions): UseQuoteResult;
17
+ export {};
18
+ //# sourceMappingURL=use-quote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-quote.d.ts","sourceRoot":"","sources":["../../src/hooks/use-quote.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAmB,KAAK,KAAK,EAAqB,MAAM,WAAW,CAAA;AAE1E,UAAU,eAAe;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAgEhB"}
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+ import { useState, useCallback, useEffect, useRef } from 'react';
3
+ import { usePublicClient } from 'wagmi';
4
+ import { OmnichainRouter } from '../router';
5
+ /**
6
+ * Hook to get swap quotes from the omnichain router
7
+ */
8
+ export function useQuote(tokenIn, tokenOut, amountIn, options = {}) {
9
+ const { refreshInterval = 10000, enabled = true } = options;
10
+ const publicClient = usePublicClient();
11
+ const routerRef = useRef(null);
12
+ const [quote, setQuote] = useState(null);
13
+ const [isLoading, setIsLoading] = useState(false);
14
+ const [error, setError] = useState(null);
15
+ // Initialize router
16
+ useEffect(() => {
17
+ if (!routerRef.current) {
18
+ routerRef.current = new OmnichainRouter();
19
+ }
20
+ if (publicClient) {
21
+ routerRef.current.setPublicClient(publicClient);
22
+ }
23
+ }, [publicClient]);
24
+ const fetchQuote = useCallback(async () => {
25
+ if (!tokenIn || !tokenOut || !amountIn || amountIn === 0n || !enabled) {
26
+ setQuote(null);
27
+ return;
28
+ }
29
+ setIsLoading(true);
30
+ setError(null);
31
+ try {
32
+ const request = {
33
+ tokenIn,
34
+ tokenOut,
35
+ amountIn,
36
+ };
37
+ const newQuote = await routerRef.current.getQuote(request);
38
+ setQuote(newQuote);
39
+ }
40
+ catch (err) {
41
+ setError(err instanceof Error ? err : new Error('Failed to get quote'));
42
+ setQuote(null);
43
+ }
44
+ finally {
45
+ setIsLoading(false);
46
+ }
47
+ }, [tokenIn, tokenOut, amountIn, enabled]);
48
+ // Fetch on mount and when inputs change
49
+ useEffect(() => {
50
+ fetchQuote();
51
+ }, [fetchQuote]);
52
+ // Auto-refresh
53
+ useEffect(() => {
54
+ if (!enabled || refreshInterval <= 0)
55
+ return;
56
+ const interval = setInterval(fetchQuote, refreshInterval);
57
+ return () => clearInterval(interval);
58
+ }, [fetchQuote, enabled, refreshInterval]);
59
+ return {
60
+ quote,
61
+ isLoading,
62
+ error,
63
+ refetch: fetchQuote,
64
+ };
65
+ }
@@ -0,0 +1,17 @@
1
+ import type { Address } from 'viem';
2
+ import type { Quote } from '../router';
3
+ interface UseSwapResult {
4
+ swap: (quote: Quote, recipient: Address) => Promise<void>;
5
+ isPending: boolean;
6
+ isConfirming: boolean;
7
+ isSuccess: boolean;
8
+ error: Error | null;
9
+ txHash: `0x${string}` | undefined;
10
+ reset: () => void;
11
+ }
12
+ /**
13
+ * Hook to execute swaps via the DEX precompiles
14
+ */
15
+ export declare function useSwap(): UseSwapResult;
16
+ export {};
17
+ //# sourceMappingURL=use-swap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-swap.d.ts","sourceRoot":"","sources":["../../src/hooks/use-swap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAKnC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,UAAU,aAAa;IACrB,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACzD,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAA;IACjC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,aAAa,CA+EvC"}
@@ -0,0 +1,75 @@
1
+ 'use client';
2
+ import { useState, useCallback } from 'react';
3
+ import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
4
+ import { DEX_PRECOMPILES } from '../precompile/addresses';
5
+ import { SWAP_ROUTER_ABI } from '../precompile/abis';
6
+ import { createPoolKey } from '../precompile/types';
7
+ /**
8
+ * Hook to execute swaps via the DEX precompiles
9
+ */
10
+ export function useSwap() {
11
+ const [error, setError] = useState(null);
12
+ const { data: txHash, writeContractAsync, isPending, reset: resetWrite, } = useWriteContract();
13
+ const { isLoading: isConfirming, isSuccess, } = useWaitForTransactionReceipt({
14
+ hash: txHash,
15
+ });
16
+ const swap = useCallback(async (quote, recipient) => {
17
+ setError(null);
18
+ if (!quote || quote.route.length === 0) {
19
+ setError(new Error('Invalid quote'));
20
+ return;
21
+ }
22
+ const step = quote.route[0];
23
+ if (step.source === 'amm') {
24
+ try {
25
+ // Execute AMM swap via precompile
26
+ const poolKey = createPoolKey(quote.tokenIn, quote.tokenOut);
27
+ const zeroForOne = quote.tokenIn.toLowerCase() < quote.tokenOut.toLowerCase();
28
+ await writeContractAsync({
29
+ address: DEX_PRECOMPILES.SWAP_ROUTER,
30
+ abi: SWAP_ROUTER_ABI,
31
+ functionName: 'exactInputSingle',
32
+ args: [{
33
+ poolKey,
34
+ zeroForOne,
35
+ amountIn: quote.amountIn,
36
+ amountOutMinimum: quote.minimumAmountOut,
37
+ sqrtPriceLimitX96: 0n,
38
+ hookData: '0x',
39
+ }],
40
+ // Include native value if swapping from native LUX
41
+ value: quote.tokenIn === '0x0000000000000000000000000000000000000000'
42
+ ? quote.amountIn
43
+ : 0n,
44
+ });
45
+ }
46
+ catch (err) {
47
+ setError(err instanceof Error ? err : new Error('Swap failed'));
48
+ throw err;
49
+ }
50
+ }
51
+ else if (step.source === 'clob') {
52
+ // CLOB swaps are handled off-chain
53
+ // The frontend should use the CLOB client directly
54
+ setError(new Error('CLOB swaps should be executed via CLOB client'));
55
+ throw new Error('CLOB swaps not supported in this hook');
56
+ }
57
+ else {
58
+ setError(new Error(`Unknown route source: ${step.source}`));
59
+ throw new Error(`Unknown route source: ${step.source}`);
60
+ }
61
+ }, [writeContractAsync]);
62
+ const reset = useCallback(() => {
63
+ setError(null);
64
+ resetWrite();
65
+ }, [resetWrite]);
66
+ return {
67
+ swap,
68
+ isPending,
69
+ isConfirming,
70
+ isSuccess,
71
+ error,
72
+ txHash,
73
+ reset,
74
+ };
75
+ }
package/dist/index.d.ts CHANGED
@@ -1,116 +1,51 @@
1
- import { MarketDataClient, LiquidationMonitor } from './marketData';
2
- export declare enum OrderType {
3
- LIMIT = 0,
4
- MARKET = 1,
5
- STOP = 2,
6
- STOP_LIMIT = 3,
7
- ICEBERG = 4,
8
- PEG = 5
9
- }
10
- export declare enum OrderSide {
11
- BUY = 0,
12
- SELL = 1
13
- }
14
- export declare enum OrderStatus {
15
- OPEN = "open",
16
- PARTIAL = "partial",
17
- FILLED = "filled",
18
- CANCELLED = "cancelled",
19
- REJECTED = "rejected"
20
- }
21
- export declare enum TimeInForce {
22
- GTC = "GTC",
23
- IOC = "IOC",
24
- FOK = "FOK",
25
- DAY = "DAY"
26
- }
27
- export interface Order {
28
- orderId?: number;
29
- symbol: string;
30
- type: OrderType;
31
- side: OrderSide;
32
- price: number;
33
- size: number;
34
- userID?: string;
35
- clientID?: string;
36
- timeInForce?: TimeInForce;
37
- postOnly?: boolean;
38
- reduceOnly?: boolean;
39
- status?: OrderStatus;
40
- filled?: number;
41
- remaining?: number;
42
- timestamp?: number;
43
- }
44
- export interface Trade {
45
- tradeId: number;
46
- symbol: string;
47
- price: number;
48
- size: number;
49
- side: OrderSide;
50
- buyOrderId: number;
51
- sellOrderId: number;
52
- buyerId: string;
53
- sellerId: string;
54
- timestamp: number;
55
- }
56
- export interface OrderBookLevel {
57
- price: number;
58
- size: number;
59
- count?: number;
60
- }
61
- export interface OrderBook {
62
- symbol: string;
63
- bids: OrderBookLevel[];
64
- asks: OrderBookLevel[];
65
- timestamp: number;
66
- }
67
- export interface NodeInfo {
68
- version: string;
69
- network: string;
70
- orderCount: number;
71
- tradeCount: number;
72
- timestamp: number;
73
- }
74
- export interface LXDexConfig {
75
- jsonRpcUrl?: string;
76
- wsUrl?: string;
77
- grpcUrl?: string;
78
- apiKey?: string;
79
- }
80
- export declare class LXDexClient {
81
- private jsonRpc;
82
- private ws;
83
- private wsCallbacks;
84
- private config;
85
- marketData: MarketDataClient;
86
- liquidationMonitor: LiquidationMonitor;
87
- constructor(config?: LXDexConfig);
88
- connect(): Promise<void>;
89
- disconnect(): void;
90
- placeOrder(order: Partial<Order>): Promise<{
91
- orderId: number;
92
- status: string;
93
- }>;
94
- cancelOrder(orderId: number): Promise<{
95
- success: boolean;
96
- message: string;
97
- }>;
98
- getOrder(orderId: number): Promise<Order>;
99
- getOrderBook(symbol?: string, depth?: number): Promise<OrderBook>;
100
- getBestBid(symbol?: string): Promise<number>;
101
- getBestAsk(symbol?: string): Promise<number>;
102
- getTrades(symbol?: string, limit?: number): Promise<Trade[]>;
103
- getInfo(): Promise<NodeInfo>;
104
- ping(): Promise<string>;
105
- subscribe(channel: string, callback: Function): void;
106
- unsubscribe(channel: string, callback?: Function): void;
107
- subscribeOrderBook(symbol: string, callback: (book: OrderBook) => void): void;
108
- subscribeTrades(symbol: string, callback: (trade: Trade) => void): void;
109
- private handleWebSocketMessage;
110
- static formatPrice(price: number, decimals?: number): string;
111
- static formatSize(size: number, decimals?: number): string;
112
- static calculateTotal(price: number, size: number): number;
113
- }
114
- export default LXDexClient;
115
- export * from './marketData';
1
+ /**
2
+ * @luxfi/dex
3
+ *
4
+ * LX Integration Package
5
+ *
6
+ * Native precompile integration for Lux DEX stack:
7
+ * - LXPool (LP-9010): v4-style AMM PoolManager
8
+ * - LXOracle (LP-9011): Multi-source price aggregation
9
+ * - LXRouter (LP-9012): Optimized swap routing
10
+ * - LXHooks (LP-9013): Hook contract registry
11
+ * - LXFlash (LP-9014): Flash loan facility
12
+ * - LXBook (LP-9020): CLOB matching engine
13
+ * - LXVault (LP-9030): Custody and margin engine
14
+ * - LXFeed (LP-9040): Mark price and funding feeds
15
+ *
16
+ * Architecture:
17
+ * ```
18
+ * ┌─────────────────────────────────────────────────────────────┐
19
+ * │ Omnichain Router │
20
+ * │ Best execution between CLOB & AMM │
21
+ * └─────────────────────────┬───────────────────────────────────┘
22
+ * │
23
+ * ┌───────────────────┼───────────────────┐
24
+ * │ │ │
25
+ * ▼ ▼ ▼
26
+ * ┌───────────┐ ┌───────────┐ ┌───────────┐
27
+ * │ LXBook │ │ LXPool │ │ LXVault │
28
+ * │ (LP-9020) │ │ (LP-9010) │ │ (LP-9030) │
29
+ * │ │ │ │ │ │
30
+ * │ • Orders │ │ • Swaps │ │ • Custody │
31
+ * │ • CLOB │ │ • AMM │ │ • Margin │
32
+ * │ • Perps │ │ • Flash │ │ • Liq.
33
+ * └───────────┘ └───────────┘ └───────────┘
34
+ * │ │ │
35
+ * └───────────────────┴───────────────────┘
36
+ * │
37
+ * ┌──────┴──────┐
38
+ * │ LXFeed
39
+ * │ (LP-9040) │
40
+ * │ │
41
+ * │ • Mark Px │
42
+ * │ • Index Px │
43
+ * │ • Funding │
44
+ * └─────────────┘
45
+ * ```
46
+ */
47
+ export { type Currency, type PoolKey, type BalanceDelta, type SwapParams, type ModifyLiquidityParams, type PoolState, type Position as AMMPosition, NATIVE_LUX, sortCurrencies, createPoolKey, TIF, OrderKind, GroupType, ActionType, type LXOrder, type LXAction, type LXPlaceResult, type LXL1, MarginMode, PositionSide, type LXAccount, type LXPosition, type LXMarginInfo, type LXSettlement, type LXLiquidationResult, type LXMarkPrice, type LXFundingRate, POOL_MANAGER_ABI, SWAP_ROUTER_ABI, HOOKS_REGISTRY_ABI, FLASH_LOAN_ABI, LX_BOOK_ABI, LX_VAULT_ABI, LX_FEED_ABI, LX_ORACLE_ABI, LX, DEX_PRECOMPILES, type LxdexPrecompile, type DexPrecompile, fromLP, toLP, isDEXPrecompile, isBridgePrecompile, } from './precompile';
48
+ export { type OrderSide, type OrderType, type OrderStatus, type TimeInForce, type OrderRequest, type Order, type OrderBookEntry, type OrderBook, type Trade, type Position as CLOBPosition, type Balance, type ICLOBClient, CLOBClient, createCLOBClient, } from './client';
49
+ export * from './router';
50
+ export * from './hooks';
116
51
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAMnB,MA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