@luxfi/dex 1.3.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/hooks/index.d.ts +16 -1
  2. package/dist/hooks/index.d.ts.map +1 -1
  3. package/dist/hooks/index.js +20 -1
  4. package/dist/hooks/use-lxbook.d.ts +84 -0
  5. package/dist/hooks/use-lxbook.d.ts.map +1 -0
  6. package/dist/hooks/use-lxbook.js +213 -0
  7. package/dist/hooks/use-lxfeed.d.ts +42 -0
  8. package/dist/hooks/use-lxfeed.d.ts.map +1 -0
  9. package/dist/hooks/use-lxfeed.js +152 -0
  10. package/dist/hooks/use-lxvault.d.ts +75 -0
  11. package/dist/hooks/use-lxvault.d.ts.map +1 -0
  12. package/dist/hooks/use-lxvault.js +227 -0
  13. package/dist/index.d.ts +38 -21
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +57 -26
  16. package/dist/precompile/abis.d.ts +593 -2
  17. package/dist/precompile/abis.d.ts.map +1 -1
  18. package/dist/precompile/abis.js +458 -2
  19. package/dist/precompile/addresses.d.ts +89 -25
  20. package/dist/precompile/addresses.d.ts.map +1 -1
  21. package/dist/precompile/addresses.js +86 -21
  22. package/dist/precompile/index.d.ts +13 -2
  23. package/dist/precompile/index.d.ts.map +1 -1
  24. package/dist/precompile/index.js +13 -2
  25. package/dist/precompile/types.d.ts +171 -1
  26. package/dist/precompile/types.d.ts.map +1 -1
  27. package/dist/precompile/types.js +67 -0
  28. package/package.json +2 -2
  29. package/src/hooks/index.ts +24 -1
  30. package/src/hooks/use-lxbook.ts +343 -0
  31. package/src/hooks/use-lxfeed.ts +179 -0
  32. package/src/hooks/use-lxvault.ts +318 -0
  33. package/src/index.ts +92 -26
  34. package/src/precompile/abis.ts +466 -2
  35. package/src/precompile/addresses.ts +109 -28
  36. package/src/precompile/index.ts +13 -2
  37. package/src/precompile/types.ts +200 -1
