-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathquotes.rs
59 lines (52 loc) · 1.91 KB
/
quotes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use jup_ag::QuoteConfig;
use {
solana_sdk::pubkey,
spl_token::{amount_to_ui_amount, ui_amount_to_amount},
};
#[tokio::main]
async fn main() -> jup_ag::Result<()> {
let usdc = pubkey!("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
let sol = pubkey!("So11111111111111111111111111111111111111112");
let msol = pubkey!("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So");
let ui_amount = 1.;
for (output_token, output_decimals) in [(usdc, 6), (msol, 9), (sol, 9)] {
let data = jup_ag::price(sol, output_token, ui_amount).await?;
println!(
"Price for {} {} is {} {}",
ui_amount, data.input_symbol, data.price, data.output_symbol
);
let slippage_bps = 100;
let only_direct_routes = false;
let quotes = jup_ag::quote(
sol,
output_token,
ui_amount_to_amount(ui_amount, 9),
QuoteConfig {
only_direct_routes,
slippage_bps: Some(slippage_bps),
..QuoteConfig::default()
},
)
.await?;
println!("Received {} quotes:", quotes.route_plan.len());
for (i, quote) in quotes.route_plan.into_iter().enumerate() {
let route = quote
.swap_info
.label
.unwrap_or_else(|| "Unknown DEX".to_string());
println!(
"{}. {} {} for {} {} via {} (worst case with slippage: {}). Impact: {:.2}%",
i,
amount_to_ui_amount(quote.swap_info.in_amount, 9),
data.input_symbol,
amount_to_ui_amount(quote.swap_info.out_amount, output_decimals),
data.output_symbol,
route,
amount_to_ui_amount(quotes.other_amount_threshold, output_decimals),
quotes.price_impact_pct * 100.
);
}
println!();
}
Ok(())
}