@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 CHANGED
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,39 +17,26 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
21
 
20
22
  // src/core/index.ts
21
23
  var core_exports = {};
22
24
  __export(core_exports, {
23
- ChainID: () => import_intents_sdk12.ChainID,
24
- NATIVE_TOKEN: () => NATIVE_TOKEN,
25
- SOLANA_CHAIN_ID: () => SOLANA_CHAIN_ID,
25
+ ChainId: () => ChainId,
26
+ OrderExecutionType: () => OrderExecutionType,
26
27
  SupportedChains: () => SupportedChains,
28
+ SwapSDK: () => SwapSDK,
27
29
  buildQuoteParams: () => buildQuoteParams,
28
- executeOrder: () => executeOrder,
29
- getBalances: () => getBalances,
30
- getQuote: () => getQuote,
31
- getTokenList: () => getTokenList,
32
- isEvmChain: () => import_intents_sdk12.isEvmChain,
33
- isNativeAddress: () => isNativeAddress,
34
- isViemWalletClient: () => isViemWalletClient,
35
- normalizeEvmTokenAddress: () => normalizeEvmTokenAddress,
36
- serializeBigIntsToStrings: () => serializeBigIntsToStrings
30
+ isEvmChain: () => isEvmChain
37
31
  });
38
32
  module.exports = __toCommonJS(core_exports);
39
33
 
40
- // src/core/token-list.ts
41
- var import_intents_sdk = require("@shogun-sdk/intents-sdk");
42
- async function getTokenList(params) {
43
- return (0, import_intents_sdk.getTokenList)(params);
44
- }
45
-
46
34
  // src/core/getQuote.ts
47
- var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
35
+ var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
48
36
  var import_viem2 = require("viem");
49
37
 
50
- // src/core/executeOrder/normalizeNative.ts
51
- var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
38
+ // src/core/execute/normalizeNative.ts
39
+ var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
52
40
 
53
41
  // src/utils/address.ts
54
42
  var import_viem = require("viem");
@@ -68,11 +56,25 @@ function normalizeEvmTokenAddress(address) {
68
56
  }
69
57
 
70
58
  // src/utils/chain.ts
