diff --git a/Cargo.toml b/Cargo.toml index 1f2d066..6fd79e9 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sol-trade-sdk" -version = "3.2.0" +version = "3.2.1" edition = "2021" authors = [ "William ", diff --git a/README.md b/README.md index f44a32b..ec24d64 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.0" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.1" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -sol-trade-sdk = "3.2.0" +sol-trade-sdk = "3.2.1" ``` ## 🛠️ Usage Examples diff --git a/README_CN.md b/README_CN.md index 3b2978c..35387ce 100755 --- a/README_CN.md +++ b/README_CN.md @@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.0" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.2.1" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = "3.2.0" +sol-trade-sdk = "3.2.1" ``` ## 🛠️ 使用示例 diff --git a/src/lib.rs b/src/lib.rs index a356d68..d56ae06 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -619,4 +619,42 @@ impl SolanaTrade { let signature = self.rpc.send_and_confirm_transaction(&transaction).await?; Ok(signature.to_string()) } + + /// Creates a wSOL associated token account (ATA) without wrapping any SOL + /// + /// This function only creates the wSOL associated token account for the payer + /// without transferring any SOL into it. This is useful when you want to set up + /// the account infrastructure in advance without committing funds yet. + /// + /// # Returns + /// * `Ok(String)` - Transaction signature if successful + /// * `Err(anyhow::Error)` - If the transaction fails to execute + /// + /// # Errors + /// + /// This function will return an error if: + /// - wSOL ATA account already exists (idempotent, will succeed silently) + /// - Transaction fails to execute or confirm + /// - Network or RPC errors occur + /// - Insufficient SOL for transaction fees + pub async fn create_wsol_ata(&self) -> Result { + use crate::trading::common::wsol_manager::create_wsol_ata; + use solana_sdk::transaction::Transaction; + + let recent_blockhash = self.rpc.get_latest_blockhash().await?; + let instructions = create_wsol_ata(&self.payer.pubkey()); + + // If instructions are empty, ATA already exists + if instructions.is_empty() { + return Err(anyhow::anyhow!( + "wSOL ATA already exists or no instructions needed" + )); + } + + let mut transaction = + Transaction::new_with_payer(&instructions, Some(&self.payer.pubkey())); + transaction.sign(&[&*self.payer], recent_blockhash); + let signature = self.rpc.send_and_confirm_transaction(&transaction).await?; + Ok(signature.to_string()) + } }