From 5c5b42c2f84fc64c6465645ac30e3e3e9f9614f3 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Wed, 19 Jun 2024 13:24:44 -0400 Subject: [PATCH 1/3] Add Jito Smart Transactions and Helper Methods to README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index e2d684e..86ef0eb 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,13 @@ Our SDK is designed to provide a seamless developer experience when building on - [`poll_transaction_confirmation`](https://github.com/helius-labs/helius-rust-sdk/blob/a79a751e1a064125010bdb359068a366d635d005/src/optimized_transaction.rs#L77-L112) - Polls a transaction to check whether it has been confirmed in 5 second intervals with a 15 second timeout - [`send_smart_transaction`](https://github.com/helius-labs/helius-rust-sdk/blob/a79a751e1a064125010bdb359068a366d635d005/src/optimized_transaction.rs#L114-L332) - Builds and sends an optimized transaction, and handles its confirmation status +### Jito Smart Transactions and Helper Methods +- [`add_tip_instruction`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L66-L83) - Adds a tip instruction to the instructions provided +- [`create_smart_transaction_with_tip`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L85-L124) - Creates a smart transaction with a Jito tip +- [`get_bundle_statuses`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L169-L202) - Get the status of Jito bundles +- [`send_jito_bundle`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L126-L167) - Sends a bundle of transactions to the Jito Block Engine +- [`send_smart_transaction_with_tip`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L204-L269) - Sends a smart transaction as a Jito bundle with a tip + ### Helper Methods - [`get_priority_fee_estimate`](https://docs.helius.dev/solana-rpc-nodes/alpha-priority-fee-api) - Gets an estimate of the priority fees required for a transaction to be processed more quickly - [`deserialize_str_to_number`](https://github.com/helius-labs/helius-rust-sdk/blob/dev/src/utils/deserialize_str_to_number.rs) - Deserializes a `String` to a `Number` From 7877c276227098ed082f303f83bfd3f50abd2968 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Wed, 19 Jun 2024 13:35:21 -0400 Subject: [PATCH 2/3] Add send_smart_transaction_with_tip Example --- examples/send_smart_transaction_with_tip.rs | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/send_smart_transaction_with_tip.rs diff --git a/examples/send_smart_transaction_with_tip.rs b/examples/send_smart_transaction_with_tip.rs new file mode 100644 index 0000000..d1b446a --- /dev/null +++ b/examples/send_smart_transaction_with_tip.rs @@ -0,0 +1,69 @@ +use helius::types::*; +use helius::Helius; +use solana_client::rpc_config::RpcSendTransactionConfig; +use solana_sdk::{ + native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction, +}; +use std::str::FromStr; +use std::time::Duration; +use tokio::time::sleep; + +#[tokio::main] +async fn main() { + let api_key: &str = "YOUR_API_KEY"; + let cluster: Cluster = Cluster::MainnetBeta; + let helius: Helius = Helius::new(api_key, cluster).unwrap(); + + // Replace with your actual keypair + let from_keypair: Keypair = Keypair::new(); // Placeholder: Replace with your keypair + let from_pubkey: Pubkey = from_keypair.pubkey(); + + // Replace with the recipient's public key + let to_pubkey: Pubkey = Pubkey::from_str("RecipientPublicKeyHere").unwrap(); // Placeholder: Replace with the recipient's public key + + // Create a simple instruction (transfer 0.01 SOL from from_pubkey to to_pubkey) + let transfer_amount: u64 = 100_000; // 0.01 SOL in lamports + let instructions = vec![system_instruction::transfer(&from_pubkey, &to_pubkey, transfer_amount)]; + + let create_config: CreateSmartTransactionConfig = CreateSmartTransactionConfig { + instructions, + signers: vec![&from_keypair], + lookup_tables: None, + fee_payer: None, + }; + + let config: SmartTransactionConfig = SmartTransactionConfig { + create_config, + send_options: RpcSendTransactionConfig { + skip_preflight: true, + preflight_commitment: None, + encoding: None, + max_retries: None, + min_context_slot: None, + }, + }; + + // Send the optimized transaction with a 10k lamport tip using the New York region's API URL + match helius + .send_smart_transaction_with_tip(config, Some(10000), Some("NY")) + .await + { + Ok(bundle_id) => { + println!("Transaction sent successfully: {}", bundle_id); + sleep(Duration::from_secs(5)).await; + + // Get final balances + let balance_from = helius.connection().get_balance(&from_pubkey).unwrap_or(0); + println!( + "From Wallet Balance: {} SOL", + balance_from as f64 / LAMPORTS_PER_SOL as f64 + ); + + let balance_to = helius.connection().get_balance(&to_pubkey).unwrap_or(0); + println!("To Wallet Balance: {} SOL", balance_to as f64 / LAMPORTS_PER_SOL as f64); + } + Err(e) => { + eprintln!("Failed to send transaction: {:?}", e); + } + } +} From c49e444052203057d32849653c3ee61adb3d243a Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Wed, 19 Jun 2024 14:24:38 -0400 Subject: [PATCH 3/3] Better Types --- examples/send_smart_transaction_with_tip.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/send_smart_transaction_with_tip.rs b/examples/send_smart_transaction_with_tip.rs index d1b446a..2f6fa76 100644 --- a/examples/send_smart_transaction_with_tip.rs +++ b/examples/send_smart_transaction_with_tip.rs @@ -2,7 +2,8 @@ use helius::types::*; use helius::Helius; use solana_client::rpc_config::RpcSendTransactionConfig; use solana_sdk::{ - native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction, + instruction::Instruction, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, signer::Signer, + system_instruction::transfer, }; use std::str::FromStr; use std::time::Duration; @@ -15,15 +16,15 @@ async fn main() { let helius: Helius = Helius::new(api_key, cluster).unwrap(); // Replace with your actual keypair - let from_keypair: Keypair = Keypair::new(); // Placeholder: Replace with your keypair + let from_keypair: Keypair = Keypair::new(); let from_pubkey: Pubkey = from_keypair.pubkey(); // Replace with the recipient's public key - let to_pubkey: Pubkey = Pubkey::from_str("RecipientPublicKeyHere").unwrap(); // Placeholder: Replace with the recipient's public key + let to_pubkey: Pubkey = Pubkey::from_str("RecipientPublicKeyHere").unwrap(); // Create a simple instruction (transfer 0.01 SOL from from_pubkey to to_pubkey) let transfer_amount: u64 = 100_000; // 0.01 SOL in lamports - let instructions = vec![system_instruction::transfer(&from_pubkey, &to_pubkey, transfer_amount)]; + let instructions: Vec = vec![transfer(&from_pubkey, &to_pubkey, transfer_amount)]; let create_config: CreateSmartTransactionConfig = CreateSmartTransactionConfig { instructions,