@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/index.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,45 +17,29 @@ 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/index.ts
21
23
  var src_exports = {};
22
24
  __export(src_exports, {
23
- NATIVE_TOKEN: () => NATIVE_TOKEN,
24
- SOLANA_CHAIN_ID: () => SOLANA_CHAIN_ID,
25
+ ChainId: () => ChainId,
26
+ OrderExecutionType: () => OrderExecutionType,
25
27
  SupportedChains: () => SupportedChains,
26
- adaptEthersSigner: () => adaptEthersSigner,
27
- adaptSolanaWallet: () => adaptSolanaWallet,
28
- adaptViemWallet: () => adaptViemWallet,
28
+ SwapSDK: () => SwapSDK,
29
29
  buildQuoteParams: () => buildQuoteParams,
30
- executeOrder: () => executeOrder,
31
- getBalances: () => getBalances,
32
- getQuote: () => getQuote,
33
- getTokenList: () => getTokenList,
34
- isNativeAddress: () => isNativeAddress,
35
- isViemWalletClient: () => isViemWalletClient,
36
- serializeBigIntsToStrings: () => serializeBigIntsToStrings,
37
- useBalances: () => useBalances,
38
- useExecuteOrder: () => useExecuteOrder,
39
- useQuote: () => useQuote,
40
- useTokenList: () => useTokenList
30
+ isEvmChain: () => isEvmChain
41
31
  });
42
32
  module.exports = __toCommonJS(src_exports);
43
33
 
44
- // src/core/token-list.ts
45
- var import_intents_sdk = require("@shogun-sdk/intents-sdk");
46
- async function getTokenList(params) {
47
- return (0, import_intents_sdk.getTokenList)(params);
48
- }
49
-
50
34
  // src/core/getQuote.ts
51
- var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
52
- var import_viem = require("viem");
53
-
54
- // src/core/executeOrder/normalizeNative.ts
55
35
  var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
36
+ var import_viem2 = require("viem");
37
+
38
+ // src/core/execute/normalizeNative.ts
39
+ var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
56
40
 
57
41
  // src/utils/address.ts
