Skip to content

Commit

Permalink
chore: upgrade dependencies and refactor for compatibility (#24)
Browse files Browse the repository at this point in the history
Updated core and v3 SDK dependencies to version 3.3.0, replaced deprecated methods (e.g., `BigInt::zero()` with `BigInt::ZERO`), and added `num-traits` for additional numeric operations. Refactored imports, added `const` to optimize certain methods, and adjusted library versions in `Cargo.toml` for compatibility improvements.
  • Loading branch information
shuhuiluo authored Jan 22, 2025
1 parent 1562d02 commit f193180
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v4-sdk"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V4 SDK for Rust"
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/entities/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ mod tests {

mod constructor {
use super::*;
use alloy_primitives::address;

#[test]
#[should_panic(expected = "Core(ChainIdMismatch(1, 3))")]
Expand Down
6 changes: 4 additions & 2 deletions src/entities/position.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -103,7 +105,7 @@ impl<TP: TickDataProvider> Position<TP> {
.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)
}
Expand All @@ -125,7 +127,7 @@ impl<TP: TickDataProvider> Position<TP> {
#[inline]
pub fn amount1(&self) -> Result<CurrencyAmount<Currency>, 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(),
Expand Down
1 change: 0 additions & 1 deletion src/entities/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
17 changes: 10 additions & 7 deletions src/entities/trade.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -623,7 +625,7 @@ where
let mut populated_routes: Vec<Swap<TInput, TOutput, TP>> = 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)
}
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions src/position_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::*;
///
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/v4_base_actions_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/utils/v4_planner.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f193180

Please sign in to comment.