@shogun-sdk/swap 0.0.2-test.23 → 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 -25
- 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 -23
- 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 -30
- 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 -2
- 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/index.js
CHANGED
|
@@ -290,10 +290,11 @@ var adaptSolanaWallet = (walletAddress, chainId, rpcUrl, signAndSendTransaction)
|
|
|
290
290
|
};
|
|
291
291
|
|
|
292
292
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
293
|
-
import "ethers/lib/ethers.js";
|
|
293
|
+
import { utils as ethersUtils } from "ethers/lib/ethers.js";
|
|
294
294
|
import { hexValue } from "ethers/lib/utils.js";
|
|
295
295
|
import {
|
|
296
|
-
custom
|
|
296
|
+
custom,
|
|
297
|
+
publicActions
|
|
297
298
|
} from "viem";
|
|
298
299
|
function isEVMTransaction(tx) {
|
|
299
300
|
return typeof tx.from === "string";
|
|
@@ -330,6 +331,21 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
330
331
|
throw error;
|
|
331
332
|
}
|
|
332
333
|
};
|
|
334
|
+
const readContract = async ({
|
|
335
|
+
address,
|
|
336
|
+
abi,
|
|
337
|
+
functionName,
|
|
338
|
+
args = []
|
|
339
|
+
}) => {
|
|
340
|
+
const iface = new ethersUtils.Interface(abi);
|
|
341
|
+
const fnArgs = Array.isArray(args) ? args : [];
|
|
342
|
+
const data = iface.encodeFunctionData(functionName, fnArgs);
|
|
343
|
+
const provider = signer.provider;
|
|
344
|
+
if (!provider) throw new Error("Signer has no provider");
|
|
345
|
+
const result = await provider.call({ to: address, data });
|
|
346
|
+
const decoded = iface.decodeFunctionResult(functionName, result);
|
|
347
|
+
return decoded[0];
|
|
348
|
+
};
|
|
333
349
|
return {
|
|
334
350
|
vmType: "EVM" /* EVM */,
|
|
335
351
|
transport,
|
|
@@ -337,7 +353,8 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
337
353
|
address: async () => signer.getAddress(),
|
|
338
354
|
sendTransaction,
|
|
339
355
|
signTypedData,
|
|
340
|
-
switchChain
|
|
356
|
+
switchChain,
|
|
357
|
+
readContract
|
|
341
358
|
};
|
|
342
359
|
};
|
|
343
360
|
var adaptViemWallet = (wallet) => {
|
|
@@ -396,6 +413,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
396
413
|
if (!addr) throw new Error("No address found");
|
|
397
414
|
return addr;
|
|
398
415
|
};
|
|
416
|
+
const readContract = async ({
|
|
417
|
+
address: address2,
|
|
418
|
+
abi,
|
|
419
|
+
functionName,
|
|
420
|
+
args = []
|
|
421
|
+
}) => {
|
|
422
|
+
const publicClient = wallet.extend(publicActions);
|
|
423
|
+
return await publicClient.readContract({
|
|
424
|
+
address: address2,
|
|
425
|
+
abi,
|
|
426
|
+
functionName,
|
|
427
|
+
args
|
|
428
|
+
});
|
|
429
|
+
};
|
|
399
430
|
return {
|
|
400
431
|
vmType: "EVM" /* EVM */,
|
|
401
432
|
transport: custom(wallet.transport),
|
|
@@ -403,17 +434,17 @@ var adaptViemWallet = (wallet) => {
|
|
|
403
434
|
address,
|
|
404
435
|
sendTransaction,
|
|
405
436
|
signTypedData,
|
|
406
|
-
switchChain
|
|
437
|
+
switchChain,
|
|
438
|
+
readContract
|
|
407
439
|
};
|
|
408
440
|
};
|
|
409
441
|
|
|
410
442
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
411
443
|
import {
|
|
412
444
|
getEVMSingleChainOrderTypedData,
|
|
413
|
-
getEVMCrossChainOrderTypedData
|
|
414
|
-
PERMIT2_ADDRESS
|
|
445
|
+
getEVMCrossChainOrderTypedData
|
|
415
446
|
} from "@shogun-sdk/intents-sdk";
|
|
416
|
-
import { encodeFunctionData
|
|
447
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
417
448
|
|
|
418
449
|
// src/core/executeOrder/stageMessages.ts
|
|
419
450
|
var DEFAULT_STAGE_MESSAGES = {
|
|
@@ -568,6 +599,51 @@ async function handleOrderPollingResult({
|
|
|
568
599
|
};
|
|
569
600
|
}
|
|
570
601
|
|
|
602
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
603
|
+
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
604
|
+
import { PERMIT2_ADDRESS } from "@shogun-sdk/intents-sdk";
|
|
605
|
+
async function ensurePermit2Allowance({
|
|
606
|
+
chainId,
|
|
607
|
+
tokenIn,
|
|
608
|
+
wallet,
|
|
609
|
+
accountAddress,
|
|
610
|
+
requiredAmount,
|
|
611
|
+
increaseByDelta = false
|
|
612
|
+
}) {
|
|
613
|
+
const spender = PERMIT2_ADDRESS[chainId];
|
|
614
|
+
let currentAllowance = 0n;
|
|
615
|
+
try {
|
|
616
|
+
if (!wallet.readContract) {
|
|
617
|
+
throw new Error("Wallet does not implement readContract()");
|
|
618
|
+
}
|
|
619
|
+
currentAllowance = await wallet.readContract({
|
|
620
|
+
address: tokenIn,
|
|
621
|
+
abi: erc20Abi,
|
|
622
|
+
functionName: "allowance",
|
|
623
|
+
args: [accountAddress, spender]
|
|
624
|
+
});
|
|
625
|
+
} catch (error) {
|
|
626
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
627
|
+
}
|
|
628
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : maxUint256;
|
|
629
|
+
console.debug(
|
|
630
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
631
|
+
);
|
|
632
|
+
await wallet.sendTransaction({
|
|
633
|
+
to: tokenIn,
|
|
634
|
+
from: accountAddress,
|
|
635
|
+
data: encodeFunctionData({
|
|
636
|
+
abi: erc20Abi,
|
|
637
|
+
functionName: "approve",
|
|
638
|
+
args: [spender, approvalAmount]
|
|
639
|
+
}),
|
|
640
|
+
value: 0n
|
|
641
|
+
});
|
|
642
|
+
console.info(
|
|
643
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
571
647
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
572
648
|
async function handleEvmExecution({
|
|
573
649
|
recipientAddress,
|
|
@@ -587,7 +663,7 @@ async function handleEvmExecution({
|
|
|
587
663
|
if (shouldWrapNative) {
|
|
588
664
|
await wallet.sendTransaction({
|
|
589
665
|
to: tokenIn,
|
|
590
|
-
data:
|
|
666
|
+
data: encodeFunctionData2({
|
|
591
667
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
592
668
|
functionName: "deposit",
|
|
593
669
|
args: []
|
|
@@ -597,15 +673,12 @@ async function handleEvmExecution({
|
|
|
597
673
|
});
|
|
598
674
|
}
|
|
599
675
|
update("processing", messageFor("approving"));
|
|
600
|
-
await
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}),
|
|
607
|
-
value: 0n,
|
|
608
|
-
from: accountAddress
|
|
676
|
+
await ensurePermit2Allowance({
|
|
677
|
+
chainId,
|
|
678
|
+
tokenIn,
|
|
679
|
+
wallet,
|
|
680
|
+
accountAddress,
|
|
681
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
609
682
|
});
|
|
610
683
|
update("processing", messageFor("approved"));
|
|
611
684
|
const destination = recipientAddress ?? accountAddress;
|
package/dist/react.cjs
CHANGED
|
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/react/index.ts
|
|
21
21
|
var react_exports = {};
|
|
22
22
|
__export(react_exports, {
|
|
23
|
-
ChainID: () =>
|
|
24
|
-
isEvmChain: () =>
|
|
23
|
+
ChainID: () => import_intents_sdk12.ChainID,
|
|
24
|
+
isEvmChain: () => import_intents_sdk12.isEvmChain,
|
|
25
25
|
useBalances: () => useBalances,
|
|
26
26
|
useExecuteOrder: () => useExecuteOrder,
|
|
27
27
|
useQuote: () => useQuote,
|
|
@@ -112,8 +112,8 @@ function useTokenList(params) {
|
|
|
112
112
|
var import_react2 = require("react");
|
|
113
113
|
|
|
114
114
|
// src/core/executeOrder/execute.ts
|
|
115
|
-
var
|
|
116
|
-
var
|
|
115
|
+
var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
|
|
116
|
+
var import_viem4 = require("viem");
|
|
117
117
|
|
|
118
118
|
// src/utils/address.ts
|
|
119
119
|
var NATIVE_TOKEN = {
|
|
@@ -276,6 +276,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
276
276
|
if (!addr) throw new Error("No address found");
|
|
277
277
|
return addr;
|
|
278
278
|
};
|
|
279
|
+
const readContract = async ({
|
|
280
|
+
address: address2,
|
|
281
|
+
abi,
|
|
282
|
+
functionName,
|
|
283
|
+
args = []
|
|
284
|
+
}) => {
|
|
285
|
+
const publicClient = wallet.extend(import_viem.publicActions);
|
|
286
|
+
return await publicClient.readContract({
|
|
287
|
+
address: address2,
|
|
288
|
+
abi,
|
|
289
|
+
functionName,
|
|
290
|
+
args
|
|
291
|
+
});
|
|
292
|
+
};
|
|
279
293
|
return {
|
|
280
294
|
vmType: "EVM" /* EVM */,
|
|
281
295
|
transport: (0, import_viem.custom)(wallet.transport),
|
|
@@ -283,13 +297,14 @@ var adaptViemWallet = (wallet) => {
|
|
|
283
297
|
address,
|
|
284
298
|
sendTransaction,
|
|
285
299
|
signTypedData,
|
|
286
|
-
switchChain
|
|
300
|
+
switchChain,
|
|
301
|
+
readContract
|
|
287
302
|
};
|
|
288
303
|
};
|
|
289
304
|
|
|
290
305
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
291
|
-
var
|
|
292
|
-
var
|
|
306
|
+
var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
|
|
307
|
+
var import_viem3 = require("viem");
|
|
293
308
|
|
|
294
309
|
// src/core/executeOrder/normalizeNative.ts
|
|
295
310
|
var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
|
|
@@ -456,6 +471,51 @@ async function handleOrderPollingResult({
|
|
|
456
471
|
};
|
|
457
472
|
}
|
|
458
473
|
|
|
474
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
475
|
+
var import_viem2 = require("viem");
|
|
476
|
+
var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
|
|
477
|
+
async function ensurePermit2Allowance({
|
|
478
|
+
chainId,
|
|
479
|
+
tokenIn,
|
|
480
|
+
wallet,
|
|
481
|
+
accountAddress,
|
|
482
|
+
requiredAmount,
|
|
483
|
+
increaseByDelta = false
|
|
484
|
+
}) {
|
|
485
|
+
const spender = import_intents_sdk6.PERMIT2_ADDRESS[chainId];
|
|
486
|
+
let currentAllowance = 0n;
|
|
487
|
+
try {
|
|
488
|
+
if (!wallet.readContract) {
|
|
489
|
+
throw new Error("Wallet does not implement readContract()");
|
|
490
|
+
}
|
|
491
|
+
currentAllowance = await wallet.readContract({
|
|
492
|
+
address: tokenIn,
|
|
493
|
+
abi: import_viem2.erc20Abi,
|
|
494
|
+
functionName: "allowance",
|
|
495
|
+
args: [accountAddress, spender]
|
|
496
|
+
});
|
|
497
|
+
} catch (error) {
|
|
498
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
499
|
+
}
|
|
500
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem2.maxUint256;
|
|
501
|
+
console.debug(
|
|
502
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
503
|
+
);
|
|
504
|
+
await wallet.sendTransaction({
|
|
505
|
+
to: tokenIn,
|
|
506
|
+
from: accountAddress,
|
|
507
|
+
data: (0, import_viem2.encodeFunctionData)({
|
|
508
|
+
abi: import_viem2.erc20Abi,
|
|
509
|
+
functionName: "approve",
|
|
510
|
+
args: [spender, approvalAmount]
|
|
511
|
+
}),
|
|
512
|
+
value: 0n
|
|
513
|
+
});
|
|
514
|
+
console.info(
|
|
515
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
459
519
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
460
520
|
async function handleEvmExecution({
|
|
461
521
|
recipientAddress,
|
|
@@ -475,7 +535,7 @@ async function handleEvmExecution({
|
|
|
475
535
|
if (shouldWrapNative) {
|
|
476
536
|
await wallet.sendTransaction({
|
|
477
537
|
to: tokenIn,
|
|
478
|
-
data: (0,
|
|
538
|
+
data: (0, import_viem3.encodeFunctionData)({
|
|
479
539
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
480
540
|
functionName: "deposit",
|
|
481
541
|
args: []
|
|
@@ -485,15 +545,12 @@ async function handleEvmExecution({
|
|
|
485
545
|
});
|
|
486
546
|
}
|
|
487
547
|
update("processing", messageFor("approving"));
|
|
488
|
-
await
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}),
|
|
495
|
-
value: 0n,
|
|
496
|
-
from: accountAddress
|
|
548
|
+
await ensurePermit2Allowance({
|
|
549
|
+
chainId,
|
|
550
|
+
tokenIn,
|
|
551
|
+
wallet,
|
|
552
|
+
accountAddress,
|
|
553
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
497
554
|
});
|
|
498
555
|
update("processing", messageFor("approved"));
|
|
499
556
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -506,7 +563,7 @@ async function handleEvmExecution({
|
|
|
506
563
|
});
|
|
507
564
|
console.debug(`order`, order);
|
|
508
565
|
update("processing", messageFor("signing"));
|
|
509
|
-
const { orderTypedData, nonce } = isSingleChain ? await (0,
|
|
566
|
+
const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk7.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk7.getEVMCrossChainOrderTypedData)(order);
|
|
510
567
|
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
511
568
|
if (!wallet.signTypedData) {
|
|
512
569
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
@@ -537,7 +594,7 @@ async function handleEvmExecution({
|
|
|
537
594
|
}
|
|
538
595
|
|
|
539
596
|
// src/core/executeOrder/handleSolanaExecution.ts
|
|
540
|
-
var
|
|
597
|
+
var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
|
|
541
598
|
var import_web3 = require("@solana/web3.js");
|
|
542
599
|
async function handleSolanaExecution({
|
|
543
600
|
recipientAddress,
|
|
@@ -596,11 +653,11 @@ async function getSolanaOrderInstructions({
|
|
|
596
653
|
rpcUrl
|
|
597
654
|
}) {
|
|
598
655
|
if (isSingleChain) {
|
|
599
|
-
return await (0,
|
|
656
|
+
return await (0, import_intents_sdk8.getSolanaSingleChainOrderInstructions)(order, {
|
|
600
657
|
rpcUrl
|
|
601
658
|
});
|
|
602
659
|
}
|
|
603
|
-
return await (0,
|
|
660
|
+
return await (0, import_intents_sdk8.getSolanaCrossChainOrderInstructions)(order, {
|
|
604
661
|
rpcUrl
|
|
605
662
|
});
|
|
606
663
|
}
|
|
@@ -654,7 +711,7 @@ async function executeOrder({
|
|
|
654
711
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
655
712
|
const chainId = Number(tokenIn.chainId);
|
|
656
713
|
update("processing");
|
|
657
|
-
if ((0,
|
|
714
|
+
if ((0, import_intents_sdk9.isEvmChain)(chainId)) {
|
|
658
715
|
log("Detected EVM chain:", chainId);
|
|
659
716
|
const result = await handleEvmExecution({
|
|
660
717
|
recipientAddress,
|
|
@@ -669,7 +726,7 @@ async function executeOrder({
|
|
|
669
726
|
log("EVM execution result:", result);
|
|
670
727
|
return result;
|
|
671
728
|
}
|
|
672
|
-
if (chainId ===
|
|
729
|
+
if (chainId === import_intents_sdk9.ChainID.Solana) {
|
|
673
730
|
log("Detected Solana chain");
|
|
674
731
|
const result = await handleSolanaExecution({
|
|
675
732
|
recipientAddress,
|
|
@@ -688,7 +745,7 @@ async function executeOrder({
|
|
|
688
745
|
log("Error:", unsupported);
|
|
689
746
|
return { status: false, message: unsupported, stage: "error" };
|
|
690
747
|
} catch (error) {
|
|
691
|
-
const message = error instanceof
|
|
748
|
+
const message = error instanceof import_viem4.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
|
|
692
749
|
log("Execution failed:", { message, error });
|
|
693
750
|
update("error", message);
|
|
694
751
|
return { status: false, message, stage: "error" };
|
|
@@ -791,8 +848,8 @@ function useExecuteOrder() {
|
|
|
791
848
|
var import_react3 = require("react");
|
|
792
849
|
|
|
793
850
|
// src/core/getQuote.ts
|
|
794
|
-
var
|
|
795
|
-
var
|
|
851
|
+
var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
|
|
852
|
+
var import_viem5 = require("viem");
|
|
796
853
|
async function getQuote(params) {
|
|
797
854
|
if (!params.tokenIn?.address || !params.tokenOut?.address) {
|
|
798
855
|
throw new Error("Both tokenIn and tokenOut must include an address.");
|
|
@@ -804,7 +861,7 @@ async function getQuote(params) {
|
|
|
804
861
|
throw new Error("Amount must be greater than 0.");
|
|
805
862
|
}
|
|
806
863
|
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
807
|
-
const data = await
|
|
864
|
+
const data = await import_intents_sdk10.QuoteProvider.getQuote({
|
|
808
865
|
sourceChainId: params.sourceChainId,
|
|
809
866
|
destChainId: params.destChainId,
|
|
810
867
|
tokenIn: normalizedTokenIn,
|
|
@@ -929,7 +986,7 @@ function useQuote(params, options) {
|
|
|
929
986
|
var import_react4 = require("react");
|
|
930
987
|
|
|
931
988
|
// src/core/getBalances.ts
|
|
932
|
-
var
|
|
989
|
+
var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
|
|
933
990
|
async function getBalances(params, options) {
|
|
934
991
|
const { addresses, cursorEvm, cursorSvm } = params;
|
|
935
992
|
const { signal } = options ?? {};
|
|
@@ -942,7 +999,7 @@ async function getBalances(params, options) {
|
|
|
942
999
|
cursorSvm
|
|
943
1000
|
});
|
|
944
1001
|
const start = performance.now();
|
|
945
|
-
const response = await fetch(`${
|
|
1002
|
+
const response = await fetch(`${import_intents_sdk11.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
|
|
946
1003
|
method: "POST",
|
|
947
1004
|
headers: {
|
|
948
1005
|
accept: "application/json",
|
|
@@ -1041,4 +1098,4 @@ function useBalances(params) {
|
|
|
1041
1098
|
}
|
|
1042
1099
|
|
|
1043
1100
|
// src/react/index.ts
|
|
1044
|
-
var
|
|
1101
|
+
var import_intents_sdk12 = require("@shogun-sdk/intents-sdk");
|
package/dist/react.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TokenSearchParams, TokenSearchResponse } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
3
|
-
import { a as SwapQuoteResponse, e as executeOrder, b as Stage, g as PollResult, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-
|
|
4
|
-
export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-
|
|
5
|
-
import { A as AdaptedWallet } from './wallet-
|
|
3
|
+
import { a as SwapQuoteResponse, e as executeOrder, b as Stage, g as PollResult, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-Xvw4wXBo.cjs';
|
|
4
|
+
export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-Xvw4wXBo.cjs';
|
|
5
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
|
|
6
6
|
import { WalletClient } from 'viem';
|
|
7
7
|
import '@mysten/sui/transactions';
|
|
8
8
|
import '@solana/web3.js';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TokenSearchParams, TokenSearchResponse } from '@shogun-sdk/intents-sdk';
|
|
2
2
|
export { ChainID, isEvmChain } from '@shogun-sdk/intents-sdk';
|
|
3
|
-
import { a as SwapQuoteResponse, e as executeOrder, b as Stage, g as PollResult, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-
|
|
4
|
-
export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-
|
|
5
|
-
import { A as AdaptedWallet } from './wallet-
|
|
3
|
+
import { a as SwapQuoteResponse, e as executeOrder, b as Stage, g as PollResult, S as SwapQuoteParams, B as BalanceRequestParams, c as BalanceResponse } from './execute-D2qcOzkI.js';
|
|
4
|
+
export { P as PlaceOrderResult, Q as QuoteTokenInfo, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse } from './execute-D2qcOzkI.js';
|
|
5
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
|
|
6
6
|
import { WalletClient } from 'viem';
|
|
7
7
|
import '@mysten/sui/transactions';
|
|
8
8
|
import '@solana/web3.js';
|
package/dist/react.js
CHANGED
|
@@ -183,10 +183,11 @@ function serializeBigIntsToStrings(obj) {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
186
|
-
import "ethers/lib/ethers.js";
|
|
186
|
+
import { utils as ethersUtils } from "ethers/lib/ethers.js";
|
|
187
187
|
import { hexValue } from "ethers/lib/utils.js";
|
|
188
188
|
import {
|
|
189
|
-
custom
|
|
189
|
+
custom,
|
|
190
|
+
publicActions
|
|
190
191
|
} from "viem";
|
|
191
192
|
function isEVMTransaction(tx) {
|
|
192
193
|
return typeof tx.from === "string";
|
|
@@ -247,6 +248,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
247
248
|
if (!addr) throw new Error("No address found");
|
|
248
249
|
return addr;
|
|
249
250
|
};
|
|
251
|
+
const readContract = async ({
|
|
252
|
+
address: address2,
|
|
253
|
+
abi,
|
|
254
|
+
functionName,
|
|
255
|
+
args = []
|
|
256
|
+
}) => {
|
|
257
|
+
const publicClient = wallet.extend(publicActions);
|
|
258
|
+
return await publicClient.readContract({
|
|
259
|
+
address: address2,
|
|
260
|
+
abi,
|
|
261
|
+
functionName,
|
|
262
|
+
args
|
|
263
|
+
});
|
|
264
|
+
};
|
|
250
265
|
return {
|
|
251
266
|
vmType: "EVM" /* EVM */,
|
|
252
267
|
transport: custom(wallet.transport),
|
|
@@ -254,17 +269,17 @@ var adaptViemWallet = (wallet) => {
|
|
|
254
269
|
address,
|
|
255
270
|
sendTransaction,
|
|
256
271
|
signTypedData,
|
|
257
|
-
switchChain
|
|
272
|
+
switchChain,
|
|
273
|
+
readContract
|
|
258
274
|
};
|
|
259
275
|
};
|
|
260
276
|
|
|
261
277
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
262
278
|
import {
|
|
263
279
|
getEVMSingleChainOrderTypedData,
|
|
264
|
-
getEVMCrossChainOrderTypedData
|
|
265
|
-
PERMIT2_ADDRESS
|
|
280
|
+
getEVMCrossChainOrderTypedData
|
|
266
281
|
} from "@shogun-sdk/intents-sdk";
|
|
267
|
-
import { encodeFunctionData
|
|
282
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
268
283
|
|
|
269
284
|
// src/core/executeOrder/normalizeNative.ts
|
|
270
285
|
import { isEvmChain } from "@shogun-sdk/intents-sdk";
|
|
@@ -431,6 +446,51 @@ async function handleOrderPollingResult({
|
|
|
431
446
|
};
|
|
432
447
|
}
|
|
433
448
|
|
|
449
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
450
|
+
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
451
|
+
import { PERMIT2_ADDRESS } from "@shogun-sdk/intents-sdk";
|
|
452
|
+
async function ensurePermit2Allowance({
|
|
453
|
+
chainId,
|
|
454
|
+
tokenIn,
|
|
455
|
+
wallet,
|
|
456
|
+
accountAddress,
|
|
457
|
+
requiredAmount,
|
|
458
|
+
increaseByDelta = false
|
|
459
|
+
}) {
|
|
460
|
+
const spender = PERMIT2_ADDRESS[chainId];
|
|
461
|
+
let currentAllowance = 0n;
|
|
462
|
+
try {
|
|
463
|
+
if (!wallet.readContract) {
|
|
464
|
+
throw new Error("Wallet does not implement readContract()");
|
|
465
|
+
}
|
|
466
|
+
currentAllowance = await wallet.readContract({
|
|
467
|
+
address: tokenIn,
|
|
468
|
+
abi: erc20Abi,
|
|
469
|
+
functionName: "allowance",
|
|
470
|
+
args: [accountAddress, spender]
|
|
471
|
+
});
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
474
|
+
}
|
|
475
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : maxUint256;
|
|
476
|
+
console.debug(
|
|
477
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
478
|
+
);
|
|
479
|
+
await wallet.sendTransaction({
|
|
480
|
+
to: tokenIn,
|
|
481
|
+
from: accountAddress,
|
|
482
|
+
data: encodeFunctionData({
|
|
483
|
+
abi: erc20Abi,
|
|
484
|
+
functionName: "approve",
|
|
485
|
+
args: [spender, approvalAmount]
|
|
486
|
+
}),
|
|
487
|
+
value: 0n
|
|
488
|
+
});
|
|
489
|
+
console.info(
|
|
490
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
434
494
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
435
495
|
async function handleEvmExecution({
|
|
436
496
|
recipientAddress,
|
|
@@ -450,7 +510,7 @@ async function handleEvmExecution({
|
|
|
450
510
|
if (shouldWrapNative) {
|
|
451
511
|
await wallet.sendTransaction({
|
|
452
512
|
to: tokenIn,
|
|
453
|
-
data:
|
|
513
|
+
data: encodeFunctionData2({
|
|
454
514
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
455
515
|
functionName: "deposit",
|
|
456
516
|
args: []
|
|
@@ -460,15 +520,12 @@ async function handleEvmExecution({
|
|
|
460
520
|
});
|
|
461
521
|
}
|
|
462
522
|
update("processing", messageFor("approving"));
|
|
463
|
-
await
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}),
|
|
470
|
-
value: 0n,
|
|
471
|
-
from: accountAddress
|
|
523
|
+
await ensurePermit2Allowance({
|
|
524
|
+
chainId,
|
|
525
|
+
tokenIn,
|
|
526
|
+
wallet,
|
|
527
|
+
accountAddress,
|
|
528
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
472
529
|
});
|
|
473
530
|
update("processing", messageFor("approved"));
|
|
474
531
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction as Transaction$1 } from '@mysten/sui/transactions';
|
|
2
2
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
-
import { CustomTransport, HttpTransport } from 'viem';
|
|
3
|
+
import { CustomTransport, HttpTransport, PublicActions } from 'viem';
|
|
4
4
|
|
|
5
5
|
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
6
6
|
type EVMTransaction = {
|
|
@@ -24,6 +24,7 @@ type AdaptedWallet = {
|
|
|
24
24
|
sendTransaction: (transaction: AnyTransaction) => Promise<string>;
|
|
25
25
|
signTypedData?: (signData: any) => Promise<string>;
|
|
26
26
|
rpcUrl?: string;
|
|
27
|
+
readContract?: PublicActions['readContract'];
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export type { AdaptedWallet as A };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction as Transaction$1 } from '@mysten/sui/transactions';
|
|
2
2
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
-
import { CustomTransport, HttpTransport } from 'viem';
|
|
3
|
+
import { CustomTransport, HttpTransport, PublicActions } from 'viem';
|
|
4
4
|
|
|
5
5
|
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
6
6
|
type EVMTransaction = {
|
|
@@ -24,6 +24,7 @@ type AdaptedWallet = {
|
|
|
24
24
|
sendTransaction: (transaction: AnyTransaction) => Promise<string>;
|
|
25
25
|
signTypedData?: (signData: any) => Promise<string>;
|
|
26
26
|
rpcUrl?: string;
|
|
27
|
+
readContract?: PublicActions['readContract'];
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export type { AdaptedWallet as A };
|
package/dist/wallet-adapter.cjs
CHANGED
|
@@ -102,6 +102,21 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
102
102
|
throw error;
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
+
const readContract = async ({
|
|
106
|
+
address,
|
|
107
|
+
abi,
|
|
108
|
+
functionName,
|
|
109
|
+
args = []
|
|
110
|
+
}) => {
|
|
111
|
+
const iface = new import_ethers.utils.Interface(abi);
|
|
112
|
+
const fnArgs = Array.isArray(args) ? args : [];
|
|
113
|
+
const data = iface.encodeFunctionData(functionName, fnArgs);
|
|
114
|
+
const provider = signer.provider;
|
|
115
|
+
if (!provider) throw new Error("Signer has no provider");
|
|
116
|
+
const result = await provider.call({ to: address, data });
|
|
117
|
+
const decoded = iface.decodeFunctionResult(functionName, result);
|
|
118
|
+
return decoded[0];
|
|
119
|
+
};
|
|
105
120
|
return {
|
|
106
121
|
vmType: "EVM" /* EVM */,
|
|
107
122
|
transport,
|
|
@@ -109,7 +124,8 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
109
124
|
address: async () => signer.getAddress(),
|
|
110
125
|
sendTransaction,
|
|
111
126
|
signTypedData,
|
|
112
|
-
switchChain
|
|
127
|
+
switchChain,
|
|
128
|
+
readContract
|
|
113
129
|
};
|
|
114
130
|
};
|
|
115
131
|
var adaptViemWallet = (wallet) => {
|
|
@@ -168,6 +184,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
168
184
|
if (!addr) throw new Error("No address found");
|
|
169
185
|
return addr;
|
|
170
186
|
};
|
|
187
|
+
const readContract = async ({
|
|
188
|
+
address: address2,
|
|
189
|
+
abi,
|
|
190
|
+
functionName,
|
|
191
|
+
args = []
|
|
192
|
+
}) => {
|
|
193
|
+
const publicClient = wallet.extend(import_viem.publicActions);
|
|
194
|
+
return await publicClient.readContract({
|
|
195
|
+
address: address2,
|
|
196
|
+
abi,
|
|
197
|
+
functionName,
|
|
198
|
+
args
|
|
199
|
+
});
|
|
200
|
+
};
|
|
171
201
|
return {
|
|
172
202
|
vmType: "EVM" /* EVM */,
|
|
173
203
|
transport: (0, import_viem.custom)(wallet.transport),
|
|
@@ -175,6 +205,7 @@ var adaptViemWallet = (wallet) => {
|
|
|
175
205
|
address,
|
|
176
206
|
sendTransaction,
|
|
177
207
|
signTypedData,
|
|
178
|
-
switchChain
|
|
208
|
+
switchChain,
|
|
209
|
+
readContract
|
|
179
210
|
};
|
|
180
211
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VersionedTransaction, SendOptions, TransactionSignature } from '@solana/web3.js';
|
|
2
|
-
import { A as AdaptedWallet } from './wallet-
|
|
2
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
|
|
3
3
|
import { Signer } from 'ethers/lib/ethers.js';
|
|
4
4
|
import { CustomTransport, HttpTransport, WalletClient } from 'viem';
|
|
5
5
|
import '@mysten/sui/transactions';
|
package/dist/wallet-adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VersionedTransaction, SendOptions, TransactionSignature } from '@solana/web3.js';
|
|
2
|
-
import { A as AdaptedWallet } from './wallet-
|
|
2
|
+
import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
|
|
3
3
|
import { Signer } from 'ethers/lib/ethers.js';
|
|
4
4
|
import { CustomTransport, HttpTransport, WalletClient } from 'viem';
|
|
5
5
|
import '@mysten/sui/transactions';
|