Skip to content

Commit

Permalink
chore: upgrade to uniswap-sdk-core v3.3.0 and clean up imports (#127)
Browse files Browse the repository at this point in the history
* chore: upgrade to uniswap-sdk-core v3.3.0 and clean up imports

Updated the SDK version to 3.3.0, along with related dependency adjustments in `Cargo.toml` and `README.md`. Refactored imports across multiple files for improved modularity and alignment with updated dependencies. Minor replacements were made for constants like `BigInt::ZERO`.

* Add `alloc::vec::Vec` imports across multiple modules

This change ensures the explicit use of `alloc::vec::Vec` where necessary for better clarity and consistency in memory allocation. Updated the imports in `trade.rs`, `tick_list_data_provider.rs`, `multicall.rs`, and `staker.rs`.
  • Loading branch information
shuhuiluo authored Jan 22, 2025
1 parent 13fd3fb commit 1901dae
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 28 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v3-sdk"
version = "3.2.0"
version = "3.3.0"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V3 SDK for Rust"
Expand All @@ -27,11 +27,10 @@ num-integer = "0.1"
num-traits = "0.2"
once_cell = "1.20"
regex = { version = "1.11", optional = true }
rustc-hash = "2.0"
serde_json = { version = "1.0", optional = true }
thiserror = { version = "2", default-features = false }
uniswap-lens = { version = "0.10", optional = true }
uniswap-sdk-core = "3.2.0"
uniswap-sdk-core = "3.3.0"

[features]
default = []
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 = "3.2.0", features = ["extensions", "std"] }
uniswap-v3-sdk = { version = "3.3.0", features = ["extensions", "std"] }
```

### Usage
Expand Down
2 changes: 1 addition & 1 deletion examples/from_pool_key_with_tick_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use alloy::{
rpc::types::TransactionRequest,
transports::http::reqwest::Url,
};
use alloy_primitives::{address, U256};
use alloy_primitives::U256;
use alloy_sol_types::SolCall;
use uniswap_sdk_core::{prelude::*, token};
use uniswap_v3_sdk::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion examples/self_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use alloy::{
sol,
transports::http::reqwest::Url,
};
use alloy_primitives::{address, keccak256, PrimitiveSignature, B256, U256};
use alloy_primitives::{keccak256, PrimitiveSignature, B256, U256};
use alloy_sol_types::SolValue;
use uniswap_sdk_core::{prelude::*, token};
use uniswap_v3_sdk::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions src/entities/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ impl<TP: Clone + TickDataProvider> Pool<TP> {
mod tests {
use super::*;
use crate::tests::*;
use alloy_primitives::address;

const ONE_ETHER: U160 = U160::from_limbs([10_u64.pow(18), 0, 0]);

Expand Down
5 changes: 3 additions & 2 deletions src/entities/position.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::{Error, *};
use alloy_primitives::{U160, U256};
use num_traits::ToPrimitive;
use uniswap_sdk_core::prelude::*;

/// Represents a position on a Uniswap V3 Pool
Expand Down Expand Up @@ -121,7 +122,7 @@ impl<TP: TickDataProvider> Position<TP> {
.to_big_int(),
)
} else {
CurrencyAmount::from_raw_amount(self.pool.token0.clone(), BigInt::zero())
CurrencyAmount::from_raw_amount(self.pool.token0.clone(), BigInt::ZERO)
}
.map_err(Error::Core)
}
Expand All @@ -143,7 +144,7 @@ impl<TP: TickDataProvider> Position<TP> {
#[inline]
pub fn amount1(&self) -> Result<CurrencyAmount<Token>, Error> {
if self.pool.tick_current < self.tick_lower {
CurrencyAmount::from_raw_amount(self.pool.token1.clone(), BigInt::zero())
CurrencyAmount::from_raw_amount(self.pool.token1.clone(), BigInt::ZERO)
} else if self.pool.tick_current < self.tick_upper {
CurrencyAmount::from_raw_amount(
self.pool.token1.clone(),
Expand Down
1 change: 1 addition & 0 deletions src/entities/tick_list_data_provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use alloc::vec::Vec;
use derive_more::Deref;

/// A data provider for ticks that is backed by an in-memory array of ticks.
Expand Down
7 changes: 5 additions & 2 deletions src/entities/trade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::prelude::{Error, *};
use rustc_hash::FxHashSet;
use uniswap_sdk_core::prelude::{sorted_insert::sorted_insert, *};
use alloc::vec;
use alloy_primitives::map::rustc_hash::FxHashSet;
use core::cmp::Ordering;
use uniswap_sdk_core::prelude::{sorted_insert, *};

/// Trades comparator, an extension of the input output comparator that also considers other
/// dimensions of the trade in ranking them
Expand Down Expand Up @@ -815,6 +817,7 @@ where
mod tests {
use super::*;
use crate::tests::*;
use num_traits::ToPrimitive;
use once_cell::sync::Lazy;

fn v2_style_pool(
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pub use price_tick_conversions::*;
pub use state_overrides::*;
pub use tick_bit_map::*;
pub use tick_map::*;

pub use uniswap_lens as lens;
4 changes: 3 additions & 1 deletion src/extensions/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use alloy::{
use alloy_primitives::{Address, ChainId, U256};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use num_bigint::ToBigInt;
use uniswap_lens::{
bindings::{
ephemeralallpositionsbyowner::EphemeralAllPositionsByOwner,
Expand Down Expand Up @@ -483,7 +484,8 @@ mod tests {
use super::*;
use crate::tests::PROVIDER;
use alloy_primitives::{address, uint};
use num_traits::Signed;
use core::str::FromStr;
use num_traits::{Signed, Zero};

const NPM: Address = address!("C36442b4a4522E871399CD717aBDD847Ab11FE88");
const BLOCK_ID: Option<BlockId> = Some(BlockId::Number(BlockNumberOrTag::Number(17188000)));
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/price_tick_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::prelude::{Error, *};
use alloc::format;
use alloy_primitives::{aliases::I24, U160};
use anyhow::{bail, Result};
use num_traits::Signed;
use core::str::FromStr;
use num_bigint::ToBigInt;
use num_traits::{Signed, Zero};
use once_cell::sync::Lazy;
use regex::Regex;
use uniswap_sdk_core::prelude::*;
Expand Down
3 changes: 3 additions & 0 deletions src/extensions/state_overrides.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! ## State Overrides
//! This module provides functions to generate state overrides for ERC20 tokens.
use crate::prelude::Error;
use alloc::vec::Vec;
use alloy::{
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/tick_bit_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use crate::prelude::*;
use alloy::uint;
use alloy_primitives::{aliases::I24, U256};
use rustc_hash::FxHashMap;
use alloy_primitives::{aliases::I24, map::rustc_hash::FxHashMap, U256};

pub type TickBitMap<I = I24> = FxHashMap<I, U256>;

Expand Down
3 changes: 1 addition & 2 deletions src/extensions/tick_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use crate::prelude::*;
use alloy::uint;
use alloy_primitives::{aliases::I24, U256};
use rustc_hash::FxHashMap;
use alloy_primitives::{aliases::I24, map::rustc_hash::FxHashMap, U256};

#[derive(Clone, Debug)]
pub struct TickMap<I = I24> {
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ pub mod prelude {
abi::*, constants::*, entities::*, error::*, multicall::*, nonfungible_position_manager::*,
payments::*, quoter::*, self_permit::*, staker::*, swap_router::*, utils::*,
};
pub use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};

pub use uniswap_sdk_core as sdk_core;

#[cfg(feature = "extensions")]
pub use crate::extensions::*;
Expand Down
1 change: 1 addition & 0 deletions src/multicall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use alloc::vec::Vec;
use alloy_primitives::Bytes;
use alloy_sol_types::{Error, SolCall};

Expand Down
3 changes: 2 additions & 1 deletion src/nonfungible_position_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::{Error, *};
use alloy_primitives::{Bytes, PrimitiveSignature, B256, U256};
use alloy_sol_types::{eip712_domain, Eip712Domain, SolCall, SolStruct};
use num_traits::ToPrimitive;
use uniswap_sdk_core::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -496,7 +497,7 @@ pub const fn get_permit_data(
mod tests {
use super::*;
use crate::tests::*;
use alloy_primitives::{hex, uint};
use alloy_primitives::{address, hex, uint};
use once_cell::sync::Lazy;

const RECIPIENT: Address = address!("0000000000000000000000000000000000000003");
Expand Down
2 changes: 1 addition & 1 deletion src/self_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn encode_permit(token: &impl BaseCurrency, options: PermitOptions) -> Bytes
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::{address, hex, uint};
use alloy_primitives::{hex, uint};
use once_cell::sync::Lazy;
use uniswap_sdk_core::token;

Expand Down
3 changes: 2 additions & 1 deletion src/staker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use alloc::vec::Vec;
use alloy_primitives::{Address, Bytes, U256};
use alloy_sol_types::{SolCall, SolValue};

Expand Down Expand Up @@ -178,7 +179,7 @@ pub fn encode_deposit<TP: TickDataProvider>(incentive_keys: &[IncentiveKey<TP>])
mod tests {
use super::*;
use crate::tests::*;
use alloy_primitives::{hex, uint};
use alloy_primitives::{address, hex, uint};
use once_cell::sync::Lazy;
use uniswap_sdk_core::{prelude::*, token};

Expand Down
6 changes: 3 additions & 3 deletions src/swap_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
calldatas.push(encode_permit(token_in, input_token_permit));
}

let mut total_amount_out = BigInt::zero();
let mut total_amount_out = BigInt::ZERO;
for trade in trades.iter_mut() {
total_amount_out += trade
.minimum_amount_out_cached(slippage_tolerance.clone(), None)?
Expand All @@ -91,7 +91,7 @@ where
// flags for whether funds should be sent first to the router
let router_must_custody = output_is_native || fee.is_some();

let mut total_value = BigInt::zero();
let mut total_value = BigInt::ZERO;
if input_is_native {
for trade in trades.iter_mut() {
total_value += trade
Expand Down Expand Up @@ -223,7 +223,7 @@ where
mod tests {
use super::*;
use crate::tests::*;
use alloy_primitives::{hex, uint};
use alloy_primitives::{address, hex, uint};
use once_cell::sync::Lazy;

static POOL_0_1: Lazy<Pool<TickListDataProvider>> =
Expand Down
2 changes: 1 addition & 1 deletion src/utils/encode_sqrt_ratio_x96.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::FromBig;
use alloy_primitives::Uint;
use num_bigint::BigInt;
use uniswap_sdk_core::utils::sqrt::sqrt;
use uniswap_sdk_core::utils::sqrt;

/// Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of `amount1` and `amount0`.
///
Expand Down

0 comments on commit 1901dae

Please sign in to comment.