Skip to content

Commit

Permalink
Merge pull request #43 from shuhuiluo/misc
Browse files Browse the repository at this point in the history
Misc chores
  • Loading branch information
malik672 authored Feb 18, 2024
2 parents 9b0c2a4 + fc87d81 commit e9fe9fe
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 36 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-sdk-core"
version = "0.14.0"
version = "0.15.0"
edition = "2021"
authors = ["malik <[email protected]>", "Shuhui Luo <twitter.com/aureliano_law>"]
description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange"
Expand All @@ -22,4 +22,4 @@ syn = "2.0.48"
thiserror = "1.0.56"

[features]
validate_parse_address = []
validate_parse_address = []
4 changes: 3 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
max_width = 100
format_code_in_doc_comments = true
imports_granularity = "Crate"
max_width = 100
unstable_features = true
use_field_init_shorthand = true
1 change: 0 additions & 1 deletion src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, C
///
///
/// returns: AdresssMap
///
pub fn construct_same_address_map(address: Address, additional_networks: &[ChainId]) -> AddressMap {
let mut networks = DEFAULT_NETWORKS.to_vec();
networks.extend_from_slice(additional_networks);
Expand Down
1 change: 0 additions & 1 deletion src/entities/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub trait CurrencyTrait: BaseCurrency {
/// # Arguments
///
/// * `other`: the other currency
///
fn equals(&self, other: &impl CurrencyTrait) -> bool;

/// Return the wrapped version of this currency that can be used with the Uniswap contracts.
Expand Down
12 changes: 11 additions & 1 deletion src/entities/fractions/fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ pub struct FractionLike<M> {
pub meta: M,
}

impl<M: Default> Default for FractionLike<M> {
fn default() -> Self {
Self {
numerator: BigInt::from(0),
denominator: BigInt::from(1),
meta: M::default(),
}
}
}

// Type alias for a simple Fraction without metadata
pub type Fraction = FractionLike<()>;

Expand Down Expand Up @@ -258,7 +268,7 @@ mod tests {
#[test]
fn test_remainder() {
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(12, 4).remainder(), Fraction::default());
assert_eq!(Fraction::new(16, 5).remainder(), Fraction::new(1, 5));
}

Expand Down
4 changes: 1 addition & 3 deletions src/entities/fractions/percent.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Importing dependencies from the same module
use crate::prelude::*;

use super::fraction::FractionBase;

// Lazily initialized constant representing the fraction 100/1
lazy_static! {
static ref ONE_HUNDRED: Fraction = Fraction::new(100, 1);
}

/// Unit struct to distinguish between a fraction and a percent
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct IsPercent;

// Type alias for a Percent, a Fraction with the IsPercent metadata
Expand Down
2 changes: 0 additions & 2 deletions src/entities/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl CurrencyTrait for Token {
/// * `other`: other token to compare
///
/// returns: bool
///
fn equals(&self, other: &impl CurrencyTrait) -> bool {
match other.is_native() {
false => self.chain_id == other.chain_id() && self.address() == other.address(),
Expand Down Expand Up @@ -72,7 +71,6 @@ impl Token {
/// # Arguments
///
/// * `other`: other token to compare
///
pub fn sorts_before(&self, other: &Token) -> Result<bool, Error> {
if self.chain_id != other.chain_id {
return Err(Error::ChainIdMismatch(self.chain_id, other.chain_id));
Expand Down
5 changes: 3 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use super::chains::{ChainId, SUPPORTED_CHAINS};
pub use crate::{
constants::{Rounding, MAX_UINT256},
chains::*,
constants::*,
entities::{
base_currency::{BaseCurrency, CurrencyLike},
currency::{Currency, CurrencyTrait},
Expand All @@ -15,6 +15,7 @@ pub use crate::{
weth9::WETH9,
},
error::Error,
utils::*,
};
pub use alloy_primitives::{address, Address};
pub use bigdecimal::{BigDecimal, RoundingMode};
Expand Down
3 changes: 1 addition & 2 deletions src/utils/compute_price_impact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::prelude::*;
/// * outputAmount the output amount of the trade
///
/// returns: Percent
///
pub fn compute_price_impact<TBase: CurrencyTrait, TQuote: CurrencyTrait>(
mid_price: Price<TBase, TQuote>,
input_amount: CurrencyAmount<TBase>,
Expand Down Expand Up @@ -51,7 +50,7 @@ mod tests {
CurrencyAmount::from_raw_amount(token.clone(), 100).unwrap()
)
.unwrap()
== Percent::new(0, 10000),
== Percent::default(),
);

//is correct for half output
Expand Down
1 change: 0 additions & 1 deletion src/utils/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::prelude::*;
/// * `value`: the value for which to compute the square root, rounded down
///
/// returns: BigInt
///
pub fn sqrt(value: &BigInt) -> Result<BigInt, Error> {
if !value >= Zero::zero() {
return Err(Error::Incorrect());
Expand Down

0 comments on commit e9fe9fe

Please sign in to comment.