@shogun-sdk/swap 0.0.2-test

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.
@@ -0,0 +1,158 @@
1
+ import { TokenSearchParams, TokenSearchResponse } from '@shogun-sdk/intents-sdk';
2
+ export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
3
+ import { a as SwapQuoteResponse, e as executeOrder, b as Stage, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-FaLLPp1i.cjs';
4
+ export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-FaLLPp1i.cjs';
5
+ import { A as AdaptedWallet } from './wallet-MmUIz8GE.cjs';
6
+ import { WalletClient } from 'viem';
7
+ import '@mysten/sui/transactions';
8
+ import '@solana/web3.js';
9
+
10
+ declare function useTokenList(params: TokenSearchParams & {
11
+ debounceMs?: number;
12
+ }): {
13
+ /** Current fetched data (cached when possible) */
14
+ data: TokenSearchResponse | null;
15
+ /** Whether a request is in progress */
16
+ loading: boolean;
17
+ /** Error object if a request failed */
18
+ error: Error | null;
19
+ /** Manually refetch the token list */
20
+ refetch: () => Promise<void>;
21
+ /** Clear all cached token results (shared across hook instances) */
22
+ clearCache: () => void;
23
+ };
24
+
25
+ /** Infers the exact return type from executeOrder() */
26
+ type ExecuteOrderResult = Awaited<ReturnType<typeof executeOrder>>;
27
+ /**
28
+ * React hook for executing swap orders via the Shogun SDK with
29
+ * built-in stage tracking, loading states, and error handling.
30
+ *
31
+ * ---
32
+ * ## Features
33
+ * - Live stage updates (processing, approving, signing, submitting, etc.)
34
+ * - Built-in 20-min deadline by default (current timestamp + 1200s)
35
+ * - Safe state handling with unmount guards
36
+ * - Works for both EVM and Solana wallets
37
+ *
38
+ * ---
39
+ * ## Example
40
+ * ```tsx
41
+ * import { useExecuteOrder } from "@shogun-sdk/swap/react"
42
+ *
43
+ * export function SwapButton({ quote, accountAddress, wallet }) {
44
+ * const { execute, status, message, loading } = useExecuteOrder()
45
+ *
46
+ * const handleClick = async () => {
47
+ * await execute({
48
+ * quote,
49
+ * accountAddress,
50
+ * wallet,
51
+ * // Optional: custom 10-minute deadline
52
+ * deadline: Math.floor(Date.now() / 1000) + 10 * 60,
53
+ * })
54
+ * }
55
+ *
56
+ * return (
57
+ * <button disabled={loading} onClick={handleClick}>
58
+ * {loading ? message ?? "Processing..." : "Execute Swap"}
59
+ * </button>
60
+ * )
61
+ * }
62
+ * ```
63
+ */
64
+ declare function useExecuteOrder(): {
65
+ /** Executes the swap order. */
66
+ execute: ({ quote, accountAddress, recipientAddress, wallet, deadline, }: {
67
+ quote: SwapQuoteResponse;
68
+ accountAddress: string;
69
+ recipientAddress?: string;
70
+ wallet: AdaptedWallet | WalletClient;
71
+ deadline?: number;
72
+ }) => Promise<ExecuteOrderResult>;
73
+ /** Current execution stage. */
74
+ status: Stage;
75
+ /** Human-readable status message. */
76
+ message: string | null;
77
+ /** Whether execution is ongoing. */
78
+ loading: boolean;
79
+ /** Raw SDK response data. */
80
+ data: {
81
+ status: boolean;
82
+ txHash: string;
83
+ chainId: number;
84
+ stage: string;
85
+ } | {
86
+ status: boolean;
87
+ message: string;
88
+ stage: string;
89
+ } | null;
90
+ /** Captured error (if execution failed). */
91
+ error: Error | null;
92
+ };
93
+
94
+ /**
95
+ * useQuote — React hook for fetching live swap quotes (single or cross-chain).
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * import { useQuote } from "@shogun-sdk/swap/react"
100
+ *
101
+ * export function SwapQuote({ params }) {
102
+ * const { data, loading, error, warning, refetch } = useQuote(params, { debounceMs: 300 })
103
+ *
104
+ * if (loading) return <p>Fetching quote...</p>
105
+ * if (error) return <p style={{ color: "red" }}>{error.message}</p>
106
+ * if (warning) return <p style={{ color: "orange" }}>{warning}</p>
107
+ *
108
+ * return (
109
+ * <div>
110
+ * <p>Output: {data?.amountOut.toString()}</p>
111
+ * <p>Reduced (after slippage): {data?.internal?.estimatedAmountOutReduced?.toString()}</p>
112
+ * <button onClick={refetch}>Refresh</button>
113
+ * </div>
114
+ * )
115
+ * }
116
+ * ```
117
+ */
118
+ declare function useQuote(params: SwapQuoteParams | null, options?: {
119
+ /** Debounce duration (ms) for reactive fetches. Default: 250 */
120
+ debounceMs?: number;
121
+ /** Optional polling interval (ms) for auto refresh */
122
+ autoRefreshMs?: number;
123
+ }): {
124
+ /** Latest quote data */
125
+ data: SwapQuoteResponse | null;
126
+ /** Whether a fetch is ongoing */
127
+ loading: boolean;
128
+ /** Error (if any) */
129
+ error: Error | null;
130
+ /** Warning (e.g. high slippage alert) */
131
+ warning: string | null;
132
+ /** Manual refetch */
133
+ refetch: () => Promise<void>;
134
+ };
135
+
136
+ /**
137
+ * React hook for fetching wallet token balances across EVM + SVM chains.
138
+ *
139
+ * ---
140
+ * ## Example
141
+ * ```tsx
142
+ * const { data, loading, error, refetch } = useBalances({
143
+ * addresses: { evm: evmAddress, svm: svmAddress },
144
+ * })
145
+ * ```
146
+ */
147
+ declare function useBalances(params: BalanceRequestParams | null): {
148
+ /** Latest fetched balance data */
149
+ data: BalanceResponse | null;
150
+ /** Whether the hook is currently fetching */
151
+ loading: boolean;
152
+ /** Error object if fetching failed */
153
+ error: Error | null;
154
+ /** Manually trigger a refresh */
155
+ refetch: () => Promise<BalanceResponse | undefined>;
156
+ };
157
+
158
+ export { BalanceRequestParams, BalanceResponse, Stage, SwapQuoteParams, SwapQuoteResponse, useBalances, useExecuteOrder, useQuote, useTokenList };
@@ -0,0 +1,158 @@
1
+ import { TokenSearchParams, TokenSearchResponse } from '@shogun-sdk/intents-sdk';
2
+ export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
3
+ import { a as SwapQuoteResponse, e as executeOrder, b as Stage, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-HX1fQ7wG.js';
4
+ export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-HX1fQ7wG.js';
5
+ import { A as AdaptedWallet } from './wallet-MmUIz8GE.js';
6
+ import { WalletClient } from 'viem';
7
+ import '@mysten/sui/transactions';
8
+ import '@solana/web3.js';
9
+
10
+ declare function useTokenList(params: TokenSearchParams & {
11
+ debounceMs?: number;
12
+ }): {
13
+ /** Current fetched data (cached when possible) */
14
+ data: TokenSearchResponse | null;
15
+ /** Whether a request is in progress */
16
+ loading: boolean;
17
+ /** Error object if a request failed */
18
+ error: Error | null;
19
+ /** Manually refetch the token list */
20
+ refetch: () => Promise<void>;
21
+ /** Clear all cached token results (shared across hook instances) */
22
+ clearCache: () => void;
23
+ };
24
+
25
+ /** Infers the exact return type from executeOrder() */
26
+ type ExecuteOrderResult = Awaited<ReturnType<typeof executeOrder>>;
27
+ /**
28
+ * React hook for executing swap orders via the Shogun SDK with
29
+ * built-in stage tracking, loading states, and error handling.
30
+ *
31
+ * ---
32
+ * ## Features
33
+ * - Live stage updates (processing, approving, signing, submitting, etc.)
34
+ * - Built-in 20-min deadline by default (current timestamp + 1200s)
35
+ * - Safe state handling with unmount guards
36
+ * - Works for both EVM and Solana wallets
37
+ *
38
+ * ---
39
+ * ## Example
40
+ * ```tsx
41
+ * import { useExecuteOrder } from "@shogun-sdk/swap/react"
42
+ *
43
+ * export function SwapButton({ quote, accountAddress, wallet }) {
44
+ * const { execute, status, message, loading } = useExecuteOrder()
45
+ *
46
+ * const handleClick = async () => {
47
+ * await execute({
48
+ * quote,
49
+ * accountAddress,
50
+ * wallet,
51
+ * // Optional: custom 10-minute deadline
52
+ * deadline: Math.floor(Date.now() / 1000) + 10 * 60,
53
+ * })
54
+ * }
55
+ *
56
+ * return (
57
+ * <button disabled={loading} onClick={handleClick}>
58
+ * {loading ? message ?? "Processing..." : "Execute Swap"}
59
+ * </button>
60
+ * )
61
+ * }
62
+ * ```
63
+ */
64
+ declare function useExecuteOrder(): {
65
+ /** Executes the swap order. */
66
+ execute: ({ quote, accountAddress, recipientAddress, wallet, deadline, }: {
67
+ quote: SwapQuoteResponse;
68
+ accountAddress: string;
69
+ recipientAddress?: string;
70
+ wallet: AdaptedWallet | WalletClient;
71
+ deadline?: number;
72
+ }) => Promise<ExecuteOrderResult>;
73
+ /** Current execution stage. */
74
+ status: Stage;
75
+ /** Human-readable status message. */
76
+ message: string | null;
77
+ /** Whether execution is ongoing. */
78
+ loading: boolean;
79
+ /** Raw SDK response data. */
80
+ data: {
81
+ status: boolean;
82
+ txHash: string;
83
+ chainId: number;
84
+ stage: string;
85
+ } | {
86
+ status: boolean;
87
+ message: string;
88
+ stage: string;
89
+ } | null;
90
+ /** Captured error (if execution failed). */
91
+ error: Error | null;
92
+ };
93
+
94
+ /**
95
+ * useQuote — React hook for fetching live swap quotes (single or cross-chain).
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * import { useQuote } from "@shogun-sdk/swap/react"
100
+ *
101
+ * export function SwapQuote({ params }) {
102
+ * const { data, loading, error, warning, refetch } = useQuote(params, { debounceMs: 300 })
103
+ *
104
+ * if (loading) return <p>Fetching quote...</p>
105
+ * if (error) return <p style={{ color: "red" }}>{error.message}</p>
106
+ * if (warning) return <p style={{ color: "orange" }}>{warning}</p>
107
+ *
108
+ * return (
109
+ * <div>
110
+ * <p>Output: {data?.amountOut.toString()}</p>
111
+ * <p>Reduced (after slippage): {data?.internal?.estimatedAmountOutReduced?.toString()}</p>
112
+ * <button onClick={refetch}>Refresh</button>
113
+ * </div>
114
+ * )
115
+ * }
116
+ * ```
117
+ */
118
+ declare function useQuote(params: SwapQuoteParams | null, options?: {
119
+ /** Debounce duration (ms) for reactive fetches. Default: 250 */
120
+ debounceMs?: number;
121
+ /** Optional polling interval (ms) for auto refresh */
122
+ autoRefreshMs?: number;
123
+ }): {
124
+ /** Latest quote data */
125
+ data: SwapQuoteResponse | null;
126
+ /** Whether a fetch is ongoing */
127
+ loading: boolean;
128
+ /** Error (if any) */
129
+ error: Error | null;
130
+ /** Warning (e.g. high slippage alert) */
131
+ warning: string | null;
132
+ /** Manual refetch */
133
+ refetch: () => Promise<void>;
134
+ };
135
+
136
+ /**
137
+ * React hook for fetching wallet token balances across EVM + SVM chains.
138
+ *
139
+ * ---
140
+ * ## Example
141
+ * ```tsx
142
+ * const { data, loading, error, refetch } = useBalances({
143
+ * addresses: { evm: evmAddress, svm: svmAddress },
144
+ * })
145
+ * ```
146
+ */
147
+ declare function useBalances(params: BalanceRequestParams | null): {
148
+ /** Latest fetched balance data */
149
+ data: BalanceResponse | null;
150
+ /** Whether the hook is currently fetching */
151
+ loading: boolean;
152
+ /** Error object if fetching failed */
153
+ error: Error | null;
154
+ /** Manually trigger a refresh */
155
+ refetch: () => Promise<BalanceResponse | undefined>;
156
+ };
157
+
158
+ export { BalanceRequestParams, BalanceResponse, Stage, SwapQuoteParams, SwapQuoteResponse, useBalances, useExecuteOrder, useQuote, useTokenList };