From 67dd522e18c2dd3d0eeab92aeafe82e39a7ac297 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 21 Dec 2023 10:24:26 -0800 Subject: [PATCH] cargo fmt --- examples/quotes.rs | 2 +- examples/swap.rs | 23 ++++++++++++++--------- src/field_option_pubkey.rs | 2 +- src/lib.rs | 14 ++++---------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/examples/quotes.rs b/examples/quotes.rs index 2433daa..0bad86c 100644 --- a/examples/quotes.rs +++ b/examples/quotes.rs @@ -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, diff --git a/examples/swap.rs b/examples/swap.rs index 408e047..708b460 100644 --- a/examples/swap.rs +++ b/examples/swap.rs @@ -1,4 +1,4 @@ -use jup_ag::{SwapRequest, QuoteConfig}; +use jup_ag::{QuoteConfig, SwapRequest}; use solana_sdk::transaction::VersionedTransaction; use { @@ -6,9 +6,9 @@ use { 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}, }; @@ -66,11 +66,11 @@ async fn main() -> Result<(), Box> { ) .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), @@ -82,11 +82,16 @@ async fn main() -> Result<(), Box> { 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: {}", diff --git a/src/field_option_pubkey.rs b/src/field_option_pubkey.rs index 617d749..45b52a0 100644 --- a/src/field_option_pubkey.rs +++ b/src/field_option_pubkey.rs @@ -11,4 +11,4 @@ where Some(pubkey) => pubkey.to_string().serialize(serializer), None => serializer.serialize_none(), } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 78055c9..393fed2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { +pub async fn price(input_mint: Pubkey, output_mint: Pubkey, ui_amount: f64) -> Result { 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?) @@ -257,7 +253,7 @@ pub struct SwapRequest { pub as_legacy_transaction: Option, pub use_token_ledger: Option, #[serde(with = "field_option_pubkey")] - pub destination_token_account: Option, + pub destination_token_account: Option, pub quote_response: Quote, } @@ -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, } } @@ -286,9 +282,7 @@ struct SwapResponse { } /// Get swap serialized transactions for a quote -pub async fn swap( - swap_request: SwapRequest, -) -> Result { +pub async fn swap(swap_request: SwapRequest) -> Result { let url = format!("{QUOTE_API_URL}/swap"); let response = maybe_jupiter_api_error::(