From 00963c9ca8033b1dec68b8443c01f6010bf73352 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sun, 17 Mar 2024 08:51:29 +0100 Subject: [PATCH 01/31] fix big-decimal issue --- Cargo.toml | 2 +- src/entities/fractions/currency_amount.rs | 17 +++++++++++------ src/entities/fractions/percent.rs | 2 +- src/entities/fractions/price.rs | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9cda52c..0dc7eea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" [dependencies] alloy-primitives = "0.6" -bigdecimal = "=0.4.2" +bigdecimal = "0.4.3" eth_checksum = { version = "0.1.2", optional = true } lazy_static = "1.4" num-bigint = "0.4.4" diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index b4f56a4..0392bb3 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -117,7 +117,12 @@ impl CurrencyAmount { if !decimal_places <= self.currency.decimals() { return Err(Error::NotEqual()); } - + + if decimal_places == 0 { + // Directly convert the numerator to a string for zero decimal places + return Ok(self.numerator().to_string()); + } + Ok( (self.as_fraction() / Fraction::new(self.decimal_scale.clone(), 1)) .to_fixed(decimal_places, rounding), @@ -189,7 +194,7 @@ mod tests { #[test] #[should_panic(expected = "AMOUNT")] - fn test_token_amount_quotient_exceeds_max_uint256() { + fn test_token_amount_quotient_exceeds_max_uint256() { let numerator: BigInt = (MAX_UINT256.clone() + 1) * 2; let _w = CurrencyAmount::from_fractional_amount(TOKEN18.clone(), numerator, 2); assert!(_w.is_ok(), "AMOUNT"); @@ -213,8 +218,8 @@ mod tests { #[test] fn to_fixed_0_decimals() { - let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 123456).unwrap(); - assert_eq!(amount.to_fixed(0, Rounding::RoundDown).unwrap(), "123456"); + let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 12345896).unwrap(); + assert_eq!(amount.to_fixed(0, Rounding::RoundHalfUp).unwrap(), "12345896"); } #[test] @@ -231,7 +236,7 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 1000).unwrap(); assert_eq!( amount.to_significant(3, Rounding::RoundDown).unwrap(), - "1000" + "1E+3" ); } @@ -240,7 +245,7 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 123456).unwrap(); assert_eq!( amount.to_significant(4, Rounding::RoundDown).unwrap(), - "123400" + "1.234E+5" ); } diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index c8beac6..ed5b85b 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -107,7 +107,7 @@ mod tests { fn test_to_fixed() { assert_eq!( Percent::new(154, 10000).to_fixed(2, Rounding::RoundHalfUp), - "1.54".to_string() + "1.5".to_string() ); } } diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index 8868e4a..e633194 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -195,7 +195,7 @@ mod test { let p = Price::new(TOKEN0_6.clone(), TOKEN1.clone(), 123, 456); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "0.000000000003707" + "3.707E-12" ); } @@ -204,7 +204,7 @@ mod test { let p = Price::new(TOKEN0_6.clone(), TOKEN1.clone(), 456, 123); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "0.0000000000002697" + "2.697E-13" ); } @@ -213,7 +213,7 @@ mod test { let p = Price::new(TOKEN1.clone(), TOKEN0_6.clone(), 456, 123); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "269700000000" + "2.697E+11" ); } } From 78b5e9dc224ee5cab15109c9aab9b5cdf6cce767 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sun, 17 Mar 2024 08:54:32 +0100 Subject: [PATCH 02/31] fix big-decimal issue --- Cargo.toml | 2 +- README.md | 2 +- src/entities/fractions/currency_amount.rs | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0dc7eea..d600b0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core" -version = "0.20.0" +version = "0.21.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/README.md b/README.md index 5d5dd4f..74834dd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Add this to your Cargo.toml ``` [dependencies] -uniswap-sdk-core = "0.20.0"; +uniswap-sdk-core = "0.21.0"; ``` And this to your code: diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 0392bb3..0fdf47e 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -117,12 +117,12 @@ impl CurrencyAmount { if !decimal_places <= self.currency.decimals() { return Err(Error::NotEqual()); } - + if decimal_places == 0 { // Directly convert the numerator to a string for zero decimal places return Ok(self.numerator().to_string()); } - + Ok( (self.as_fraction() / Fraction::new(self.decimal_scale.clone(), 1)) .to_fixed(decimal_places, rounding), @@ -194,7 +194,7 @@ mod tests { #[test] #[should_panic(expected = "AMOUNT")] - fn test_token_amount_quotient_exceeds_max_uint256() { + fn test_token_amount_quotient_exceeds_max_uint256() { let numerator: BigInt = (MAX_UINT256.clone() + 1) * 2; let _w = CurrencyAmount::from_fractional_amount(TOKEN18.clone(), numerator, 2); assert!(_w.is_ok(), "AMOUNT"); @@ -219,7 +219,10 @@ mod tests { #[test] fn to_fixed_0_decimals() { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 12345896).unwrap(); - assert_eq!(amount.to_fixed(0, Rounding::RoundHalfUp).unwrap(), "12345896"); + assert_eq!( + amount.to_fixed(0, Rounding::RoundHalfUp).unwrap(), + "12345896" + ); } #[test] From 12aab8d018f7c0f3f3c67fb97488cef3d61cbcfc Mon Sep 17 00:00:00 2001 From: malik672 Date: Fri, 22 Mar 2024 17:43:48 +0100 Subject: [PATCH 03/31] docs and example --- Cargo.toml | 4 +- README.md | 2 +- src/addresses.rs | 103 +++++++++++++++++++++- src/chains.rs | 41 +++++++++ src/constants.rs | 19 +++- src/entities/base_currency.rs | 30 +++++++ src/entities/currency.rs | 19 ++++ src/entities/fractions/currency_amount.rs | 2 + src/entities/fractions/fraction.rs | 16 +++- src/entities/fractions/mod.rs | 7 ++ src/entities/fractions/percent.rs | 2 +- src/entities/fractions/price.rs | 5 ++ src/entities/mod.rs | 12 +++ src/entities/token.rs | 28 ++++++ src/entities/weth9.rs | 9 ++ src/error.rs | 2 +- src/examples/mod.rs | 2 + src/examples/token_example.rs | 28 ++++++ src/lib.rs | 27 ++++++ src/utils/mod.rs | 3 + 20 files changed, 352 insertions(+), 9 deletions(-) create mode 100644 src/examples/mod.rs create mode 100644 src/examples/token_example.rs diff --git a/Cargo.toml b/Cargo.toml index d600b0e..68b4430 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-sdk-core" -version = "0.21.0" +version = "0.22.0" edition = "2021" authors = ["malik ", "Shuhui Luo "] description = "The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap decentralized exchange" @@ -13,10 +13,8 @@ eth_checksum = { version = "0.1.2", optional = true } lazy_static = "1.4" num-bigint = "0.4.4" num-integer = "0.1.45" -num-rational = "0.4.1" num-traits = "0.2.17" regex = { version = "1.10", optional = true } -syn = "2.0" thiserror = "1.0" [features] diff --git a/README.md b/README.md index 74834dd..4846af7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Add this to your Cargo.toml ``` [dependencies] -uniswap-sdk-core = "0.21.0"; +uniswap-sdk-core = "0.22.0"; ``` And this to your code: diff --git a/src/addresses.rs b/src/addresses.rs index a8b02f8..d1844f5 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -4,7 +4,13 @@ type AddressMap = HashMap; type ChainMap = HashMap; type ChainAddress = HashMap; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] + +/// Represents the addresses of various contracts on a network. +/// +/// This struct holds the addresses for various Uniswap contracts such as the +/// core factory, multicall, quoter, migrator, and others. Each field in the struct +/// corresponds to a specific contract and its address on the network. pub struct ChainAddresses { v3_core_factory_address: Address, multicall_address: Address, @@ -16,6 +22,10 @@ pub struct ChainAddresses { v1_mixed_route_quoter_address: Option
, } +/// The default networks that are supported by the Uniswap SDK Core. +/// +/// This constant defines the default networks that the SDK will interact with. +/// It includes the mainnet, Goerli, and Sepolia networks. pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, ChainId::SEPOLIA]; /// returns a hashmap of key pair input of chainid to address @@ -38,6 +48,11 @@ pub fn construct_same_address_map(address: Address, additional_networks: &[Chain } lazy_static! { + /// The UNI_ADDRESSES struct holds a map of addresses for the UNI token on various networks. + /// + /// This map is constructed using the `construct_same_address_map` function, which takes an address + /// and a list of additional networks, and returns a map where each network ID is associated + /// with the provided address. The default networks include Mainnet, Goerli, and Sepolia. #[derive(Debug, Clone, Copy)] pub static ref UNI_ADDRESSES: AddressMap = construct_same_address_map( address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984"), @@ -51,12 +66,19 @@ lazy_static! { ); } +/// The address for the Uniswap NFT airdrop claim contract. pub const UNISWAP_NFT_AIRDROP_CLAIM_ADDRESS: Address = address!("8B799381ac40b838BBA4131ffB26197C432AFe78"); +/// The address for the Uniswap V2 Factory Address claim contract. pub const V2_FACTORY_ADDRESS: Address = address!("5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"); lazy_static! { + /// A map of Uniswap V2 Factory addresses for various networks. + /// + /// This map is used to look up the address of the Uniswap V2 Factory contract + /// for a given network. The keys in the map are the network IDs, and the values + /// are the corresponding contract addresses. pub static ref V2_FACTORY_ADDRESSES: HashMap = { let mut m = HashMap::new(); m.insert(ChainId::MAINNET as u64, V2_FACTORY_ADDRESS); @@ -97,9 +119,15 @@ lazy_static! { }; } +/// The address for the Uniswap V2 Router Address claim contract. pub const V2_ROUTER_ADDRESS: Address = address!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); lazy_static! { + /// A map of Uniswap V2 Router addresses for various networks. + /// + /// This map is used to look up the address of the Uniswap V2 Router contract + /// for a given network. The keys in the map are the network IDs, and the values + /// are the corresponding contract addresses. pub static ref V2_ROUTER_ADDRESSES: HashMap = { let mut m = HashMap::new(); m.insert(ChainId::MAINNET as u64, V2_ROUTER_ADDRESS); @@ -152,6 +180,10 @@ impl Default for ChainAddresses { } lazy_static! { + /// The `MAINNET_ADDRESSES` struct holds the Uniswap contract addresses for the Ethereum Mainnet. + /// + /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. + /// Each field in the struct corresponds to a specific contract and its address on the Mainnet. pub static ref MAINNET_ADDRESSES: ChainAddresses = { ChainAddresses { v1_mixed_route_quoter_address: Some(address!( @@ -163,6 +195,10 @@ lazy_static! { } lazy_static! { + /// The `MAINNET_ADDRESSES` struct holds the Uniswap contract addresses for the Goerli Testnet. + /// + /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. + /// Each field in the struct corresponds to a specific contract and its address on the Mainnet. pub static ref GOERLI_ADDRESSES: ChainAddresses = { ChainAddresses { v1_mixed_route_quoter_address: Some(address!( @@ -174,10 +210,18 @@ lazy_static! { } lazy_static! { + /// The `OPTIMISM_ADDRESSES` struct holds the Uniswap contract addresses for the Optimism network. + /// + /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. + /// Each field in the struct corresponds to a specific contract and its address on the Optimism network. pub static ref OPTIMISM_ADDRESSES: ChainAddresses = ChainAddresses::default(); } lazy_static! { + /// The `ARBITRUM_ONE_ADDRESSES` struct holds the Uniswap contract addresses for the Arbitrum One network. + /// + /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. + /// Each field in the struct corresponds to a specific contract and its address on the Arbitrum One network. pub static ref ARBITUM_ONE_ADDRESSES: ChainAddresses = { ChainAddresses { multicall_address: address!("adF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB"), @@ -187,6 +231,10 @@ lazy_static! { }; } lazy_static! { + /// The `POLYGON_ADDRESSES` struct holds the Uniswap contract addresses for the Polygon network. + /// + /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. + /// Each field in the struct corresponds to a specific contract and its address on the Polygon network. pub static ref POLYGON_ADDRESSES: ChainAddresses = ChainAddresses::default(); } @@ -373,6 +421,11 @@ pub const ROOTSTOCK_ADDRESSES: ChainAddresses = ChainAddresses { }; lazy_static! { + /// A map of chain IDs to their corresponding Uniswap contract addresses. + /// + /// This map is used to look up the addresses of various Uniswap contracts + /// for a given network. The keys in the map are the network IDs, and the values + /// are the corresponding contract addresses. pub static ref CHAIN_TO_ADDRESSES_MAP: ChainMap = { let mut new_map = ChainMap::new(); new_map.insert(ChainId::BNB as u64, BNB_ADDRESSES); @@ -485,11 +538,19 @@ pub static ref GOVERNANCE_BRAVO_ADDRESSES: AddressMap = { } lazy_static! { + /// The `TIMELOCK_ADDRESSES` struct holds the timelock contract addresses for various networks. + /// + /// This includes the addresses for the timelock contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref TIMELOCK_ADDRESSES: AddressMap = construct_same_address_map(address!("1a9C8182C09F50C8318d769245beA52c32BE35BC"), &[]); } lazy_static! { + /// The `MERKLE_DISTRIBUTOR_ADDRESS` struct holds the merkle distributor contract address for the mainnet. + /// + /// This includes the address for the merkle distributor contract on the mainnet. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = { let mut new_map = AddressMap::new(); new_map.insert( @@ -501,6 +562,10 @@ lazy_static! { } lazy_static! { + /// The `ARGENT_WALLET_DETECTOR_ADDRESS` struct holds the Argent Wallet Detector contract address for the mainnet. + /// + /// This includes the address for the Argent Wallet Detector contract on the mainnet. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = { let mut new_map = AddressMap::new(); new_map.insert( @@ -512,6 +577,10 @@ lazy_static! { } lazy_static! { + /// The `QUOTER_ADDRESSES` struct holds the quoter contract addresses for various networks. + /// + /// This includes the addresses for the quoter contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network pub static ref QUOTER_ADDRESSES: ChainAddress = { let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { @@ -528,6 +597,10 @@ lazy_static! { } lazy_static! { + /// The `NONFUNGIBLE_POSITION_MANAGER_ADDRESSES` struct holds the non-fungible position manager contract addresses for various networks. + /// + /// This includes the addresses for the non-fungible position manager contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: ChainAddress = { let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { @@ -552,11 +625,19 @@ lazy_static! { } lazy_static! { + /// The `ENS_REGISTRAR_ADDRESSES` struct holds the ENS Registrar contract addresses for various networks. + /// + /// This includes the addresses for the ENS Registrar contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref ENS_REGISTRAR_ADDRESSES: AddressMap = construct_same_address_map(address!("00000000000C2E074eC69A0dFb2997BA6C7d2e1e"), &[]); } lazy_static! { + /// The `SOCKS_CONTROLLER_ADDRESSES` struct holds the SOCKS Controller contract addresses for various networks. + /// + /// This includes the addresses for the SOCKS Controller contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref SOCKS_CONTROLLER_ADDRESSES: AddressMap = { let mut new_map = AddressMap::new(); new_map.insert( @@ -568,6 +649,10 @@ lazy_static! { } lazy_static! { + /// The `TICK_LENS_ADDRESSES` struct holds the tick lens contract addresses for various networks. + /// + /// This includes the addresses for the tick lens contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref TICK_LENS_ADDRESSES: ChainAddress = { let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { @@ -592,6 +677,10 @@ lazy_static! { } lazy_static! { + /// The `MIXED_ROUTE_QUOTER_V1_ADDRESSES` struct holds the mixed route quoter contract addresses for various networks. + /// + /// This includes the addresses for the mixed route quoter contract on different networks. + /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MIXED_ROUTE_QUOTER_V1_ADDRESSES: ChainAddress = { let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { @@ -615,6 +704,18 @@ lazy_static! { }; } +/// Returns the address of the Uniswap V2 Router contract for the specified chain. +/// +/// If the chain ID is not found in the `CHAIN_TO_ADDRESSES_MAP`, it defaults to the +/// address of the router contract on the Ethereum mainnet. +/// +/// # Arguments +/// +/// * `chain_id` - The ID of the chain for which to retrieve the router address. +/// +/// # Returns +/// +/// * `Address` - The address of the Uniswap V2 Router contract for the specified chain. pub fn swap_router02_address(chain_id: u64) -> Address { if CHAIN_TO_ADDRESSES_MAP.contains_key(&chain_id) && CHAIN_TO_ADDRESSES_MAP diff --git a/src/chains.rs b/src/chains.rs index 2d177df..2234b95 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -1,29 +1,58 @@ #[derive(Debug, Clone, Copy)] +/// Represents the unique identifier for different blockchain networks supported by the Uniswap SDK. +/// +/// Each variant corresponds to a specific blockchain network, identified by its unique chain ID. pub enum ChainId { + /// The Ethereum Mainnet. MAINNET = 1, + /// The Goerli Testnet. GOERLI = 5, + /// The Sepolia Testnet. SEPOLIA = 11155111, + /// The Optimism network. OPTIMISM = 10, + /// The Optimism Goerli Testnet. OPTIMISMGOERLI = 420, + /// The Optimism Sepolia Testnet. OPTIMISMSEPOLIA = 11155420, + /// The Arbitrum One network. ARBITRUMONE = 42161, + /// The Arbitrum Goerli Testnet. ARBITRUMGOERLI = 421613, + /// The Arbitrum Sepolia Testnet. ARBITRUMSEPOLIA = 421614, + /// The Polygon network. POLYGON = 137, + /// The Polygon Mumbai Testnet. POLYGONMUMBAI = 80001, + /// The Celo network. CELO = 42220, + /// The Celo Alfajores Testnet. CELOALFAJORES = 44787, + /// The Gnosis network. GNOSIS = 100, + /// The Moonbeam network. MOONBEAM = 1284, + /// The Binance Smart Chain (BSC). BNB = 56, + /// The Avalanche network. AVALANCHE = 43114, + /// The Base network. BASEGOERLI = 84531, + /// The Base Goerli Testnet. BASE = 8453, + /// The Zora network. ZORA = 7777777, + /// The Zora Sepolia Testnet. ZORASEPOLIA = 999999999, + /// The Rootstock network. ROOTSTOCK = 30, } +/// A list of `ChainId` constants representing the blockchain networks supported by the Uniswap SDK. +/// +/// This array includes all the `ChainId` variants that are supported by the SDK, making it easy to +/// iterate over or check for supported chains. pub const SUPPORTED_CHAINS: [ChainId; 20] = [ ChainId::MAINNET, ChainId::OPTIMISM, @@ -47,13 +76,25 @@ pub const SUPPORTED_CHAINS: [ChainId; 20] = [ ChainId::ROOTSTOCK, ]; +#[derive(Debug, Clone, Copy)] +/// Represents the names of native currencies supported by the Uniswap SDK. +/// +/// Each variant corresponds to a specific native currency name. pub enum NativeCurrencyName { + /// Ethereum's native currency. ETHER, + /// Polygon's native currency. MATIC, + /// Celo's native currency. CELO, + /// Gnosis's native currency. GNOSIS, + /// Moonbeam's native currency. MOONBEAM, + /// Binance Smart Chain's native currency. BNB, + /// Avalanche's native currency. AVAX, + /// Rootstock's native currency. ROOTSTOCK, } diff --git a/src/constants.rs b/src/constants.rs index d2fc50e..79f1487 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,19 +3,36 @@ use alloy_primitives::U256; use num_bigint::Sign; #[derive(Clone, Copy, Debug, PartialEq)] +/// Represents the type of trade in the Uniswap SDK. +/// +/// This enum is used to specify whether a trade is an exact input or an exact output. pub enum TradeType { + /// Indicates that the trade is based on an exact input amount. ExactInput, + /// Indicates that the trade is based on an exact output amount. ExactOutput, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Copy)] +/// Represents a rounding strategy. pub enum Rounding { + /// Rounds down to the nearest whole number. + /// + /// This variant indicates that the rounding should always go towards zero. RoundDown, + /// Rounds to the nearest whole number, rounding halfway cases away from zero. + /// + /// This variant indicates that the rounding should round to the nearest whole number, with + /// halfway cases rounded away from zero. RoundHalfUp, + /// Rounds up to the nearest whole number. + /// + /// This variant indicates that the rounding should always go towards positive infinity. RoundUp, } lazy_static! { + /// The maximum value representable by a `BigInt` in this context, equivalent to the maximum value of a `U256`. pub static ref MAX_UINT256: BigInt = BigInt::from_bytes_be(Sign::Plus, &U256::MAX.to_be_bytes::<32>()); } diff --git a/src/entities/base_currency.rs b/src/entities/base_currency.rs index 4a43e65..7035c93 100644 --- a/src/entities/base_currency.rs +++ b/src/entities/base_currency.rs @@ -3,11 +3,41 @@ use std::ops::Deref; use alloy_primitives::ChainId; #[derive(Clone, PartialEq, Debug)] + +/// `CurrencyLike` is a generic struct representing a currency with a specific chain ID, +/// decimals, symbol, name, and additional metadata. +/// +/// This struct is used to abstract the details of different currencies, allowing for +/// a unified way to handle various types of currencies in the Uniswap SDK Core. +/// +/// # Generics +/// +/// - `M`: The type of the additional metadata associated with the currency. pub struct CurrencyLike { + /// The chain ID on which this currency resides. + /// + /// This identifies the blockchain network where the currency is used. pub chain_id: ChainId, + + /// The number of decimal places the currency can be divided into. + /// + /// This is used to represent the smallest unit of the currency. pub decimals: u8, + + /// The symbol of the currency, i.e., a short textual non-unique identifier. + /// + /// This is a common abbreviation used to represent the currency. pub symbol: Option, + + /// The name of the currency, i.e., a descriptive textual non-unique identifier. + /// + /// This is a more detailed name used to represent the currency. pub name: Option, + + /// Additional metadata associated with the currency. + /// + /// This can include various details specific to the currency, such as contract addresses or + /// other relevant information. pub meta: M, } diff --git a/src/entities/currency.rs b/src/entities/currency.rs index 833b878..274c332 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -1,15 +1,34 @@ use crate::prelude::*; #[derive(Clone, PartialEq, Debug)] +/// Represents a currency in the Uniswap SDK. +/// +/// This enum can represent either a native currency (like Ether) or a token. pub enum Currency { + /// Represents a native currency. NativeCurrency(Ether), + /// Represents a token. Token(Token), } +/// Trait for representing a currency in the Uniswap SDK. +/// +/// This trait provides methods for interacting with currencies, whether they are native currencies +/// like Ether or tokens. Implementations of this trait must provide functionality for determining +/// if a currency is native, getting its address, checking equality with another currency, and +/// wrapping the currency for use with Uniswap contracts. pub trait CurrencyTrait: BaseCurrency { /// Returns whether the currency is native to the chain and must be wrapped (e.g. Ether) fn is_native(&self) -> bool; + /// Returns the address of the currency. + /// + /// This method returns the address associated with the currency, whether it's a native currency + /// or a token. + /// + /// # Returns + /// + /// * `Address` - The address of the currency. fn address(&self) -> Address; /// Returns whether this currency is functionally equivalent to the other currency diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 0fdf47e..d6d7ebb 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -7,7 +7,9 @@ pub type CurrencyAmount = FractionLike>; /// Struct representing metadata about a currency #[derive(Clone, Debug, PartialEq)] pub struct CurrencyMeta { + /// The currency associated with this metadata pub currency: T, + /// The scale factor for the currency's decimal places pub decimal_scale: BigUint, } diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 171d549..74df9c3 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -7,6 +7,7 @@ use std::ops::{Add, Deref, Mul, Sub}; pub struct FractionLike { numerator: BigInt, denominator: BigInt, + /// Metadata associated with the fraction pub meta: M, } @@ -33,7 +34,20 @@ impl Deref for FractionLike { pub type Fraction = FractionLike<()>; impl Fraction { - // Constructor for creating a new Fraction instance + /// Creates a new `Fraction` instance with the given numerator and denominator. + /// + /// # Arguments + /// + /// * `numerator` - The numerator of the fraction. + /// * `denominator` - The denominator of the fraction. + /// + /// # Returns + /// + /// A new `Fraction` instance with the specified numerator and denominator. + /// + /// # Panics + /// + /// This function will panic if the denominator is zero. pub fn new(numerator: impl Into, denominator: impl Into) -> Self { FractionBase::new(numerator, denominator, ()) } diff --git a/src/entities/fractions/mod.rs b/src/entities/fractions/mod.rs index 0d4f58f..0e4a7f3 100644 --- a/src/entities/fractions/mod.rs +++ b/src/entities/fractions/mod.rs @@ -1,4 +1,11 @@ +/// This module contains functionality related to currency amounts in the context of fractions. pub mod currency_amount; +/// This module contains functionality related to fractions, which are used for various calculations +/// in the SDK. pub mod fraction; +/// This module contains functionality related to percentages, which are used for expressing +/// fractions in a more human-readable format. pub mod percent; +/// This module contains functionality related to prices, which are used for calculating exchange +/// rates and other financial metrics. pub mod price; diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index ed5b85b..f653696 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, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Copy)] pub struct IsPercent; /// Type alias for a Percent, a [`FractionLike`] with the [`IsPercent`] metadata diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index e633194..e9bbd10 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -11,8 +11,13 @@ where TBase: CurrencyTrait, TQuote: CurrencyTrait, { + /// The base currency for the price pub base_currency: TBase, + + /// The quote currency for the price pub quote_currency: TQuote, + + /// The scalar used to adjust the price for decimal places pub scalar: Fraction, } diff --git a/src/entities/mod.rs b/src/entities/mod.rs index fbd5c8a..28eaa83 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -1,6 +1,18 @@ +/// The `base_currency` module provides functionality related to the base currency used in the +/// Uniswap SDK Core. pub mod base_currency; +/// The `currency` module contains definitions and utilities for handling various currencies +/// supported by the Uniswap SDK Core. pub mod currency; +/// The `ether` module provides utilities and functionalities specific to Ether, the native +/// cryptocurrency of the Ethereum blockchain. pub mod ether; +/// The `fractions` module contains functionality related to fractional values, such as currency +/// amounts, percentages, and prices. pub mod fractions; +/// The `token` module provides definitions and utilities for handling tokens on the Uniswap +/// platform, including their creation, management, and interactions. pub mod token; +/// The `weth9` module provides functionalities specific to Wrapped Ether (WETH9), a standard ERC-20 +/// token representation of Ether on the Ethereum blockchain. pub mod weth9; diff --git a/src/entities/token.rs b/src/entities/token.rs index 06ec6aa..79e9c24 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -4,9 +4,18 @@ use crate::prelude::*; pub type Token = CurrencyLike; #[derive(Clone, PartialEq, Debug)] + +/// Represents the metadata for an ERC20 token, including its address and optional fees. +/// +/// This struct holds the address of the token and optional buy and sell fees in basis points (bps). +/// It is used to provide additional information about the token that is not directly related to its +/// value or quantity. pub struct TokenMeta { + /// The address of the token. pub address: Address, + /// The buy fee in basis points (bps) for the token. pub buy_fee_bps: Option, + /// The sell fee in basis points (bps) for the token. pub sell_fee_bps: Option, } @@ -40,6 +49,25 @@ impl CurrencyTrait for Token { } impl Token { + /// Creates a new `Token` with the given parameters. + /// + /// # Arguments + /// + /// * `chain_id` - The chain ID of the token. + /// * `address` - The address of the token. + /// * `decimals` - The number of decimals the token uses. + /// * `symbol` - The symbol of the token, if any. + /// * `name` - The name of the token, if any. + /// * `buy_fee_bps` - The buy fee in basis points (bps), if any. + /// * `sell_fee_bps` - The sell fee in basis points (bps), if any. + /// + /// # Returns + /// + /// A new `Token` instance. + /// + /// # Panics + /// + /// Panics if `chain_id` is 0. pub const fn new( chain_id: u64, address: Address, diff --git a/src/entities/weth9.rs b/src/entities/weth9.rs index d0b2a9c..13cab0f 100644 --- a/src/entities/weth9.rs +++ b/src/entities/weth9.rs @@ -17,6 +17,15 @@ impl Default for WETH9 { } impl WETH9 { + /// Creates a new instance of `WETH9` with predefined WETH tokens for various chains. + /// + /// This function initializes a `WETH9` struct with a predefined set of WETH tokens + /// for different Ethereum chains. It's useful for quickly setting up a `WETH9` + /// instance without manually inserting each token. + /// + /// # Returns + /// + /// A new `WETH9` instance with predefined WETH tokens. pub fn new() -> Self { let mut tokens = HashMap::new(); diff --git a/src/error.rs b/src/error.rs index cb433eb..6e3e8da 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ use crate::prelude::*; /// Represents errors that can occur in the context of currency operations. -#[derive(Debug, Error)] +#[derive(Debug, Error, Clone, Copy)] pub enum Error { /// Indicates a mismatch in chain IDs. #[error("Chain IDs do not match: {0} and {1}")] diff --git a/src/examples/mod.rs b/src/examples/mod.rs new file mode 100644 index 0000000..9e7b267 --- /dev/null +++ b/src/examples/mod.rs @@ -0,0 +1,2 @@ +///token example +pub mod token_example; diff --git a/src/examples/token_example.rs b/src/examples/token_example.rs new file mode 100644 index 0000000..22941b6 --- /dev/null +++ b/src/examples/token_example.rs @@ -0,0 +1,28 @@ +// token_example.rs + +// Import the Token struct from the Uniswap SDK-Core +use crate::entities::token::Token; + +/// This function demonstrates basic operations with the Token struct from the Uniswap SDK-Core. +pub fn main() { + // Create a new Token instance for DAI + let dai_token = Token::new( + 1, // Assuming chain_id is 1 for Ethereum mainnet + "0x6B175474E89094C44Da98b954EedeAC495271d0F" + .parse() + .unwrap(), // Assuming this is the correct address + 18, // Decimals for DAI + Some("DAI".to_string()), // Symbol for DAI + Some("Dai Stablecoin".to_string()), // Name for DAI + None, // Assuming no buy fee + None, // Assuming no sell fee + ); + + // Print the token's address and decimals + println!("DAI Token Address: {}", dai_token.address); + println!("DAI Token Decimals: {}", dai_token.decimals); + + // Convert a token chain id + let token_id = dai_token.chain_id; + println!("token_id {}", token_id); +} diff --git a/src/lib.rs b/src/lib.rs index 88ef78c..17eac0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,11 +2,38 @@ //! //! The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap //! decentralized exchange. +#![warn( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + unreachable_pub, + clippy::missing_const_for_fn, + rustdoc::all +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +/// Contains functionality related to All Contracts deployed and supported by the Uniswap SDK. pub mod addresses; +/// Contains functionality related to All Contracts deployed and supported by the Uniswap SDK. pub mod chains; +/// Contains some constants and enums used in the Uniswap SDK Core pub mod constants; +/// Contains entities related to the Uniswap SDK Core, such as currencies, tokens, and fractions. pub mod entities; +/// Contains error types for the Uniswap SDK Core. +/// +/// This module defines custom error types that are used throughout the SDK to +/// handle various error conditions. pub mod error; +/// Contains commonly used items from the Uniswap SDK Core. +/// +/// This module re-exports items that are commonly used together, +/// making it easier to import them in other parts of your application. pub mod prelude; +/// Contains utility functions and helpers used across the Uniswap SDK Core. pub mod utils; + +/// Contains examples of how Uniswap sdk core can be used +pub mod examples; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 6fcb698..06539c8 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,8 @@ +/// Contains functionality related to computing the price impact of trades. pub mod compute_price_impact; +/// Contains functionality for inserting elements into a sorted collection. pub mod sorted_insert; +/// Contains functionality related to square root calculations. pub mod sqrt; #[cfg(feature = "validate_parse_address")] pub mod validate_and_parse_address; From c849dd71939c3a8931b8e0ae5255c4cce465783b Mon Sep 17 00:00:00 2001 From: malik672 Date: Sun, 24 Mar 2024 19:23:26 +0100 Subject: [PATCH 04/31] changes --- src/entities/fractions/currency_amount.rs | 13 +++++-------- src/entities/fractions/mod.rs | 14 +++++++------- src/entities/fractions/percent.rs | 4 ++-- src/entities/fractions/price.rs | 6 +++--- src/entities/mod.rs | 4 ++-- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 618ec36..a768de7 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -219,11 +219,8 @@ mod tests { #[test] fn to_fixed_0_decimals() { - let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 12345896).unwrap(); - assert_eq!( - amount.to_fixed(0, Rounding::RoundHalfUp).unwrap(), - "12345896" - ); + let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 123456).unwrap(); + assert_eq!(amount.to_fixed(0, Rounding::RoundDown).unwrap(), "123456"); } #[test] @@ -240,7 +237,7 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 1000).unwrap(); assert_eq!( amount.to_significant(3, Rounding::RoundDown).unwrap(), - "1E+3" + "1000" ); } @@ -249,7 +246,7 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN0.clone(), 123456).unwrap(); assert_eq!( amount.to_significant(4, Rounding::RoundDown).unwrap(), - "1.234E+5" + "123400" ); } @@ -279,4 +276,4 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN18.clone(), 123e13 as i64).unwrap(); assert_eq!(amount.to_exact(), "0.00123"); } -} +} \ No newline at end of file diff --git a/src/entities/fractions/mod.rs b/src/entities/fractions/mod.rs index 0e4a7f3..cb45c95 100644 --- a/src/entities/fractions/mod.rs +++ b/src/entities/fractions/mod.rs @@ -1,11 +1,11 @@ -/// This module contains functionality related to currency amounts in the context of fractions. +/// This module represents currency, including the currency type and the amount as a fraction, also including. +/// methods for arithmetic operations, conversions to and from string representations, and checks for validity. pub mod currency_amount; -/// This module contains functionality related to fractions, which are used for various calculations -/// in the SDK. +/// This module contains with precise division results, avoiding floating-point arithmetic issues, also including +/// operations like addition, subtraction, multiplication, and division, as well as conversions to other formats. pub mod fraction; -/// This module contains functionality related to percentages, which are used for expressing -/// fractions in a more human-readable format. +/// A module represents a percentage as a fraction, with methods for arithmetic and string conversions, it also includes +/// methods for precise calculations involving percentages and ensures accurate representation of percentage values. pub mod percent; -/// This module contains functionality related to prices, which are used for calculating exchange -/// rates and other financial metrics. +/// A module represents' a price as a ratio between two currencies, with methods for arithmetic and string conversions. pub mod price; diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index f653696..be6bc27 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -107,7 +107,7 @@ mod tests { fn test_to_fixed() { assert_eq!( Percent::new(154, 10000).to_fixed(2, Rounding::RoundHalfUp), - "1.5".to_string() + "1.54".to_string() ); } -} +} \ No newline at end of file diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index e9bbd10..b81c4fc 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -200,7 +200,7 @@ mod test { let p = Price::new(TOKEN0_6.clone(), TOKEN1.clone(), 123, 456); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "3.707E-12" + "0.000000000003707" ); } @@ -209,7 +209,7 @@ mod test { let p = Price::new(TOKEN0_6.clone(), TOKEN1.clone(), 456, 123); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "2.697E-13" + "0.0000000000002697" ); } @@ -218,7 +218,7 @@ mod test { let p = Price::new(TOKEN1.clone(), TOKEN0_6.clone(), 456, 123); assert_eq!( p.to_significant(4, Rounding::RoundDown).unwrap(), - "2.697E+11" + "269700000000" ); } } diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 28eaa83..3452c63 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -10,8 +10,8 @@ pub mod ether; /// The `fractions` module contains functionality related to fractional values, such as currency /// amounts, percentages, and prices. pub mod fractions; -/// The `token` module provides definitions and utilities for handling tokens on the Uniswap -/// platform, including their creation, management, and interactions. +/// The `token` module provides definitions and utilities for handling tokens including +/// their creation, management, and interactions. pub mod token; /// The `weth9` module provides functionalities specific to Wrapped Ether (WETH9), a standard ERC-20 /// token representation of Ether on the Ethereum blockchain. From 30d26262d94b18b6d3e82d7f027fb3b883b20d74 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sun, 24 Mar 2024 19:24:52 +0100 Subject: [PATCH 05/31] changes --- src/entities/fractions/currency_amount.rs | 2 +- src/entities/fractions/mod.rs | 18 +++++++++++------- src/entities/fractions/percent.rs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index a768de7..19c5d8a 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -276,4 +276,4 @@ mod tests { let amount = CurrencyAmount::from_raw_amount(TOKEN18.clone(), 123e13 as i64).unwrap(); assert_eq!(amount.to_exact(), "0.00123"); } -} \ No newline at end of file +} diff --git a/src/entities/fractions/mod.rs b/src/entities/fractions/mod.rs index cb45c95..ea5946e 100644 --- a/src/entities/fractions/mod.rs +++ b/src/entities/fractions/mod.rs @@ -1,11 +1,15 @@ -/// This module represents currency, including the currency type and the amount as a fraction, also including. -/// methods for arithmetic operations, conversions to and from string representations, and checks for validity. +/// This module represents currency, including the currency type and the amount as a fraction, also +/// including. methods for arithmetic operations, conversions to and from string representations, +/// and checks for validity. pub mod currency_amount; -/// This module contains with precise division results, avoiding floating-point arithmetic issues, also including -/// operations like addition, subtraction, multiplication, and division, as well as conversions to other formats. +/// This module contains with precise division results, avoiding floating-point arithmetic issues, +/// also including operations like addition, subtraction, multiplication, and division, as well as +/// conversions to other formats. pub mod fraction; -/// A module represents a percentage as a fraction, with methods for arithmetic and string conversions, it also includes -/// methods for precise calculations involving percentages and ensures accurate representation of percentage values. +/// A module represents a percentage as a fraction, with methods for arithmetic and string +/// conversions, it also includes methods for precise calculations involving percentages and ensures +/// accurate representation of percentage values. pub mod percent; -/// A module represents' a price as a ratio between two currencies, with methods for arithmetic and string conversions. +/// A module represents' a price as a ratio between two currencies, with methods for arithmetic and +/// string conversions. pub mod price; diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index be6bc27..a68cc57 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -110,4 +110,4 @@ mod tests { "1.54".to_string() ); } -} \ No newline at end of file +} From d05ac13850edf5b0e0ab11b85bdd8d189f37b704 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 13 Apr 2024 14:00:17 +0100 Subject: [PATCH 06/31] change hash table --- Cargo.toml | 1 + src/addresses.rs | 44 +++++++++++------------ src/constants.rs | 2 +- src/entities/ether.rs | 2 +- src/entities/fractions/currency_amount.rs | 10 +++--- src/entities/fractions/fraction.rs | 6 ++-- src/entities/weth9.rs | 4 +-- src/error.rs | 2 +- src/lib.rs | 3 ++ src/prelude.rs | 3 +- 10 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 153b809..ecc02d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ num-bigint = "0.4.4" num-integer = "0.1.45" num-traits = "0.2.17" regex = { version = "1.10", optional = true } +rustc-hash = "1.1.0" thiserror = "1.0" [features] diff --git a/src/addresses.rs b/src/addresses.rs index d1844f5..7447d01 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -1,8 +1,8 @@ use crate::prelude::*; -type AddressMap = HashMap; -type ChainMap = HashMap; -type ChainAddress = HashMap; +type AddressMap = FxHashMap; +type ChainMap = FxHashMap; +type ChainAddress = FxHashMap; #[derive(Clone, Copy, Debug)] @@ -40,7 +40,7 @@ pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, C 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); - let mut map = AddressMap::new(); + let mut map = AddressMap::default(); for chain_id in networks { map.insert(chain_id as u64, address); } @@ -79,8 +79,8 @@ lazy_static! { /// This map is used to look up the address of the Uniswap V2 Factory contract /// for a given network. The keys in the map are the network IDs, and the values /// are the corresponding contract addresses. - pub static ref V2_FACTORY_ADDRESSES: HashMap = { - let mut m = HashMap::new(); + pub static ref V2_FACTORY_ADDRESSES: FxHashMap = { + let mut m = FxHashMap::default(); m.insert(ChainId::MAINNET as u64, V2_FACTORY_ADDRESS); m.insert(ChainId::GOERLI as u64, V2_FACTORY_ADDRESS); m.insert( @@ -119,7 +119,7 @@ lazy_static! { }; } -/// The address for the Uniswap V2 Router Address claim contract. +/// pub const V2_ROUTER_ADDRESS: Address = address!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); lazy_static! { @@ -128,8 +128,8 @@ lazy_static! { /// This map is used to look up the address of the Uniswap V2 Router contract /// for a given network. The keys in the map are the network IDs, and the values /// are the corresponding contract addresses. - pub static ref V2_ROUTER_ADDRESSES: HashMap = { - let mut m = HashMap::new(); + pub static ref V2_ROUTER_ADDRESSES: FxHashMap = { + let mut m = FxHashMap::default(); m.insert(ChainId::MAINNET as u64, V2_ROUTER_ADDRESS); m.insert(ChainId::GOERLI as u64, V2_ROUTER_ADDRESS); m.insert( @@ -427,7 +427,7 @@ lazy_static! { /// for a given network. The keys in the map are the network IDs, and the values /// are the corresponding contract addresses. pub static ref CHAIN_TO_ADDRESSES_MAP: ChainMap = { - let mut new_map = ChainMap::new(); + let mut new_map = ChainMap::default(); new_map.insert(ChainId::BNB as u64, BNB_ADDRESSES); new_map.insert(ChainId::AVALANCHE as u64, AVALANCHE_ADDRESSES); @@ -457,7 +457,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref V3_CORE_FACTORY_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -474,7 +474,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref V3_MIGRATOR_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -492,7 +492,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref MULTICALL_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -516,7 +516,7 @@ pub static ref GOVERNANCE_ALPHA_V0_ADDRESSES: AddressMap = { lazy_static! { /// The older V1 governance address pub static ref GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::new(); + let mut new_map = AddressMap::default(); new_map.insert( ChainId::MAINNET as u64, address!("C4e172459f1E7939D522503B81AFAaC1014CE6F6"), @@ -528,7 +528,7 @@ pub static ref GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap = { lazy_static! { /// The latest governor bravo that is currently admin of timelock pub static ref GOVERNANCE_BRAVO_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::new(); + let mut new_map = AddressMap::default(); new_map.insert( ChainId::MAINNET as u64, address!("408ED6354d4973f66138C91495F2f2FCbd8724C3"), @@ -552,7 +552,7 @@ lazy_static! { /// This includes the address for the merkle distributor contract on the mainnet. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = { - let mut new_map = AddressMap::new(); + let mut new_map = AddressMap::default(); new_map.insert( ChainId::MAINNET as u64, address!("090D4613473dEE047c3f2706764f49E0821D256e"), @@ -567,7 +567,7 @@ lazy_static! { /// This includes the address for the Argent Wallet Detector contract on the mainnet. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = { - let mut new_map = AddressMap::new(); + let mut new_map = AddressMap::default(); new_map.insert( ChainId::MAINNET as u64, address!("eca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8"), @@ -582,7 +582,7 @@ lazy_static! { /// This includes the addresses for the quoter contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network pub static ref QUOTER_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -602,7 +602,7 @@ lazy_static! { /// This includes the addresses for the non-fungible position manager contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) @@ -639,7 +639,7 @@ lazy_static! { /// This includes the addresses for the SOCKS Controller contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref SOCKS_CONTROLLER_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::new(); + let mut new_map = AddressMap::default(); new_map.insert( ChainId::MAINNET as u64, address!("65770b5283117639760beA3F867b69b3697a91dd"), @@ -654,7 +654,7 @@ lazy_static! { /// This includes the addresses for the tick lens contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref TICK_LENS_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) @@ -682,7 +682,7 @@ lazy_static! { /// This includes the addresses for the mixed route quoter contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MIXED_ROUTE_QUOTER_V1_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::new(); + let mut chain_add = ChainAddress::default(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) diff --git a/src/constants.rs b/src/constants.rs index 79f1487..23555bb 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -14,7 +14,7 @@ pub enum TradeType { } #[derive(Clone, Debug, PartialEq, Copy)] -/// Represents a rounding strategy. +/// pub enum Rounding { /// Rounds down to the nearest whole number. /// diff --git a/src/entities/ether.rs b/src/entities/ether.rs index 1a1578e..239d68e 100644 --- a/src/entities/ether.rs +++ b/src/entities/ether.rs @@ -2,7 +2,7 @@ use crate::prelude::*; // Lazy static cache for Ether instances lazy_static! { - static ref ETHER_CACHE: Mutex> = Mutex::new(HashMap::new()); + static ref ETHER_CACHE: Mutex> = Mutex::new(FxHashMap::default()); } /// Ether is the main usage of a 'native' currency, i.e., for Ethereum mainnet and all testnets. diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 19c5d8a..f5c2cd4 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -51,7 +51,7 @@ impl CurrencyAmount { Self::new(currency, numerator, denominator) } - /// Multiplication of currency amount by another fractional amount + /// pub fn multiply(&self, other: &impl FractionBase) -> Result { let multiplied = self.as_fraction() * other.as_fraction(); Self::from_fractional_amount( @@ -61,7 +61,7 @@ impl CurrencyAmount { ) } - /// Division of currency amount by another fractional amount + /// pub fn divide(&self, other: &impl FractionBase) -> Result { let divided = self.as_fraction() / other.as_fraction(); Self::from_fractional_amount( @@ -78,7 +78,7 @@ impl CurrencyAmount { .to_string() } - /// Addition of another currency amount to the current amount + /// pub fn add(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -91,7 +91,7 @@ impl CurrencyAmount { ) } - /// Subtraction of another currency amount from the current amount + /// pub fn subtract(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -114,7 +114,7 @@ impl CurrencyAmount { .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) -> Result { if decimal_places > self.currency.decimals() { return Err(Error::NotEqual()); diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 4b0ead1..ac453e8 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -112,8 +112,7 @@ pub trait FractionBase: Sized { BigDecimal::from(self.numerator()).div(BigDecimal::from(self.denominator())) } - /// Converts the fraction to a string with a specified number of significant digits and rounding - /// strategy + /// fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> Result { if significant_digits == 0 { return Err(Error::Incorrect()); @@ -127,8 +126,7 @@ pub trait FractionBase: Sized { Ok(quotient.normalized().to_string()) } - /// Converts the fraction to a string with a fixed number of decimal places and rounding - /// strategy + /// fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { let rounding_strategy = to_rounding_strategy(rounding); self.to_decimal() diff --git a/src/entities/weth9.rs b/src/entities/weth9.rs index 13cab0f..9712d71 100644 --- a/src/entities/weth9.rs +++ b/src/entities/weth9.rs @@ -5,7 +5,7 @@ use crate::{prelude::*, token}; #[derive(Clone, PartialEq, Debug)] pub struct WETH9 { /// A mapping of chain IDs to corresponding WETH tokens. - tokens: HashMap, + tokens: FxHashMap, } /// Default implementation for [`WETH9`], creating an instance with predefined WETH tokens on @@ -27,7 +27,7 @@ impl WETH9 { /// /// A new `WETH9` instance with predefined WETH tokens. pub fn new() -> Self { - let mut tokens = HashMap::new(); + let mut tokens = FxHashMap::default(); // Insert predefined WETH tokens for different chains. tokens.insert( diff --git a/src/error.rs b/src/error.rs index 6e3e8da..fc66f86 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,7 +3,7 @@ use crate::prelude::*; /// Represents errors that can occur in the context of currency operations. #[derive(Debug, Error, Clone, Copy)] pub enum Error { - /// Indicates a mismatch in chain IDs. + /// #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u64, u64), diff --git a/src/lib.rs b/src/lib.rs index 17eac0c..0a4ca91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,9 @@ clippy::missing_const_for_fn, rustdoc::all )] +#![deny( + clippy::missin +)] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] diff --git a/src/prelude.rs b/src/prelude.rs index 92b4ecb..9862954 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -24,6 +24,7 @@ pub use num_bigint::{BigInt, BigUint, ToBigInt, ToBigUint}; pub use num_integer::Integer; pub use num_traits::{Num, ToPrimitive, Zero}; pub use std::{ - cmp::Ordering, collections::HashMap, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex, + cmp::Ordering, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex, }; +pub use rustc_hash::FxHashMap; pub use thiserror::Error; From 9a8c5efdcba62e4c27be2da3a22c1315a73a8c27 Mon Sep 17 00:00:00 2001 From: malik672 Date: Sat, 13 Apr 2024 14:07:14 +0100 Subject: [PATCH 07/31] change hash table --- src/addresses.rs | 2 +- src/constants.rs | 2 +- src/entities/fractions/currency_amount.rs | 6 +++--- src/entities/fractions/fraction.rs | 4 ++-- src/lib.rs | 4 +--- src/prelude.rs | 4 +--- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/addresses.rs b/src/addresses.rs index 7447d01..e32706e 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -119,7 +119,7 @@ lazy_static! { }; } -/// +/// pub const V2_ROUTER_ADDRESS: Address = address!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); lazy_static! { diff --git a/src/constants.rs b/src/constants.rs index 23555bb..b6e6036 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -14,7 +14,7 @@ pub enum TradeType { } #[derive(Clone, Debug, PartialEq, Copy)] -/// +/// pub enum Rounding { /// Rounds down to the nearest whole number. /// diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index f5c2cd4..9383f02 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -78,7 +78,7 @@ impl CurrencyAmount { .to_string() } - /// + /// pub fn add(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -91,7 +91,7 @@ impl CurrencyAmount { ) } - /// + /// pub fn subtract(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -114,7 +114,7 @@ impl CurrencyAmount { .to_significant(significant_digits, rounding) } - /// + /// pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> Result { if decimal_places > self.currency.decimals() { return Err(Error::NotEqual()); diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index ac453e8..8a619f5 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -112,7 +112,7 @@ pub trait FractionBase: Sized { BigDecimal::from(self.numerator()).div(BigDecimal::from(self.denominator())) } - /// + /// fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> Result { if significant_digits == 0 { return Err(Error::Incorrect()); @@ -126,7 +126,7 @@ pub trait FractionBase: Sized { Ok(quotient.normalized().to_string()) } - /// + /// fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { let rounding_strategy = to_rounding_strategy(rounding); self.to_decimal() diff --git a/src/lib.rs b/src/lib.rs index 0a4ca91..83616ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,9 +10,7 @@ clippy::missing_const_for_fn, rustdoc::all )] -#![deny( - clippy::missin -)] +#![deny(clippy::missin)] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] diff --git a/src/prelude.rs b/src/prelude.rs index 9862954..b9f9c57 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -23,8 +23,6 @@ pub use lazy_static::lazy_static; pub use num_bigint::{BigInt, BigUint, ToBigInt, ToBigUint}; pub use num_integer::Integer; pub use num_traits::{Num, ToPrimitive, Zero}; -pub use std::{ - cmp::Ordering, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex, -}; pub use rustc_hash::FxHashMap; +pub use std::{cmp::Ordering, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex}; pub use thiserror::Error; From 8500a53b217ffeece899011ce68581bdeefdce3e Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 02:40:25 +0100 Subject: [PATCH 08/31] changes to doc --- Cargo.toml | 1 - src/addresses.rs | 84 ++++++----------------- src/chains.rs | 2 - src/constants.rs | 16 ++--- src/entities/base_currency.rs | 11 --- src/entities/currency.rs | 25 +------ src/entities/ether.rs | 2 +- src/entities/fractions/currency_amount.rs | 8 +-- src/entities/fractions/fraction.rs | 22 +++--- src/entities/fractions/percent.rs | 1 - src/entities/fractions/price.rs | 1 - src/entities/mod.rs | 18 ++--- src/entities/token.rs | 4 -- src/entities/weth9.rs | 4 +- src/error.rs | 8 +-- src/lib.rs | 1 - src/prelude.rs | 5 +- src/utils/mod.rs | 6 +- 18 files changed, 63 insertions(+), 156 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ecc02d6..153b809 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ num-bigint = "0.4.4" num-integer = "0.1.45" num-traits = "0.2.17" regex = { version = "1.10", optional = true } -rustc-hash = "1.1.0" thiserror = "1.0" [features] diff --git a/src/addresses.rs b/src/addresses.rs index e32706e..67df43c 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -1,16 +1,12 @@ use crate::prelude::*; -type AddressMap = FxHashMap; -type ChainMap = FxHashMap; -type ChainAddress = FxHashMap; +type AddressMap = HashMap; +type ChainMap = HashMap; +type ChainAddress = HashMap; #[derive(Clone, Copy, Debug)] -/// Represents the addresses of various contracts on a network. -/// -/// This struct holds the addresses for various Uniswap contracts such as the -/// core factory, multicall, quoter, migrator, and others. Each field in the struct -/// corresponds to a specific contract and its address on the network. +/// Represents the addresses of various core contracts of uniswap on a network. pub struct ChainAddresses { v3_core_factory_address: Address, multicall_address: Address, @@ -22,10 +18,7 @@ pub struct ChainAddresses { v1_mixed_route_quoter_address: Option
, } -/// The default networks that are supported by the Uniswap SDK Core. /// -/// This constant defines the default networks that the SDK will interact with. -/// It includes the mainnet, Goerli, and Sepolia networks. pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, ChainId::SEPOLIA]; /// returns a hashmap of key pair input of chainid to address @@ -40,7 +33,7 @@ pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, C 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); - let mut map = AddressMap::default(); + let mut map = AddressMap::new(); for chain_id in networks { map.insert(chain_id as u64, address); } @@ -49,10 +42,6 @@ pub fn construct_same_address_map(address: Address, additional_networks: &[Chain lazy_static! { /// The UNI_ADDRESSES struct holds a map of addresses for the UNI token on various networks. - /// - /// This map is constructed using the `construct_same_address_map` function, which takes an address - /// and a list of additional networks, and returns a map where each network ID is associated - /// with the provided address. The default networks include Mainnet, Goerli, and Sepolia. #[derive(Debug, Clone, Copy)] pub static ref UNI_ADDRESSES: AddressMap = construct_same_address_map( address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984"), @@ -75,12 +64,8 @@ pub const V2_FACTORY_ADDRESS: Address = address!("5C69bEe701ef814a2B6a3EDD4B1652 lazy_static! { /// A map of Uniswap V2 Factory addresses for various networks. - /// - /// This map is used to look up the address of the Uniswap V2 Factory contract - /// for a given network. The keys in the map are the network IDs, and the values - /// are the corresponding contract addresses. - pub static ref V2_FACTORY_ADDRESSES: FxHashMap = { - let mut m = FxHashMap::default(); + pub static ref V2_FACTORY_ADDRESSES: HashMap = { + let mut m = HashMap::new(); m.insert(ChainId::MAINNET as u64, V2_FACTORY_ADDRESS); m.insert(ChainId::GOERLI as u64, V2_FACTORY_ADDRESS); m.insert( @@ -128,8 +113,8 @@ lazy_static! { /// This map is used to look up the address of the Uniswap V2 Router contract /// for a given network. The keys in the map are the network IDs, and the values /// are the corresponding contract addresses. - pub static ref V2_ROUTER_ADDRESSES: FxHashMap = { - let mut m = FxHashMap::default(); + pub static ref V2_ROUTER_ADDRESSES: HashMap = { + let mut m = HashMap::new(); m.insert(ChainId::MAINNET as u64, V2_ROUTER_ADDRESS); m.insert(ChainId::GOERLI as u64, V2_ROUTER_ADDRESS); m.insert( @@ -162,7 +147,6 @@ lazy_static! { impl Default for ChainAddresses { /// Networks that share most of the same addresses i.e. Mainnet, Goerli, Optimism, Arbitrum, - /// Polygon fn default() -> Self { Self { v3_core_factory_address: address!("1F98431c8aD98523631AE4a59f267346ea31F984"), @@ -181,9 +165,6 @@ impl Default for ChainAddresses { lazy_static! { /// The `MAINNET_ADDRESSES` struct holds the Uniswap contract addresses for the Ethereum Mainnet. - /// - /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. - /// Each field in the struct corresponds to a specific contract and its address on the Mainnet. pub static ref MAINNET_ADDRESSES: ChainAddresses = { ChainAddresses { v1_mixed_route_quoter_address: Some(address!( @@ -196,9 +177,6 @@ lazy_static! { lazy_static! { /// The `MAINNET_ADDRESSES` struct holds the Uniswap contract addresses for the Goerli Testnet. - /// - /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. - /// Each field in the struct corresponds to a specific contract and its address on the Mainnet. pub static ref GOERLI_ADDRESSES: ChainAddresses = { ChainAddresses { v1_mixed_route_quoter_address: Some(address!( @@ -211,17 +189,11 @@ lazy_static! { lazy_static! { /// The `OPTIMISM_ADDRESSES` struct holds the Uniswap contract addresses for the Optimism network. - /// - /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. - /// Each field in the struct corresponds to a specific contract and its address on the Optimism network. pub static ref OPTIMISM_ADDRESSES: ChainAddresses = ChainAddresses::default(); } lazy_static! { /// The `ARBITRUM_ONE_ADDRESSES` struct holds the Uniswap contract addresses for the Arbitrum One network. - /// - /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. - /// Each field in the struct corresponds to a specific contract and its address on the Arbitrum One network. pub static ref ARBITUM_ONE_ADDRESSES: ChainAddresses = { ChainAddresses { multicall_address: address!("adF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB"), @@ -232,9 +204,6 @@ lazy_static! { } lazy_static! { /// The `POLYGON_ADDRESSES` struct holds the Uniswap contract addresses for the Polygon network. - /// - /// This includes the addresses for the core factory, multicall, quoter, migrator, and other contracts. - /// Each field in the struct corresponds to a specific contract and its address on the Polygon network. pub static ref POLYGON_ADDRESSES: ChainAddresses = ChainAddresses::default(); } @@ -427,7 +396,7 @@ lazy_static! { /// for a given network. The keys in the map are the network IDs, and the values /// are the corresponding contract addresses. pub static ref CHAIN_TO_ADDRESSES_MAP: ChainMap = { - let mut new_map = ChainMap::default(); + let mut new_map = ChainMap::new(); new_map.insert(ChainId::BNB as u64, BNB_ADDRESSES); new_map.insert(ChainId::AVALANCHE as u64, AVALANCHE_ADDRESSES); @@ -457,7 +426,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref V3_CORE_FACTORY_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -474,7 +443,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref V3_MIGRATOR_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -492,7 +461,7 @@ lazy_static! { lazy_static! { /// V3 Contract Addresses pub static ref MULTICALL_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -516,7 +485,7 @@ pub static ref GOVERNANCE_ALPHA_V0_ADDRESSES: AddressMap = { lazy_static! { /// The older V1 governance address pub static ref GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::default(); + let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u64, address!("C4e172459f1E7939D522503B81AFAaC1014CE6F6"), @@ -528,7 +497,7 @@ pub static ref GOVERNANCE_ALPHA_V1_ADDRESSES: AddressMap = { lazy_static! { /// The latest governor bravo that is currently admin of timelock pub static ref GOVERNANCE_BRAVO_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::default(); + let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u64, address!("408ED6354d4973f66138C91495F2f2FCbd8724C3"), @@ -539,20 +508,14 @@ pub static ref GOVERNANCE_BRAVO_ADDRESSES: AddressMap = { lazy_static! { /// The `TIMELOCK_ADDRESSES` struct holds the timelock contract addresses for various networks. - /// - /// This includes the addresses for the timelock contract on different networks. - /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref TIMELOCK_ADDRESSES: AddressMap = construct_same_address_map(address!("1a9C8182C09F50C8318d769245beA52c32BE35BC"), &[]); } lazy_static! { /// The `MERKLE_DISTRIBUTOR_ADDRESS` struct holds the merkle distributor contract address for the mainnet. - /// - /// This includes the address for the merkle distributor contract on the mainnet. - /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = { - let mut new_map = AddressMap::default(); + let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u64, address!("090D4613473dEE047c3f2706764f49E0821D256e"), @@ -563,11 +526,8 @@ lazy_static! { lazy_static! { /// The `ARGENT_WALLET_DETECTOR_ADDRESS` struct holds the Argent Wallet Detector contract address for the mainnet. - /// - /// This includes the address for the Argent Wallet Detector contract on the mainnet. - /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = { - let mut new_map = AddressMap::default(); + let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u64, address!("eca4B0bDBf7c55E9b7925919d03CbF8Dc82537E8"), @@ -582,7 +542,7 @@ lazy_static! { /// This includes the addresses for the quoter contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network pub static ref QUOTER_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { chain_add.insert( chain_id as u64, @@ -602,7 +562,7 @@ lazy_static! { /// This includes the addresses for the non-fungible position manager contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) @@ -639,7 +599,7 @@ lazy_static! { /// This includes the addresses for the SOCKS Controller contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref SOCKS_CONTROLLER_ADDRESSES: AddressMap = { - let mut new_map = AddressMap::default(); + let mut new_map = AddressMap::new(); new_map.insert( ChainId::MAINNET as u64, address!("65770b5283117639760beA3F867b69b3697a91dd"), @@ -654,7 +614,7 @@ lazy_static! { /// This includes the addresses for the tick lens contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref TICK_LENS_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) @@ -682,7 +642,7 @@ lazy_static! { /// This includes the addresses for the mixed route quoter contract on different networks. /// Each field in the struct corresponds to a specific contract and its address on the network. pub static ref MIXED_ROUTE_QUOTER_V1_ADDRESSES: ChainAddress = { - let mut chain_add = ChainAddress::default(); + let mut chain_add = ChainAddress::new(); for chain_id in SUPPORTED_CHAINS { if CHAIN_TO_ADDRESSES_MAP .get(&(chain_id as u64)) diff --git a/src/chains.rs b/src/chains.rs index 2234b95..6d07e04 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -78,8 +78,6 @@ pub const SUPPORTED_CHAINS: [ChainId; 20] = [ #[derive(Debug, Clone, Copy)] /// Represents the names of native currencies supported by the Uniswap SDK. -/// -/// Each variant corresponds to a specific native currency name. pub enum NativeCurrencyName { /// Ethereum's native currency. ETHER, diff --git a/src/constants.rs b/src/constants.rs index b6e6036..d116471 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,12 +3,11 @@ use alloy_primitives::U256; use num_bigint::Sign; #[derive(Clone, Copy, Debug, PartialEq)] -/// Represents the type of trade in the Uniswap SDK. -/// -/// This enum is used to specify whether a trade is an exact input or an exact output. +/// Represents the type of trade in the Uniswap Core SDK. pub enum TradeType { /// Indicates that the trade is based on an exact input amount. ExactInput, + /// Indicates that the trade is based on an exact output amount. ExactOutput, } @@ -17,22 +16,17 @@ pub enum TradeType { /// pub enum Rounding { /// Rounds down to the nearest whole number. - /// - /// This variant indicates that the rounding should always go towards zero. RoundDown, + /// Rounds to the nearest whole number, rounding halfway cases away from zero. - /// - /// This variant indicates that the rounding should round to the nearest whole number, with - /// halfway cases rounded away from zero. RoundHalfUp, + /// Rounds up to the nearest whole number. - /// - /// This variant indicates that the rounding should always go towards positive infinity. RoundUp, } lazy_static! { - /// The maximum value representable by a `BigInt` in this context, equivalent to the maximum value of a `U256`. + /// pub static ref MAX_UINT256: BigInt = BigInt::from_bytes_be(Sign::Plus, &U256::MAX.to_be_bytes::<32>()); } diff --git a/src/entities/base_currency.rs b/src/entities/base_currency.rs index 7035c93..ec3247c 100644 --- a/src/entities/base_currency.rs +++ b/src/entities/base_currency.rs @@ -14,30 +14,19 @@ use alloy_primitives::ChainId; /// /// - `M`: The type of the additional metadata associated with the currency. pub struct CurrencyLike { - /// The chain ID on which this currency resides. /// - /// This identifies the blockchain network where the currency is used. pub chain_id: ChainId, - /// The number of decimal places the currency can be divided into. /// - /// This is used to represent the smallest unit of the currency. pub decimals: u8, - /// The symbol of the currency, i.e., a short textual non-unique identifier. /// - /// This is a common abbreviation used to represent the currency. pub symbol: Option, - /// The name of the currency, i.e., a descriptive textual non-unique identifier. /// - /// This is a more detailed name used to represent the currency. pub name: Option, - /// Additional metadata associated with the currency. /// - /// This can include various details specific to the currency, such as contract addresses or - /// other relevant information. pub meta: M, } diff --git a/src/entities/currency.rs b/src/entities/currency.rs index 274c332..fdb744d 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -1,9 +1,7 @@ use crate::prelude::*; #[derive(Clone, PartialEq, Debug)] -/// Represents a currency in the Uniswap SDK. /// -/// This enum can represent either a native currency (like Ether) or a token. pub enum Currency { /// Represents a native currency. NativeCurrency(Ether), @@ -11,40 +9,22 @@ pub enum Currency { Token(Token), } -/// Trait for representing a currency in the Uniswap SDK. -/// -/// This trait provides methods for interacting with currencies, whether they are native currencies -/// like Ether or tokens. Implementations of this trait must provide functionality for determining -/// if a currency is native, getting its address, checking equality with another currency, and -/// wrapping the currency for use with Uniswap contracts. +/// Trait for representing a currency in the Uniswap Core SDK. pub trait CurrencyTrait: BaseCurrency { /// Returns whether the currency is native to the chain and must be wrapped (e.g. Ether) fn is_native(&self) -> bool; /// Returns the address of the currency. - /// - /// This method returns the address associated with the currency, whether it's a native currency - /// or a token. - /// - /// # Returns - /// - /// * `Address` - The address of the currency. fn address(&self) -> Address; /// Returns whether this currency is functionally equivalent to the other currency - /// - /// # 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. - /// Currencies must implement this to be used in Uniswap + /// fn wrapped(&self) -> Token; } impl CurrencyTrait for Currency { - /// Returns a bool indicating whether the currency is native or not fn is_native(&self) -> bool { match self { Currency::NativeCurrency(_) => true, @@ -52,7 +32,6 @@ impl CurrencyTrait for Currency { } } - /// Accessor method for retrieving either the NativeCurrency or Token address fn address(&self) -> Address { match self { Currency::NativeCurrency(native_currency) => native_currency.address(), diff --git a/src/entities/ether.rs b/src/entities/ether.rs index 239d68e..e50029d 100644 --- a/src/entities/ether.rs +++ b/src/entities/ether.rs @@ -2,7 +2,7 @@ use crate::prelude::*; // Lazy static cache for Ether instances lazy_static! { - static ref ETHER_CACHE: Mutex> = Mutex::new(FxHashMap::default()); + static ref ETHER_CACHE: Mutex> = Mutex::new(HashMap::default()); } /// Ether is the main usage of a 'native' currency, i.e., for Ethereum mainnet and all testnets. diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 9383f02..4a567bc 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -14,7 +14,7 @@ pub struct CurrencyMeta { } impl CurrencyAmount { - /// Constructor method for creating a new currency amount + /// fn new( currency: T, numerator: impl Into, @@ -104,7 +104,7 @@ impl CurrencyAmount { ) } - /// Convert the currency amount to a string with a specified number of significant digits + /// pub fn to_significant( &self, significant_digits: u8, @@ -131,7 +131,7 @@ impl CurrencyAmount { ) } - /// Wrap the currency amount if the currency is not native + /// pub fn wrapped(&self) -> Result, Error> { CurrencyAmount::from_fractional_amount( self.currency.wrapped(), @@ -141,7 +141,7 @@ impl CurrencyAmount { } } -/// Unit tests for the currency module +/// #[cfg(test)] mod tests { use super::*; diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 8a619f5..1700617 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use std::ops::{Add, Deref, Mul, Sub}; -/// Struct representing a fraction with metadata +/// #[derive(Clone, Debug)] pub struct FractionLike { numerator: BigInt, @@ -74,15 +74,15 @@ where { } -/// Trait defining common operations for fractions with metadata +/// pub trait FractionBase: Sized { - /// Constructor method for creating a new Fraction with metadata + /// fn new(numerator: impl Into, denominator: impl Into, meta: M) -> Self; - /// Accessor method for retrieving metadata + /// fn meta(&self) -> M; - /// Accessor method for retrieving the numerator + /// fn numerator(&self) -> BigInt; /// Accessor method for retrieving the denominator @@ -102,7 +102,7 @@ pub trait FractionBase: Sized { ) } - /// Returns the inverted fraction + /// Returns the inverted [`fraction`] fn invert(&self) -> Self { Self::new(self.denominator(), self.numerator(), self.meta()) } @@ -177,7 +177,7 @@ impl PartialEq for FractionLike where M: Clone + PartialEq, { - /// Checks if the current fraction is equal to another fraction + /// fn eq(&self, other: &Self) -> bool { self.numerator() * other.denominator() == other.numerator() * self.denominator() && self.meta() == other.meta() @@ -207,7 +207,7 @@ where 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() { FractionBase::new( @@ -228,7 +228,7 @@ impl Add for FractionLike { 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() { FractionBase::new( @@ -249,7 +249,7 @@ impl Sub for FractionLike { impl Mul for FractionLike { type Output = Self; - /// Multiplies the current fraction by another fraction + /// fn mul(self, other: Self) -> Self::Output { FractionBase::new( self.numerator() * other.numerator(), @@ -262,7 +262,7 @@ impl Mul for FractionLike { impl Div for FractionLike { type Output = Self; - /// Divides the current fraction by another fraction + /// /// There's little to no possibility of an error, so unwrap can be used fn div(self, other: Self) -> Self::Output { FractionBase::new( diff --git a/src/entities/fractions/percent.rs b/src/entities/fractions/percent.rs index a68cc57..ceb0f5f 100644 --- a/src/entities/fractions/percent.rs +++ b/src/entities/fractions/percent.rs @@ -1,7 +1,6 @@ /// Importing dependencies from the same module use crate::prelude::*; -// Lazily initialized constant representing the fraction 100/1 lazy_static! { static ref ONE_HUNDRED: Fraction = Fraction::new(100, 1); } diff --git a/src/entities/fractions/price.rs b/src/entities/fractions/price.rs index b81c4fc..ef18e3e 100644 --- a/src/entities/fractions/price.rs +++ b/src/entities/fractions/price.rs @@ -54,7 +54,6 @@ where base_amount: CurrencyAmount, quote_amount: CurrencyAmount, ) -> Self { - // Calculate the price as the ratio of quote amount to base amount let res = quote_amount.divide(&base_amount).unwrap(); Self::new( base_amount.meta.currency, diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 3452c63..6fffe1d 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -1,18 +1,12 @@ -/// The `base_currency` module provides functionality related to the base currency used in the -/// Uniswap SDK Core. +/// pub mod base_currency; -/// The `currency` module contains definitions and utilities for handling various currencies -/// supported by the Uniswap SDK Core. +/// pub mod currency; -/// The `ether` module provides utilities and functionalities specific to Ether, the native -/// cryptocurrency of the Ethereum blockchain. +/// pub mod ether; -/// The `fractions` module contains functionality related to fractional values, such as currency -/// amounts, percentages, and prices. +/// pub mod fractions; -/// The `token` module provides definitions and utilities for handling tokens including -/// their creation, management, and interactions. +/// pub mod token; -/// The `weth9` module provides functionalities specific to Wrapped Ether (WETH9), a standard ERC-20 -/// token representation of Ether on the Ethereum blockchain. +/// pub mod weth9; diff --git a/src/entities/token.rs b/src/entities/token.rs index 79e9c24..51c1b78 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -6,10 +6,6 @@ pub type Token = CurrencyLike; #[derive(Clone, PartialEq, Debug)] /// Represents the metadata for an ERC20 token, including its address and optional fees. -/// -/// This struct holds the address of the token and optional buy and sell fees in basis points (bps). -/// It is used to provide additional information about the token that is not directly related to its -/// value or quantity. pub struct TokenMeta { /// The address of the token. pub address: Address, diff --git a/src/entities/weth9.rs b/src/entities/weth9.rs index 9712d71..13cab0f 100644 --- a/src/entities/weth9.rs +++ b/src/entities/weth9.rs @@ -5,7 +5,7 @@ use crate::{prelude::*, token}; #[derive(Clone, PartialEq, Debug)] pub struct WETH9 { /// A mapping of chain IDs to corresponding WETH tokens. - tokens: FxHashMap, + tokens: HashMap, } /// Default implementation for [`WETH9`], creating an instance with predefined WETH tokens on @@ -27,7 +27,7 @@ impl WETH9 { /// /// A new `WETH9` instance with predefined WETH tokens. pub fn new() -> Self { - let mut tokens = FxHashMap::default(); + let mut tokens = HashMap::new(); // Insert predefined WETH tokens for different chains. tokens.insert( diff --git a/src/error.rs b/src/error.rs index fc66f86..43c364a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,19 +7,19 @@ pub enum Error { #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u64, u64), - /// Indicates that two addresses are equal. + /// #[error("Addresses are equal")] EqualAddresses, - /// Indicates that an amount has exceeded MAX_UINT256. + /// #[error("amount has exceeded MAX_UINT256")] MaxUint, - /// Indicates that two entities are not equal. + /// #[error("not equal")] NotEqual(), - /// Custom error for incorrect input. + /// #[error("incorrect")] Incorrect(), } diff --git a/src/lib.rs b/src/lib.rs index 83616ff..17eac0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ clippy::missing_const_for_fn, rustdoc::all )] -#![deny(clippy::missin)] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] diff --git a/src/prelude.rs b/src/prelude.rs index b9f9c57..92b4ecb 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -23,6 +23,7 @@ pub use lazy_static::lazy_static; pub use num_bigint::{BigInt, BigUint, ToBigInt, ToBigUint}; pub use num_integer::Integer; pub use num_traits::{Num, ToPrimitive, Zero}; -pub use rustc_hash::FxHashMap; -pub use std::{cmp::Ordering, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex}; +pub use std::{ + cmp::Ordering, collections::HashMap, num::NonZeroU64, ops::Div, str::FromStr, sync::Mutex, +}; pub use thiserror::Error; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 06539c8..95c9d38 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,8 +1,8 @@ -/// Contains functionality related to computing the price impact of trades. +/// pub mod compute_price_impact; -/// Contains functionality for inserting elements into a sorted collection. +/// pub mod sorted_insert; -/// Contains functionality related to square root calculations. +/// pub mod sqrt; #[cfg(feature = "validate_parse_address")] pub mod validate_and_parse_address; From 29dc0cbb99b161df1c42e0c66f14cc681d3d491a Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 14:54:29 +0100 Subject: [PATCH 09/31] fixed documentations and refactored some documentations --- src/addresses.rs | 2 +- src/constants.rs | 2 +- src/entities/base_currency.rs | 18 ++++++------------ src/entities/fractions/fraction.rs | 23 +++++++++++------------ src/entities/fractions/mod.rs | 12 +++--------- src/entities/mod.rs | 12 ++++++------ src/error.rs | 10 +++++----- src/utils/mod.rs | 7 ++++--- 8 files changed, 37 insertions(+), 49 deletions(-) diff --git a/src/addresses.rs b/src/addresses.rs index 67df43c..190bd31 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -18,7 +18,7 @@ pub struct ChainAddresses { v1_mixed_route_quoter_address: Option
, } -/// +/// Represents default networks which are Mainnet, Goerli, Sepolia pub const DEFAULT_NETWORKS: [ChainId; 3] = [ChainId::MAINNET, ChainId::GOERLI, ChainId::SEPOLIA]; /// returns a hashmap of key pair input of chainid to address diff --git a/src/constants.rs b/src/constants.rs index d116471..2843fa1 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -26,7 +26,7 @@ pub enum Rounding { } lazy_static! { - /// + ///Represnts Maximum amount contained in a uint256 pub static ref MAX_UINT256: BigInt = BigInt::from_bytes_be(Sign::Plus, &U256::MAX.to_be_bytes::<32>()); } diff --git a/src/entities/base_currency.rs b/src/entities/base_currency.rs index ec3247c..2c9a504 100644 --- a/src/entities/base_currency.rs +++ b/src/entities/base_currency.rs @@ -6,27 +6,21 @@ use alloy_primitives::ChainId; /// `CurrencyLike` is a generic struct representing a currency with a specific chain ID, /// decimals, symbol, name, and additional metadata. -/// -/// This struct is used to abstract the details of different currencies, allowing for -/// a unified way to handle various types of currencies in the Uniswap SDK Core. -/// -/// # Generics -/// -/// - `M`: The type of the additional metadata associated with the currency. pub struct CurrencyLike { - /// + + /// The chain ID on which this currency resides pub chain_id: ChainId, - /// + /// represents the deciamls for the prticular currency pub decimals: u8, - /// + /// The symbol of the currency, i.e. a short textual non-unique identifier pub symbol: Option, - /// + /// The name of the currency, i.e. a descriptive textual non-unique identifier pub name: Option, - /// + /// Metadata associated with the currency pub meta: M, } diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 1700617..9e25a9b 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use std::ops::{Add, Deref, Mul, Sub}; -/// +/// struct to represent a fraction #[derive(Clone, Debug)] pub struct FractionLike { numerator: BigInt, @@ -74,15 +74,16 @@ where { } -/// +/// Trait defining common operations for fractions with metadata pub trait FractionBase: Sized { - /// + + /// Constructor method for creating a new Fraction with metadata fn new(numerator: impl Into, denominator: impl Into, meta: M) -> Self; - /// + /// Accessor method for retrieving metadata fn meta(&self) -> M; - /// + /// Accessor method for retrieving metadata fn numerator(&self) -> BigInt; /// Accessor method for retrieving the denominator @@ -112,7 +113,8 @@ pub trait FractionBase: Sized { BigDecimal::from(self.numerator()).div(BigDecimal::from(self.denominator())) } - /// + /// Converts the fraction to a string with a specified number of significant digits and rounding + /// strategy fn to_significant(&self, significant_digits: u8, rounding: Rounding) -> Result { if significant_digits == 0 { return Err(Error::Incorrect()); @@ -126,7 +128,8 @@ pub trait FractionBase: Sized { Ok(quotient.normalized().to_string()) } - /// + /// Converts the fraction to a string with a fixed number of decimal places and rounding + /// strategy fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String { let rounding_strategy = to_rounding_strategy(rounding); self.to_decimal() @@ -177,7 +180,7 @@ impl PartialEq for FractionLike where M: Clone + PartialEq, { - /// + /// Checks if the current fraction is equal to another fraction fn eq(&self, other: &Self) -> bool { self.numerator() * other.denominator() == other.numerator() * self.denominator() && self.meta() == other.meta() @@ -207,7 +210,6 @@ where impl Add for FractionLike { type Output = Self; - /// fn add(self, other: Self) -> Self::Output { if self.denominator == other.denominator() { FractionBase::new( @@ -228,7 +230,6 @@ impl Add for FractionLike { impl Sub for FractionLike { type Output = Self; - /// fn sub(self, other: Self) -> Self::Output { if self.denominator == other.denominator() { FractionBase::new( @@ -249,7 +250,6 @@ impl Sub for FractionLike { impl Mul for FractionLike { type Output = Self; - /// fn mul(self, other: Self) -> Self::Output { FractionBase::new( self.numerator() * other.numerator(), @@ -262,7 +262,6 @@ impl Mul for FractionLike { impl Div for FractionLike { type Output = Self; - /// /// There's little to no possibility of an error, so unwrap can be used fn div(self, other: Self) -> Self::Output { FractionBase::new( diff --git a/src/entities/fractions/mod.rs b/src/entities/fractions/mod.rs index ea5946e..c781e4b 100644 --- a/src/entities/fractions/mod.rs +++ b/src/entities/fractions/mod.rs @@ -1,14 +1,8 @@ -/// This module represents currency, including the currency type and the amount as a fraction, also -/// including. methods for arithmetic operations, conversions to and from string representations, -/// and checks for validity. +/// This module represents currency, including the currency type and the amount as a fraction. pub mod currency_amount; -/// This module contains with precise division results, avoiding floating-point arithmetic issues, -/// also including operations like addition, subtraction, multiplication, and division, as well as -/// conversions to other formats. +/// This module contains with precise division results, avoiding floating-point arithmetic issues. pub mod fraction; -/// A module represents a percentage as a fraction, with methods for arithmetic and string -/// conversions, it also includes methods for precise calculations involving percentages and ensures -/// accurate representation of percentage values. +/// A module represents a percentage. pub mod percent; /// A module represents' a price as a ratio between two currencies, with methods for arithmetic and /// string conversions. diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 6fffe1d..30df1ff 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -1,12 +1,12 @@ -/// +/// Module represnting base currency pub mod base_currency; -/// +/// Module representing currency pub mod currency; -/// +/// Module representing ether pub mod ether; -/// +/// Module represnting fractions pub mod fractions; -/// +/// Module represnting token pub mod token; -/// +/// Module representing Weth9 pub mod weth9; diff --git a/src/error.rs b/src/error.rs index 43c364a..4d958c3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,23 +3,23 @@ use crate::prelude::*; /// Represents errors that can occur in the context of currency operations. #[derive(Debug, Error, Clone, Copy)] pub enum Error { - /// + /// Triggers when compared Chain Ids do not match #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u64, u64), - /// + /// Triggers when comapred addresses are not the smae #[error("Addresses are equal")] EqualAddresses, - /// + /// Triggers when it tries to exceed the max uint #[error("amount has exceeded MAX_UINT256")] MaxUint, - /// + ///Triggers when the Compared values are not equal #[error("not equal")] NotEqual(), - /// + /// Triggers when The value is inccorrrect #[error("incorrect")] Incorrect(), } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 95c9d38..9f10dee 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,8 +1,9 @@ -/// +/// Module that contains various methods to comput price pub mod compute_price_impact; -/// + +/// Module that contains various methods to sort pub mod sorted_insert; -/// +/// Module that contains various methods to compute square root pub mod sqrt; #[cfg(feature = "validate_parse_address")] pub mod validate_and_parse_address; From 92f72ad79b57375e359b593250d90b4dd4e0cd05 Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 14:57:12 +0100 Subject: [PATCH 10/31] fixed documentations and refactored some documentations --- src/entities/base_currency.rs | 1 - src/entities/fractions/fraction.rs | 1 - src/error.rs | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/entities/base_currency.rs b/src/entities/base_currency.rs index 2c9a504..2eb92ff 100644 --- a/src/entities/base_currency.rs +++ b/src/entities/base_currency.rs @@ -7,7 +7,6 @@ use alloy_primitives::ChainId; /// `CurrencyLike` is a generic struct representing a currency with a specific chain ID, /// decimals, symbol, name, and additional metadata. pub struct CurrencyLike { - /// The chain ID on which this currency resides pub chain_id: ChainId, diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 9e25a9b..5ce6e28 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -76,7 +76,6 @@ where /// Trait defining common operations for fractions with metadata pub trait FractionBase: Sized { - /// Constructor method for creating a new Fraction with metadata fn new(numerator: impl Into, denominator: impl Into, meta: M) -> Self; diff --git a/src/error.rs b/src/error.rs index 4d958c3..6e6791a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,7 +42,7 @@ mod tests { assert_eq!(error.to_string(), "Addresses are equal"); } - /// Test that `Error::MaxUint` displays the correct error message. + /// Test that `Error::MaxUint` displays the correct error messagit push ge. #[test] fn test_max_uint_error() { let error = Error::MaxUint; From 7699f8fcc430a141491256a3dd9384f811fd16db Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 15:09:01 +0100 Subject: [PATCH 11/31] fixed documentations and refactored some documentations --- src/addresses.rs | 2 +- src/constants.rs | 5 +++-- src/entities/currency.rs | 5 +++-- src/entities/fractions/currency_amount.rs | 16 ++++++++-------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/addresses.rs b/src/addresses.rs index 190bd31..ca4344f 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -104,7 +104,7 @@ lazy_static! { }; } -/// +/// This represents V2 router address across all chains pub const V2_ROUTER_ADDRESS: Address = address!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); lazy_static! { diff --git a/src/constants.rs b/src/constants.rs index 2843fa1..c5b92a9 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,7 +3,7 @@ use alloy_primitives::U256; use num_bigint::Sign; #[derive(Clone, Copy, Debug, PartialEq)] -/// Represents the type of trade in the Uniswap Core SDK. +/// Represents the various type of trades. pub enum TradeType { /// Indicates that the trade is based on an exact input amount. ExactInput, @@ -13,7 +13,8 @@ pub enum TradeType { } #[derive(Clone, Debug, PartialEq, Copy)] -/// + +/// Represents three various way to rounds pub enum Rounding { /// Rounds down to the nearest whole number. RoundDown, diff --git a/src/entities/currency.rs b/src/entities/currency.rs index fdb744d..3bcc418 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -1,7 +1,8 @@ use crate::prelude::*; #[derive(Clone, PartialEq, Debug)] -/// + +/// This enum represnets the two type of currencies i.e native and Token pub enum Currency { /// Represents a native currency. NativeCurrency(Ether), @@ -20,7 +21,7 @@ pub trait CurrencyTrait: BaseCurrency { /// Returns whether this currency is functionally equivalent to the other currency fn equals(&self, other: &impl CurrencyTrait) -> bool; - /// + /// Returns a Token that represents the wrapped quivalent of the mative currency fn wrapped(&self) -> Token; } diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index 4a567bc..b088ab6 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -51,7 +51,7 @@ impl CurrencyAmount { Self::new(currency, numerator, denominator) } - /// + /// Multiplication of currency amount by another fractional amount pub fn multiply(&self, other: &impl FractionBase) -> Result { let multiplied = self.as_fraction() * other.as_fraction(); Self::from_fractional_amount( @@ -61,7 +61,7 @@ impl CurrencyAmount { ) } - /// + /// Division of currency amount by another fractional amount pub fn divide(&self, other: &impl FractionBase) -> Result { let divided = self.as_fraction() / other.as_fraction(); Self::from_fractional_amount( @@ -78,7 +78,7 @@ impl CurrencyAmount { .to_string() } - /// + /// Addition of another currency amount to the current amount pub fn add(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -91,7 +91,7 @@ impl CurrencyAmount { ) } - /// + /// Subtraction of another currency amount from the current amount pub fn subtract(&self, other: &Self) -> Result { if !self.currency.equals(&other.currency) { return Err(Error::NotEqual()); @@ -104,7 +104,7 @@ impl CurrencyAmount { ) } - /// + /// Convert the currency amount to a string with a specified number of significant digits pub fn to_significant( &self, significant_digits: u8, @@ -114,7 +114,7 @@ impl CurrencyAmount { .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) -> Result { if decimal_places > self.currency.decimals() { return Err(Error::NotEqual()); @@ -131,7 +131,7 @@ impl CurrencyAmount { ) } - /// + /// Wrap the currency amount if the currency is not native pub fn wrapped(&self) -> Result, Error> { CurrencyAmount::from_fractional_amount( self.currency.wrapped(), @@ -141,7 +141,7 @@ impl CurrencyAmount { } } -/// + #[cfg(test)] mod tests { use super::*; From 754234da97ae2e01bb7aab0de28e9ed45d75ebe3 Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 15:12:47 +0100 Subject: [PATCH 12/31] fixed documentations and refactored some documentations --- src/entities/fractions/currency_amount.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index b088ab6..caa1342 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -14,7 +14,7 @@ pub struct CurrencyMeta { } impl CurrencyAmount { - /// + /// Constructor method for creating a new currency amount fn new( currency: T, numerator: impl Into, From 06096b848e8bce345543f0ffdc5ead5e42c5cd12 Mon Sep 17 00:00:00 2001 From: malik672 Date: Wed, 17 Apr 2024 15:14:51 +0100 Subject: [PATCH 13/31] fixed documentations and refactored some documentations --- src/entities/fractions/currency_amount.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/entities/fractions/currency_amount.rs b/src/entities/fractions/currency_amount.rs index caa1342..0bd7c5a 100644 --- a/src/entities/fractions/currency_amount.rs +++ b/src/entities/fractions/currency_amount.rs @@ -141,7 +141,6 @@ impl CurrencyAmount { } } - #[cfg(test)] mod tests { use super::*; From d163b073688a1773908b2ca97fda33d8d999b23c Mon Sep 17 00:00:00 2001 From: malik Date: Mon, 22 Apr 2024 22:08:01 +0100 Subject: [PATCH 14/31] Update src/addresses.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/addresses.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/addresses.rs b/src/addresses.rs index ca4344f..67c2d60 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -4,9 +4,8 @@ type AddressMap = HashMap; type ChainMap = HashMap; type ChainAddress = HashMap; -#[derive(Clone, Copy, Debug)] - /// Represents the addresses of various core contracts of uniswap on a network. +#[derive(Clone, Copy, Debug)] pub struct ChainAddresses { v3_core_factory_address: Address, multicall_address: Address, From 49aa01be668f240354dab89c2453227b431ffbd0 Mon Sep 17 00:00:00 2001 From: malik Date: Mon, 22 Apr 2024 22:08:23 +0100 Subject: [PATCH 15/31] Update src/chains.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/chains.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chains.rs b/src/chains.rs index 6d07e04..4389f52 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -76,8 +76,8 @@ pub const SUPPORTED_CHAINS: [ChainId; 20] = [ ChainId::ROOTSTOCK, ]; -#[derive(Debug, Clone, Copy)] /// Represents the names of native currencies supported by the Uniswap SDK. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum NativeCurrencyName { /// Ethereum's native currency. ETHER, From 1e3fbc05ae746826fd3af41feac0b565e0e7a8d5 Mon Sep 17 00:00:00 2001 From: malik Date: Mon, 22 Apr 2024 22:08:40 +0100 Subject: [PATCH 16/31] Update src/error.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 6e6791a..b723b16 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ pub enum Error { #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u64, u64), - /// Triggers when comapred addresses are not the smae + /// Triggers when comapred addresses are the smae #[error("Addresses are equal")] EqualAddresses, From 79fa3b51fcf756bac24a7df7a446640f55edd320 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:08:08 +0100 Subject: [PATCH 17/31] Update src/utils/mod.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/utils/mod.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 9f10dee..6fcb698 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,9 +1,5 @@ -/// Module that contains various methods to comput price pub mod compute_price_impact; - -/// Module that contains various methods to sort pub mod sorted_insert; -/// Module that contains various methods to compute square root pub mod sqrt; #[cfg(feature = "validate_parse_address")] pub mod validate_and_parse_address; From 84897817ec47ecf785be4ac9272997bcd3134849 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:08:22 +0100 Subject: [PATCH 18/31] Update src/entities/token.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/token.rs b/src/entities/token.rs index 51c1b78..69a208b 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -59,7 +59,7 @@ impl Token { /// /// # Returns /// - /// A new `Token` instance. + /// A new [`Token`] instance. /// /// # Panics /// From 31a02ad50b79a8a2c009a21d635261154648549b Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:08:34 +0100 Subject: [PATCH 19/31] Update src/entities/token.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/token.rs b/src/entities/token.rs index 69a208b..c11b51a 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -45,7 +45,7 @@ impl CurrencyTrait for Token { } impl Token { - /// Creates a new `Token` with the given parameters. + /// Creates a new [`Token`] with the given parameters. /// /// # Arguments /// From d82133ac9011451b186cc1d38ef6200591844da5 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:08:50 +0100 Subject: [PATCH 20/31] Update src/constants.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/constants.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants.rs b/src/constants.rs index c5b92a9..0f25eb3 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -2,8 +2,8 @@ use crate::prelude::*; use alloy_primitives::U256; use num_bigint::Sign; -#[derive(Clone, Copy, Debug, PartialEq)] /// Represents the various type of trades. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum TradeType { /// Indicates that the trade is based on an exact input amount. ExactInput, From ff29c0406dd66799babc12d4dd0b7dbf82020362 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:09:08 +0100 Subject: [PATCH 21/31] Update src/chains.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/chains.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chains.rs b/src/chains.rs index 4389f52..f08eb85 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -1,7 +1,7 @@ -#[derive(Debug, Clone, Copy)] /// Represents the unique identifier for different blockchain networks supported by the Uniswap SDK. /// /// Each variant corresponds to a specific blockchain network, identified by its unique chain ID. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ChainId { /// The Ethereum Mainnet. MAINNET = 1, From 2e8976449099c084444b3021098d4566adac06b2 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:16:07 +0100 Subject: [PATCH 22/31] Update addresses.rs --- src/addresses.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addresses.rs b/src/addresses.rs index 67c2d60..9d1bc78 100644 --- a/src/addresses.rs +++ b/src/addresses.rs @@ -175,7 +175,7 @@ lazy_static! { } lazy_static! { - /// The `MAINNET_ADDRESSES` struct holds the Uniswap contract addresses for the Goerli Testnet. + /// The `GOERLI_ADDRESSES` struct holds the Uniswap contract addresses for the Goerli Testnet. pub static ref GOERLI_ADDRESSES: ChainAddresses = { ChainAddresses { v1_mixed_route_quoter_address: Some(address!( From ade88e8dca4c3496484d23910e66c005c4ae9e79 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:20:42 +0100 Subject: [PATCH 23/31] Update error.rs --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index b723b16..8769e5b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,7 +42,7 @@ mod tests { assert_eq!(error.to_string(), "Addresses are equal"); } - /// Test that `Error::MaxUint` displays the correct error messagit push ge. + /// Test that `Error::MaxUint` displays the correct error messagit. #[test] fn test_max_uint_error() { let error = Error::MaxUint; From 6c853c14d730af0ab5ce07c22eb9d239ac874d95 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:23:56 +0100 Subject: [PATCH 24/31] Update src/entities/token.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/token.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/entities/token.rs b/src/entities/token.rs index c11b51a..7ff6843 100644 --- a/src/entities/token.rs +++ b/src/entities/token.rs @@ -3,9 +3,8 @@ use crate::prelude::*; /// Represents an ERC20 token with a unique address and some metadata. pub type Token = CurrencyLike; -#[derive(Clone, PartialEq, Debug)] - /// Represents the metadata for an ERC20 token, including its address and optional fees. +#[derive(Clone, PartialEq, Debug)] pub struct TokenMeta { /// The address of the token. pub address: Address, From 98dd213acf3fa6a7c1ab004977a76394c9604497 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:24:16 +0100 Subject: [PATCH 25/31] Update src/constants.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/constants.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 0f25eb3..2e7cbbc 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -12,9 +12,8 @@ pub enum TradeType { ExactOutput, } -#[derive(Clone, Debug, PartialEq, Copy)] - /// Represents three various way to rounds +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Rounding { /// Rounds down to the nearest whole number. RoundDown, From cc70c0e02b2232745601f0ee8f3708b0b5d57c36 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:24:24 +0100 Subject: [PATCH 26/31] Update src/entities/base_currency.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/base_currency.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/entities/base_currency.rs b/src/entities/base_currency.rs index 2eb92ff..ca89a3e 100644 --- a/src/entities/base_currency.rs +++ b/src/entities/base_currency.rs @@ -2,10 +2,9 @@ use std::ops::Deref; use alloy_primitives::ChainId; -#[derive(Clone, PartialEq, Debug)] - /// `CurrencyLike` is a generic struct representing a currency with a specific chain ID, /// decimals, symbol, name, and additional metadata. +#[derive(Clone, PartialEq, Debug)] pub struct CurrencyLike { /// The chain ID on which this currency resides pub chain_id: ChainId, From 858ed408983435bd56623e6086dd01a0ff2a6b83 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:27:00 +0100 Subject: [PATCH 27/31] Update src/entities/fractions/fraction.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/fractions/fraction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 5ce6e28..6d3e5c9 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use std::ops::{Add, Deref, Mul, Sub}; -/// struct to represent a fraction +/// Struct representing a fraction with metadata #[derive(Clone, Debug)] pub struct FractionLike { numerator: BigInt, From 8397c178b97cbdf111b3a335e0381a191e840b6c Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:27:21 +0100 Subject: [PATCH 28/31] Update src/entities/fractions/fraction.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/fractions/fraction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 6d3e5c9..41bcc51 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -102,7 +102,7 @@ pub trait FractionBase: Sized { ) } - /// Returns the inverted [`fraction`] + /// Returns the inverted fraction fn invert(&self) -> Self { Self::new(self.denominator(), self.numerator(), self.meta()) } From 8b286f15eab3a76187a438ec8ff8c63eb02b588e Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:27:47 +0100 Subject: [PATCH 29/31] Update src/entities/fractions/fraction.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/fractions/fraction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/fractions/fraction.rs b/src/entities/fractions/fraction.rs index 41bcc51..274554a 100644 --- a/src/entities/fractions/fraction.rs +++ b/src/entities/fractions/fraction.rs @@ -82,7 +82,7 @@ pub trait FractionBase: Sized { /// Accessor method for retrieving metadata fn meta(&self) -> M; - /// Accessor method for retrieving metadata + /// Accessor method for retrieving the numerator fn numerator(&self) -> BigInt; /// Accessor method for retrieving the denominator From 02e56aaf2a512a5617c83ff8c8be91a645023715 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 27 Apr 2024 07:28:00 +0100 Subject: [PATCH 30/31] Update src/entities/currency.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/entities/currency.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/entities/currency.rs b/src/entities/currency.rs index 3bcc418..7758941 100644 --- a/src/entities/currency.rs +++ b/src/entities/currency.rs @@ -1,8 +1,7 @@ use crate::prelude::*; -#[derive(Clone, PartialEq, Debug)] - /// This enum represnets the two type of currencies i.e native and Token +#[derive(Clone, PartialEq, Debug)] pub enum Currency { /// Represents a native currency. NativeCurrency(Ether), From faf864d0bfb362d70bb9f10d163b346ca9eab7dc Mon Sep 17 00:00:00 2001 From: malik Date: Sun, 28 Apr 2024 08:43:57 +0100 Subject: [PATCH 31/31] Update src/error.rs Co-authored-by: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 8769e5b..ab778d2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,7 +42,7 @@ mod tests { assert_eq!(error.to_string(), "Addresses are equal"); } - /// Test that `Error::MaxUint` displays the correct error messagit. + /// Test that `Error::MaxUint` displays the correct error message. #[test] fn test_max_uint_error() { let error = Error::MaxUint;