Skip to content

Commit db5c904

Browse files
authored
Use new Jup endpoints. JUP_API_KEY is now required (#23)
1 parent 1fc7f01 commit db5c904

3 files changed

Lines changed: 72 additions & 55 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ftx = { git = "https://github.com/fabianboesiger/ftx", rev = "bb98235d356dd1a2be
3131
futures = "0.3.25"
3232
influxdb-client = "0.1.4"
3333
itertools = "0.10.0"
34-
jup-ag = "0.9.2"
34+
jup-ag = "0.10.0"
3535
#jup-ag = { path = "../jup_ag" }
3636
#kraken_sdk_rest = { path = "../kraken_sdk_rust/kraken_sdk_rest" }
3737
kraken_sdk_rest = { git = "https://github.com/mvines/kraken_sdk_rust", rev = "80c634b3a8527f653db989689b298496dad30d4e" }

src/bin/sys.rs

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ async fn process_jup_quote(
998998
to_token: MaybeToken,
999999
ui_amount: f64,
10001000
slippage_bps: u64,
1001+
jup_api_key: String,
10011002
) -> Result<(), Box<dyn std::error::Error>> {
10021003
let quote = jup_ag::quote(
10031004
from_token.mint(),
@@ -1007,6 +1008,7 @@ async fn process_jup_quote(
10071008
slippage_bps: Some(slippage_bps),
10081009
..jup_ag::QuoteConfig::default()
10091010
},
1011+
jup_api_key,
10101012
)
10111013
.await?;
10121014

@@ -1032,6 +1034,7 @@ async fn process_jup_swap<T: Signers>(
10321034
max_coingecko_value_percentage_loss: f64,
10331035
priority_fee: PriorityFee,
10341036
notifier: &Notifier,
1037+
jup_api_key: String,
10351038
) -> Result<(), Box<dyn std::error::Error>> {
10361039
let rpc_client = rpc_clients.default();
10371040

@@ -1106,6 +1109,7 @@ async fn process_jup_swap<T: Signers>(
11061109
slippage_bps: Some(slippage_bps),
11071110
..jup_ag::QuoteConfig::default()
11081111
},
1112+
jup_api_key.clone(),
11091113
)
11101114
.await?;
11111115

@@ -1150,7 +1154,9 @@ async fn process_jup_swap<T: Signers>(
11501154
jup_ag::PrioritizationFeeLamports::Exact { lamports };
11511155
}
11521156

1153-
let mut transaction = jup_ag::swap(swap_request).await?.swap_transaction;
1157+
let mut transaction = jup_ag::swap(swap_request, jup_api_key.clone())
1158+
.await?
1159+
.swap_transaction;
11541160

11551161
{
11561162
let mut transaction_compute_budget = sys::priority_fee::ComputeBudget::default();
@@ -6453,60 +6459,71 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
64536459
}
64546460
_ => unreachable!(),
64556461
},
6456-
("jup", Some(jup_matches)) => match jup_matches.subcommand() {
6457-
("quote", Some(arg_matches)) => {
6458-
let from_token = MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok());
6459-
let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok());
6460-
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
6461-
let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64);
6462+
("jup", Some(jup_matches)) => {
6463+
let jup_api_key = std::env::var("JUP_API_KEY").map_err(|_| {
6464+
"JUP_API_KEY env var not set. Get one from https://portal.jup.ag".to_string()
6465+
});
64626466

6463-
process_jup_quote(from_token, to_token, ui_amount, slippage_bps).await?;
6464-
}
6465-
("swap", Some(arg_matches)) => {
6466-
let (signer, address) = signer_of(arg_matches, "address", &mut wallet_manager)?;
6467-
let from_token = MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok());
6468-
let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok());
6469-
let ui_amount = match arg_matches.value_of("amount").unwrap() {
6470-
"ALL" => None,
6471-
ui_amount => Some(ui_amount.parse::<f64>().unwrap()),
6472-
};
6473-
let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64);
6474-
let signer = signer.expect("signer");
6475-
let address = address.expect("address");
6476-
let lot_selection_method =
6477-
value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod);
6478-
let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers");
6479-
let signature = value_t!(arg_matches, "transaction", Signature).ok();
6480-
let if_from_balance_exceeds = value_t!(arg_matches, "if_from_balance_exceeds", f64)
6481-
.ok()
6482-
.map(|x| from_token.amount(x));
6483-
let for_no_less_than = value_t!(arg_matches, "for_no_less_than", f64).ok();
6484-
let max_coingecko_value_percentage_loss =
6485-
value_t_or_exit!(arg_matches, "max_coingecko_value_percentage_loss", f64);
6467+
match jup_matches.subcommand() {
6468+
("quote", Some(arg_matches)) => {
6469+
let from_token =
6470+
MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok());
6471+
let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok());
6472+
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
6473+
let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64);
64866474

