@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,755 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEX Precompile ABIs (LP-Aligned)
|
|
3
|
+
* Native Go implementation at LP-9010 to LP-9040
|
|
4
|
+
* Address format: 0x0000000000000000000000000000000000LPNUM
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* PoolManager ABI (0x0400)
|
|
9
|
+
* Singleton contract managing all pools
|
|
10
|
+
*/
|
|
11
|
+
export const POOL_MANAGER_ABI = [
|
|
12
|
+
// Initialize a new pool
|
|
13
|
+
{
|
|
14
|
+
type: 'function',
|
|
15
|
+
name: 'initialize',
|
|
16
|
+
inputs: [
|
|
17
|
+
{
|
|
18
|
+
name: 'key',
|
|
19
|
+
type: 'tuple',
|
|
20
|
+
components: [
|
|
21
|
+
{ name: 'currency0', type: 'address' },
|
|
22
|
+
{ name: 'currency1', type: 'address' },
|
|
23
|
+
{ name: 'fee', type: 'uint24' },
|
|
24
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
25
|
+
{ name: 'hooks', type: 'address' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{ name: 'sqrtPriceX96', type: 'uint160' },
|
|
29
|
+
],
|
|
30
|
+
outputs: [{ name: 'tick', type: 'int24' }],
|
|
31
|
+
stateMutability: 'nonpayable',
|
|
32
|
+
},
|
|
33
|
+
// Execute a swap
|
|
34
|
+
{
|
|
35
|
+
type: 'function',
|
|
36
|
+
name: 'swap',
|
|
37
|
+
inputs: [
|
|
38
|
+
{
|
|
39
|
+
name: 'key',
|
|
40
|
+
type: 'tuple',
|
|
41
|
+
components: [
|
|
42
|
+
{ name: 'currency0', type: 'address' },
|
|
43
|
+
{ name: 'currency1', type: 'address' },
|
|
44
|
+
{ name: 'fee', type: 'uint24' },
|
|
45
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
46
|
+
{ name: 'hooks', type: 'address' },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'params',
|
|
51
|
+
type: 'tuple',
|
|
52
|
+
components: [
|
|
53
|
+
{ name: 'zeroForOne', type: 'bool' },
|
|
54
|
+
{ name: 'amountSpecified', type: 'int256' },
|
|
55
|
+
{ name: 'sqrtPriceLimitX96', type: 'uint160' },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{ name: 'hookData', type: 'bytes' },
|
|
59
|
+
],
|
|
60
|
+
outputs: [{ name: 'delta', type: 'int256' }],
|
|
61
|
+
stateMutability: 'nonpayable',
|
|
62
|
+
},
|
|
63
|
+
// Modify liquidity
|
|
64
|
+
{
|
|
65
|
+
type: 'function',
|
|
66
|
+
name: 'modifyLiquidity',
|
|
67
|
+
inputs: [
|
|
68
|
+
{
|
|
69
|
+
name: 'key',
|
|
70
|
+
type: 'tuple',
|
|
71
|
+
components: [
|
|
72
|
+
{ name: 'currency0', type: 'address' },
|
|
73
|
+
{ name: 'currency1', type: 'address' },
|
|
74
|
+
{ name: 'fee', type: 'uint24' },
|
|
75
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
76
|
+
{ name: 'hooks', type: 'address' },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'params',
|
|
81
|
+
type: 'tuple',
|
|
82
|
+
components: [
|
|
83
|
+
{ name: 'tickLower', type: 'int24' },
|
|
84
|
+
{ name: 'tickUpper', type: 'int24' },
|
|
85
|
+
{ name: 'liquidityDelta', type: 'int256' },
|
|
86
|
+
{ name: 'salt', type: 'bytes32' },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{ name: 'hookData', type: 'bytes' },
|
|
90
|
+
],
|
|
91
|
+
outputs: [
|
|
92
|
+
{ name: 'callerDelta', type: 'int256' },
|
|
93
|
+
{ name: 'feesAccrued', type: 'int256' },
|
|
94
|
+
],
|
|
95
|
+
stateMutability: 'nonpayable',
|
|
96
|
+
},
|
|
97
|
+
// Settle outstanding balance
|
|
98
|
+
{
|
|
99
|
+
type: 'function',
|
|
100
|
+
name: 'settle',
|
|
101
|
+
inputs: [{ name: 'currency', type: 'address' }],
|
|
102
|
+
outputs: [{ name: 'amount', type: 'uint256' }],
|
|
103
|
+
stateMutability: 'payable',
|
|
104
|
+
},
|
|
105
|
+
// Take tokens from pool
|
|
106
|
+
{
|
|
107
|
+
type: 'function',
|
|
108
|
+
name: 'take',
|
|
109
|
+
inputs: [
|
|
110
|
+
{ name: 'currency', type: 'address' },
|
|
111
|
+
{ name: 'to', type: 'address' },
|
|
112
|
+
{ name: 'amount', type: 'uint256' },
|
|
113
|
+
],
|
|
114
|
+
outputs: [],
|
|
115
|
+
stateMutability: 'nonpayable',
|
|
116
|
+
},
|
|
117
|
+
// Get pool state
|
|
118
|
+
{
|
|
119
|
+
type: 'function',
|
|
120
|
+
name: 'getSlot0',
|
|
121
|
+
inputs: [
|
|
122
|
+
{
|
|
123
|
+
name: 'key',
|
|
124
|
+
type: 'tuple',
|
|
125
|
+
components: [
|
|
126
|
+
{ name: 'currency0', type: 'address' },
|
|
127
|
+
{ name: 'currency1', type: 'address' },
|
|
128
|
+
{ name: 'fee', type: 'uint24' },
|
|
129
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
130
|
+
{ name: 'hooks', type: 'address' },
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
outputs: [
|
|
135
|
+
{ name: 'sqrtPriceX96', type: 'uint160' },
|
|
136
|
+
{ name: 'tick', type: 'int24' },
|
|
137
|
+
{ name: 'protocolFee', type: 'uint24' },
|
|
138
|
+
{ name: 'lpFee', type: 'uint24' },
|
|
139
|
+
],
|
|
140
|
+
stateMutability: 'view',
|
|
141
|
+
},
|
|
142
|
+
// Get liquidity
|
|
143
|
+
{
|
|
144
|
+
type: 'function',
|
|
145
|
+
name: 'getLiquidity',
|
|
146
|
+
inputs: [
|
|
147
|
+
{
|
|
148
|
+
name: 'key',
|
|
149
|
+
type: 'tuple',
|
|
150
|
+
components: [
|
|
151
|
+
{ name: 'currency0', type: 'address' },
|
|
152
|
+
{ name: 'currency1', type: 'address' },
|
|
153
|
+
{ name: 'fee', type: 'uint24' },
|
|
154
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
155
|
+
{ name: 'hooks', type: 'address' },
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
outputs: [{ name: 'liquidity', type: 'uint128' }],
|
|
160
|
+
stateMutability: 'view',
|
|
161
|
+
},
|
|
162
|
+
] as const
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* SwapRouter ABI (0x0401)
|
|
166
|
+
* Optimized swap routing
|
|
167
|
+
*/
|
|
168
|
+
export const SWAP_ROUTER_ABI = [
|
|
169
|
+
// Single swap (exact input)
|
|
170
|
+
{
|
|
171
|
+
type: 'function',
|
|
172
|
+
name: 'exactInputSingle',
|
|
173
|
+
inputs: [
|
|
174
|
+
{
|
|
175
|
+
name: 'params',
|
|
176
|
+
type: 'tuple',
|
|
177
|
+
components: [
|
|
178
|
+
{
|
|
179
|
+
name: 'poolKey',
|
|
180
|
+
type: 'tuple',
|
|
181
|
+
components: [
|
|
182
|
+
{ name: 'currency0', type: 'address' },
|
|
183
|
+
{ name: 'currency1', type: 'address' },
|
|
184
|
+
{ name: 'fee', type: 'uint24' },
|
|
185
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
186
|
+
{ name: 'hooks', type: 'address' },
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
{ name: 'zeroForOne', type: 'bool' },
|
|
190
|
+
{ name: 'amountIn', type: 'uint256' },
|
|
191
|
+
{ name: 'amountOutMinimum', type: 'uint256' },
|
|
192
|
+
{ name: 'sqrtPriceLimitX96', type: 'uint160' },
|
|
193
|
+
{ name: 'hookData', type: 'bytes' },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
outputs: [{ name: 'amountOut', type: 'uint256' }],
|
|
198
|
+
stateMutability: 'payable',
|
|
199
|
+
},
|
|
200
|
+
// Single swap (exact output)
|
|
201
|
+
{
|
|
202
|
+
type: 'function',
|
|
203
|
+
name: 'exactOutputSingle',
|
|
204
|
+
inputs: [
|
|
205
|
+
{
|
|
206
|
+
name: 'params',
|
|
207
|
+
type: 'tuple',
|
|
208
|
+
components: [
|
|
209
|
+
{
|
|
210
|
+
name: 'poolKey',
|
|
211
|
+
type: 'tuple',
|
|
212
|
+
components: [
|
|
213
|
+
{ name: 'currency0', type: 'address' },
|
|
214
|
+
{ name: 'currency1', type: 'address' },
|
|
215
|
+
{ name: 'fee', type: 'uint24' },
|
|
216
|
+
{ name: 'tickSpacing', type: 'int24' },
|
|
217
|
+
{ name: 'hooks', type: 'address' },
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
{ name: 'zeroForOne', type: 'bool' },
|
|
221
|
+
{ name: 'amountOut', type: 'uint256' },
|
|
222
|
+
{ name: 'amountInMaximum', type: 'uint256' },
|
|
223
|
+
{ name: 'sqrtPriceLimitX96', type: 'uint160' },
|
|
224
|
+
{ name: 'hookData', type: 'bytes' },
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
outputs: [{ name: 'amountIn', type: 'uint256' }],
|
|
229
|
+
stateMutability: 'payable',
|
|
230
|
+
},
|
|
231
|
+
// Multi-hop swap
|
|
232
|
+
{
|
|
233
|
+
type: 'function',
|
|
234
|
+
name: 'exactInput',
|
|
235
|
+
inputs: [
|
|
236
|
+
{
|
|
237
|
+
name: 'params',
|
|
238
|
+
type: 'tuple',
|
|
239
|
+
components: [
|
|
240
|
+
{ name: 'path', type: 'bytes' },
|
|
241
|
+
{ name: 'amountIn', type: 'uint256' },
|
|
242
|
+
{ name: 'amountOutMinimum', type: 'uint256' },
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
outputs: [{ name: 'amountOut', type: 'uint256' }],
|
|
247
|
+
stateMutability: 'payable',
|
|
248
|
+
},
|
|
249
|
+
] as const
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* HooksRegistry ABI (0x0402)
|
|
253
|
+
* Registry for hook contracts
|
|
254
|
+
*/
|
|
255
|
+
export const HOOKS_REGISTRY_ABI = [
|
|
256
|
+
{
|
|
257
|
+
type: 'function',
|
|
258
|
+
name: 'registerHook',
|
|
259
|
+
inputs: [
|
|
260
|
+
{ name: 'hook', type: 'address' },
|
|
261
|
+
{ name: 'permissions', type: 'uint256' },
|
|
262
|
+
],
|
|
263
|
+
outputs: [],
|
|
264
|
+
stateMutability: 'nonpayable',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
type: 'function',
|
|
268
|
+
name: 'getHookPermissions',
|
|
269
|
+
inputs: [{ name: 'hook', type: 'address' }],
|
|
270
|
+
outputs: [{ name: 'permissions', type: 'uint256' }],
|
|
271
|
+
stateMutability: 'view',
|
|
272
|
+
},
|
|
273
|
+
] as const
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* FlashLoan ABI (0x0403)
|
|
277
|
+
* Flash loan facility
|
|
278
|
+
*/
|
|
279
|
+
export const FLASH_LOAN_ABI = [
|
|
280
|
+
{
|
|
281
|
+
type: 'function',
|
|
282
|
+
name: 'flash',
|
|
283
|
+
inputs: [
|
|
284
|
+
{ name: 'recipient', type: 'address' },
|
|
285
|
+
{ name: 'currency', type: 'address' },
|
|
286
|
+
{ name: 'amount', type: 'uint256' },
|
|
287
|
+
{ name: 'data', type: 'bytes' },
|
|
288
|
+
],
|
|
289
|
+
outputs: [],
|
|
290
|
+
stateMutability: 'nonpayable',
|
|
291
|
+
},
|
|
292
|
+
] as const
|
|
293
|
+
|
|
294
|
+
// ============================================================================
|
|
295
|
+
// LXBook ABI (LP-9020) - CLOB Matching Engine
|
|
296
|
+
// ============================================================================
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* LXBook ABI (LP-9020)
|
|
300
|
+
* Permissionless orderbooks with Hyperliquid-style execute() endpoint
|
|
301
|
+
*/
|
|
302
|
+
export const LX_BOOK_ABI = [
|
|
303
|
+
// Hyperliquid-style execute endpoint
|
|
304
|
+
{
|
|
305
|
+
type: 'function',
|
|
306
|
+
name: 'execute',
|
|
307
|
+
inputs: [
|
|
308
|
+
{
|
|
309
|
+
name: 'action',
|
|
310
|
+
type: 'tuple',
|
|
311
|
+
components: [
|
|
312
|
+
{ name: 'actionType', type: 'uint8' },
|
|
313
|
+
{ name: 'nonce', type: 'uint64' },
|
|
314
|
+
{ name: 'expiresAfter', type: 'uint64' },
|
|
315
|
+
{ name: 'data', type: 'bytes' },
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
outputs: [{ name: 'result', type: 'bytes' }],
|
|
320
|
+
stateMutability: 'nonpayable',
|
|
321
|
+
},
|
|
322
|
+
// Batch execute
|
|
323
|
+
{
|
|
324
|
+
type: 'function',
|
|
325
|
+
name: 'executeBatch',
|
|
326
|
+
inputs: [
|
|
327
|
+
{
|
|
328
|
+
name: 'actions',
|
|
329
|
+
type: 'tuple[]',
|
|
330
|
+
components: [
|
|
331
|
+
{ name: 'actionType', type: 'uint8' },
|
|
332
|
+
{ name: 'nonce', type: 'uint64' },
|
|
333
|
+
{ name: 'expiresAfter', type: 'uint64' },
|
|
334
|
+
{ name: 'data', type: 'bytes' },
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
outputs: [{ name: 'results', type: 'bytes[]' }],
|
|
339
|
+
stateMutability: 'nonpayable',
|
|
340
|
+
},
|
|
341
|
+
// Create market
|
|
342
|
+
{
|
|
343
|
+
type: 'function',
|
|
344
|
+
name: 'createMarket',
|
|
345
|
+
inputs: [
|
|
346
|
+
{
|
|
347
|
+
name: 'cfg',
|
|
348
|
+
type: 'tuple',
|
|
349
|
+
components: [
|
|
350
|
+
{ name: 'baseAsset', type: 'bytes32' },
|
|
351
|
+
{ name: 'quoteAsset', type: 'bytes32' },
|
|
352
|
+
{ name: 'tickSizeX18', type: 'uint128' },
|
|
353
|
+
{ name: 'lotSizeX18', type: 'uint128' },
|
|
354
|
+
{ name: 'makerFeePpm', type: 'uint32' },
|
|
355
|
+
{ name: 'takerFeePpm', type: 'uint32' },
|
|
356
|
+
{ name: 'feedId', type: 'bytes32' },
|
|
357
|
+
{ name: 'initialStatus', type: 'uint8' },
|
|
358
|
+
],
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
outputs: [{ name: 'marketId', type: 'uint32' }],
|
|
362
|
+
stateMutability: 'nonpayable',
|
|
363
|
+
},
|
|
364
|
+
// Get L1 (best bid/ask)
|
|
365
|
+
{
|
|
366
|
+
type: 'function',
|
|
367
|
+
name: 'getL1',
|
|
368
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
369
|
+
outputs: [
|
|
370
|
+
{
|
|
371
|
+
name: 'l1',
|
|
372
|
+
type: 'tuple',
|
|
373
|
+
components: [
|
|
374
|
+
{ name: 'bestBidPxX18', type: 'uint128' },
|
|
375
|
+
{ name: 'bestBidSzX18', type: 'uint128' },
|
|
376
|
+
{ name: 'bestAskPxX18', type: 'uint128' },
|
|
377
|
+
{ name: 'bestAskSzX18', type: 'uint128' },
|
|
378
|
+
{ name: 'lastTradePxX18', type: 'uint128' },
|
|
379
|
+
],
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
stateMutability: 'view',
|
|
383
|
+
},
|
|
384
|
+
// Get market config
|
|
385
|
+
{
|
|
386
|
+
type: 'function',
|
|
387
|
+
name: 'getMarketConfig',
|
|
388
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
389
|
+
outputs: [
|
|
390
|
+
{
|
|
391
|
+
name: 'cfg',
|
|
392
|
+
type: 'tuple',
|
|
393
|
+
components: [
|
|
394
|
+
{ name: 'baseAsset', type: 'bytes32' },
|
|
395
|
+
{ name: 'quoteAsset', type: 'bytes32' },
|
|
396
|
+
{ name: 'tickSizeX18', type: 'uint128' },
|
|
397
|
+
{ name: 'lotSizeX18', type: 'uint128' },
|
|
398
|
+
{ name: 'makerFeePpm', type: 'uint32' },
|
|
399
|
+
{ name: 'takerFeePpm', type: 'uint32' },
|
|
400
|
+
{ name: 'feedId', type: 'bytes32' },
|
|
401
|
+
{ name: 'initialStatus', type: 'uint8' },
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
stateMutability: 'view',
|
|
406
|
+
},
|
|
407
|
+
// Get market status
|
|
408
|
+
{
|
|
409
|
+
type: 'function',
|
|
410
|
+
name: 'getMarketStatus',
|
|
411
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
412
|
+
outputs: [{ name: 'status', type: 'uint8' }],
|
|
413
|
+
stateMutability: 'view',
|
|
414
|
+
},
|
|
415
|
+
] as const
|
|
416
|
+
|
|
417
|
+
// ============================================================================
|
|
418
|
+
// LXVault ABI (LP-9030) - Custody and Risk Engine
|
|
419
|
+
// ============================================================================
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* LXVault ABI (LP-9030)
|
|
423
|
+
* Balances, margin, collateral, liquidations
|
|
424
|
+
*/
|
|
425
|
+
export const LX_VAULT_ABI = [
|
|
426
|
+
// Deposit
|
|
427
|
+
{
|
|
428
|
+
type: 'function',
|
|
429
|
+
name: 'deposit',
|
|
430
|
+
inputs: [
|
|
431
|
+
{ name: 'token', type: 'address' },
|
|
432
|
+
{ name: 'amount', type: 'uint128' },
|
|
433
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
434
|
+
],
|
|
435
|
+
outputs: [],
|
|
436
|
+
stateMutability: 'nonpayable',
|
|
437
|
+
},
|
|
438
|
+
// Withdraw
|
|
439
|
+
{
|
|
440
|
+
type: 'function',
|
|
441
|
+
name: 'withdraw',
|
|
442
|
+
inputs: [
|
|
443
|
+
{ name: 'token', type: 'address' },
|
|
444
|
+
{ name: 'amount', type: 'uint128' },
|
|
445
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
446
|
+
],
|
|
447
|
+
outputs: [],
|
|
448
|
+
stateMutability: 'nonpayable',
|
|
449
|
+
},
|
|
450
|
+
// Transfer between subaccounts
|
|
451
|
+
{
|
|
452
|
+
type: 'function',
|
|
453
|
+
name: 'transfer',
|
|
454
|
+
inputs: [
|
|
455
|
+
{ name: 'token', type: 'address' },
|
|
456
|
+
{ name: 'amount', type: 'uint128' },
|
|
457
|
+
{ name: 'fromSubaccount', type: 'uint8' },
|
|
458
|
+
{ name: 'toSubaccount', type: 'uint8' },
|
|
459
|
+
],
|
|
460
|
+
outputs: [],
|
|
461
|
+
stateMutability: 'nonpayable',
|
|
462
|
+
},
|
|
463
|
+
// Get balance
|
|
464
|
+
{
|
|
465
|
+
type: 'function',
|
|
466
|
+
name: 'getBalance',
|
|
467
|
+
inputs: [
|
|
468
|
+
{
|
|
469
|
+
name: 'account',
|
|
470
|
+
type: 'tuple',
|
|
471
|
+
components: [
|
|
472
|
+
{ name: 'main', type: 'address' },
|
|
473
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
474
|
+
],
|
|
475
|
+
},
|
|
476
|
+
{ name: 'token', type: 'address' },
|
|
477
|
+
],
|
|
478
|
+
outputs: [{ name: 'balance', type: 'uint128' }],
|
|
479
|
+
stateMutability: 'view',
|
|
480
|
+
},
|
|
481
|
+
// Get position
|
|
482
|
+
{
|
|
483
|
+
type: 'function',
|
|
484
|
+
name: 'getPosition',
|
|
485
|
+
inputs: [
|
|
486
|
+
{
|
|
487
|
+
name: 'account',
|
|
488
|
+
type: 'tuple',
|
|
489
|
+
components: [
|
|
490
|
+
{ name: 'main', type: 'address' },
|
|
491
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
492
|
+
],
|
|
493
|
+
},
|
|
494
|
+
{ name: 'marketId', type: 'uint32' },
|
|
495
|
+
],
|
|
496
|
+
outputs: [
|
|
497
|
+
{
|
|
498
|
+
name: 'position',
|
|
499
|
+
type: 'tuple',
|
|
500
|
+
components: [
|
|
501
|
+
{ name: 'marketId', type: 'uint32' },
|
|
502
|
+
{ name: 'side', type: 'uint8' },
|
|
503
|
+
{ name: 'sizeX18', type: 'uint128' },
|
|
504
|
+
{ name: 'entryPxX18', type: 'uint128' },
|
|
505
|
+
{ name: 'unrealizedPnlX18', type: 'uint128' },
|
|
506
|
+
{ name: 'accumulatedFundingX18', type: 'int128' },
|
|
507
|
+
{ name: 'lastFundingTime', type: 'uint64' },
|
|
508
|
+
],
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
stateMutability: 'view',
|
|
512
|
+
},
|
|
513
|
+
// Get margin info
|
|
514
|
+
{
|
|
515
|
+
type: 'function',
|
|
516
|
+
name: 'getMargin',
|
|
517
|
+
inputs: [
|
|
518
|
+
{
|
|
519
|
+
name: 'account',
|
|
520
|
+
type: 'tuple',
|
|
521
|
+
components: [
|
|
522
|
+
{ name: 'main', type: 'address' },
|
|
523
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
524
|
+
],
|
|
525
|
+
},
|
|
526
|
+
],
|
|
527
|
+
outputs: [
|
|
528
|
+
{
|
|
529
|
+
name: 'info',
|
|
530
|
+
type: 'tuple',
|
|
531
|
+
components: [
|
|
532
|
+
{ name: 'totalCollateralX18', type: 'uint128' },
|
|
533
|
+
{ name: 'usedMarginX18', type: 'uint128' },
|
|
534
|
+
{ name: 'freeMarginX18', type: 'uint128' },
|
|
535
|
+
{ name: 'marginRatioX18', type: 'uint128' },
|
|
536
|
+
{ name: 'maintenanceMarginX18', type: 'uint128' },
|
|
537
|
+
{ name: 'liquidatable', type: 'bool' },
|
|
538
|
+
],
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
stateMutability: 'view',
|
|
542
|
+
},
|
|
543
|
+
// Check if liquidatable
|
|
544
|
+
{
|
|
545
|
+
type: 'function',
|
|
546
|
+
name: 'isLiquidatable',
|
|
547
|
+
inputs: [
|
|
548
|
+
{
|
|
549
|
+
name: 'account',
|
|
550
|
+
type: 'tuple',
|
|
551
|
+
components: [
|
|
552
|
+
{ name: 'main', type: 'address' },
|
|
553
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
554
|
+
],
|
|
555
|
+
},
|
|
556
|
+
],
|
|
557
|
+
outputs: [
|
|
558
|
+
{ name: 'liquidatable', type: 'bool' },
|
|
559
|
+
{ name: 'shortfall', type: 'uint128' },
|
|
560
|
+
],
|
|
561
|
+
stateMutability: 'view',
|
|
562
|
+
},
|
|
563
|
+
// Liquidate
|
|
564
|
+
{
|
|
565
|
+
type: 'function',
|
|
566
|
+
name: 'liquidate',
|
|
567
|
+
inputs: [
|
|
568
|
+
{
|
|
569
|
+
name: 'account',
|
|
570
|
+
type: 'tuple',
|
|
571
|
+
components: [
|
|
572
|
+
{ name: 'main', type: 'address' },
|
|
573
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
574
|
+
],
|
|
575
|
+
},
|
|
576
|
+
{ name: 'marketId', type: 'uint32' },
|
|
577
|
+
{ name: 'sizeX18', type: 'uint128' },
|
|
578
|
+
],
|
|
579
|
+
outputs: [
|
|
580
|
+
{
|
|
581
|
+
name: 'result',
|
|
582
|
+
type: 'tuple',
|
|
583
|
+
components: [
|
|
584
|
+
{
|
|
585
|
+
name: 'liquidated',
|
|
586
|
+
type: 'tuple',
|
|
587
|
+
components: [
|
|
588
|
+
{ name: 'main', type: 'address' },
|
|
589
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
590
|
+
],
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
name: 'liquidator',
|
|
594
|
+
type: 'tuple',
|
|
595
|
+
components: [
|
|
596
|
+
{ name: 'main', type: 'address' },
|
|
597
|
+
{ name: 'subaccountId', type: 'uint8' },
|
|
598
|
+
],
|
|
599
|
+
},
|
|
600
|
+
{ name: 'marketId', type: 'uint32' },
|
|
601
|
+
{ name: 'sizeX18', type: 'uint128' },
|
|
602
|
+
{ name: 'priceX18', type: 'uint128' },
|
|
603
|
+
{ name: 'penaltyX18', type: 'uint128' },
|
|
604
|
+
{ name: 'adlTriggered', type: 'bool' },
|
|
605
|
+
],
|
|
606
|
+
},
|
|
607
|
+
],
|
|
608
|
+
stateMutability: 'nonpayable',
|
|
609
|
+
},
|
|
610
|
+
// Get funding rate
|
|
611
|
+
{
|
|
612
|
+
type: 'function',
|
|
613
|
+
name: 'getFundingRate',
|
|
614
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
615
|
+
outputs: [
|
|
616
|
+
{ name: 'rateX18', type: 'int128' },
|
|
617
|
+
{ name: 'nextFundingTime', type: 'uint64' },
|
|
618
|
+
],
|
|
619
|
+
stateMutability: 'view',
|
|
620
|
+
},
|
|
621
|
+
] as const
|
|
622
|
+
|
|
623
|
+
// ============================================================================
|
|
624
|
+
// LXFeed ABI (LP-9040) - Price Feeds
|
|
625
|
+
// ============================================================================
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* LXFeed ABI (LP-9040)
|
|
629
|
+
* Mark price, index price, funding calculations
|
|
630
|
+
*/
|
|
631
|
+
export const LX_FEED_ABI = [
|
|
632
|
+
// Get mark price
|
|
633
|
+
{
|
|
634
|
+
type: 'function',
|
|
635
|
+
name: 'getMarkPrice',
|
|
636
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
637
|
+
outputs: [
|
|
638
|
+
{
|
|
639
|
+
name: 'mark',
|
|
640
|
+
type: 'tuple',
|
|
641
|
+
components: [
|
|
642
|
+
{ name: 'indexPxX18', type: 'uint128' },
|
|
643
|
+
{ name: 'markPxX18', type: 'uint128' },
|
|
644
|
+
{ name: 'premiumX18', type: 'int128' },
|
|
645
|
+
{ name: 'timestamp', type: 'uint64' },
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
stateMutability: 'view',
|
|
650
|
+
},
|
|
651
|
+
// Get index price
|
|
652
|
+
{
|
|
653
|
+
type: 'function',
|
|
654
|
+
name: 'getIndexPrice',
|
|
655
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
656
|
+
outputs: [
|
|
657
|
+
{ name: 'priceX18', type: 'uint128' },
|
|
658
|
+
{ name: 'timestamp', type: 'uint64' },
|
|
659
|
+
],
|
|
660
|
+
stateMutability: 'view',
|
|
661
|
+
},
|
|
662
|
+
// Get funding rate
|
|
663
|
+
{
|
|
664
|
+
type: 'function',
|
|
665
|
+
name: 'getFundingRate',
|
|
666
|
+
inputs: [{ name: 'marketId', type: 'uint32' }],
|
|
667
|
+
outputs: [
|
|
668
|
+
{ name: 'rateX18', type: 'int128' },
|
|
669
|
+
{ name: 'nextFundingTime', type: 'uint64' },
|
|
670
|
+
],
|
|
671
|
+
stateMutability: 'view',
|
|
672
|
+
},
|
|
673
|
+
// Get trigger price for order
|
|
674
|
+
{
|
|
675
|
+
type: 'function',
|
|
676
|
+
name: 'getTriggerPrice',
|
|
677
|
+
inputs: [
|
|
678
|
+
{ name: 'marketId', type: 'uint32' },
|
|
679
|
+
{ name: 'isBuy', type: 'bool' },
|
|
680
|
+
],
|
|
681
|
+
outputs: [{ name: 'priceX18', type: 'uint128' }],
|
|
682
|
+
stateMutability: 'view',
|
|
683
|
+
},
|
|
684
|
+
] as const
|
|
685
|
+
|
|
686
|
+
// ============================================================================
|
|
687
|
+
// LXOracle ABI (LP-9011) - Price Oracle
|
|
688
|
+
// ============================================================================
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* LXOracle ABI (LP-9011)
|
|
692
|
+
* Multi-source price aggregation
|
|
693
|
+
*/
|
|
694
|
+
export const LX_ORACLE_ABI = [
|
|
695
|
+
// Get price
|
|
696
|
+
{
|
|
697
|
+
type: 'function',
|
|
698
|
+
name: 'getPrice',
|
|
699
|
+
inputs: [
|
|
700
|
+
{ name: 'baseToken', type: 'address' },
|
|
701
|
+
{ name: 'quoteToken', type: 'address' },
|
|
702
|
+
],
|
|
703
|
+
outputs: [
|
|
704
|
+
{
|
|
705
|
+
name: 'price',
|
|
706
|
+
type: 'tuple',
|
|
707
|
+
components: [
|
|
708
|
+
{ name: 'price', type: 'uint256' },
|
|
709
|
+
{ name: 'confidence', type: 'uint256' },
|
|
710
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
711
|
+
{ name: 'source', type: 'uint8' },
|
|
712
|
+
{ name: 'expo', type: 'int32' },
|
|
713
|
+
],
|
|
714
|
+
},
|
|
715
|
+
],
|
|
716
|
+
stateMutability: 'view',
|
|
717
|
+
},
|
|
718
|
+
// Get aggregated price
|
|
719
|
+
{
|
|
720
|
+
type: 'function',
|
|
721
|
+
name: 'getAggregatedPrice',
|
|
722
|
+
inputs: [
|
|
723
|
+
{ name: 'baseToken', type: 'address' },
|
|
724
|
+
{ name: 'quoteToken', type: 'address' },
|
|
725
|
+
{ name: 'maxStaleness', type: 'uint256' },
|
|
726
|
+
],
|
|
727
|
+
outputs: [
|
|
728
|
+
{
|
|
729
|
+
name: 'aggregated',
|
|
730
|
+
type: 'tuple',
|
|
731
|
+
components: [
|
|
732
|
+
{ name: 'price', type: 'uint256' },
|
|
733
|
+
{ name: 'minPrice', type: 'uint256' },
|
|
734
|
+
{ name: 'maxPrice', type: 'uint256' },
|
|
735
|
+
{ name: 'deviation', type: 'uint256' },
|
|
736
|
+
{ name: 'numSources', type: 'uint256' },
|
|
737
|
+
{ name: 'timestamp', type: 'uint256' },
|
|
738
|
+
],
|
|
739
|
+
},
|
|
740
|
+
],
|
|
741
|
+
stateMutability: 'view',
|
|
742
|
+
},
|
|
743
|
+
// Check if price is fresh
|
|
744
|
+
{
|
|
745
|
+
type: 'function',
|
|
746
|
+
name: 'isPriceFresh',
|
|
747
|
+
inputs: [
|
|
748
|
+
{ name: 'baseToken', type: 'address' },
|
|
749
|
+
{ name: 'quoteToken', type: 'address' },
|
|
750
|
+
{ name: 'maxStaleness', type: 'uint256' },
|
|
751
|
+
],
|
|
752
|
+
outputs: [{ name: 'fresh', type: 'bool' }],
|
|
753
|
+
stateMutability: 'view',
|
|
754
|
+
},
|
|
755
|
+
] as const
|