@shogun-sdk/swap 0.0.2-test.2 → 0.0.2-test.21
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 +226 -62
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +219 -56
- package/dist/{execute-HX1fQ7wG.d.ts → execute-CKTsf_tD.d.ts} +14 -16
- package/dist/{execute-FaLLPp1i.d.cts → execute-DOv1i2Su.d.cts} +14 -16
- package/dist/index.cjs +260 -109
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +254 -104
- package/dist/react.cjs +266 -115
- package/dist/react.d.cts +6 -40
- package/dist/react.d.ts +6 -40
- package/dist/react.js +255 -105
- package/dist/wallet-adapter.cjs +21 -10
- package/dist/wallet-adapter.js +21 -10
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -139,22 +139,25 @@ async function getQuote(params) {
|
|
|
139
139
|
tokenOut: params.tokenOut.address,
|
|
140
140
|
amount: params.amount
|
|
141
141
|
});
|
|
142
|
-
const
|
|
143
|
-
const slippageDecimal = inputSlippage / 100;
|
|
144
|
-
const slippage = Math.min(Math.max(slippageDecimal, 0), 0.5);
|
|
142
|
+
const slippagePercent = Math.min(Math.max(params.slippage ?? 0.5, 0), 50);
|
|
145
143
|
let warning;
|
|
146
|
-
if (
|
|
147
|
-
warning = `\u26A0\uFE0F High slippage tolerance (${
|
|
144
|
+
if (slippagePercent > 10) {
|
|
145
|
+
warning = `\u26A0\uFE0F High slippage tolerance (${slippagePercent.toFixed(2)}%) \u2014 price may vary significantly.`;
|
|
148
146
|
}
|
|
149
|
-
const estimatedAmountOut = BigInt(data.
|
|
150
|
-
const slippageBps = BigInt(Math.round(
|
|
147
|
+
const estimatedAmountOut = BigInt(data.estimatedAmountOut);
|
|
148
|
+
const slippageBps = BigInt(Math.round(slippagePercent * 100));
|
|
151
149
|
const estimatedAmountOutAfterSlippage = estimatedAmountOut * (10000n - slippageBps) / 10000n;
|
|
150
|
+
const pricePerTokenOutInUsd = data.estimatedAmountOutUsd / Number(data.estimatedAmountOut);
|
|
151
|
+
const amountOutUsdAfterSlippage = Number(estimatedAmountOutAfterSlippage) * pricePerTokenOutInUsd;
|
|
152
|
+
const minStablecoinsAmountValue = BigInt(data.estimatedAmountInAsMinStablecoinAmount);
|
|
153
|
+
const minStablecoinsAmountAfterSlippage = minStablecoinsAmountValue * (10000n - slippageBps) / 10000n;
|
|
152
154
|
const pricePerInputToken = estimatedAmountOut * 10n ** BigInt(params.tokenIn.decimals ?? 18) / BigInt(params.amount);
|
|
153
155
|
return {
|
|
154
|
-
amountOut:
|
|
155
|
-
amountOutUsd:
|
|
156
|
+
amountOut: estimatedAmountOutAfterSlippage,
|
|
157
|
+
amountOutUsd: amountOutUsdAfterSlippage,
|
|
156
158
|
amountInUsd: data.amountInUsd,
|
|
157
|
-
|
|
159
|
+
// Input USD stays the same
|
|
160
|
+
minStablecoinsAmount: minStablecoinsAmountAfterSlippage,
|
|
158
161
|
tokenIn: {
|
|
159
162
|
address: params.tokenIn.address,
|
|
160
163
|
decimals: params.tokenIn.decimals ?? 18,
|
|
@@ -167,10 +170,11 @@ async function getQuote(params) {
|
|
|
167
170
|
},
|
|
168
171
|
amountIn: params.amount,
|
|
169
172
|
pricePerInputToken,
|
|
170
|
-
slippage,
|
|
173
|
+
slippage: slippagePercent,
|
|
171
174
|
internal: {
|
|
172
175
|
...data,
|
|
173
|
-
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage
|
|
176
|
+
estimatedAmountOutReduced: estimatedAmountOutAfterSlippage,
|
|
177
|
+
estimatedAmountOutUsdReduced: amountOutUsdAfterSlippage
|
|
174
178
|
},
|
|
175
179
|
warning
|
|
176
180
|
};
|
|
@@ -243,7 +247,7 @@ async function getBalances(params, options) {
|
|
|
243
247
|
}
|
|
244
248
|
|
|
245
249
|
// src/core/executeOrder/execute.ts
|
|
246
|
-
import { ChainID as
|
|
250
|
+
import { ChainID as ChainID3, isEvmChain as isEvmChain2 } from "@shogun-sdk/intents-sdk";
|
|
247
251
|
import { BaseError } from "viem";
|
|
248
252
|
|
|
249
253
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
@@ -269,15 +273,26 @@ var adaptViemWallet = (wallet) => {
|
|
|
269
273
|
if (!isEVMTransaction(transaction)) {
|
|
270
274
|
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
271
275
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
if (wallet.transport.type === "http") {
|
|
277
|
+
const request = await wallet.prepareTransactionRequest({
|
|
278
|
+
to: transaction.to,
|
|
279
|
+
data: transaction.data,
|
|
280
|
+
value: transaction.value,
|
|
281
|
+
chain: wallet.chain
|
|
282
|
+
});
|
|
283
|
+
const serializedTransaction = await wallet.signTransaction(request);
|
|
284
|
+
const tx = await wallet.sendRawTransaction({ serializedTransaction });
|
|
285
|
+
return tx;
|
|
286
|
+
} else {
|
|
287
|
+
const hash = await wallet.sendTransaction({
|
|
288
|
+
to: transaction.to,
|
|
289
|
+
data: transaction.data,
|
|
290
|
+
value: transaction.value,
|
|
291
|
+
chain: wallet.chain,
|
|
292
|
+
account: wallet.account
|
|
293
|
+
});
|
|
294
|
+
return hash;
|
|
295
|
+
}
|
|
281
296
|
};
|
|
282
297
|
const switchChain = async (chainId) => {
|
|
283
298
|
try {
|
|
@@ -324,10 +339,12 @@ var DEFAULT_STAGE_MESSAGES = {
|
|
|
324
339
|
processing: "Preparing transaction for execution",
|
|
325
340
|
approving: "Approving token allowance",
|
|
326
341
|
approved: "Token approved successfully",
|
|
327
|
-
signing: "Signing
|
|
328
|
-
submitting: "Submitting
|
|
329
|
-
|
|
330
|
-
|
|
342
|
+
signing: "Signing transaction for submission",
|
|
343
|
+
submitting: "Submitting transaction",
|
|
344
|
+
initiated: "Transaction initiated.",
|
|
345
|
+
success: "Transaction Executed successfully",
|
|
346
|
+
shogun_processing: "Shogun is processing your transaction",
|
|
347
|
+
error: "Transaction failed during submission"
|
|
331
348
|
};
|
|
332
349
|
|
|
333
350
|
// src/core/executeOrder/buildOrder.ts
|
|
@@ -366,6 +383,110 @@ async function buildOrder({
|
|
|
366
383
|
});
|
|
367
384
|
}
|
|
368
385
|
|
|
386
|
+
// src/utils/pollOrderStatus.ts
|
|
387
|
+
import { AUCTIONEER_URL } from "@shogun-sdk/intents-sdk";
|
|
388
|
+
async function pollOrderStatus(address, orderId, options = {}) {
|
|
389
|
+
const { intervalMs = 2e3, timeoutMs = 3e5 } = options;
|
|
390
|
+
const startTime = Date.now();
|
|
391
|
+
const isDebug = process.env.NODE_ENV !== "production";
|
|
392
|
+
const isEvmAddress = /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
393
|
+
const isSuiAddress = /^0x[a-fA-F0-9]{64}$/.test(address);
|
|
394
|
+
const isSolanaAddress = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
|
|
395
|
+
let queryParam;
|
|
396
|
+
if (isEvmAddress) queryParam = `evmWallets=${address}`;
|
|
397
|
+
else if (isSuiAddress) queryParam = `suiWallets=${address}`;
|
|
398
|
+
else if (isSolanaAddress) queryParam = `solanaWallets=${address}`;
|
|
399
|
+
else throw new Error(`Unrecognized wallet address format: ${address}`);
|
|
400
|
+
const queryUrl = `${AUCTIONEER_URL}/user_intent?${queryParam}`;
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
const pollInterval = setInterval(async () => {
|
|
403
|
+
try {
|
|
404
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
405
|
+
clearInterval(pollInterval);
|
|
406
|
+
return resolve("Timeout");
|
|
407
|
+
}
|
|
408
|
+
const res = await fetch(queryUrl, {
|
|
409
|
+
method: "GET",
|
|
410
|
+
headers: { "Content-Type": "application/json" }
|
|
411
|
+
});
|
|
412
|
+
if (!res.ok) {
|
|
413
|
+
clearInterval(pollInterval);
|
|
414
|
+
return reject(
|
|
415
|
+
new Error(`Failed to fetch orders: ${res.status} ${res.statusText}`)
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
const json = await res.json();
|
|
419
|
+
const data = json?.data ?? {};
|
|
420
|
+
const allOrders = [
|
|
421
|
+
...data.crossChainDcaOrders ?? [],
|
|
422
|
+
...data.crossChainLimitOrders ?? [],
|
|
423
|
+
...data.singleChainDcaOrders ?? [],
|
|
424
|
+
...data.singleChainLimitOrders ?? []
|
|
425
|
+
];
|
|
426
|
+
const targetOrder = allOrders.find((o) => o.orderId === orderId);
|
|
427
|
+
if (!targetOrder) {
|
|
428
|
+
if (isDebug)
|
|
429
|
+
console.debug(`[pollOrderStatus] [${orderId}] Not found yet`);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const { orderStatus } = targetOrder;
|
|
433
|
+
if (isDebug) {
|
|
434
|
+
const elapsed = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
435
|
+
console.debug(`targetOrder`, targetOrder);
|
|
436
|
+
console.debug(
|
|
437
|
+
`[pollOrderStatus] [${orderId}] status=${orderStatus} (elapsed ${elapsed}s)`
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
if (["Fulfilled", "Cancelled", "Outdated"].includes(orderStatus)) {
|
|
441
|
+
clearInterval(pollInterval);
|
|
442
|
+
return resolve(orderStatus);
|
|
443
|
+
}
|
|
444
|
+
} catch (error) {
|
|
445
|
+
clearInterval(pollInterval);
|
|
446
|
+
return reject(error);
|
|
447
|
+
}
|
|
448
|
+
}, intervalMs);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/core/executeOrder/handleOrderPollingResult.ts
|
|
453
|
+
async function handleOrderPollingResult({
|
|
454
|
+
status,
|
|
455
|
+
orderId,
|
|
456
|
+
chainId,
|
|
457
|
+
update,
|
|
458
|
+
messageFor
|
|
459
|
+
}) {
|
|
460
|
+
switch (status) {
|
|
461
|
+
case "Fulfilled":
|
|
462
|
+
update("success", messageFor("success"));
|
|
463
|
+
return {
|
|
464
|
+
status: true,
|
|
465
|
+
orderId,
|
|
466
|
+
chainId,
|
|
467
|
+
finalStatus: status,
|
|
468
|
+
stage: "success"
|
|
469
|
+
};
|
|
470
|
+
case "Cancelled":
|
|
471
|
+
update("error", "Order was cancelled before fulfillment");
|
|
472
|
+
break;
|
|
473
|
+
case "Timeout":
|
|
474
|
+
update("error", "Order polling timed out");
|
|
475
|
+
break;
|
|
476
|
+
case "NotFound":
|
|
477
|
+
default:
|
|
478
|
+
update("error", "Order not found");
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
status: false,
|
|
483
|
+
orderId,
|
|
484
|
+
chainId,
|
|
485
|
+
finalStatus: status,
|
|
486
|
+
stage: "error"
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
369
490
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
370
491
|
async function handleEvmExecution({
|
|
371
492
|
recipientAddress,
|
|
@@ -394,18 +515,18 @@ async function handleEvmExecution({
|
|
|
394
515
|
from: accountAddress
|
|
395
516
|
});
|
|
396
517
|
}
|
|
397
|
-
update("
|
|
518
|
+
update("processing", messageFor("approving"));
|
|
398
519
|
await wallet.sendTransaction({
|
|
399
520
|
to: tokenIn,
|
|
400
521
|
data: encodeFunctionData({
|
|
401
522
|
abi: erc20Abi,
|
|
402
523
|
functionName: "approve",
|
|
403
|
-
args: [PERMIT2_ADDRESS[chainId],
|
|
524
|
+
args: [PERMIT2_ADDRESS[chainId], quote.amountIn]
|
|
404
525
|
}),
|
|
405
526
|
value: 0n,
|
|
406
527
|
from: accountAddress
|
|
407
528
|
});
|
|
408
|
-
update("
|
|
529
|
+
update("processing", messageFor("approved"));
|
|
409
530
|
const destination = recipientAddress ?? accountAddress;
|
|
410
531
|
const order = await buildOrder({
|
|
411
532
|
quote,
|
|
@@ -414,24 +535,40 @@ async function handleEvmExecution({
|
|
|
414
535
|
deadline,
|
|
415
536
|
isSingleChain
|
|
416
537
|
});
|
|
417
|
-
|
|
538
|
+
console.debug(`order`, order);
|
|
539
|
+
update("processing", messageFor("signing"));
|
|
418
540
|
const { orderTypedData, nonce } = isSingleChain ? await getEVMSingleChainOrderTypedData(order) : await getEVMCrossChainOrderTypedData(order);
|
|
541
|
+
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
419
542
|
if (!wallet.signTypedData) {
|
|
420
543
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
421
544
|
}
|
|
422
|
-
const signature = await wallet.signTypedData(
|
|
423
|
-
|
|
545
|
+
const signature = await wallet.signTypedData({
|
|
546
|
+
domain: typedData.domain,
|
|
547
|
+
types: typedData.types,
|
|
548
|
+
primaryType: typedData.primaryType,
|
|
549
|
+
value: typedData.message,
|
|
550
|
+
message: typedData.message
|
|
551
|
+
});
|
|
552
|
+
update("processing", messageFor("submitting"));
|
|
424
553
|
const res = await order.sendToAuctioneer({ signature, nonce: nonce.toString() });
|
|
425
554
|
if (!res.success) {
|
|
426
555
|
throw new Error("Auctioneer submission failed");
|
|
427
556
|
}
|
|
428
|
-
update("
|
|
429
|
-
|
|
557
|
+
update("initiated", messageFor("initiated"));
|
|
558
|
+
const { intentId: orderId } = res.data;
|
|
559
|
+
update("initiated", messageFor("shogun_processing"));
|
|
560
|
+
const status = await pollOrderStatus(accountAddress, orderId);
|
|
561
|
+
return await handleOrderPollingResult({
|
|
562
|
+
status,
|
|
563
|
+
orderId,
|
|
564
|
+
chainId,
|
|
565
|
+
update,
|
|
566
|
+
messageFor
|
|
567
|
+
});
|
|
430
568
|
}
|
|
431
569
|
|
|
432
570
|
// src/core/executeOrder/handleSolanaExecution.ts
|
|
433
571
|
import {
|
|
434
|
-
ChainID as ChainID3,
|
|
435
572
|
getSolanaSingleChainOrderInstructions,
|
|
436
573
|
getSolanaCrossChainOrderInstructions
|
|
437
574
|
} from "@shogun-sdk/intents-sdk";
|
|
@@ -464,10 +601,9 @@ async function handleSolanaExecution({
|
|
|
464
601
|
rpcUrl: wallet.rpcUrl
|
|
465
602
|
});
|
|
466
603
|
const transaction = VersionedTransaction.deserialize(Uint8Array.from(txData.txBytes));
|
|
467
|
-
update("
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
update("submitting", messageFor("submitting"));
|
|
604
|
+
update("processing", messageFor("signing"));
|
|
605
|
+
await wallet.sendTransaction(transaction);
|
|
606
|
+
update("processing", messageFor("submitting"));
|
|
471
607
|
const response = await submitToAuctioneer({
|
|
472
608
|
order,
|
|
473
609
|
isSingleChain,
|
|
@@ -476,13 +612,17 @@ async function handleSolanaExecution({
|
|
|
476
612
|
if (!response.success) {
|
|
477
613
|
throw new Error("Auctioneer submission failed");
|
|
478
614
|
}
|
|
479
|
-
update("
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
615
|
+
update("initiated", messageFor("initiated"));
|
|
616
|
+
const { jwt, intentId: orderId } = response.data;
|
|
617
|
+
update("initiated", messageFor("shogun_processing"));
|
|
618
|
+
const status = await pollOrderStatus(jwt, orderId);
|
|
619
|
+
return await handleOrderPollingResult({
|
|
620
|
+
status,
|
|
621
|
+
orderId,
|
|
622
|
+
chainId: SOLANA_CHAIN_ID,
|
|
623
|
+
update,
|
|
624
|
+
messageFor
|
|
625
|
+
});
|
|
486
626
|
}
|
|
487
627
|
async function getSolanaOrderInstructions({
|
|
488
628
|
order,
|
|
@@ -524,18 +664,33 @@ async function executeOrder({
|
|
|
524
664
|
onStatus,
|
|
525
665
|
options = {}
|
|
526
666
|
}) {
|
|
527
|
-
const
|
|
667
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
668
|
+
const log = (...args) => {
|
|
669
|
+
if (isDev) console.debug("[OneShot::executeOrder]", ...args);
|
|
670
|
+
};
|
|
528
671
|
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
|
|
529
|
-
const update = (stage, message) =>
|
|
672
|
+
const update = (stage, message) => {
|
|
673
|
+
log("Stage:", stage, "| Message:", message ?? messageFor(stage));
|
|
674
|
+
onStatus?.(stage, message ?? messageFor(stage));
|
|
675
|
+
};
|
|
530
676
|
try {
|
|
677
|
+
const deadline = options.deadline ?? Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
678
|
+
log("Starting execution:", {
|
|
679
|
+
accountAddress,
|
|
680
|
+
recipientAddress,
|
|
681
|
+
deadline,
|
|
682
|
+
tokenIn: quote?.tokenIn,
|
|
683
|
+
tokenOut: quote?.tokenOut
|
|
684
|
+
});
|
|
531
685
|
const adapter = normalizeWallet(wallet);
|
|
532
686
|
if (!adapter) throw new Error("No wallet provided");
|
|
533
687
|
const { tokenIn, tokenOut } = quote;
|
|
534
688
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
535
689
|
const chainId = Number(tokenIn.chainId);
|
|
536
|
-
update("processing"
|
|
690
|
+
update("processing");
|
|
537
691
|
if (isEvmChain2(chainId)) {
|
|
538
|
-
|
|
692
|
+
log("Detected EVM chain:", chainId);
|
|
693
|
+
const result = await handleEvmExecution({
|
|
539
694
|
recipientAddress,
|
|
540
695
|
quote,
|
|
541
696
|
chainId,
|
|
@@ -545,9 +700,12 @@ async function executeOrder({
|
|
|
545
700
|
deadline,
|
|
546
701
|
update
|
|
547
702
|
});
|
|
703
|
+
log("EVM execution result:", result);
|
|
704
|
+
return result;
|
|
548
705
|
}
|
|
549
|
-
if (chainId ===
|
|
550
|
-
|
|
706
|
+
if (chainId === ChainID3.Solana) {
|
|
707
|
+
log("Detected Solana chain");
|
|
708
|
+
const result = await handleSolanaExecution({
|
|
551
709
|
recipientAddress,
|
|
552
710
|
quote,
|
|
553
711
|
accountAddress,
|
|
@@ -556,11 +714,16 @@ async function executeOrder({
|
|
|
556
714
|
deadline,
|
|
557
715
|
update
|
|
558
716
|
});
|
|
717
|
+
log("Solana execution result:", result);
|
|
718
|
+
return result;
|
|
559
719
|
}
|
|
560
|
-
|
|
561
|
-
|
|
720
|
+
const unsupported = `Unsupported chain: ${chainId}`;
|
|
721
|
+
update("error", unsupported);
|
|
722
|
+
log("Error:", unsupported);
|
|
723
|
+
return { status: false, message: unsupported, stage: "error" };
|
|
562
724
|
} catch (error) {
|
|
563
725
|
const message = error instanceof BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
|
|
726
|
+
log("Execution failed:", { message, error });
|
|
564
727
|
update("error", message);
|
|
565
728
|
return { status: false, message, stage: "error" };
|
|
566
729
|
}
|
|
@@ -572,9 +735,9 @@ function normalizeWallet(wallet) {
|
|
|
572
735
|
}
|
|
573
736
|
|
|
574
737
|
// src/core/index.ts
|
|
575
|
-
import { ChainID as
|
|
738
|
+
import { ChainID as ChainID4, isEvmChain as isEvmChain3 } from "@shogun-sdk/intents-sdk";
|
|
576
739
|
export {
|
|
577
|
-
|
|
740
|
+
ChainID4 as ChainID,
|
|
578
741
|
NATIVE_TOKEN,
|
|
579
742
|
SOLANA_CHAIN_ID,
|
|
580
743
|
SupportedChains,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainID, QuoteResponse, TokenSearchResponse as TokenSearchResponse$1, TokenInfo as TokenInfo$1 } from '@shogun-sdk/intents-sdk';
|
|
1
|
+
import { ChainID, QuoteResponse, TokenSearchResponse as TokenSearchResponse$1, TokenInfo as TokenInfo$1, ChainOrderStatus } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
import { WalletClient } from 'viem';
|
|
3
3
|
import { A as AdaptedWallet } from './wallet-MmUIz8GE.js';
|
|
4
4
|
|
|
@@ -65,7 +65,7 @@ type SwapQuoteResponse = {
|
|
|
65
65
|
warning?: string;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
type Stage = 'processing' | 'approving' | 'approved' | 'signing' | 'submitting' | 'success' | 'error';
|
|
68
|
+
type Stage = 'processing' | 'approving' | 'approved' | 'signing' | 'submitting' | 'initiated' | 'shogun_processing' | 'success' | 'error';
|
|
69
69
|
type PlaceOrderResult = {
|
|
70
70
|
status: boolean;
|
|
71
71
|
txHash?: string;
|
|
@@ -109,19 +109,17 @@ interface BalanceResponse {
|
|
|
109
109
|
type TokenSearchResponse = TokenSearchResponse$1;
|
|
110
110
|
type TokenInfo = TokenInfo$1;
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Types representing the structure of user orders and polling results.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
type OrderStatus = ChainOrderStatus | "Timeout" | "NotFound";
|
|
117
|
+
type PollResult = OrderStatus;
|
|
118
|
+
|
|
112
119
|
/**
|
|
113
120
|
* Executes a swap order on the correct chain (EVM or Solana).
|
|
114
121
|
*
|
|
115
|
-
*
|
|
116
|
-
* @param accountAddress - The wallet address initiating the swap.
|
|
117
|
-
* @param recipientAddress - recipient for output tokens.
|
|
118
|
-
* @param wallet - Adapted wallet (EVM or Solana).
|
|
119
|
-
* @param onStatus - Optional callback for UI updates.
|
|
120
|
-
* @param options - Optional execution settings.
|
|
121
|
-
* - deadline: UNIX timestamp (seconds)
|
|
122
|
-
* Default = now + 20 minutes
|
|
123
|
-
*
|
|
124
|
-
* @returns Execution result { status, message, stage }
|
|
122
|
+
* Provides detailed logs for debugging when NODE_ENV !== 'production'.
|
|
125
123
|
*/
|
|
126
124
|
declare function executeOrder({ quote, accountAddress, recipientAddress, wallet, onStatus, options, }: {
|
|
127
125
|
quote: SwapQuoteResponse;
|
|
@@ -130,18 +128,18 @@ declare function executeOrder({ quote, accountAddress, recipientAddress, wallet,
|
|
|
130
128
|
wallet: AdaptedWallet | WalletClient;
|
|
131
129
|
onStatus?: (stage: Stage, message?: string) => void;
|
|
132
130
|
options?: {
|
|
133
|
-
/** Optional swap deadline (UNIX seconds). Default: now + 20 minutes */
|
|
134
131
|
deadline?: number;
|
|
135
132
|
};
|
|
136
133
|
}): Promise<{
|
|
137
134
|
status: boolean;
|
|
138
|
-
|
|
135
|
+
orderId: string;
|
|
139
136
|
chainId: number;
|
|
140
|
-
|
|
137
|
+
finalStatus: PollResult;
|
|
138
|
+
stage: Stage;
|
|
141
139
|
} | {
|
|
142
140
|
status: boolean;
|
|
143
141
|
message: string;
|
|
144
142
|
stage: string;
|
|
145
143
|
}>;
|
|
146
144
|
|
|
147
|
-
export { type BalanceRequestParams as B, type PlaceOrderResult as P, type QuoteTokenInfo as Q, type SwapQuoteParams as S, type TokenBalance as T, type SwapQuoteResponse as a, type Stage as b, type BalanceResponse as c, type TokenSearchResponse as d, executeOrder as e, type TokenInfo as f };
|
|
145
|
+
export { type BalanceRequestParams as B, type PlaceOrderResult as P, type QuoteTokenInfo as Q, type SwapQuoteParams as S, type TokenBalance as T, type SwapQuoteResponse as a, type Stage as b, type BalanceResponse as c, type TokenSearchResponse as d, executeOrder as e, type TokenInfo as f, type PollResult as g };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainID, QuoteResponse, TokenSearchResponse as TokenSearchResponse$1, TokenInfo as TokenInfo$1 } from '@shogun-sdk/intents-sdk';
|
|
1
|
+
import { ChainID, QuoteResponse, TokenSearchResponse as TokenSearchResponse$1, TokenInfo as TokenInfo$1, ChainOrderStatus } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
import { WalletClient } from 'viem';
|
|
3
3
|
import { A as AdaptedWallet } from './wallet-MmUIz8GE.cjs';
|
|
4
4
|
|
|
@@ -65,7 +65,7 @@ type SwapQuoteResponse = {
|
|
|
65
65
|
warning?: string;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
type Stage = 'processing' | 'approving' | 'approved' | 'signing' | 'submitting' | 'success' | 'error';
|
|
68
|
+
type Stage = 'processing' | 'approving' | 'approved' | 'signing' | 'submitting' | 'initiated' | 'shogun_processing' | 'success' | 'error';
|
|
69
69
|
type PlaceOrderResult = {
|
|
70
70
|
status: boolean;
|
|
71
71
|
txHash?: string;
|
|
@@ -109,19 +109,17 @@ interface BalanceResponse {
|
|
|
109
109
|
type TokenSearchResponse = TokenSearchResponse$1;
|
|
110
110
|
type TokenInfo = TokenInfo$1;
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Types representing the structure of user orders and polling results.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
type OrderStatus = ChainOrderStatus | "Timeout" | "NotFound";
|
|
117
|
+
type PollResult = OrderStatus;
|
|
118
|
+
|
|
112
119
|
/**
|
|
113
120
|
* Executes a swap order on the correct chain (EVM or Solana).
|
|
114
121
|
*
|
|
115
|
-
*
|
|
116
|
-
* @param accountAddress - The wallet address initiating the swap.
|
|
117
|
-
* @param recipientAddress - recipient for output tokens.
|
|
118
|
-
* @param wallet - Adapted wallet (EVM or Solana).
|
|
119
|
-
* @param onStatus - Optional callback for UI updates.
|
|
120
|
-
* @param options - Optional execution settings.
|
|
121
|
-
* - deadline: UNIX timestamp (seconds)
|
|
122
|
-
* Default = now + 20 minutes
|
|
123
|
-
*
|
|
124
|
-
* @returns Execution result { status, message, stage }
|
|
122
|
+
* Provides detailed logs for debugging when NODE_ENV !== 'production'.
|
|
125
123
|
*/
|
|
126
124
|
declare function executeOrder({ quote, accountAddress, recipientAddress, wallet, onStatus, options, }: {
|
|
127
125
|
quote: SwapQuoteResponse;
|
|
@@ -130,18 +128,18 @@ declare function executeOrder({ quote, accountAddress, recipientAddress, wallet,
|
|
|
130
128
|
wallet: AdaptedWallet | WalletClient;
|
|
131
129
|
onStatus?: (stage: Stage, message?: string) => void;
|
|
132
130
|
options?: {
|
|
133
|
-
/** Optional swap deadline (UNIX seconds). Default: now + 20 minutes */
|
|
134
131
|
deadline?: number;
|
|
135
132
|
};
|
|
136
133
|
}): Promise<{
|
|
137
134
|
status: boolean;
|
|
138
|
-
|
|
135
|
+
orderId: string;
|
|
139
136
|
chainId: number;
|
|
140
|
-
|
|
137
|
+
finalStatus: PollResult;
|
|
138
|
+
stage: Stage;
|
|
141
139
|
} | {
|
|
142
140
|
status: boolean;
|
|
143
141
|
message: string;
|
|
144
142
|
stage: string;
|
|
145
143
|
}>;
|
|
146
144
|
|
|
147
|
-
export { type BalanceRequestParams as B, type PlaceOrderResult as P, type QuoteTokenInfo as Q, type SwapQuoteParams as S, type TokenBalance as T, type SwapQuoteResponse as a, type Stage as b, type BalanceResponse as c, type TokenSearchResponse as d, executeOrder as e, type TokenInfo as f };
|
|
145
|
+
export { type BalanceRequestParams as B, type PlaceOrderResult as P, type QuoteTokenInfo as Q, type SwapQuoteParams as S, type TokenBalance as T, type SwapQuoteResponse as a, type Stage as b, type BalanceResponse as c, type TokenSearchResponse as d, executeOrder as e, type TokenInfo as f, type PollResult as g };
|