@shapeshiftoss/swap-widget 0.5.1 → 0.6.0

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.
Files changed (2) hide show
  1. package/dist/index.js +51 -22
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -108,7 +108,6 @@ import { createPublicClient, http } from "viem";
108
108
  import { mainnet as mainnet2 } from "viem/chains";
109
109
 
110
110
  // src/constants/viemChains.ts
111
- import { defineChain } from "viem";
112
111
  import {
113
112
  arbitrum,
114
113
  avalanche,
@@ -118,20 +117,12 @@ import {
118
117
  hyperEvm,
119
118
  katana,
120
119
  mainnet,
120
+ megaeth,
121
121
  monad,
122
122
  optimism,
123
123
  plasma,
124
124
  polygon
125
125
  } from "viem/chains";
126
- var megaeth = defineChain({
127
- id: 4326,
128
- name: "MegaETH",
129
- nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
130
- rpcUrls: { default: { http: ["https://mainnet.megaeth.com/rpc"] } },
131
- blockExplorers: {
132
- default: { name: "MegaETH Explorer", url: "https://megaeth.blockscout.com" }
133
- }
134
- });
135
126
  var VIEM_CHAINS_BY_ID = {
136
127
  [mainnet.id]: {
137
128
  ...mainnet,
@@ -2468,13 +2459,13 @@ var executeEvm = async (txData, walletClient, walletAddress) => {
2468
2459
  account: getAddress2(walletAddress)
2469
2460
  });
2470
2461
  };
2471
- var executeUtxoDeposit = (txData, bitcoin3) => {
2462
+ var executeUtxo = (txData, bitcoin3) => {
2472
2463
  if (!bitcoin3.isConnected || !bitcoin3.address) throw new Error("Bitcoin wallet not connected");
2473
2464
  bitcoin3.reset();
2474
2465
  return bitcoin3.sendTransfer({
2475
- recipientAddress: txData.depositAddress,
2466
+ recipientAddress: txData.to,
2476
2467
  amount: txData.value,
2477
- memo: txData.memo
2468
+ memo: txData.opReturnData
2478
2469
  });
2479
2470
  };
2480
2471
  var executeSolana = async (txData, solana3) => {
@@ -2482,7 +2473,13 @@ var executeSolana = async (txData, solana3) => {
2482
2473
  throw new Error("Solana wallet not connected");
2483
2474
  }
2484
2475
  solana3.reset();
2485
- const { Transaction, PublicKey: PublicKey3, TransactionInstruction } = await import("@solana/web3.js");
2476
+ const {
2477
+ ComputeBudgetProgram,
2478
+ PublicKey: PublicKey3,
2479
+ TransactionInstruction,
2480
+ TransactionMessage,
2481
+ VersionedTransaction
2482
+ } = await import("@solana/web3.js");
2486
2483
  const instructions = txData.instructions.map((ix) => {
2487
2484
  return new TransactionInstruction({
2488
2485
  keys: ix.keys.map((key) => ({
@@ -2494,11 +2491,41 @@ var executeSolana = async (txData, solana3) => {
2494
2491
  data: Buffer.from(ix.data, "base64")
2495
2492
  });
2496
2493
  });
2497
- const transaction = new Transaction().add(...instructions);
2498
2494
  const conn = solana3.connection;
2495
+ const includeComputeBudget = instructions.some(
2496
+ (ix) => ix.programId.equals(ComputeBudgetProgram.programId)
2497
+ );
2498
+ if (includeComputeBudget) {
2499
+ const recentFees = await conn.getRecentPrioritizationFees();
2500
+ const fees = recentFees.map((fee) => fee.prioritizationFee).filter((fee) => fee > 0).sort((a, b) => a - b);
2501
+ const priorityFee = fees[Math.floor(fees.length * 0.75)] ?? 0;
2502
+ if (priorityFee > 0) {
2503
+ instructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee }));
2504
+ }
2505
+ }
2506
+ const lookupTableAccounts = (await Promise.all(
2507
+ txData.addressLookupTableAddresses.map(async (address) => {
2508
+ const { value } = await conn.getAddressLookupTable(new PublicKey3(address));
2509
+ return value;
2510
+ })
2511
+ )).filter((account) => account !== null);
2499
2512
  const { blockhash } = await conn.getLatestBlockhash("confirmed");
2500
- transaction.recentBlockhash = blockhash;
2501
- transaction.feePayer = new PublicKey3(solana3.address);
2513
+ const message = new TransactionMessage({
2514
+ payerKey: new PublicKey3(solana3.address),
2515
+ recentBlockhash: blockhash,
2516
+ instructions
2517
+ }).compileToV0Message(lookupTableAccounts);
2518
+ return solana3.sendTransaction({ transaction: new VersionedTransaction(message) });
2519
+ };
2520
+ var executeSolanaSerializedTx = async (txData, solana3) => {
2521
+ if (!solana3.isConnected || !solana3.address || !solana3.connection) {
2522
+ throw new Error("Solana wallet not connected");
2523
+ }
2524
+ solana3.reset();
2525
+ const { VersionedTransaction } = await import("@solana/web3.js");
2526
+ const transaction = VersionedTransaction.deserialize(
2527
+ new Uint8Array(Buffer.from(txData.serializedTx, "base64"))
2528
+ );
2502
2529
  return solana3.sendTransaction({ transaction });
2503
2530
  };
2504
2531
  var useSwapExecution = () => {
@@ -2534,12 +2561,14 @@ var useSwapExecution = () => {
2534
2561
  switch (txData.type) {
2535
2562
  case "evm":
2536
2563
  return executeEvm(txData, walletClient, walletAddress);
2537
- case "utxo_deposit":
2538
- return executeUtxoDeposit(txData, bitcoin3);
2539
- case "solana":
2564
+ case "utxo":
2565
+ return executeUtxo(txData, bitcoin3);
2566
+ case "solana_instructions":
2540
2567
  return executeSolana(txData, solana3);
2541
- case "utxo_psbt":
2542
- case "cosmos":
2568
+ case "solana_serialized_tx":
2569
+ return executeSolanaSerializedTx(txData, solana3);
2570
+ case "cosmossdk_msg_send":
2571
+ case "cosmossdk_msg_deposit":
2543
2572
  throw new Error("This swap is not yet supported \u2014 please try a different route");
2544
2573
  default: {
2545
2574
  const _exhaustive = txData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swap-widget",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Embeddable swap widget using ShapeShift API",
5
5
  "repository": "https://github.com/shapeshift/web",
6
6
  "license": "MIT",
@@ -30,9 +30,9 @@
30
30
  "p-queue": "^8.0.1",
31
31
  "react-virtuoso": "^4.7.11",
32
32
  "xstate": "5.28.0",
33
- "@shapeshiftoss/caip": "^8.16.9",
34
- "@shapeshiftoss/utils": "^1.1.0",
35
- "@shapeshiftoss/types": "^8.6.8"
33
+ "@shapeshiftoss/caip": "^8.16.10",
34
+ "@shapeshiftoss/types": "^9.0.0",
35
+ "@shapeshiftoss/utils": "^1.1.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@wagmi/core": "^2.0.0",
@@ -45,7 +45,7 @@
45
45
  "@tanstack/react-query": "^5.69.0",
46
46
  "react": "^18.0.0 || ^19.0.0",
47
47
  "react-dom": "^18.0.0 || ^19.0.0",
48
- "viem": "^2.43.5",
48
+ "viem": "^2.45.0",
49
49
  "wagmi": "^2.19.5"
50
50
  },
51
51
  "peerDependenciesMeta": {
@@ -88,7 +88,7 @@
88
88
  "react-dom": "^19.0.0",
89
89
  "tsup": "^8.5.1",
90
90
  "typescript": "~5.2.2",
91
- "viem": "2.43.5",
91
+ "viem": "2.46.3",
92
92
  "vite": "^5.0.0",
93
93
  "vite-plugin-node-polyfills": "0.23.0",
94
94
  "wagmi": "2.19.5"