@shogun-sdk/swap 0.0.2-test.4 → 0.0.2-test.40

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,134 +1,331 @@
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';
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-DB1gT72l.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-DB1gT72l.js';
6
4
  import { WalletClient } from 'viem';
7
- import '@mysten/sui/transactions';
5
+ import { A as AdaptedWallet } from './wallet-B9bKceyN.js';
6
+ import { ApiUserOrders, ApiCrossChainOrder, ApiSingleChainOrder } 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
91
  * ## 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
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
37
97
  *
38
- * ---
39
- * ## Example
98
+ * @example
40
99
  * ```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
- * }
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
+ * });
62
119
  * ```
63
120
  */
64
- declare function useExecuteOrder(): {
65
- /** Executes the swap order. */
66
- execute: ({ quote, accountAddress, recipientAddress, wallet, deadline, }: {
121
+ declare function useExecuteTransaction(): {
122
+ execute: ({ quote, accountAddress, recipientAddress, wallet, orderType, options, }: {
67
123
  quote: SwapQuoteResponse;
68
124
  accountAddress: string;
69
- recipientAddress?: string;
125
+ recipientAddress: string;
70
126
  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: {
127
+ } & ExecuteOrderParams) => Promise<{
81
128
  status: boolean;
82
- txHash: string;
129
+ orderId: string;
83
130
  chainId: number;
131
+ finalStatus: string;
84
132
  stage: string;
85
133
  } | {
86
134
  status: boolean;
87
135
  message: string;
88
136
  stage: string;
89
- } | null;
90
- /** Captured error (if execution failed). */
91
- error: Error | null;
137
+ }>;
138
+ isLoading: boolean;
139
+ stage: Stage | null;
140
+ message: string | null;
141
+ error: string | null;
142
+ result: PlaceOrderResult | null;
92
143
  };
93
144
 
94
145
  /**
95
- * 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();
96
157
  *
97
- * - Supports debounce and auto-refresh.
98
- * - Safe for React 18+ (no double fetch).
99
- * - Compatible with AbortController.
158
+ * useEffect(() => {
159
+ * loadTokens({ q: "USDC", networkId: 1, reset: true });
160
+ * }, []);
161
+ * ```
100
162
  */
101
- declare function useQuote(params: SwapQuoteParams, options?: {
102
- debounceMs?: number;
103
- autoRefreshMs?: number;
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, options?: {
201
+ refreshInterval?: number;
104
202
  }): {
105
- data: SwapQuoteResponse | null;
203
+ data: BalanceResponse | null | undefined;
106
204
  loading: boolean;
205
+ isValidating: boolean;
107
206
  error: Error | null;
108
- warning: string | null;
109
207
  refetch: () => Promise<void>;
208
+ setParams: (next: BalanceRequestParams | null) => void;
209
+ readonly activeParams: BalanceRequestParams | null;
110
210
  };
111
211
 
112
212
  /**
113
- * React hook for fetching wallet token balances across EVM + SVM chains.
213
+ * React hook to fetch metadata and price for one or multiple tokens using the Swap SDK.
114
214
  *
115
215
  * ---
116
- * ## Example
216
+ * ## Features
217
+ * - Automatically fetches token metadata and price info
218
+ * - Handles loading and error states
219
+ * - Works with both EVM and SVM tokens
220
+ *
221
+ * @param addresses - List of token contract addresses to fetch.
222
+ *
223
+ * @example
117
224
  * ```tsx
118
- * const { data, loading, error, refetch } = useBalances({
119
- * addresses: { evm: evmAddress, svm: svmAddress },
120
- * })
225
+ * const { data, loading, error } = useTokensData([
226
+ * "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
227
+ * "0xC02aaa39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
228
+ * ]);
121
229
  * ```
122
230
  */
123
- declare function useBalances(params: BalanceRequestParams | null): {
124
- /** Latest fetched balance data */
125
- data: BalanceResponse | null;
126
- /** Whether the hook is currently fetching */
231
+ declare function useTokensData(addresses: string[]): {
232
+ data: TokenInfo[];
127
233
  loading: boolean;
128
- /** Error object if fetching failed */
129
234
  error: Error | null;
130
- /** Manually trigger a refresh */
131
- refetch: () => Promise<BalanceResponse | undefined>;
132
235
  };
133
236
 
134
- export { BalanceRequestParams, BalanceResponse, Stage, SwapQuoteParams, SwapQuoteResponse, useBalances, useExecuteOrder, useQuote, useTokenList };
237
+ /**
238
+ * @fileoverview Centralized SWR hook for fetching user orders via the Swap SDK.
239
+ *
240
+ * ## Features
241
+ * - Shared global cache via SWR
242
+ * - Abort-safe concurrent requests
243
+ * - Accepts addresses via params or setAddresses()
244
+ * - No auto-refresh (manual control)
245
+ */
246
+
247
+ /**
248
+ * Augment globalThis to safely hold a shared address ref.
249
+ */
250
+ declare global {
251
+ var __ORDERS_ADDR_REF__: {
252
+ current: {
253
+ evmAddress?: string | null;
254
+ solAddress?: string | null;
255
+ suiAddress?: string | null;
256
+ } | null;
257
+ } | undefined;
258
+ }
259
+ /**
260
+ * Centralized SWR-powered hook for fetching user orders.
261
+ *
262
+ * ---
263
+ * ### Features
264
+ * - Shared global cache via SWR (no auto revalidation)
265
+ * - Manual `refetch()` support
266
+ * - Pass addresses directly or set later with `setAddresses()`
267
+ * - Safe abort for concurrent requests
268
+ *
269
+ * @example
270
+ * ```tsx
271
+ * const { data, loading, error, setAddresses, refetch } = useOrders();
272
+ *
273
+ * // Later, you can set addresses manually:
274
+ * useEffect(() => {
275
+ * setAddresses({ evmAddress: "0x123..." });
276
+ * }, []);
277
+ *
278
+ * // Or pass them directly:
279
+ * const { data } = useOrders({ evmAddress: "0x123..." });
280
+ * ```
281
+ */
282
+ declare function useOrders(initialAddresses?: {
283
+ evmAddress?: string | null;
284
+ solAddress?: string | null;
285
+ suiAddress?: string | null;
286
+ }): {
287
+ data: ApiUserOrders | null | undefined;
288
+ loading: boolean;
289
+ error: string | null;
290
+ refetch: () => Promise<void>;
291
+ setAddresses: (next: {
292
+ evmAddress?: string | null;
293
+ solAddress?: string | null;
294
+ suiAddress?: string | null;
295
+ }) => void;
296
+ readonly activeAddresses: {
297
+ evmAddress?: string | null;
298
+ solAddress?: string | null;
299
+ suiAddress?: string | null;
300
+ } | null;
301
+ };
302
+
303
+ /**
304
+ * `useCancelOrder`
305
+ *
306
+ * React hook to cancel an intents order (single-chain or cross-chain) on EVM or Solana.
307
+ * Returns helpers for loading/error state and the resulting transaction hash/signature.
308
+ *
309
+ * @example
310
+ * ```tsx
311
+ * const { cancel, isLoading, error, result } = useCancelOrder();
312
+ *
313
+ * await cancel({
314
+ * order,
315
+ * wallet, // AdaptedWallet instance
316
+ * solRpc: "https://api.mainnet-beta.solana.com",
317
+ * });
318
+ * ```
319
+ */
320
+ declare function useCancelOrder(): {
321
+ cancel: (params: {
322
+ order: ApiCrossChainOrder | ApiSingleChainOrder;
323
+ wallet: AdaptedWallet;
324
+ solRpc: string;
325
+ }) => Promise<string>;
326
+ isLoading: boolean;
327
+ error: string | null;
328
+ result: string | null;
329
+ };
330
+
331
+ export { BalanceRequestParams, BalanceResponse, SwapProvider, SwapQuoteParams, SwapQuoteResponse, useBalances, useCancelOrder, useExecuteTransaction, useOrders, useQuote, useSwap, useTokenList, useTokensData };