Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Dec 21, 2023
1 parent 999f70b commit 67dd522
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> jup_ag::Result<()> {
let route = quote
.swap_info
.label
.unwrap_or_else(||"Unknown DEX".to_string());
.unwrap_or_else(|| "Unknown DEX".to_string());
println!(
"{}. {} {} for {} {} via {} (worst case with slippage: {}). Impact: {:.2}%",
i,
Expand Down
23 changes: 14 additions & 9 deletions examples/swap.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use jup_ag::{SwapRequest, QuoteConfig};
use jup_ag::{QuoteConfig, SwapRequest};
use solana_sdk::transaction::VersionedTransaction;

use {
itertools::Itertools,
solana_client::nonblocking::rpc_client::RpcClient,
solana_sdk::{
commitment_config::CommitmentConfig,
hash::Hash,
pubkey,
signature::{read_keypair_file, Keypair, Signer},
hash::Hash,
},
spl_token::{amount_to_ui_amount, ui_amount_to_amount},
};
Expand Down Expand Up @@ -66,11 +66,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.await?;

let route = quotes
.route_plan[0]
let route = quotes.route_plan[0]
.swap_info
.label.clone()
.unwrap_or_else(||"Unknown DEX".to_string());
.label
.clone()
.unwrap_or_else(|| "Unknown DEX".to_string());
println!(
"Quote: {} SOL for {} mSOL via {} (worst case with slippage: {}). Impact: {:.2}%",
amount_to_ui_amount(quotes.in_amount, 9),
Expand All @@ -82,11 +82,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let request: SwapRequest = SwapRequest::new(keypair.pubkey(), quotes.clone());

let jup_ag::Swap { mut swap_transaction, last_valid_block_height: _ } = jup_ag::swap(request).await?;
let jup_ag::Swap {
mut swap_transaction,
last_valid_block_height: _,
} = jup_ag::swap(request).await?;

let recent_blockhash_for_swap: Hash = rpc_client.get_latest_blockhash().await?;
swap_transaction.message.set_recent_blockhash(recent_blockhash_for_swap); // Updating to latest blockhash to not error out

swap_transaction
.message
.set_recent_blockhash(recent_blockhash_for_swap); // Updating to latest blockhash to not error out

let swap_transaction = VersionedTransaction::try_new(swap_transaction.message, &[&keypair])?;
println!(
"Simulating swap transaction: {}",
Expand Down
2 changes: 1 addition & 1 deletion src/field_option_pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ where
Some(pubkey) => pubkey.to_string().serialize(serializer),
None => serializer.serialize_none(),
}
}
}
14 changes: 4 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ where
}

/// Get simple price for a given input mint, output mint and amount
pub async fn price(
input_mint: Pubkey,
output_mint: Pubkey,
ui_amount: f64,
) -> Result<Price> {
pub async fn price(input_mint: Pubkey, output_mint: Pubkey, ui_amount: f64) -> Result<Price> {
let url =
format!("{PRICE_API_URL}/price?id={input_mint}&vsToken={output_mint}&amount={ui_amount}");
maybe_jupiter_api_error(reqwest::get(url).await?.json().await?)
Expand Down Expand Up @@ -257,7 +253,7 @@ pub struct SwapRequest {
pub as_legacy_transaction: Option<bool>,
pub use_token_ledger: Option<bool>,
#[serde(with = "field_option_pubkey")]
pub destination_token_account: Option<Pubkey>,
pub destination_token_account: Option<Pubkey>,
pub quote_response: Quote,
}

Expand All @@ -272,7 +268,7 @@ impl SwapRequest {
compute_unit_price_micro_lamports: None, // Tested with reqbin if null the value will work, most likely then using "auto"
as_legacy_transaction: Some(false),
use_token_ledger: Some(false),
destination_token_account: None,
destination_token_account: None,
quote_response,
}
}
Expand All @@ -286,9 +282,7 @@ struct SwapResponse {
}

/// Get swap serialized transactions for a quote
pub async fn swap(
swap_request: SwapRequest,
) -> Result<Swap> {
pub async fn swap(swap_request: SwapRequest) -> Result<Swap> {
let url = format!("{QUOTE_API_URL}/swap");

let response = maybe_jupiter_api_error::<SwapResponse>(
Expand Down

0 comments on commit 67dd522

Please sign in to comment.