diff --git a/Cargo.toml b/Cargo.toml index faf2d69..f520957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniswap-v4-sdk" -version = "0.1.1" +version = "0.2.0" edition = "2021" authors = ["Shuhui Luo "] description = "Uniswap V4 SDK for Rust" @@ -15,14 +15,13 @@ exclude = [".github", ".gitignore", "rustfmt.toml"] alloy-primitives = "0.8" alloy-sol-types = "0.8" derive_more = "1.0.0" -rustc-hash = "2.1.0" +num-traits = "0.2.19" thiserror = { version = "2", default-features = false } -uniswap-sdk-core = "3.2.0" -uniswap-v3-sdk = "3.1.1" +uniswap-sdk-core = "3.3.0" +uniswap-v3-sdk = "3.3.0" [dev-dependencies] -alloy-signer = "0.8" -alloy-signer-local = "0.8" +alloy = { version = "0.9", features = ["signer-local"] } once_cell = "1.20.2" [features] diff --git a/src/entities/pool.rs b/src/entities/pool.rs index fa4ce87..96cb9d0 100644 --- a/src/entities/pool.rs +++ b/src/entities/pool.rs @@ -438,6 +438,7 @@ mod tests { mod constructor { use super::*; + use alloy_primitives::address; #[test] #[should_panic(expected = "Core(ChainIdMismatch(1, 3))")] diff --git a/src/entities/position.rs b/src/entities/position.rs index 547acb3..29560d5 100644 --- a/src/entities/position.rs +++ b/src/entities/position.rs @@ -1,5 +1,7 @@ use crate::prelude::{tick_to_price, Error, Pool, *}; +use alloc::vec; use alloy_primitives::{aliases::U48, uint, U160, U256}; +use num_traits::ToPrimitive; use uniswap_sdk_core::prelude::*; use uniswap_v3_sdk::prelude::*; @@ -103,7 +105,7 @@ impl Position { .to_big_int(), ) } else { - CurrencyAmount::from_raw_amount(self.pool.currency0.clone(), BigInt::zero()) + CurrencyAmount::from_raw_amount(self.pool.currency0.clone(), BigInt::ZERO) } .map_err(Error::Core) } @@ -125,7 +127,7 @@ impl Position { #[inline] pub fn amount1(&self) -> Result, Error> { if self.pool.tick_current < self.tick_lower { - CurrencyAmount::from_raw_amount(self.pool.currency1.clone(), BigInt::zero()) + CurrencyAmount::from_raw_amount(self.pool.currency1.clone(), BigInt::ZERO) } else if self.pool.tick_current < self.tick_upper { CurrencyAmount::from_raw_amount( self.pool.currency1.clone(), diff --git a/src/entities/route.rs b/src/entities/route.rs index 4b7f12d..80990ea 100644 --- a/src/entities/route.rs +++ b/src/entities/route.rs @@ -125,7 +125,6 @@ where mod tests { use super::{Pool, Route}; use crate::tests::*; - use alloy_primitives::address; use once_cell::sync::Lazy; use uniswap_sdk_core::{prelude::*, token}; use uniswap_v3_sdk::prelude::*; diff --git a/src/entities/trade.rs b/src/entities/trade.rs index f02ef06..7057aaa 100644 --- a/src/entities/trade.rs +++ b/src/entities/trade.rs @@ -1,6 +1,8 @@ use crate::prelude::{amount_with_path_currency, Error, Pool, Route}; -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, *}; use uniswap_v3_sdk::prelude::*; /// Trades comparator, an extension of the input output comparator that also considers other @@ -113,14 +115,14 @@ where /// Returns the input currency of the swap #[inline] - pub fn input_currency(&self) -> &TInput { - &self.input_amount.currency + pub const fn input_currency(&self) -> &TInput { + &self.input_amount.meta.currency } /// Returns the output currency of the swap #[inline] - pub fn output_currency(&self) -> &TOutput { - &self.output_amount.currency + pub const fn output_currency(&self) -> &TOutput { + &self.output_amount.meta.currency } } @@ -623,7 +625,7 @@ where let mut populated_routes: Vec> = Vec::with_capacity(routes.len()); for (amount, route) in routes { let trade = Self::from_route(route, amount, trade_type)?; - populated_routes.push(trade.swaps[0].clone()); + populated_routes.push(trade.swaps.into_iter().next().unwrap()); } Self::new(populated_routes, trade_type) } @@ -836,6 +838,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/lib.rs b/src/lib.rs index 9809e40..9c5cacb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,4 +40,7 @@ mod tests; pub mod prelude { pub use crate::{abi::*, entities::*, error::*, multicall::*, position_manager::*, utils::*}; + + pub use uniswap_sdk_core as sdk_core; + pub use uniswap_v3_sdk as v3_sdk; } diff --git a/src/position_manager.rs b/src/position_manager.rs index 724e545..291e1ce 100644 --- a/src/position_manager.rs +++ b/src/position_manager.rs @@ -3,6 +3,7 @@ use alloc::vec::Vec; use alloy_primitives::{address, Address, Bytes, PrimitiveSignature, U160, U256}; use alloy_sol_types::{eip712_domain, SolCall}; use derive_more::{Deref, DerefMut}; +use num_traits::ToPrimitive; use uniswap_sdk_core::prelude::*; use uniswap_v3_sdk::prelude::{ IERC721Permit, MethodParameters, MintAmounts, TickDataProvider, TickIndex, @@ -452,9 +453,8 @@ pub fn encode_erc721_permit( /// ## Examples /// /// ``` +/// use alloy::signers::{local::PrivateKeySigner, SignerSync}; /// use alloy_primitives::{address, b256, uint, PrimitiveSignature, B256}; -/// use alloy_signer::SignerSync; -/// use alloy_signer_local::PrivateKeySigner; /// use alloy_sol_types::SolStruct; /// use uniswap_v4_sdk::prelude::*; /// @@ -475,7 +475,7 @@ pub fn encode_erc721_permit( /// ); /// /// // Derive the EIP-712 signing hash. -/// let hash: B256 = data.values.eip712_signing_hash(&data.domain); +/// let hash: B256 = data.eip712_signing_hash(); /// /// let signer = PrivateKeySigner::random(); /// let signature: PrimitiveSignature = signer.sign_hash_sync(&hash).unwrap(); diff --git a/src/utils/v4_base_actions_parser.rs b/src/utils/v4_base_actions_parser.rs index 312e43b..68b1e30 100644 --- a/src/utils/v4_base_actions_parser.rs +++ b/src/utils/v4_base_actions_parser.rs @@ -26,7 +26,7 @@ mod tests { use crate::{prelude::*, tests::*}; use alloy_primitives::{address, uint, Address, U160, U256}; use once_cell::sync::Lazy; - use uniswap_v3_sdk::{constants::FeeAmount, prelude::encode_sqrt_ratio_x96}; + use uniswap_v3_sdk::prelude::{encode_sqrt_ratio_x96, FeeAmount}; const ADDRESS_ONE: Address = address!("0000000000000000000000000000000000000001"); const ADDRESS_TWO: Address = address!("0000000000000000000000000000000000000002"); diff --git a/src/utils/v4_planner.rs b/src/utils/v4_planner.rs index b094492..cd8046e 100644 --- a/src/utils/v4_planner.rs +++ b/src/utils/v4_planner.rs @@ -1,6 +1,7 @@ use crate::prelude::{encode_route_to_path, Error, Trade, *}; use alloy_primitives::{Bytes, U256}; use alloy_sol_types::SolValue; +use num_traits::ToPrimitive; use uniswap_sdk_core::prelude::*; use uniswap_v3_sdk::prelude::*; @@ -541,7 +542,7 @@ mod tests { mod add_take { use super::*; - use alloy_primitives::uint; + use alloy_primitives::{address, uint}; #[test] fn completes_v4_take_without_specified_amount() {