diff --git a/Cargo.lock b/Cargo.lock index 6c1c462..3b9fe6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,9 +305,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -656,9 +656,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pest" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" +checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" dependencies = [ "memchr", "thiserror", @@ -718,9 +718,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.73" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -753,9 +753,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -970,7 +970,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.20", + "semver 1.0.21", ] [[package]] @@ -1009,9 +1009,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "semver-parser" @@ -1024,22 +1024,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.44", + "syn 2.0.48", ] [[package]] @@ -1071,9 +1071,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.44" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d27c2c202598d05175a6dd3af46824b7f747f8d8e9b14c623f19fa5069735d" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1101,22 +1101,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.44", + "syn 2.0.48", ] [[package]] @@ -1194,7 +1194,7 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uniswap-sdk-core" -version = "0.7.0" +version = "0.8.0" dependencies = [ "alloy-primitives", "bigdecimal", @@ -1330,9 +1330,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.31" +version = "0.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" dependencies = [ "memchr", ] @@ -1363,5 +1363,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.44", + "syn 2.0.48", ] diff --git a/Cargo.toml b/Cargo.toml index a9651c5..82b85f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core" -version = "0.7.0" +version = "0.8.0" 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/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index a737153..6b1a45d 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -46,7 +46,7 @@ impl CurrencyAmount { // Multiplication of currency amount by another fractional amount pub fn multiply(&self, other: &impl FractionTrait) -> Self { - let multiplied = self.as_fraction().multiply(&other.as_fraction()); + let multiplied = self.as_fraction() * other.as_fraction(); Self::from_fractional_amount( self.meta.currency.clone(), multiplied.numerator().clone(), @@ -56,7 +56,7 @@ impl CurrencyAmount { // Division of currency amount by another fractional amount pub fn divide(&self, other: &impl FractionTrait) -> Self { - let divided = self.as_fraction().divide(&other.as_fraction()); + let divided = self.as_fraction() / other.as_fraction(); Self::from_fractional_amount( self.meta.currency.clone(), divided.numerator().clone(), @@ -75,7 +75,7 @@ impl CurrencyAmount { // Addition of another currency amount to the current amount pub fn add(&self, other: &Self) -> Self { assert!(self.meta.currency.equals(&other.meta.currency), "CURRENCY"); - let added = self.as_fraction().add(&other.as_fraction()); + let added = self.as_fraction() + other.as_fraction(); Self::from_fractional_amount( self.meta.currency.clone(), added.numerator().clone(), @@ -86,7 +86,7 @@ impl CurrencyAmount { // Subtraction of another currency amount from the current amount pub fn subtract(&self, other: &Self) -> Self { assert!(self.meta.currency.equals(&other.meta.currency), "CURRENCY"); - let subtracted = self.as_fraction().subtract(&other.as_fraction()); + let subtracted = self.as_fraction() - other.as_fraction(); Self::from_fractional_amount( self.meta.currency.clone(), subtracted.numerator().clone(), @@ -96,16 +96,14 @@ impl CurrencyAmount { // Convert the currency amount to a string with a specified number of significant digits pub fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> String { - self.as_fraction() - .divide(&Fraction::new(self.meta.decimal_scale.clone(), 1)) + (self.as_fraction() / Fraction::new(self.meta.decimal_scale.clone(), 1)) .to_significant(significant_digits, rounding) } // Convert the currency amount to a string with a fixed number of decimal places pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { assert!(decimal_places <= self.meta.currency.decimals(), "DECIMALS"); - self.as_fraction() - .divide(&Fraction::new(self.meta.decimal_scale.clone(), 1)) + (self.as_fraction() / Fraction::new(self.meta.decimal_scale.clone(), 1)) .to_fixed(decimal_places, rounding) } } diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 6f2af44..98b5355 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -1,8 +1,9 @@ // External crate dependencies use crate::prelude::*; +use std::ops::{Add, Div, Mul, Sub}; // Struct representing a fraction with metadata -#[derive(Clone, PartialEq)] +#[derive(Clone, Debug)] pub struct FractionLike { numerator: BigInt, denominator: BigInt, @@ -29,7 +30,15 @@ const fn to_rounding_strategy(rounding: Rounding) -> RoundingMode { } // Trait defining common operations for fractions with metadata -pub trait FractionTrait: Sized { +pub trait FractionTrait +where + Self: Sized + + Ord + + Add + + Sub + + Mul + + Div, +{ // Constructor method for creating a new Fraction with metadata fn new(numerator: impl Into, denominator: impl Into, meta: M) -> Self; @@ -65,73 +74,6 @@ pub trait FractionTrait: Sized { ) } - // Adds another fraction to the current fraction - fn add(&self, other: &Self) -> Self { - if self.denominator() == other.denominator() { - Self::new( - self.numerator() + other.numerator(), - self.denominator().clone(), - self.meta(), - ) - } else { - Self::new( - self.numerator() * other.denominator() + other.numerator() * self.denominator(), - self.denominator() * other.denominator(), - self.meta(), - ) - } - } - - // Subtracts another fraction from the current fraction - fn subtract(&self, other: &Self) -> Self { - if self.denominator() == other.denominator() { - Self::new( - self.numerator() - other.numerator(), - self.denominator().clone(), - self.meta(), - ) - } else { - Self::new( - self.numerator() * other.denominator() - other.numerator() * self.denominator(), - self.denominator() * other.denominator(), - self.meta(), - ) - } - } - - // Multiplies the current fraction by another fraction - fn multiply(&self, other: &Self) -> Self { - Self::new( - self.numerator() * other.numerator(), - self.denominator() * other.denominator(), - self.meta(), - ) - } - - // Divides the current fraction by another fraction - fn divide(&self, other: &Self) -> Self { - Self::new( - self.numerator() * other.denominator(), - self.denominator() * other.numerator(), - self.meta(), - ) - } - - // Checks if the current fraction is less than another fraction - fn less_than(&self, other: &Self) -> bool { - self.numerator() * other.denominator() < other.numerator() * self.denominator() - } - - // Checks if the current fraction is equal to another fraction - fn equal_to(&self, other: &Self) -> bool { - self.numerator() * other.denominator() == other.numerator() * self.denominator() - } - - // Checks if the current fraction is greater than another fraction - fn greater_than(&self, other: &Self) -> bool { - self.numerator() * other.denominator() > other.numerator() * self.denominator() - } - // Converts the fraction to a `bigdecimal::BigDecimal` fn to_decimal(&self) -> BigDecimal { BigDecimal::from_str(&self.numerator().to_str_radix(10)) @@ -201,6 +143,95 @@ impl FractionTrait for FractionLike { } } +impl PartialEq for FractionLike { + // Checks if the current fraction is equal to another fraction + fn eq(&self, other: &Self) -> bool { + self.numerator() * other.denominator() == other.numerator() * self.denominator() + } +} + +impl Eq for FractionLike {} + +impl Ord for FractionLike { + fn cmp(&self, other: &Self) -> Ordering { + (self.numerator() * other.denominator()).cmp(&(other.numerator() * self.denominator())) + } +} + +impl PartialOrd for FractionLike { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Add for FractionLike { + type Output = Self; + + // Adds another fraction to the current fraction + fn add(self, other: Self) -> Self::Output { + if self.denominator() == other.denominator() { + FractionTrait::new( + self.numerator() + other.numerator(), + self.denominator().clone(), + self.meta(), + ) + } else { + FractionTrait::new( + self.numerator() * other.denominator() + other.numerator() * self.denominator(), + self.denominator() * other.denominator(), + self.meta(), + ) + } + } +} + +impl Sub for FractionLike { + type Output = Self; + + // Subtracts another fraction from the current fraction + fn sub(self, other: Self) -> Self::Output { + if self.denominator() == other.denominator() { + FractionTrait::new( + self.numerator() - other.numerator(), + self.denominator().clone(), + self.meta(), + ) + } else { + FractionTrait::new( + self.numerator() * other.denominator() - other.numerator() * self.denominator(), + self.denominator() * other.denominator(), + self.meta(), + ) + } + } +} + +impl Mul for FractionLike { + type Output = Self; + + // Multiplies the current fraction by another fraction + fn mul(self, other: Self) -> Self::Output { + FractionTrait::new( + self.numerator() * other.numerator(), + self.denominator() * other.denominator(), + self.meta(), + ) + } +} + +impl Div for FractionLike { + type Output = Self; + + // Divides the current fraction by another fraction + fn div(self, other: Self) -> Self::Output { + FractionTrait::new( + self.numerator() * other.denominator(), + self.denominator() * other.numerator(), + self.meta(), + ) + } +} + #[cfg(test)] mod tests { use super::*; @@ -214,15 +245,9 @@ mod tests { #[test] fn test_remainder() { - assert!(Fraction::new(8, 3) - .remainder() - .equal_to(&Fraction::new(2, 3))); - assert!(Fraction::new(12, 4) - .remainder() - .equal_to(&Fraction::new(0, 4))); - assert!(Fraction::new(16, 5) - .remainder() - .equal_to(&Fraction::new(1, 5))); + assert_eq!(Fraction::new(8, 3).remainder(), Fraction::new(2, 3)); + assert_eq!(Fraction::new(12, 4).remainder(), Fraction::new(0, 4)); + assert_eq!(Fraction::new(16, 5).remainder(), Fraction::new(1, 5)); } #[test] @@ -234,76 +259,86 @@ mod tests { #[test] fn test_add() { - assert!(Fraction::new(1, 10) - .add(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(52, 120))); - assert!(Fraction::new(1, 5) - .add(&Fraction::new(2, 5)) - .equal_to(&Fraction::new(3, 5))); + assert_eq!( + Fraction::new(1, 10) + Fraction::new(4, 12), + Fraction::new(52, 120) + ); + assert_eq!( + Fraction::new(1, 5) + Fraction::new(2, 5), + Fraction::new(3, 5) + ); } #[test] fn test_subtract() { - assert!(Fraction::new(1, 10) - .subtract(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(-28, 120))); - assert!(Fraction::new(3, 5) - .subtract(&Fraction::new(2, 5)) - .equal_to(&Fraction::new(1, 5))); + assert_eq!( + Fraction::new(1, 10) - Fraction::new(4, 12), + Fraction::new(-28, 120) + ); + assert_eq!( + Fraction::new(3, 5) - Fraction::new(2, 5), + Fraction::new(1, 5) + ); } #[test] fn test_less_than() { - assert!(Fraction::new(1, 10).less_than(&Fraction::new(4, 12))); - assert!(!Fraction::new(1, 3).less_than(&Fraction::new(4, 12))); - assert!(!Fraction::new(5, 12).less_than(&Fraction::new(4, 12))); + assert!(Fraction::new(1, 10) < Fraction::new(4, 12)); + assert!(!(Fraction::new(1, 3) < Fraction::new(4, 12))); + assert!(!(Fraction::new(5, 12) < Fraction::new(4, 12))); } #[test] fn test_equal_to() { - assert!(!Fraction::new(1, 10).equal_to(&Fraction::new(4, 12))); - assert!(Fraction::new(1, 3).equal_to(&Fraction::new(4, 12))); - assert!(!Fraction::new(5, 12).equal_to(&Fraction::new(4, 12))); + assert_ne!(Fraction::new(1, 10), Fraction::new(4, 12)); + assert_eq!(Fraction::new(1, 3), Fraction::new(4, 12)); + assert_ne!(Fraction::new(5, 12), Fraction::new(4, 12)); } #[test] fn test_greater_than() { - assert!(!Fraction::new(1, 10).greater_than(&Fraction::new(4, 12))); - assert!(!Fraction::new(1, 3).greater_than(&Fraction::new(4, 12))); - assert!(Fraction::new(5, 12).greater_than(&Fraction::new(4, 12))); + assert!(!(Fraction::new(1, 10) > Fraction::new(4, 12))); + assert!(!(Fraction::new(1, 3) > Fraction::new(4, 12))); + assert!(Fraction::new(5, 12) > Fraction::new(4, 12)); } #[test] fn test_multiply() { - assert!(Fraction::new(1, 10) - .multiply(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(4, 120))); - assert!(Fraction::new(1, 3) - .multiply(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(4, 36))); - assert!(Fraction::new(5, 12) - .multiply(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(20, 144))); + assert_eq!( + Fraction::new(1, 10) * Fraction::new(4, 12), + Fraction::new(4, 120) + ); + assert_eq!( + Fraction::new(1, 3) * Fraction::new(4, 12), + Fraction::new(4, 36) + ); + assert_eq!( + Fraction::new(5, 12) * Fraction::new(4, 12), + Fraction::new(20, 144) + ); } #[test] fn test_divide() { - assert!(Fraction::new(1, 10) - .divide(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(12, 40))); - assert!(Fraction::new(1, 3) - .divide(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(12, 12))); - assert!(Fraction::new(5, 12) - .divide(&Fraction::new(4, 12)) - .equal_to(&Fraction::new(60, 48))); + assert_eq!( + Fraction::new(1, 10) / Fraction::new(4, 12), + Fraction::new(12, 40) + ); + assert_eq!( + Fraction::new(1, 3) / Fraction::new(4, 12), + Fraction::new(12, 12) + ); + assert_eq!( + Fraction::new(5, 12) / Fraction::new(4, 12), + Fraction::new(60, 48) + ); } #[test] fn test_as_faction() { let f = Fraction::new(1, 2); // returns an equivalent but not the same reference fraction - assert!(f.as_fraction().equal_to(&f)); + assert_eq!(f.as_fraction(), f); assert_ne!(&f as *const _, &f.as_fraction() as *const _); } } diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index 3163a4b..722192b 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -7,7 +7,7 @@ lazy_static! { } /// Unit struct to distinguish between a fraction and a percent -#[derive(Clone, PartialEq)] +#[derive(Clone, Debug)] pub struct IsPercent; // Type alias for a Percent, a Fraction with the IsPercent metadata @@ -22,17 +22,13 @@ impl Percent { /// Converts the Percent to a string with a specified number of significant digits and rounding strategy pub fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> String { // Convert the Percent to a simple Fraction, multiply by 100, and then call to_significant on the result - self.as_fraction() - .multiply(&ONE_HUNDRED) - .to_significant(significant_digits, rounding) + (self.as_fraction() * ONE_HUNDRED.clone()).to_significant(significant_digits, rounding) } /// Converts the Percent to a string with a fixed number of decimal places and rounding strategy pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { // Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the result - self.as_fraction() - .multiply(&ONE_HUNDRED) - .to_fixed(decimal_places, rounding) + (self.as_fraction() * ONE_HUNDRED.clone()).to_fixed(decimal_places, rounding) } } @@ -42,42 +38,50 @@ mod tests { #[test] fn test_add() { - assert!(Percent::new(1, 100) - .add(&Percent::new(2, 100)) - .equal_to(&Percent::new(3, 100))); - assert!(Percent::new(1, 25) - .add(&Percent::new(2, 100)) - .equal_to(&Percent::new(150, 2500))); + assert_eq!( + Percent::new(1, 100) + Percent::new(2, 100), + Percent::new(3, 100) + ); + assert_eq!( + Percent::new(1, 25) + Percent::new(2, 100), + Percent::new(150, 2500) + ); } #[test] fn test_subtract() { - assert!(Percent::new(1, 100) - .subtract(&Percent::new(2, 100)) - .equal_to(&Percent::new(-1, 100))); - assert!(Percent::new(1, 25) - .subtract(&Percent::new(2, 100)) - .equal_to(&Percent::new(50, 2500))); + assert_eq!( + Percent::new(1, 100) - Percent::new(2, 100), + Percent::new(-1, 100) + ); + assert_eq!( + Percent::new(1, 25) - Percent::new(2, 100), + Percent::new(50, 2500) + ); } #[test] fn test_multiply() { - assert!(Percent::new(1, 100) - .multiply(&Percent::new(2, 100)) - .equal_to(&Percent::new(2, 10000))); - assert!(Percent::new(1, 25) - .multiply(&Percent::new(2, 100)) - .equal_to(&Percent::new(2, 2500))); + assert_eq!( + Percent::new(1, 100) * Percent::new(2, 100), + Percent::new(2, 10000) + ); + assert_eq!( + Percent::new(1, 25) * Percent::new(2, 100), + Percent::new(2, 2500) + ); } #[test] fn test_divide() { - assert!(Percent::new(1, 100) - .divide(&Percent::new(2, 100)) - .equal_to(&Percent::new(100, 200))); - assert!(Percent::new(1, 25) - .divide(&Percent::new(2, 100)) - .equal_to(&Percent::new(100, 50))); + assert_eq!( + Percent::new(1, 100) / Percent::new(2, 100), + Percent::new(100, 200) + ); + assert_eq!( + Percent::new(1, 25) / Percent::new(2, 100), + Percent::new(100, 50) + ); } #[test] diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index e2c8c54..044f2b8 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -79,7 +79,7 @@ where self.meta.quote_currency.equals(&other.meta.base_currency), "TOKEN" ); - let fraction = self.as_fraction().multiply(&other.as_fraction()); + let fraction = self.as_fraction() * other.as_fraction(); Price::new( self.meta.base_currency.clone(), other.meta.quote_currency.clone(), @@ -97,7 +97,7 @@ where .equals(&self.meta.base_currency), "TOKEN" ); - let fraction = self.as_fraction().multiply(¤cy_amount.as_fraction()); + let fraction = self.as_fraction() * currency_amount.as_fraction(); CurrencyAmount::from_fractional_amount( self.meta.quote_currency.clone(), fraction.numerator().clone(), @@ -107,7 +107,7 @@ where /// Get the value scaled by decimals for formatting pub fn adjusted_for_decimals(&self) -> Fraction { - self.as_fraction().multiply(&self.meta.scalar) + self.as_fraction() * self.meta.scalar.clone() } /// Converts the adjusted price to a string with a specified number of significant digits and rounding strategy @@ -159,9 +159,10 @@ mod test { #[test] fn test_quote_returns_correct_value() { let price = Price::new(TOKEN0.clone(), TOKEN1.clone(), 1, 5); - assert!(price - .quote(CurrencyAmount::from_raw_amount(TOKEN0.clone(), 10)) - .equal_to(&CurrencyAmount::from_raw_amount(TOKEN1.clone(), 50))); + assert!( + price.quote(CurrencyAmount::from_raw_amount(TOKEN0.clone(), 10)) + == CurrencyAmount::from_raw_amount(TOKEN1.clone(), 50) + ); } #[test] diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 5279e1f..cf71494 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,4 @@ -pub mod compute_price_impact; +// pub mod compute_price_impact; pub mod sorted_insert; pub mod sqrt; pub mod validate_and_parse_address;