71
- var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
72
- var SOLANA_CHAIN_ID = import_intents_sdk2.ChainID.Solana;
73
- var SupportedChains = [
59
+ var import_intents_sdk = require("@shogun-sdk/intents-sdk");
60
+ var SOLANA_CHAIN_ID = import_intents_sdk.ChainID.Solana;
61
+ var CURRENT_SUPPORTED = [
62
+ import_intents_sdk.ChainID.Solana,
63
+ import_intents_sdk.ChainID.BSC,
64
+ import_intents_sdk.ChainID.Base
65
+ ];
66
+ var ChainId = Object.entries(import_intents_sdk.ChainID).reduce(
67
+ (acc, [key, value]) => {
68
+ if (typeof value === "number" && CURRENT_SUPPORTED.includes(value)) {
69
+ acc[key] = value;
70
+ }
71
+ return acc;
72
+ },
73
+ {}
74
+ );
75
+ var SupportedChainsInternal = [
74
76
  {
75
- id: import_intents_sdk2.ChainID.Arbitrum,
77
+ id: import_intents_sdk.ChainID.Arbitrum,
76
78
  name: "Arbitrum",
77
79
  isEVM: true,
78
80
  wrapped: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
@@ -81,7 +83,7 @@ var SupportedChains = [
81
83
  tokenAddress: NATIVE_TOKEN.ETH
82
84
  },
83
85
  {
84
- id: import_intents_sdk2.ChainID.Optimism,
86
+ id: import_intents_sdk.ChainID.Optimism,
85
87
  name: "Optimism",
86
88
  isEVM: true,
87
89
  wrapped: "0x4200000000000000000000000000000000000006",
@@ -90,7 +92,7 @@ var SupportedChains = [
90
92
  tokenAddress: NATIVE_TOKEN.ETH
91
93
  },
92
94
  {
93
- id: import_intents_sdk2.ChainID.Base,
95
+ id: import_intents_sdk.ChainID.Base,
94
96
  name: "Base",
95
97
  isEVM: true,
96
98
  wrapped: "0x4200000000000000000000000000000000000006",
@@ -99,7 +101,7 @@ var SupportedChains = [
99
101
  tokenAddress: NATIVE_TOKEN.ETH
100
102
  },
101
103
  {
102
- id: import_intents_sdk2.ChainID.Hyperliquid,
104
+ id: import_intents_sdk.ChainID.Hyperliquid,
103
105
  name: "Hyperliquid",
104
106
  isEVM: true,
105
107
  wrapped: "0x5555555555555555555555555555555555555555",
@@ -108,7 +110,7 @@ var SupportedChains = [
108
110
  tokenAddress: NATIVE_TOKEN.ETH
109
111
  },
110
112
  {
111
- id: import_intents_sdk2.ChainID.BSC,
113
+ id: import_intents_sdk.ChainID.BSC,
112
114
  name: "BSC",
113
115
  isEVM: true,
114
116
  wrapped: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
@@ -126,6 +128,10 @@ var SupportedChains = [
126
128
  tokenAddress: NATIVE_TOKEN.SOL
127
129
  }
128
130
  ];
131
+ var SupportedChains = SupportedChainsInternal.filter(
132
+ (c) => CURRENT_SUPPORTED.includes(c.id)
133
+ );
134
+ var isEvmChain = import_intents_sdk.isEvmChain;
129
135
 
130
136
  // src/utils/viem.ts
131
137
  function isViemWalletClient(wallet) {
@@ -153,9 +159,9 @@ function serializeBigIntsToStrings(obj) {
153
159
  return obj;
154
160
  }
155
161
 
156
- // src/core/executeOrder/normalizeNative.ts
162
+ // src/core/execute/normalizeNative.ts
157
163
  function normalizeNative(chainId, address) {
158
- if ((0, import_intents_sdk3.isEvmChain)(chainId) && isNativeAddress(address)) {
164
+ if ((0, import_intents_sdk2.isEvmChain)(chainId) && isNativeAddress(address)) {
159
165
  const chain = SupportedChains.find((c) => c.id === chainId);
160
166
  if (!chain?.wrapped)
161
167
  throw new Error(`Wrapped token not found for chainId ${chainId}`);
@@ -166,22 +172,23 @@ function normalizeNative(chainId, address) {
166
172
 
167
173
  // src/core/getQuote.ts
168
174
  async function getQuote(params) {
175
+ const amount = BigInt(params.amount);
169
176
  if (!params.tokenIn?.address || !params.tokenOut?.address) {
170
177
  throw new Error("Both tokenIn and tokenOut must include an address.");
171
178
  }
172
179
  if (!params.sourceChainId || !params.destChainId) {
173
180
  throw new Error("Both sourceChainId and destChainId are required.");
174
181
  }
175
- if (params.amount <= 0n) {
182
+ if (amount <= 0n) {
176
183
  throw new Error("Amount must be greater than 0.");
177
184
  }
178
185
  const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
179
- const data = await import_intents_sdk4.QuoteProvider.getQuote({
186
+ const data = await import_intents_sdk3.QuoteProvider.getQuote({
180
187
  sourceChainId: params.sourceChainId,
181
188
  destChainId: params.destChainId,
182
189
  tokenIn: normalizedTokenIn,
183
190
  tokenOut: params.tokenOut.address,
184
- amount: params.amount
191
+ amount
185
192
  });
186
193
  const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
187
194
  let warning;
@@ -212,7 +219,7 @@ async function getQuote(params) {
212
219
  decimals: params.tokenOut.decimals ?? 18,
213
220
  chainId: params.destChainId
214
221
  },
215
- amountIn: params.amount,
222
+ amountIn: BigInt(params.amount),
216
223
  pricePerInputToken,
217
224
  slippage: slippagePercent,
218
225
  internal: {
@@ -236,13 +243,13 @@ function buildQuoteParams({
236
243
  tokenOut,
237
244
  sourceChainId,
238
245
  destChainId,
239
- amount: (0, import_viem2.parseUnits)(amount.toString(), tokenIn.decimals ?? 18),
246
+ amount: (0, import_viem2.parseUnits)(amount.toString(), tokenIn.decimals ?? 18).toString(),
240
247
  slippage
241
248
  };
242
249
  }
243
250
 
244
251
  // src/core/getBalances.ts
245
- var import_intents_sdk5 = require("@shogun-sdk/intents-sdk");
252
+ var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
246
253
  async function getBalances(params, options) {
247
254
  const { addresses, cursorEvm, cursorSvm } = params;
248
255
  const { signal } = options ?? {};
@@ -255,7 +262,7 @@ async function getBalances(params, options) {
255
262
  cursorSvm
256
263
  });
257
264
  const start = performance.now();
258
- const response = await fetch(`${import_intents_sdk5.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
265
+ const response = await fetch(`${import_intents_sdk4.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
259
266
  method: "POST",
260
267
  headers: {
261
268
  accept: "application/json",
@@ -283,20 +290,66 @@ async function getBalances(params, options) {
283
290
  const evmItems = data.evm?.items ?? [];
284
291
  const svmItems = data.svm?.items ?? [];
285
292
  const combined = [...evmItems, ...svmItems];
293
+ const filtered = combined.filter(
294
+ (b) => CURRENT_SUPPORTED.includes(b.chainId)
295
+ );
286
296
  return {
287
- results: combined,
297
+ results: filtered,
288
298
  nextCursorEvm: data.evm?.cursor ?? null,
289
299
  nextCursorSvm: data.svm?.cursor ?? null
290
300
  };
291
301
  }
292
302
 
293
- // src/core/executeOrder/execute.ts
294
- var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
295
- var import_viem6 = require("viem");
303
+ // src/core/token-list.ts
304
+ var import_intents_sdk5 = require("@shogun-sdk/intents-sdk");
305
+ async function getTokenList(params) {
306
+ const url = new URL(`${import_intents_sdk5.TOKEN_SEARCH_API_BASE_URL}/tokens/search`);
307
+ if (params.q) url.searchParams.append("q", params.q);
308
+ if (params.networkId) url.searchParams.append("networkId", String(params.networkId));
309
+ if (params.page) url.searchParams.append("page", String(params.page));
310
+ if (params.limit) url.searchParams.append("limit", String(params.limit));
311
+ const res = await fetch(url.toString(), {
312
+ signal: params.signal
313
+ });
314
+ if (!res.ok) {
315
+ throw new Error(`Failed to fetch tokens: ${res.status} ${res.statusText}`);
316
+ }
317
+ const data = await res.json();
318
+ const filteredResults = data.results.filter(
319
+ (token) => CURRENT_SUPPORTED.includes(token.chainId)
320
+ );
321
+ return {
322
+ ...data,
323
+ results: filteredResults,
324
+ count: filteredResults.length
325
+ };
326
+ }
327
+
328
+ // src/core/token.ts
329
+ var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
330
+ async function getTokensData(addresses) {
331
+ if (!addresses?.length) return [];
332
+ const response = await fetch(`${import_intents_sdk6.TOKEN_SEARCH_API_BASE_URL}/tokens/tokens`, {
333
+ method: "POST",
334
+ headers: {
335
+ "Content-Type": "application/json",
336
+ accept: "*/*"
337
+ },
338
+ body: JSON.stringify({ addresses })
339
+ });
340
+ if (!response.ok) {
341
+ throw new Error(`Failed to fetch token data: ${response.statusText}`);
342
+ }
343
+ const data = await response.json();
344
+ const filtered = data.filter((t) => CURRENT_SUPPORTED.includes(Number(t.chainId)));
345
+ return filtered;
346
+ }
347
+
348
+ // src/core/execute/execute.ts
349
+ var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
350
+ var import_viem7 = require("viem");
296
351
 
297
352
  // src/wallet-adapter/evm-wallet-adapter/adapter.ts
298
- var import_ethers = require("ethers/lib/ethers.js");
299
- var import_utils2 = require("ethers/lib/utils.js");
300
353
  var import_viem3 = require("viem");
301
354
  function isEVMTransaction(tx) {
302
355
  return typeof tx.from === "string";
@@ -383,11 +436,11 @@ var adaptViemWallet = (wallet) => {
383
436
  };
384
437
  };
385
438
 
386
- // src/core/executeOrder/handleEvmExecution.ts
387
- var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
388
- var import_viem5 = require("viem");
439
+ // src/core/execute/handleEvmExecution.ts
440
+ var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
441
+ var import_viem6 = require("viem");
389
442
 
390
- // src/core/executeOrder/stageMessages.ts
443
+ // src/core/execute/stageMessages.ts
391
444
  var DEFAULT_STAGE_MESSAGES = {
392
445
  processing: "Preparing transaction for execution",
393
446
  approving: "Approving token allowance",
@@ -396,33 +449,57 @@ var DEFAULT_STAGE_MESSAGES = {
396
449
  submitting: "Submitting transaction",
397
450
  initiated: "Transaction initiated.",
398
451
  success: "Transaction Executed successfully",
452
+ success_limit: "Limit order has been submitted successfully.",
399
453
  shogun_processing: "Shogun is processing your transaction",
400
454
  error: "Transaction failed during submission"
401
455
  };
402
456
 
403
- // src/core/executeOrder/buildOrder.ts
404
- var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
457
+ // src/core/execute/buildOrder.ts
458
+ var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
459
+ var import_viem4 = require("viem");
460
+
461
+ // src/utils/order.ts
462
+ var OrderExecutionType = /* @__PURE__ */ ((OrderExecutionType2) => {
463
+ OrderExecutionType2["LIMIT"] = "limit";
464
+ OrderExecutionType2["MARKET"] = "market";
465
+ return OrderExecutionType2;
466
+ })(OrderExecutionType || {});
467
+
468
+ // src/core/execute/buildOrder.ts
405
469
  async function buildOrder({
406
470
  quote,
407
471
  accountAddress,
408
472
  destination,
409
473
  deadline,
410
- isSingleChain
474
+ isSingleChain,
475
+ orderType,
476
+ options
411
477
  }) {
412
478
  const { tokenIn, tokenOut } = quote;
479
+ let amountOutMin = BigInt(quote.internal.estimatedAmountOutReduced);
480
+ if (orderType === "limit" /* LIMIT */ && options && "executionPrice" in options) {
481
+ const executionPrice = Number(options.executionPrice);
482
+ if (Number.isFinite(executionPrice) && executionPrice > 0) {
483
+ const decimalsIn = tokenIn.decimals ?? 18;
484
+ const decimalsOut = tokenOut.decimals ?? 18;
485
+ const formattedAmountIn = Number((0, import_viem4.formatUnits)(BigInt(quote.amountIn.toString()), decimalsIn));
486
+ const rawAmountOut = formattedAmountIn * executionPrice;
487
+ amountOutMin = (0, import_viem4.parseUnits)(rawAmountOut.toString(), decimalsOut);
488
+ }
489
+ }
413
490
  if (isSingleChain) {
414
- return await import_intents_sdk6.SingleChainOrder.create({
491
+ return await import_intents_sdk7.SingleChainOrder.create({
415
492
  user: accountAddress,
416
493
  chainId: tokenIn.chainId,
417
494
  tokenIn: tokenIn.address,
418
495
  tokenOut: tokenOut.address,
419
496
  amountIn: quote.amountIn,
420
- amountOutMin: quote.internal.estimatedAmountOutReduced,
497
+ amountOutMin,
421
498
  deadline,
422
499
  destinationAddress: destination
423
500
  });
424
501
  }
425
- return await import_intents_sdk6.CrossChainOrder.create({
502
+ return await import_intents_sdk7.CrossChainOrder.create({
426
503
  user: accountAddress,
427
504
  sourceChainId: tokenIn.chainId,
428
505
  sourceTokenAddress: tokenIn.address,
@@ -431,13 +508,13 @@ async function buildOrder({
431
508
  destinationTokenAddress: tokenOut.address,
432
509
  destinationAddress: destination,
433
510
  deadline,
434
- destinationTokenMinAmount: quote.internal.estimatedAmountOutReduced,
511
+ destinationTokenMinAmount: amountOutMin,
435
512
  minStablecoinAmount: quote.minStablecoinsAmount
436
513
  });
437
514
  }
438
515
 
439
516
  // src/utils/pollOrderStatus.ts
440
- var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
517
+ var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
441
518
  async function pollOrderStatus(address, orderId, options = {}) {
442
519
  const { intervalMs = 2e3, timeoutMs = 3e5 } = options;
443
520
  const startTime = Date.now();
@@ -450,7 +527,7 @@ async function pollOrderStatus(address, orderId, options = {}) {
450
527
  else if (isSuiAddress) queryParam = `suiWallets=${address}`;
451
528
  else if (isSolanaAddress) queryParam = `solanaWallets=${address}`;
452
529
  else throw new Error(`Unrecognized wallet address format: ${address}`);
453
- const queryUrl = `${import_intents_sdk7.AUCTIONEER_URL}/user_intent?${queryParam}`;
530
+ const queryUrl = `${import_intents_sdk8.AUCTIONEER_URL}/user_intent?${queryParam}`;
454
531
  return new Promise((resolve, reject) => {
455
532
  const pollInterval = setInterval(async () => {
456
533
  try {
@@ -502,7 +579,7 @@ async function pollOrderStatus(address, orderId, options = {}) {
502
579
  });
503
580
  }
504
581
 
505
- // src/core/executeOrder/handleOrderPollingResult.ts
582
+ // src/core/execute/handleOrderPollingResult.ts
506
583
  async function handleOrderPollingResult({
507
584
  status,
508
585
  orderId,
@@ -540,9 +617,9 @@ async function handleOrderPollingResult({
540
617
  };
541
618
  }
542
619
 
543
- // src/core/executeOrder/ensurePermit2Allowance.ts
544
- var import_viem4 = require("viem");
545
- var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
620
+ // src/core/execute/ensurePermit2Allowance.ts
621
+ var import_viem5 = require("viem");
622
+ var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
546
623
  async function ensurePermit2Allowance({
547
624
  chainId,
548
625
  tokenIn,
@@ -551,7 +628,7 @@ async function ensurePermit2Allowance({
551
628
  requiredAmount,
552
629
  increaseByDelta = false
553
630
  }) {
554
- const spender = import_intents_sdk8.PERMIT2_ADDRESS[chainId];
631
+ const spender = import_intents_sdk9.PERMIT2_ADDRESS[chainId];
555
632
  let currentAllowance = 0n;
556
633
  try {
557
634
  if (!wallet.readContract) {
@@ -559,22 +636,22 @@ async function ensurePermit2Allowance({
559
636
  }
560
637
  currentAllowance = await wallet.readContract({
561
638
  address: tokenIn,
562
- abi: import_viem4.erc20Abi,
639
+ abi: import_viem5.erc20Abi,
563
640
  functionName: "allowance",
564
641
  args: [accountAddress, spender]
565
642
  });
566
643
  } catch (error) {
567
644
  console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
568
645
  }
569
- const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem4.maxUint256;
646
+ const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem5.maxUint256;
570
647
  console.debug(
571
648
  `[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
572
649
  );
573
650
  await wallet.sendTransaction({
574
651
  to: tokenIn,
575
652
  from: accountAddress,
576
- data: (0, import_viem4.encodeFunctionData)({
577
- abi: import_viem4.erc20Abi,
653
+ data: (0, import_viem5.encodeFunctionData)({
654
+ abi: import_viem5.erc20Abi,
578
655
  functionName: "approve",
579
656
  args: [spender, approvalAmount]
580
657
  }),
@@ -585,7 +662,7 @@ async function ensurePermit2Allowance({
585
662
  );
586
663
  }
587
664
 
588
- // src/core/executeOrder/handleEvmExecution.ts
665
+ // src/core/execute/handleEvmExecution.ts
589
666
  async function handleEvmExecution({
590
667
  recipientAddress,
591
668
  quote,
@@ -593,19 +670,22 @@ async function handleEvmExecution({
593
670
  accountAddress,
594
671
  wallet,
595
672
  isSingleChain,
596
- deadline,
597
- update
673
+ update,
674
+ orderType,
675
+ options
598
676
  }) {
599
- const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
677
+ const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
678
+ const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
600
679
  await wallet.switchChain(chainId);
601
680
  const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
602
681
  quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
603
682
  const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
604
683
  update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
605
684
  if (shouldWrapNative) {
685
+ quote.tokenIn.address === tokenIn;
606
686
  await wallet.sendTransaction({
607
687
  to: tokenIn,
608
- data: (0, import_viem5.encodeFunctionData)({
688
+ data: (0, import_viem6.encodeFunctionData)({
609
689
  abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
610
690
  functionName: "deposit",
611
691
  args: []
@@ -629,11 +709,13 @@ async function handleEvmExecution({
629
709
  accountAddress,
630
710
  destination,
631
711
  deadline,
632
- isSingleChain
712
+ isSingleChain,
713
+ orderType,
714
+ options
633
715
  });
634
716
  console.debug(`order`, order);
635
717
  update("processing", messageFor("signing"));
636
- const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk9.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk9.getEVMCrossChainOrderTypedData)(order);
718
+ const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk10.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk10.getEVMCrossChainOrderTypedData)(order);
637
719
  const typedData = serializeBigIntsToStrings(orderTypedData);
638
720
  if (!wallet.signTypedData) {
639
721
  throw new Error("Wallet does not support EIP-712 signing");
@@ -653,18 +735,29 @@ async function handleEvmExecution({
653
735
  update("initiated", messageFor("initiated"));
654
736
  const { intentId: orderId } = res.data;
655
737
  update("initiated", messageFor("shogun_processing"));
656
- const status = await pollOrderStatus(accountAddress, orderId);
657
- return await handleOrderPollingResult({
658
- status,
659
- orderId,
660
- chainId,
661
- update,
662
- messageFor
663
- });
738
+ if (orderType === "limit" /* LIMIT */) {
739
+ update("success", messageFor("success_limit"));
740
+ return {
741
+ status: true,
742
+ orderId,
743
+ chainId,
744
+ finalStatus: "OrderPlaced",
745
+ stage: "success"
746
+ };
747
+ } else {
748
+ const status = await pollOrderStatus(accountAddress, orderId);
749
+ return await handleOrderPollingResult({
750
+ status,
751
+ orderId,
752
+ chainId,
753
+ update,
754
+ messageFor
755
+ });
756
+ }
664
757
  }
665
758
 
666
- // src/core/executeOrder/handleSolanaExecution.ts
667
- var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
759
+ // src/core/execute/handleSolanaExecution.ts
760
+ var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
668
761
  var import_web3 = require("@solana/web3.js");
669
762
  async function handleSolanaExecution({
670
763
  recipientAddress,
@@ -673,12 +766,14 @@ async function handleSolanaExecution({
673
766
  isSingleChain,
674
767
  update,
675
768
  accountAddress,
676
- deadline
769
+ orderType,
770
+ options
677
771
  }) {
678
772
  if (!wallet.rpcUrl) {
679
773
  throw new Error("Solana wallet is missing rpcUrl");
680
774
  }
681
- const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
775
+ const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
776
+ const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
682
777
  update("processing", messageFor("processing"));
683
778
  const destination = recipientAddress ?? accountAddress;
684
779
  const order = await buildOrder({
@@ -686,7 +781,9 @@ async function handleSolanaExecution({
686
781
  accountAddress,
687
782
  destination,
688
783
  deadline,
689
- isSingleChain
784
+ isSingleChain,
785
+ orderType,
786
+ options
690
787
  });
691
788
  const txData = await getSolanaOrderInstructions({
692
789
  order,
@@ -706,16 +803,27 @@ async function handleSolanaExecution({
706
803
  throw new Error("Auctioneer submission failed");
707
804
  }
708
805
  update("initiated", messageFor("initiated"));
709
- const { jwt, intentId: orderId } = response.data;
806
+ const { intentId: orderId } = response.data;
710
807
  update("initiated", messageFor("shogun_processing"));
711
- const status = await pollOrderStatus(jwt, orderId);
712
- return await handleOrderPollingResult({
713
- status,
714
- orderId,
715
- chainId: SOLANA_CHAIN_ID,
716
- update,
717
- messageFor
718
- });
808
+ if (orderType === "limit" /* LIMIT */) {
809
+ update("success", messageFor("success_limit"));
810
+ return {
811
+ status: true,
812
+ orderId,
813
+ chainId: SOLANA_CHAIN_ID,
814
+ finalStatus: "OrderPlaced",
815
+ stage: "success"
816
+ };
817
+ } else {
818
+ const status = await pollOrderStatus(accountAddress, orderId);
819
+ return await handleOrderPollingResult({
820
+ status,
821
+ orderId,
822
+ chainId: SOLANA_CHAIN_ID,
823
+ update,
824
+ messageFor
825
+ });
826
+ }
719
827
  }
720
828
  async function getSolanaOrderInstructions({
721
829
  order,
@@ -723,11 +831,11 @@ async function getSolanaOrderInstructions({
723
831
  rpcUrl
724
832
  }) {
725
833
  if (isSingleChain) {
726
- return await (0, import_intents_sdk10.getSolanaSingleChainOrderInstructions)(order, {
834
+ return await (0, import_intents_sdk11.getSolanaSingleChainOrderInstructions)(order, {
727
835
  rpcUrl
728
836
  });
729
837
  }
730
- return await (0, import_intents_sdk10.getSolanaCrossChainOrderInstructions)(order, {
838
+ return await (0, import_intents_sdk11.getSolanaCrossChainOrderInstructions)(order, {
731
839
  rpcUrl
732
840
  });
733
841
  }
@@ -748,13 +856,14 @@ async function submitToAuctioneer({
748
856
  });
749
857
  }
750
858
 
751
- // src/core/executeOrder/execute.ts
859
+ // src/core/execute/execute.ts
752
860
  async function executeOrder({
753
861
  quote,
754
862
  accountAddress,
755
863
  recipientAddress,
756
864
  wallet,
757
865
  onStatus,
866
+ orderType = "market" /* MARKET */,
758
867
  options = {}
759
868
  }) {
760
869
  const isDev = process.env.NODE_ENV !== "production";
@@ -767,21 +876,31 @@ async function executeOrder({
767
876
  onStatus?.(stage, message ?? messageFor(stage));
768
877
  };
769
878
  try {
770
- const deadline = options.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
771
879
  log("Starting execution:", {
772
880
  accountAddress,
773
881
  recipientAddress,
774
- deadline,
775
882
  tokenIn: quote?.tokenIn,
776
883
  tokenOut: quote?.tokenOut
777
884
  });
778
885
  const adapter = normalizeWallet(wallet);
779
886
  if (!adapter) throw new Error("No wallet provided");
780
887
  const { tokenIn, tokenOut } = quote;
888
+ const srcChain = Number(tokenIn.chainId);
889
+ const destChain = Number(tokenOut.chainId);
890
+ if (!CURRENT_SUPPORTED.includes(srcChain) || !CURRENT_SUPPORTED.includes(destChain)) {
891
+ const unsupportedChains = [
892
+ !CURRENT_SUPPORTED.includes(srcChain) ? srcChain : null,
893
+ !CURRENT_SUPPORTED.includes(destChain) ? destChain : null
894
+ ].filter(Boolean).join(", ");
895
+ const errorMsg = `Unsupported chain(s): ${unsupportedChains}`;
896
+ update("error", errorMsg);
897
+ log("Error:", errorMsg);
898
+ throw new Error(errorMsg);
899
+ }
781
900
  const isSingleChain = tokenIn.chainId === tokenOut.chainId;
782
901
  const chainId = Number(tokenIn.chainId);
783
902
  update("processing");
784
- if ((0, import_intents_sdk11.isEvmChain)(chainId)) {
903
+ if ((0, import_intents_sdk12.isEvmChain)(chainId)) {
785
904
  log("Detected EVM chain:", chainId);
786
905
  const result = await handleEvmExecution({
787
906
  recipientAddress,
@@ -790,13 +909,14 @@ async function executeOrder({
790
909
  accountAddress,
791
910
  wallet: adapter,
792
911
  isSingleChain,
793
- deadline,
794
- update
912
+ update,
913
+ orderType,
914
+ options
795
915
  });
796
916
  log("EVM execution result:", result);
797
917
  return result;
798
918
  }
799
- if (chainId === import_intents_sdk11.ChainID.Solana) {
919
+ if (chainId === import_intents_sdk12.ChainID.Solana) {
800
920
  log("Detected Solana chain");
801
921
  const result = await handleSolanaExecution({
802
922
  recipientAddress,
@@ -804,8 +924,9 @@ async function executeOrder({
804
924
  accountAddress,
805
925
  wallet: adapter,
806
926
  isSingleChain,
807
- deadline,
808
- update
927
+ update,
928
+ orderType,
929
+ options
809
930
  });
810
931
  log("Solana execution result:", result);
811
932
  return result;
@@ -815,8 +936,13 @@ async function executeOrder({
815
936
  log("Error:", unsupported);
816
937
  return { status: false, message: unsupported, stage: "error" };
817
938
  } catch (error) {
818
- const message = error instanceof import_viem6.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
819
- log("Execution failed:", { message, error });
939
+ let message = "An unknown error occurred";
940
+ if (error && typeof error === "object") {
941
+ const err = error;
942
+ message = err.details ?? err.message ?? message;
943
+ } else if (typeof error === "string") {
944
+ message = error;
945
+ }
820
946
  update("error", message);
821
947
  return { status: false, message, stage: "error" };
822
948
  }
@@ -827,5 +953,177 @@ function normalizeWallet(wallet) {
827
953
  return wallet;
828
954
  }
829
955
 
830
- // src/core/index.ts
831
- var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
956
+ // src/core/orders/getOrders.ts
957
+ var import_intents_sdk13 = require("@shogun-sdk/intents-sdk");
958
+ async function getOrders({
959
+ evmAddress,
960
+ solAddress
961
+ }) {
962
+ if (!evmAddress && !solAddress) {
963
+ throw new Error("At least one wallet address (EVM, Solana) must be provided.");
964
+ }
965
+ const orders = await (0, import_intents_sdk13.fetchUserOrders)(evmAddress, solAddress);
966
+ return orders;
967
+ }
968
+
969
+ // src/core/client.ts
970
+ var SwapSDK = class {
971
+ constructor(config) {
972
+ __publicField(this, "apiKey");
973
+ /**
974
+ * Fetches metadata for one or more tokens from the Shogun Token Search API.
975
+ *
976
+ * ---
977
+ * ### Overview
978
+ * `getTokensData` retrieves normalized token information — such as symbol, name,
979
+ * decimals, logo URI, and verified status — for a given list of token addresses.
980
+ *
981
+ * It supports both **EVM** and **SVM (Solana)** tokens, returning metadata from
982
+ * Shogun’s unified token registry.
983
+ *
984
+ * ---
985
+ * @example
986
+ * ```ts
987
+ * const tokens = await getTokensData([
988
+ * "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
989
+ * "So11111111111111111111111111111111111111112", // SOL
990
+ * ]);
991
+ *
992
+ * console.log(tokens);
993
+ * [
994
+ * { symbol: "USDC", name: "USD Coin", chainId: 1, decimals: 6, ... },
995
+ * { symbol: "SOL", name: "Solana", chainId: 101, decimals: 9, ... }
996
+ * ]
997
+ * ```
998
+ *
999
+ * @param addresses - An array of token addresses (EVM or SVM) to fetch metadata for.
1000
+ * @returns A promise resolving to an array of {@link TokenInfo} objects.
1001
+ *
1002
+ * @throws Will throw an error if the network request fails or the API responds with a non-OK status.
1003
+ */
1004
+ __publicField(this, "getTokensData", getTokensData.bind(this));
1005
+ if (!config.apiKey) {
1006
+ throw new Error("SwapSDK: Missing API key");
1007
+ }
1008
+ this.apiKey = config.apiKey;
1009
+ if (this.apiKey) void this.apiKey;
1010
+ }
1011
+ /**
1012
+ * Retrieves a swap quote for the given input and output tokens.
1013
+ *
1014
+ * @param params - Quote parameters including source/destination tokens and amount.
1015
+ * @returns A normalized `SwapQuoteResponse` containing output amount, route, and metadata.
1016
+ */
1017
+ async getQuote(params) {
1018
+ return getQuote(params);
1019
+ }
1020
+ /**
1021
+ * Fetches token balances for the specified user wallet(s).
1022
+ *
1023
+ * Supports both EVM and SVM (Solana) wallet addresses.
1024
+ *
1025
+ * @param params - Wallet address and optional chain filters.
1026
+ * @param options - Optional abort signal for cancellation.
1027
+ * @returns A unified balance response with per-chain token details.
1028
+ */
1029
+ async getBalances(params, options) {
1030
+ return getBalances(params, options);
1031
+ }
1032
+ /**
1033
+ * Retrieves a list of verified tokens based on search query or chain filter.
1034
+ *
1035
+ * @param params - Search parameters (query, chain ID, pagination options).
1036
+ * @returns Paginated `TokenSearchResponse` containing token metadata.
1037
+ */
1038
+ async getTokenList(params) {
1039
+ return getTokenList(params);
1040
+ }
1041
+ /**
1042
+ * Executes a prepared swap quote using the provided wallet and configuration.
1043
+ *
1044
+ * Handles:
1045
+ * - Token approval (if required)
1046
+ * - Transaction signing and broadcasting
1047
+ * - Confirmation polling and stage-based status updates
1048
+ *
1049
+ * Supports both:
1050
+ * - Market orders (with optional deadline)
1051
+ * - Limit orders (requires executionPrice and deadline)
1052
+ *
1053
+ * @param quote - The swap quote to execute, containing route and metadata.
1054
+ * @param accountAddress - The user's wallet address executing the swap.
1055
+ * @param recipientAddress - Optional recipient address for the output tokens (defaults to sender).
1056
+ * @param wallet - Adapted wallet instance (EVM/Solana) or a standard Viem `WalletClient`.
1057
+ * @param onStatus - Optional callback for receiving execution stage updates and messages.
1058
+ * @param orderType - Defines whether this is a market or limit order.
1059
+ * @param options - Execution parameters (different per order type).
1060
+ *
1061
+ * @returns A finalized execution result containing transaction hash, status, and any returned data.
1062
+ *
1063
+ * @example
1064
+ * ```ts
1065
+ * * Market order
1066
+ * const result = await sdk.executeTransaction({
1067
+ * quote,
1068
+ * accountAddress: "0x123...",
1069
+ * wallet,
1070
+ * orderType: OrderExecutionType.MARKET,
1071
+ * options: { deadline: 1800 },
1072
+ * onStatus: (stage, msg) => console.log(stage, msg),
1073
+ * });
1074
+ *
1075
+ * * Limit order
1076
+ * const result = await sdk.executeTransaction({
1077
+ * quote,
1078
+ * accountAddress: "0x123...",
1079
+ * wallet,
1080
+ * orderType: OrderExecutionType.LIMIT,
1081
+ * options: { executionPrice: "0.0021", deadline: 3600 },
1082
+ * });
1083
+ * ```
1084
+ */
1085
+ async executeTransaction({
1086
+ quote,
1087
+ accountAddress,
1088
+ recipientAddress,
1089
+ wallet,
1090
+ onStatus,
1091
+ orderType,
1092
+ options
1093
+ }) {
1094
+ return executeOrder({
1095
+ quote,
1096
+ wallet,
1097
+ accountAddress,
1098
+ recipientAddress,
1099
+ onStatus,
1100
+ orderType,
1101
+ options
1102
+ });
1103
+ }
1104
+ /**
1105
+ * Fetches all user orders (Market, Limit, Cross-chain) for connected wallets.
1106
+ *
1107
+ * ---
1108
+ * ### Overview
1109
+ * Retrieves both **single-chain** and **cross-chain** orders from the Shogun Intents API.
1110
+ * Works across EVM, Solana
1111
+ *
1112
+ * ---
1113
+ * @example
1114
+ * ```ts
1115
+ * const orders = await sdk.getOrders({
1116
+ * evmAddress: "0x123...",
1117
+ * solAddress: "9d12hF...abc",
1118
+ * });
1119
+ *
1120
+ * console.log(orders.singleChainLimitOrders);
1121
+ * ```
1122
+ *
1123
+ * @param params - Wallet addresses to fetch orders for (EVM, Solana).
1124
+ * @returns A structured {@link ApiUserOrders} object containing all user orders.
1125
+ */
1126
+ async getOrders(params) {
1127
+ return getOrders(params);
1128
+ }
1129
+ };