#[macro_export]
macro_rules! impl_v3_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency0_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let slot0 = self.slot0(block_id).await?;
let pool_key = self.pool_key();
let price = $crate::pool_viewers::v3::utils::calculate_price_from_sqrt_price_x96(
slot0.sqrtPriceX96,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency0 price calculated");
Ok(price)
}
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency1_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let price = self.currency0_price(block_id).await?.invert();
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency1 price calculated (inverted)");
Ok(price)
}
}
};
}
#[macro_export]
macro_rules! impl_slipstream_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency0_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let slot0 = self.slot0(block_id).await?;
let pool_key = self.pool_key();
let price = $crate::pool_viewers::slipstream::utils::calculate_price_from_sqrt_price_x96(
slot0.sqrtPriceX96,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency0 price calculated");
Ok(price)
}
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency1_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let price = self.currency0_price(block_id).await?.invert();
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency1 price calculated (inverted)");
Ok(price)
}
}
};
}
#[macro_export]
macro_rules! impl_pancake_v3_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency0_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let slot0 = self.slot0(block_id).await?;
let pool_key = self.pool_key();
let price = $crate::pool_viewers::v3::utils::calculate_price_from_sqrt_price_x96(
slot0.sqrtPriceX96,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency0 price calculated");
Ok(price)
}
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency1_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let price = self.currency0_price(block_id).await?.invert();
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency1 price calculated (inverted)");
Ok(price)
}
}
};
}
#[macro_export]
macro_rules! impl_shadow_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency0_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let slot0 = self.slot0(block_id).await?;
let pool_key = self.pool_key();
let price = $crate::pool_viewers::v3::utils::calculate_price_from_sqrt_price_x96(
slot0.sqrtPriceX96,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency0 price calculated");
Ok(price)
}
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency1_price(&self, block_id: Option<alloy::eips::BlockId>) -> anyhow::Result<uniswap_sdk_core::prelude::Price<uniswap_sdk_core::prelude::Currency, uniswap_sdk_core::prelude::Currency>> {
let price = self.currency0_price(block_id).await?.invert();
tracing::debug!(price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()), "Currency1 price calculated (inverted)");
Ok(price)
}
}
};
}
#[macro_export]
macro_rules! impl_quickswap_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency0_price(
&self,
block_id: Option<alloy::eips::BlockId>,
) -> anyhow::Result<
uniswap_sdk_core::prelude::Price<
uniswap_sdk_core::prelude::Currency,
uniswap_sdk_core::prelude::Currency,
>,
> {
let sqrt_price_x96 = $crate::traits::pool_state::PoolState::sqrt_price_x96(self, block_id).await?;
let pool_key = self.pool_key();
let price = $crate::pool_viewers::v3::utils::calculate_price_from_sqrt_price_x96(
sqrt_price_x96,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
tracing::debug!(
price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()),
"Currency0 price calculated"
);
Ok(price)
}
#[tracing::instrument(skip(self), fields(pool_address = ?self.pool_address()))]
async fn currency1_price(
&self,
block_id: Option<alloy::eips::BlockId>,
) -> anyhow::Result<
uniswap_sdk_core::prelude::Price<
uniswap_sdk_core::prelude::Currency,
uniswap_sdk_core::prelude::Currency,
>,
> {
let price = self.currency0_price(block_id).await?.invert();
tracing::debug!(
price = %price.to_significant(8, None).unwrap_or_else(|_| "N/A".to_string()),
"Currency1 price calculated (inverted)"
);
Ok(price)
}
}
};
}
#[macro_export]
macro_rules! impl_v4_pool_viewer {
($struct_name:ident) => {
#[async_trait::async_trait]
impl $crate::traits::pool_viewer::PoolViewer for $struct_name {
async fn currency0_price(
&self,
block_id: Option<alloy::eips::BlockId>,
) -> anyhow::Result<
uniswap_sdk_core::prelude::Price<
uniswap_sdk_core::prelude::Currency,
uniswap_sdk_core::prelude::Currency,
>,
> {
let slot0 = self.slot0(block_id).await?;
tracing::debug!("Slot0 retrieved: {:?}", slot0);
let pool_key = self.pool_key();
let price = $crate::common::v4_utils::calculate_price_from_sqrt_price_x96(
slot0.0,
pool_key.token_a.clone(),
pool_key.token_b.clone(),
);
Ok(price)
}
async fn currency1_price(
&self,
block_id: Option<alloy::eips::BlockId>,
) -> anyhow::Result<
uniswap_sdk_core::prelude::Price<
uniswap_sdk_core::prelude::Currency,
uniswap_sdk_core::prelude::Currency,
>,
> {
let price = self.currency0_price(block_id).await?;
Ok(price.invert())
}
}
};
}