Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
thal0x committed May 7, 2024
1 parent fcef3c1 commit cff82e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions contracts/entry-point/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,22 @@ pub fn execute_swap_and_action(
match smart_swap.amount().cmp(&remaining_asset.amount()) {
std::cmp::Ordering::Equal => {}
std::cmp::Ordering::Less => {
let diff = smart_swap.amount().checked_sub(remaining_asset.amount())?;
// If the total swap in amount is greater than remaining asset,
let diff = remaining_asset.amount().checked_sub(smart_swap.amount())?;

// If the total swap in amount is less than remaining asset,
// adjust the routes to match the remaining asset amount
let largest_route_idx = smart_swap.largest_route_index().unwrap();

smart_swap.routes[largest_route_idx].offer_asset.sub(diff)?;
smart_swap.routes[largest_route_idx].offer_asset.add(diff)?;
}
std::cmp::Ordering::Greater => {
let diff = remaining_asset.amount().checked_sub(smart_swap.amount())?;
let diff = smart_swap.amount().checked_sub(remaining_asset.amount())?;

// If the total swap in amount is less than remaining asset,
// If the total swap in amount is greater than remaining asset,
// adjust the routes to match the remaining asset amount
let largest_route_idx = smart_swap.largest_route_index().unwrap();

smart_swap.routes[largest_route_idx].offer_asset.add(diff)?;
smart_swap.routes[largest_route_idx].offer_asset.sub(diff)?;
}
}
}
Expand Down

0 comments on commit cff82e7

Please sign in to comment.