6487-
process_jup_swap(
6488-
&mut db,
6489-
&rpc_clients,
6490-
address,
6491-
from_token,
6492-
to_token,
6493-
ui_amount,
6494-
slippage_bps,
6495-
lot_selection_method,
6496-
lot_numbers,
6497-
vec![signer],
6498-
signature,
6499-
if_from_balance_exceeds,
6500-
for_no_less_than,
6501-
max_coingecko_value_percentage_loss,
6502-
priority_fee,
6503-
&notifier,
6504-
)
6505-
.await?;
6506-
process_sync_swaps(&mut db, rpc_client, &notifier).await?;
6475+
process_jup_quote(from_token, to_token, ui_amount, slippage_bps, jup_api_key?)
6476+
.await?;
6477+
}
6478+
("swap", Some(arg_matches)) => {
6479+
let (signer, address) = signer_of(arg_matches, "address", &mut wallet_manager)?;
6480+
let from_token =
6481+
MaybeToken::from(value_t!(arg_matches, "from_token", Token).ok());
6482+
let to_token = MaybeToken::from(value_t!(arg_matches, "to_token", Token).ok());
6483+
let ui_amount = match arg_matches.value_of("amount").unwrap() {
6484+
"ALL" => None,
6485+
ui_amount => Some(ui_amount.parse::<f64>().unwrap()),
6486+
};
6487+
let slippage_bps = value_t_or_exit!(arg_matches, "slippage_bps", u64);
6488+
let signer = signer.expect("signer");
6489+
let address = address.expect("address");
6490+
let lot_selection_method =
6491+
value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod);
6492+
let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers");
6493+
let signature = value_t!(arg_matches, "transaction", Signature).ok();
6494+
let if_from_balance_exceeds =
6495+
value_t!(arg_matches, "if_from_balance_exceeds", f64)
6496+
.ok()
6497+
.map(|x| from_token.amount(x));
6498+
let for_no_less_than = value_t!(arg_matches, "for_no_less_than", f64).ok();
6499+
let max_coingecko_value_percentage_loss =
6500+
value_t_or_exit!(arg_matches, "max_coingecko_value_percentage_loss", f64);
6501+
6502+
process_jup_swap(
6503+
&mut db,
6504+
&rpc_clients,
6505+
address,
6506+
from_token,
6507+
to_token,
6508+
ui_amount,
6509+
slippage_bps,
6510+
lot_selection_method,
6511+
lot_numbers,
6512+
vec![signer],
6513+
signature,
6514+
if_from_balance_exceeds,
6515+
for_no_less_than,
6516+
max_coingecko_value_percentage_loss,
6517+
priority_fee,
6518+
&notifier,
6519+
jup_api_key?,
6520+
)
6521+
.await?;
6522+
process_sync_swaps(&mut db, rpc_client, &notifier).await?;
6523+
}
6524+
_ => unreachable!(),
65076525
}
6508-
_ => unreachable!(),
6509-
},
6526+
}
65106527
(exchange, Some(exchange_matches)) => {
65116528
assert!(exchanges.contains(&exchange), "Bug!");
65126529
let exchange = Exchange::from_str(exchange)?;

0 commit comments

Comments
 (0)