@shogun-sdk/swap 0.0.2-test.25 → 0.0.2-test.27

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/react.d.ts CHANGED
@@ -1,124 +1,300 @@
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, g as PollResult, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-D2qcOzkI.js';
4
- export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-D2qcOzkI.js';
5
- import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
1
+ import React from 'react';
2
+ import { S as SwapSDKConfig, a as SwapSDK, b as SwapQuoteParams, c as SwapQuoteResponse, E as ExecuteOrderParams, d as Stage, P as PlaceOrderResult, T as TokenInfo, B as BalanceRequestParams, e as BalanceResponse } from './index-Qoc6Q9XN.js';
3
+ export { C as ChainId, O as OrderExecutionType, j as SupportedChain, g as SupportedChains, h as TokenBalance, f as buildQuoteParams, i as isEvmChain } from './index-Qoc6Q9XN.js';
6
4
  import { WalletClient } from 'viem';
7
- import '@mysten/sui/transactions';
5
+ import { A as AdaptedWallet } from './wallet-B9bKceyN.js';
6
+ import { ApiUserOrders } from '@shogun-sdk/intents-sdk';
8
7
  import '@solana/web3.js';
9
8
 
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 */
9
+ /**
10
+ * @fileoverview React provider for Swap SDK
11
+ *
12
+ * This provider initializes a single instance of `SwapSDK` and
13
+ * makes it available to all child components via React context.
14
+ *
15
+ * Usage:
16
+ * ```tsx
17
+ * <SwapProvider config={{ apiKey: "your-api-key" }}>
18
+ * <App />
19
+ * </SwapProvider>
20
+ * ```
21
+ *
22
+ * Then, access it anywhere:
23
+ * ```tsx
24
+ * const sdk = useSwap();
25
+ * const quote = await sdk.getQuote({ ... });
26
+ * ```
27
+ */
28
+
29
+ /**
30
+ * Provides a `SwapSDK` instance to React components.
31
+ */
32
+ declare const SwapProvider: React.FC<React.PropsWithChildren<{
33
+ config: SwapSDKConfig;
34
+ }>>;
35
+ /**
36
+ * Hook to access the initialized `SwapSDK` instance.
37
+ *
38
+ * Must be used within a `<SwapProvider>` context.
39
+ *
40
+ * @throws Will throw if called outside of `<SwapProvider>`.
41
+ */
42
+ declare const useSwap: () => SwapSDK;
43
+
44
+ /**
45
+ * Augment globalThis to safely hold a shared quote params reference.
46
+ */
47
+ declare global {
48
+ var __QUOTE_PARAMS_REF__: {
49
+ current: SwapQuoteParams | null;
50
+ } | undefined;
51
+ }
52
+ /**
53
+ * Centralized SWR-powered hook for fetching swap quotes.
54
+ *
55
+ * This hook provides:
56
+ * - A globally shared quote state (via SWR global cache)
57
+ * - Abort-safe refetching logic
58
+ * - Consistent parameters shared across multiple components
59
+ * - Easy revalidation triggers
60
+ *
61
+ * @param initialParams Optional initial quote parameters.
62
+ * @returns Object containing quote data, loading state, refetch and setParams methods.
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * const { data, loading, error, refetch, setParams } = useQuote({
67
+ * tokenIn: "0x123...",
68
+ * tokenOut: "0xabc...",
69
+ * amount: "1000000000000000000",
70
+ * srcChainId: 1,
71
+ * destChainId: 8453,
72
+ * });
73
+ * ```
74
+ */
75
+ declare function useQuote(initialParams?: SwapQuoteParams | null): {
76
+ data: SwapQuoteResponse | null | undefined;
16
77
  loading: boolean;
17
- /** Error object if a request failed */
18
- error: Error | null;
19
- /** Manually refetch the token list */
78
+ error: string | null;
20
79
  refetch: () => Promise<void>;
21
- /** Clear all cached token results (shared across hook instances) */
22
- clearCache: () => void;
80
+ setParams: (next: SwapQuoteParams | null) => void;
81
+ readonly activeParams: SwapQuoteParams | null;
23
82
  };
24
83
 
