Skip to content

Commit

Permalink
add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Apr 17, 2024
1 parent e22a296 commit 49c0dde
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions pallets/swaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,24 @@ pub mod pallet {
) -> Result<(SwapStatus<T::Balance>, Option<T::OrderId>), DispatchError> {
match over_order_id {
None => {
let order_id = T::OrderBook::place_order(
who.clone(),
new_swap.currency_in,
new_swap.currency_out,
new_swap.amount_out,
OrderRatio::Market,
)?;
let order_id = if !new_swap.amount_out.is_zero() {
Some(T::OrderBook::place_order(
who.clone(),
new_swap.currency_in,
new_swap.currency_out,
new_swap.amount_out,
OrderRatio::Market,
)?)
} else {
None
};

Ok((
SwapStatus {
swapped: T::Balance::zero(),
pending: new_swap.amount_out,
},
Some(order_id),
order_id,
))
}
Some(order_id) => {
Expand Down Expand Up @@ -228,20 +232,24 @@ pub mod pallet {
let amount_to_swap =
new_swap.amount_out.ensure_sub(inverse_swap_amount_in)?;

let order_id = T::OrderBook::place_order(
who.clone(),
new_swap.currency_in,
new_swap.currency_out,
amount_to_swap,
OrderRatio::Market,
)?;
let order_id = if !amount_to_swap.is_zero() {
Some(T::OrderBook::place_order(
who.clone(),
new_swap.currency_in,
new_swap.currency_out,
amount_to_swap,
OrderRatio::Market,
)?)
} else {
None
};

Ok((
SwapStatus {
swapped: inverse_swap.amount_out,
pending: amount_to_swap,
},
Some(order_id),
order_id,
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/swaps/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ mod zero_amount_order {
Swap {
currency_in: CURRENCY_B,
currency_out: CURRENCY_A,
amount_out: AMOUNT,
amount_out: 0,
},
),
SwapStatus {
Expand Down

0 comments on commit 49c0dde

Please sign in to comment.