Skip to content

Commit

Permalink
Merge pull request #101 from shuhuiluo/chore
Browse files Browse the repository at this point in the history
Chores
  • Loading branch information
shuhuiluo authored Oct 24, 2024
2 parents 53f94f4 + c98c28c commit 29d2da6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v3-sdk"
version = "2.3.0"
version = "2.4.0"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V3 SDK for Rust"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/entities/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ where
.iter()
.map(|swap| swap.route.pools.len())
.sum::<usize>();
let mut pool_address_set = FxHashSet::<Address>::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,
Expand Down
21 changes: 15 additions & 6 deletions src/extensions/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ fn normalize_ticks<I: TickIndex>(
(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<I: TickIndex>(
tick_array: Vec<(I, i128)>,
pub fn reconstruct_liquidity_array<I: TickIndex>(
tick_array: &[(I, i128)],
tick_current_aligned: I,
current_liquidity: u128,
) -> Result<Vec<(I, u128)>, Error> {
Expand Down Expand Up @@ -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::<Vec<(TP::Index, i128)>>(),
tick_current_aligned,
pool.liquidity,
)
Expand Down
4 changes: 2 additions & 2 deletions src/quoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 29d2da6

Please sign in to comment.