diff --git a/Cargo.toml b/Cargo.toml index 9cda52c..8673438 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core" -version = "0.20.0" +version = "0.20.1" edition = "2021" authors = ["malik ", "Shuhui Luo "] description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange" diff --git a/README.md b/README.md index 5d5dd4f..4c24db1 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ fn main() { } ``` -This example demonstrates how to create a Token instance for DAI on the Ethereum Mainnet using the token! macro. +This example demonstrates how to create a `Token` instance for DAI on the Ethereum Mainnet using the `token!` macro. It then prints the token's address and checks if it's a native token (which it isn't, so it prints false). diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index b4f56a4..ba79729 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -114,7 +114,7 @@ impl CurrencyAmount { /// Convert the currency amount to a string with a fixed number of decimal places pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> Result { - if !decimal_places <= self.currency.decimals() { + if decimal_places > self.currency.decimals() { return Err(Error::NotEqual()); } @@ -204,7 +204,6 @@ mod tests { } #[test] - #[should_panic(expected = "DECIMALS")] fn to_fixed_decimals_exceeds_currency_decimals() { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 1000).unwrap(); let _w = amount.to_fixed(3, Rounding::RoundDown); diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 171d549..ddc545a 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -117,11 +117,9 @@ pub trait FractionBase: Sized { /// strategy fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { let rounding_strategy = to_rounding_strategy(rounding); - let quotient = self - .to_decimal() - .with_scale_round(decimal_places as i64, rounding_strategy); - - format!("{:.1$}", quotient, decimal_places as usize) + self.to_decimal() + .with_scale_round(decimal_places as i64, rounding_strategy) + .to_string() } /// Helper method for converting any superclass back to a simple [`Fraction`] diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index da3670e..9f0c92c 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use num_traits::Signed; /// Computes floor(sqrt(value)) /// @@ -7,10 +8,8 @@ use crate::prelude::*; /// * `value`: the value for which to compute the square root, rounded down /// /// returns: BigInt - -#[allow(clippy::assigning_clones)] pub fn sqrt(value: &BigInt) -> Result { - if !value >= Zero::zero() { + if value.is_negative() { return Err(Error::Incorrect()); }