42
+ var import_viem = require("viem");
58
43
  var NATIVE_TOKEN = {
59
44
  ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
60
45
  SOL: "So11111111111111111111111111111111111111111",
@@ -65,13 +50,32 @@ var isNativeAddress = (tokenAddress) => {
65
50
  const normalizedTokenAddress = tokenAddress.toLowerCase();
66
51
  return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
67
52
  };
53
+ function normalizeEvmTokenAddress(address) {
54
+ const lower = address.toLowerCase();
55
+ return lower === NATIVE_TOKEN.ETH.toLowerCase() ? import_viem.zeroAddress : address;
56
+ }
68
57
 
69
58
  // src/utils/chain.ts
70
- var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
71
- var SOLANA_CHAIN_ID = import_intents_sdk2.ChainID.Solana;
72
- 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
+ import_intents_sdk.ChainID.MONAD
66
+ ];
67
+ var ChainId = Object.entries(import_intents_sdk.ChainID).reduce(
68
+ (acc, [key, value]) => {
69
+ if (typeof value === "number" && CURRENT_SUPPORTED.includes(value)) {
70
+ acc[key] = value;
71
+ }
72
+ return acc;
73
+ },
74
+ {}
75
+ );
76
+ var SupportedChainsInternal = [
73
77
  {
74
- id: import_intents_sdk2.ChainID.Arbitrum,
78
+ id: import_intents_sdk.ChainID.Arbitrum,
75
79
  name: "Arbitrum",
76
80
  isEVM: true,
77
81
  wrapped: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
@@ -80,7 +84,7 @@ var SupportedChains = [
80
84
  tokenAddress: NATIVE_TOKEN.ETH
81
85
  },
82
86
  {
83
- id: import_intents_sdk2.ChainID.Optimism,
87
+ id: import_intents_sdk.ChainID.Optimism,
84
88
  name: "Optimism",
85
89
  isEVM: true,
86
90
  wrapped: "0x4200000000000000000000000000000000000006",
@@ -89,7 +93,7 @@ var SupportedChains = [
89
93
  tokenAddress: NATIVE_TOKEN.ETH
90
94
  },
91
95
  {
92
- id: import_intents_sdk2.ChainID.Base,
96
+ id: import_intents_sdk.ChainID.Base,
93
97
  name: "Base",
94
98
  isEVM: true,
95
99
  wrapped: "0x4200000000000000000000000000000000000006",
@@ -98,7 +102,7 @@ var SupportedChains = [
98
102
  tokenAddress: NATIVE_TOKEN.ETH
99
103
  },
100
104
  {
101
- id: import_intents_sdk2.ChainID.Hyperliquid,
105
+ id: import_intents_sdk.ChainID.Hyperliquid,
102
106
  name: "Hyperliquid",
103
107
  isEVM: true,
104
108
  wrapped: "0x5555555555555555555555555555555555555555",
@@ -107,7 +111,7 @@ var SupportedChains = [
107
111
  tokenAddress: NATIVE_TOKEN.ETH
108
112
  },
109
113
  {
110
- id: import_intents_sdk2.ChainID.BSC,
114
+ id: import_intents_sdk.ChainID.BSC,
111
115
  name: "BSC",
112
116
  isEVM: true,
113
117
  wrapped: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
@@ -123,8 +127,21 @@ var SupportedChains = [
123
127
  symbol: "SOL",
124
128
  decimals: 9,
125
129
  tokenAddress: NATIVE_TOKEN.SOL
130
+ },
131
+ {
132
+ id: import_intents_sdk.ChainID.MONAD,
133
+ name: "Monad",
134
+ isEVM: true,
135
+ wrapped: "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A",
136
+ symbol: "MON",
137
+ decimals: 18,
138
+ tokenAddress: NATIVE_TOKEN.ETH
126
139
  }
127
140
  ];
141
+ var SupportedChains = SupportedChainsInternal.filter(
142
+ (c) => CURRENT_SUPPORTED.includes(c.id)
143
+ );
144
+ var isEvmChain = import_intents_sdk.isEvmChain;
128
145
 
129
146
  // src/utils/viem.ts
130
147
  function isViemWalletClient(wallet) {
@@ -152,9 +169,9 @@ function serializeBigIntsToStrings(obj) {
152
169
  return obj;
153
170
  }
154
171
 
155
- // src/core/executeOrder/normalizeNative.ts
172
+ // src/core/execute/normalizeNative.ts
156
173
  function normalizeNative(chainId, address) {
157
- if ((0, import_intents_sdk3.isEvmChain)(chainId) && isNativeAddress(address)) {
174
+ if ((0, import_intents_sdk2.isEvmChain)(chainId) && isNativeAddress(address)) {
158
175
  const chain = SupportedChains.find((c) => c.id === chainId);
159
176
  if (!chain?.wrapped)
160
177
  throw new Error(`Wrapped token not found for chainId ${chainId}`);
@@ -165,39 +182,43 @@ function normalizeNative(chainId, address) {
165
182
 
166
183
  // src/core/getQuote.ts
167
184
  async function getQuote(params) {
185
+ const amount = BigInt(params.amount);
168
186
  if (!params.tokenIn?.address || !params.tokenOut?.address) {
169
187
  throw new Error("Both tokenIn and tokenOut must include an address.");
170
188
  }
171
189
  if (!params.sourceChainId || !params.destChainId) {
172
190
  throw new Error("Both sourceChainId and destChainId are required.");
173
191
  }
174
- if (params.amount <= 0n) {
192
+ if (amount <= 0n) {
175
193
  throw new Error("Amount must be greater than 0.");
176
194
  }
177
195
  const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
178
- const data = await import_intents_sdk4.QuoteProvider.getQuote({
196
+ const data = await import_intents_sdk3.QuoteProvider.getQuote({
179
197
  sourceChainId: params.sourceChainId,
180
198
  destChainId: params.destChainId,
181
199
  tokenIn: normalizedTokenIn,
182
200
  tokenOut: params.tokenOut.address,
183
- amount: params.amount
201
+ amount
184
202
  });
185
- const inputSlippage = params.slippage ?? 5;
186
- const slippageDecimal = inputSlippage / 100;
187
- const slippage = Math.min(Math.max(slippageDecimal, 0), 0.5);
203
+ const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
188
204
  let warning;
189
- if (slippage > 0.1) {
190
- warning = `\u26A0\uFE0F High slippage tolerance (${(slippage * 100).toFixed(2)}%) \u2014 price may vary significantly.`;
205
+ if (slippagePercent > 10) {
206
+ warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
191
207
  }
192
- const estimatedAmountOut = BigInt(data.estimatedAmountOutReduced);
193
- const slippageBps = BigInt(Math.round(slippage * 1e4));
208
+ const estimatedAmountOut = BigInt(data.estimatedAmountOut);
209
+ const slippageBps = BigInt(Math.round(slippagePercent * 100));
194
210
  const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
211
+ const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
212
+ const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
213
+ const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
214
+ const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
195
215
  const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
196
216
  return {
197
- amountOut: estimatedAmountOut,
198
- amountOutUsd: data.estimatedAmountOutUsd,
217
+ amountOut: estimatedAmountOutAfterSlippage,
218
+ amountOutUsd: amountOutUsdAfterSlippage,
199
219
  amountInUsd: data.amountInUsd,
200
- minStablecoinsAmount: data.estimatedAmountInAsMinStablecoinAmount,
220
+ // Input USD stays the same
221
+ minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
201
222
  tokenIn: {
202
223
  address: params.tokenIn.address,
203
224
  decimals: params.tokenIn.decimals ?? 18,
@@ -208,12 +229,13 @@ async function getQuote(params) {
208
229
  decimals: params.tokenOut.decimals ?? 18,
209
230
  chainId: params.destChainId
210
231
  },
211
- amountIn: params.amount,
232
+ amountIn: BigInt(params.amount),
212
233
  pricePerInputToken,
213
- slippage,
234
+ slippage: slippagePercent,
214
235
  internal: {
215
236
  ...data,
216
- estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
237
+ estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
238
+ estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
217
239
  },
218
240
  warning
219
241
  };
@@ -231,13 +253,13 @@ function buildQuoteParams({
231
253
  tokenOut,
232
254
  sourceChainId,
233
255
  destChainId,
234
- amount: (0, import_viem.parseUnits)(amount.toString(), tokenIn.decimals ?? 18),
256
+ amount: (0, import_viem2.parseUnits)(amount.toString(), tokenIn.decimals ?? 18).toString(),
235
257
  slippage
236
258
  };
237
259
  }
238
260
 
239
261
  // src/core/getBalances.ts
240
- var import_intents_sdk5 = require("@shogun-sdk/intents-sdk");
262
+ var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
241
263
  async function getBalances(params, options) {
242
264
  const { addresses, cursorEvm, cursorSvm } = params;
243
265
  const { signal } = options ?? {};
@@ -250,7 +272,7 @@ async function getBalances(params, options) {
250
272
  cursorSvm
251
273
  });
252
274
  const start = performance.now();
253
- const response = await fetch(`${import_intents_sdk5.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
275
+ const response = await fetch(`${import_intents_sdk4.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
254
276
  method: "POST",
255
277
  headers: {
256
278
  accept: "application/json",
@@ -278,103 +300,70 @@ async function getBalances(params, options) {
278
300
  const evmItems = data.evm?.items ?? [];
279
301
  const svmItems = data.svm?.items ?? [];
280
302
  const combined = [...evmItems, ...svmItems];
303
+ const filtered = combined.filter(
304
+ (b) => CURRENT_SUPPORTED.includes(b.chainId)
305
+ );
281
306
  return {
282
- results: combined,
307
+ results: filtered,
283
308
  nextCursorEvm: data.evm?.cursor ?? null,
284
309
  nextCursorSvm: data.svm?.cursor ?? null
285
310
  };
286
311
  }
287
312
 
288
- // src/core/executeOrder/execute.ts
289
- var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
290
- var import_viem4 = require("viem");
291
-
292
- // src/wallet-adapter/svm-wallet-adapter/adapter.ts
293
- var import_web3 = require("@solana/web3.js");
294
- var adaptSolanaWallet = (walletAddress, chainId, rpcUrl, signAndSendTransaction) => {
295
- let _chainId = chainId;
296
- const connection = new import_web3.Connection(rpcUrl, { commitment: "confirmed" });
297
- const getChainId = async () => _chainId;
298
- const sendTransaction = async (transaction) => {
299
- const txHash = await signAndSendTransaction(transaction);
300
- console.log(`\u{1F6F0} Sent transaction: ${txHash}`);
301
- const maxRetries = 20;
302
- const delayMs = 2e3;
303
- for (let attempt = 0; attempt < maxRetries; attempt++) {
304
- const res = await connection.getSignatureStatus(txHash, { searchTransactionHistory: true });
305
- if (res?.value?.confirmationStatus === "confirmed" || res?.value?.confirmationStatus === "finalized") {
306
- return txHash;
307
- }
308
- await new Promise((resolve) => setTimeout(resolve, delayMs));
309
- }
310
- throw new Error(`Transaction not confirmed after ${maxRetries * (delayMs / 1e3)}s`);
311
- };
312
- const signTypedData = async () => {
313
- throw new Error("signTypedData not implemented for Solana");
314
- };
315
- const switchChain = async (newChainId) => {
316
- _chainId = newChainId;
317
- };
313
+ // src/core/token-list.ts
314
+ var import_intents_sdk5 = require("@shogun-sdk/intents-sdk");
315
+ async function getTokenList(params) {
316
+ const url = new URL(`${import_intents_sdk5.TOKEN_SEARCH_API_BASE_URL}/tokens/search`);
317
+ if (params.q) url.searchParams.append("q", params.q);
318
+ if (params.networkId) url.searchParams.append("networkId", String(params.networkId));
319
+ if (params.page) url.searchParams.append("page", String(params.page));
320
+ if (params.limit) url.searchParams.append("limit", String(params.limit));
321
+ const res = await fetch(url.toString(), {
322
+ signal: params.signal
323
+ });
324
+ if (!res.ok) {
325
+ throw new Error(`Failed to fetch tokens: ${res.status} ${res.statusText}`);
326
+ }
327
+ const data = await res.json();
328
+ const filteredResults = data.results.filter(
329
+ (token) => CURRENT_SUPPORTED.includes(token.chainId)
330
+ );
318
331
  return {
319
- vmType: "SVM" /* SVM */,
320
- getChainId,
321
- address: async () => walletAddress,
322
- sendTransaction,
323
- switchChain,
324
- signTypedData,
325
- rpcUrl
332
+ ...data,
333
+ results: filteredResults,
334
+ count: filteredResults.length
326
335
  };
327
- };
336
+ }
337
+
338
+ // src/core/token.ts
339
+ var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
340
+ async function getTokensData(addresses) {
341
+ if (!addresses?.length) return [];
342
+ const response = await fetch(`${import_intents_sdk6.TOKEN_SEARCH_API_BASE_URL}/tokens/tokens`, {
343
+ method: "POST",
344
+ headers: {
345
+ "Content-Type": "application/json",
346
+ accept: "*/*"
347
+ },
348
+ body: JSON.stringify({ addresses })
349
+ });
350
+ if (!response.ok) {
351
+ throw new Error(`Failed to fetch token data: ${response.statusText}`);
352
+ }
353
+ const data = await response.json();
354
+ const filtered = data.filter((t) => CURRENT_SUPPORTED.includes(Number(t.chainId)));
355
+ return filtered;
356
+ }
357
+
358
+ // src/core/execute/execute.ts
359
+ var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
360
+ var import_viem7 = require("viem");
328
361
 
329
362
  // src/wallet-adapter/evm-wallet-adapter/adapter.ts
330
- var import_ethers = require("ethers/lib/ethers.js");
331
- var import_utils2 = require("ethers/lib/utils.js");
332
- var import_viem2 = require("viem");
363
+ var import_viem3 = require("viem");
333
364
  function isEVMTransaction(tx) {
334
365
  return typeof tx.from === "string";
335
366
  }
336
- var adaptEthersSigner = (signer, transport) => {
337
- const signTypedData = async (signData) => {
338
- const typedSigner = signer;
339
- return await typedSigner._signTypedData(
340
- signData.domain,
341
- signData.types,
342
- signData.value
343
- );
344
- };
345
- const sendTransaction = async (transaction) => {
346
- if (!isEVMTransaction(transaction)) {
347
- throw new Error("Expected EVMTransaction but got SolanaTransaction");
348
- }
349
- const tx = await signer.sendTransaction({
350
- from: transaction.from,
351
- to: transaction.to,
352
- data: transaction.data,
353
- value: transaction.value
354
- });
355
- return tx.hash;
356
- };
357
- const switchChain = async (chainId) => {
358
- try {
359
- await window.ethereum.request({
360
- method: "wallet_switchEthereumChain",
361
- params: [{ chainId: (0, import_utils2.hexValue)(chainId) }]
362
- });
363
- } catch (error) {
364
- console.error("Failed to switch chain:", error);
365
- throw error;
366
- }
367
- };
368
- return {
369
- vmType: "EVM" /* EVM */,
370
- transport,
371
- getChainId: async () => signer.getChainId(),
372
- address: async () => signer.getAddress(),
373
- sendTransaction,
374
- signTypedData,
375
- switchChain
376
- };
377
- };
378
367
  var adaptViemWallet = (wallet) => {
379
368
  const signTypedData = async (signData) => {
380
369
  return await wallet.signTypedData({
@@ -389,15 +378,26 @@ var adaptViemWallet = (wallet) => {
389
378
  if (!isEVMTransaction(transaction)) {
390
379
  throw new Error("Expected EVMTransaction but got SolanaTransaction");
391
380
  }
392
- const tx = await wallet.sendTransaction({
393
- from: transaction.from,
394
- to: transaction.to,
395
- data: transaction.data,
396
- value: transaction.value,
397
- account: wallet.account?.address,
398
- chain: wallet.chain
399
- });
400
- return tx;
381
+ if (wallet.transport.type === "http") {
382
+ const request = await wallet.prepareTransactionRequest({
383
+ to: transaction.to,
384
+ data: transaction.data,
385
+ value: transaction.value,
386
+ chain: wallet.chain
387
+ });
388
+ const serializedTransaction = await wallet.signTransaction(request);
389
+ const tx = await wallet.sendRawTransaction({ serializedTransaction });
390
+ return tx;
391
+ } else {
392
+ const hash = await wallet.sendTransaction({
393
+ to: transaction.to,
394
+ data: transaction.data,
395
+ value: transaction.value,
396
+ chain: wallet.chain,
397
+ account: wallet.account
398
+ });
399
+ return hash;
400
+ }
401
401
  };
402
402
  const switchChain = async (chainId) => {
403
403
  try {
@@ -420,55 +420,96 @@ var adaptViemWallet = (wallet) => {
420
420
  if (!addr) throw new Error("No address found");
421
421
  return addr;
422
422
  };
423
+ const readContract = async ({
424
+ address: address2,
425
+ abi,
426
+ functionName,
427
+ args = []
428
+ }) => {
429
+ const publicClient = wallet.extend(import_viem3.publicActions);
430
+ return await publicClient.readContract({
431
+ address: address2,
432
+ abi,
433
+ functionName,
434
+ args
435
+ });
436
+ };
423
437
  return {
424
438
  vmType: "EVM" /* EVM */,
425
- transport: (0, import_viem2.custom)(wallet.transport),
439
+ transport: (0, import_viem3.custom)(wallet.transport),
426
440
  getChainId: async () => wallet.getChainId(),
427
441
  address,
428
442
  sendTransaction,
429
443
  signTypedData,
430
- switchChain
444
+ switchChain,
445
+ readContract
431
446
  };
432
447
  };
433
448
 
434
- // src/core/executeOrder/handleEvmExecution.ts
435
- var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
436
- var import_viem3 = require("viem");
449
+ // src/core/execute/handleEvmExecution.ts
450
+ var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
451
+ var import_viem6 = require("viem");
437
452
 
438
- // src/core/executeOrder/stageMessages.ts
453
+ // src/core/execute/stageMessages.ts
439
454
  var DEFAULT_STAGE_MESSAGES = {
440
455
  processing: "Preparing transaction for execution",
441
456
  approving: "Approving token allowance",
442
457
  approved: "Token approved successfully",
443
- signing: "Signing order for submission",
444
- submitting: "Submitting order to Auctioneer",
445
- success: "Order executed successfully",
446
- error: "Order execution failed"
458
+ signing: "Signing transaction for submission",
459
+ submitting: "Submitting transaction",
460
+ initiated: "Transaction initiated.",
461
+ success: "Transaction Executed successfully",
462
+ success_limit: "Limit order has been submitted successfully.",
463
+ shogun_processing: "Shogun is processing your transaction",
464
+ error: "Transaction failed during submission"
447
465
  };
448
466
 
449
- // src/core/executeOrder/buildOrder.ts
450
- var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
467
+ // src/core/execute/buildOrder.ts
468
+ var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
469
+ var import_viem4 = require("viem");
470
+
471
+ // src/utils/order.ts
472
+ var OrderExecutionType = /* @__PURE__ */ ((OrderExecutionType2) => {
473
+ OrderExecutionType2["LIMIT"] = "limit";
474
+ OrderExecutionType2["MARKET"] = "market";
475
+ return OrderExecutionType2;
476
+ })(OrderExecutionType || {});
477
+
478
+ // src/core/execute/buildOrder.ts
451
479
  async function buildOrder({
452
480
  quote,
453
481
  accountAddress,
454
482
  destination,
455
483
  deadline,
456
- isSingleChain
484
+ isSingleChain,
485
+ orderType,
486
+ options
457
487
  }) {
458
488
  const { tokenIn, tokenOut } = quote;
489
+ let amountOutMin = BigInt(quote.internal.estimatedAmountOutReduced);
490
+ if (orderType === "limit" /* LIMIT */ && options && "executionPrice" in options) {
491
+ const executionPrice = Number(options.executionPrice);
492
+ if (Number.isFinite(executionPrice) && executionPrice > 0) {
493
+ const decimalsIn = tokenIn.decimals ?? 18;
494
+ const decimalsOut = tokenOut.decimals ?? 18;
495
+ const formattedAmountIn = Number((0, import_viem4.formatUnits)(BigInt(quote.amountIn.toString()), decimalsIn));
496
+ const rawAmountOut = formattedAmountIn * executionPrice;
497
+ amountOutMin = (0, import_viem4.parseUnits)(rawAmountOut.toString(), decimalsOut);
498
+ }
499
+ }
459
500
  if (isSingleChain) {
460
- return await import_intents_sdk6.SingleChainOrder.create({
501
+ return await import_intents_sdk7.SingleChainOrder.create({
461
502
  user: accountAddress,
462
503
  chainId: tokenIn.chainId,
463
504
  tokenIn: tokenIn.address,
464
505
  tokenOut: tokenOut.address,
465
506
  amountIn: quote.amountIn,
466
- amountOutMin: quote.internal.estimatedAmountOutReduced,
507
+ amountOutMin,
467
508
  deadline,
468
509
  destinationAddress: destination
469
510
  });
470
511
  }
471
- return await import_intents_sdk6.CrossChainOrder.create({
512
+ return await import_intents_sdk7.CrossChainOrder.create({
472
513
  user: accountAddress,
473
514
  sourceChainId: tokenIn.chainId,
474
515
  sourceTokenAddress: tokenIn.address,
@@ -477,12 +518,161 @@ async function buildOrder({
477
518
  destinationTokenAddress: tokenOut.address,
478
519
  destinationAddress: destination,
479
520
  deadline,
480
- destinationTokenMinAmount: quote.internal.estimatedAmountOutReduced,
521
+ destinationTokenMinAmount: amountOutMin,
481
522
  minStablecoinAmount: quote.minStablecoinsAmount
482
523
  });
483
524
  }
484
525
 
485
- // src/core/executeOrder/handleEvmExecution.ts
526
+ // src/utils/pollOrderStatus.ts
527
+ var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
528
+ async function pollOrderStatus(address, orderId, options = {}) {
529
+ const { intervalMs = 2e3, timeoutMs = 3e5 } = options;
530
+ const startTime = Date.now();
531
+ const isDebug = process.env.NODE_ENV !== "production";
532
+ const isEvmAddress = /^0x[a-fA-F0-9]{40}$/.test(address);
533
+ const isSuiAddress = /^0x[a-fA-F0-9]{64}$/.test(address);
534
+ const isSolanaAddress = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
535
+ let queryParam;
536
+ if (isEvmAddress) queryParam = `evmWallets=${address}`;
537
+ else if (isSuiAddress) queryParam = `suiWallets=${address}`;
538
+ else if (isSolanaAddress) queryParam = `solanaWallets=${address}`;
539
+ else throw new Error(`Unrecognized wallet address format: ${address}`);
540
+ const queryUrl = `${import_intents_sdk8.AUCTIONEER_URL}/user_intent?${queryParam}`;
541
+ return new Promise((resolve, reject) => {
542
+ const pollInterval = setInterval(async () => {
543
+ try {
544
+ if (Date.now() - startTime > timeoutMs) {
545
+ clearInterval(pollInterval);
546
+ return resolve("Timeout");
547
+ }
548
+ const res = await fetch(queryUrl, {
549
+ method: "GET",
550
+ headers: { "Content-Type": "application/json" }
551
+ });
552
+ if (!res.ok) {
553
+ clearInterval(pollInterval);
554
+ return reject(
555
+ new Error(`Failed to fetch orders: ${res.status} ${res.statusText}`)
556
+ );
557
+ }
558
+ const json = await res.json();
559
+ const data = json?.data ?? {};
560
+ const allOrders = [
561
+ ...data.crossChainDcaOrders ?? [],
562
+ ...data.crossChainLimitOrders ?? [],
563
+ ...data.singleChainDcaOrders ?? [],
564
+ ...data.singleChainLimitOrders ?? []
565
+ ];
566
+ const targetOrder = allOrders.find((o) => o.orderId === orderId);
567
+ if (!targetOrder) {
568
+ if (isDebug)
569
+ console.debug(`[pollOrderStatus] [${orderId}] Not found yet`);
570
+ return;
571
+ }
572
+ const { orderStatus } = targetOrder;
573
+ if (isDebug) {
574
+ const elapsed = ((Date.now() - startTime) / 1e3).toFixed(1);
575
+ console.debug(`targetOrder`, targetOrder);
576
+ console.debug(
577
+ `[pollOrderStatus] [${orderId}] status=${orderStatus} (elapsed ${elapsed}s)`
578
+ );
579
+ }
580
+ if (["Fulfilled", "Cancelled", "Outdated"].includes(orderStatus)) {
581
+ clearInterval(pollInterval);
582
+ return resolve(orderStatus);
583
+ }
584
+ } catch (error) {
585
+ clearInterval(pollInterval);
586
+ return reject(error);
587
+ }
588
+ }, intervalMs);
589
+ });
590
+ }
591
+
592
+ // src/core/execute/handleOrderPollingResult.ts
593
+ async function handleOrderPollingResult({
594
+ status,
595
+ orderId,
596
+ chainId,
597
+ update,
598
+ messageFor
599
+ }) {
600
+ switch (status) {
601
+ case "Fulfilled":
602
+ update("success", messageFor("success"));
603
+ return {
604
+ status: true,
605
+ orderId,
606
+ chainId,
607
+ finalStatus: status,
608
+ stage: "success"
609
+ };
610
+ case "Cancelled":
611
+ update("error", "Order was cancelled before fulfillment");
612
+ break;
613
+ case "Timeout":
614
+ update("error", "Order polling timed out");
615
+ break;
616
+ case "NotFound":
617
+ default:
618
+ update("error", "Order not found");
619
+ break;
620
+ }
621
+ return {
622
+ status: false,
623
+ orderId,
624
+ chainId,
625
+ finalStatus: status,
626
+ stage: "error"
627
+ };
628
+ }
629
+
630
+ // src/core/execute/ensurePermit2Allowance.ts
631
+ var import_viem5 = require("viem");
632
+ var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
633
+ async function ensurePermit2Allowance({
634
+ chainId,
635
+ tokenIn,
636
+ wallet,
637
+ accountAddress,
638
+ requiredAmount,
639
+ increaseByDelta = false
640
+ }) {
641
+ const spender = import_intents_sdk9.PERMIT2_ADDRESS[chainId];
642
+ let currentAllowance = 0n;
643
+ try {
644
+ if (!wallet.readContract) {
645
+ throw new Error("Wallet does not implement readContract()");
646
+ }
647
+ currentAllowance = await wallet.readContract({
648
+ address: tokenIn,
649
+ abi: import_viem5.erc20Abi,
650
+ functionName: "allowance",
651
+ args: [accountAddress, spender]
652
+ });
653
+ } catch (error) {
654
+ console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
655
+ }
656
+ const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem5.maxUint256;
657
+ console.debug(
658
+ `[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
659
+ );
660
+ await wallet.sendTransaction({
661
+ to: tokenIn,
662
+ from: accountAddress,
663
+ data: (0, import_viem5.encodeFunctionData)({
664
+ abi: import_viem5.erc20Abi,
665
+ functionName: "approve",
666
+ args: [spender, approvalAmount]
667
+ }),
668
+ value: 0n
669
+ });
670
+ console.info(
671
+ `[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
672
+ );
673
+ }
674
+
675
+ // src/core/execute/handleEvmExecution.ts
486
676
  async function handleEvmExecution({
487
677
  recipientAddress,
488
678
  quote,
@@ -490,18 +680,22 @@ async function handleEvmExecution({
490
680
  accountAddress,
491
681
  wallet,
492
682
  isSingleChain,
493
- deadline,
494
- update
683
+ update,
684
+ orderType,
685
+ options
495
686
  }) {
496
- const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
687
+ const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
688
+ const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
497
689
  await wallet.switchChain(chainId);
498
690
  const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
691
+ quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
499
692
  const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
500
693
  update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
501
694
  if (shouldWrapNative) {
695
+ quote.tokenIn.address === tokenIn;
502
696
  await wallet.sendTransaction({
503
697
  to: tokenIn,
504
- data: (0, import_viem3.encodeFunctionData)({
698
+ data: (0, import_viem6.encodeFunctionData)({
505
699
  abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
506
700
  functionName: "deposit",
507
701
  args: []
@@ -510,44 +704,71 @@ async function handleEvmExecution({
510
704
  from: accountAddress
511
705
  });
512
706
  }
513
- update("approving", messageFor("approving"));
514
- await wallet.sendTransaction({
515
- to: tokenIn,
516
- data: (0, import_viem3.encodeFunctionData)({
517
- abi: import_viem3.erc20Abi,
518
- functionName: "approve",
519
- args: [import_intents_sdk7.PERMIT2_ADDRESS[chainId], BigInt(quote.amountIn)]
520
- }),
521
- value: 0n,
522
- from: accountAddress
707
+ update("processing", messageFor("approving"));
708
+ await ensurePermit2Allowance({
709
+ chainId,
710
+ tokenIn,
711
+ wallet,
712
+ accountAddress,
713
+ requiredAmount: BigInt(quote.amountIn)
523
714
  });
524
- update("approved", messageFor("approved"));
715
+ update("processing", messageFor("approved"));
525
716
  const destination = recipientAddress ?? accountAddress;
526
717
  const order = await buildOrder({
527
718
  quote,
528
719
  accountAddress,
529
720
  destination,
530
721
  deadline,
531
- isSingleChain
722
+ isSingleChain,
723
+ orderType,
724
+ options
532
725
  });
533
- update("signing", messageFor("signing"));
534
- const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk7.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk7.getEVMCrossChainOrderTypedData)(order);
726
+ console.debug(`order`, order);
727
+ update("processing", messageFor("signing"));
728
+ const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk10.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk10.getEVMCrossChainOrderTypedData)(order);
729
+ const typedData = serializeBigIntsToStrings(orderTypedData);
535
730
  if (!wallet.signTypedData) {
536
731
  throw new Error("Wallet does not support EIP-712 signing");
537
732
  }
538
- const signature = await wallet.signTypedData(serializeBigIntsToStrings(orderTypedData));
539
- update("submitting", messageFor("submitting"));
733
+ const signature = await wallet.signTypedData({
734
+ domain: typedData.domain,
735
+ types: typedData.types,
736
+ primaryType: typedData.primaryType,
737
+ value: typedData.message,
738
+ message: typedData.message
739
+ });
740
+ update("processing", messageFor("submitting"));
540
741
  const res = await order.sendToAuctioneer({ signature, nonce: nonce.toString() });
541
742
  if (!res.success) {
542
743
  throw new Error("Auctioneer submission failed");
543
744
  }
544
- update("success", messageFor("success"));
545
- return { status: true, txHash: res.data, chainId, stage: "success" };
745
+ update("initiated", messageFor("initiated"));
746
+ const { intentId: orderId } = res.data;
747
+ update("initiated", messageFor("shogun_processing"));
748
+ if (orderType === "limit" /* LIMIT */) {
749
+ update("success", messageFor("success_limit"));
750
+ return {
751
+ status: true,
752
+ orderId,
753
+ chainId,
754
+ finalStatus: "OrderPlaced",
755
+ stage: "success"
756
+ };
757
+ } else {
758
+ const status = await pollOrderStatus(accountAddress, orderId);
759
+ return await handleOrderPollingResult({
760
+ status,
761
+ orderId,
762
+ chainId,
763
+ update,
764
+ messageFor
765
+ });
766
+ }
546
767
  }
547
768
 
548
- // src/core/executeOrder/handleSolanaExecution.ts
549
- var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
550
- var import_web32 = require("@solana/web3.js");
769
+ // src/core/execute/handleSolanaExecution.ts
770
+ var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
771
+ var import_web3 = require("@solana/web3.js");
551
772
  async function handleSolanaExecution({
552
773
  recipientAddress,
553
774
  quote,
@@ -555,12 +776,14 @@ async function handleSolanaExecution({
555
776
  isSingleChain,
556
777
  update,
557
778
  accountAddress,
558
- deadline
779
+ orderType,
780
+ options
559
781
  }) {
560
782
  if (!wallet.rpcUrl) {
561
783
  throw new Error("Solana wallet is missing rpcUrl");
562
784
  }
563
- const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
785
+ const deadline = options?.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
786
+ const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage] ?? "";
564
787
  update("processing", messageFor("processing"));
565
788
  const destination = recipientAddress ?? accountAddress;
566
789
  const order = await buildOrder({
@@ -568,18 +791,19 @@ async function handleSolanaExecution({
568
791
  accountAddress,
569
792
  destination,
570
793
  deadline,
571
- isSingleChain
794
+ isSingleChain,
795
+ orderType,
796
+ options
572
797
  });
573
798
  const txData = await getSolanaOrderInstructions({
574
799
  order,
575
800
  isSingleChain,
576
801
  rpcUrl: wallet.rpcUrl
577
802
  });
578
- const transaction = import_web32.VersionedTransaction.deserialize(Uint8Array.from(txData.txBytes));
579
- update("signing", messageFor("signing"));
580
- console.log({ order });
581
- const txSignature = await wallet.sendTransaction(transaction);
582
- update("submitting", messageFor("submitting"));
803
+ const transaction = import_web3.VersionedTransaction.deserialize(Uint8Array.from(txData.txBytes));
804
+ update("processing", messageFor("signing"));
805
+ await wallet.sendTransaction(transaction);
806
+ update("processing", messageFor("submitting"));
583
807
  const response = await submitToAuctioneer({
584
808
  order,
585
809
  isSingleChain,
@@ -588,13 +812,28 @@ async function handleSolanaExecution({
588
812
  if (!response.success) {
589
813
  throw new Error("Auctioneer submission failed");
590
814
  }
591
- update("success", messageFor("success"));
592
- return {
593
- status: true,
594
- txHash: txSignature,
595
- chainId: import_intents_sdk8.ChainID.Solana,
596
- stage: "success"
597
- };
815
+ update("initiated", messageFor("initiated"));
816
+ const { intentId: orderId } = response.data;
817
+ update("initiated", messageFor("shogun_processing"));
818
+ if (orderType === "limit" /* LIMIT */) {
819
+ update("success", messageFor("success_limit"));
820
+ return {
821
+ status: true,
822
+ orderId,
823
+ chainId: SOLANA_CHAIN_ID,
824
+ finalStatus: "OrderPlaced",
825
+ stage: "success"
826
+ };
827
+ } else {
828
+ const status = await pollOrderStatus(accountAddress, orderId);
829
+ return await handleOrderPollingResult({
830
+ status,
831
+ orderId,
832
+ chainId: SOLANA_CHAIN_ID,
833
+ update,
834
+ messageFor
835
+ });
836
+ }
598
837
  }
599
838
  async function getSolanaOrderInstructions({
600
839
  order,
@@ -602,11 +841,11 @@ async function getSolanaOrderInstructions({
602
841
  rpcUrl
603
842
  }) {
604
843
  if (isSingleChain) {
605
- return await (0, import_intents_sdk8.getSolanaSingleChainOrderInstructions)(order, {
844
+ return await (0, import_intents_sdk11.getSolanaSingleChainOrderInstructions)(order, {
606
845
  rpcUrl
607
846
  });
608
847
  }
609
- return await (0, import_intents_sdk8.getSolanaCrossChainOrderInstructions)(order, {
848
+ return await (0, import_intents_sdk11.getSolanaCrossChainOrderInstructions)(order, {
610
849
  rpcUrl
611
850
  });
612
851
  }
@@ -627,52 +866,93 @@ async function submitToAuctioneer({
627
866
  });
628
867
  }
629
868
 
630
- // src/core/executeOrder/execute.ts
869
+ // src/core/execute/execute.ts
631
870
  async function executeOrder({
632
871
  quote,
633
872
  accountAddress,
634
873
  recipientAddress,
635
874
  wallet,
636
875
  onStatus,
876
+ orderType = "market" /* MARKET */,
637
877
  options = {}
638
878
  }) {
639
- const deadline = options.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
879
+ const isDev = process.env.NODE_ENV !== "production";
880
+ const log = (...args) => {
881
+ if (isDev) console.debug("[OneShot::executeOrder]", ...args);
882
+ };
640
883
  const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
641
- const update = (stage, message) => onStatus?.(stage, message ?? messageFor(stage));
884
+ const update = (stage, message) => {
885
+ log("Stage:", stage, "| Message:", message ?? messageFor(stage));
886
+ onStatus?.(stage, message ?? messageFor(stage));
887
+ };
642
888
  try {
889
+ log("Starting execution:", {
890
+ accountAddress,
891
+ recipientAddress,
892
+ tokenIn: quote?.tokenIn,
893
+ tokenOut: quote?.tokenOut
894
+ });
643
895
  const adapter = normalizeWallet(wallet);
644
896
  if (!adapter) throw new Error("No wallet provided");
645
897
  const { tokenIn, tokenOut } = quote;
898
+ const srcChain = Number(tokenIn.chainId);
899
+ const destChain = Number(tokenOut.chainId);
900
+ if (!CURRENT_SUPPORTED.includes(srcChain) || !CURRENT_SUPPORTED.includes(destChain)) {
901
+ const unsupportedChains = [
902
+ !CURRENT_SUPPORTED.includes(srcChain) ? srcChain : null,
903
+ !CURRENT_SUPPORTED.includes(destChain) ? destChain : null
904
+ ].filter(Boolean).join(", ");
905
+ const errorMsg = `Unsupported chain(s): ${unsupportedChains}`;
906
+ update("error", errorMsg);
907
+ log("Error:", errorMsg);
908
+ throw new Error(errorMsg);
909
+ }
646
910
  const isSingleChain = tokenIn.chainId === tokenOut.chainId;
647
911
  const chainId = Number(tokenIn.chainId);
648
- update("processing", messageFor("processing"));
649
- if ((0, import_intents_sdk9.isEvmChain)(chainId)) {
650
- return await handleEvmExecution({
912
+ update("processing");
913
+ if ((0, import_intents_sdk12.isEvmChain)(chainId)) {
914
+ log("Detected EVM chain:", chainId);
915
+ const result = await handleEvmExecution({
651
916
  recipientAddress,
652
917
  quote,
653
918
  chainId,
654
919
  accountAddress,
655
920
  wallet: adapter,
656
921
  isSingleChain,
657
- deadline,
658
- update
922
+ update,
923
+ orderType,
924
+ options
659
925
  });
926
+ log("EVM execution result:", result);
927
+ return result;
660
928
  }
661
- if (chainId === import_intents_sdk9.ChainID.Solana) {
662
- return await handleSolanaExecution({
929
+ if (chainId === import_intents_sdk12.ChainID.Solana) {
930
+ log("Detected Solana chain");
931
+ const result = await handleSolanaExecution({
663
932
  recipientAddress,
664
933
  quote,
665
934
  accountAddress,
666
935
  wallet: adapter,
667
936
  isSingleChain,
668
- deadline,
669
- update
937
+ update,
938
+ orderType,
939
+ options
670
940
  });
941
+ log("Solana execution result:", result);
942
+ return result;
671
943
  }
672
- update("error", "Unsupported chain");
673
- return { status: false, message: "Unsupported chain", stage: "error" };
944
+ const unsupported = `Unsupported chain: ${chainId}`;
945
+ update("error", unsupported);
946
+ log("Error:", unsupported);
947
+ return { status: false, message: unsupported, stage: "error" };
674
948
  } catch (error) {
675
- const message = error instanceof import_viem4.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
949
+ let message = "An unknown error occurred";
950
+ if (error && typeof error === "object") {
951
+ const err = error;
952
+ message = err.details ?? err.message ?? message;
953
+ } else if (typeof error === "string") {
954
+ message = error;
955
+ }
676
956
  update("error", message);
677
957
  return { status: false, message, stage: "error" };
678
958
  }
@@ -683,318 +963,484 @@ function normalizeWallet(wallet) {
683
963
  return wallet;
684
964
  }
685
965
 
686
- // src/react/useTokenList.ts
687
- var import_react = require("react");
688
- var tokenCache = /* @__PURE__ */ new Map();
689
- function useTokenList(params) {
690
- const [data, setData] = (0, import_react.useState)(null);
691
- const [loading, setLoading] = (0, import_react.useState)(false);
692
- const [error, setError] = (0, import_react.useState)(null);
693
- const controllerRef = (0, import_react.useRef)(null);
694
- const debounceRef = (0, import_react.useRef)(null);
695
- const debounceMs = params.debounceMs ?? 250;
696
- const cacheKey = (0, import_react.useMemo)(() => {
697
- return JSON.stringify({
698
- q: params.q?.trim().toLowerCase() ?? "",
699
- networkId: params.networkId ?? "all",
700
- page: params.page ?? 1,
701
- limit: params.limit ?? 50
702
- });
703
- }, [params.q, params.networkId, params.page, params.limit]);
704
- async function fetchTokens(signal) {
705
- if (tokenCache.has(cacheKey)) {
706
- setData(tokenCache.get(cacheKey));
707
- setLoading(false);
708
- setError(null);
709
- return;
966
+ // src/core/orders/getOrders.ts
967
+ var import_intents_sdk13 = require("@shogun-sdk/intents-sdk");
968
+ async function getOrders({
969
+ evmAddress,
970
+ solAddress
971
+ }) {
972
+ if (!evmAddress && !solAddress) {
973
+ throw new Error("At least one wallet address (EVM, Solana) must be provided.");
974
+ }
975
+ const orders = await (0, import_intents_sdk13.fetchUserOrders)(evmAddress, solAddress);
976
+ return orders;
977
+ }
978
+
979
+ // src/core/orders/cancelOrder.ts
980
+ var import_intents_sdk14 = require("@shogun-sdk/intents-sdk");
981
+ var import_web32 = require("@solana/web3.js");
982
+ var import_viem8 = require("viem");
983
+ async function cancelIntentsOrder({
984
+ order,
985
+ wallet,
986
+ sol_rpc
987
+ }) {
988
+ const isCrossChain = "srcChainId" in order && "destChainId" in order && order.srcChainId !== order.destChainId;
989
+ const srcChain = "srcChainId" in order ? order.srcChainId : order.chainId;
990
+ const isSolanaOrder = srcChain === import_intents_sdk14.ChainID.Solana;
991
+ if (isSolanaOrder) {
992
+ if (!isCrossChain) {
993
+ const { versionedMessageBytes: versionedMessageBytes2 } = await (0, import_intents_sdk14.cancelSingleChainOrderInstructionsAsBytes)(
994
+ order.orderId,
995
+ order.user,
996
+ { rpcUrl: sol_rpc }
997
+ );
998
+ const message2 = import_web32.VersionedMessage.deserialize(
999
+ versionedMessageBytes2
1000
+ );
1001
+ const tx2 = new import_web32.VersionedTransaction(message2);
1002
+ return await wallet.sendTransaction(tx2);
710
1003
  }
711
- try {
712
- setLoading(true);
713
- const result = await getTokenList({ ...params, signal });
714
- tokenCache.set(cacheKey, result);
715
- setData(result);
716
- setError(null);
717
- } catch (err) {
718
- if (err.name !== "AbortError") {
719
- const e = err instanceof Error ? err : new Error("Unknown error while fetching tokens");
720
- setError(e);
1004
+ const { versionedMessageBytes } = await (0, import_intents_sdk14.cancelCrossChainOrderInstructionsAsBytes)(
1005
+ order.orderId,
1006
+ order.user,
1007
+ { rpcUrl: sol_rpc }
1008
+ );
1009
+ const message = import_web32.VersionedMessage.deserialize(
1010
+ versionedMessageBytes
1011
+ );
1012
+ const tx = new import_web32.VersionedTransaction(message);
1013
+ return await wallet.sendTransaction(tx);
1014
+ }
1015
+ const chainId = srcChain;
1016
+ const { readContract } = wallet;
1017
+ if (!readContract) {
1018
+ throw new Error("Wallet does not support readContract");
1019
+ }
1020
+ const nonce = BigInt(order.nonce ?? "0");
1021
+ const nonceWordPos = nonce >> 8n;
1022
+ const nonceBitPos = nonce - nonceWordPos * 256n;
1023
+ if (isCrossChain) {
1024
+ const [orderData = [false, false], currentNonceBitmap = 0n] = await Promise.all([
1025
+ readContract({
1026
+ address: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[chainId],
1027
+ abi: [
1028
+ {
1029
+ inputs: [{ name: "orderId", type: "bytes32" }],
1030
+ name: "orderData",
1031
+ outputs: [
1032
+ { name: "initialized", type: "bool" },
1033
+ { name: "deactivated", type: "bool" }
1034
+ ],
1035
+ stateMutability: "view",
1036
+ type: "function"
1037
+ }
1038
+ ],
1039
+ functionName: "orderData",
1040
+ args: [order.orderId]
1041
+ }),
1042
+ readContract({
1043
+ address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
1044
+ abi: [
1045
+ {
1046
+ inputs: [
1047
+ { name: "owner", type: "address" },
1048
+ { name: "wordPos", type: "uint256" }
1049
+ ],
1050
+ name: "nonceBitmap",
1051
+ outputs: [{ name: "", type: "uint256" }],
1052
+ stateMutability: "view",
1053
+ type: "function"
1054
+ }
1055
+ ],
1056
+ functionName: "nonceBitmap",
1057
+ args: [order.user, nonceWordPos]
1058
+ })
1059
+ ]);
1060
+ const [initialized, deactivated] = orderData;
1061
+ if (initialized) {
1062
+ if (deactivated) {
1063
+ throw new Error("Order is already deactivated");
721
1064
  }
722
- } finally {
723
- setLoading(false);
1065
+ return await wallet.sendTransaction({
1066
+ to: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[order.srcChainId],
1067
+ data: (0, import_viem8.encodeFunctionData)({
1068
+ abi: [
1069
+ {
1070
+ inputs: [
1071
+ {
1072
+ components: [
1073
+ { name: "user", type: "address" },
1074
+ { name: "tokenIn", type: "address" },
1075
+ { name: "srcChainId", type: "uint256" },
1076
+ { name: "deadline", type: "uint256" },
1077
+ { name: "amountIn", type: "uint256" },
1078
+ { name: "minStablecoinsAmount", type: "uint256" },
1079
+ { name: "executionDetailsHash", type: "bytes32" },
1080
+ { name: "nonce", type: "uint256" }
1081
+ ],
1082
+ name: "orderInfo",
1083
+ type: "tuple"
1084
+ }
1085
+ ],
1086
+ name: "cancelOrder",
1087
+ outputs: [],
1088
+ stateMutability: "nonpayable",
1089
+ type: "function"
1090
+ }
1091
+ ],
1092
+ functionName: "cancelOrder",
1093
+ args: [
1094
+ {
1095
+ user: order.user,
1096
+ tokenIn: order.tokenIn,
1097
+ srcChainId: BigInt(order.srcChainId),
1098
+ deadline: BigInt(order.deadline),
1099
+ amountIn: BigInt(order.amountIn),
1100
+ minStablecoinsAmount: BigInt(order.minStablecoinsAmount),
1101
+ executionDetailsHash: order.executionDetailsHash,
1102
+ nonce
1103
+ }
1104
+ ]
1105
+ }),
1106
+ value: BigInt(0),
1107
+ from: order.user
1108
+ });
1109
+ } else {
1110
+ if ((currentNonceBitmap & 1n << nonceBitPos) !== 0n) {
1111
+ throw new Error("Nonce is already invalidated");
1112
+ }
1113
+ const mask2 = 1n << nonceBitPos;
1114
+ return await wallet.sendTransaction({
1115
+ to: import_intents_sdk14.PERMIT2_ADDRESS[order.srcChainId],
1116
+ data: (0, import_viem8.encodeFunctionData)({
1117
+ abi: [
1118
+ {
1119
+ inputs: [
1120
+ { name: "wordPos", type: "uint256" },
1121
+ { name: "mask", type: "uint256" }
1122
+ ],
1123
+ name: "invalidateUnorderedNonces",
1124
+ outputs: [],
1125
+ stateMutability: "nonpayable",
1126
+ type: "function"
1127
+ }
1128
+ ],
1129
+ functionName: "invalidateUnorderedNonces",
1130
+ args: [nonceWordPos, mask2]
1131
+ }),
1132
+ value: BigInt(0),
1133
+ from: order.user
1134
+ });
724
1135
  }
725
1136
  }
726
- (0, import_react.useEffect)(() => {
727
- if (!params.q && !params.networkId) return;
728
- if (debounceRef.current) clearTimeout(debounceRef.current);
729
- if (controllerRef.current) controllerRef.current.abort();
730
- const controller = new AbortController();
731
- controllerRef.current = controller;
732
- debounceRef.current = setTimeout(() => {
733
- fetchTokens(controller.signal);
734
- }, debounceMs);
735
- return () => {
736
- controller.abort();
737
- if (debounceRef.current) clearTimeout(debounceRef.current);
738
- };
739
- }, [cacheKey, debounceMs]);
740
- return (0, import_react.useMemo)(
741
- () => ({
742
- /** Current fetched data (cached when possible) */
743
- data,
744
- /** Whether a request is in progress */
745
- loading,
746
- /** Error object if a request failed */
747
- error,
748
- /** Manually refetch the token list */
749
- refetch: () => fetchTokens(),
750
- /** Clear all cached token results (shared across hook instances) */
751
- clearCache: () => tokenCache.clear()
1137
+ const [wasManuallyInitialized, currentBitmap = 0n] = await Promise.all([
1138
+ readContract({
1139
+ address: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
1140
+ abi: [
1141
+ {
1142
+ inputs: [{ name: "orderHash", type: "bytes32" }],
1143
+ name: "orderManuallyInitialized",
1144
+ outputs: [{ name: "", type: "bool" }],
1145
+ stateMutability: "view",
1146
+ type: "function"
1147
+ }
1148
+ ],
1149
+ functionName: "orderManuallyInitialized",
1150
+ args: [order.orderId]
752
1151
  }),
753
- [data, loading, error]
754
- );
755
- }
756
-
757
- // src/react/useExecuteOrder.ts
758
- var import_react2 = require("react");
759
- function useExecuteOrder() {
760
- const [status, setStatus] = (0, import_react2.useState)("processing");
761
- const [message, setMessage] = (0, import_react2.useState)(null);
762
- const [loading, setLoading] = (0, import_react2.useState)(false);
763
- const [data, setData] = (0, import_react2.useState)(null);
764
- const [error, setError] = (0, import_react2.useState)(null);
765
- const isMounted = (0, import_react2.useRef)(true);
766
- (0, import_react2.useEffect)(() => {
767
- return () => {
768
- isMounted.current = false;
769
- };
770
- }, []);
771
- const execute = (0, import_react2.useCallback)(
772
- async ({
773
- quote,
774
- accountAddress,
775
- recipientAddress,
776
- wallet,
777
- deadline
778
- }) => {
779
- if (!quote || !wallet) {
780
- throw new Error("Quote and wallet are required for order execution.");
781
- }
782
- setLoading(true);
783
- setError(null);
784
- setData(null);
785
- setMessage(null);
786
- try {
787
- const effectiveDeadline = deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
788
- const onStatus = (stage, msg) => {
789
- if (!isMounted.current) return;
790
- setStatus(stage);
791
- if (msg) setMessage(msg);
792
- };
793
- const result = await executeOrder({
794
- quote,
795
- accountAddress,
796
- recipientAddress,
797
- wallet,
798
- onStatus,
799
- options: { deadline: effectiveDeadline }
800
- });
801
- if (!isMounted.current) return result;
802
- setData(result);
803
- setStatus(result.stage);
804
- setMessage("Order executed successfully");
805
- return result;
806
- } catch (err) {
807
- const errorObj = err instanceof Error ? err : new Error(String(err));
808
- if (isMounted.current) {
809
- setError(errorObj);
810
- setStatus("error");
811
- setMessage(errorObj.message);
812
- setData({
813
- status: false,
814
- stage: "error",
815
- message: errorObj.message
816
- });
1152
+ readContract({
1153
+ address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
1154
+ abi: [
1155
+ {
1156
+ inputs: [
1157
+ { name: "owner", type: "address" },
1158
+ { name: "wordPos", type: "uint256" }
1159
+ ],
1160
+ name: "nonceBitmap",
1161
+ outputs: [{ name: "", type: "uint256" }],
1162
+ stateMutability: "view",
1163
+ type: "function"
817
1164
  }
818
- return {
819
- status: false,
820
- stage: "error",
821
- message: errorObj.message
822
- };
823
- } finally {
824
- if (isMounted.current) setLoading(false);
825
- }
826
- },
827
- []
828
- );
829
- return {
830
- /** Executes the swap order. */
831
- execute,
832
- /** Current execution stage. */
833
- status,
834
- /** Human-readable status message. */
835
- message,
836
- /** Whether execution is ongoing. */
837
- loading,
838
- /** Raw SDK response data. */
839
- data,
840
- /** Captured error (if execution failed). */
841
- error
842
- };
843
- }
844
-
845
- // src/react/useQuote.ts
846
- var import_react3 = require("react");
847
- function useQuote(params, options) {
848
- const [data, setData] = (0, import_react3.useState)(null);
849
- const [loading, setLoading] = (0, import_react3.useState)(false);
850
- const [error, setError] = (0, import_react3.useState)(null);
851
- const [warning, setWarning] = (0, import_react3.useState)(null);
852
- const debounceMs = options?.debounceMs ?? 250;
853
- const autoRefreshMs = options?.autoRefreshMs;
854
- const abortRef = (0, import_react3.useRef)(null);
855
- const debounceRef = (0, import_react3.useRef)(null);
856
- const mounted = (0, import_react3.useRef)(false);
857
- (0, import_react3.useEffect)(() => {
858
- mounted.current = true;
859
- return () => {
860
- mounted.current = false;
861
- abortRef.current?.abort();
862
- if (debounceRef.current) clearTimeout(debounceRef.current);
863
- };
864
- }, []);
865
- const fetchQuote = (0, import_react3.useCallback)(
866
- async () => {
867
- if (!params) return;
868
- try {
869
- setLoading(true);
870
- setWarning(null);
871
- const result = await getQuote(params);
872
- if (!mounted.current) return;
873
- setData((prev) => {
874
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
875
- return result;
876
- });
877
- setWarning(result.warning ?? null);
878
- setError(null);
879
- } catch (err) {
880
- if (err.name === "AbortError") return;
881
- console.error("[useQuote] fetch error:", err);
882
- if (mounted.current) setError(err instanceof Error ? err : new Error(String(err)));
883
- } finally {
884
- if (mounted.current) setLoading(false);
885
- }
886
- },
887
- [params]
888
- );
889
- (0, import_react3.useEffect)(() => {
890
- if (!params) return;
891
- if (debounceRef.current) clearTimeout(debounceRef.current);
892
- debounceRef.current = setTimeout(() => {
893
- fetchQuote();
894
- }, debounceMs);
895
- return () => {
896
- if (debounceRef.current) clearTimeout(debounceRef.current);
897
- abortRef.current?.abort();
898
- };
899
- }, [params, debounceMs, fetchQuote]);
900
- (0, import_react3.useEffect)(() => {
901
- if (!autoRefreshMs || !params) return;
902
- const interval = setInterval(() => fetchQuote(), autoRefreshMs);
903
- return () => clearInterval(interval);
904
- }, [autoRefreshMs, params, fetchQuote]);
905
- return (0, import_react3.useMemo)(
906
- () => ({
907
- data,
908
- loading,
909
- error,
910
- warning,
911
- refetch: () => fetchQuote()
1165
+ ],
1166
+ functionName: "nonceBitmap",
1167
+ args: [order.user, nonceWordPos]
1168
+ })
1169
+ ]);
1170
+ if (wasManuallyInitialized) {
1171
+ return await wallet.sendTransaction({
1172
+ to: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
1173
+ data: (0, import_viem8.encodeFunctionData)({
1174
+ abi: [
1175
+ {
1176
+ inputs: [
1177
+ {
1178
+ name: "order",
1179
+ type: "tuple",
1180
+ components: [
1181
+ { name: "amountIn", type: "uint256" },
1182
+ { name: "tokenIn", type: "address" },
1183
+ { name: "deadline", type: "uint256" },
1184
+ { name: "nonce", type: "uint256" },
1185
+ { name: "encodedExternalCallData", type: "bytes" },
1186
+ {
1187
+ name: "extraTransfers",
1188
+ type: "tuple[]",
1189
+ components: [
1190
+ { name: "amount", type: "uint256" },
1191
+ { name: "receiver", type: "address" },
1192
+ { name: "token", type: "address" }
1193
+ ]
1194
+ },
1195
+ {
1196
+ name: "requestedOutput",
1197
+ type: "tuple",
1198
+ components: [
1199
+ { name: "amount", type: "uint256" },
1200
+ { name: "receiver", type: "address" },
1201
+ { name: "token", type: "address" }
1202
+ ]
1203
+ },
1204
+ { name: "user", type: "address" }
1205
+ ]
1206
+ }
1207
+ ],
1208
+ name: "cancelManuallyCreatedOrder",
1209
+ outputs: [],
1210
+ stateMutability: "nonpayable",
1211
+ type: "function"
1212
+ }
1213
+ ],
1214
+ functionName: "cancelManuallyCreatedOrder",
1215
+ args: [
1216
+ {
1217
+ amountIn: BigInt(order.amountIn),
1218
+ tokenIn: order.tokenIn,
1219
+ deadline: BigInt(order.deadline),
1220
+ nonce,
1221
+ encodedExternalCallData: "0x",
1222
+ extraTransfers: (order.extraTransfers || []).map((t) => ({
1223
+ amount: BigInt(t.amount),
1224
+ receiver: t.receiver,
1225
+ token: t.token
1226
+ })),
1227
+ requestedOutput: {
1228
+ amount: BigInt(order.amountOutMin),
1229
+ receiver: order.destinationAddress,
1230
+ token: order.tokenOut
1231
+ },
1232
+ user: order.user
1233
+ }
1234
+ ]
1235
+ }),
1236
+ value: 0n,
1237
+ from: order.user
1238
+ });
1239
+ }
1240
+ const mask = 1n << nonceBitPos;
1241
+ if ((currentBitmap & mask) !== 0n) {
1242
+ throw new Error("Nonce is already invalidated");
1243
+ }
1244
+ return await wallet.sendTransaction({
1245
+ to: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
1246
+ data: (0, import_viem8.encodeFunctionData)({
1247
+ abi: [
1248
+ {
1249
+ inputs: [
1250
+ { name: "wordPos", type: "uint256" },
1251
+ { name: "mask", type: "uint256" }
1252
+ ],
1253
+ name: "invalidateUnorderedNonces",
1254
+ outputs: [],
1255
+ stateMutability: "nonpayable",
1256
+ type: "function"
1257
+ }
1258
+ ],
1259
+ functionName: "invalidateUnorderedNonces",
1260
+ args: [nonceWordPos, mask]
912
1261
  }),
913
- [data, loading, error, warning, fetchQuote]
914
- );
1262
+ value: 0n,
1263
+ from: order.user
1264
+ });
915
1265
  }
916
1266
 
917
- // src/react/useBalances.ts
918
- var import_react4 = require("react");
919
- function useBalances(params) {
920
- const [data, setData] = (0, import_react4.useState)(null);
921
- const [loading, setLoading] = (0, import_react4.useState)(false);
922
- const [error, setError] = (0, import_react4.useState)(null);
923
- const abortRef = (0, import_react4.useRef)(null);
924
- const stableParams = (0, import_react4.useMemo)(() => {
925
- if (!params) return null;
926
- const { addresses, cursorEvm, cursorSvm } = params;
927
- return {
928
- addresses: {
929
- evm: addresses?.evm ?? void 0,
930
- svm: addresses?.svm ?? void 0
931
- },
932
- cursorEvm,
933
- cursorSvm
934
- };
935
- }, [params?.addresses?.evm, params?.addresses?.svm, params?.cursorEvm, params?.cursorSvm]);
936
- const fetchBalances = (0, import_react4.useCallback)(async () => {
937
- if (!stableParams) return;
938
- if (abortRef.current) abortRef.current.abort();
939
- const controller = new AbortController();
940
- abortRef.current = controller;
941
- setLoading(true);
942
- setError(null);
943
- try {
944
- const result = await getBalances(stableParams, { signal: controller.signal });
945
- setData((prev) => {
946
- if (JSON.stringify(prev) === JSON.stringify(result)) return prev;
947
- return result;
948
- });
949
- return result;
950
- } catch (err) {
951
- if (err.name === "AbortError") return;
952
- const e = err instanceof Error ? err : new Error(String(err));
953
- setError(e);
954
- throw e;
955
- } finally {
956
- setLoading(false);
1267
+ // src/core/client.ts
1268
+ var SwapSDK = class {
1269
+ constructor(config) {
1270
+ __publicField(this, "apiKey");
1271
+ /**
1272
+ * Fetches metadata for one or more tokens from the Shogun Token Search API.
1273
+ *
1274
+ * ---
1275
+ * ### Overview
1276
+ * `getTokensData` retrieves normalized token information such as symbol, name,
1277
+ * decimals, logo URI, and verified status — for a given list of token addresses.
1278
+ *
1279
+ * It supports both **EVM** and **SVM (Solana)** tokens, returning metadata from
1280
+ * Shogun’s unified token registry.
1281
+ *
1282
+ * ---
1283
+ * @example
1284
+ * ```ts
1285
+ * const tokens = await getTokensData([
1286
+ * "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
1287
+ * "So11111111111111111111111111111111111111112", // SOL
1288
+ * ]);
1289
+ *
1290
+ * console.log(tokens);
1291
+ * [
1292
+ * { symbol: "USDC", name: "USD Coin", chainId: 1, decimals: 6, ... },
1293
+ * { symbol: "SOL", name: "Solana", chainId: 101, decimals: 9, ... }
1294
+ * ]
1295
+ * ```
1296
+ *
1297
+ * @param addresses - An array of token addresses (EVM or SVM) to fetch metadata for.
1298
+ * @returns A promise resolving to an array of {@link TokenInfo} objects.
1299
+ *
1300
+ * @throws Will throw an error if the network request fails or the API responds with a non-OK status.
1301
+ */
1302
+ __publicField(this, "getTokensData", getTokensData.bind(this));
1303
+ if (!config.apiKey) {
1304
+ throw new Error("SwapSDK: Missing API key");
957
1305
  }
958
- }, [stableParams]);
959
- (0, import_react4.useEffect)(() => {
960
- if (stableParams) fetchBalances().catch(() => {
1306
+ this.apiKey = config.apiKey;
1307
+ if (this.apiKey) void this.apiKey;
1308
+ }
1309
+ /**
1310
+ * Retrieves a swap quote for the given input and output tokens.
1311
+ *
1312
+ * @param params - Quote parameters including source/destination tokens and amount.
1313
+ * @returns A normalized `SwapQuoteResponse` containing output amount, route, and metadata.
1314
+ */
1315
+ async getQuote(params) {
1316
+ return getQuote(params);
1317
+ }
1318
+ /**
1319
+ * Fetches token balances for the specified user wallet(s).
1320
+ *
1321
+ * Supports both EVM and SVM (Solana) wallet addresses.
1322
+ *
1323
+ * @param params - Wallet address and optional chain filters.
1324
+ * @param options - Optional abort signal for cancellation.
1325
+ * @returns A unified balance response with per-chain token details.
1326
+ */
1327
+ async getBalances(params, options) {
1328
+ return getBalances(params, options);
1329
+ }
1330
+ /**
1331
+ * Retrieves a list of verified tokens based on search query or chain filter.
1332
+ *
1333
+ * @param params - Search parameters (query, chain ID, pagination options).
1334
+ * @returns Paginated `TokenSearchResponse` containing token metadata.
1335
+ */
1336
+ async getTokenList(params) {
1337
+ return getTokenList(params);
1338
+ }
1339
+ /**
1340
+ * Executes a prepared swap quote using the provided wallet and configuration.
1341
+ *
1342
+ * Handles:
1343
+ * - Token approval (if required)
1344
+ * - Transaction signing and broadcasting
1345
+ * - Confirmation polling and stage-based status updates
1346
+ *
1347
+ * Supports both:
1348
+ * - Market orders (with optional deadline)
1349
+ * - Limit orders (requires executionPrice and deadline)
1350
+ *
1351
+ * @param quote - The swap quote to execute, containing route and metadata.
1352
+ * @param accountAddress - The user's wallet address executing the swap.
1353
+ * @param recipientAddress - Optional recipient address for the output tokens (defaults to sender).
1354
+ * @param wallet - Adapted wallet instance (EVM/Solana) or a standard Viem `WalletClient`.
1355
+ * @param onStatus - Optional callback for receiving execution stage updates and messages.
1356
+ * @param orderType - Defines whether this is a market or limit order.
1357
+ * @param options - Execution parameters (different per order type).
1358
+ *
1359
+ * @returns A finalized execution result containing transaction hash, status, and any returned data.
1360
+ *
1361
+ * @example
1362
+ * ```ts
1363
+ * * Market order
1364
+ * const result = await sdk.executeTransaction({
1365
+ * quote,
1366
+ * accountAddress: "0x123...",
1367
+ * wallet,
1368
+ * orderType: OrderExecutionType.MARKET,
1369
+ * options: { deadline: 1800 },
1370
+ * onStatus: (stage, msg) => console.log(stage, msg),
1371
+ * });
1372
+ *
1373
+ * * Limit order
1374
+ * const result = await sdk.executeTransaction({
1375
+ * quote,
1376
+ * accountAddress: "0x123...",
1377
+ * wallet,
1378
+ * orderType: OrderExecutionType.LIMIT,
1379
+ * options: { executionPrice: "0.0021", deadline: 3600 },
1380
+ * });
1381
+ * ```
1382
+ */
1383
+ async executeTransaction({
1384
+ quote,
1385
+ accountAddress,
1386
+ recipientAddress,
1387
+ wallet,
1388
+ onStatus,
1389
+ orderType,
1390
+ options
1391
+ }) {
1392
+ return executeOrder({
1393
+ quote,
1394
+ wallet,
1395
+ accountAddress,
1396
+ recipientAddress,
1397
+ onStatus,
1398
+ orderType,
1399
+ options
961
1400
  });
962
- return () => {
963
- if (abortRef.current) abortRef.current.abort();
964
- };
965
- }, [fetchBalances]);
966
- return (0, import_react4.useMemo)(
967
- () => ({
968
- /** Latest fetched balance data */
969
- data,
970
- /** Whether the hook is currently fetching */
971
- loading,
972
- /** Error object if fetching failed */
973
- error,
974
- /** Manually trigger a refresh */
975
- refetch: fetchBalances
976
- }),
977
- [data, loading, error, fetchBalances]
978
- );
979
- }
980
- // Annotate the CommonJS export names for ESM import in node:
981
- 0 && (module.exports = {
982
- NATIVE_TOKEN,
983
- SOLANA_CHAIN_ID,
984
- SupportedChains,
985
- adaptEthersSigner,
986
- adaptSolanaWallet,
987
- adaptViemWallet,
988
- buildQuoteParams,
989
- executeOrder,
990
- getBalances,
991
- getQuote,
992
- getTokenList,
993
- isNativeAddress,
994
- isViemWalletClient,
995
- serializeBigIntsToStrings,
996
- useBalances,
997
- useExecuteOrder,
998
- useQuote,
999
- useTokenList
1000
- });
1401
+ }
1402
+ /**
1403
+ * Fetches all user orders (Market, Limit, Cross-chain) for connected wallets.
1404
+ *
1405
+ * ---
1406
+ * ### Overview
1407
+ * Retrieves both **single-chain** and **cross-chain** orders from the Shogun Intents API.
1408
+ * Works across EVM, Solana
1409
+ *
1410
+ * ---
1411
+ * @example
1412
+ * ```ts
1413
+ * const orders = await sdk.getOrders({
1414
+ * evmAddress: "0x123...",
1415
+ * solAddress: "9d12hF...abc",
1416
+ * });
1417
+ *
1418
+ * console.log(orders.singleChainLimitOrders);
1419
+ * ```
1420
+ *
1421
+ * @param params - Wallet addresses to fetch orders for (EVM, Solana).
1422
+ * @returns A structured {@link ApiUserOrders} object containing all user orders.
1423
+ */
1424
+ async getOrders(params) {
1425
+ return getOrders(params);
1426
+ }
1427
+ /**
1428
+ * Cancels an order (single-chain or cross-chain) on EVM or Solana.
1429
+ *
1430
+ * Internally routes to the correct guard contract or Solana program to
1431
+ * deactivate the order or invalidate its nonce.
1432
+ *
1433
+ * @param params.order - Order payload returned from the Intents API.
1434
+ * @param params.wallet - Adapted wallet used to submit the cancellation transaction.
1435
+ * @param params.solRpc - Solana RPC URL used for SVM cancellations.
1436
+ *
1437
+ * @returns A transaction signature or hash from the underlying wallet.
1438
+ */
1439
+ async cancelOrder(params) {
1440
+ return cancelIntentsOrder({
1441
+ order: params.order,
1442
+ wallet: params.wallet,
1443
+ sol_rpc: params.solRpc
1444
+ });
1445
+ }
1446
+ };