25
- /** Infers the exact return type from executeOrder() */
26
- type ExecuteOrderResult = Awaited<ReturnType<typeof executeOrder>>;
27
84
  /**
28
- * React hook for executing swap orders via the Shogun SDK with
29
- * built-in stage tracking, loading states, and error handling.
85
+ * `useExecuteTransaction`
86
+ *
87
+ * React hook to execute a swap transaction (EVM or Solana) using the Swap SDK.
88
+ * It provides live transaction status updates through stage-based tracking.
30
89
  *
31
90
  * ---
32
- * ## Example
91
+ * ## Features
92
+ * - Handles the full swap lifecycle: token approval → execution → confirmation
93
+ * - Tracks execution stage and status messages in real time
94
+ * - Automatically refreshes balances and latest quote data after completion
95
+ * - Supports both EVM and Solana (SVM) wallets
96
+ * - Works seamlessly with market and limit orders
97
+ *
98
+ * @example
33
99
  * ```tsx
34
- * import { useExecuteOrder } from "@shogun-sdk/swap/react"
35
- *
36
- * export function SwapButton({ quote, accountAddress, wallet }) {
37
- * const { execute, status, message, loading } = useExecuteOrder()
38
- *
39
- * const handleClick = async () => {
40
- * await execute({
41
- * quote,
42
- * accountAddress,
43
- * wallet,
44
- * // Optional: custom 10-minute deadline
45
- * deadline: Math.floor(Date.now() / 1000) + 10 * 60,
46
- * })
47
- * }
48
- *
49
- * return (
50
- * <button disabled={loading} onClick={handleClick}>
51
- * {loading ? message ?? "Processing..." : "Execute Swap"}
52
- * </button>
53
- * )
54
- * }
100
+ * const { execute, isLoading, stage, message, result, error } = useExecuteTransaction();
101
+ *
102
+ * * Example: Market order
103
+ * await execute({
104
+ * quote,
105
+ * accountAddress: "0x123...",
106
+ * wallet,
107
+ * orderType: OrderExecutionType.MARKET,
108
+ * options: { deadline: 1800 },
109
+ * });
110
+ *
111
+ * * Example: Limit order
112
+ * await execute({
113
+ * quote,
114
+ * accountAddress: "0x123...",
115
+ * wallet,
116
+ * orderType: OrderExecutionType.LIMIT,
117
+ * options: { executionPrice: "0.0021", deadline: 3600 },
118
+ * });
55
119
  * ```
56
120
  */
