@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.
- package/dist/client/clob.d.ts +52 -0
- package/dist/client/clob.d.ts.map +1 -0
- package/dist/client/clob.js +196 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/types.d.ts +126 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +5 -0
- package/dist/hooks/index.d.ts +22 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +25 -0
- package/dist/hooks/use-lxbook.d.ts +95 -0
- package/dist/hooks/use-lxbook.d.ts.map +1 -0
- package/dist/hooks/use-lxbook.js +213 -0
- package/dist/hooks/use-lxfeed.d.ts +111 -0
- package/dist/hooks/use-lxfeed.d.ts.map +1 -0
- package/dist/hooks/use-lxfeed.js +152 -0
- package/dist/hooks/use-lxvault.d.ts +137 -0
- package/dist/hooks/use-lxvault.d.ts.map +1 -0
- package/dist/hooks/use-lxvault.js +227 -0
- package/dist/hooks/use-quote.d.ts +18 -0
- package/dist/hooks/use-quote.d.ts.map +1 -0
- package/dist/hooks/use-quote.js +65 -0
- package/dist/hooks/use-swap.d.ts +17 -0
- package/dist/hooks/use-swap.d.ts.map +1 -0
- package/dist/hooks/use-swap.js +75 -0
- package/dist/index.d.ts +50 -115
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +72 -225
- package/dist/precompile/abis.d.ts +991 -0
- package/dist/precompile/abis.d.ts.map +1 -0
- package/dist/precompile/abis.js +743 -0
- package/dist/precompile/addresses.d.ts +129 -0
- package/dist/precompile/addresses.d.ts.map +1 -0
- package/dist/precompile/addresses.js +117 -0
- package/dist/precompile/index.d.ts +19 -0
- package/dist/precompile/index.d.ts.map +1 -0
- package/dist/precompile/index.js +18 -0
- package/dist/precompile/types.d.ts +246 -0
- package/dist/precompile/types.d.ts.map +1 -0
- package/dist/precompile/types.js +84 -0
- package/dist/router/index.d.ts +7 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +6 -0
- package/dist/router/router.d.ts +58 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +272 -0
- package/dist/router/types.d.ts +76 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +1 -0
- package/package.json +55 -29
- package/src/client/clob.ts +256 -0
- package/src/client/index.ts +6 -0
- package/src/client/types.ts +148 -0
- package/src/hooks/index.ts +29 -0
- package/src/hooks/use-lxbook.ts +343 -0
- package/src/hooks/use-lxfeed.ts +179 -0
- package/src/hooks/use-lxvault.ts +318 -0
- package/src/hooks/use-quote.ts +92 -0
- package/src/hooks/use-swap.ts +103 -0
- package/src/index.ts +142 -309
- package/src/precompile/abis.ts +755 -0
- package/src/precompile/addresses.ts +153 -0
- package/src/precompile/index.ts +18 -0
- package/src/precompile/types.ts +295 -0
- package/src/router/index.ts +6 -0
- package/src/router/router.ts +338 -0
- package/src/router/types.ts +87 -0
- package/dist/marketData.d.ts +0 -152
- package/dist/marketData.d.ts.map +0 -1
- package/dist/marketData.js +0 -253
- package/src/marketData.ts +0 -351
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLOB Client
|
|
3
|
+
* WebSocket client for lux/dex order book
|
|
4
|
+
*/
|
|
5
|
+
import type { ICLOBClient, OrderRequest, Order, OrderBook, Trade, Position, Balance } from './types';
|
|
6
|
+
interface CLOBClientOptions {
|
|
7
|
+
url: string;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
reconnect?: boolean;
|
|
10
|
+
reconnectInterval?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Central Limit Order Book client
|
|
14
|
+
* Connects to lux/dex WebSocket server
|
|
15
|
+
*/
|
|
16
|
+
export declare class CLOBClient implements ICLOBClient {
|
|
17
|
+
private ws;
|
|
18
|
+
private url;
|
|
19
|
+
private debug;
|
|
20
|
+
private reconnect;
|
|
21
|
+
private reconnectInterval;
|
|
22
|
+
private connected;
|
|
23
|
+
private authenticated;
|
|
24
|
+
private requestId;
|
|
25
|
+
private pendingRequests;
|
|
26
|
+
private subscriptions;
|
|
27
|
+
constructor(options: CLOBClientOptions);
|
|
28
|
+
private log;
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
isConnected(): boolean;
|
|
32
|
+
private handleMessage;
|
|
33
|
+
private request;
|
|
34
|
+
authenticate(apiKey: string, apiSecret: string): Promise<void>;
|
|
35
|
+
placeOrder(order: OrderRequest): Promise<Order>;
|
|
36
|
+
cancelOrder(orderId: string): Promise<void>;
|
|
37
|
+
getOrder(orderId: string): Promise<Order>;
|
|
38
|
+
getOrders(symbol?: string): Promise<Order[]>;
|
|
39
|
+
getOrderBook(symbol: string, depth?: number): Promise<OrderBook>;
|
|
40
|
+
getTrades(symbol: string, limit?: number): Promise<Trade[]>;
|
|
41
|
+
getPositions(): Promise<Position[]>;
|
|
42
|
+
getBalances(): Promise<Balance[]>;
|
|
43
|
+
subscribeOrderBook(symbol: string, callback: (book: OrderBook) => void): () => void;
|
|
44
|
+
subscribeTrades(symbol: string, callback: (trade: Trade) => void): () => void;
|
|
45
|
+
subscribeOrders(callback: (order: Order) => void): () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a CLOB client
|
|
49
|
+
*/
|
|
50
|
+
export declare function createCLOBClient(url: string, debug?: boolean): ICLOBClient;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=clob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clob.d.ts","sourceRoot":"","sources":["../../src/client/clob.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR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SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,MAAY,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAIhE,YAAY,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAInC,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIvC,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI;IAmBnF,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI;IAmB7E,eAAe,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI;CAkB9D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,WAAW,CAEjF"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central Limit Order Book client
|
|
3
|
+
* Connects to lux/dex WebSocket server
|
|
4
|
+
*/
|
|
5
|
+
export class CLOBClient {
|
|
6
|
+
ws = null;
|
|
7
|
+
url;
|
|
8
|
+
debug;
|
|
9
|
+
reconnect;
|
|
10
|
+
reconnectInterval;
|
|
11
|
+
connected = false;
|
|
12
|
+
authenticated = false;
|
|
13
|
+
requestId = 0;
|
|
14
|
+
pendingRequests = new Map();
|
|
15
|
+
subscriptions = new Map();
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.url = options.url;
|
|
18
|
+
this.debug = options.debug ?? false;
|
|
19
|
+
this.reconnect = options.reconnect ?? true;
|
|
20
|
+
this.reconnectInterval = options.reconnectInterval ?? 5000;
|
|
21
|
+
}
|
|
22
|
+
log(...args) {
|
|
23
|
+
if (this.debug) {
|
|
24
|
+
console.log('[CLOBClient]', ...args);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
try {
|
|
30
|
+
this.ws = new WebSocket(this.url);
|
|
31
|
+
this.ws.onopen = () => {
|
|
32
|
+
this.connected = true;
|
|
33
|
+
this.log('Connected to', this.url);
|
|
34
|
+
resolve();
|
|
35
|
+
};
|
|
36
|
+
this.ws.onclose = () => {
|
|
37
|
+
this.connected = false;
|
|
38
|
+
this.authenticated = false;
|
|
39
|
+
this.log('Disconnected');
|
|
40
|
+
if (this.reconnect) {
|
|
41
|
+
setTimeout(() => this.connect(), this.reconnectInterval);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
this.ws.onerror = (error) => {
|
|
45
|
+
this.log('Error:', error);
|
|
46
|
+
reject(error);
|
|
47
|
+
};
|
|
48
|
+
this.ws.onmessage = (event) => {
|
|
49
|
+
this.handleMessage(event.data);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
reject(error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async disconnect() {
|
|
58
|
+
this.reconnect = false;
|
|
59
|
+
this.ws?.close();
|
|
60
|
+
this.ws = null;
|
|
61
|
+
this.connected = false;
|
|
62
|
+
this.authenticated = false;
|
|
63
|
+
}
|
|
64
|
+
isConnected() {
|
|
65
|
+
return this.connected;
|
|
66
|
+
}
|
|
67
|
+
handleMessage(data) {
|
|
68
|
+
try {
|
|
69
|
+
const message = JSON.parse(data);
|
|
70
|
+
this.log('Received:', message);
|
|
71
|
+
// Handle response to request
|
|
72
|
+
if (message.id && this.pendingRequests.has(message.id)) {
|
|
73
|
+
const { resolve, reject } = this.pendingRequests.get(message.id);
|
|
74
|
+
this.pendingRequests.delete(message.id);
|
|
75
|
+
if (message.error) {
|
|
76
|
+
reject(new Error(message.error));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
resolve(message.result || message);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Handle subscription updates
|
|
84
|
+
const type = message.type || message.channel;
|
|
85
|
+
if (type && this.subscriptions.has(type)) {
|
|
86
|
+
this.subscriptions.get(type).forEach(handler => handler(message));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.log('Parse error:', error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async request(method, params) {
|
|
94
|
+
if (!this.connected) {
|
|
95
|
+
throw new Error('Not connected');
|
|
96
|
+
}
|
|
97
|
+
const id = ++this.requestId;
|
|
98
|
+
const message = {
|
|
99
|
+
jsonrpc: '2.0',
|
|
100
|
+
id,
|
|
101
|
+
method,
|
|
102
|
+
params,
|
|
103
|
+
};
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
this.pendingRequests.set(id, { resolve, reject });
|
|
106
|
+
this.ws.send(JSON.stringify(message));
|
|
107
|
+
this.log('Sent:', message);
|
|
108
|
+
// Timeout after 30 seconds
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
if (this.pendingRequests.has(id)) {
|
|
111
|
+
this.pendingRequests.delete(id);
|
|
112
|
+
reject(new Error('Request timeout'));
|
|
113
|
+
}
|
|
114
|
+
}, 30000);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async authenticate(apiKey, apiSecret) {
|
|
118
|
+
await this.request('authenticate', { apiKey, apiSecret });
|
|
119
|
+
this.authenticated = true;
|
|
120
|
+
}
|
|
121
|
+
async placeOrder(order) {
|
|
122
|
+
return this.request('placeOrder', order);
|
|
123
|
+
}
|
|
124
|
+
async cancelOrder(orderId) {
|
|
125
|
+
await this.request('cancelOrder', { orderId });
|
|
126
|
+
}
|
|
127
|
+
async getOrder(orderId) {
|
|
128
|
+
return this.request('getOrder', { orderId });
|
|
129
|
+
}
|
|
130
|
+
async getOrders(symbol) {
|
|
131
|
+
return this.request('getOrders', { symbol });
|
|
132
|
+
}
|
|
133
|
+
async getOrderBook(symbol, depth = 20) {
|
|
134
|
+
return this.request('getOrderBook', { symbol, depth });
|
|
135
|
+
}
|
|
136
|
+
async getTrades(symbol, limit = 100) {
|
|
137
|
+
return this.request('getTrades', { symbol, limit });
|
|
138
|
+
}
|
|
139
|
+
async getPositions() {
|
|
140
|
+
return this.request('getPositions', {});
|
|
141
|
+
}
|
|
142
|
+
async getBalances() {
|
|
143
|
+
return this.request('getBalances', {});
|
|
144
|
+
}
|
|
145
|
+
subscribeOrderBook(symbol, callback) {
|
|
146
|
+
const channel = `orderbook:${symbol}`;
|
|
147
|
+
if (!this.subscriptions.has(channel)) {
|
|
148
|
+
this.subscriptions.set(channel, new Set());
|
|
149
|
+
this.request('subscribe', { channel: 'orderbook', symbol }).catch(console.error);
|
|
150
|
+
}
|
|
151
|
+
this.subscriptions.get(channel).add(callback);
|
|
152
|
+
return () => {
|
|
153
|
+
this.subscriptions.get(channel)?.delete(callback);
|
|
154
|
+
if (this.subscriptions.get(channel)?.size === 0) {
|
|
155
|
+
this.subscriptions.delete(channel);
|
|
156
|
+
this.request('unsubscribe', { channel: 'orderbook', symbol }).catch(console.error);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
subscribeTrades(symbol, callback) {
|
|
161
|
+
const channel = `trades:${symbol}`;
|
|
162
|
+
if (!this.subscriptions.has(channel)) {
|
|
163
|
+
this.subscriptions.set(channel, new Set());
|
|
164
|
+
this.request('subscribe', { channel: 'trades', symbol }).catch(console.error);
|
|
165
|
+
}
|
|
166
|
+
this.subscriptions.get(channel).add(callback);
|
|
167
|
+
return () => {
|
|
168
|
+
this.subscriptions.get(channel)?.delete(callback);
|
|
169
|
+
if (this.subscriptions.get(channel)?.size === 0) {
|
|
170
|
+
this.subscriptions.delete(channel);
|
|
171
|
+
this.request('unsubscribe', { channel: 'trades', symbol }).catch(console.error);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
subscribeOrders(callback) {
|
|
176
|
+
const channel = 'orders';
|
|
177
|
+
if (!this.subscriptions.has(channel)) {
|
|
178
|
+
this.subscriptions.set(channel, new Set());
|
|
179
|
+
this.request('subscribe', { channel: 'orders' }).catch(console.error);
|
|
180
|
+
}
|
|
181
|
+
this.subscriptions.get(channel).add(callback);
|
|
182
|
+
return () => {
|
|
183
|
+
this.subscriptions.get(channel)?.delete(callback);
|
|
184
|
+
if (this.subscriptions.get(channel)?.size === 0) {
|
|
185
|
+
this.subscriptions.delete(channel);
|
|
186
|
+
this.request('unsubscribe', { channel: 'orders' }).catch(console.error);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a CLOB client
|
|
193
|
+
*/
|
|
194
|
+
export function createCLOBClient(url, debug = false) {
|
|
195
|
+
return new CLOBClient({ url, debug });
|
|
196
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLOB Client Types
|
|
3
|
+
* Interfaces for Central Limit Order Book operations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Order side
|
|
7
|
+
*/
|
|
8
|
+
export type OrderSide = 'buy' | 'sell';
|
|
9
|
+
/**
|
|
10
|
+
* Order type
|
|
11
|
+
*/
|
|
12
|
+
export type OrderType = 'limit' | 'market' | 'stop' | 'stop_limit';
|
|
13
|
+
/**
|
|
14
|
+
* Order status
|
|
15
|
+
*/
|
|
16
|
+
export type OrderStatus = 'pending' | 'open' | 'partial' | 'filled' | 'cancelled' | 'rejected';
|
|
17
|
+
/**
|
|
18
|
+
* Time in force
|
|
19
|
+
*/
|
|
20
|
+
export type TimeInForce = 'GTC' | 'IOC' | 'FOK' | 'GTD';
|
|
21
|
+
/**
|
|
22
|
+
* Order request
|
|
23
|
+
*/
|
|
24
|
+
export interface OrderRequest {
|
|
25
|
+
symbol: string;
|
|
26
|
+
side: OrderSide;
|
|
27
|
+
type: OrderType;
|
|
28
|
+
price?: number;
|
|
29
|
+
size: number;
|
|
30
|
+
timeInForce?: TimeInForce;
|
|
31
|
+
clientOrderId?: string;
|
|
32
|
+
reduceOnly?: boolean;
|
|
33
|
+
postOnly?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Order response
|
|
37
|
+
*/
|
|
38
|
+
export interface Order {
|
|
39
|
+
orderId: string;
|
|
40
|
+
clientOrderId?: string;
|
|
41
|
+
symbol: string;
|
|
42
|
+
side: OrderSide;
|
|
43
|
+
type: OrderType;
|
|
44
|
+
price: number;
|
|
45
|
+
size: number;
|
|
46
|
+
filledSize: number;
|
|
47
|
+
remainingSize: number;
|
|
48
|
+
status: OrderStatus;
|
|
49
|
+
timeInForce: TimeInForce;
|
|
50
|
+
createdAt: number;
|
|
51
|
+
updatedAt: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Order book entry
|
|
55
|
+
*/
|
|
56
|
+
export interface OrderBookEntry {
|
|
57
|
+
price: number;
|
|
58
|
+
size: number;
|
|
59
|
+
count: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Order book
|
|
63
|
+
*/
|
|
64
|
+
export interface OrderBook {
|
|
65
|
+
symbol: string;
|
|
66
|
+
bids: OrderBookEntry[];
|
|
67
|
+
asks: OrderBookEntry[];
|
|
68
|
+
timestamp: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Trade
|
|
72
|
+
*/
|
|
73
|
+
export interface Trade {
|
|
74
|
+
tradeId: string;
|
|
75
|
+
symbol: string;
|
|
76
|
+
side: OrderSide;
|
|
77
|
+
price: number;
|
|
78
|
+
size: number;
|
|
79
|
+
timestamp: number;
|
|
80
|
+
makerOrderId: string;
|
|
81
|
+
takerOrderId: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Position
|
|
85
|
+
*/
|
|
86
|
+
export interface Position {
|
|
87
|
+
symbol: string;
|
|
88
|
+
side: 'long' | 'short';
|
|
89
|
+
size: number;
|
|
90
|
+
entryPrice: number;
|
|
91
|
+
markPrice: number;
|
|
92
|
+
liquidationPrice: number;
|
|
93
|
+
unrealizedPnl: number;
|
|
94
|
+
margin: number;
|
|
95
|
+
leverage: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Balance
|
|
99
|
+
*/
|
|
100
|
+
export interface Balance {
|
|
101
|
+
currency: string;
|
|
102
|
+
available: number;
|
|
103
|
+
locked: number;
|
|
104
|
+
total: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* CLOB client interface
|
|
108
|
+
*/
|
|
109
|
+
export interface ICLOBClient {
|
|
110
|
+
connect(): Promise<void>;
|
|
111
|
+
disconnect(): Promise<void>;
|
|
112
|
+
isConnected(): boolean;
|
|
113
|
+
authenticate(apiKey: string, apiSecret: string): Promise<void>;
|
|
114
|
+
placeOrder(order: OrderRequest): Promise<Order>;
|
|
115
|
+
cancelOrder(orderId: string): Promise<void>;
|
|
116
|
+
getOrder(orderId: string): Promise<Order>;
|
|
117
|
+
getOrders(symbol?: string): Promise<Order[]>;
|
|
118
|
+
getOrderBook(symbol: string, depth?: number): Promise<OrderBook>;
|
|
119
|
+
getTrades(symbol: string, limit?: number): Promise<Trade[]>;
|
|
120
|
+
getPositions(): Promise<Position[]>;
|
|
121
|
+
getBalances(): Promise<Balance[]>;
|
|
122
|
+
subscribeOrderBook(symbol: string, callback: (book: OrderBook) => void): () => void;
|
|
123
|
+
subscribeTrades(symbol: string, callback: (trade: Trade) => void): () => void;
|
|
124
|
+
subscribeOrders(callback: (order: Order) => void): () => void;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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
|
+
*
|
|
8
|
+
* CLOB (LP-9020):
|
|
9
|
+
* - useLXBookL1, useLXBookPlaceOrder, useLXBookCancelOrder
|
|
10
|
+
*
|
|
11
|
+
* Vault (LP-9030):
|
|
12
|
+
* - useLXVault, useLXVaultPosition, useLXVaultMargin
|
|
13
|
+
*
|
|
14
|
+
* Feeds (LP-9040):
|
|
15
|
+
* - useLXFeedMarkPrice, useLXFeedFundingRate, useLXMarketPrices
|
|
16
|
+
*/
|
|
17
|
+
export * from './use-quote';
|
|
18
|
+
export * from './use-swap';
|
|
19
|
+
export * from './use-lxbook';
|
|
20
|
+
export * from './use-lxvault';
|
|
21
|
+
export * from './use-lxfeed';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAG1B,cAAc,cAAc,CAAA;AAG5B,cAAc,eAAe,CAAA;AAG7B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LX Hooks Exports
|
|
3
|
+
* React hooks for DEX integration
|
|
4
|
+
*
|
|
5
|
+
* AMM (LP-9010):
|
|
6
|
+
* - useQuote, useSwap
|
|
7
|
+
*
|
|
8
|
+
* CLOB (LP-9020):
|
|
9
|
+
* - useLXBookL1, useLXBookPlaceOrder, useLXBookCancelOrder
|
|
10
|
+
*
|
|
11
|
+
* Vault (LP-9030):
|
|
12
|
+
* - useLXVault, useLXVaultPosition, useLXVaultMargin
|
|
13
|
+
*
|
|
14
|
+
* Feeds (LP-9040):
|
|
15
|
+
* - useLXFeedMarkPrice, useLXFeedFundingRate, useLXMarketPrices
|
|
16
|
+
*/
|
|
17
|
+
// AMM hooks
|
|
18
|
+
export * from './use-quote';
|
|
19
|
+
export * from './use-swap';
|
|
20
|
+
// LXBook hooks (LP-9020) - CLOB trading
|
|
21
|
+
export * from './use-lxbook';
|
|
22
|
+
// LXVault hooks (LP-9030) - Custody and margin
|
|
23
|
+
export * from './use-lxvault';
|
|
24
|
+
// LXFeed hooks (LP-9040) - Price feeds
|
|
25
|
+
export * from './use-lxfeed';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type LXAction, type LXL1, TIF } from '../precompile/types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get L1 (best bid/ask) for a market
|
|
4
|
+
*/
|
|
5
|
+
export declare function useLXBookL1(marketId: number): {
|
|
6
|
+
l1: LXL1 | undefined;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
error: import("viem").ReadContractErrorType | null;
|
|
9
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
10
|
+
bestBidPxX18: bigint;
|
|
11
|
+
bestBidSzX18: bigint;
|
|
12
|
+
bestAskPxX18: bigint;
|
|
13
|
+
bestAskSzX18: bigint;
|
|
14
|
+
lastTradePxX18: bigint;
|
|
15
|
+
}, import("viem").ReadContractErrorType>>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Hook to get market config
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLXBookMarket(marketId: number): {
|
|
21
|
+
config: {
|
|
22
|
+
baseAsset: `0x${string}`;
|
|
23
|
+
quoteAsset: `0x${string}`;
|
|
24
|
+
tickSizeX18: bigint;
|
|
25
|
+
lotSizeX18: bigint;
|
|
26
|
+
makerFeePpm: number;
|
|
27
|
+
takerFeePpm: number;
|
|
28
|
+
feedId: `0x${string}`;
|
|
29
|
+
initialStatus: number;
|
|
30
|
+
} | undefined;
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
error: import("viem").ReadContractErrorType | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Hook to get market status
|
|
36
|
+
*/
|
|
37
|
+
export declare function useLXBookMarketStatus(marketId: number): {
|
|
38
|
+
status: number | undefined;
|
|
39
|
+
isLoading: boolean;
|
|
40
|
+
error: import("viem").ReadContractErrorType | null;
|
|
41
|
+
};
|
|
42
|
+
interface UseLXBookExecuteResult {
|
|
43
|
+
execute: (action: LXAction) => void;
|
|
44
|
+
executeBatch: (actions: LXAction[]) => void;
|
|
45
|
+
hash: `0x${string}` | undefined;
|
|
46
|
+
isPending: boolean;
|
|
47
|
+
isConfirming: boolean;
|
|
48
|
+
isSuccess: boolean;
|
|
49
|
+
error: Error | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Hook for placing orders via LXBook execute()
|
|
53
|
+
*/
|
|
54
|
+
export declare function useLXBookExecute(): UseLXBookExecuteResult;
|
|
55
|
+
interface UseLXBookPlaceOrderResult {
|
|
56
|
+
placeOrder: (params: {
|
|
57
|
+
marketId: number;
|
|
58
|
+
isBuy: boolean;
|
|
59
|
+
size: bigint;
|
|
60
|
+
price: bigint;
|
|
61
|
+
tif?: TIF;
|
|
62
|
+
reduceOnly?: boolean;
|
|
63
|
+
cloid?: `0x${string}`;
|
|
64
|
+
}) => void;
|
|
65
|
+
placeMarketOrder: (params: {
|
|
66
|
+
marketId: number;
|
|
67
|
+
isBuy: boolean;
|
|
68
|
+
size: bigint;
|
|
69
|
+
reduceOnly?: boolean;
|
|
70
|
+
}) => void;
|
|
71
|
+
hash: `0x${string}` | undefined;
|
|
72
|
+
isPending: boolean;
|
|
73
|
+
isConfirming: boolean;
|
|
74
|
+
isSuccess: boolean;
|
|
75
|
+
error: Error | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook for placing limit orders
|
|
79
|
+
*/
|
|
80
|
+
export declare function useLXBookPlaceOrder(): UseLXBookPlaceOrderResult;
|
|
81
|
+
interface UseLXBookCancelOrderResult {
|
|
82
|
+
cancelByOid: (oid: bigint) => void;
|
|
83
|
+
cancelByCloid: (cloid: `0x${string}`) => void;
|
|
84
|
+
hash: `0x${string}` | undefined;
|
|
85
|
+
isPending: boolean;
|
|
86
|
+
isConfirming: boolean;
|
|
87
|
+
isSuccess: boolean;
|
|
88
|
+
error: Error | null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Hook for canceling orders
|
|
92
|
+
*/
|
|
93
|
+
export declare function useLXBookCancelOrder(): UseLXBookCancelOrderResult;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=use-lxbook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-lxbook.d.ts","sourceRoot":"","sources":["../../src/hooks/use-lxbook.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,KAAK,QAAQ,EAEb,KAAK,IAAI,EAET,GAAG,EAEJ,MAAM,qBAAqB,CAAA;AAE5B;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM;QAS5B,IAAI,GAAG,SAAS;;;;;;;;;;EAK/B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;EAa/C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM;YASlC,MAAM,GAAG,SAAS;;;EAIrC;AAuDD,UAAU,sBAAsB;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAA;IACnC,YAAY,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAA;IAC3C,IAAI,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAA;IAC/B,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,sBAAsB,CAqCzD;AAED,UAAU,yBAAyB;IACjC,UAAU,EAAE,CAAC,MAA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