Skip to content

Commit

Permalink
chore: update dependencies and refactor code (#104)
Browse files Browse the repository at this point in the history
* chore: update dependencies and refactor code

Updated several package dependencies to their latest versions to improve compatibility and performance. Refactored code to use `PrimitiveSignature` instead of `Signature` and simplified pool entity creation by eliminating redundant method calls.

* Refactor `Signature` to `PrimitiveSignature`

Updated various structs and functions to use `PrimitiveSignature` instead of `Signature` for better consistency and clarity. Modified the creation logic and type casting for the `v` field to handle boolean values.
  • Loading branch information
shuhuiluo authored Nov 8, 2024
1 parent ec6a972 commit 43921d0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniswap-v3-sdk"
version = "2.5.0"
version = "2.6.0"
edition = "2021"
authors = ["Shuhui Luo <twitter.com/aureliano_law>"]
description = "Uniswap V3 SDK for Rust"
Expand All @@ -14,7 +14,7 @@ exclude = [".github", ".gitignore", "rustfmt.toml"]
all-features = true

[dependencies]
alloy = { version = "0.5", optional = true, features = ["contract"] }
alloy = { version = "0.6", optional = true, features = ["contract"] }
alloy-primitives = "0.8"
alloy-sol-types = "0.8"
anyhow = { version = "1.0", optional = true }
Expand All @@ -29,7 +29,7 @@ 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.6", optional = true }
uniswap-lens = { version = "0.7", optional = true }
uniswap-sdk-core = "3.1.0"

[features]
Expand All @@ -38,8 +38,8 @@ extensions = ["alloy", "anyhow", "base64", "regex", "serde_json", "uniswap-lens"
std = ["alloy?/std", "thiserror/std", "uniswap-sdk-core/std", "uniswap-lens?/std"]

[dev-dependencies]
alloy-signer = "0.5"
alloy-signer-local = "0.5"
alloy-signer = "0.6"
alloy-signer-local = "0.6"
criterion = "0.5.1"
dotenv = "0.15.0"
tokio = { version = "1.40", features = ["full"] }
Expand Down
24 changes: 10 additions & 14 deletions src/entities/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,12 @@ impl<TP: Clone + TickDataProvider> Pool<TP> {
};
Ok((
CurrencyAmount::from_raw_amount(output_token, -output_amount.to_big_int())?,
Self::new_with_tick_data_provider(
self.token0.clone(),
self.token1.clone(),
self.fee,
sqrt_price_x96,
Self {
sqrt_ratio_x96: sqrt_price_x96,
tick_current: TP::Index::from_i24(sqrt_price_x96.get_tick_at_sqrt_ratio()?),
liquidity,
self.tick_data_provider.clone(),
)?,
..self.clone()
},
))
}

Expand Down Expand Up @@ -355,14 +353,12 @@ impl<TP: Clone + TickDataProvider> Pool<TP> {
};
Ok((
CurrencyAmount::from_raw_amount(input_token, input_amount.to_big_int())?,
Self::new_with_tick_data_provider(
self.token0.clone(),
self.token1.clone(),
self.fee,
sqrt_price_x96,
Self {
sqrt_ratio_x96: sqrt_price_x96,
tick_current: TP::Index::from_i24(sqrt_price_x96.get_tick_at_sqrt_ratio()?),
liquidity,
self.tick_data_provider.clone(),
)?,
..self.clone()
},
))
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/nonfungible_position_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::{Error, *};
use alloy_primitives::{Bytes, Signature, U256};
use alloy_primitives::{Bytes, PrimitiveSignature, U256};
use alloy_sol_types::{eip712_domain, Eip712Domain, SolCall};
use uniswap_sdk_core::prelude::*;

Expand Down Expand Up @@ -74,7 +74,7 @@ pub struct NFTPermitData {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NFTPermitOptions {
pub signature: Signature,
pub signature: PrimitiveSignature,
pub deadline: U256,
pub spender: Address,
}
Expand Down Expand Up @@ -335,7 +335,7 @@ where
spender: permit.spender,
tokenId: token_id,
deadline: permit.deadline,
v: permit.signature.v().y_parity_byte(),
v: permit.signature.v() as u8,
r: permit.signature.r().into(),
s: permit.signature.s().into(),
}
Expand Down Expand Up @@ -435,7 +435,7 @@ pub fn safe_transfer_from_parameters(options: SafeTransferOptions) -> MethodPara
/// ## Examples
///
/// ```
/// use alloy_primitives::{address, b256, uint, Signature, B256};
/// use alloy_primitives::{address, b256, uint, PrimitiveSignature, B256};
/// use alloy_signer::SignerSync;
/// use alloy_signer_local::PrivateKeySigner;
/// use alloy_sol_types::SolStruct;
Expand All @@ -458,7 +458,7 @@ pub fn safe_transfer_from_parameters(options: SafeTransferOptions) -> MethodPara
/// let hash: B256 = data.values.eip712_signing_hash(&data.domain);
///
/// let signer = PrivateKeySigner::random();
/// let signature: Signature = signer.sign_hash_sync(&hash).unwrap();
/// let signature: PrimitiveSignature = signer.sign_hash_sync(&hash).unwrap();
/// assert_eq!(
/// signature.recover_address_from_prehash(&hash).unwrap(),
/// signer.address()
Expand Down
26 changes: 13 additions & 13 deletions src/self_permit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::abi::ISelfPermit;
use alloy_primitives::{Bytes, Signature, U256};
use alloy_primitives::{Bytes, PrimitiveSignature, U256};
use alloy_sol_types::{eip712_domain, Eip712Domain, SolCall, SolStruct};
use uniswap_sdk_core::prelude::*;

Expand All @@ -26,7 +26,7 @@ pub struct ERC20PermitData<P: SolStruct> {
/// ## Examples
///
/// ```
/// use alloy_primitives::{address, b256, uint, Signature, B256};
/// use alloy_primitives::{address, b256, uint, PrimitiveSignature, B256};
/// use alloy_signer::SignerSync;
/// use alloy_signer_local::PrivateKeySigner;
/// use alloy_sol_types::SolStruct;
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct ERC20PermitData<P: SolStruct> {
/// // Derive the EIP-712 signing hash.
/// let hash: B256 = data.values.eip712_signing_hash(&data.domain);
///
/// let signature: Signature = signer.sign_hash_sync(&hash).unwrap();
/// let signature: PrimitiveSignature = signer.sign_hash_sync(&hash).unwrap();
/// assert_eq!(
/// signature.recover_address_from_prehash(&hash).unwrap(),
/// signer.address()
Expand Down Expand Up @@ -96,14 +96,14 @@ pub fn get_erc20_permit_data<P: SolStruct>(

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StandardPermitArguments {
pub signature: Signature,
pub signature: PrimitiveSignature,
pub amount: U256,
pub deadline: U256,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AllowedPermitArguments {
pub signature: Signature,
pub signature: PrimitiveSignature,
pub nonce: U256,
pub expiry: U256,
}
Expand All @@ -117,9 +117,9 @@ pub enum PermitOptions {
impl StandardPermitArguments {
#[inline]
#[must_use]
pub fn new(r: U256, s: U256, v: u64, amount: U256, deadline: U256) -> Self {
pub fn new(r: U256, s: U256, v: bool, amount: U256, deadline: U256) -> Self {
Self {
signature: Signature::from_rs_and_parity(r, s, v).unwrap(),
signature: PrimitiveSignature::new(r, s, v),
amount,
deadline,
}
Expand All @@ -129,9 +129,9 @@ impl StandardPermitArguments {
impl AllowedPermitArguments {
#[inline]
#[must_use]
pub fn new(r: U256, s: U256, v: u64, nonce: U256, expiry: U256) -> Self {
pub fn new(r: U256, s: U256, v: bool, nonce: U256, expiry: U256) -> Self {
Self {
signature: Signature::from_rs_and_parity(r, s, v).unwrap(),
signature: PrimitiveSignature::new(r, s, v),
nonce,
expiry,
}
Expand All @@ -146,7 +146,7 @@ pub fn encode_permit(token: &Token, options: PermitOptions) -> Bytes {
token: token.address(),
value: args.amount,
deadline: args.deadline,
v: args.signature.v().y_parity_byte(),
v: args.signature.v() as u8,
r: args.signature.r().into(),
s: args.signature.s().into(),
}
Expand All @@ -155,7 +155,7 @@ pub fn encode_permit(token: &Token, options: PermitOptions) -> Bytes {
token: token.address(),
nonce: args.nonce,
expiry: args.expiry,
v: args.signature.v().y_parity_byte(),
v: args.signature.v() as u8,
r: args.signature.r().into(),
s: args.signature.s().into(),
}
Expand All @@ -179,7 +179,7 @@ mod tests {
let standard_permit_options = StandardPermitArguments::new(
uint!(1_U256),
uint!(2_U256),
0,
false,
uint!(123_U256),
uint!(123_U256),
);
Expand All @@ -192,7 +192,7 @@ mod tests {
let allowed_permit_options = AllowedPermitArguments::new(
uint!(1_U256),
uint!(2_U256),
0,
false,
uint!(123_U256),
uint!(123_U256),
);
Expand Down

0 comments on commit 43921d0

Please sign in to comment.