@luxfi/exchange 0.1.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.
Files changed (154) hide show
  1. package/dist/bridge/__tests__/use-private-teleport.test.d.ts +2 -0
  2. package/dist/bridge/__tests__/use-private-teleport.test.d.ts.map +1 -0
  3. package/dist/bridge/__tests__/use-private-teleport.test.js +272 -0
  4. package/dist/bridge/cross-chain-store.d.ts +57 -0
  5. package/dist/bridge/cross-chain-store.d.ts.map +1 -0
  6. package/dist/bridge/cross-chain-store.js +158 -0
  7. package/dist/bridge/index.d.ts +78 -0
  8. package/dist/bridge/index.d.ts.map +1 -0
  9. package/dist/bridge/index.js +79 -0
  10. package/dist/bridge/private-teleport-types.d.ts +634 -0
  11. package/dist/bridge/private-teleport-types.d.ts.map +1 -0
  12. package/dist/bridge/private-teleport-types.js +308 -0
  13. package/dist/bridge/types.d.ts +84 -0
  14. package/dist/bridge/types.d.ts.map +1 -0
  15. package/dist/bridge/types.js +37 -0
  16. package/dist/bridge/use-cross-chain-mint.d.ts +34 -0
  17. package/dist/bridge/use-cross-chain-mint.d.ts.map +1 -0
  18. package/dist/bridge/use-cross-chain-mint.js +228 -0
  19. package/dist/bridge/use-private-teleport.d.ts +69 -0
  20. package/dist/bridge/use-private-teleport.d.ts.map +1 -0
  21. package/dist/bridge/use-private-teleport.js +666 -0
  22. package/dist/chains/index.d.ts +6 -0
  23. package/dist/chains/index.d.ts.map +1 -0
  24. package/dist/chains/index.js +6 -0
  25. package/dist/chains/lux.d.ts +508 -0
  26. package/dist/chains/lux.d.ts.map +1 -0
  27. package/dist/chains/lux.js +131 -0
  28. package/dist/contracts/abis/dex-swap-router.d.ts +137 -0
  29. package/dist/contracts/abis/dex-swap-router.d.ts.map +1 -0
  30. package/dist/contracts/abis/dex-swap-router.js +95 -0
  31. package/dist/contracts/abis/erc20.d.ts +136 -0
  32. package/dist/contracts/abis/erc20.d.ts.map +1 -0
  33. package/dist/contracts/abis/erc20.js +96 -0
  34. package/dist/contracts/abis/index.d.ts +15 -0
  35. package/dist/contracts/abis/index.d.ts.map +1 -0
  36. package/dist/contracts/abis/index.js +15 -0
  37. package/dist/contracts/abis/nft-position-manager.d.ts +235 -0
  38. package/dist/contracts/abis/nft-position-manager.d.ts.map +1 -0
  39. package/dist/contracts/abis/nft-position-manager.js +146 -0
  40. package/dist/contracts/abis/pool-manager.d.ts +315 -0
  41. package/dist/contracts/abis/pool-manager.d.ts.map +1 -0
  42. package/dist/contracts/abis/pool-manager.js +191 -0
  43. package/dist/contracts/abis/quoter-v2.d.ts +103 -0
  44. package/dist/contracts/abis/quoter-v2.d.ts.map +1 -0
  45. package/dist/contracts/abis/quoter-v2.js +68 -0
  46. package/dist/contracts/abis/swap-router.d.ts +119 -0
  47. package/dist/contracts/abis/swap-router.d.ts.map +1 -0
  48. package/dist/contracts/abis/swap-router.js +75 -0
  49. package/dist/contracts/abis/uniswap-v2-factory.d.ts +75 -0
  50. package/dist/contracts/abis/uniswap-v2-factory.d.ts.map +1 -0
  51. package/dist/contracts/abis/uniswap-v2-factory.js +49 -0
  52. package/dist/contracts/abis/uniswap-v2-pair.d.ts +119 -0
  53. package/dist/contracts/abis/uniswap-v2-pair.d.ts.map +1 -0
  54. package/dist/contracts/abis/uniswap-v2-pair.js +85 -0
  55. package/dist/contracts/abis/uniswap-v2-router.d.ts +249 -0
  56. package/dist/contracts/abis/uniswap-v2-router.d.ts.map +1 -0
  57. package/dist/contracts/abis/uniswap-v2-router.js +146 -0
  58. package/dist/contracts/abis/uniswap-v3-factory.d.ts +77 -0
  59. package/dist/contracts/abis/uniswap-v3-factory.d.ts.map +1 -0
  60. package/dist/contracts/abis/uniswap-v3-factory.js +45 -0
  61. package/dist/contracts/abis/uniswap-v3-pool.d.ts +128 -0
  62. package/dist/contracts/abis/uniswap-v3-pool.d.ts.map +1 -0
  63. package/dist/contracts/abis/uniswap-v3-pool.js +81 -0
  64. package/dist/contracts/addresses.d.ts +141 -0
  65. package/dist/contracts/addresses.d.ts.map +1 -0
  66. package/dist/contracts/addresses.js +108 -0
  67. package/dist/contracts/index.d.ts +6 -0
  68. package/dist/contracts/index.d.ts.map +1 -0
  69. package/dist/contracts/index.js +5 -0
  70. package/dist/dex/balance-delta.d.ts +27 -0
  71. package/dist/dex/balance-delta.d.ts.map +1 -0
  72. package/dist/dex/balance-delta.js +45 -0
  73. package/dist/dex/index.d.ts +7 -0
  74. package/dist/dex/index.d.ts.map +1 -0
  75. package/dist/dex/index.js +6 -0
  76. package/dist/dex/pool-key.d.ts +19 -0
  77. package/dist/dex/pool-key.d.ts.map +1 -0
  78. package/dist/dex/pool-key.js +44 -0
  79. package/dist/dex/types.d.ts +71 -0
  80. package/dist/dex/types.d.ts.map +1 -0
  81. package/dist/dex/types.js +28 -0
  82. package/dist/hooks/index.d.ts +10 -0
  83. package/dist/hooks/index.d.ts.map +1 -0
  84. package/dist/hooks/index.js +9 -0
  85. package/dist/hooks/use-pools.d.ts +24 -0
  86. package/dist/hooks/use-pools.d.ts.map +1 -0
  87. package/dist/hooks/use-pools.js +85 -0
  88. package/dist/hooks/use-positions.d.ts +17 -0
  89. package/dist/hooks/use-positions.d.ts.map +1 -0
  90. package/dist/hooks/use-positions.js +65 -0
  91. package/dist/hooks/use-swap-quote.d.ts +19 -0
  92. package/dist/hooks/use-swap-quote.d.ts.map +1 -0
  93. package/dist/hooks/use-swap-quote.js +54 -0
  94. package/dist/hooks/use-swap.d.ts +22 -0
  95. package/dist/hooks/use-swap.d.ts.map +1 -0
  96. package/dist/hooks/use-swap.js +46 -0
  97. package/dist/hooks/use-token-allowance.d.ts +27 -0
  98. package/dist/hooks/use-token-allowance.d.ts.map +1 -0
  99. package/dist/hooks/use-token-allowance.js +59 -0
  100. package/dist/hooks/use-token-balance.d.ts +17 -0
  101. package/dist/hooks/use-token-balance.d.ts.map +1 -0
  102. package/dist/hooks/use-token-balance.js +58 -0
  103. package/dist/index.d.ts +17 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +24 -0
  106. package/dist/stores/index.d.ts +7 -0
  107. package/dist/stores/index.d.ts.map +1 -0
  108. package/dist/stores/index.js +6 -0
  109. package/dist/stores/settings-store.d.ts +25 -0
  110. package/dist/stores/settings-store.d.ts.map +1 -0
  111. package/dist/stores/settings-store.js +16 -0
  112. package/dist/stores/swap-store.d.ts +38 -0
  113. package/dist/stores/swap-store.d.ts.map +1 -0
  114. package/dist/stores/swap-store.js +58 -0
  115. package/dist/stores/token-store.d.ts +21 -0
  116. package/dist/stores/token-store.d.ts.map +1 -0
  117. package/dist/stores/token-store.js +32 -0
  118. package/dist/tokens/index.d.ts +65 -0
  119. package/dist/tokens/index.d.ts.map +1 -0
  120. package/dist/tokens/index.js +185 -0
  121. package/package.json +78 -0
  122. package/src/chains/index.ts +21 -0
  123. package/src/chains/lux.ts +141 -0
  124. package/src/contracts/abis/dex-swap-router.ts +98 -0
  125. package/src/contracts/abis/erc20.ts +96 -0
  126. package/src/contracts/abis/index.ts +17 -0
  127. package/src/contracts/abis/nft-position-manager.ts +146 -0
  128. package/src/contracts/abis/pool-manager.ts +198 -0
  129. package/src/contracts/abis/quoter-v2.ts +68 -0
  130. package/src/contracts/abis/swap-router.ts +75 -0
  131. package/src/contracts/abis/uniswap-v2-factory.ts +49 -0
  132. package/src/contracts/abis/uniswap-v2-pair.ts +85 -0
  133. package/src/contracts/abis/uniswap-v2-router.ts +146 -0
  134. package/src/contracts/abis/uniswap-v3-factory.ts +45 -0
  135. package/src/contracts/abis/uniswap-v3-pool.ts +81 -0
  136. package/src/contracts/addresses.ts +128 -0
  137. package/src/contracts/index.ts +14 -0
  138. package/src/dex/balance-delta.ts +52 -0
  139. package/src/dex/index.ts +7 -0
  140. package/src/dex/pool-key.ts +62 -0
  141. package/src/dex/types.ts +87 -0
  142. package/src/hooks/index.ts +10 -0
  143. package/src/hooks/use-pools.ts +116 -0
  144. package/src/hooks/use-positions.ts +90 -0
  145. package/src/hooks/use-swap-quote.ts +81 -0
  146. package/src/hooks/use-swap.ts +64 -0
  147. package/src/hooks/use-token-allowance.ts +74 -0
  148. package/src/hooks/use-token-balance.ts +71 -0
  149. package/src/index.ts +31 -0
  150. package/src/stores/index.ts +7 -0
  151. package/src/stores/settings-store.ts +54 -0
  152. package/src/stores/swap-store.ts +112 -0
  153. package/src/stores/token-store.ts +62 -0
  154. package/src/tokens/index.ts +220 -0
