Skip to content

Commit bebdc6a

Browse files
authored
Merge pull request #18 from thrishank/bump-version-1.0.4
add payer in swap request
2 parents 9ccd38e + e824b78 commit bebdc6a

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ or Add this to your `Cargo.toml`:
1313

1414
```toml
1515
[dependencies]
16-
jup-ag-sdk = "1.0.3"
16+
jup-ag-sdk = "1.0.4"
1717
```
1818

1919
## Features
@@ -83,6 +83,7 @@ async fn main() {
8383

8484
- [API Documentation](https://dev.jup.ag/)
8585
- [Discord](https://discord.gg/jup)
86+
- [crates.io](https://crates.io/crates/jup-ag-sdk)
8687

8788
## Local
8889

examples/src/swap.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ pub async fn swap() {
3232

3333
let quote_res = client.get_quote(&quote).await.expect("Failed to get quote");
3434

35-
let payload = SwapRequest::new("input_your_wallet_address", quote_res);
35+
let payload = SwapRequest::new(
36+
"input_your_wallet_address",
37+
"payer_wallet_address",
38+
quote_res,
39+
);
3640
let swap_res: SwapResponse = client
3741
.get_swap_transaction(&payload)
3842
.await
@@ -96,7 +100,11 @@ pub async fn swap_with_instructions() {
96100
let quote_res = client.get_quote(&quote).await.expect("Failed to get quote");
97101

98102
// get swap instructions
99-
let payload = SwapRequest::new("EXBdeRCdiNChKyD7akt64n9HgSXEpUtpPEhmbnm4L6iH", quote_res);
103+
let payload = SwapRequest::new(
104+
"EXBdeRCdiNChKyD7akt64n9HgSXEpUtpPEhmbnm4L6iH",
105+
"payer_wallet_address",
106+
quote_res,
107+
);
100108

101109
let swap_instructions = client
102110
.get_swap_instructions(&payload)

jup-ag-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jup-ag-sdk"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
edition = "2024"
55
license-file = "../LICENSE"
66
readme = "../README.md"

jup-ag-sdk/src/types/swap_transaction.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub struct SwapRequest {
1313
/// Rquired. The public key of the user initiating the swap.
1414
pub user_public_key: String,
1515

16+
/// Allow a custom payer to pay for the transaction
17+
pub payer: String,
18+
1619
/// Automatically wrap/unwrap native SOL to/from WSOL Default (true)
1720
/// When true, uses SOL and unwraps WSOL post-swap.
1821
/// When false, uses WSOL only and leaves it wrapped.
@@ -113,6 +116,7 @@ impl SwapRequest {
113116
///
114117
/// # Arguments
115118
/// * `input_wallet` - The user's public key as a string.
119+
/// * `payer` - payer to pay for the transaction
116120
/// * `quote` - The `QuoteResponse` obtained from a quoting endpoint.
117121
///
118122
/// # Returns
@@ -122,9 +126,14 @@ impl SwapRequest {
122126
/// ```
123127
/// let payload = SwapRequest::new("YourPubKey...", quote);
124128
/// ```
125-
pub fn new(input_wallet: &str, quote: QuoteResponse) -> Self {
129+
pub fn new(
130+
input_wallet: impl Into<String>,
131+
payer: impl Into<String>,
132+
quote: QuoteResponse,
133+
) -> Self {
126134
Self {
127-
user_public_key: input_wallet.to_string(),
135+
user_public_key: input_wallet.into(),
136+
payer: payer.into(),
128137
wrap_and_unwrap_sol: None,
129138
use_shared_accounts: None,
130139
fee_account: None,

tests/src/swap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod swap_tests {
131131

132132
match client.get_quote(&quote).await {
133133
Ok(quote_res) => {
134-
let swap = SwapRequest::new(TEST_USER_PUBKEY, quote_res);
134+
let swap = SwapRequest::new(TEST_USER_PUBKEY, TEST_USER_PUBKEY, quote_res);
135135

136136
assert_eq!(
137137
swap.user_public_key, TEST_USER_PUBKEY,
@@ -163,7 +163,7 @@ mod swap_tests {
163163
Err(err) => panic!("Failed to get quote for swap test: {:?}", err),
164164
};
165165

166-
let swap = SwapRequest::new(TEST_USER_PUBKEY, quote_res);
166+
let swap = SwapRequest::new(TEST_USER_PUBKEY, TEST_USER_PUBKEY, quote_res);
167167

168168
match client.get_swap_transaction(&swap).await {
169169
Ok(swap_res) => {

0 commit comments

Comments
 (0)