57
- declare function useExecuteOrder(): {
58
- /** Executes the swap order. */
59
- execute: ({ quote, accountAddress, recipientAddress, wallet, deadline, }: {
121
+ declare function useExecuteTransaction(): {
122
+ execute: ({ quote, accountAddress, recipientAddress, wallet, orderType, options, }: {
60
123
  quote: SwapQuoteResponse;
61
124
  accountAddress: string;
62
- recipientAddress?: string;
125
+ recipientAddress: string;
63
126
  wallet: AdaptedWallet | WalletClient;
64
- deadline?: number;
65
- }) => Promise<ExecuteOrderResult>;
66
- /** Current execution stage. */
67
- status: Stage;
68
- /** Human-readable status message. */
69
- message: string | null;
70
- /** Whether execution is ongoing. */
71
- loading: boolean;
72
- /** Raw SDK response data. */
73
- data: {
127
+ } & ExecuteOrderParams) => Promise<{
74
128
  status: boolean;
75
129
  orderId: string;
76
130
  chainId: number;
77
- finalStatus: PollResult;
78
- stage: Stage;
131
+ finalStatus: string;
132
+ stage: string;
79
133
  } | {
80
134
  status: boolean;
81
135
  message: string;
82
136
  stage: string;
83
- } | null;
84
- /** Captured error (if execution failed). */
85
- error: Error | null;
137
+ }>;
138
+ isLoading: boolean;
139
+ stage: Stage | null;
140
+ message: string | null;
141
+ error: string | null;
142
+ result: PlaceOrderResult | null;
86
143
  };
87
144
 
88
145
  /**
89
- * useQuote — React hook for fetching live swap quotes.
146
+ * React hook for searching and paginating verified tokens using the Swap SDK.
147
+ *
148
+ * ## Features
149
+ * - Optional `networkId` for chain-specific or global search
150
+ * - Caches results per query and page to minimize redundant API calls
151
+ * - Supports infinite scroll-style pagination
152
+ * - Provides loading, error, and `hasMore` state tracking
153
+ *
154
+ * @example
155
+ * ```tsx
156
+ * const { tokens, loadTokens, hasMore, loading } = useTokenList();
157
+ *
158
+ * useEffect(() => {
159
+ * loadTokens({ q: "USDC", networkId: 1, reset: true });
160
+ * }, []);
161
+ * ```
90
162
  */
91
- declare function useQuote(params: SwapQuoteParams | null, options?: {
92
- debounceMs?: number;
93
- autoRefreshMs?: number;
94
- }): {
95
- data: SwapQuoteResponse | null;
163
+ declare function useTokenList(): {
164
+ tokens: TokenInfo[];
165
+ loading: boolean;
166
+ error: string | null;
167
+ hasMore: boolean;
168
+ page: number;
169
+ lastQuery: {
170
+ q?: string;
171
+ networkId?: number;
172
+ };
173
+ loadTokens: (params: {
174
+ q?: string;
175
+ networkId?: number;
176
+ reset?: boolean;
177
+ }) => Promise<void>;
178
+ resetTokens: () => void;
179
+ };
180
+
181
+ /**
182
+ * Augment globalThis to safely hold a shared params reference.
183
+ */
184
+ declare global {
185
+ var __BALANCES_PARAMS_REF__: {
186
+ current: BalanceRequestParams | null;
187
+ } | undefined;
188
+ }
189
+ /**
190
+ * SWR-powered, centralized balance fetching hook.
191
+ *
192
+ * ## Features
193
+ * - Shared global cache across all components (SWR)
194
+ * - Strongly typed params and responses
195
+ * - Abort-safe concurrent refetch
196
+ * - Centralized params sync using `globalThis`
197
+ * - Keeps previous data during refetch (no reset)
198
+ * - Auto-refetch when initialParams change (svm_address or evm_address)
199
+ */
200
+ declare function useBalances(initialParams?: BalanceRequestParams | null): {
201
+ data: BalanceResponse | null | undefined;
96
202
  loading: boolean;
97
203
  error: Error | null;
98
- warning: string | null;
99
204
  refetch: () => Promise<void>;
205
+ setParams: (next: BalanceRequestParams | null) => void;
206
+ readonly activeParams: BalanceRequestParams | null;
100
207
  };
101
208
 
102
209
  /**
103
- * React hook for fetching wallet token balances across EVM + SVM chains.
210
+ * React hook to fetch metadata and price for one or multiple tokens using the Swap SDK.
104
211
  *
105
212
  * ---
106
- * ## Example
213
+ * ## Features
214
+ * - Automatically fetches token metadata and price info
215
+ * - Handles loading and error states
216
+ * - Works with both EVM and SVM tokens
217
+ *
218
+ * @param addresses - List of token contract addresses to fetch.
219
+ *
220
+ * @example
107
221
  * ```tsx
108
- * const { data, loading, error, refetch } = useBalances({
109
- * addresses: { evm: evmAddress, svm: svmAddress },
110
- * })
222
+ * const { data, loading, error } = useTokensData([
223
+ * "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
224
+ * "0xC02aaa39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
225
+ * ]);
111
226
  * ```
112
227
  */
113
- declare function useBalances(params: BalanceRequestParams | null): {
114
- /** Latest fetched balance data */
115
- data: BalanceResponse | null;
116
- /** Whether the hook is currently fetching */
228
+ declare function useTokensData(addresses: string[]): {
229
+ data: TokenInfo[];
117
230
  loading: boolean;
118
- /** Error object if fetching failed */
119
231
  error: Error | null;
120
- /** Manually trigger a refresh */
121
- refetch: () => Promise<BalanceResponse | undefined>;
122
232
  };
123
233
 
124
- export { BalanceRequestParams, BalanceResponse, Stage, SwapQuoteParams, SwapQuoteResponse, useBalances, useExecuteOrder, useQuote, useTokenList };
234
+ /**
235
+ * @fileoverview Centralized SWR hook for fetching user orders via the Swap SDK.
236
+ *
237
+ * ## Features
238
+ * - Shared global cache via SWR
239
+ * - Abort-safe concurrent requests
240
+ * - Accepts addresses via params or setAddresses()
241
+ * - No auto-refresh (manual control)
242
+ */
243
+
244
+ /**
245
+ * Augment globalThis to safely hold a shared address ref.
246
+ */
247
+ declare global {
248
+ var __ORDERS_ADDR_REF__: {
249
+ current: {
250
+ evmAddress?: string | null;
251
+ solAddress?: string | null;
252
+ suiAddress?: string | null;
253
+ } | null;
254
+ } | undefined;
255
+ }
256
+ /**
257
+ * Centralized SWR-powered hook for fetching user orders.
258
+ *
259
+ * ---
260
+ * ### Features
261
+ * - Shared global cache via SWR (no auto revalidation)
262
+ * - Manual `refetch()` support
263
+ * - Pass addresses directly or set later with `setAddresses()`
264
+ * - Safe abort for concurrent requests
265
+ *
266
+ * @example
267
+ * ```tsx
268
+ * const { data, loading, error, setAddresses, refetch } = useOrders();
269
+ *
270
+ * // Later, you can set addresses manually:
271
+ * useEffect(() => {
272
+ * setAddresses({ evmAddress: "0x123..." });
273
+ * }, []);
274
+ *
275
+ * // Or pass them directly:
276
+ * const { data } = useOrders({ evmAddress: "0x123..." });
277
+ * ```
278
+ */
279
+ declare function useOrders(initialAddresses?: {
280
+ evmAddress?: string | null;
281
+ solAddress?: string | null;
282
+ suiAddress?: string | null;
283
+ }): {
284
+ data: ApiUserOrders | null | undefined;
285
+ loading: boolean;
286
+ error: string | null;
287
+ refetch: () => Promise<void>;
288
+ setAddresses: (next: {
289
+ evmAddress?: string | null;
290
+ solAddress?: string | null;
291
+ suiAddress?: string | null;
292
+ }) => void;
293
+ readonly activeAddresses: {
294
+ evmAddress?: string | null;
295
+ solAddress?: string | null;
296
+ suiAddress?: string | null;
297
+ } | null;
298
+ };
299
+
300
+ export { BalanceRequestParams, BalanceResponse, SwapProvider, SwapQuoteParams, SwapQuoteResponse, useBalances, useExecuteTransaction, useOrders, useQuote, useSwap, useTokenList, useTokensData };