diff --git a/Cargo.toml b/Cargo.toml index c71c743..eb3abf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-v3-sdk" -version = "2.3.0" +version = "2.4.0" edition = "2021" authors = ["Shuhui Luo "] description = "Uniswap V3 SDK for Rust" diff --git a/README.md b/README.md index f56574d..208d062 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ It is feature-complete with unit tests matching the TypeScript SDK. Add the following to your `Cargo.toml` file: ```toml -uniswap-v3-sdk = { version = "2.3.0", features = ["extensions", "std"] } +uniswap-v3-sdk = { version = "2.4.0", features = ["extensions", "std"] } ``` ### Usage diff --git a/src/entities/trade.rs b/src/entities/trade.rs index 25b6488..b5e07a7 100644 --- a/src/entities/trade.rs +++ b/src/entities/trade.rs @@ -182,12 +182,11 @@ where .iter() .map(|swap| swap.route.pools.len()) .sum::(); - let mut pool_address_set = FxHashSet::
::default(); - for Swap { route, .. } in &swaps { - for pool in &route.pools { - pool_address_set.insert(pool.address(None, None)); - } - } + let pool_addresses = swaps + .iter() + .flat_map(|swap| swap.route.pools.iter()) + .map(|pool| pool.address(None, None)); + let pool_address_set = FxHashSet::from_iter(pool_addresses); assert_eq!(num_pools, pool_address_set.len(), "POOLS_DUPLICATED"); Ok(Self { swaps, diff --git a/src/extensions/pool.rs b/src/extensions/pool.rs index 40ddb11..69048d2 100644 --- a/src/extensions/pool.rs +++ b/src/extensions/pool.rs @@ -166,11 +166,20 @@ fn normalize_ticks( (tick_current_aligned, tick_lower, tick_upper) } -/// Reconstructs the liquidity array from the tick array and the current liquidity. +/// Reconstructs the liquidity array from the tick array and the current liquidity +/// +/// ## Arguments +/// +/// * `tick_array`: The tick array of tick and net liquidity sorted by tick +/// * `tick_current_aligned`: The current tick aligned to the tick spacing +/// * `current_liquidity`: The current liquidity +/// +/// ## Returns +/// +/// An array of ticks and corresponding cumulative liquidity #[inline] -#[allow(clippy::needless_pass_by_value)] -fn reconstruct_liquidity_array( - tick_array: Vec<(I, i128)>, +pub fn reconstruct_liquidity_array( + tick_array: &[(I, i128)], tick_current_aligned: I, current_liquidity: u128, ) -> Result, Error> { @@ -244,10 +253,10 @@ where .await .map_err(Error::LensError)?; reconstruct_liquidity_array( - ticks + &ticks .into_iter() .map(|tick| (TP::Index::from_i24(tick.tick), tick.liquidityNet)) - .collect(), + .collect::>(), tick_current_aligned, pool.liquidity, ) diff --git a/src/quoter.rs b/src/quoter.rs index d24db05..a720aeb 100644 --- a/src/quoter.rs +++ b/src/quoter.rs @@ -7,9 +7,9 @@ use uniswap_sdk_core::prelude::*; #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct QuoteOptions { /// The price limit for the trade. - sqrt_price_limit_x96: U160, + pub sqrt_price_limit_x96: U160, /// The quoter interface to use - use_quoter_v2: bool, + pub use_quoter_v2: bool, } /// Produces the on-chain method name of the appropriate function within QuoterV2,