Skip to content

Commit

Permalink
Update to jup-ag 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Dec 21, 2023
1 parent d9eb557 commit da17449
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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.5.0"
jup-ag = "0.6.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" }
Expand Down
47 changes: 16 additions & 31 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ async fn process_exchange_sell(

fn println_jup_quote(from_token: Token, to_token: Token, quote: &jup_ag::Quote) {
let route = quote
.market_infos
.route_plan
.iter()
.map(|market_info| market_info.label.clone())
.map(|route_plan| route_plan.swap_info.label.clone().unwrap_or_default())
.join(", ");
println!(
"Swap {}{} for {}{} (min: {}{}) via {}",
Expand All @@ -948,9 +948,8 @@ async fn process_jup_quote(
to_token: Token,
ui_amount: f64,
slippage_bps: u64,
max_quotes: usize,
) -> Result<(), Box<dyn std::error::Error>> {
let quotes = jup_ag::quote(
let quote = jup_ag::quote(
from_token.mint(),
to_token.mint(),
from_token.amount(ui_amount),
Expand All @@ -959,12 +958,9 @@ async fn process_jup_quote(
..jup_ag::QuoteConfig::default()
},
)
.await?
.data;
.await?;

for quote in quotes.into_iter().take(max_quotes) {
println_jup_quote(from_token, to_token, dbg!(&quote));
}
println_jup_quote(from_token, to_token, &quote);
Ok(())
}

Expand All @@ -983,7 +979,7 @@ async fn process_jup_swap<T: Signers>(
if_from_balance_exceeds: Option<u64>,
for_no_less_than: Option<f64>,
max_coingecko_value_percentage_loss: f64,
compute_unit_price_micro_lamports: Option<usize>,
compute_unit_price_micro_lamports: Option<u64>,
notifier: &Notifier,
) -> Result<(), Box<dyn std::error::Error>> {
let from_account = db
Expand Down Expand Up @@ -1048,7 +1044,7 @@ async fn process_jup_swap<T: Signers>(
})?;

println!("Fetching best {from_token}->{to_token} quote...");
let quotes = jup_ag::quote(
let quote = jup_ag::quote(
from_token.mint(),
to_token.mint(),
amount,
Expand All @@ -1057,13 +1053,9 @@ async fn process_jup_swap<T: Signers>(
..jup_ag::QuoteConfig::default()
},
)
.await?
.data;
.await?;

let quote = quotes
.get(0)
.ok_or_else(|| format!("No quotes found for {from_token} to {to_token}"))?;
println_jup_quote(from_token, to_token, quote);
println_jup_quote(from_token, to_token, &quote);

let from_value =
from_token_price * Decimal::from_f64(from_token.ui_amount(quote.in_amount)).unwrap();
Expand Down Expand Up @@ -1096,15 +1088,11 @@ async fn process_jup_swap<T: Signers>(
}

println!("Generating {swap_prefix} Transaction...");
let mut transaction = jup_ag::swap_with_config(
quote.clone(),
address,
jup_ag::SwapConfig {
wrap_unwrap_sol: Some(false),
as_legacy_transaction: None,
compute_unit_price_micro_lamports,
..jup_ag::SwapConfig::default()
},
let mut swap_request = jup_ag::SwapRequest::new( address, quote.clone());
swap_request.wrap_and_unwrap_sol = Some(false);
swap_request.compute_unit_price_micro_lamports = compute_unit_price_micro_lamports;

let mut transaction = jup_ag::swap(swap_request
)
.await?
.swap_transaction;
Expand Down Expand Up @@ -6047,11 +6035,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let to_token = value_t_or_exit!(arg_matches, "to_token", Token);
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64);
let max_quotes = value_t!(arg_matches, "max_quotes", usize)
.ok()
.unwrap_or(usize::MAX);

process_jup_quote(from_token, to_token, ui_amount, slippage_bps, max_quotes)
process_jup_quote(from_token, to_token, ui_amount, slippage_bps)
.await?;
}
("swap", Some(arg_matches)) => {
Expand All @@ -6075,7 +6060,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let max_coingecko_value_percentage_loss =
value_t_or_exit!(arg_matches, "max_coingecko_value_percentage_loss", f64);
let compute_unit_price_micro_lamports =
value_t!(arg_matches, "compute_unit_price_micro_lamports", usize).ok();
value_t!(arg_matches, "compute_unit_price_micro_lamports", u64).ok();

process_jup_swap(
&mut db,
Expand Down

0 comments on commit da17449

Please sign in to comment.