@shapeshiftoss/swap-widget 0.5.2 → 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.
- package/dist/index.js +50 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2459,13 +2459,13 @@ var executeEvm = async (txData, walletClient, walletAddress) => {
|
|
|
2459
2459
|
account: getAddress2(walletAddress)
|
|
2460
2460
|
});
|
|
2461
2461
|
};
|
|
2462
|
-
var
|
|
2462
|
+
var executeUtxo = (txData, bitcoin3) => {
|
|
2463
2463
|
if (!bitcoin3.isConnected || !bitcoin3.address) throw new Error("Bitcoin wallet not connected");
|
|
2464
2464
|
bitcoin3.reset();
|
|
2465
2465
|
return bitcoin3.sendTransfer({
|
|
2466
|
-
recipientAddress: txData.
|
|
2466
|
+
recipientAddress: txData.to,
|
|
2467
2467
|
amount: txData.value,
|
|
2468
|
-
memo: txData.
|
|
2468
|
+
memo: txData.opReturnData
|
|
2469
2469
|
});
|
|
2470
2470
|
};
|
|
2471
2471
|
var executeSolana = async (txData, solana3) => {
|
|
@@ -2473,7 +2473,13 @@ var executeSolana = async (txData, solana3) => {
|
|
|
2473
2473
|
throw new Error("Solana wallet not connected");
|
|
2474
2474
|
}
|
|
2475
2475
|
solana3.reset();
|
|
2476
|
-
const {
|
|
2476
|
+
const {
|
|
2477
|
+
ComputeBudgetProgram,
|
|
2478
|
+
PublicKey: PublicKey3,
|
|
2479
|
+
TransactionInstruction,
|
|
2480
|
+
TransactionMessage,
|
|
2481
|
+
VersionedTransaction
|
|
2482
|
+
} = await import("@solana/web3.js");
|
|
2477
2483
|
const instructions = txData.instructions.map((ix) => {
|
|
2478
2484
|
return new TransactionInstruction({
|
|
2479
2485
|
keys: ix.keys.map((key) => ({
|
|
@@ -2485,11 +2491,41 @@ var executeSolana = async (txData, solana3) => {
|
|
|
2485
2491
|
data: Buffer.from(ix.data, "base64")
|
|
2486
2492
|
});
|
|
2487
2493
|
});
|
|
2488
|
-
const transaction = new Transaction().add(...instructions);
|
|
2489
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);
|
|
2490
2512
|
const { blockhash } = await conn.getLatestBlockhash("confirmed");
|
|
2491
|
-
|
|
2492
|
-
|
|
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
|
+
);
|
|
2493
2529
|
return solana3.sendTransaction({ transaction });
|
|
2494
2530
|
};
|
|
2495
2531
|
var useSwapExecution = () => {
|
|
@@ -2525,12 +2561,14 @@ var useSwapExecution = () => {
|
|
|
2525
2561
|
switch (txData.type) {
|
|
2526
2562
|
case "evm":
|
|
2527
2563
|
return executeEvm(txData, walletClient, walletAddress);
|
|
2528
|
-
case "
|
|
2529
|
-
return
|
|
2530
|
-
case "
|
|
2564
|
+
case "utxo":
|
|
2565
|
+
return executeUtxo(txData, bitcoin3);
|
|
2566
|
+
case "solana_instructions":
|
|
2531
2567
|
return executeSolana(txData, solana3);
|
|
2532
|
-
case "
|
|
2533
|
-
|
|
2568
|
+
case "solana_serialized_tx":
|
|
2569
|
+
return executeSolanaSerializedTx(txData, solana3);
|
|
2570
|
+
case "cosmossdk_msg_send":
|
|
2571
|
+
case "cosmossdk_msg_deposit":
|
|
2534
2572
|
throw new Error("This swap is not yet supported \u2014 please try a different route");
|
|
2535
2573
|
default: {
|
|
2536
2574
|
const _exhaustive = txData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swap-widget",
|
|
3
|
-
"version": "0.
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"react-virtuoso": "^4.7.11",
|
|
32
32
|
"xstate": "5.28.0",
|
|
33
33
|
"@shapeshiftoss/caip": "^8.16.10",
|
|
34
|
-
"@shapeshiftoss/types": "^
|
|
34
|
+
"@shapeshiftoss/types": "^9.0.0",
|
|
35
35
|
"@shapeshiftoss/utils": "^1.1.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|