From 1901daee667a2a0e5f262ec12772fc49feca0faa Mon Sep 17 00:00:00 2001 From: Shuhui Luo <107524008+shuhuiluo@users.noreply.github.com> Date: Wed, 22 Jan 2025 04:20:36 -0500 Subject: [PATCH] chore: upgrade to uniswap-sdk-core v3.3.0 and clean up imports (#127) * 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`. --- Cargo.toml | 5 ++--- README.md | 2 +- examples/from_pool_key_with_tick_data_provider.rs | 2 +- examples/self_permit.rs | 2 +- src/entities/pool.rs | 1 + src/entities/position.rs | 5 +++-- src/entities/tick_list_data_provider.rs | 1 + src/entities/trade.rs | 7 +++++-- src/extensions/mod.rs | 2 ++ src/extensions/position.rs | 4 +++- src/extensions/price_tick_conversions.rs | 4 +++- src/extensions/state_overrides.rs | 3 +++ src/extensions/tick_bit_map.rs | 3 +-- src/extensions/tick_map.rs | 3 +-- src/lib.rs | 7 ++----- src/multicall.rs | 1 + src/nonfungible_position_manager.rs | 3 ++- src/self_permit.rs | 2 +- src/staker.rs | 3 ++- src/swap_router.rs | 6 +++--- src/utils/encode_sqrt_ratio_x96.rs | 2 +- 21 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbc4165..4aa6563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-v3-sdk" -version = "3.2.0" +version = "3.3.0" edition = "2021" authors = ["Shuhui Luo "] description = "Uniswap V3 SDK for Rust" @@ -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 = [] diff --git a/README.md b/README.md index 67f993f..4bef791 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 = "3.2.0", features = ["extensions", "std"] } +uniswap-v3-sdk = { version = "3.3.0", features = ["extensions", "std"] } ``` ### Usage diff --git a/examples/from_pool_key_with_tick_data_provider.rs b/examples/from_pool_key_with_tick_data_provider.rs index 56f02ee..ec96112 100644 --- a/examples/from_pool_key_with_tick_data_provider.rs +++ b/examples/from_pool_key_with_tick_data_provider.rs @@ -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::*; diff --git a/examples/self_permit.rs b/examples/self_permit.rs index abd521b..a7621f8 100644 --- a/examples/self_permit.rs +++ b/examples/self_permit.rs @@ -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::*; diff --git a/src/entities/pool.rs b/src/entities/pool.rs index 3dc1a8e..e7ea7b6 100644 --- a/src/entities/pool.rs +++ b/src/entities/pool.rs @@ -367,6 +367,7 @@ impl Pool { mod tests { use super::*; use crate::tests::*; + use alloy_primitives::address; const ONE_ETHER: U160 = U160::from_limbs([10_u64.pow(18), 0, 0]); diff --git a/src/entities/position.rs b/src/entities/position.rs index 5905b2b..2a1aa15 100644 --- a/src/entities/position.rs +++ b/src/entities/position.rs @@ -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 @@ -121,7 +122,7 @@ impl Position { .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) } @@ -143,7 +144,7 @@ impl Position { #[inline] pub fn amount1(&self) -> Result, 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(), diff --git a/src/entities/tick_list_data_provider.rs b/src/entities/tick_list_data_provider.rs index a52caad..8209265 100644 --- a/src/entities/tick_list_data_provider.rs +++ b/src/entities/tick_list_data_provider.rs @@ -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. diff --git a/src/entities/trade.rs b/src/entities/trade.rs index c476182..6e9f1d2 100644 --- a/src/entities/trade.rs +++ b/src/entities/trade.rs @@ -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 @@ -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( diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 6879f30..5f0db8d 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -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; diff --git a/src/extensions/position.rs b/src/extensions/position.rs index 32085f8..c303fdd 100644 --- a/src/extensions/position.rs +++ b/src/extensions/position.rs @@ -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, @@ -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 = Some(BlockId::Number(BlockNumberOrTag::Number(17188000))); diff --git a/src/extensions/price_tick_conversions.rs b/src/extensions/price_tick_conversions.rs index b4deffd..2943dcc 100644 --- a/src/extensions/price_tick_conversions.rs +++ b/src/extensions/price_tick_conversions.rs @@ -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::*; diff --git a/src/extensions/state_overrides.rs b/src/extensions/state_overrides.rs index 199a2df..8464dbb 100644 --- a/src/extensions/state_overrides.rs +++ b/src/extensions/state_overrides.rs @@ -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::{ diff --git a/src/extensions/tick_bit_map.rs b/src/extensions/tick_bit_map.rs index a7b6c4c..8e082ce 100644 --- a/src/extensions/tick_bit_map.rs +++ b/src/extensions/tick_bit_map.rs @@ -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 = FxHashMap; diff --git a/src/extensions/tick_map.rs b/src/extensions/tick_map.rs index e9a8180..51a92f8 100644 --- a/src/extensions/tick_map.rs +++ b/src/extensions/tick_map.rs @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index ec17d9a..d1e378c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::*; diff --git a/src/multicall.rs b/src/multicall.rs index 13b75c2..cb97b08 100644 --- a/src/multicall.rs +++ b/src/multicall.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use alloc::vec::Vec; use alloy_primitives::Bytes; use alloy_sol_types::{Error, SolCall}; diff --git a/src/nonfungible_position_manager.rs b/src/nonfungible_position_manager.rs index 2766533..baff639 100644 --- a/src/nonfungible_position_manager.rs +++ b/src/nonfungible_position_manager.rs @@ -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)] @@ -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"); diff --git a/src/self_permit.rs b/src/self_permit.rs index c280127..ff7254b 100644 --- a/src/self_permit.rs +++ b/src/self_permit.rs @@ -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; diff --git a/src/staker.rs b/src/staker.rs index c3f159b..6b4fabb 100644 --- a/src/staker.rs +++ b/src/staker.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use alloc::vec::Vec; use alloy_primitives::{Address, Bytes, U256}; use alloy_sol_types::{SolCall, SolValue}; @@ -178,7 +179,7 @@ pub fn encode_deposit(incentive_keys: &[IncentiveKey]) 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}; diff --git a/src/swap_router.rs b/src/swap_router.rs index edf5cae..6b3c7aa 100644 --- a/src/swap_router.rs +++ b/src/swap_router.rs @@ -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)? @@ -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 @@ -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> = diff --git a/src/utils/encode_sqrt_ratio_x96.rs b/src/utils/encode_sqrt_ratio_x96.rs index d661a19..66a2f71 100644 --- a/src/utils/encode_sqrt_ratio_x96.rs +++ b/src/utils/encode_sqrt_ratio_x96.rs @@ -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`. ///