@@ -0,0 +1,44 @@
1
+ import { keccak256, encodeAbiParameters } from 'viem';
2
+ /**
3
+ * Sort currencies to ensure currency0 < currency1
4
+ */
5
+ export function sortCurrencies(currencyA, currencyB) {
6
+ const a = BigInt(currencyA);
7
+ const b = BigInt(currencyB);
8
+ return a < b ? [currencyA, currencyB] : [currencyB, currencyA];
9
+ }
10
+ /**
11
+ * Create a pool key from parameters
12
+ */
13
+ export function createPoolKey(currencyA, currencyB, fee, tickSpacing, hooks = '0x0000000000000000000000000000000000000000') {
14
+ const [currency0, currency1] = sortCurrencies(currencyA, currencyB);
15
+ return {
16
+ currency0,
17
+ currency1,
18
+ fee,
19
+ tickSpacing,
20
+ hooks,
21
+ };
22
+ }
23
+ /**
24
+ * Compute pool ID from pool key
25
+ */
26
+ export function computePoolId(key) {
27
+ return keccak256(encodeAbiParameters([
28
+ { type: 'address', name: 'currency0' },
29
+ { type: 'address', name: 'currency1' },
30
+ { type: 'uint24', name: 'fee' },
31
+ { type: 'int24', name: 'tickSpacing' },
32
+ { type: 'address', name: 'hooks' },
33
+ ], [key.currency0, key.currency1, key.fee, key.tickSpacing, key.hooks]));
34
+ }
35
+ /**
36
+ * Check if two pool keys are equal
37
+ */
38
+ export function poolKeysEqual(a, b) {
39
+ return (a.currency0.toLowerCase() === b.currency0.toLowerCase() &&
40
+ a.currency1.toLowerCase() === b.currency1.toLowerCase() &&
41
+ a.fee === b.fee &&
42
+ a.tickSpacing === b.tickSpacing &&
43
+ a.hooks.toLowerCase() === b.hooks.toLowerCase());
44
+ }
@@ -0,0 +1,71 @@
1
+ import type { Address } from 'viem';
2
+ /**
3
+ * Currency type - address(0) represents native token
4
+ */
5
+ export type Currency = Address;
6
+ /**
7
+ * Pool key uniquely identifies a pool
8
+ */
9
+ export interface PoolKey {
10
+ currency0: Currency;
11
+ currency1: Currency;
12
+ fee: number;
13
+ tickSpacing: number;
14
+ hooks: Address;
15
+ }
16
+ /**
17
+ * Balance delta represents changes in token balances
18
+ * Positive = user owes pool, Negative = pool owes user
19
+ */
20
+ export interface BalanceDelta {
21
+ amount0: bigint;
22
+ amount1: bigint;
23
+ }
24
+ /**
25
+ * Swap parameters
26
+ */
27
+ export interface SwapParams {
28
+ zeroForOne: boolean;
29
+ amountSpecified: bigint;
30
+ sqrtPriceLimitX96: bigint;
31
+ }
32
+ /**
33
+ * Modify liquidity parameters
34
+ */
35
+ export interface ModifyLiquidityParams {
36
+ tickLower: number;
37
+ tickUpper: number;
38
+ liquidityDelta: bigint;
39
+ salt: `0x${string}`;
40
+ }
41
+ /**
42
+ * Pool slot0 state
43
+ */
44
+ export interface Slot0 {
45
+ sqrtPriceX96: bigint;
46
+ tick: number;
47
+ protocolFee: number;
48
+ lpFee: number;
49
+ }
50
+ /**
51
+ * Fee tiers (in hundredths of a bip)
52
+ */
53
+ export declare const FEE_TIERS: {
54
+ readonly LOWEST: 100;
55
+ readonly LOW: 500;
56
+ readonly MEDIUM: 3000;
57
+ readonly HIGH: 10000;
58
+ };
59
+ /**
60
+ * Tick spacing for fee tiers
61
+ */
62
+ export declare const TICK_SPACINGS: Record<number, number>;
63
+ /**
64
+ * Native currency constant
65
+ */
66
+ export declare const NATIVE_CURRENCY: Currency;
67
+ /**
68
+ * Check if currency is native
69
+ */
70
+ export declare function isNativeCurrency(currency: Currency): boolean;
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dex/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAA;AAE9B;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,QAAQ,CAAA;IACnB,SAAS,EAAE,QAAQ,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,OAAO,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,OAAO,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;CAKZ,CAAA;AAEV;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKhD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAAuD,CAAA;AAErF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Fee tiers (in hundredths of a bip)
3
+ */
4
+ export const FEE_TIERS = {
5
+ LOWEST: 100, // 0.01%
6
+ LOW: 500, // 0.05%
7
+ MEDIUM: 3000, // 0.30%
8
+ HIGH: 10000, // 1.00%
9
+ };
10
+ /**
11
+ * Tick spacing for fee tiers
12
+ */
13
+ export const TICK_SPACINGS = {
14
+ 100: 1,
15
+ 500: 10,
16
+ 3000: 60,
17
+ 10000: 200,
18
+ };
19
+ /**
20
+ * Native currency constant
21
+ */
22
+ export const NATIVE_CURRENCY = '0x0000000000000000000000000000000000000000';
23
+ /**
24
+ * Check if currency is native
25
+ */
26
+ export function isNativeCurrency(currency) {
27
+ return currency === NATIVE_CURRENCY;
28
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * React hooks for DEX interactions
3
+ */
4
+ export * from './use-swap-quote';
5
+ export * from './use-swap';
6
+ export * from './use-pools';
7
+ export * from './use-positions';
8
+ export * from './use-token-balance';
9
+ export * from './use-token-allowance';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React hooks for DEX interactions
3
+ */
4
+ export * from './use-swap-quote';
5
+ export * from './use-swap';
6
+ export * from './use-pools';
7
+ export * from './use-positions';
8
+ export * from './use-token-balance';
9
+ export * from './use-token-allowance';
@@ -0,0 +1,24 @@
1
+ import type { Address } from 'viem';
2
+ export interface Pool {
3
+ address: Address;
4
+ token0: Address;
5
+ token1: Address;
6
+ fee: number;
7
+ tickSpacing: number;
8
+ liquidity: bigint;
9
+ sqrtPriceX96: bigint;
10
+ tick: number;
11
+ }
12
+ /**
13
+ * Hook to get pool information
14
+ */
15
+ export declare function usePool(token0: Address | undefined, token1: Address | undefined, fee: number, chainId: number): import("@tanstack/react-query").UseQueryResult<Pool | null, Error>;
16
+ /**
17
+ * Hook to get all pools for a token pair
18
+ */
19
+ export declare function usePools(token0: Address | undefined, token1: Address | undefined, chainId: number): {
20
+ pools: Pool[];
21
+ isLoading: boolean;
22
+ bestPool: Pool | null;
23
+ };
24
+ //# sourceMappingURL=use-pools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-pools.d.ts","sourceRoot":"","sources":["../../src/hooks/use-pools.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,sEA4DhB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,MAAM,EAAE,OAAO,GAAG,SAAS,EAC3B,OAAO,EAAE,MAAM;;;;EAqBhB"}
@@ -0,0 +1,85 @@
1
+ 'use client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { usePublicClient } from 'wagmi';
4
+ import { getContracts } from '../contracts';
5
+ import { UNISWAP_V3_FACTORY_ABI, UNISWAP_V3_POOL_ABI } from '../contracts/abis';
6
+ /**
7
+ * Hook to get pool information
8
+ */
9
+ export function usePool(token0, token1, fee, chainId) {
10
+ const publicClient = usePublicClient({ chainId });
11
+ const contracts = getContracts(chainId);
12
+ return useQuery({
13
+ queryKey: ['pool', token0, token1, fee, chainId],
14
+ queryFn: async () => {
15
+ if (!token0 || !token1 || !publicClient)
16
+ return null;
17
+ try {
18
+ // Get pool address from factory
19
+ const poolAddress = await publicClient.readContract({
20
+ address: contracts.V3_FACTORY,
21
+ abi: UNISWAP_V3_FACTORY_ABI,
22
+ functionName: 'getPool',
23
+ args: [token0, token1, fee],
24
+ });
25
+ if (poolAddress === '0x0000000000000000000000000000000000000000') {
26
+ return null;
27
+ }
28
+ // Get pool state
29
+ const [slot0, liquidity, tickSpacing] = await Promise.all([
30
+ publicClient.readContract({
31
+ address: poolAddress,
32
+ abi: UNISWAP_V3_POOL_ABI,
33
+ functionName: 'slot0',
34
+ }),
35
+ publicClient.readContract({
36
+ address: poolAddress,
37
+ abi: UNISWAP_V3_POOL_ABI,
38
+ functionName: 'liquidity',
39
+ }),
40
+ publicClient.readContract({
41
+ address: poolAddress,
42
+ abi: UNISWAP_V3_POOL_ABI,
43
+ functionName: 'tickSpacing',
44
+ }),
45
+ ]);
46
+ return {
47
+ address: poolAddress,
48
+ token0,
49
+ token1,
50
+ fee,
51
+ tickSpacing,
52
+ liquidity,
53
+ sqrtPriceX96: slot0[0],
54
+ tick: slot0[1],
55
+ };
56
+ }
57
+ catch (error) {
58
+ console.error('Failed to fetch pool:', error);
59
+ return null;
60
+ }
61
+ },
62
+ enabled: !!token0 && !!token1 && !!publicClient,
63
+ staleTime: 30_000,
64
+ });
65
+ }
66
+ /**
67
+ * Hook to get all pools for a token pair
68
+ */
69
+ export function usePools(token0, token1, chainId) {
70
+ const pool100 = usePool(token0, token1, 100, chainId);
71
+ const pool500 = usePool(token0, token1, 500, chainId);
72
+ const pool3000 = usePool(token0, token1, 3000, chainId);
73
+ const pool10000 = usePool(token0, token1, 10000, chainId);
74
+ const pools = [
75
+ pool100.data,
76
+ pool500.data,
77
+ pool3000.data,
78
+ pool10000.data,
79
+ ].filter((p) => p !== null);
80
+ return {
81
+ pools,
82
+ isLoading: pool100.isLoading || pool500.isLoading || pool3000.isLoading || pool10000.isLoading,
83
+ bestPool: pools.length > 0 ? pools.reduce((best, pool) => pool.liquidity > best.liquidity ? pool : best) : null,
84
+ };
85
+ }
@@ -0,0 +1,17 @@
1
+ import type { Address } from 'viem';
2
+ export interface Position {
3
+ tokenId: bigint;
4
+ token0: Address;
5
+ token1: Address;
6
+ fee: number;
7
+ tickLower: number;
8
+ tickUpper: number;
9
+ liquidity: bigint;
10
+ tokensOwed0: bigint;
11
+ tokensOwed1: bigint;
12
+ }
13
+ /**
14
+ * Hook to get user's liquidity positions
15
+ */
16
+ export declare function usePositions(owner: Address | undefined, chainId: number): import("@tanstack/react-query").UseQueryResult<Position[], Error>;
17
+ //# sourceMappingURL=use-positions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-positions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-positions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,qEAkEvE"}
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { usePublicClient } from 'wagmi';
4
+ import { getContracts } from '../contracts';
5
+ import { NFT_POSITION_MANAGER_ABI } from '../contracts/abis';
6
+ /**
7
+ * Hook to get user's liquidity positions
8
+ */
9
+ export function usePositions(owner, chainId) {
10
+ const publicClient = usePublicClient({ chainId });
11
+ const contracts = getContracts(chainId);
12
+ return useQuery({
13
+ queryKey: ['positions', owner, chainId],
14
+ queryFn: async () => {
15
+ if (!owner || !publicClient)
16
+ return [];
17
+ try {
18
+ // Get number of positions
19
+ const balance = await publicClient.readContract({
20
+ address: contracts.V3_NFT_POSITION_MANAGER,
21
+ abi: NFT_POSITION_MANAGER_ABI,
22
+ functionName: 'balanceOf',
23
+ args: [owner],
24
+ });
25
+ if (balance === 0n)
26
+ return [];
27
+ // Get all token IDs
28
+ const tokenIds = await Promise.all(Array.from({ length: Number(balance) }, (_, i) => publicClient.readContract({
29
+ address: contracts.V3_NFT_POSITION_MANAGER,
30
+ abi: NFT_POSITION_MANAGER_ABI,
31
+ functionName: 'tokenOfOwnerByIndex',
32
+ args: [owner, BigInt(i)],
33
+ })));
34
+ // Get position details for each token ID
35
+ const positions = await Promise.all(tokenIds.map(async (tokenId) => {
36
+ const position = await publicClient.readContract({
37
+ address: contracts.V3_NFT_POSITION_MANAGER,
38
+ abi: NFT_POSITION_MANAGER_ABI,
39
+ functionName: 'positions',
40
+ args: [tokenId],
41
+ });
42
+ return {
43
+ tokenId,
44
+ token0: position[2],
45
+ token1: position[3],
46
+ fee: position[4],
47
+ tickLower: position[5],
48
+ tickUpper: position[6],
49
+ liquidity: position[7],
50
+ tokensOwed0: position[10],
51
+ tokensOwed1: position[11],
52
+ };
53
+ }));
54
+ // Filter out closed positions (zero liquidity)
55
+ return positions.filter((p) => p.liquidity > 0n);
56
+ }
57
+ catch (error) {
58
+ console.error('Failed to fetch positions:', error);
59
+ return [];
60
+ }
61
+ },
62
+ enabled: !!owner && !!publicClient,
63
+ staleTime: 60_000,
64
+ });
65
+ }
@@ -0,0 +1,19 @@
1
+ import type { Token } from '../tokens';
2
+ export interface SwapQuote {
3
+ amountIn: bigint;
4
+ amountOut: bigint;
5
+ priceImpact: number;
6
+ route: Token[];
7
+ gasEstimate: bigint;
8
+ }
9
+ export interface UseSwapQuoteParams {
10
+ tokenIn: Token | null;
11
+ tokenOut: Token | null;
12
+ amountIn: bigint;
13
+ chainId: number;
14
+ }
15
+ /**
16
+ * Hook to get swap quote from V3 Quoter
17
+ */
18
+ export declare function useSwapQuote({ tokenIn, tokenOut, amountIn, chainId, }: UseSwapQuoteParams): import("@tanstack/react-query").UseQueryResult<SwapQuote | null, Error>;
19
+ //# sourceMappingURL=use-swap-quote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-swap-quote.d.ts","sourceRoot":"","sources":["../../src/hooks/use-swap-quote.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,KAAK,EAAE,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAA;IACrB,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,GACR,EAAE,kBAAkB,2EAiDpB"}
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { usePublicClient } from 'wagmi';
4
+ import { getContracts } from '../contracts';
5
+ import { QUOTER_V2_ABI } from '../contracts/abis';
6
+ /**
7
+ * Hook to get swap quote from V3 Quoter
8
+ */
9
+ export function useSwapQuote({ tokenIn, tokenOut, amountIn, chainId, }) {
10
+ const publicClient = usePublicClient({ chainId });
11
+ const contracts = getContracts(chainId);
12
+ return useQuery({
13
+ queryKey: ['swapQuote', tokenIn?.address, tokenOut?.address, amountIn.toString(), chainId],
14
+ queryFn: async () => {
15
+ if (!tokenIn || !tokenOut || amountIn === 0n || !publicClient) {
16
+ return null;
17
+ }
18
+ try {
19
+ // Call QuoterV2 for quote
20
+ const result = await publicClient.simulateContract({
21
+ address: contracts.V3_QUOTER_V2,
22
+ abi: QUOTER_V2_ABI,
23
+ functionName: 'quoteExactInputSingle',
24
+ args: [
25
+ {
26
+ tokenIn: tokenIn.address,
27
+ tokenOut: tokenOut.address,
28
+ amountIn,
29
+ fee: 3000, // 0.30% fee tier
30
+ sqrtPriceLimitX96: 0n,
31
+ },
32
+ ],
33
+ });
34
+ const [amountOut, , , gasEstimate] = result.result;
35
+ // Calculate price impact (simplified)
36
+ const priceImpact = 0.003; // 0.3% placeholder
37
+ return {
38
+ amountIn,
39
+ amountOut,
40
+ priceImpact,
41
+ route: [tokenIn, tokenOut],
42
+ gasEstimate,
43
+ };
44
+ }
45
+ catch (error) {
46
+ console.error('Failed to get swap quote:', error);
47
+ return null;
48
+ }
49
+ },
50
+ enabled: !!tokenIn && !!tokenOut && amountIn > 0n && !!publicClient,
51
+ staleTime: 10_000, // 10 seconds
52
+ refetchInterval: 15_000, // Refetch every 15 seconds
53
+ });
54
+ }
@@ -0,0 +1,22 @@
1
+ import type { Token } from '../tokens';
2
+ export interface SwapRequest {
3
+ tokenIn: Token;
4
+ tokenOut: Token;
5
+ amountIn: bigint;
6
+ amountOutMinimum: bigint;
7
+ recipient: `0x${string}`;
8
+ deadline: bigint;
9
+ chainId: number;
10
+ }
11
+ /**
12
+ * Hook to execute a swap transaction
13
+ */
14
+ export declare function useSwap(): {
15
+ swap: import("@tanstack/react-query").UseMutateAsyncFunction<`0x${string}`, Error, SwapRequest, unknown>;
16
+ hash: `0x${string}` | undefined;
17
+ isPending: boolean;
18
+ isConfirming: boolean;
19
+ isSuccess: boolean;
20
+ error: Error | null;
21
+ };
22
+ //# sourceMappingURL=use-swap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-swap.d.ts","sourceRoot":"","sources":["../../src/hooks/use-swap.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAGtC,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,KAAK,CAAA;IACd,QAAQ,EAAE,KAAK,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,KAAK,MAAM,EAAE,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,wBAAgB,OAAO;;;;;;;EAwCtB"}
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ import { useMutation } from '@tanstack/react-query';
3
+ import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
4
+ import { getContracts } from '../contracts';
5
+ import { SWAP_ROUTER_ABI } from '../contracts/abis';
6
+ import { isNativeToken } from '../tokens';
7
+ /**
8
+ * Hook to execute a swap transaction
9
+ */
10
+ export function useSwap() {
11
+ const { writeContractAsync, data: hash, isPending } = useWriteContract();
12
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
13
+ const swap = useMutation({
14
+ mutationFn: async (params) => {
15
+ const contracts = getContracts(params.chainId);
16
+ const isNativeIn = isNativeToken(params.tokenIn);
17
+ const txHash = await writeContractAsync({
18
+ address: contracts.V3_SWAP_ROUTER_02,
19
+ abi: SWAP_ROUTER_ABI,
20
+ functionName: 'exactInputSingle',
21
+ args: [
22
+ {
23
+ tokenIn: isNativeIn ? contracts.WLUX : params.tokenIn.address,
24
+ tokenOut: params.tokenOut.address,
25
+ fee: 3000, // 0.30% fee tier
26
+ recipient: params.recipient,
27
+ deadline: params.deadline,
28
+ amountIn: params.amountIn,
29
+ amountOutMinimum: params.amountOutMinimum,
30
+ sqrtPriceLimitX96: 0n,
31
+ },
32
+ ],
33
+ value: isNativeIn ? params.amountIn : 0n,
34
+ });
35
+ return txHash;
36
+ },
37
+ });
38
+ return {
39
+ swap: swap.mutateAsync,
40
+ hash,
41
+ isPending: isPending || swap.isPending,
42
+ isConfirming,
43
+ isSuccess,
44
+ error: swap.error,
45
+ };
46
+ }
@@ -0,0 +1,27 @@
1
+ import type { Token } from '../tokens';
2
+ import type { Address } from 'viem';
3
+ /**
4
+ * Hook to check and manage token allowance
5
+ */
6
+ export declare function useTokenAllowance(token: Token | null, owner: Address | undefined, spender: Address | undefined, chainId: number): {
7
+ allowance: bigint;
8
+ isApproved: boolean;
9
+ approve: (amount?: bigint) => Promise<`0x${string}` | undefined>;
10
+ isPending: boolean;
11
+ isConfirming: boolean;
12
+ isSuccess: boolean;
13
+ refetch?: undefined;
14
+ } | {
15
+ allowance: bigint;
16
+ isApproved: boolean;
17
+ approve: (amount?: bigint) => Promise<`0x${string}` | undefined>;
18
+ isPending: boolean;
19
+ isConfirming: boolean;
20
+ isSuccess: boolean;
21
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<bigint, import("viem").ReadContractErrorType>>;
22
+ };
23
+ /**
24
+ * Check if approval is needed for a specific amount
25
+ */
26
+ export declare function needsApproval(allowance: bigint, amount: bigint): boolean;
27
+ //# sourceMappingURL=use-token-allowance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-token-allowance.d.ts","sourceRoot":"","sources":["../../src/hooks/use-token-allowance.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,KAAK,EAAE,OAAO,GAAG,SAAS,EAC1B,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,OAAO,EAAE,MAAM;;;uBAgBgB,MAAM;;;;;;;;uBAAN,MAAM;;;;;EAkCtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAExE"}
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+ import { useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
3
+ import { maxUint256 } from 'viem';
4
+ import { ERC20_ABI } from '../contracts/abis';
5
+ import { isNativeToken } from '../tokens';
6
+ /**
7
+ * Hook to check and manage token allowance
8
+ */
9
+ export function useTokenAllowance(token, owner, spender, chainId) {
10
+ const allowance = useReadContract({
11
+ address: token?.address,
12
+ abi: ERC20_ABI,
13
+ functionName: 'allowance',
14
+ args: owner && spender ? [owner, spender] : undefined,
15
+ chainId,
16
+ query: {
17
+ enabled: !!token && !isNativeToken(token) && !!owner && !!spender,
18
+ },
19
+ });
20
+ const { writeContractAsync, data: hash, isPending } = useWriteContract();
21
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
22
+ const approve = async (amount = maxUint256) => {
23
+ if (!token || !spender || isNativeToken(token))
24
+ return;
25
+ return writeContractAsync({
26
+ address: token.address,
27
+ abi: ERC20_ABI,
28
+ functionName: 'approve',
29
+ args: [spender, amount],
30
+ });
31
+ };
32
+ // Native tokens don't need approval
33
+ if (token && isNativeToken(token)) {
34
+ return {
35
+ allowance: maxUint256,
36
+ isApproved: true,
37
+ approve,
38
+ isPending: false,
39
+ isConfirming: false,
40
+ isSuccess: true,
41
+ };
42
+ }
43
+ const currentAllowance = allowance.data ?? 0n;
44
+ return {
45
+ allowance: currentAllowance,
46
+ isApproved: currentAllowance > 0n,
47
+ approve,
48
+ isPending,
49
+ isConfirming,
50
+ isSuccess,
51
+ refetch: allowance.refetch,
52
+ };
53
+ }
54
+ /**
55
+ * Check if approval is needed for a specific amount
56
+ */
57
+ export function needsApproval(allowance, amount) {
58
+ return allowance < amount;
59
+ }
@@ -0,0 +1,17 @@
1
+ import type { Token } from '../tokens';
2
+ import type { Address } from 'viem';
3
+ /**
4
+ * Hook to get token balance for an address
5
+ */
6
+ export declare function useTokenBalance(token: Token | null, address: Address | undefined, chainId: number): {
7
+ balance: bigint;
8
+ formatted: string;
9
+ isLoading: boolean;
10
+ error: import("viem").GetBalanceErrorType | null;
11
+ } | {
12
+ balance: bigint;
13
+ formatted: string;
14
+ isLoading: boolean;
15
+ error: import("viem").ReadContractErrorType | null;
16
+ };
17
+ //# sourceMappingURL=use-token-balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-token-balance.d.ts","sourceRoot":"","sources":["../../src/hooks/use-token-balance.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,GAAG,IAAI,EACnB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,OAAO,EAAE,MAAM;;;;;;;;;;EAgDhB"}