diff --git a/Cargo.lock b/Cargo.lock index 1cd8f9f..d7b3fe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1882,7 +1882,7 @@ dependencies = [ [[package]] name = "jup-ag-sdk" -version = "1.0.3" +version = "1.0.4" dependencies = [ "reqwest 0.12.15", "serde", diff --git a/README.md b/README.md index 964e7c7..d91ee5b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ or Add this to your `Cargo.toml`: ```toml [dependencies] -jup-ag-sdk = "1.0.3" +jup-ag-sdk = "1.0.4" ``` ## Features @@ -83,6 +83,7 @@ async fn main() { - [API Documentation](https://dev.jup.ag/) - [Discord](https://discord.gg/jup) +- [crates.io](https://crates.io/crates/jup-ag-sdk) ## Local diff --git a/examples/src/swap.rs b/examples/src/swap.rs index 190f76f..cebfa82 100644 --- a/examples/src/swap.rs +++ b/examples/src/swap.rs @@ -32,7 +32,11 @@ pub async fn swap() { let quote_res = client.get_quote("e).await.expect("Failed to get quote"); - let payload = SwapRequest::new("input_your_wallet_address", quote_res); + let payload = SwapRequest::new( + "input_your_wallet_address", + "payer_wallet_address", + quote_res, + ); let swap_res: SwapResponse = client .get_swap_transaction(&payload) .await @@ -96,7 +100,11 @@ pub async fn swap_with_instructions() { let quote_res = client.get_quote("e).await.expect("Failed to get quote"); // get swap instructions - let payload = SwapRequest::new("EXBdeRCdiNChKyD7akt64n9HgSXEpUtpPEhmbnm4L6iH", quote_res); + let payload = SwapRequest::new( + "EXBdeRCdiNChKyD7akt64n9HgSXEpUtpPEhmbnm4L6iH", + "payer_wallet_address", + quote_res, + ); let swap_instructions = client .get_swap_instructions(&payload) diff --git a/jup-ag-sdk/Cargo.toml b/jup-ag-sdk/Cargo.toml index eb9b631..8819ffb 100644 --- a/jup-ag-sdk/Cargo.toml +++ b/jup-ag-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jup-ag-sdk" -version = "1.0.3" +version = "1.0.4" edition = "2024" license-file = "../LICENSE" readme = "../README.md" diff --git a/jup-ag-sdk/src/types/swap_transaction.rs b/jup-ag-sdk/src/types/swap_transaction.rs index 3e720d3..fc5f0d5 100644 --- a/jup-ag-sdk/src/types/swap_transaction.rs +++ b/jup-ag-sdk/src/types/swap_transaction.rs @@ -13,6 +13,9 @@ pub struct SwapRequest { /// Rquired. The public key of the user initiating the swap. pub user_public_key: String, + /// Allow a custom payer to pay for the transaction + pub payer: String, + /// Automatically wrap/unwrap native SOL to/from WSOL Default (true) /// When true, uses SOL and unwraps WSOL post-swap. /// When false, uses WSOL only and leaves it wrapped. @@ -113,6 +116,7 @@ impl SwapRequest { /// /// # Arguments /// * `input_wallet` - The user's public key as a string. + /// * `payer` - payer to pay for the transaction /// * `quote` - The `QuoteResponse` obtained from a quoting endpoint. /// /// # Returns @@ -122,9 +126,14 @@ impl SwapRequest { /// ``` /// let payload = SwapRequest::new("YourPubKey...", quote); /// ``` - pub fn new(input_wallet: &str, quote: QuoteResponse) -> Self { + pub fn new( + input_wallet: impl Into, + payer: impl Into, + quote: QuoteResponse, + ) -> Self { Self { - user_public_key: input_wallet.to_string(), + user_public_key: input_wallet.into(), + payer: payer.into(), wrap_and_unwrap_sol: None, use_shared_accounts: None, fee_account: None, diff --git a/tests/src/swap.rs b/tests/src/swap.rs index 30310bd..0213206 100644 --- a/tests/src/swap.rs +++ b/tests/src/swap.rs @@ -131,7 +131,7 @@ mod swap_tests { match client.get_quote("e).await { Ok(quote_res) => { - let swap = SwapRequest::new(TEST_USER_PUBKEY, quote_res); + let swap = SwapRequest::new(TEST_USER_PUBKEY, TEST_USER_PUBKEY, quote_res); assert_eq!( swap.user_public_key, TEST_USER_PUBKEY, @@ -163,7 +163,7 @@ mod swap_tests { Err(err) => panic!("Failed to get quote for swap test: {:?}", err), }; - let swap = SwapRequest::new(TEST_USER_PUBKEY, quote_res); + let swap = SwapRequest::new(TEST_USER_PUBKEY, TEST_USER_PUBKEY, quote_res); match client.get_swap_transaction(&swap).await { Ok(swap_res) => {