@shogun-sdk/swap 0.0.2-test.23 → 0.0.2-test.25
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 +93 -29
- package/dist/core.d.cts +5 -4
- package/dist/core.d.ts +5 -4
- package/dist/core.js +80 -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 +107 -27
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +97 -17
- package/dist/react.cjs +95 -32
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +79 -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/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,10 +112,11 @@ 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_viem5 = require("viem");
|
|
117
117
|
|
|
118
118
|
// src/utils/address.ts
|
|
119
|
+
var import_viem = require("viem");
|
|
119
120
|
var NATIVE_TOKEN = {
|
|
120
121
|
ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
121
122
|
SOL: "So11111111111111111111111111111111111111111",
|
|
@@ -126,6 +127,10 @@ var isNativeAddress = (tokenAddress) => {
|
|
|
126
127
|
const normalizedTokenAddress = tokenAddress.toLowerCase();
|
|
127
128
|
return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
|
|
128
129
|
};
|
|
130
|
+
function normalizeEvmTokenAddress(address) {
|
|
131
|
+
const lower = address.toLowerCase();
|
|
132
|
+
return lower === NATIVE_TOKEN.ETH.toLowerCase() ? import_viem.zeroAddress : address;
|
|
133
|
+
}
|
|
129
134
|
|
|
130
135
|
// src/utils/chain.ts
|
|
131
136
|
var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
|
|
@@ -216,7 +221,7 @@ function serializeBigIntsToStrings(obj) {
|
|
|
216
221
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
217
222
|
var import_ethers = require("ethers/lib/ethers.js");
|
|
218
223
|
var import_utils = require("ethers/lib/utils.js");
|
|
219
|
-
var
|
|
224
|
+
var import_viem2 = require("viem");
|
|
220
225
|
function isEVMTransaction(tx) {
|
|
221
226
|
return typeof tx.from === "string";
|
|
222
227
|
}
|
|
@@ -276,20 +281,35 @@ var adaptViemWallet = (wallet) => {
|
|
|
276
281
|
if (!addr) throw new Error("No address found");
|
|
277
282
|
return addr;
|
|
278
283
|
};
|
|
284
|
+
const readContract = async ({
|
|
285
|
+
address: address2,
|
|
286
|
+
abi,
|
|
287
|
+
functionName,
|
|
288
|
+
args = []
|
|
289
|
+
}) => {
|
|
290
|
+
const publicClient = wallet.extend(import_viem2.publicActions);
|
|
291
|
+
return await publicClient.readContract({
|
|
292
|
+
address: address2,
|
|
293
|
+
abi,
|
|
294
|
+
functionName,
|
|
295
|
+
args
|
|
296
|
+
});
|
|
297
|
+
};
|
|
279
298
|
return {
|
|
280
299
|
vmType: "EVM" /* EVM */,
|
|
281
|
-
transport: (0,
|
|
300
|
+
transport: (0, import_viem2.custom)(wallet.transport),
|
|
282
301
|
getChainId: async () => wallet.getChainId(),
|
|
283
302
|
address,
|
|
284
303
|
sendTransaction,
|
|
285
304
|
signTypedData,
|
|
286
|
-
switchChain
|
|
305
|
+
switchChain,
|
|
306
|
+
readContract
|
|
287
307
|
};
|
|
288
308
|
};
|
|
289
309
|
|
|
290
310
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
291
|
-
var
|
|
292
|
-
var
|
|
311
|
+
var import_intents_sdk7 = require("@shogun-sdk/intents-sdk");
|
|
312
|
+
var import_viem4 = require("viem");
|
|
293
313
|
|
|
294
314
|
// src/core/executeOrder/normalizeNative.ts
|
|
295
315
|
var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
|
|
@@ -456,6 +476,51 @@ async function handleOrderPollingResult({
|
|
|
456
476
|
};
|
|
457
477
|
}
|
|
458
478
|
|
|
479
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
480
|
+
var import_viem3 = require("viem");
|
|
481
|
+
var import_intents_sdk6 = require("@shogun-sdk/intents-sdk");
|
|
482
|
+
async function ensurePermit2Allowance({
|
|
483
|
+
chainId,
|
|
484
|
+
tokenIn,
|
|
485
|
+
wallet,
|
|
486
|
+
accountAddress,
|
|
487
|
+
requiredAmount,
|
|
488
|
+
increaseByDelta = false
|
|
489
|
+
}) {
|
|
490
|
+
const spender = import_intents_sdk6.PERMIT2_ADDRESS[chainId];
|
|
491
|
+
let currentAllowance = 0n;
|
|
492
|
+
try {
|
|
493
|
+
if (!wallet.readContract) {
|
|
494
|
+
throw new Error("Wallet does not implement readContract()");
|
|
495
|
+
}
|
|
496
|
+
currentAllowance = await wallet.readContract({
|
|
497
|
+
address: tokenIn,
|
|
498
|
+
abi: import_viem3.erc20Abi,
|
|
499
|
+
functionName: "allowance",
|
|
500
|
+
args: [accountAddress, spender]
|
|
501
|
+
});
|
|
502
|
+
} catch (error) {
|
|
503
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
504
|
+
}
|
|
505
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem3.maxUint256;
|
|
506
|
+
console.debug(
|
|
507
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
508
|
+
);
|
|
509
|
+
await wallet.sendTransaction({
|
|
510
|
+
to: tokenIn,
|
|
511
|
+
from: accountAddress,
|
|
512
|
+
data: (0, import_viem3.encodeFunctionData)({
|
|
513
|
+
abi: import_viem3.erc20Abi,
|
|
514
|
+
functionName: "approve",
|
|
515
|
+
args: [spender, approvalAmount]
|
|
516
|
+
}),
|
|
517
|
+
value: 0n
|
|
518
|
+
});
|
|
519
|
+
console.info(
|
|
520
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
459
524
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
460
525
|
async function handleEvmExecution({
|
|
461
526
|
recipientAddress,
|
|
@@ -470,12 +535,13 @@ async function handleEvmExecution({
|
|
|
470
535
|
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
|
|
471
536
|
await wallet.switchChain(chainId);
|
|
472
537
|
const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
|
|
538
|
+
quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
|
|
473
539
|
const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
|
|
474
540
|
update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
|
|
475
541
|
if (shouldWrapNative) {
|
|
476
542
|
await wallet.sendTransaction({
|
|
477
543
|
to: tokenIn,
|
|
478
|
-
data: (0,
|
|
544
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
479
545
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
480
546
|
functionName: "deposit",
|
|
481
547
|
args: []
|
|
@@ -485,15 +551,12 @@ async function handleEvmExecution({
|
|
|
485
551
|
});
|
|
486
552
|
}
|
|
487
553
|
update("processing", messageFor("approving"));
|
|
488
|
-
await
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}),
|
|
495
|
-
value: 0n,
|
|
496
|
-
from: accountAddress
|
|
554
|
+
await ensurePermit2Allowance({
|
|
555
|
+
chainId,
|
|
556
|
+
tokenIn,
|
|
557
|
+
wallet,
|
|
558
|
+
accountAddress,
|
|
559
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
497
560
|
});
|
|
498
561
|
update("processing", messageFor("approved"));
|
|
499
562
|
const destination = recipientAddress ?? accountAddress;
|
|
@@ -506,7 +569,7 @@ async function handleEvmExecution({
|
|
|
506
569
|
});
|
|
507
570
|
console.debug(`order`, order);
|
|
508
571
|
update("processing", messageFor("signing"));
|
|
509
|
-
const { orderTypedData, nonce } = isSingleChain ? await (0,
|
|
572
|
+
const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk7.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk7.getEVMCrossChainOrderTypedData)(order);
|
|
510
573
|
const typedData = serializeBigIntsToStrings(orderTypedData);
|
|
511
574
|
if (!wallet.signTypedData) {
|
|
512
575
|
throw new Error("Wallet does not support EIP-712 signing");
|
|
@@ -537,7 +600,7 @@ async function handleEvmExecution({
|
|
|
537
600
|
}
|
|
538
601
|
|
|
539
602
|
// src/core/executeOrder/handleSolanaExecution.ts
|
|
540
|
-
var
|
|
603
|
+
var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
|
|
541
604
|
var import_web3 = require("@solana/web3.js");
|
|
542
605
|
async function handleSolanaExecution({
|
|
543
606
|
recipientAddress,
|
|
@@ -596,11 +659,11 @@ async function getSolanaOrderInstructions({
|
|
|
596
659
|
rpcUrl
|
|
597
660
|
}) {
|
|
598
661
|
if (isSingleChain) {
|
|
599
|
-
return await (0,
|
|
662
|
+
return await (0, import_intents_sdk8.getSolanaSingleChainOrderInstructions)(order, {
|
|
600
663
|
rpcUrl
|
|
601
664
|
});
|
|
602
665
|
}
|
|
603
|
-
return await (0,
|
|
666
|
+
return await (0, import_intents_sdk8.getSolanaCrossChainOrderInstructions)(order, {
|
|
604
667
|
rpcUrl
|
|
605
668
|
});
|
|
606
669
|
}
|
|
@@ -654,7 +717,7 @@ async function executeOrder({
|
|
|
654
717
|
const isSingleChain = tokenIn.chainId === tokenOut.chainId;
|
|
655
718
|
const chainId = Number(tokenIn.chainId);
|
|
656
719
|
update("processing");
|
|
657
|
-
if ((0,
|
|
720
|
+
if ((0, import_intents_sdk9.isEvmChain)(chainId)) {
|
|
658
721
|
log("Detected EVM chain:", chainId);
|
|
659
722
|
const result = await handleEvmExecution({
|
|
660
723
|
recipientAddress,
|
|
@@ -669,7 +732,7 @@ async function executeOrder({
|
|
|
669
732
|
log("EVM execution result:", result);
|
|
670
733
|
return result;
|
|
671
734
|
}
|
|
672
|
-
if (chainId ===
|
|
735
|
+
if (chainId === import_intents_sdk9.ChainID.Solana) {
|
|
673
736
|
log("Detected Solana chain");
|
|
674
737
|
const result = await handleSolanaExecution({
|
|
675
738
|
recipientAddress,
|
|
@@ -688,7 +751,7 @@ async function executeOrder({
|
|
|
688
751
|
log("Error:", unsupported);
|
|
689
752
|
return { status: false, message: unsupported, stage: "error" };
|
|
690
753
|
} catch (error) {
|
|
691
|
-
const message = error instanceof
|
|
754
|
+
const message = error instanceof import_viem5.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
|
|
692
755
|
log("Execution failed:", { message, error });
|
|
693
756
|
update("error", message);
|
|
694
757
|
return { status: false, message, stage: "error" };
|
|
@@ -791,8 +854,8 @@ function useExecuteOrder() {
|
|
|
791
854
|
var import_react3 = require("react");
|
|
792
855
|
|
|
793
856
|
// src/core/getQuote.ts
|
|
794
|
-
var
|
|
795
|
-
var
|
|
857
|
+
var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
|
|
858
|
+
var import_viem6 = require("viem");
|
|
796
859
|
async function getQuote(params) {
|
|
797
860
|
if (!params.tokenIn?.address || !params.tokenOut?.address) {
|
|
798
861
|
throw new Error("Both tokenIn and tokenOut must include an address.");
|
|
@@ -804,7 +867,7 @@ async function getQuote(params) {
|
|
|
804
867
|
throw new Error("Amount must be greater than 0.");
|
|
805
868
|
}
|
|
806
869
|
const normalizedTokenIn = normalizeNative(params.sourceChainId, params.tokenIn.address);
|
|
807
|
-
const data = await
|
|
870
|
+
const data = await import_intents_sdk10.QuoteProvider.getQuote({
|
|
808
871
|
sourceChainId: params.sourceChainId,
|
|
809
872
|
destChainId: params.destChainId,
|
|
810
873
|
tokenIn: normalizedTokenIn,
|
|
@@ -929,7 +992,7 @@ function useQuote(params, options) {
|
|
|
929
992
|
var import_react4 = require("react");
|
|
930
993
|
|
|
931
994
|
// src/core/getBalances.ts
|
|
932
|
-
var
|
|
995
|
+
var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
|
|
933
996
|
async function getBalances(params, options) {
|
|
934
997
|
const { addresses, cursorEvm, cursorSvm } = params;
|
|
935
998
|
const { signal } = options ?? {};
|
|
@@ -942,7 +1005,7 @@ async function getBalances(params, options) {
|
|
|
942
1005
|
cursorSvm
|
|
943
1006
|
});
|
|
944
1007
|
const start = performance.now();
|
|
945
|
-
const response = await fetch(`${
|
|
1008
|
+
const response = await fetch(`${import_intents_sdk11.TOKEN_SEARCH_API_BASE_URL}/tokens/balances`, {
|
|
946
1009
|
method: "POST",
|
|
947
1010
|
headers: {
|
|
948
1011
|
accept: "application/json",
|
|
@@ -1041,4 +1104,4 @@ function useBalances(params) {
|
|
|
1041
1104
|
}
|
|
1042
1105
|
|
|
1043
1106
|
// src/react/index.ts
|
|
1044
|
-
var
|
|
1107
|
+
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
|
@@ -85,6 +85,7 @@ import { ChainID as ChainID3, isEvmChain as isEvmChain2 } from "@shogun-sdk/inte
|
|
|
85
85
|
import { BaseError } from "viem";
|
|
86
86
|
|
|
87
87
|
// src/utils/address.ts
|
|
88
|
+
import { zeroAddress } from "viem";
|
|
88
89
|
var NATIVE_TOKEN = {
|
|
89
90
|
ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
90
91
|
SOL: "So11111111111111111111111111111111111111111",
|
|
@@ -95,6 +96,10 @@ var isNativeAddress = (tokenAddress) => {
|
|
|
95
96
|
const normalizedTokenAddress = tokenAddress.toLowerCase();
|
|
96
97
|
return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
|
|
97
98
|
};
|
|
99
|
+
function normalizeEvmTokenAddress(address) {
|
|
100
|
+
const lower = address.toLowerCase();
|
|
101
|
+
return lower === NATIVE_TOKEN.ETH.toLowerCase() ? zeroAddress : address;
|
|
102
|
+
}
|
|
98
103
|
|
|
99
104
|
// src/utils/chain.ts
|
|
100
105
|
import { ChainID } from "@shogun-sdk/intents-sdk";
|
|
@@ -183,10 +188,11 @@ function serializeBigIntsToStrings(obj) {
|
|
|
183
188
|
}
|
|
184
189
|
|
|
185
190
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
186
|
-
import "ethers/lib/ethers.js";
|
|
191
|
+
import { utils as ethersUtils } from "ethers/lib/ethers.js";
|
|
187
192
|
import { hexValue } from "ethers/lib/utils.js";
|
|
188
193
|
import {
|
|
189
|
-
custom
|
|
194
|
+
custom,
|
|
195
|
+
publicActions
|
|
190
196
|
} from "viem";
|
|
191
197
|
function isEVMTransaction(tx) {
|
|
192
198
|
return typeof tx.from === "string";
|
|
@@ -247,6 +253,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
247
253
|
if (!addr) throw new Error("No address found");
|
|
248
254
|
return addr;
|
|
249
255
|
};
|
|
256
|
+
const readContract = async ({
|
|
257
|
+
address: address2,
|
|
258
|
+
abi,
|
|
259
|
+
functionName,
|
|
260
|
+
args = []
|
|
261
|
+
}) => {
|
|
262
|
+
const publicClient = wallet.extend(publicActions);
|
|
263
|
+
return await publicClient.readContract({
|
|
264
|
+
address: address2,
|
|
265
|
+
abi,
|
|
266
|
+
functionName,
|
|
267
|
+
args
|
|
268
|
+
});
|
|
269
|
+
};
|
|
250
270
|
return {
|
|
251
271
|
vmType: "EVM" /* EVM */,
|
|
252
272
|
transport: custom(wallet.transport),
|
|
@@ -254,17 +274,17 @@ var adaptViemWallet = (wallet) => {
|
|
|
254
274
|
address,
|
|
255
275
|
sendTransaction,
|
|
256
276
|
signTypedData,
|
|
257
|
-
switchChain
|
|
277
|
+
switchChain,
|
|
278
|
+
readContract
|
|
258
279
|
};
|
|
259
280
|
};
|
|
260
281
|
|
|
261
282
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
262
283
|
import {
|
|
263
284
|
getEVMSingleChainOrderTypedData,
|
|
264
|
-
getEVMCrossChainOrderTypedData
|
|
265
|
-
PERMIT2_ADDRESS
|
|
285
|
+
getEVMCrossChainOrderTypedData
|
|
266
286
|
} from "@shogun-sdk/intents-sdk";
|
|
267
|
-
import { encodeFunctionData
|
|
287
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
268
288
|
|
|
269
289
|
// src/core/executeOrder/normalizeNative.ts
|
|
270
290
|
import { isEvmChain } from "@shogun-sdk/intents-sdk";
|
|
@@ -431,6 +451,51 @@ async function handleOrderPollingResult({
|
|
|
431
451
|
};
|
|
432
452
|
}
|
|
433
453
|
|
|
454
|
+
// src/core/executeOrder/ensurePermit2Allowance.ts
|
|
455
|
+
import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
|
|
456
|
+
import { PERMIT2_ADDRESS } from "@shogun-sdk/intents-sdk";
|
|
457
|
+
async function ensurePermit2Allowance({
|
|
458
|
+
chainId,
|
|
459
|
+
tokenIn,
|
|
460
|
+
wallet,
|
|
461
|
+
accountAddress,
|
|
462
|
+
requiredAmount,
|
|
463
|
+
increaseByDelta = false
|
|
464
|
+
}) {
|
|
465
|
+
const spender = PERMIT2_ADDRESS[chainId];
|
|
466
|
+
let currentAllowance = 0n;
|
|
467
|
+
try {
|
|
468
|
+
if (!wallet.readContract) {
|
|
469
|
+
throw new Error("Wallet does not implement readContract()");
|
|
470
|
+
}
|
|
471
|
+
currentAllowance = await wallet.readContract({
|
|
472
|
+
address: tokenIn,
|
|
473
|
+
abi: erc20Abi,
|
|
474
|
+
functionName: "allowance",
|
|
475
|
+
args: [accountAddress, spender]
|
|
476
|
+
});
|
|
477
|
+
} catch (error) {
|
|
478
|
+
console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
|
|
479
|
+
}
|
|
480
|
+
const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : maxUint256;
|
|
481
|
+
console.debug(
|
|
482
|
+
`[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
|
|
483
|
+
);
|
|
484
|
+
await wallet.sendTransaction({
|
|
485
|
+
to: tokenIn,
|
|
486
|
+
from: accountAddress,
|
|
487
|
+
data: encodeFunctionData({
|
|
488
|
+
abi: erc20Abi,
|
|
489
|
+
functionName: "approve",
|
|
490
|
+
args: [spender, approvalAmount]
|
|
491
|
+
}),
|
|
492
|
+
value: 0n
|
|
493
|
+
});
|
|
494
|
+
console.info(
|
|
495
|
+
`[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
434
499
|
// src/core/executeOrder/handleEvmExecution.ts
|
|
435
500
|
async function handleEvmExecution({
|
|
436
501
|
recipientAddress,
|
|
@@ -445,12 +510,13 @@ async function handleEvmExecution({
|
|
|
445
510
|
const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
|
|
446
511
|
await wallet.switchChain(chainId);
|
|
447
512
|
const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
|
|
513
|
+
quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
|
|
448
514
|
const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
|
|
449
515
|
update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
|
|
450
516
|
if (shouldWrapNative) {
|
|
451
517
|
await wallet.sendTransaction({
|
|
452
518
|
to: tokenIn,
|
|
453
|
-
data:
|
|
519
|
+
data: encodeFunctionData2({
|
|
454
520
|
abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
|
|
455
521
|
functionName: "deposit",
|
|
456
522
|
args: []
|
|
@@ -460,15 +526,12 @@ async function handleEvmExecution({
|
|
|
460
526
|
});
|
|
461
527
|
}
|
|
462
528
|
update("processing", messageFor("approving"));
|
|
463
|
-
await
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}),
|
|
470
|
-
value: 0n,
|
|
471
|
-
from: accountAddress
|
|
529
|
+
await ensurePermit2Allowance({
|
|
530
|
+
chainId,
|
|
531
|
+
tokenIn,
|
|
532
|
+
wallet,
|
|
533
|
+
accountAddress,
|
|
534
|
+
requiredAmount: BigInt(quote.amountIn)
|
|
472
535
|
});
|
|
473
536
|
update("processing", messageFor("approved"));
|
|
474
537
|
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';
|
package/dist/wallet-adapter.js
CHANGED
|
@@ -38,10 +38,11 @@ var adaptSolanaWallet = (walletAddress, chainId, rpcUrl, signAndSendTransaction)
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
41
|
-
import "ethers/lib/ethers.js";
|
|
41
|
+
import { utils as ethersUtils } from "ethers/lib/ethers.js";
|
|
42
42
|
import { hexValue } from "ethers/lib/utils.js";
|
|
43
43
|
import {
|
|
44
|
-
custom
|
|
44
|
+
custom,
|
|
45
|
+
publicActions
|
|
45
46
|
} from "viem";
|
|
46
47
|
function isEVMTransaction(tx) {
|
|
47
48
|
return typeof tx.from === "string";
|
|
@@ -78,6 +79,21 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
78
79
|
throw error;
|
|
79
80
|
}
|
|
80
81
|
};
|
|
82
|
+
const readContract = async ({
|
|
83
|
+
address,
|
|
84
|
+
abi,
|
|
85
|
+
functionName,
|
|
86
|
+
args = []
|
|
87
|
+
}) => {
|
|
88
|
+
const iface = new ethersUtils.Interface(abi);
|
|
89
|
+
const fnArgs = Array.isArray(args) ? args : [];
|
|
90
|
+
const data = iface.encodeFunctionData(functionName, fnArgs);
|
|
91
|
+
const provider = signer.provider;
|
|
92
|
+
if (!provider) throw new Error("Signer has no provider");
|
|
93
|
+
const result = await provider.call({ to: address, data });
|
|
94
|
+
const decoded = iface.decodeFunctionResult(functionName, result);
|
|
95
|
+
return decoded[0];
|
|
96
|
+
};
|
|
81
97
|
return {
|
|
82
98
|
vmType: "EVM" /* EVM */,
|
|
83
99
|
transport,
|
|
@@ -85,7 +101,8 @@ var adaptEthersSigner = (signer, transport) => {
|
|
|
85
101
|
address: async () => signer.getAddress(),
|
|
86
102
|
sendTransaction,
|
|
87
103
|
signTypedData,
|
|
88
|
-
switchChain
|
|
104
|
+
switchChain,
|
|
105
|
+
readContract
|
|
89
106
|
};
|
|
90
107
|
};
|
|
91
108
|
var adaptViemWallet = (wallet) => {
|
|
@@ -144,6 +161,20 @@ var adaptViemWallet = (wallet) => {
|
|
|
144
161
|
if (!addr) throw new Error("No address found");
|
|
145
162
|
return addr;
|
|
146
163
|
};
|
|
164
|
+
const readContract = async ({
|
|
165
|
+
address: address2,
|
|
166
|
+
abi,
|
|
167
|
+
functionName,
|
|
168
|
+
args = []
|
|
169
|
+
}) => {
|
|
170
|
+
const publicClient = wallet.extend(publicActions);
|
|
171
|
+
return await publicClient.readContract({
|
|
172
|
+
address: address2,
|
|
173
|
+
abi,
|
|
174
|
+
functionName,
|
|
175
|
+
args
|
|
176
|
+
});
|
|
177
|
+
};
|
|
147
178
|
return {
|
|
148
179
|
vmType: "EVM" /* EVM */,
|
|
149
180
|
transport: custom(wallet.transport),
|
|
@@ -151,7 +182,8 @@ var adaptViemWallet = (wallet) => {
|
|
|
151
182
|
address,
|
|
152
183
|
sendTransaction,
|
|
153
184
|
signTypedData,
|
|
154
|
-
switchChain
|
|
185
|
+
switchChain,
|
|
186
|
+
readContract
|
|
155
187
|
};
|
|
156
188
|
};
|
|
157
189
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shogun-sdk/swap",
|
|
3
|
-
"version": "0.0.2-test.
|
|
3
|
+
"version": "0.0.2-test.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shogun Network Swap utilities and helpers",
|
|
6
6
|
"author": "Shogun Network",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@solana/web3.js": "^1.98.4",
|
|
58
58
|
"ethers": "^5.6.1",
|
|
59
59
|
"wagmi": "2.18.0",
|
|
60
|
-
"@shogun-sdk/intents-sdk": "1.2.6-test.
|
|
60
|
+
"@shogun-sdk/intents-sdk": "1.2.6-test.9"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"viem": "^2.38.1",
|