@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,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Omnichain Router
|
|
3
|
+
* Routes orders between CLOB and AMM for best execution
|
|
4
|
+
*/
|
|
5
|
+
import type { Address, PublicClient } from 'viem'
|
|
6
|
+
import { DEX_PRECOMPILES } from '../precompile/addresses'
|
|
7
|
+
import { POOL_MANAGER_ABI, SWAP_ROUTER_ABI } from '../precompile/abis'
|
|
8
|
+
import { createPoolKey, type PoolKey } from '../precompile/types'
|
|
9
|
+
import type { ICLOBClient } from '../client/types'
|
|
10
|
+
import type {
|
|
11
|
+
RouterConfig,
|
|
12
|
+
QuoteRequest,
|
|
13
|
+
Quote,
|
|
14
|
+
RouteStep,
|
|
15
|
+
SwapRequest,
|
|
16
|
+
SwapResult,
|
|
17
|
+
} from './types'
|
|
18
|
+
|
|
19
|
+
const DEFAULT_CONFIG: RouterConfig = {
|
|
20
|
+
clobEnabled: true,
|
|
21
|
+
ammEnabled: true,
|
|
22
|
+
maxHops: 3,
|
|
23
|
+
preferCLOB: false,
|
|
24
|
+
hybridEnabled: true,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Omnichain Router
|
|
29
|
+
* Best execution routing between CLOB and AMM
|
|
30
|
+
*/
|
|
31
|
+
export class OmnichainRouter {
|
|
32
|
+
private config: RouterConfig
|
|
33
|
+
private publicClient: PublicClient | null = null
|
|
34
|
+
private clobClient: ICLOBClient | null = null
|
|
35
|
+
|
|
36
|
+
constructor(config: Partial<RouterConfig> = {}) {
|
|
37
|
+
this.config = { ...DEFAULT_CONFIG, ...config }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Set the public client for AMM interactions
|
|
42
|
+
*/
|
|
43
|
+
setPublicClient(client: PublicClient) {
|
|
44
|
+
this.publicClient = client
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set the CLOB client
|
|
49
|
+
*/
|
|
50
|
+
setCLOBClient(client: ICLOBClient) {
|
|
51
|
+
this.clobClient = client
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get a quote for a swap
|
|
56
|
+
*/
|
|
57
|
+
async getQuote(request: QuoteRequest): Promise<Quote> {
|
|
58
|
+
const {
|
|
59
|
+
tokenIn,
|
|
60
|
+
tokenOut,
|
|
61
|
+
amountIn,
|
|
62
|
+
slippageTolerance = 50, // 0.5%
|
|
63
|
+
preferredSource,
|
|
64
|
+
} = request
|
|
65
|
+
|
|
66
|
+
const quotes: Quote[] = []
|
|
67
|
+
|
|
68
|
+
// Get AMM quote if enabled
|
|
69
|
+
if (this.config.ammEnabled && (!preferredSource || preferredSource !== 'clob')) {
|
|
70
|
+
try {
|
|
71
|
+
const ammQuote = await this.getAMMQuote(tokenIn, tokenOut, amountIn)
|
|
72
|
+
if (ammQuote) quotes.push(ammQuote)
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.warn('AMM quote failed:', error)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Get CLOB quote if enabled
|
|
79
|
+
if (this.config.clobEnabled && this.clobClient && (!preferredSource || preferredSource !== 'amm')) {
|
|
80
|
+
try {
|
|
81
|
+
const clobQuote = await this.getCLOBQuote(tokenIn, tokenOut, amountIn)
|
|
82
|
+
if (clobQuote) quotes.push(clobQuote)
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.warn('CLOB quote failed:', error)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (quotes.length === 0) {
|
|
89
|
+
throw new Error('No quotes available')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Select best quote (highest output)
|
|
93
|
+
const bestQuote = quotes.reduce((best, quote) =>
|
|
94
|
+
quote.amountOut > best.amountOut ? quote : best
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
// Apply slippage tolerance
|
|
98
|
+
const minimumAmountOut = bestQuote.amountOut - (bestQuote.amountOut * BigInt(slippageTolerance)) / 10000n
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
...bestQuote,
|
|
102
|
+
minimumAmountOut,
|
|
103
|
+
validUntil: Date.now() + 30000, // 30 seconds
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get AMM quote using precompiles
|
|
109
|
+
*/
|
|
110
|
+
private async getAMMQuote(
|
|
111
|
+
tokenIn: Address,
|
|
112
|
+
tokenOut: Address,
|
|
113
|
+
amountIn: bigint
|
|
114
|
+
): Promise<Quote | null> {
|
|
115
|
+
if (!this.publicClient) return null
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
// Create pool key
|
|
119
|
+
const poolKey = createPoolKey(tokenIn, tokenOut)
|
|
120
|
+
const zeroForOne = tokenIn.toLowerCase() < tokenOut.toLowerCase()
|
|
121
|
+
|
|
122
|
+
// Get pool state
|
|
123
|
+
const slot0 = await this.publicClient.readContract({
|
|
124
|
+
address: DEX_PRECOMPILES.POOL_MANAGER,
|
|
125
|
+
abi: POOL_MANAGER_ABI,
|
|
126
|
+
functionName: 'getSlot0',
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
+
args: [poolKey] as any,
|
|
129
|
+
}) as [bigint, number, number, number]
|
|
130
|
+
|
|
131
|
+
if (slot0[0] === 0n) {
|
|
132
|
+
return null // Pool doesn't exist
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Calculate expected output (simplified - real implementation would use tick math)
|
|
136
|
+
// For now, use a simple estimate based on sqrt price
|
|
137
|
+
const sqrtPriceX96 = slot0[0]
|
|
138
|
+
const price = (sqrtPriceX96 * sqrtPriceX96) / (2n ** 192n)
|
|
139
|
+
const amountOut = zeroForOne
|
|
140
|
+
? (amountIn * price) / (10n ** 18n)
|
|
141
|
+
: (amountIn * (10n ** 18n)) / price
|
|
142
|
+
|
|
143
|
+
// Estimate price impact (simplified)
|
|
144
|
+
const priceImpact = Number((amountIn * 10n) / (amountIn + amountOut))
|
|
145
|
+
|
|
146
|
+
const step: RouteStep = {
|
|
147
|
+
source: 'amm',
|
|
148
|
+
tokenIn,
|
|
149
|
+
tokenOut,
|
|
150
|
+
amountIn,
|
|
151
|
+
amountOut,
|
|
152
|
+
pool: DEX_PRECOMPILES.POOL_MANAGER,
|
|
153
|
+
fee: (amountIn * BigInt(poolKey.fee)) / 1_000_000n,
|
|
154
|
+
priceImpact,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
tokenIn,
|
|
159
|
+
tokenOut,
|
|
160
|
+
amountIn,
|
|
161
|
+
amountOut,
|
|
162
|
+
minimumAmountOut: amountOut,
|
|
163
|
+
route: [step],
|
|
164
|
+
priceImpact,
|
|
165
|
+
estimatedGas: 150_000n,
|
|
166
|
+
validUntil: Date.now() + 30000,
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error('AMM quote error:', error)
|
|
170
|
+
return null
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get CLOB quote
|
|
176
|
+
*/
|
|
177
|
+
private async getCLOBQuote(
|
|
178
|
+
tokenIn: Address,
|
|
179
|
+
tokenOut: Address,
|
|
180
|
+
amountIn: bigint
|
|
181
|
+
): Promise<Quote | null> {
|
|
182
|
+
if (!this.clobClient || !this.clobClient.isConnected()) return null
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
// Convert addresses to symbol (e.g., "LUX-USDT")
|
|
186
|
+
const symbol = this.getSymbol(tokenIn, tokenOut)
|
|
187
|
+
if (!symbol) return null
|
|
188
|
+
|
|
189
|
+
const orderBook = await this.clobClient.getOrderBook(symbol, 50)
|
|
190
|
+
|
|
191
|
+
// Calculate output by walking the order book
|
|
192
|
+
let remainingIn = amountIn
|
|
193
|
+
let totalOut = 0n
|
|
194
|
+
const side = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? 'asks' : 'bids'
|
|
195
|
+
const levels = side === 'asks' ? orderBook.asks : orderBook.bids
|
|
196
|
+
|
|
197
|
+
for (const level of levels) {
|
|
198
|
+
if (remainingIn <= 0n) break
|
|
199
|
+
|
|
200
|
+
const levelSize = BigInt(Math.floor(level.size * 1e18))
|
|
201
|
+
const levelPrice = BigInt(Math.floor(level.price * 1e18))
|
|
202
|
+
|
|
203
|
+
const fillSize = remainingIn < levelSize ? remainingIn : levelSize
|
|
204
|
+
const fillOut = side === 'asks'
|
|
205
|
+
? (fillSize * (10n ** 18n)) / levelPrice
|
|
206
|
+
: (fillSize * levelPrice) / (10n ** 18n)
|
|
207
|
+
|
|
208
|
+
totalOut += fillOut
|
|
209
|
+
remainingIn -= fillSize
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (totalOut === 0n) return null
|
|
213
|
+
|
|
214
|
+
// Calculate price impact
|
|
215
|
+
const avgPrice = (amountIn * (10n ** 18n)) / totalOut
|
|
216
|
+
const bestPrice = BigInt(Math.floor(levels[0]?.price * 1e18 || 0))
|
|
217
|
+
const priceImpact = bestPrice > 0n
|
|
218
|
+
? Number(((avgPrice - bestPrice) * 10000n) / bestPrice)
|
|
219
|
+
: 0
|
|
220
|
+
|
|
221
|
+
const step: RouteStep = {
|
|
222
|
+
source: 'clob',
|
|
223
|
+
tokenIn,
|
|
224
|
+
tokenOut,
|
|
225
|
+
amountIn,
|
|
226
|
+
amountOut: totalOut,
|
|
227
|
+
symbol,
|
|
228
|
+
fee: (amountIn * 30n) / 10000n, // 0.3% maker fee estimate
|
|
229
|
+
priceImpact,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
tokenIn,
|
|
234
|
+
tokenOut,
|
|
235
|
+
amountIn,
|
|
236
|
+
amountOut: totalOut,
|
|
237
|
+
minimumAmountOut: totalOut,
|
|
238
|
+
route: [step],
|
|
239
|
+
priceImpact,
|
|
240
|
+
estimatedGas: 50_000n, // CLOB is off-chain
|
|
241
|
+
validUntil: Date.now() + 10000, // 10 seconds (faster expiry for CLOB)
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
console.error('CLOB quote error:', error)
|
|
245
|
+
return null
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Convert token addresses to trading symbol
|
|
251
|
+
*/
|
|
252
|
+
private getSymbol(tokenIn: Address, tokenOut: Address): string | null {
|
|
253
|
+
// TODO: Implement proper token-to-symbol mapping
|
|
254
|
+
// This should look up the token registry
|
|
255
|
+
const tokenMap: Record<string, string> = {
|
|
256
|
+
'0x0000000000000000000000000000000000000000': 'LUX',
|
|
257
|
+
// Add more tokens as needed
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const symbolIn = tokenMap[tokenIn.toLowerCase()]
|
|
261
|
+
const symbolOut = tokenMap[tokenOut.toLowerCase()]
|
|
262
|
+
|
|
263
|
+
if (!symbolIn || !symbolOut) return null
|
|
264
|
+
|
|
265
|
+
return `${symbolIn}-${symbolOut}`
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Execute a swap
|
|
270
|
+
*/
|
|
271
|
+
async executeSwap(request: SwapRequest): Promise<SwapResult> {
|
|
272
|
+
const { quote, recipient, deadline = Math.floor(Date.now() / 1000) + 1200 } = request
|
|
273
|
+
|
|
274
|
+
if (Date.now() > quote.validUntil) {
|
|
275
|
+
throw new Error('Quote expired')
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Determine execution path
|
|
279
|
+
const source = quote.route[0]?.source
|
|
280
|
+
|
|
281
|
+
if (source === 'amm') {
|
|
282
|
+
return this.executeAMMSwap(quote, recipient, deadline)
|
|
283
|
+
} else if (source === 'clob') {
|
|
284
|
+
return this.executeCLOBSwap(quote, recipient)
|
|
285
|
+
} else {
|
|
286
|
+
throw new Error(`Unknown route source: ${source}`)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Execute AMM swap via precompile
|
|
292
|
+
*/
|
|
293
|
+
private async executeAMMSwap(
|
|
294
|
+
quote: Quote,
|
|
295
|
+
recipient: Address,
|
|
296
|
+
deadline: number
|
|
297
|
+
): Promise<SwapResult> {
|
|
298
|
+
// This would be called by the wallet/wagmi on the frontend
|
|
299
|
+
// Just return the transaction parameters
|
|
300
|
+
throw new Error('AMM swap execution should be handled by wagmi writeContract')
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Execute CLOB swap
|
|
305
|
+
*/
|
|
306
|
+
private async executeCLOBSwap(quote: Quote, recipient: Address): Promise<SwapResult> {
|
|
307
|
+
if (!this.clobClient) {
|
|
308
|
+
throw new Error('CLOB client not configured')
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const step = quote.route[0]
|
|
312
|
+
if (!step?.symbol) {
|
|
313
|
+
throw new Error('Invalid CLOB route')
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Place market order on CLOB
|
|
317
|
+
const order = await this.clobClient.placeOrder({
|
|
318
|
+
symbol: step.symbol,
|
|
319
|
+
side: step.tokenIn.toLowerCase() < step.tokenOut.toLowerCase() ? 'buy' : 'sell',
|
|
320
|
+
type: 'market',
|
|
321
|
+
size: Number(quote.amountIn) / 1e18,
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
txHash: `0x${order.orderId}` as `0x${string}`,
|
|
326
|
+
amountIn: quote.amountIn,
|
|
327
|
+
amountOut: quote.amountOut,
|
|
328
|
+
route: quote.route,
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Create an omnichain router instance
|
|
335
|
+
*/
|
|
336
|
+
export function createRouter(config?: Partial<RouterConfig>): OmnichainRouter {
|
|
337
|
+
return new OmnichainRouter(config)
|
|
338
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router Types
|
|
3
|
+
* Types for hybrid CLOB + AMM routing
|
|
4
|
+
*/
|
|
5
|
+
import type { Address } from 'viem'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Route source - where liquidity comes from
|
|
9
|
+
*/
|
|
10
|
+
export type RouteSource = 'clob' | 'amm' | 'hybrid'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Quote request
|
|
14
|
+
*/
|
|
15
|
+
export interface QuoteRequest {
|
|
16
|
+
tokenIn: Address
|
|
17
|
+
tokenOut: Address
|
|
18
|
+
amountIn: bigint
|
|
19
|
+
slippageTolerance?: number // basis points (default 50 = 0.5%)
|
|
20
|
+
preferredSource?: RouteSource
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Route step
|
|
25
|
+
*/
|
|
26
|
+
export interface RouteStep {
|
|
27
|
+
source: RouteSource
|
|
28
|
+
tokenIn: Address
|
|
29
|
+
tokenOut: Address
|
|
30
|
+
amountIn: bigint
|
|
31
|
+
amountOut: bigint
|
|
32
|
+
pool?: Address // For AMM
|
|
33
|
+
symbol?: string // For CLOB
|
|
34
|
+
fee: bigint
|
|
35
|
+
priceImpact: number // basis points
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Quote response
|
|
40
|
+
*/
|
|
41
|
+
export interface Quote {
|
|
42
|
+
tokenIn: Address
|
|
43
|
+
tokenOut: Address
|
|
44
|
+
amountIn: bigint
|
|
45
|
+
amountOut: bigint
|
|
46
|
+
minimumAmountOut: bigint
|
|
47
|
+
route: RouteStep[]
|
|
48
|
+
priceImpact: number // total price impact in basis points
|
|
49
|
+
estimatedGas: bigint
|
|
50
|
+
validUntil: number // timestamp
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Swap request
|
|
55
|
+
*/
|
|
56
|
+
export interface SwapRequest {
|
|
57
|
+
quote: Quote
|
|
58
|
+
recipient: Address
|
|
59
|
+
deadline?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Swap result
|
|
64
|
+
*/
|
|
65
|
+
export interface SwapResult {
|
|
66
|
+
txHash: `0x${string}`
|
|
67
|
+
amountIn: bigint
|
|
68
|
+
amountOut: bigint
|
|
69
|
+
route: RouteStep[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Router configuration
|
|
74
|
+
*/
|
|
75
|
+
export interface RouterConfig {
|
|
76
|
+
// CLOB connection
|
|
77
|
+
clobUrl?: string
|
|
78
|
+
clobEnabled?: boolean
|
|
79
|
+
|
|
80
|
+
// AMM configuration
|
|
81
|
+
ammEnabled?: boolean
|
|
82
|
+
maxHops?: number // max number of AMM hops
|
|
83
|
+
|
|
84
|
+
// Routing preferences
|
|
85
|
+
preferCLOB?: boolean // prefer CLOB for limit orders
|
|
86
|
+
hybridEnabled?: boolean // allow splitting between CLOB and AMM
|
|
87
|
+
}
|
package/dist/marketData.d.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Market data, liquidation, and settlement features for LX TypeScript SDK
|
|
3
|
-
*/
|
|
4
|
-
import WebSocket from 'ws';
|
|
5
|
-
export interface MarketDataSource {
|
|
6
|
-
name: string;
|
|
7
|
-
symbol: string;
|
|
8
|
-
price: number;
|
|
9
|
-
bid: number;
|
|
10
|
-
ask: number;
|
|
11
|
-
volume: number;
|
|
12
|
-
latencyNs: number;
|
|
13
|
-
provider: string;
|
|
14
|
-
}
|
|
15
|
-
export interface LiquidationInfo {
|
|
16
|
-
userId: string;
|
|
17
|
-
positionId: string;
|
|
18
|
-
symbol: string;
|
|
19
|
-
size: number;
|
|
20
|
-
liquidationPrice: number;
|
|
21
|
-
markPrice: number;
|
|
22
|
-
status: string;
|
|
23
|
-
timestamp: Date;
|
|
24
|
-
}
|
|
25
|
-
export interface SettlementBatch {
|
|
26
|
-
batchId: number;
|
|
27
|
-
orderIds: number[];
|
|
28
|
-
status: string;
|
|
29
|
-
txHash?: string;
|
|
30
|
-
gasUsed?: number;
|
|
31
|
-
timestamp: Date;
|
|
32
|
-
}
|
|
33
|
-
export interface MarginInfo {
|
|
34
|
-
userId: string;
|
|
35
|
-
initialMargin: number;
|
|
36
|
-
maintenanceMargin: number;
|
|
37
|
-
marginRatio: number;
|
|
38
|
-
freeMargin: number;
|
|
39
|
-
marginLevel: number;
|
|
40
|
-
}
|
|
41
|
-
export interface InsuranceFundStatus {
|
|
42
|
-
totalFund: number;
|
|
43
|
-
availableFund: number;
|
|
44
|
-
usedFund: number;
|
|
45
|
-
pendingClaims: number;
|
|
46
|
-
lastUpdate: Date;
|
|
47
|
-
}
|
|
48
|
-
export interface MarketStats {
|
|
49
|
-
symbol: string;
|
|
50
|
-
volume24h: number;
|
|
51
|
-
high24h: number;
|
|
52
|
-
low24h: number;
|
|
53
|
-
priceChange24h: number;
|
|
54
|
-
priceChangePercent24h: number;
|
|
55
|
-
openInterest: number;
|
|
56
|
-
fundingRate: number;
|
|
57
|
-
nextFundingTime: Date;
|
|
58
|
-
}
|
|
59
|
-
export interface LiquidationRisk {
|
|
60
|
-
userId: string;
|
|
61
|
-
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
62
|
-
marginLevel: number;
|
|
63
|
-
liquidationPrice: number;
|
|
64
|
-
timeToLiquidation: number | null;
|
|
65
|
-
recommendations: string[];
|
|
66
|
-
}
|
|
67
|
-
export declare class MarketDataClient {
|
|
68
|
-
private jsonRpc;
|
|
69
|
-
constructor(jsonRpcClient: any);
|
|
70
|
-
/**
|
|
71
|
-
* Get market data from a specific source
|
|
72
|
-
*/
|
|
73
|
-
getMarketData(symbol: string, source: string): Promise<MarketDataSource>;
|
|
74
|
-
/**
|
|
75
|
-
* Get aggregated market data from all sources
|
|
76
|
-
*/
|
|
77
|
-
getAggregatedMarketData(symbol: string): Promise<MarketDataSource[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Get recent liquidations
|
|
80
|
-
*/
|
|
81
|
-
getLiquidations(symbol: string, limit?: number): Promise<LiquidationInfo[]>;
|
|
82
|
-
/**
|
|
83
|
-
* Get settlement batch information
|
|
84
|
-
*/
|
|
85
|
-
getSettlementBatch(batchId: number): Promise<SettlementBatch>;
|
|
86
|
-
/**
|
|
87
|
-
* Get margin information for a user
|
|
88
|
-
*/
|
|
89
|
-
getMarginInfo(userId: string): Promise<MarginInfo>;
|
|
90
|
-
/**
|
|
91
|
-
* Check liquidation risk for a user
|
|
92
|
-
*/
|
|
93
|
-
checkLiquidationRisk(userId: string): Promise<LiquidationRisk>;
|
|
94
|
-
/**
|
|
95
|
-
* Get insurance fund status
|
|
96
|
-
*/
|
|
97
|
-
getInsuranceFundStatus(): Promise<InsuranceFundStatus>;
|
|
98
|
-
/**
|
|
99
|
-
* Get list of available market data sources
|
|
100
|
-
*/
|
|
101
|
-
getMarketDataSources(): Promise<string[]>;
|
|
102
|
-
/**
|
|
103
|
-
* Get comprehensive market statistics
|
|
104
|
-
*/
|
|
105
|
-
getMarketStats(symbol: string): Promise<MarketStats>;
|
|
106
|
-
}
|
|
107
|
-
export declare class LiquidationMonitor {
|
|
108
|
-
private ws;
|
|
109
|
-
private callbacks;
|
|
110
|
-
constructor(wsConnection: WebSocket | null);
|
|
111
|
-
/**
|
|
112
|
-
* Set WebSocket connection
|
|
113
|
-
*/
|
|
114
|
-
setWebSocket(ws: WebSocket): void;
|
|
115
|
-
/**
|
|
116
|
-
* Subscribe to liquidation events
|
|
117
|
-
*/
|
|
118
|
-
subscribeLiquidations(callback: (liquidation: LiquidationInfo) => void): void;
|
|
119
|
-
/**
|
|
120
|
-
* Subscribe to settlement events
|
|
121
|
-
*/
|
|
122
|
-
subscribeSettlements(callback: (settlement: SettlementBatch) => void): void;
|
|
123
|
-
/**
|
|
124
|
-
* Subscribe to margin call events for a user
|
|
125
|
-
*/
|
|
126
|
-
subscribeMarginCalls(userId: string, callback: (marginCall: any) => void): void;
|
|
127
|
-
/**
|
|
128
|
-
* Unsubscribe from a channel
|
|
129
|
-
*/
|
|
130
|
-
unsubscribe(channel: string): void;
|
|
131
|
-
/**
|
|
132
|
-
* Handle incoming message
|
|
133
|
-
*/
|
|
134
|
-
handleMessage(channel: string, data: any): void;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Market data sources supported by LX
|
|
138
|
-
*/
|
|
139
|
-
export declare const MarketDataProviders: {
|
|
140
|
-
readonly ALPACA: "alpaca";
|
|
141
|
-
readonly NYSE_ARCA: "nyse_arca";
|
|
142
|
-
readonly IEX_CLOUD: "iex";
|
|
143
|
-
readonly POLYGON: "polygon";
|
|
144
|
-
readonly CME_GROUP: "cme";
|
|
145
|
-
readonly REFINITIV: "refinitiv";
|
|
146
|
-
readonly ICE_DATA: "ice";
|
|
147
|
-
readonly BLOOMBERG: "bloomberg";
|
|
148
|
-
readonly NASDAQ_TOTALVIEW: "nasdaq";
|
|
149
|
-
readonly COINBASE_PRO: "coinbase";
|
|
150
|
-
};
|
|
151
|
-
export type MarketDataProvider = typeof MarketDataProviders[keyof typeof MarketDataProviders];
|
|
152
|
-
//# sourceMappingURL=marketData.d.ts.map
|
package/dist/marketData.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"marketData.d.ts","sourceRoot":"","sources":["../src/marketData.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM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