Client: Fix loan amount for jupiter ExactOut swaps

This commit is contained in:
Christian Kamm 2022-08-07 20:09:28 +02:00
parent 2552bffc66
commit 13e4d0a432
1 changed files with 9 additions and 1 deletions

View File

@ -996,7 +996,14 @@ impl MangoClient {
})
.collect::<Vec<_>>();
let loan_amounts = vec![route.in_amount, 0u64];
let loan_amounts = vec![
match swap_mode {
JupiterSwapMode::ExactIn => amount,
// in amount + slippage
JupiterSwapMode::ExactOut => route.other_amount_threshold,
},
0u64,
];
// This relies on the fact that health account banks will be identical to the first_bank above!
let health_ams = self
@ -1128,6 +1135,7 @@ pub fn prettify_client_error(err: anchor_client::ClientError) -> anyhow::Error {
err.into()
}
#[derive(Clone, Copy)]
pub enum JupiterSwapMode {
ExactIn,
ExactOut,