Skip to content

Commit

Permalink
Fix panic caused by division by zero (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD authored Nov 22, 2022
1 parent 867ab05 commit cbc083d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/slippage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use anyhow::{Context as _, Result};
use ethcontract::{H160, U256};
use num::{BigInt, BigRational, Integer as _, ToPrimitive as _};
use num::{BigInt, BigRational, CheckedDiv as _, Integer as _, ToPrimitive as _};
use std::{borrow::Cow, cmp, collections::HashMap};

use crate::{models::batch_auction_model::OrderModel, utils::conversions};
Expand Down Expand Up @@ -105,7 +105,9 @@ impl SlippageCalculator {
/ BigRational::from_float(*price)
.context("price cannot be converted into rational")?;

let max_relative_slippage_respecting_absolute_limit = max_absolute_slippage / &amount;
let max_relative_slippage_respecting_absolute_limit = max_absolute_slippage
.checked_div(&amount.clone().into())
.context("slippage computation divides by 0")?;

cmp::min(
Cow::Owned(max_relative_slippage_respecting_absolute_limit),
Expand Down

0 comments on commit cbc083d

Please sign in to comment.