From e8ccdf056ecb163eaccafc72fde211f61b4b6255 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sun, 11 Jan 2026 23:34:05 -0800 Subject: [PATCH] Use new Jup endpoints. JUP_API_KEY is now required --- Cargo.lock | 4 +- Cargo.toml | 2 +- src/bin/sys.rs | 121 ++++++++++++++++++++++++++++--------------------- 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07f2806..5d287ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2686,9 +2686,9 @@ dependencies = [ [[package]] name = "jup-ag" -version = "0.9.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "189308879f8d3de398ebd63a1c266241115eb45b48008b06758a46d0c3a8ee91" +checksum = "f5832e7a077dc6a5d282b21324b98eba850e5cb35a64047b9dfb7de41ea387c3" dependencies = [ "base64 0.22.1", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 2c1a2e1..af8b5a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ ftx = { git = "https://github.com/fabianboesiger/ftx", rev = "bb98235d356dd1a2be futures = "0.3.25" influxdb-client = "0.1.4" itertools = "0.10.0" -jup-ag = "0.9.2" +jup-ag = "0.10.0" #jup-ag = { path = "../jup_ag" } #kraken_sdk_rest = { path = "../kraken_sdk_rust/kraken_sdk_rest" } kraken_sdk_rest = { git = "https://github.com/mvines/kraken_sdk_rust", rev = "80c634b3a8527f653db989689b298496dad30d4e" } diff --git a/src/bin/sys.rs b/src/bin/sys.rs index 098e1a3..ff492c5 100644 --- a/src/bin/sys.rs +++ b/src/bin/sys.rs @@ -998,6 +998,7 @@ async fn process_jup_quote( to_token: MaybeToken, ui_amount: f64, slippage_bps: u64, + jup_api_key: String, ) -> Result<(), Box> { let quote = jup_ag::quote( from_token.mint(), @@ -1007,6 +1008,7 @@ async fn process_jup_quote( slippage_bps: Some(slippage_bps), ..jup_ag::QuoteConfig::default() }, + jup_api_key, ) .await?; @@ -1032,6 +1034,7 @@ async fn process_jup_swap( max_coingecko_value_percentage_loss: f64, priority_fee: PriorityFee, notifier: &Notifier, + jup_api_key: String, ) -> Result<(), Box> { let rpc_client = rpc_clients.default(); @@ -1106,6 +1109,7 @@ async fn process_jup_swap( slippage_bps: Some(slippage_bps), ..jup_ag::QuoteConfig::default() }, + jup_api_key.clone(), ) .await?; @@ -1150,7 +1154,9 @@ async fn process_jup_swap( jup_ag::PrioritizationFeeLamports::Exact { lamports }; } - let mut transaction = jup_ag::swap(swap_request).await?.swap_transaction; + let mut transaction = jup_ag::swap(swap_request, jup_api_key.clone()) + .await? + .swap_transaction; { let mut transaction_compute_budget = sys::priority_fee::ComputeBudget::default(); @@ -6453,60 +6459,71 @@ async fn main() -> Result<(), Box> { } _ => unreachable!(), }, - ("jup", Some(jup_matches)) => match jup_matches.subcommand() { - ("quote", Some(arg_matches)) => { - let from_token = MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok()); - let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok()); - let ui_amount = value_t_or_exit!(arg_matches, "amount", f64); - let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64); + ("jup", Some(jup_matches)) => { + let jup_api_key = std::env::var("JUP_API_KEY").map_err(|_| { + "JUP_API_KEY env var not set. Get one from https://portal.jup.ag".to_string() + }); - process_jup_quote(from_token, to_token, ui_amount, slippage_bps).await?; - } - ("swap", Some(arg_matches)) => { - let (signer, address) = signer_of(arg_matches, "address", &mut wallet_manager)?; - let from_token = MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok()); - let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok()); - let ui_amount = match arg_matches.value_of("amount").unwrap() { - "ALL" => None, - ui_amount => Some(ui_amount.parse::().unwrap()), - }; - let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64); - let signer = signer.expect("signer"); - let address = address.expect("address"); - let lot_selection_method = - value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod); - let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers"); - let signature = value_t!(arg_matches, "transaction", Signature).ok(); - let if_from_balance_exceeds = value_t!(arg_matches, "if_from_balance_exceeds", f64) - .ok() - .map(|x| from_token.amount(x)); - let for_no_less_than = value_t!(arg_matches, "for_no_less_than", f64).ok(); - let max_coingecko_value_percentage_loss = - value_t_or_exit!(arg_matches, "max_coingecko_value_percentage_loss", f64); + match jup_matches.subcommand() { + ("quote", Some(arg_matches)) => { + let from_token = + MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok()); + let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok()); + let ui_amount = value_t_or_exit!(arg_matches, "amount", f64); + let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64); - process_jup_swap( - &mut db, - &rpc_clients, - address, - from_token, - to_token, - ui_amount, - slippage_bps, - lot_selection_method, - lot_numbers, - vec![signer], - signature, - if_from_balance_exceeds, - for_no_less_than, - max_coingecko_value_percentage_loss, - priority_fee, - ¬ifier, - ) - .await?; - process_sync_swaps(&mut db, rpc_client, ¬ifier).await?; + process_jup_quote(from_token, to_token, ui_amount, slippage_bps, jup_api_key?) + .await?; + } + ("swap", Some(arg_matches)) => { + let (signer, address) = signer_of(arg_matches, "address", &mut wallet_manager)?; + let from_token = + MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok()); + let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok()); + let ui_amount = match arg_matches.value_of("amount").unwrap() { + "ALL" => None, + ui_amount => Some(ui_amount.parse::().unwrap()), + }; + let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64); + let signer = signer.expect("signer"); + let address = address.expect("address"); + let lot_selection_method = + value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod); + let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers"); + let signature = value_t!(arg_matches, "transaction", Signature).ok(); + let if_from_balance_exceeds = + value_t!(arg_matches, "if_from_balance_exceeds", f64) + .ok() + .map(|x| from_token.amount(x)); + let for_no_less_than = value_t!(arg_matches, "for_no_less_than", f64).ok(); + let max_coingecko_value_percentage_loss = + value_t_or_exit!(arg_matches, "max_coingecko_value_percentage_loss", f64); + + process_jup_swap( + &mut db, + &rpc_clients, + address, + from_token, + to_token, + ui_amount, + slippage_bps, + lot_selection_method, + lot_numbers, + vec![signer], + signature, + if_from_balance_exceeds, + for_no_less_than, + max_coingecko_value_percentage_loss, + priority_fee, + ¬ifier, + jup_api_key?, + ) + .await?; + process_sync_swaps(&mut db, rpc_client, ¬ifier).await?; + } + _ => unreachable!(), } - _ => unreachable!(), - }, + } (exchange, Some(exchange_matches)) => { assert!(exchanges.contains(&exchange), "Bug!"); let exchange = Exchange::from_str(exchange)?;