@shogun-sdk/swap 0.0.2-test.3 → 0.0.2-test.31
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 +984 -157
- package/dist/core.d.cts +4 -136
- package/dist/core.d.ts +4 -136
- package/dist/core.js +983 -129
- package/dist/index-CXY6BUx9.d.ts +394 -0
- package/dist/index-CtZ-hgYk.d.cts +394 -0
- package/dist/index.cjs +973 -527
- package/dist/index.d.cts +4 -9
- package/dist/index.d.ts +4 -9
- package/dist/index.js +972 -496
- package/dist/react.cjs +1517 -484
- package/dist/react.d.cts +283 -89
- package/dist/react.d.ts +283 -89
- package/dist/react.js +1510 -467
- package/dist/{wallet-MmUIz8GE.d.cts → wallet-B9bKceyN.d.cts} +3 -3
- package/dist/{wallet-MmUIz8GE.d.ts → wallet-B9bKceyN.d.ts} +3 -3
- package/dist/wallet-adapter.cjs +25659 -27
- package/dist/wallet-adapter.d.cts +1 -2
- package/dist/wallet-adapter.d.ts +1 -2
- package/dist/wallet-adapter.js +25679 -16
- package/package.json +44 -14
- package/dist/execute-FaLLPp1i.d.cts +0 -147
- package/dist/execute-HX1fQ7wG.d.ts +0 -147
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { ChainID, QuoteResponse, ChainOrderStatus, TokenSearchResponse as TokenSearchResponse$1, TokenSearchParams, ApiUserOrders, ApiCrossChainOrder, ApiSingleChainOrder, isEvmChain as isEvmChain$1 } from '@shogun-sdk/intents-sdk';
|
|
2
|
+
import { A as AdaptedWallet } from './wallet-B9bKceyN.cjs';
|
|
3
|
+
import { WalletClient } from 'viem';
|
|
4
|
+
|
|
5
|
+
type ChainId$1 = ChainID;
|
|
6
|
+
interface SupportedChain {
|
|
7
|
+
id: ChainId$1;
|
|
8
|
+
name: string;
|
|
9
|
+
isEVM: boolean;
|
|
10
|
+
wrapped: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
decimals: number;
|
|
13
|
+
tokenAddress: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Token metadata used in quotes.
|
|
18
|
+
* Provides address, decimals, and optional symbol.
|
|
19
|
+
*/
|
|
20
|
+
type QuoteTokenInfo = {
|
|
21
|
+
/** Token contract or mint address (EVM/Solana/Sui) */
|
|
22
|
+
address: string;
|
|
23
|
+
/** Number of decimals for precise conversion */
|
|
24
|
+
decimals: number;
|
|
25
|
+
/** Optional symbol (for display purposes only) */
|
|
26
|
+
symbol?: string;
|
|
27
|
+
chainId: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 🔧 SwapQuoteParams — input shape for requesting a swap quote.
|
|
31
|
+
*
|
|
32
|
+
* Works for both EVM and non-EVM chains (Solana, Sui, etc.).
|
|
33
|
+
*/
|
|
34
|
+
type SwapQuoteParams = {
|
|
35
|
+
/** Token you’re swapping *from* */
|
|
36
|
+
tokenIn: QuoteTokenInfo;
|
|
37
|
+
/** Token you’re swapping *to* */
|
|
38
|
+
tokenOut: QuoteTokenInfo;
|
|
39
|
+
/** The source chain ID — where the swap starts */
|
|
40
|
+
sourceChainId: ChainId$1;
|
|
41
|
+
/** The destination chain ID — where the swap ends */
|
|
42
|
+
destChainId: ChainId$1;
|
|
43
|
+
/** Input amount (smallest unit — wei, lamports, etc.) */
|
|
44
|
+
amount: string;
|
|
45
|
+
slippage?: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 💱 SwapQuoteResponse — output returned by `getQuote()`.
|
|
49
|
+
*/
|
|
50
|
+
type SwapQuoteResponse = {
|
|
51
|
+
/** Input token amount (smallest units, e.g. wei, lamports, etc.) */
|
|
52
|
+
amountIn: bigint;
|
|
53
|
+
/** Output token amount after routing/slippage (smallest units) */
|
|
54
|
+
amountOut: bigint;
|
|
55
|
+
/** Estimated USD value of output tokens */
|
|
56
|
+
amountOutUsd: number;
|
|
57
|
+
/** Estimated USD value of input tokens */
|
|
58
|
+
amountInUsd: number;
|
|
59
|
+
/** Minimum stablecoin equivalent for guaranteed slippage bounds */
|
|
60
|
+
minStablecoinsAmount: bigint;
|
|
61
|
+
/** Metadata for input token (includes decimals & chain ID) */
|
|
62
|
+
tokenIn: QuoteTokenInfo & {
|
|
63
|
+
chainId: ChainId$1;
|
|
64
|
+
};
|
|
65
|
+
/** Metadata for output token (includes decimals & chain ID) */
|
|
66
|
+
tokenOut: QuoteTokenInfo & {
|
|
67
|
+
chainId: ChainId$1;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Derived: how many tokenOut for 1 tokenIn (raw, 1e18 scaled bigint)
|
|
71
|
+
* Formula: (amountOut * 1e18) / amountIn
|
|
72
|
+
*/
|
|
73
|
+
pricePerInputToken: bigint;
|
|
74
|
+
internal: QuoteResponse;
|
|
75
|
+
slippage: number;
|
|
76
|
+
warning?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Types representing the structure of user orders and polling results.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
type OrderStatus = ChainOrderStatus | "Timeout" | "NotFound";
|
|
84
|
+
type PollResult = OrderStatus;
|
|
85
|
+
|
|
86
|
+
type Stage = 'processing' | 'approving' | 'approved' | 'signing' | 'submitting' | 'initiated' | 'shogun_processing' | 'success' | 'error';
|
|
87
|
+
type PlaceOrderResult = {
|
|
88
|
+
status: boolean;
|
|
89
|
+
orderId: string;
|
|
90
|
+
chainId: number;
|
|
91
|
+
finalStatus: PollResult;
|
|
92
|
+
stage: Stage;
|
|
93
|
+
} | {
|
|
94
|
+
status: boolean;
|
|
95
|
+
message: string;
|
|
96
|
+
stage: string;
|
|
97
|
+
};
|
|
98
|
+
interface MarketOrderOptions {
|
|
99
|
+
deadline?: number;
|
|
100
|
+
}
|
|
101
|
+
interface LimitOrderOptions {
|
|
102
|
+
executionPrice: string;
|
|
103
|
+
deadline: number;
|
|
104
|
+
}
|
|
105
|
+
type ExecuteOrderParams = {
|
|
106
|
+
orderType?: OrderExecutionType.MARKET;
|
|
107
|
+
options?: MarketOrderOptions;
|
|
108
|
+
} | {
|
|
109
|
+
orderType?: OrderExecutionType.LIMIT;
|
|
110
|
+
options: LimitOrderOptions;
|
|
111
|
+
};
|
|
112
|
+
type ExtendedOrderParams = {
|
|
113
|
+
orderType?: OrderExecutionType;
|
|
114
|
+
options?: MarketOrderOptions | LimitOrderOptions;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
interface BalanceRequestParams {
|
|
118
|
+
/** Object containing wallet addresses for supported chains. */
|
|
119
|
+
addresses: {
|
|
120
|
+
/** EVM-compatible wallet address (optional). */
|
|
121
|
+
evm?: string;
|
|
122
|
+
/** Solana wallet address (optional). */
|
|
123
|
+
svm?: string;
|
|
124
|
+
};
|
|
125
|
+
/** Optional pagination cursor for EVM balances. */
|
|
126
|
+
cursorEvm?: string;
|
|
127
|
+
/** Optional pagination cursor for Solana balances. */
|
|
128
|
+
cursorSvm?: string;
|
|
129
|
+
}
|
|
130
|
+
interface TokenBalance {
|
|
131
|
+
name: string;
|
|
132
|
+
symbol: string;
|
|
133
|
+
chainId: ChainID;
|
|
134
|
+
address: string;
|
|
135
|
+
balance: string;
|
|
136
|
+
balanceUsd: number;
|
|
137
|
+
decimals: number;
|
|
138
|
+
image?: string;
|
|
139
|
+
isNative: boolean;
|
|
140
|
+
}
|
|
141
|
+
interface BalanceResponse {
|
|
142
|
+
/** List of balances across networks. */
|
|
143
|
+
results: TokenBalance[];
|
|
144
|
+
/** Optional pagination cursors */
|
|
145
|
+
nextCursorEvm?: string;
|
|
146
|
+
nextCursorSvm?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type TokenSearchResponse = TokenSearchResponse$1;
|
|
150
|
+
type TokenInfo = {
|
|
151
|
+
address: string;
|
|
152
|
+
symbol: string;
|
|
153
|
+
name: string;
|
|
154
|
+
chainId: number;
|
|
155
|
+
decimals: number;
|
|
156
|
+
image?: string;
|
|
157
|
+
isVerified?: boolean;
|
|
158
|
+
priceUSD?: string;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
declare function getTokensData(addresses: string[]): Promise<TokenInfo[]>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Configuration options for initializing the Swap SDK.
|
|
165
|
+
*/
|
|
166
|
+
type SwapSDKConfig = {
|
|
167
|
+
apiKey: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* SwapSDK — Unified SDK for token discovery, quoting, and transaction execution.
|
|
171
|
+
*
|
|
172
|
+
* Features:
|
|
173
|
+
* - Retrieve real-time swap quotes across EVM and Solana.
|
|
174
|
+
* - Execute swaps using an adapted wallet or standard WalletClient.
|
|
175
|
+
* - Search verified tokens with pagination and query support.
|
|
176
|
+
* - Fetch balances across EVM and SVM chains.
|
|
177
|
+
*
|
|
178
|
+
* Designed to integrate easily with React hooks and Vue composables.
|
|
179
|
+
*/
|
|
180
|
+
declare class SwapSDK {
|
|
181
|
+
private readonly apiKey;
|
|
182
|
+
constructor(config: SwapSDKConfig);
|
|
183
|
+
/**
|
|
184
|
+
* Retrieves a swap quote for the given input and output tokens.
|
|
185
|
+
*
|
|
186
|
+
* @param params - Quote parameters including source/destination tokens and amount.
|
|
187
|
+
* @returns A normalized `SwapQuoteResponse` containing output amount, route, and metadata.
|
|
188
|
+
*/
|
|
189
|
+
getQuote(params: SwapQuoteParams): Promise<SwapQuoteResponse>;
|
|
190
|
+
/**
|
|
191
|
+
* Fetches token balances for the specified user wallet(s).
|
|
192
|
+
*
|
|
193
|
+
* Supports both EVM and SVM (Solana) wallet addresses.
|
|
194
|
+
*
|
|
195
|
+
* @param params - Wallet address and optional chain filters.
|
|
196
|
+
* @param options - Optional abort signal for cancellation.
|
|
197
|
+
* @returns A unified balance response with per-chain token details.
|
|
198
|
+
*/
|
|
199
|
+
getBalances(params: BalanceRequestParams, options?: {
|
|
200
|
+
signal?: AbortSignal;
|
|
201
|
+
}): Promise<BalanceResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Retrieves a list of verified tokens based on search query or chain filter.
|
|
204
|
+
*
|
|
205
|
+
* @param params - Search parameters (query, chain ID, pagination options).
|
|
206
|
+
* @returns Paginated `TokenSearchResponse` containing token metadata.
|
|
207
|
+
*/
|
|
208
|
+
getTokenList(params: TokenSearchParams): Promise<TokenSearchResponse>;
|
|
209
|
+
/**
|
|
210
|
+
* Executes a prepared swap quote using the provided wallet and configuration.
|
|
211
|
+
*
|
|
212
|
+
* Handles:
|
|
213
|
+
* - Token approval (if required)
|
|
214
|
+
* - Transaction signing and broadcasting
|
|
215
|
+
* - Confirmation polling and stage-based status updates
|
|
216
|
+
*
|
|
217
|
+
* Supports both:
|
|
218
|
+
* - Market orders (with optional deadline)
|
|
219
|
+
* - Limit orders (requires executionPrice and deadline)
|
|
220
|
+
*
|
|
221
|
+
* @param quote - The swap quote to execute, containing route and metadata.
|
|
222
|
+
* @param accountAddress - The user's wallet address executing the swap.
|
|
223
|
+
* @param recipientAddress - Optional recipient address for the output tokens (defaults to sender).
|
|
224
|
+
* @param wallet - Adapted wallet instance (EVM/Solana) or a standard Viem `WalletClient`.
|
|
225
|
+
* @param onStatus - Optional callback for receiving execution stage updates and messages.
|
|
226
|
+
* @param orderType - Defines whether this is a market or limit order.
|
|
227
|
+
* @param options - Execution parameters (different per order type).
|
|
228
|
+
*
|
|
229
|
+
* @returns A finalized execution result containing transaction hash, status, and any returned data.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* * Market order
|
|
234
|
+
* const result = await sdk.executeTransaction({
|
|
235
|
+
* quote,
|
|
236
|
+
* accountAddress: "0x123...",
|
|
237
|
+
* wallet,
|
|
238
|
+
* orderType: OrderExecutionType.MARKET,
|
|
239
|
+
* options: { deadline: 1800 },
|
|
240
|
+
* onStatus: (stage, msg) => console.log(stage, msg),
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* * Limit order
|
|
244
|
+
* const result = await sdk.executeTransaction({
|
|
245
|
+
* quote,
|
|
246
|
+
* accountAddress: "0x123...",
|
|
247
|
+
* wallet,
|
|
248
|
+
* orderType: OrderExecutionType.LIMIT,
|
|
249
|
+
* options: { executionPrice: "0.0021", deadline: 3600 },
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
executeTransaction({ quote, accountAddress, recipientAddress, wallet, onStatus, orderType, options, }: {
|
|
254
|
+
quote: SwapQuoteResponse;
|
|
255
|
+
accountAddress: string;
|
|
256
|
+
recipientAddress: string;
|
|
257
|
+
wallet: AdaptedWallet | WalletClient;
|
|
258
|
+
onStatus?: (stage: Stage, message?: string) => void;
|
|
259
|
+
} & ExtendedOrderParams): Promise<{
|
|
260
|
+
status: boolean;
|
|
261
|
+
orderId: string;
|
|
262
|
+
chainId: number;
|
|
263
|
+
finalStatus: string;
|
|
264
|
+
stage: string;
|
|
265
|
+
} | {
|
|
266
|
+
status: boolean;
|
|
267
|
+
message: string;
|
|
268
|
+
stage: string;
|
|
269
|
+
}>;
|
|
270
|
+
/**
|
|
271
|
+
* Fetches metadata for one or more tokens from the Shogun Token Search API.
|
|
272
|
+
*
|
|
273
|
+
* ---
|
|
274
|
+
* ### Overview
|
|
275
|
+
* `getTokensData` retrieves normalized token information — such as symbol, name,
|
|
276
|
+
* decimals, logo URI, and verified status — for a given list of token addresses.
|
|
277
|
+
*
|
|
278
|
+
* It supports both **EVM** and **SVM (Solana)** tokens, returning metadata from
|
|
279
|
+
* Shogun’s unified token registry.
|
|
280
|
+
*
|
|
281
|
+
* ---
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const tokens = await getTokensData([
|
|
285
|
+
* "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
|
|
286
|
+
* "So11111111111111111111111111111111111111112", // SOL
|
|
287
|
+
* ]);
|
|
288
|
+
*
|
|
289
|
+
* console.log(tokens);
|
|
290
|
+
* [
|
|
291
|
+
* { symbol: "USDC", name: "USD Coin", chainId: 1, decimals: 6, ... },
|
|
292
|
+
* { symbol: "SOL", name: "Solana", chainId: 101, decimals: 9, ... }
|
|
293
|
+
* ]
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @param addresses - An array of token addresses (EVM or SVM) to fetch metadata for.
|
|
297
|
+
* @returns A promise resolving to an array of {@link TokenInfo} objects.
|
|
298
|
+
*
|
|
299
|
+
* @throws Will throw an error if the network request fails or the API responds with a non-OK status.
|
|
300
|
+
*/
|
|
301
|
+
getTokensData: typeof getTokensData;
|
|
302
|
+
/**
|
|
303
|
+
* Fetches all user orders (Market, Limit, Cross-chain) for connected wallets.
|
|
304
|
+
*
|
|
305
|
+
* ---
|
|
306
|
+
* ### Overview
|
|
307
|
+
* Retrieves both **single-chain** and **cross-chain** orders from the Shogun Intents API.
|
|
308
|
+
* Works across EVM, Solana
|
|
309
|
+
*
|
|
310
|
+
* ---
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const orders = await sdk.getOrders({
|
|
314
|
+
* evmAddress: "0x123...",
|
|
315
|
+
* solAddress: "9d12hF...abc",
|
|
316
|
+
* });
|
|
317
|
+
*
|
|
318
|
+
* console.log(orders.singleChainLimitOrders);
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @param params - Wallet addresses to fetch orders for (EVM, Solana).
|
|
322
|
+
* @returns A structured {@link ApiUserOrders} object containing all user orders.
|
|
323
|
+
*/
|
|
324
|
+
getOrders(params: {
|
|
325
|
+
evmAddress?: string | null;
|
|
326
|
+
solAddress?: string | null;
|
|
327
|
+
}): Promise<ApiUserOrders>;
|
|
328
|
+
/**
|
|
329
|
+
* Cancels an order (single-chain or cross-chain) on EVM or Solana.
|
|
330
|
+
*
|
|
331
|
+
* Internally routes to the correct guard contract or Solana program to
|
|
332
|
+
* deactivate the order or invalidate its nonce.
|
|
333
|
+
*
|
|
334
|
+
* @param params.order - Order payload returned from the Intents API.
|
|
335
|
+
* @param params.wallet - Adapted wallet used to submit the cancellation transaction.
|
|
336
|
+
* @param params.solRpc - Solana RPC URL used for SVM cancellations.
|
|
337
|
+
*
|
|
338
|
+
* @returns A transaction signature or hash from the underlying wallet.
|
|
339
|
+
*/
|
|
340
|
+
cancelOrder(params: {
|
|
341
|
+
order: ApiCrossChainOrder | ApiSingleChainOrder;
|
|
342
|
+
wallet: AdaptedWallet;
|
|
343
|
+
solRpc: string;
|
|
344
|
+
}): Promise<string>;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* buildQuoteParams — Converts user-friendly input into normalized `SwapQuoteParams`.
|
|
349
|
+
*
|
|
350
|
+
* Converts human-readable token amount (like "100") into base units via `parseUnits`.
|
|
351
|
+
* Slippage should be passed as a percentage number (e.g., 1 = 1%, 10 = 10%).
|
|
352
|
+
*/
|
|
353
|
+
declare function buildQuoteParams({ tokenIn, tokenOut, sourceChainId, destChainId, amount, slippage, }: {
|
|
354
|
+
tokenIn: QuoteTokenInfo;
|
|
355
|
+
tokenOut: QuoteTokenInfo;
|
|
356
|
+
sourceChainId: ChainID;
|
|
357
|
+
destChainId: ChainID;
|
|
358
|
+
amount: string | number;
|
|
359
|
+
slippage?: number;
|
|
360
|
+
}): SwapQuoteParams;
|
|
361
|
+
|
|
362
|
+
declare enum OrderExecutionType {
|
|
363
|
+
LIMIT = "limit",
|
|
364
|
+
MARKET = "market"
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Public filtered enum — exposes only currently supported chains.
|
|
369
|
+
*
|
|
370
|
+
*/
|
|
371
|
+
declare const ChainId: Partial<Record<"Arbitrum" | "Optimism" | "Base" | "Hyperliquid" | "BSC" | "Solana" | "Sui" | "MONAD", number>>;
|
|
372
|
+
/**
|
|
373
|
+
* Public chains — only currently supported ones.
|
|
374
|
+
*/
|
|
375
|
+
declare const SupportedChains: ({
|
|
376
|
+
id: ChainID;
|
|
377
|
+
name: string;
|
|
378
|
+
isEVM: boolean;
|
|
379
|
+
wrapped: string;
|
|
380
|
+
symbol: string;
|
|
381
|
+
decimals: number;
|
|
382
|
+
tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
383
|
+
} | {
|
|
384
|
+
id: ChainID;
|
|
385
|
+
name: string;
|
|
386
|
+
isEVM: boolean;
|
|
387
|
+
wrapped: string;
|
|
388
|
+
symbol: string;
|
|
389
|
+
decimals: number;
|
|
390
|
+
tokenAddress: "So11111111111111111111111111111111111111111";
|
|
391
|
+
})[];
|
|
392
|
+
declare const isEvmChain: typeof isEvmChain$1;
|
|
393
|
+
|
|
394
|
+
export { type BalanceRequestParams as B, ChainId as C, type ExecuteOrderParams as E, OrderExecutionType as O, type PlaceOrderResult as P, type SwapSDKConfig as S, type TokenInfo as T, SwapSDK as a, type SwapQuoteParams as b, type SwapQuoteResponse as c, type Stage as d, type BalanceResponse as e, buildQuoteParams as f, SupportedChains as g, type TokenBalance as h, isEvmChain as i, type SupportedChain as j };
|