@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 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: () => import_intents_sdk11.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,9 +29,10 @@ __export(core_exports, {
29
29
  getBalances: () => getBalances,
30
30
  getQuote: () => getQuote,
31
31
  getTokenList: () => getTokenList,
32
- isEvmChain: () => import_intents_sdk11.isEvmChain,
32
+ isEvmChain: () => import_intents_sdk12.isEvmChain,
33
33
  isNativeAddress: () => isNativeAddress,
34
34
  isViemWalletClient: () => isViemWalletClient,
35
+ normalizeEvmTokenAddress: () => normalizeEvmTokenAddress,
35
36
  serializeBigIntsToStrings: () => serializeBigIntsToStrings
36
37
  });
37
38
  module.exports = __toCommonJS(core_exports);
@@ -44,12 +45,13 @@ async function getTokenList(params) {
44
45
 
45
46
  // src/core/getQuote.ts
46
47
  var import_intents_sdk4 = require("@shogun-sdk/intents-sdk");
47
- var import_viem = require("viem");
48
+ var import_viem2 = require("viem");
48
49
 
49
50
  // src/core/executeOrder/normalizeNative.ts
50
51
  var import_intents_sdk3 = require("@shogun-sdk/intents-sdk");
51
52
 
52
53
  // src/utils/address.ts
54
+ var import_viem = require("viem");
53
55
  var NATIVE_TOKEN = {
54
56
  ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
55
57
  SOL: "So11111111111111111111111111111111111111111",
@@ -60,6 +62,10 @@ var isNativeAddress = (tokenAddress) => {
60
62
  const normalizedTokenAddress = tokenAddress.toLowerCase();
61
63
  return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
62
64
  };
65
+ function normalizeEvmTokenAddress(address) {
66
+ const lower = address.toLowerCase();
67
+ return lower === NATIVE_TOKEN.ETH.toLowerCase() ? import_viem.zeroAddress : address;
68
+ }
63
69
 
64
70
  // src/utils/chain.ts
65
71
  var import_intents_sdk2 = require("@shogun-sdk/intents-sdk");
@@ -230,7 +236,7 @@ function buildQuoteParams({
230
236
  tokenOut,
231
237
  sourceChainId,
232
238
  destChainId,
233
- amount: (0, import_viem.parseUnits)(amount.toString(), tokenIn.decimals ?? 18),
239
+ amount: (0, import_viem2.parseUnits)(amount.toString(), tokenIn.decimals ?? 18),
234
240
  slippage
235
241
  };
236
242
  }
@@ -285,13 +291,13 @@ async function getBalances(params, options) {
285
291
  }
286
292
 
287
293
  // src/core/executeOrder/execute.ts
288
- var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
289
- var import_viem4 = require("viem");
294
+ var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
295
+ var import_viem6 = require("viem");
290
296
 
291
297
  // src/wallet-adapter/evm-wallet-adapter/adapter.ts
292
298
  var import_ethers = require("ethers/lib/ethers.js");
293
299
  var import_utils2 = require("ethers/lib/utils.js");
294
- var import_viem2 = require("viem");
300
+ var import_viem3 = require("viem");
295
301
  function isEVMTransaction(tx) {
296
302
  return typeof tx.from === "string";
297
303
  }
@@ -351,20 +357,35 @@ var adaptViemWallet = (wallet) => {
351
357
  if (!addr) throw new Error("No address found");
352
358
  return addr;
353
359
  };
360
+ const readContract = async ({
361
+ address: address2,
362
+ abi,
363
+ functionName,
364
+ args = []
365
+ }) => {
366
+ const publicClient = wallet.extend(import_viem3.publicActions);
367
+ return await publicClient.readContract({
368
+ address: address2,
369
+ abi,
370
+ functionName,
371
+ args
372
+ });
373
+ };
354
374
  return {
355
375
  vmType: "EVM" /* EVM */,
356
- transport: (0, import_viem2.custom)(wallet.transport),
376
+ transport: (0, import_viem3.custom)(wallet.transport),
357
377
  getChainId: async () => wallet.getChainId(),
358
378
  address,
359
379
  sendTransaction,
360
380
  signTypedData,
361
- switchChain
381
+ switchChain,
382
+ readContract
362
383
  };
363
384
  };
364
385
 
365
386
  // src/core/executeOrder/handleEvmExecution.ts
366
- var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
367
- var import_viem3 = require("viem");
387
+ var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
388
+ var import_viem5 = require("viem");
368
389
 
369
390
  // src/core/executeOrder/stageMessages.ts
370
391
  var DEFAULT_STAGE_MESSAGES = {
@@ -519,6 +540,51 @@ async function handleOrderPollingResult({
519
540
  };
520
541
  }
521
542
 
543
+ // src/core/executeOrder/ensurePermit2Allowance.ts
544
+ var import_viem4 = require("viem");
545
+ var import_intents_sdk8 = require("@shogun-sdk/intents-sdk");
546
+ async function ensurePermit2Allowance({
547
+ chainId,
548
+ tokenIn,
549
+ wallet,
550
+ accountAddress,
551
+ requiredAmount,
552
+ increaseByDelta = false
553
+ }) {
554
+ const spender = import_intents_sdk8.PERMIT2_ADDRESS[chainId];
555
+ let currentAllowance = 0n;
556
+ try {
557
+ if (!wallet.readContract) {
558
+ throw new Error("Wallet does not implement readContract()");
559
+ }
560
+ currentAllowance = await wallet.readContract({
561
+ address: tokenIn,
562
+ abi: import_viem4.erc20Abi,
563
+ functionName: "allowance",
564
+ args: [accountAddress, spender]
565
+ });
566
+ } catch (error) {
567
+ console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
568
+ }
569
+ const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : import_viem4.maxUint256;
570
+ console.debug(
571
+ `[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
572
+ );
573
+ await wallet.sendTransaction({
574
+ to: tokenIn,
575
+ from: accountAddress,
576
+ data: (0, import_viem4.encodeFunctionData)({
577
+ abi: import_viem4.erc20Abi,
578
+ functionName: "approve",
579
+ args: [spender, approvalAmount]
580
+ }),
581
+ value: 0n
582
+ });
583
+ console.info(
584
+ `[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
585
+ );
586
+ }
587
+
522
588
  // src/core/executeOrder/handleEvmExecution.ts
523
589
  async function handleEvmExecution({
524
590
  recipientAddress,
@@ -533,12 +599,13 @@ async function handleEvmExecution({
533
599
  const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
534
600
  await wallet.switchChain(chainId);
535
601
  const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
602
+ quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
536
603
  const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
537
604
  update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
538
605
  if (shouldWrapNative) {
539
606
  await wallet.sendTransaction({
540
607
  to: tokenIn,
541
- data: (0, import_viem3.encodeFunctionData)({
608
+ data: (0, import_viem5.encodeFunctionData)({
542
609
  abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
543
610
  functionName: "deposit",
544
611
  args: []
@@ -548,15 +615,12 @@ async function handleEvmExecution({
548
615
  });
549
616
  }
550
617
  update("processing", messageFor("approving"));
551
- await wallet.sendTransaction({
552
- to: tokenIn,
553
- data: (0, import_viem3.encodeFunctionData)({
554
- abi: import_viem3.erc20Abi,
555
- functionName: "approve",
556
- args: [import_intents_sdk8.PERMIT2_ADDRESS[chainId], quote.amountIn]
557
- }),
558
- value: 0n,
559
- from: accountAddress
618
+ await ensurePermit2Allowance({
619
+ chainId,
620
+ tokenIn,
621
+ wallet,
622
+ accountAddress,
623
+ requiredAmount: BigInt(quote.amountIn)
560
624
  });
561
625
  update("processing", messageFor("approved"));
562
626
  const destination = recipientAddress ?? accountAddress;
@@ -569,7 +633,7 @@ async function handleEvmExecution({
569
633
  });
570
634
  console.debug(`order`, order);
571
635
  update("processing", messageFor("signing"));
572
- const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk8.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk8.getEVMCrossChainOrderTypedData)(order);
636
+ const { orderTypedData, nonce } = isSingleChain ? await (0, import_intents_sdk9.getEVMSingleChainOrderTypedData)(order) : await (0, import_intents_sdk9.getEVMCrossChainOrderTypedData)(order);
573
637
  const typedData = serializeBigIntsToStrings(orderTypedData);
574
638
  if (!wallet.signTypedData) {
575
639
  throw new Error("Wallet does not support EIP-712 signing");
@@ -600,7 +664,7 @@ async function handleEvmExecution({
600
664
  }
601
665
 
602
666
  // src/core/executeOrder/handleSolanaExecution.ts
603
- var import_intents_sdk9 = require("@shogun-sdk/intents-sdk");
667
+ var import_intents_sdk10 = require("@shogun-sdk/intents-sdk");
604
668
  var import_web3 = require("@solana/web3.js");
605
669
  async function handleSolanaExecution({
606
670
  recipientAddress,
@@ -659,11 +723,11 @@ async function getSolanaOrderInstructions({
659
723
  rpcUrl
660
724
  }) {
661
725
  if (isSingleChain) {
662
- return await (0, import_intents_sdk9.getSolanaSingleChainOrderInstructions)(order, {
726
+ return await (0, import_intents_sdk10.getSolanaSingleChainOrderInstructions)(order, {
663
727
  rpcUrl
664
728
  });
665
729
  }
666
- return await (0, import_intents_sdk9.getSolanaCrossChainOrderInstructions)(order, {
730
+ return await (0, import_intents_sdk10.getSolanaCrossChainOrderInstructions)(order, {
667
731
  rpcUrl
668
732
  });
669
733
  }
@@ -717,7 +781,7 @@ async function executeOrder({
717
781
  const isSingleChain = tokenIn.chainId === tokenOut.chainId;
718
782
  const chainId = Number(tokenIn.chainId);
719
783
  update("processing");
720
- if ((0, import_intents_sdk10.isEvmChain)(chainId)) {
784
+ if ((0, import_intents_sdk11.isEvmChain)(chainId)) {
721
785
  log("Detected EVM chain:", chainId);
722
786
  const result = await handleEvmExecution({
723
787
  recipientAddress,
@@ -732,7 +796,7 @@ async function executeOrder({
732
796
  log("EVM execution result:", result);
733
797
  return result;
734
798
  }
735
- if (chainId === import_intents_sdk10.ChainID.Solana) {
799
+ if (chainId === import_intents_sdk11.ChainID.Solana) {
736
800
  log("Detected Solana chain");
737
801
  const result = await handleSolanaExecution({
738
802
  recipientAddress,
@@ -751,7 +815,7 @@ async function executeOrder({
751
815
  log("Error:", unsupported);
752
816
  return { status: false, message: unsupported, stage: "error" };
753
817
  } catch (error) {
754
- const message = error instanceof import_viem4.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
818
+ const message = error instanceof import_viem6.BaseError ? error.shortMessage : error instanceof Error ? error.message : String(error);
755
819
  log("Execution failed:", { message, error });
756
820
  update("error", message);
757
821
  return { status: false, message, stage: "error" };
@@ -764,4 +828,4 @@ function normalizeWallet(wallet) {
764
828
  }
765
829
 
766
830
  // src/core/index.ts
767
- var import_intents_sdk11 = require("@shogun-sdk/intents-sdk");
831
+ 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-DOv1i2Su.cjs';
4
- export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-DOv1i2Su.cjs';
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-MmUIz8GE.cjs';
6
+ import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
7
7
  import '@mysten/sui/transactions';
8
8
  import '@solana/web3.js';
9
9
 
@@ -129,9 +129,10 @@ declare const NATIVE_TOKEN: {
129
129
  readonly SUI: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
130
130
  };
131
131
  declare const isNativeAddress: (tokenAddress: string) => boolean;
132
+ declare function normalizeEvmTokenAddress(address: string): string;
132
133
 
133
134
  declare function isViemWalletClient(wallet: WalletClient | AdaptedWallet): wallet is WalletClient;
134
135
 
135
136
  declare function serializeBigIntsToStrings<T>(obj: T): T;
136
137
 
137
- export { BalanceRequestParams, BalanceResponse, NATIVE_TOKEN, QuoteTokenInfo, SOLANA_CHAIN_ID, SupportedChains, SwapQuoteParams, SwapQuoteResponse, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, serializeBigIntsToStrings };
138
+ export { BalanceRequestParams, BalanceResponse, NATIVE_TOKEN, QuoteTokenInfo, SOLANA_CHAIN_ID, SupportedChains, SwapQuoteParams, SwapQuoteResponse, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, normalizeEvmTokenAddress, serializeBigIntsToStrings };
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-CKTsf_tD.js';
4
- export { P as PlaceOrderResult, b as Stage, T as TokenBalance, f as TokenInfo, d as TokenSearchResponse, e as executeOrder } from './execute-CKTsf_tD.js';
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-MmUIz8GE.js';
6
+ import { A as AdaptedWallet } from './wallet-BhuMJ3K_.js';
7
7
  import '@mysten/sui/transactions';
8
8
  import '@solana/web3.js';
9
9
 
@@ -129,9 +129,10 @@ declare const NATIVE_TOKEN: {
129
129
  readonly SUI: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
130
130
  };
131
131
  declare const isNativeAddress: (tokenAddress: string) => boolean;
132
+ declare function normalizeEvmTokenAddress(address: string): string;
132
133
 
133
134
  declare function isViemWalletClient(wallet: WalletClient | AdaptedWallet): wallet is WalletClient;
134
135
 
135
136
  declare function serializeBigIntsToStrings<T>(obj: T): T;
136
137
 
137
- export { BalanceRequestParams, BalanceResponse, NATIVE_TOKEN, QuoteTokenInfo, SOLANA_CHAIN_ID, SupportedChains, SwapQuoteParams, SwapQuoteResponse, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, serializeBigIntsToStrings };
138
+ export { BalanceRequestParams, BalanceResponse, NATIVE_TOKEN, QuoteTokenInfo, SOLANA_CHAIN_ID, SupportedChains, SwapQuoteParams, SwapQuoteResponse, buildQuoteParams, getBalances, getQuote, getTokenList, isNativeAddress, isViemWalletClient, normalizeEvmTokenAddress, serializeBigIntsToStrings };
package/dist/core.js CHANGED
@@ -12,6 +12,7 @@ import { parseUnits } from "viem";
12
12
  import { isEvmChain } from "@shogun-sdk/intents-sdk";
13
13
 
14
14
  // src/utils/address.ts
15
+ import { zeroAddress } from "viem";
15
16
  var NATIVE_TOKEN = {
16
17
  ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
17
18
  SOL: "So11111111111111111111111111111111111111111",
@@ -22,6 +23,10 @@ var isNativeAddress = (tokenAddress) => {
22
23
  const normalizedTokenAddress = tokenAddress.toLowerCase();
23
24
  return !!tokenAddress && NATIVE_ADDRESSES.includes(normalizedTokenAddress);
24
25
  };
26
+ function normalizeEvmTokenAddress(address) {
27
+ const lower = address.toLowerCase();
28
+ return lower === NATIVE_TOKEN.ETH.toLowerCase() ? zeroAddress : address;
29
+ }
25
30
 
26
31
  // src/utils/chain.ts
27
32
  import { ChainID } from "@shogun-sdk/intents-sdk";
@@ -251,10 +256,11 @@ import { ChainID as ChainID3, isEvmChain as isEvmChain2 } from "@shogun-sdk/inte
251
256
  import { BaseError } from "viem";
252
257
 
253
258
  // src/wallet-adapter/evm-wallet-adapter/adapter.ts
254
- import "ethers/lib/ethers.js";
259
+ import { utils as ethersUtils } from "ethers/lib/ethers.js";
255
260
  import { hexValue } from "ethers/lib/utils.js";
256
261
  import {
257
- custom
262
+ custom,
263
+ publicActions
258
264
  } from "viem";
259
265
  function isEVMTransaction(tx) {
260
266
  return typeof tx.from === "string";
@@ -315,6 +321,20 @@ var adaptViemWallet = (wallet) => {
315
321
  if (!addr) throw new Error("No address found");
316
322
  return addr;
317
323
  };
324
+ const readContract = async ({
325
+ address: address2,
326
+ abi,
327
+ functionName,
328
+ args = []
329
+ }) => {
330
+ const publicClient = wallet.extend(publicActions);
331
+ return await publicClient.readContract({
332
+ address: address2,
333
+ abi,
334
+ functionName,
335
+ args
336
+ });
337
+ };
318
338
  return {
319
339
  vmType: "EVM" /* EVM */,
320
340
  transport: custom(wallet.transport),
@@ -322,17 +342,17 @@ var adaptViemWallet = (wallet) => {
322
342
  address,
323
343
  sendTransaction,
324
344
  signTypedData,
325
- switchChain
345
+ switchChain,
346
+ readContract
326
347
  };
327
348
  };
328
349
 
329
350
  // src/core/executeOrder/handleEvmExecution.ts
330
351
  import {
331
352
  getEVMSingleChainOrderTypedData,
332
- getEVMCrossChainOrderTypedData,
333
- PERMIT2_ADDRESS
353
+ getEVMCrossChainOrderTypedData
334
354
  } from "@shogun-sdk/intents-sdk";
335
- import { encodeFunctionData, erc20Abi } from "viem";
355
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
336
356
 
337
357
  // src/core/executeOrder/stageMessages.ts
338
358
  var DEFAULT_STAGE_MESSAGES = {
@@ -487,6 +507,51 @@ async function handleOrderPollingResult({
487
507
  };
488
508
  }
489
509
 
510
+ // src/core/executeOrder/ensurePermit2Allowance.ts
511
+ import { encodeFunctionData, erc20Abi, maxUint256 } from "viem";
512
+ import { PERMIT2_ADDRESS } from "@shogun-sdk/intents-sdk";
513
+ async function ensurePermit2Allowance({
514
+ chainId,
515
+ tokenIn,
516
+ wallet,
517
+ accountAddress,
518
+ requiredAmount,
519
+ increaseByDelta = false
520
+ }) {
521
+ const spender = PERMIT2_ADDRESS[chainId];
522
+ let currentAllowance = 0n;
523
+ try {
524
+ if (!wallet.readContract) {
525
+ throw new Error("Wallet does not implement readContract()");
526
+ }
527
+ currentAllowance = await wallet.readContract({
528
+ address: tokenIn,
529
+ abi: erc20Abi,
530
+ functionName: "allowance",
531
+ args: [accountAddress, spender]
532
+ });
533
+ } catch (error) {
534
+ console.warn(`[Permit2] Failed to read allowance for ${tokenIn}`, error);
535
+ }
536
+ const approvalAmount = increaseByDelta ? currentAllowance + requiredAmount : maxUint256;
537
+ console.debug(
538
+ `[Permit2] Approving ${approvalAmount} for ${tokenIn} (current: ${currentAllowance}, required: ${requiredAmount})`
539
+ );
540
+ await wallet.sendTransaction({
541
+ to: tokenIn,
542
+ from: accountAddress,
543
+ data: encodeFunctionData({
544
+ abi: erc20Abi,
545
+ functionName: "approve",
546
+ args: [spender, approvalAmount]
547
+ }),
548
+ value: 0n
549
+ });
550
+ console.info(
551
+ `[Permit2] Approval transaction sent for ${tokenIn} on chain ${chainId}`
552
+ );
553
+ }
554
+
490
555
  // src/core/executeOrder/handleEvmExecution.ts
491
556
  async function handleEvmExecution({
492
557
  recipientAddress,
@@ -501,12 +566,13 @@ async function handleEvmExecution({
501
566
  const messageFor = (stage) => DEFAULT_STAGE_MESSAGES[stage];
502
567
  await wallet.switchChain(chainId);
503
568
  const tokenIn = normalizeNative(chainId, quote.tokenIn.address);
569
+ quote.tokenOut.address = normalizeEvmTokenAddress(quote.tokenOut.address);
504
570
  const shouldWrapNative = isNativeAddress(quote.tokenIn.address);
505
571
  update("processing", shouldWrapNative ? `${messageFor("processing")} (wrapping native token)` : messageFor("processing"));
506
572
  if (shouldWrapNative) {
507
573
  await wallet.sendTransaction({
508
574
  to: tokenIn,
509
- data: encodeFunctionData({
575
+ data: encodeFunctionData2({
510
576
  abi: [{ type: "function", name: "deposit", stateMutability: "payable", inputs: [], outputs: [] }],
511
577
  functionName: "deposit",
512
578
  args: []
@@ -516,15 +582,12 @@ async function handleEvmExecution({
516
582
  });
517
583
  }
518
584
  update("processing", messageFor("approving"));
519
- await wallet.sendTransaction({
520
- to: tokenIn,
521
- data: encodeFunctionData({
522
- abi: erc20Abi,
523
- functionName: "approve",
524
- args: [PERMIT2_ADDRESS[chainId], quote.amountIn]
525
- }),
526
- value: 0n,
527
- from: accountAddress
585
+ await ensurePermit2Allowance({
586
+ chainId,
587
+ tokenIn,
588
+ wallet,
589
+ accountAddress,
590
+ requiredAmount: BigInt(quote.amountIn)
528
591
  });
529
592
  update("processing", messageFor("approved"));
530
593
  const destination = recipientAddress ?? accountAddress;
@@ -749,5 +812,6 @@ export {
749
812
  isEvmChain3 as isEvmChain,
750
813
  isNativeAddress,
751
814
  isViemWalletClient,
815
+ normalizeEvmTokenAddress,
752
816
  serializeBigIntsToStrings
753
817
  };
@@ -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-MmUIz8GE.js';
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-MmUIz8GE.cjs';
3
+ import { A as AdaptedWallet } from './wallet-BhuMJ3K_.cjs';
4
4
 
5
5
  /**
6
6
  * Token metadata used in quotes.