@@ -1,7 +1,22 @@
1
1
  /**
2
- * DEX Hooks Exports
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;;;GAGG;AACH,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
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"}
@@ -1,6 +1,25 @@
1
1
  /**
2
- * DEX Hooks Exports
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,84 @@
1
+ import { type LXAction, TIF } from '../precompile/types';
2
+ /**
3
+ * Hook to get L1 (best bid/ask) for a market
4
+ */
5
+ export declare function useLXBookL1(marketId: number): any;
6
+ /**
7
+ * Hook to get market config
8
+ */
9
+ export declare function useLXBookMarket(marketId: number): {
10
+ config: {
11
+ baseAsset: `0x${string}`;
12
+ quoteAsset: `0x${string}`;
13
+ tickSizeX18: bigint;
14
+ lotSizeX18: bigint;
15
+ makerFeePpm: number;
16
+ takerFeePpm: number;
17
+ feedId: `0x${string}`;
18
+ initialStatus: number;
19
+ } | undefined;
20
+ isLoading: boolean;
21
+ error: import("viem").ReadContractErrorType | null;
22
+ };
23
+ /**
24
+ * Hook to get market status
25
+ */
26
+ export declare function useLXBookMarketStatus(marketId: number): {
27
+ status: number | undefined;
28
+ isLoading: boolean;
29
+ error: import("viem").ReadContractErrorType | null;
30
+ };
31
+ interface UseLXBookExecuteResult {
32
+ execute: (action: LXAction) => void;
33
+ executeBatch: (actions: LXAction[]) => void;
34
+ hash: `0x${string}` | undefined;
35
+ isPending: boolean;
36
+ isConfirming: boolean;
37
+ isSuccess: boolean;
38
+ error: Error | null;
39
+ }
40
+ /**
41
+ * Hook for placing orders via LXBook execute()
42
+ */
43
+ export declare function useLXBookExecute(): UseLXBookExecuteResult;
44
+ interface UseLXBookPlaceOrderResult {
45
+ placeOrder: (params: {
46
+ marketId: number;
47
+ isBuy: boolean;
48
+ size: bigint;
49
+ price: bigint;
50
+ tif?: TIF;
51
+ reduceOnly?: boolean;
52
+ cloid?: `0x${string}`;
53
+ }) => void;
54
+ placeMarketOrder: (params: {
55
+ marketId: number;
56
+ isBuy: boolean;
57
+ size: bigint;
58
+ reduceOnly?: boolean;
59
+ }) => void;
60
+ hash: `0x${string}` | undefined;
61
+ isPending: boolean;
62
+ isConfirming: boolean;
63
+ isSuccess: boolean;
64
+ error: Error | null;
65
+ }
66
+ /**
67
+ * Hook for placing limit orders
68
+ */
69
+ export declare function useLXBookPlaceOrder(): UseLXBookPlaceOrderResult;
70
+ interface UseLXBookCancelOrderResult {
71
+ cancelByOid: (oid: bigint) => void;
72
+ cancelByCloid: (cloid: `0x${string}`) => void;
73
+ hash: `0x${string}` | undefined;
74
+ isPending: boolean;
75
+ isConfirming: boolean;
76
+ isSuccess: boolean;
77
+ error: Error | null;
78
+ }
79
+ /**
80
+ * Hook for canceling orders
81
+ */
82
+ export declare function useLXBookCancelOrder(): UseLXBookCancelOrderResult;
83
+ export {};
84
+ //# 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,EAIb,GAAG,EAEJ,MAAM,qBAAqB,CAAA;AAE5B;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAcjD;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,KAA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AI,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,42 @@
1
+ import type { Address } from 'viem';
2
+ /**
3
+ * Hook to get mark price for a market
4
+ */
5
+ export declare function useLXFeedMarkPrice(marketId: number): any;
6
+ /**
7
+ * Hook to get index price for a market
8
+ */
9
+ export declare function useLXFeedIndexPrice(marketId: number): any;
10
+ /**
11
+ * Hook to get funding rate for a market
12
+ */
13
+ export declare function useLXFeedFundingRate(marketId: number): any;
14
+ /**
15
+ * Hook to get trigger price for stop/take orders
16
+ */
17
+ export declare function useLXFeedTriggerPrice(marketId: number, isBuy: boolean): any;
18
+ /**
19
+ * Hook to get oracle price for token pair
20
+ */
21
+ export declare function useLXOraclePrice(baseToken: Address, quoteToken: Address): any;
22
+ /**
23
+ * Hook to get aggregated oracle price with deviation info
24
+ */
25
+ export declare function useLXOracleAggregatedPrice(baseToken: Address, quoteToken: Address, maxStaleness?: bigint): any;
26
+ /**
27
+ * Hook to check if oracle price is fresh
28
+ */
29
+ export declare function useLXOraclePriceFresh(baseToken: Address, quoteToken: Address, maxStaleness?: bigint): any;
30
+ /**
31
+ * Combined hook for market price data
32
+ */
33
+ export declare function useLXMarketPrices(marketId: number): {
34
+ markPrice: any;
35
+ indexPrice: any;
36
+ fundingRate: any;
37
+ nextFundingTime: any;
38
+ isLoading: any;
39
+ error: any;
40
+ refetch: () => void;
41
+ };
42
+ //# 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;AAKnC;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAcxD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAiBzD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAiB1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,GAAG,CAc3E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,GAAG,CAc7E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,EACnB,YAAY,GAAE,MAAc,GAC3B,GAAG,CAcL;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,OAAO,EACnB,YAAY,GAAE,MAAc,GAC3B,GAAG,CAcL;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
+ }
@@ -0,0 +1,75 @@
1
+ import type { Address } from 'viem';
2
+ /**
3
+ * Hook to get token balance in vault
4
+ */
5
+ export declare function useLXVaultBalance(token: Address, subaccountId?: number): any;
6
+ /**
7
+ * Hook to get position for a market
8
+ */
9
+ export declare function useLXVaultPosition(marketId: number, subaccountId?: number): any;
10
+ /**
11
+ * Hook to get margin info (free margin, used margin, etc.)
12
+ */
13
+ export declare function useLXVaultMargin(subaccountId?: number): any;
14
+ /**
15
+ * Hook to check if account is liquidatable
16
+ */
17
+ export declare function useLXVaultLiquidatable(account?: Address, subaccountId?: number): any;
18
+ /**
19
+ * Hook to get funding rate for a market
20
+ */
21
+ export declare function useLXVaultFundingRate(marketId: number): any;
22
+ interface UseLXVaultDepositResult {
23
+ deposit: (token: Address, amount: bigint, subaccountId?: number) => void;
24
+ hash: `0x${string}` | undefined;
25
+ isPending: boolean;
26
+ isConfirming: boolean;
27
+ isSuccess: boolean;
28
+ error: Error | null;
29
+ }
30
+ /**
31
+ * Hook for depositing tokens into vault
32
+ */
33
+ export declare function useLXVaultDeposit(): UseLXVaultDepositResult;
34
+ interface UseLXVaultWithdrawResult {
35
+ withdraw: (token: Address, amount: bigint, subaccountId?: number) => void;
36
+ hash: `0x${string}` | undefined;
37
+ isPending: boolean;
38
+ isConfirming: boolean;
39
+ isSuccess: boolean;
40
+ error: Error | null;
41
+ }
42
+ /**
43
+ * Hook for withdrawing tokens from vault
44
+ */
45
+ export declare function useLXVaultWithdraw(): UseLXVaultWithdrawResult;
46
+ interface UseLXVaultTransferResult {
47
+ transfer: (token: Address, amount: bigint, fromSubaccount: number, toSubaccount: number) => void;
48
+ hash: `0x${string}` | undefined;
49
+ isPending: boolean;
50
+ isConfirming: boolean;
51
+ isSuccess: boolean;
52
+ error: Error | null;
53
+ }
54
+ /**
55
+ * Hook for transferring between subaccounts
56
+ */
57
+ export declare function useLXVaultTransfer(): UseLXVaultTransferResult;
58
+ interface UseLXVaultLiquidateResult {
59
+ liquidate: (targetAccount: Address, targetSubaccount: number, marketId: number, sizeX18: bigint) => void;
60
+ hash: `0x${string}` | undefined;
61
+ isPending: boolean;
62
+ isConfirming: boolean;
63
+ isSuccess: boolean;
64
+ error: Error | null;
65
+ }
66
+ /**
67
+ * Hook for liquidating underwater positions
68
+ */
69
+ export declare function useLXVaultLiquidate(): UseLXVaultLiquidateResult;
70
+ /**
71
+ * Combined hook for common vault operations
72
+ */
73
+ export declare function useLXVault(subaccountId?: number): any;
74
+ export {};
75
+ //# sourceMappingURL=use-lxvault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-lxvault.d.ts","sourceRoot":"","sources":["../../src/hooks/use-lxvault.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAYnC;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,GAAE,MAAU,GAAG,GAAG,CAiB/E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAE,MAAU,GAAG,GAAG,CAiBlF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,GAAE,MAAU,GAAG,GAAG,CAiB9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,YAAY,GAAE,MAAU,GAAG,GAAG,CAqBvF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAiB3D;AAED,UAAU,uBAAuB;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACxE,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,iBAAiB,IAAI,uBAAuB,CAwB3D;AAED,UAAU,wBAAwB;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK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