@shogun-sdk/swap 0.0.2-test.22 → 0.0.2-test.24
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 +82 -41
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +73 -16
- package/dist/{execute-CKTsf_tD.d.ts → execute-D2qcOzkI.d.ts} +1 -1
- package/dist/{execute-DOv1i2Su.d.cts → execute-Xvw4wXBo.d.cts} +1 -1
- package/dist/index.cjs +96 -44
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +90 -17
- package/dist/react.cjs +87 -39
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +73 -16
- package/dist/{wallet-MmUIz8GE.d.cts → wallet-BhuMJ3K_.d.cts} +2 -1
- package/dist/{wallet-MmUIz8GE.d.ts → wallet-BhuMJ3K_.d.ts} +2 -1
- package/dist/wallet-adapter.cjs +33 -8
- package/dist/wallet-adapter.d.cts +1 -1
- package/dist/wallet-adapter.d.ts +1 -1
- package/dist/wallet-adapter.js +36 -4
- package/package.json +2 -2
package/dist/core.cjs
CHANGED
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/core/index.ts
|
|
21
21
|
var core_exports = {};
|
|
22
22
|
__export(core_exports, {
|
|
23
|
-
ChainID: () =>
|
|
23
|
+
ChainID: () => import_intents_sdk12.ChainID,
|
|
24
24
|
NATIVE_TOKEN: () => NATIVE_TOKEN,
|
|
25
25
|
SOLANA_CHAIN_ID: () => SOLANA_CHAIN_ID,
|
|
26
26
|
SupportedChains: () => SupportedChains,
|
|
@@ -29,7 +29,7 @@ __export(core_exports, {
|
|
|
29
29
|
getBalances: () => getBalances,
|
|
30
30
|
getQuote: () => getQuote,
|
|
31
31
|
getTokenList: () => getTokenList,
|
|
32
|
-
isEvmChain: () =>
|
|
32
|
+
isEvmChain: () => import_intents_sdk12.isEvmChain,
|
|
33
33
|
isNativeAddress: () => isNativeAddress,
|
|
34
34
|
isViemWalletClient: () => isViemWalletClient,
|
|
35
35
|
serializeBigIntsToStrings: () => serializeBigIntsToStrings
|
|
@@ -285,8 +285,8 @@ async function getBalances(params, options) {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// src/core/executeOrder/execute.ts
|
|
288
|
-
var
|
|
289
|
-
var
|
|
288
|
+
var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
|
|
289
|
+
var import_viem5 = require("viem");
|
|
290
290
|
|
|
291
291
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
292
292
|
var import_ethers = require("ethers/lib/ethers.js");
|
|
@@ -351,6 +351,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
351
351
|
if (!addr) throw new Error("No address found");
|
|
352
352
|
return addr;
|
|
353
353
|
};
|
|
354
|
+
const readContract = async ({
|
|
355
|
+
address: address2,
|
|
356
|
+
abi,
|
|
357
|
+
functionName,
|
|
358
|
+
args = []
|
|
359
|
+
}) => {
|
|
360
|
+
const publicClient = wallet.extend(import_viem2.publicActions);
|
|
361
|
+
return await publicClient.readContract({
|
|
362
|
+
address: address2,
|
|
363
|
+
abi,
|
|
364
|
+
functionName,
|
|
365
|
+
args
|
|
366
|
+
});
|
|
367
|
+
};
|
|
354
368
|
return {
|
|
355
369
|
vmType: "EVM" /* EVM */,
|
|
356
370
|
transport: (0, import_viem2.custom)(wallet.transport),
|
|
@@ -358,13 +372,14 @@ var adaptViemWallet = (wallet) => {
|
|
|
358
372
|
address,
|
|
359
373
|
sendTransaction,
|
|
360
374
|
signTypedData,
|
|
361
|
-
switchChain
|
|
375
|
+
switchChain,
|
|
376
|
+
readContract
|
|
362
377
|
};
|
|
363
378
|
};
|
|
364
379
|
|
|
365
380
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
366
|
-
var
|
|
367
|
-
var
|
|
381
|
+
var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
|
|
382
|
+
var import_viem4 = require("viem");
|
|
368
383
|
|
|
369
384
|
// src/core/executeOrder/stageMessages.ts
|
|
370
385
|
var DEFAULT_STAGE_MESSAGES = {
|
|
@@ -519,6 +534,51 @@ async function handleOrderPollingResult({
|
|
|
519
534
|
};
|
|
520
535
|
}
|
|
521
536
|
|
|
537
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
538
|
+
var import_viem3 = require("viem");
|
|
539
|
+
var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
|
|
540
|
+
async function ensurePermit2Allowance({
|
|
541
|
+
chainId,
|
|
542
|
+
tokenIn,
|
|
543
|
+
wallet,
|
|
544
|
+
accountAddress,
|
|
545
|
+
requiredAmount,
|
|
546
|
+
increaseByDelta = false
|
|
547
|
+
}) {
|
|
548
|
+
const spender = import_intents_sdk8.PERMIT2_ADDRESS[chainId];
|
|
549
|
+
let currentAllowance = 0n;
|
|
550
|
+
try {
|
|
551
|
+
if (!wallet.readContract) {
|
|
552
|
+
throw new Error("Wallet does not implement readContract()");
|
|
553
|
+
}
|
|
554
|
+
currentAllowance = await wallet.readContract({
|
|
555
|
+
address: tokenIn,
|
|
556
|
+
abi: import_viem3.erc20Abi,
|
|
557
|
+
functionName: "allowance",
|
|
558
|
+
args: [accountAddress, spender]
|
|
559
|
+
});
|
|
560
|
+
} catch (error) {
|
|
561
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
562
|
+
}
|
|
563
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem3.maxUint256;
|
|
564
|
+
console.debug(
|
|
565
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
566
|
+
);
|
|
567
|
+
await wallet.sendTransaction({
|
|
568
|
+
to: tokenIn,
|
|
569
|
+
from: accountAddress,
|
|
570
|
+
data: (0, import_viem3.encodeFunctionData)({
|
|
571
|
+
abi: import_viem3.erc20Abi,
|
|
572
|
+
functionName: "approve",
|
|
573
|
+
args: [spender, approvalAmount]
|
|
574
|
+
}),
|
|
575
|
+
value: 0n
|
|
576
|
+
});
|
|
577
|
+
console.info(
|
|
578
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
|
|
522
582
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
523
583
|
async function handleEvmExecution({
|
|
524
584
|
recipientAddress,
|
|
@@ -538,7 +598,7 @@ async function handleEvmExecution({
|
|
|
538
598
|
if (shouldWrapNative) {
|
|
539
599
|
await wallet.sendTransaction({
|
|
540
600
|
to: tokenIn,
|
|
541
|
-
data: (0,
|
|
601
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
542
602
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
543
603
|
functionName: "deposit",
|
|
544
604
|
args: []
|
|
@@ -548,15 +608,12 @@ async function handleEvmExecution({
|
|
|
548
608
|
});
|
|
549
609
|
}
|
|
550
610
|
update("processing", messageFor("approving"));
|
|
551
|
-
await
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}),
|
|
558
|
-
value: 0n,
|
|
559
|
-
from: accountAddress
|
|
611
|
+
await ensurePermit2Allowance({
|
|
612
|
+
chainId,
|
|
613
|
+
tokenIn,
|
|
614
|
+
wallet,
|
|
615
|
+
accountAddress,
|
|
616
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
560
617
|
});
|
|
561
618
|
update("processing", messageFor("approved"));
|
|
562
619
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -569,7 +626,7 @@ async function handleEvmExecution({
|
|
|
569
626
|
});
|
|
570
627
|
console.debug(`order`, order);
|
|
571
628
|
update("processing", messageFor("signing"));
|
|
572
|
-
const { orderTypedData, nonce } = isSingleChain ? await (0,
|
|
629
|
+
const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk9.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk9.getEVMCrossChainOrderTypedData)(order);
|
|
573
630
|
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
574
631
|
if (!wallet.signTypedData) {
|
|
575
632
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
@@ -600,7 +657,7 @@ async function handleEvmExecution({
|
|
|
600
657
|
}
|
|
601
658
|
|
|
602
659
|
// src/core/executeOrder/handleSolanaExecution.ts
|
|
603
|
-
var
|
|
660
|
+
var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
|
|
604
661
|
var import_web3 = require("@solana/web3.js");
|
|
605
662
|
async function handleSolanaExecution({
|
|
606
663
|
recipientAddress,
|
|
@@ -659,11 +716,11 @@ async function getSolanaOrderInstructions({
|
|
|
659
716
|
rpcUrl
|
|
660
717
|
}) {
|
|
661
718
|
if (isSingleChain) {
|
|
662
|
-
return await (0,
|
|
719
|
+
return await (0, import_intents_sdk10.getSolanaSingleChainOrderInstructions)(order, {
|
|
663
720
|
rpcUrl
|
|
664
721
|
});
|
|
665
722
|
}
|
|
666
|
-
return await (0,
|
|
723
|
+
return await (0, import_intents_sdk10.getSolanaCrossChainOrderInstructions)(order, {
|
|
667
724
|
rpcUrl
|
|
668
725
|
});
|
|
669
726
|
}
|
|
@@ -717,7 +774,7 @@ async function executeOrder({
|
|
|
717
774
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
718
775
|
const chainId = Number(tokenIn.chainId);
|
|
719
776
|
update("processing");
|
|
720
|
-
if ((0,
|
|
777
|
+
if ((0, import_intents_sdk11.isEvmChain)(chainId)) {
|
|
721
778
|
log("Detected EVM chain:", chainId);
|
|
722
779
|
const result = await handleEvmExecution({
|
|
723
780
|
recipientAddress,
|
|
@@ -732,7 +789,7 @@ async function executeOrder({
|
|
|
732
789
|
log("EVM execution result:", result);
|
|
733
790
|
return result;
|
|
734
791
|
}
|
|
735
|
-
if (chainId ===
|
|
792
|
+
if (chainId === import_intents_sdk11.ChainID.Solana) {
|
|
736
793
|
log("Detected Solana chain");
|
|
737
794
|
const result = await handleSolanaExecution({
|
|
738
795
|
recipientAddress,
|
|
@@ -751,7 +808,7 @@ async function executeOrder({
|
|
|
751
808
|
log("Error:", unsupported);
|
|
752
809
|
return { status: false, message: unsupported, stage: "error" };
|
|
753
810
|
} catch (error) {
|
|
754
|
-
const message = error instanceof
|
|
811
|
+
const message = error instanceof import_viem5.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
|
|
755
812
|
log("Execution failed:", { message, error });
|
|
756
813
|
update("error", message);
|
|
757
814
|
return { status: false, message, stage: "error" };
|
|
@@ -764,20 +821,4 @@ function normalizeWallet(wallet) {
|
|
|
764
821
|
}
|
|
765
822
|
|
|
766
823
|
// src/core/index.ts
|
|
767
|
-
var
|
|
768
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
769
|
-
0 && (module.exports = {
|
|
770
|
-
ChainID,
|
|
771
|
-
NATIVE_TOKEN,
|
|
772
|
-
SOLANA_CHAIN_ID,
|
|
773
|
-
SupportedChains,
|
|
774
|
-
buildQuoteParams,
|
|
775
|
-
executeOrder,
|
|
776
|
-
getBalances,
|
|
777
|
-
getQuote,
|
|
778
|
-
getTokenList,
|
|
779
|
-
isEvmChain,
|
|
780
|
-
isNativeAddress,
|
|
781
|
-
isViemWalletClient,
|
|
782
|
-
serializeBigIntsToStrings
|
|
783
|
-
});
|
|
824
|
+
var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
|
package/dist/core.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TokenSearchParams, TokenSearchResponse, ChainID } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
3
|
-
import { S as SwapQuoteParams, a as SwapQuoteResponse, Q as QuoteTokenInfo, B as BalanceRequestParams, c as BalanceResponse } from './execute-
|
|
4
|
-
export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-
|
|
3
|
+
import { S as SwapQuoteParams, a as SwapQuoteResponse, Q as QuoteTokenInfo, B as BalanceRequestParams, c as BalanceResponse } from './execute-Xvw4wXBo.cjs';
|
|
4
|
+
export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-Xvw4wXBo.cjs';
|
|
5
5
|
import { WalletClient } from 'viem';
|
|
6
|
-
import { A as AdaptedWallet } from './wallet-
|
|
6
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
|
|
7
7
|
import '@mysten/sui/transactions';
|
|
8
8
|
import '@solana/web3.js';
|
|
9
9
|
|
package/dist/core.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TokenSearchParams, TokenSearchResponse, ChainID } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
3
|
-
import { S as SwapQuoteParams, a as SwapQuoteResponse, Q as QuoteTokenInfo, B as BalanceRequestParams, c as BalanceResponse } from './execute-
|
|
4
|
-
export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-
|
|
3
|
+
import { S as SwapQuoteParams, a as SwapQuoteResponse, Q as QuoteTokenInfo, B as BalanceRequestParams, c as BalanceResponse } from './execute-D2qcOzkI.js';
|
|
4
|
+
export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-D2qcOzkI.js';
|
|
5
5
|
import { WalletClient } from 'viem';
|
|
6
|
-
import { A as AdaptedWallet } from './wallet-
|
|
6
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
|
|
7
7
|
import '@mysten/sui/transactions';
|
|
8
8
|
import '@solana/web3.js';
|
|
9
9
|
|
package/dist/core.js
CHANGED
|
@@ -251,10 +251,11 @@ import { ChainID as ChainID3, isEvmChain as isEvmChain2 } from "@shogun-sdk/inte
|
|
|
251
251
|
import { BaseError } from "viem";
|
|
252
252
|
|
|
253
253
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
254
|
-
import "ethers/lib/ethers.js";
|
|
254
|
+
import { utils as ethersUtils } from "ethers/lib/ethers.js";
|
|
255
255
|
import { hexValue } from "ethers/lib/utils.js";
|
|
256
256
|
import {
|
|
257
|
-
custom
|
|
257
|
+
custom,
|
|
258
|
+
publicActions
|
|
258
259
|
} from "viem";
|
|
259
260
|
function isEVMTransaction(tx) {
|
|
260
261
|
return typeof tx.from === "string";
|
|
@@ -315,6 +316,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
315
316
|
if (!addr) throw new Error("No address found");
|
|
316
317
|
return addr;
|
|
317
318
|
};
|
|
319
|
+
const readContract = async ({
|
|
320
|
+
address: address2,
|
|
321
|
+
abi,
|
|
322
|
+
functionName,
|
|
323
|
+
args = []
|
|
324
|
+
}) => {
|
|
325
|
+
const publicClient = wallet.extend(publicActions);
|
|
326
|
+
return await publicClient.readContract({
|
|
327
|
+
address: address2,
|
|
328
|
+
abi,
|
|
329
|
+
functionName,
|
|
330
|
+
args
|
|
331
|
+
});
|
|
332
|
+
};
|
|
318
333
|
return {
|
|
319
334
|
vmType: "EVM" /* EVM */,
|
|
320
335
|
transport: custom(wallet.transport),
|
|
@@ -322,17 +337,17 @@ var adaptViemWallet = (wallet) => {
|
|
|
322
337
|
address,
|
|
323
338
|
sendTransaction,
|
|
324
339
|
signTypedData,
|
|
325
|
-
switchChain
|
|
340
|
+
switchChain,
|
|
341
|
+
readContract
|
|
326
342
|
};
|
|
327
343
|
};
|
|
328
344
|
|
|
329
345
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
330
346
|
import {
|
|
331
347
|
getEVMSingleChainOrderTypedData,
|
|
332
|
-
getEVMCrossChainOrderTypedData
|
|
333
|
-
PERMIT2_ADDRESS
|
|
348
|
+
getEVMCrossChainOrderTypedData
|
|
334
349
|
} from "@shogun-sdk/intents-sdk";
|
|
335
|
-
import { encodeFunctionData
|
|
350
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
336
351
|
|
|
337
352
|
// src/core/executeOrder/stageMessages.ts
|
|
338
353
|
var DEFAULT_STAGE_MESSAGES = {
|
|
@@ -487,6 +502,51 @@ async function handleOrderPollingResult({
|
|
|
487
502
|
};
|
|
488
503
|
}
|
|
489
504
|
|
|
505
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
506
|
+
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
507
|
+
import { PERMIT2_ADDRESS } from "@shogun-sdk/intents-sdk";
|
|
508
|
+
async function ensurePermit2Allowance({
|
|
509
|
+
chainId,
|
|
510
|
+
tokenIn,
|
|
511
|
+
wallet,
|
|
512
|
+
accountAddress,
|
|
513
|
+
requiredAmount,
|
|
514
|
+
increaseByDelta = false
|
|
515
|
+
}) {
|
|
516
|
+
const spender = PERMIT2_ADDRESS[chainId];
|
|
517
|
+
let currentAllowance = 0n;
|
|
518
|
+
try {
|
|
519
|
+
if (!wallet.readContract) {
|
|
520
|
+
throw new Error("Wallet does not implement readContract()");
|
|
521
|
+
}
|
|
522
|
+
currentAllowance = await wallet.readContract({
|
|
523
|
+
address: tokenIn,
|
|
524
|
+
abi: erc20Abi,
|
|
525
|
+
functionName: "allowance",
|
|
526
|
+
args: [accountAddress, spender]
|
|
527
|
+
});
|
|
528
|
+
} catch (error) {
|
|
529
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
530
|
+
}
|
|
531
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : maxUint256;
|
|
532
|
+
console.debug(
|
|
533
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
534
|
+
);
|
|
535
|
+
await wallet.sendTransaction({
|
|
536
|
+
to: tokenIn,
|
|
537
|
+
from: accountAddress,
|
|
538
|
+
data: encodeFunctionData({
|
|
539
|
+
abi: erc20Abi,
|
|
540
|
+
functionName: "approve",
|
|
541
|
+
args: [spender, approvalAmount]
|
|
542
|
+
}),
|
|
543
|
+
value: 0n
|
|
544
|
+
});
|
|
545
|
+
console.info(
|
|
546
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
490
550
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
491
551
|
async function handleEvmExecution({
|
|
492
552
|
recipientAddress,
|
|
@@ -506,7 +566,7 @@ async function handleEvmExecution({
|
|
|
506
566
|
if (shouldWrapNative) {
|
|
507
567
|
await wallet.sendTransaction({
|
|
508
568
|
to: tokenIn,
|
|
509
|
-
data:
|
|
569
|
+
data: encodeFunctionData2({
|
|
510
570
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
511
571
|
functionName: "deposit",
|
|
512
572
|
args: []
|
|
@@ -516,15 +576,12 @@ async function handleEvmExecution({
|
|
|
516
576
|
});
|
|
517
577
|
}
|
|
518
578
|
update("processing", messageFor("approving"));
|
|
519
|
-
await
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}),
|
|
526
|
-
value: 0n,
|
|
527
|
-
from: accountAddress
|
|
579
|
+
await ensurePermit2Allowance({
|
|
580
|
+
chainId,
|
|
581
|
+
tokenIn,
|
|
582
|
+
wallet,
|
|
583
|
+
accountAddress,
|
|
584
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
528
585
|
});
|
|
529
586
|
update("processing", messageFor("approved"));
|
|
530
587
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
-
import { A as AdaptedWallet } from './wallet-
|
|
3
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Token metadata used in quotes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
-
import { A as AdaptedWallet } from './wallet-
|
|
3
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Token metadata used in quotes.
|
package/dist/index.cjs
CHANGED
|
@@ -290,8 +290,8 @@ async function getBalances(params, options) {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
// src/core/executeOrder/execute.ts
|
|
293
|
-
var
|
|
294
|
-
var
|
|
293
|
+
var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
|
|
294
|
+
var import_viem5 = require("viem");
|
|
295
295
|
|
|
296
296
|
// src/wallet-adapter/svm-wallet-adapter/adapter.ts
|
|
297
297
|
var import_web3 = require("@solana/web3.js");
|
|
@@ -369,6 +369,21 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
369
369
|
throw error;
|
|
370
370
|
}
|
|
371
371
|
};
|
|
372
|
+
const readContract = async ({
|
|
373
|
+
address,
|
|
374
|
+
abi,
|
|
375
|
+
functionName,
|
|
376
|
+
args = []
|
|
377
|
+
}) => {
|
|
378
|
+
const iface = new import_ethers.utils.Interface(abi);
|
|
379
|
+
const fnArgs = Array.isArray(args) ? args : [];
|
|
380
|
+
const data = iface.encodeFunctionData(functionName, fnArgs);
|
|
381
|
+
const provider = signer.provider;
|
|
382
|
+
if (!provider) throw new Error("Signer has no provider");
|
|
383
|
+
const result = await provider.call({ to: address, data });
|
|
384
|
+
const decoded = iface.decodeFunctionResult(functionName, result);
|
|
385
|
+
return decoded[0];
|
|
386
|
+
};
|
|
372
387
|
return {
|
|
373
388
|
vmType: "EVM" /* EVM */,
|
|
374
389
|
transport,
|
|
@@ -376,7 +391,8 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
376
391
|
address: async () => signer.getAddress(),
|
|
377
392
|
sendTransaction,
|
|
378
393
|
signTypedData,
|
|
379
|
-
switchChain
|
|
394
|
+
switchChain,
|
|
395
|
+
readContract
|
|
380
396
|
};
|
|
381
397
|
};
|
|
382
398
|
var adaptViemWallet = (wallet) => {
|
|
@@ -435,6 +451,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
435
451
|
if (!addr) throw new Error("No address found");
|
|
436
452
|
return addr;
|
|
437
453
|
};
|
|
454
|
+
const readContract = async ({
|
|
455
|
+
address: address2,
|
|
456
|
+
abi,
|
|
457
|
+
functionName,
|
|
458
|
+
args = []
|
|
459
|
+
}) => {
|
|
460
|
+
const publicClient = wallet.extend(import_viem2.publicActions);
|
|
461
|
+
return await publicClient.readContract({
|
|
462
|
+
address: address2,
|
|
463
|
+
abi,
|
|
464
|
+
functionName,
|
|
465
|
+
args
|
|
466
|
+
});
|
|
467
|
+
};
|
|
438
468
|
return {
|
|
439
469
|
vmType: "EVM" /* EVM */,
|
|
440
470
|
transport: (0, import_viem2.custom)(wallet.transport),
|
|
@@ -442,13 +472,14 @@ var adaptViemWallet = (wallet) => {
|
|
|
442
472
|
address,
|
|
443
473
|
sendTransaction,
|
|
444
474
|
signTypedData,
|
|
445
|
-
switchChain
|
|
475
|
+
switchChain,
|
|
476
|
+
readContract
|
|
446
477
|
};
|
|
447
478
|
};
|
|
448
479
|
|
|
449
480
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
450
|
-
var
|
|
451
|
-
var
|
|
481
|
+
var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
|
|
482
|
+
var import_viem4 = require("viem");
|
|
452
483
|
|
|
453
484
|
// src/core/executeOrder/stageMessages.ts
|
|
454
485
|
var DEFAULT_STAGE_MESSAGES = {
|
|
@@ -603,6 +634,51 @@ async function handleOrderPollingResult({
|
|
|
603
634
|
};
|
|
604
635
|
}
|
|
605
636
|
|
|
637
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
638
|
+
var import_viem3 = require("viem");
|
|
639
|
+
var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
|
|
640
|
+
async function ensurePermit2Allowance({
|
|
641
|
+
chainId,
|
|
642
|
+
tokenIn,
|
|
643
|
+
wallet,
|
|
644
|
+
accountAddress,
|
|
645
|
+
requiredAmount,
|
|
646
|
+
increaseByDelta = false
|
|
647
|
+
}) {
|
|
648
|
+
const spender = import_intents_sdk8.PERMIT2_ADDRESS[chainId];
|
|
649
|
+
let currentAllowance = 0n;
|
|
650
|
+
try {
|
|
651
|
+
if (!wallet.readContract) {
|
|
652
|
+
throw new Error("Wallet does not implement readContract()");
|
|
653
|
+
}
|
|
654
|
+
currentAllowance = await wallet.readContract({
|
|
655
|
+
address: tokenIn,
|
|
656
|
+
abi: import_viem3.erc20Abi,
|
|
657
|
+
functionName: "allowance",
|
|
658
|
+
args: [accountAddress, spender]
|
|
659
|
+
});
|
|
660
|
+
} catch (error) {
|
|
661
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
662
|
+
}
|
|
663
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem3.maxUint256;
|
|
664
|
+
console.debug(
|
|
665
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
666
|
+
);
|
|
667
|
+
await wallet.sendTransaction({
|
|
668
|
+
to: tokenIn,
|
|
669
|
+
from: accountAddress,
|
|
670
|
+
data: (0, import_viem3.encodeFunctionData)({
|
|
671
|
+
abi: import_viem3.erc20Abi,
|
|
672
|
+
functionName: "approve",
|
|
673
|
+
args: [spender, approvalAmount]
|
|
674
|
+
}),
|
|
675
|
+
value: 0n
|
|
676
|
+
});
|
|
677
|
+
console.info(
|
|
678
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
|
|
606
682
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
607
683
|
async function handleEvmExecution({
|
|
608
684
|
recipientAddress,
|
|
@@ -622,7 +698,7 @@ async function handleEvmExecution({
|
|
|
622
698
|
if (shouldWrapNative) {
|
|
623
699
|
await wallet.sendTransaction({
|
|
624
700
|
to: tokenIn,
|
|
625
|
-
data: (0,
|
|
701
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
626
702
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
627
703
|
functionName: "deposit",
|
|
628
704
|
args: []
|
|
@@ -632,15 +708,12 @@ async function handleEvmExecution({
|
|
|
632
708
|
});
|
|
633
709
|
}
|
|
634
710
|
update("processing", messageFor("approving"));
|
|
635
|
-
await
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}),
|
|
642
|
-
value: 0n,
|
|
643
|
-
from: accountAddress
|
|
711
|
+
await ensurePermit2Allowance({
|
|
712
|
+
chainId,
|
|
713
|
+
tokenIn,
|
|
714
|
+
wallet,
|
|
715
|
+
accountAddress,
|
|
716
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
644
717
|
});
|
|
645
718
|
update("processing", messageFor("approved"));
|
|
646
719
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -653,7 +726,7 @@ async function handleEvmExecution({
|
|
|
653
726
|
});
|
|
654
727
|
console.debug(`order`, order);
|
|
655
728
|
update("processing", messageFor("signing"));
|
|
656
|
-
const { orderTypedData, nonce } = isSingleChain ? await (0,
|
|
729
|
+
const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk9.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk9.getEVMCrossChainOrderTypedData)(order);
|
|
657
730
|
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
658
731
|
if (!wallet.signTypedData) {
|
|
659
732
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
@@ -684,7 +757,7 @@ async function handleEvmExecution({
|
|
|
684
757
|
}
|
|
685
758
|
|
|
686
759
|
// src/core/executeOrder/handleSolanaExecution.ts
|
|
687
|
-
var
|
|
760
|
+
var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
|
|
688
761
|
var import_web32 = require("@solana/web3.js");
|
|
689
762
|
async function handleSolanaExecution({
|
|
690
763
|
recipientAddress,
|
|
@@ -743,11 +816,11 @@ async function getSolanaOrderInstructions({
|
|
|
743
816
|
rpcUrl
|
|
744
817
|
}) {
|
|
745
818
|
if (isSingleChain) {
|
|
746
|
-
return await (0,
|
|
819
|
+
return await (0, import_intents_sdk10.getSolanaSingleChainOrderInstructions)(order, {
|
|
747
820
|
rpcUrl
|
|
748
821
|
});
|
|
749
822
|
}
|
|
750
|
-
return await (0,
|
|
823
|
+
return await (0, import_intents_sdk10.getSolanaCrossChainOrderInstructions)(order, {
|
|
751
824
|
rpcUrl
|
|
752
825
|
});
|
|
753
826
|
}
|
|
@@ -801,7 +874,7 @@ async function executeOrder({
|
|
|
801
874
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
802
875
|
const chainId = Number(tokenIn.chainId);
|
|
803
876
|
update("processing");
|
|
804
|
-
if ((0,
|
|
877
|
+
if ((0, import_intents_sdk11.isEvmChain)(chainId)) {
|
|
805
878
|
log("Detected EVM chain:", chainId);
|
|
806
879
|
const result = await handleEvmExecution({
|
|
807
880
|
recipientAddress,
|
|
@@ -816,7 +889,7 @@ async function executeOrder({
|
|
|
816
889
|
log("EVM execution result:", result);
|
|
817
890
|
return result;
|
|
818
891
|
}
|
|
819
|
-
if (chainId ===
|
|
892
|
+
if (chainId === import_intents_sdk11.ChainID.Solana) {
|
|
820
893
|
log("Detected Solana chain");
|
|
821
894
|
const result = await handleSolanaExecution({
|
|
822
895
|
recipientAddress,
|
|
@@ -835,7 +908,7 @@ async function executeOrder({
|
|
|
835
908
|
log("Error:", unsupported);
|
|
836
909
|
return { status: false, message: unsupported, stage: "error" };
|
|
837
910
|
} catch (error) {
|
|
838
|
-
const message = error instanceof
|
|
911
|
+
const message = error instanceof import_viem5.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
|
|
839
912
|
log("Execution failed:", { message, error });
|
|
840
913
|
update("error", message);
|
|
841
914
|
return { status: false, message, stage: "error" };
|
|
@@ -1143,24 +1216,3 @@ function useBalances(params) {
|
|
|
1143
1216
|
[data, loading, error, fetchBalances]
|
|
1144
1217
|
);
|
|
1145
1218
|
}
|
|
1146
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1147
|
-
0 && (module.exports = {
|
|
1148
|
-
NATIVE_TOKEN,
|
|
1149
|
-
SOLANA_CHAIN_ID,
|
|
1150
|
-
SupportedChains,
|
|
1151
|
-
adaptEthersSigner,
|
|
1152
|
-
adaptSolanaWallet,
|
|
1153
|
-
adaptViemWallet,
|
|
1154
|
-
buildQuoteParams,
|
|
1155
|
-
executeOrder,
|
|
1156
|
-
getBalances,
|
|
1157
|
-
getQuote,
|
|
1158
|
-
getTokenList,
|
|
1159
|
-
isNativeAddress,
|
|
1160
|
-
isViemWalletClient,
|
|
1161
|
-
serializeBigIntsToStrings,
|
|
1162
|
-
useBalances,
|
|
1163
|
-
useExecuteOrder,
|
|
1164
|
-
useQuote,
|
|
1165
|
-
useTokenList
|
|
1166
|
-
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { NATIVE_TOKEN, SOLANA_CHAIN_ID, SupportedChains, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, serializeBigIntsToStrings } from './core.cjs';
|
|
2
|
-
export { B as BalanceRequestParams, c as BalanceResponse, P as PlaceOrderResult, Q as QuoteTokenInfo, b as Stage, S as SwapQuoteParams, a as SwapQuoteResponse, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-
|
|
2
|
+
export { B as BalanceRequestParams, c as BalanceResponse, P as PlaceOrderResult, Q as QuoteTokenInfo, b as Stage, S as SwapQuoteParams, a as SwapQuoteResponse, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-Xvw4wXBo.cjs';
|
|
3
3
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
4
4
|
export { useBalances, useExecuteOrder, useQuote, useTokenList } from './react.cjs';
|
|
5
5
|
export { adaptEthersSigner, adaptSolanaWallet, adaptViemWallet } from './wallet-adapter.cjs';
|
|
6
6
|
import 'viem';
|
|
7
|
-
import './wallet-
|
|
7
|
+
import './wallet-BhuMJ3K_.cjs';
|
|
8
8
|
import '@mysten/sui/transactions';
|
|
9
9
|
import '@solana/web3.js';
|
|
10
10
|
import 'ethers/lib/ethers.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { NATIVE_TOKEN, SOLANA_CHAIN_ID, SupportedChains, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, serializeBigIntsToStrings } from './core.js';
|
|
2
|
-
export { B as BalanceRequestParams, c as BalanceResponse, P as PlaceOrderResult, Q as QuoteTokenInfo, b as Stage, S as SwapQuoteParams, a as SwapQuoteResponse, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-
|
|
2
|
+
export { B as BalanceRequestParams, c as BalanceResponse, P as PlaceOrderResult, Q as QuoteTokenInfo, b as Stage, S as SwapQuoteParams, a as SwapQuoteResponse, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-D2qcOzkI.js';
|
|
3
3
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
4
4
|
export { useBalances, useExecuteOrder, useQuote, useTokenList } from './react.js';
|
|
5
5
|
export { adaptEthersSigner, adaptSolanaWallet, adaptViemWallet } from './wallet-adapter.js';
|
|
6
6
|
import 'viem';
|
|
7
|
-
import './wallet-
|
|
7
|
+
import './wallet-BhuMJ3K_.js';
|
|
8
8
|
import '@mysten/sui/transactions';
|
|
9
9
|
import '@solana/web3.js';
|
|
10
10
|
import 'ethers/lib/ethers.js';
|