@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/core.cjs +408 -110
- package/dist/core.d.cts +4 -137
- package/dist/core.d.ts +4 -137
- package/dist/core.js +386 -86
- package/dist/index-CmsKzdEu.d.cts +377 -0
- package/dist/index-Qoc6Q9XN.d.ts +377 -0
- package/dist/index.cjs +401 -497
- package/dist/index.d.cts +4 -9
- package/dist/index.d.ts +4 -9
- package/dist/index.js +379 -475
- package/dist/react.cjs +924 -469
- package/dist/react.d.cts +258 -82
- package/dist/react.d.ts +258 -82
- package/dist/react.js +890 -443
- package/dist/{wallet-BhuMJ3K_.d.cts → wallet-B9bKceyN.d.cts} +1 -2
- package/dist/{wallet-BhuMJ3K_.d.ts → wallet-B9bKceyN.d.ts} +1 -2
- package/dist/wallet-adapter.cjs +25607 -11
- package/dist/wallet-adapter.d.cts +1 -2
- package/dist/wallet-adapter.d.ts +1 -2
- package/dist/wallet-adapter.js +25626 -6
- package/package.json +44 -14
- package/dist/execute-D2qcOzkI.d.ts +0 -145
- package/dist/execute-Xvw4wXBo.d.cts +0 -145
package/dist/react.d.cts
CHANGED
|
@@ -1,124 +1,300 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-Xvw4wXBo.cjs';
|
|
5
|
-
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
|
|
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-CmsKzdEu.cjs';
|
|
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-CmsKzdEu.cjs';
|
|
6
4
|
import { WalletClient } from 'viem';
|
|
7
|
-
import '
|
|
5
|
+
import { A as AdaptedWallet } from './wallet-B9bKceyN.cjs';
|
|
6
|
+
import { ApiUserOrders } from '@shogun-sdk/intents-sdk';
|
|
8
7
|
import '@solana/web3.js';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
error: Error | null;
|
|
19
|
-
/** Manually refetch the token list */
|
|
78
|
+
error: string | null;
|
|
20
79
|
refetch: () => Promise<void>;
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
*
|
|
29
|
-
*
|
|
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
|
|
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
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
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
|
|
58
|
-
|
|
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
|
|
125
|
+
recipientAddress: string;
|
|
63
126
|
wallet: AdaptedWallet | WalletClient;
|
|
64
|
-
|
|
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:
|
|
78
|
-
stage:
|
|
131
|
+
finalStatus: string;
|
|
132
|
+
stage: string;
|
|
79
133
|
} | {
|
|
80
134
|
status: boolean;
|
|
81
135
|
message: string;
|
|
82
136
|
stage: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
*
|
|
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
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
210
|
+
* React hook to fetch metadata and price for one or multiple tokens using the Swap SDK.
|
|
104
211
|
*
|
|
105
212
|
* ---
|
|
106
|
-
* ##
|
|
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
|
|
109
|
-
*
|
|
110
|
-
*
|
|
222
|
+
* const { data, loading, error } = useTokensData([
|
|
223
|
+
* "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
|
|
224
|
+
* "0xC02aaa39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
225
|
+
* ]);
|
|
111
226
|
* ```
|
|
112
227
|
*/
|
|
113
|
-
declare function
|
|
114
|
-
|
|
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
|
-
|
|
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 };
|