@luxfi/dex 1.3.0 → 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/hooks/index.d.ts +16 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +20 -1
- 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/index.d.ts +38 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -26
- package/dist/precompile/abis.d.ts +593 -2
- package/dist/precompile/abis.d.ts.map +1 -1
- package/dist/precompile/abis.js +458 -2
- package/dist/precompile/addresses.d.ts +89 -25
- package/dist/precompile/addresses.d.ts.map +1 -1
- package/dist/precompile/addresses.js +86 -21
- package/dist/precompile/index.d.ts +13 -2
- package/dist/precompile/index.d.ts.map +1 -1
- package/dist/precompile/index.js +13 -2
- package/dist/precompile/types.d.ts +170 -0
- package/dist/precompile/types.d.ts.map +1 -1
- package/dist/precompile/types.js +67 -0
- package/package.json +2 -2
- package/src/hooks/index.ts +24 -1
- 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/index.ts +92 -26
- package/src/precompile/abis.ts +466 -2
- package/src/precompile/addresses.ts +109 -28
- package/src/precompile/index.ts +13 -2
- package/src/precompile/types.ts +200 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LX Hooks Exports
|
|
3
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
|
|
4
16
|
*/
|
|
5
17
|
export * from './use-quote';
|
|
6
18
|
export * from './use-swap';
|
|
19
|
+
export * from './use-lxbook';
|
|
20
|
+
export * from './use-lxvault';
|
|
21
|
+
export * from './use-lxfeed';
|
|
7
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* LX Hooks Exports
|
|
3
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
|
|
4
16
|
*/
|
|
17
|
+
// AMM hooks
|
|
5
18
|
export * from './use-quote';
|
|
6
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,MAAM,EAAE;QACnB,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,OAAO,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,GAAG,CAAC,EAAE,GAAG,CAAA;QACT,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB,KAAK,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;KACtB,KAAK,IAAI,CAAA;IACV,gBAAgB,EAAE,CAAC,MAAM,EAAE;QACzB,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,OAAO,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,KAAK,IAAI,CAAA;IACV,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,mBAAmB,IAAI,yBAAyB,CAiF/D;AAED,UAAU,0BAA0B;IAClC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,CAAA;IAC7C,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,oBAAoB,IAAI,0BAA0B,CAwCjE"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LXBook Hooks (LP-9020)
|
|
3
|
+
* React hooks for CLOB trading via LXBook precompile
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
import { useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
|
|
7
|
+
import { encodeFunctionData } from 'viem';
|
|
8
|
+
import { LX } from '../precompile/addresses';
|
|
9
|
+
import { LX_BOOK_ABI } from '../precompile/abis';
|
|
10
|
+
import { ActionType, TIF, OrderKind, } from '../precompile/types';
|
|
11
|
+
/**
|
|
12
|
+
* Hook to get L1 (best bid/ask) for a market
|
|
13
|
+
*/
|
|
14
|
+
export function useLXBookL1(marketId) {
|
|
15
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
16
|
+
address: LX.LX_BOOK,
|
|
17
|
+
abi: LX_BOOK_ABI,
|
|
18
|
+
functionName: 'getL1',
|
|
19
|
+
args: [marketId],
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
l1: data,
|
|
23
|
+
isLoading,
|
|
24
|
+
error,
|
|
25
|
+
refetch,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook to get market config
|
|
30
|
+
*/
|
|
31
|
+
export function useLXBookMarket(marketId) {
|
|
32
|
+
const { data, isLoading, error } = useReadContract({
|
|
33
|
+
address: LX.LX_BOOK,
|
|
34
|
+
abi: LX_BOOK_ABI,
|
|
35
|
+
functionName: 'getMarketConfig',
|
|
36
|
+
args: [marketId],
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
config: data,
|
|
40
|
+
isLoading,
|
|
41
|
+
error,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hook to get market status
|
|
46
|
+
*/
|
|
47
|
+
export function useLXBookMarketStatus(marketId) {
|
|
48
|
+
const { data, isLoading, error } = useReadContract({
|
|
49
|
+
address: LX.LX_BOOK,
|
|
50
|
+
abi: LX_BOOK_ABI,
|
|
51
|
+
functionName: 'getMarketStatus',
|
|
52
|
+
args: [marketId],
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
status: data,
|
|
56
|
+
isLoading,
|
|
57
|
+
error,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build action payload for execute()
|
|
62
|
+
*/
|
|
63
|
+
function buildAction(actionType, nonce, expiresAfter, data) {
|
|
64
|
+
return {
|
|
65
|
+
actionType,
|
|
66
|
+
nonce,
|
|
67
|
+
expiresAfter,
|
|
68
|
+
data,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Encode order data for placement
|
|
73
|
+
*/
|
|
74
|
+
function encodeOrderData(order) {
|
|
75
|
+
// Pack order into bytes - this matches the Go/Solidity struct layout
|
|
76
|
+
const encoded = encodeFunctionData({
|
|
77
|
+
abi: [{
|
|
78
|
+
type: 'function',
|
|
79
|
+
name: 'encodeOrder',
|
|
80
|
+
inputs: [{
|
|
81
|
+
name: 'order',
|
|
82
|
+
type: 'tuple',
|
|
83
|
+
components: [
|
|
84
|
+
{ name: 'marketId', type: 'uint32' },
|
|
85
|
+
{ name: 'isBuy', type: 'bool' },
|
|
86
|
+
{ name: 'kind', type: 'uint8' },
|
|
87
|
+
{ name: 'sizeX18', type: 'uint128' },
|
|
88
|
+
{ name: 'limitPxX18', type: 'uint128' },
|
|
89
|
+
{ name: 'triggerPxX18', type: 'uint128' },
|
|
90
|
+
{ name: 'reduceOnly', type: 'bool' },
|
|
91
|
+
{ name: 'tif', type: 'uint8' },
|
|
92
|
+
{ name: 'cloid', type: 'bytes16' },
|
|
93
|
+
{ name: 'groupId', type: 'bytes16' },
|
|
94
|
+
{ name: 'groupType', type: 'uint8' },
|
|
95
|
+
],
|
|
96
|
+
}],
|
|
97
|
+
outputs: [],
|
|
98
|
+
stateMutability: 'pure',
|
|
99
|
+
}],
|
|
100
|
+
functionName: 'encodeOrder',
|
|
101
|
+
args: [order],
|
|
102
|
+
});
|
|
103
|
+
// Strip function selector (first 4 bytes)
|
|
104
|
+
return `0x${encoded.slice(10)}`;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Hook for placing orders via LXBook execute()
|
|
108
|
+
*/
|
|
109
|
+
export function useLXBookExecute() {
|
|
110
|
+
const { writeContract, data: hash, isPending, error } = useWriteContract();
|
|
111
|
+
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
|
|
112
|
+
const execute = useCallback((action) => {
|
|
113
|
+
writeContract({
|
|
114
|
+
address: LX.LX_BOOK,
|
|
115
|
+
abi: LX_BOOK_ABI,
|
|
116
|
+
functionName: 'execute',
|
|
117
|
+
args: [action],
|
|
118
|
+
});
|
|
119
|
+
}, [writeContract]);
|
|
120
|
+
const executeBatch = useCallback((actions) => {
|
|
121
|
+
writeContract({
|
|
122
|
+
address: LX.LX_BOOK,
|
|
123
|
+
abi: LX_BOOK_ABI,
|
|
124
|
+
functionName: 'executeBatch',
|
|
125
|
+
args: [actions],
|
|
126
|
+
});
|
|
127
|
+
}, [writeContract]);
|
|
128
|
+
return {
|
|
129
|
+
execute,
|
|
130
|
+
executeBatch,
|
|
131
|
+
hash,
|
|
132
|
+
isPending,
|
|
133
|
+
isConfirming,
|
|
134
|
+
isSuccess,
|
|
135
|
+
error,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Hook for placing limit orders
|
|
140
|
+
*/
|
|
141
|
+
export function useLXBookPlaceOrder() {
|
|
142
|
+
const { execute, hash, isPending, isConfirming, isSuccess, error } = useLXBookExecute();
|
|
143
|
+
const placeOrder = useCallback(async (params) => {
|
|
144
|
+
const order = {
|
|
145
|
+
marketId: params.marketId,
|
|
146
|
+
isBuy: params.isBuy,
|
|
147
|
+
kind: OrderKind.LIMIT,
|
|
148
|
+
sizeX18: params.size,
|
|
149
|
+
limitPxX18: params.price,
|
|
150
|
+
triggerPxX18: 0n,
|
|
151
|
+
reduceOnly: params.reduceOnly ?? false,
|
|
152
|
+
tif: params.tif ?? TIF.GTC,
|
|
153
|
+
cloid: params.cloid ?? '0x00000000000000000000000000000000',
|
|
154
|
+
groupId: '0x00000000000000000000000000000000',
|
|
155
|
+
groupType: 0,
|
|
156
|
+
};
|
|
157
|
+
const action = buildAction(ActionType.PLACE, BigInt(Date.now()), BigInt(Math.floor(Date.now() / 1000) + 300), // 5 min expiry
|
|
158
|
+
encodeOrderData(order));
|
|
159
|
+
return execute(action);
|
|
160
|
+
}, [execute]);
|
|
161
|
+
const placeMarketOrder = useCallback(async (params) => {
|
|
162
|
+
const order = {
|
|
163
|
+
marketId: params.marketId,
|
|
164
|
+
isBuy: params.isBuy,
|
|
165
|
+
kind: OrderKind.MARKET,
|
|
166
|
+
sizeX18: params.size,
|
|
167
|
+
limitPxX18: 0n, // Market order - no limit
|
|
168
|
+
triggerPxX18: 0n,
|
|
169
|
+
reduceOnly: params.reduceOnly ?? false,
|
|
170
|
+
tif: TIF.IOC,
|
|
171
|
+
cloid: '0x00000000000000000000000000000000',
|
|
172
|
+
groupId: '0x00000000000000000000000000000000',
|
|
173
|
+
groupType: 0,
|
|
174
|
+
};
|
|
175
|
+
const action = buildAction(ActionType.PLACE, BigInt(Date.now()), BigInt(Math.floor(Date.now() / 1000) + 60), // 1 min expiry for market
|
|
176
|
+
encodeOrderData(order));
|
|
177
|
+
return execute(action);
|
|
178
|
+
}, [execute]);
|
|
179
|
+
return {
|
|
180
|
+
placeOrder,
|
|
181
|
+
placeMarketOrder,
|
|
182
|
+
hash,
|
|
183
|
+
isPending,
|
|
184
|
+
isConfirming,
|
|
185
|
+
isSuccess,
|
|
186
|
+
error,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Hook for canceling orders
|
|
191
|
+
*/
|
|
192
|
+
export function useLXBookCancelOrder() {
|
|
193
|
+
const { execute, hash, isPending, isConfirming, isSuccess, error } = useLXBookExecute();
|
|
194
|
+
const cancelByOid = useCallback(async (oid) => {
|
|
195
|
+
// Encode oid as bytes
|
|
196
|
+
const data = `0x${oid.toString(16).padStart(64, '0')}`;
|
|
197
|
+
const action = buildAction(ActionType.CANCEL, BigInt(Date.now()), BigInt(Math.floor(Date.now() / 1000) + 60), data);
|
|
198
|
+
return execute(action);
|
|
199
|
+
}, [execute]);
|
|
200
|
+
const cancelByCloid = useCallback(async (cloid) => {
|
|
201
|
+
const action = buildAction(ActionType.CANCEL_BY_CLOID, BigInt(Date.now()), BigInt(Math.floor(Date.now() / 1000) + 60), cloid);
|
|
202
|
+
return execute(action);
|
|
203
|
+
}, [execute]);
|
|
204
|
+
return {
|
|
205
|
+
cancelByOid,
|
|
206
|
+
cancelByCloid,
|
|
207
|
+
hash,
|
|
208
|
+
isPending,
|
|
209
|
+
isConfirming,
|
|
210
|
+
isSuccess,
|
|
211
|
+
error,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import type { LXMarkPrice } from '../precompile/types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get mark price for a market
|
|
5
|
+
*/
|
|
6
|
+
export declare function useLXFeedMarkPrice(marketId: number): {
|
|
7
|
+
markPrice: LXMarkPrice | undefined;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: import("viem").ReadContractErrorType | null;
|
|
10
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
11
|
+
indexPxX18: bigint;
|
|
12
|
+
markPxX18: bigint;
|
|
13
|
+
premiumX18: bigint;
|
|
14
|
+
timestamp: bigint;
|
|
15
|
+
}, import("viem").ReadContractErrorType>>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Hook to get index price for a market
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLXFeedIndexPrice(marketId: number): {
|
|
21
|
+
priceX18: bigint | undefined;
|
|
22
|
+
timestamp: bigint | undefined;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
error: import("viem").ReadContractErrorType | null;
|
|
25
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<readonly [bigint, timestamp: bigint], import("viem").ReadContractErrorType>>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Hook to get funding rate for a market
|
|
29
|
+
*/
|
|
30
|
+
export declare function useLXFeedFundingRate(marketId: number): {
|
|
31
|
+
rateX18: bigint | undefined;
|
|
32
|
+
nextFundingTime: bigint | undefined;
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
error: import("viem").ReadContractErrorType | null;
|
|
35
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<readonly [bigint, bigint], import("viem").ReadContractErrorType>>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Hook to get trigger price for stop/take orders
|
|
39
|
+
*/
|
|
40
|
+
export declare function useLXFeedTriggerPrice(marketId: number, isBuy: boolean): {
|
|
41
|
+
triggerPriceX18: bigint | undefined;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
error: import("viem").ReadContractErrorType | null;
|
|
44
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<bigint, import("viem").ReadContractErrorType>>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Hook to get oracle price for token pair
|
|
48
|
+
*/
|
|
49
|
+
export declare function useLXOraclePrice(baseToken: Address, quoteToken: Address): {
|
|
50
|
+
price: {
|
|
51
|
+
price: bigint;
|
|
52
|
+
confidence: bigint;
|
|
53
|
+
timestamp: bigint;
|
|
54
|
+
source: number;
|
|
55
|
+
expo: number;
|
|
56
|
+
} | undefined;
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
error: import("viem").ReadContractErrorType | null;
|
|
59
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
60
|
+
price: bigint;
|
|
61
|
+
confidence: bigint;
|
|
62
|
+
timestamp: bigint;
|
|
63
|
+
source: number;
|
|
64
|
+
expo: number;
|
|
65
|
+
}, import("viem").ReadContractErrorType>>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Hook to get aggregated oracle price with deviation info
|
|
69
|
+
*/
|
|
70
|
+
export declare function useLXOracleAggregatedPrice(baseToken: Address, quoteToken: Address, maxStaleness?: bigint): {
|
|
71
|
+
aggregated: {
|
|
72
|
+
price: bigint;
|
|
73
|
+
minPrice: bigint;
|
|
74
|
+
maxPrice: bigint;
|
|
75
|
+
deviation: bigint;
|
|
76
|
+
numSources: bigint;
|
|
77
|
+
timestamp: bigint;
|
|
78
|
+
} | undefined;
|
|
79
|
+
isLoading: boolean;
|
|
80
|
+
error: import("viem").ReadContractErrorType | null;
|
|
81
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
82
|
+
price: bigint;
|
|
83
|
+
minPrice: bigint;
|
|
84
|
+
maxPrice: bigint;
|
|
85
|
+
deviation: bigint;
|
|
86
|
+
numSources: bigint;
|
|
87
|
+
timestamp: bigint;
|
|
88
|
+
}, import("viem").ReadContractErrorType>>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Hook to check if oracle price is fresh
|
|
92
|
+
*/
|
|
93
|
+
export declare function useLXOraclePriceFresh(baseToken: Address, quoteToken: Address, maxStaleness?: bigint): {
|
|
94
|
+
isFresh: boolean | undefined;
|
|
95
|
+
isLoading: boolean;
|
|
96
|
+
error: import("viem").ReadContractErrorType | null;
|
|
97
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<boolean, import("viem").ReadContractErrorType>>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Combined hook for market price data
|
|
101
|
+
*/
|
|
102
|
+
export declare function useLXMarketPrices(marketId: number): {
|
|
103
|
+
markPrice: LXMarkPrice | undefined;
|
|
104
|
+
indexPrice: bigint | undefined;
|
|
105
|
+
fundingRate: bigint | undefined;
|
|
106
|
+
nextFundingTime: bigint | undefined;
|
|
107
|
+
isLoading: boolean;
|
|
108
|
+
error: import("viem").ReadContractErrorType | null;
|
|
109
|
+
refetch: () => void;
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=use-lxfeed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-lxfeed.d.ts","sourceRoot":"","sources":["../../src/hooks/use-lxfeed.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,qBAAqB,CAAA;AAErE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM;eAS5B,WAAW,GAAG,SAAS;;;;;;;;;EAK7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM;;;;;;EAiBnD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM;;;;;;EAiBpD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;qBASzC,MAAM,GAAG,SAAS;;;;EAK9C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO;;;;;;;;;;;;;;;;;EAcvE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,EACnB,YAAY,GAAE,MAAc;;;;;;;;;;;;;;;;;;;EAe7B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,EACnB,YAAY,GAAE,MAAc;aAUT,OAAO,GAAG,SAAS;;;;EAKvC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;EAkBjD"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LXFeed Hooks (LP-9040)
|
|
3
|
+
* React hooks for price feeds, mark price, and funding rates
|
|
4
|
+
*/
|
|
5
|
+
import { useReadContract } from 'wagmi';
|
|
6
|
+
import { LX } from '../precompile/addresses';
|
|
7
|
+
import { LX_FEED_ABI, LX_ORACLE_ABI } from '../precompile/abis';
|
|
8
|
+
/**
|
|
9
|
+
* Hook to get mark price for a market
|
|
10
|
+
*/
|
|
11
|
+
export function useLXFeedMarkPrice(marketId) {
|
|
12
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
13
|
+
address: LX.LX_FEED,
|
|
14
|
+
abi: LX_FEED_ABI,
|
|
15
|
+
functionName: 'getMarkPrice',
|
|
16
|
+
args: [marketId],
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
markPrice: data,
|
|
20
|
+
isLoading,
|
|
21
|
+
error,
|
|
22
|
+
refetch,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Hook to get index price for a market
|
|
27
|
+
*/
|
|
28
|
+
export function useLXFeedIndexPrice(marketId) {
|
|
29
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
30
|
+
address: LX.LX_FEED,
|
|
31
|
+
abi: LX_FEED_ABI,
|
|
32
|
+
functionName: 'getIndexPrice',
|
|
33
|
+
args: [marketId],
|
|
34
|
+
});
|
|
35
|
+
const result = data;
|
|
36
|
+
return {
|
|
37
|
+
priceX18: result?.[0],
|
|
38
|
+
timestamp: result?.[1],
|
|
39
|
+
isLoading,
|
|
40
|
+
error,
|
|
41
|
+
refetch,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Hook to get funding rate for a market
|
|
46
|
+
*/
|
|
47
|
+
export function useLXFeedFundingRate(marketId) {
|
|
48
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
49
|
+
address: LX.LX_FEED,
|
|
50
|
+
abi: LX_FEED_ABI,
|
|
51
|
+
functionName: 'getFundingRate',
|
|
52
|
+
args: [marketId],
|
|
53
|
+
});
|
|
54
|
+
const result = data;
|
|
55
|
+
return {
|
|
56
|
+
rateX18: result?.[0],
|
|
57
|
+
nextFundingTime: result?.[1],
|
|
58
|
+
isLoading,
|
|
59
|
+
error,
|
|
60
|
+
refetch,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Hook to get trigger price for stop/take orders
|
|
65
|
+
*/
|
|
66
|
+
export function useLXFeedTriggerPrice(marketId, isBuy) {
|
|
67
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
68
|
+
address: LX.LX_FEED,
|
|
69
|
+
abi: LX_FEED_ABI,
|
|
70
|
+
functionName: 'getTriggerPrice',
|
|
71
|
+
args: [marketId, isBuy],
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
triggerPriceX18: data,
|
|
75
|
+
isLoading,
|
|
76
|
+
error,
|
|
77
|
+
refetch,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Hook to get oracle price for token pair
|
|
82
|
+
*/
|
|
83
|
+
export function useLXOraclePrice(baseToken, quoteToken) {
|
|
84
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
85
|
+
address: LX.LX_ORACLE,
|
|
86
|
+
abi: LX_ORACLE_ABI,
|
|
87
|
+
functionName: 'getPrice',
|
|
88
|
+
args: [baseToken, quoteToken],
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
price: data,
|
|
92
|
+
isLoading,
|
|
93
|
+
error,
|
|
94
|
+
refetch,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Hook to get aggregated oracle price with deviation info
|
|
99
|
+
*/
|
|
100
|
+
export function useLXOracleAggregatedPrice(baseToken, quoteToken, maxStaleness = 3600n // 1 hour default
|
|
101
|
+
) {
|
|
102
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
103
|
+
address: LX.LX_ORACLE,
|
|
104
|
+
abi: LX_ORACLE_ABI,
|
|
105
|
+
functionName: 'getAggregatedPrice',
|
|
106
|
+
args: [baseToken, quoteToken, maxStaleness],
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
aggregated: data,
|
|
110
|
+
isLoading,
|
|
111
|
+
error,
|
|
112
|
+
refetch,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Hook to check if oracle price is fresh
|
|
117
|
+
*/
|
|
118
|
+
export function useLXOraclePriceFresh(baseToken, quoteToken, maxStaleness = 3600n) {
|
|
119
|
+
const { data, isLoading, error, refetch } = useReadContract({
|
|
120
|
+
address: LX.LX_ORACLE,
|
|
121
|
+
abi: LX_ORACLE_ABI,
|
|
122
|
+
functionName: 'isPriceFresh',
|
|
123
|
+
args: [baseToken, quoteToken, maxStaleness],
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
isFresh: data,
|
|
127
|
+
isLoading,
|
|
128
|
+
error,
|
|
129
|
+
refetch,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Combined hook for market price data
|
|
134
|
+
*/
|
|
135
|
+
export function useLXMarketPrices(marketId) {
|
|
136
|
+
const mark = useLXFeedMarkPrice(marketId);
|
|
137
|
+
const index = useLXFeedIndexPrice(marketId);
|
|
138
|
+
const funding = useLXFeedFundingRate(marketId);
|
|
139
|
+
return {
|
|
140
|
+
markPrice: mark.markPrice,
|
|
141
|
+
indexPrice: index.priceX18,
|
|
142
|
+
fundingRate: funding.rateX18,
|
|
143
|
+
nextFundingTime: funding.nextFundingTime,
|
|
144
|
+
isLoading: mark.isLoading || index.isLoading || funding.isLoading,
|
|
145
|
+
error: mark.error || index.error || funding.error,
|
|
146
|
+
refetch: () => {
|
|
147
|
+
mark.refetch();
|
|
148
|
+
index.refetch();
|
|
149
|
+
funding.refetch();
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|