diff --git a/Cargo.toml b/Cargo.toml index f4b8685..1cb51c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ alloy-sol-types = "0.8" anyhow = { version = "1.0", optional = true } base64 = { version = "0.22", optional = true } bigdecimal = "0.4.5" +derive_more = { version = "1.0.0", features = ["deref", "from"] } num-bigint = "0.4" num-integer = "0.1" num-traits = "0.2" diff --git a/src/entities/tick_list_data_provider.rs b/src/entities/tick_list_data_provider.rs index 22ef03d..9141aa7 100644 --- a/src/entities/tick_list_data_provider.rs +++ b/src/entities/tick_list_data_provider.rs @@ -1,8 +1,8 @@ use crate::prelude::*; -use core::ops::Deref; +use derive_more::Deref; /// A data provider for ticks that is backed by an in-memory array of ticks. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Deref)] pub struct TickListDataProvider(Vec>); impl TickListDataProvider { @@ -13,15 +13,6 @@ impl TickListDataProvider { } } -impl Deref for TickListDataProvider { - type Target = Vec>; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.0 - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/error.rs b/src/error.rs index a7449ba..3112d29 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,18 +7,16 @@ use alloy::contract::Error as ContractError; use uniswap_lens::error::Error as LensError; use alloy_primitives::{aliases::I24, U160}; +use derive_more::From; use uniswap_sdk_core::error::Error as CoreError; -#[cfg_attr( - not(feature = "extensions"), - derive(Clone, Copy, Debug, Hash, PartialEq, Eq) -)] -#[cfg_attr(feature = "extensions", derive(Debug))] +#[derive(Debug, From)] +#[cfg_attr(not(feature = "extensions"), derive(Clone, Copy, Hash, PartialEq, Eq))] #[cfg_attr(feature = "std", derive(thiserror::Error))] pub enum Error { /// Thrown when an error occurs in the core library. #[cfg_attr(feature = "std", error("{0}"))] - Core(CoreError), + Core(#[cfg_attr(not(feature = "std"), from)] CoreError), /// Thrown when the token passed to [`Pool::price_of`] is not one of the pool's tokens. #[cfg_attr(feature = "std", error("Invalid token"))] @@ -64,32 +62,9 @@ pub enum Error { #[cfg(feature = "extensions")] #[cfg_attr(feature = "std", error("{0}"))] - ContractError(ContractError), + ContractError(#[cfg_attr(not(feature = "std"), from)] ContractError), #[cfg(feature = "extensions")] #[cfg_attr(feature = "std", error("{0}"))] - LensError(LensError), -} - -impl From for Error { - #[inline] - fn from(error: CoreError) -> Self { - Self::Core(error) - } -} - -#[cfg(feature = "extensions")] -impl From for Error { - #[inline] - fn from(error: ContractError) -> Self { - Self::ContractError(error) - } -} - -#[cfg(feature = "extensions")] -impl From for Error { - #[inline] - fn from(error: LensError) -> Self { - Self::LensError(error) - } + LensError(#[cfg_attr(not(feature = "std"), from)] LensError), } diff --git a/src/extensions/ephemeral_tick_data_provider.rs b/src/extensions/ephemeral_tick_data_provider.rs index f07c9dd..358f016 100644 --- a/src/extensions/ephemeral_tick_data_provider.rs +++ b/src/extensions/ephemeral_tick_data_provider.rs @@ -4,17 +4,18 @@ use crate::prelude::*; use alloy::{eips::BlockId, providers::Provider, transports::Transport}; use alloy_primitives::{aliases::I24, Address}; -use core::ops::Deref; +use derive_more::Deref; use uniswap_lens::pool_lens; /// A data provider that fetches ticks using an ephemeral contract in a single `eth_call`. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Deref)] pub struct EphemeralTickDataProvider { pub pool: Address, pub tick_lower: I, pub tick_upper: I, pub tick_spacing: I, pub block_id: Option, + #[deref] pub ticks: Vec>, } @@ -59,15 +60,6 @@ impl EphemeralTickDataProvider { } } -impl Deref for EphemeralTickDataProvider { - type Target = Vec>; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.ticks - } -} - impl From> for TickListDataProvider { #[inline] fn from(provider: EphemeralTickDataProvider) -> Self { diff --git a/src/extensions/ephemeral_tick_map_data_provider.rs b/src/extensions/ephemeral_tick_map_data_provider.rs index 124c175..d9f2ca2 100644 --- a/src/extensions/ephemeral_tick_map_data_provider.rs +++ b/src/extensions/ephemeral_tick_map_data_provider.rs @@ -4,16 +4,17 @@ use crate::prelude::*; use alloy::{eips::BlockId, providers::Provider, transports::Transport}; use alloy_primitives::{aliases::I24, Address}; -use core::ops::Deref; +use derive_more::Deref; /// A data provider that fetches ticks using an ephemeral contract in a single `eth_call`. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Deref)] pub struct EphemeralTickMapDataProvider { pub pool: Address, pub tick_lower: I, pub tick_upper: I, pub tick_spacing: I, pub block_id: Option, + #[deref] pub tick_map: TickMap, } @@ -44,15 +45,6 @@ impl EphemeralTickMapDataProvider { } } -impl Deref for EphemeralTickMapDataProvider { - type Target = TickMap; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.tick_map - } -} - #[cfg(test)] mod tests { use super::*;