Skip to content

Commit

Permalink
Use BigInt to compute unit (#2605)
Browse files Browse the repository at this point in the history
# Description
Follow up to #2603.
10**24 doesn't fit into a `u64` so we were still dividing by the wrong
base.

# Changes
compute base using big int which does not result in an over flow see
[here](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6321e0b405f0e6ff0f469b5a8ecedbc1).

## How to test
tested using rust playground ☝️
  • Loading branch information
MartinquaXD authored Apr 10, 2024
1 parent 98a4d11 commit 25ed74b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/shared/src/price_estimation/native/oneinch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ async fn get_current_prices(
tracing::debug!(?token, "could not fetch decimals; discarding spot price");
return None;
};
let unit = num::BigRational::from_integer(10u64.pow(decimals.into()).into());
let unit =
num::BigRational::from_integer(num::BigInt::from(10u64).pow(decimals.into()));
let normalized_price = u256_to_big_rational(&price) / unit;
Some((token, normalized_price.to_f64()?))
})
Expand Down

0 comments on commit 25ed74b

Please sign in to comment.