use alloy_chains::NamedChain;
use alloy_primitives::BlockNumber;
use alloy_provider::Provider;
use alloy_rpc_types::{Filter, Log};
use crate::config::SemioscanConfig;
use crate::errors::PriceCalculationError;
use crate::price::PriceSource;
use crate::scan::LogScanner;
pub(crate) struct SwapLogScanner<'a, P> {
provider: &'a P,
chain: NamedChain,
config: SemioscanConfig,
filter: Filter,
}
impl<'a, P: Provider + Clone> SwapLogScanner<'a, P> {
pub fn new(
provider: &'a P,
chain: NamedChain,
price_source: &dyn PriceSource,
config: SemioscanConfig,
) -> Self {
let filter = Filter::new()
.address(price_source.router_address())
.event_signature(price_source.event_topics());
Self {
provider,
chain,
config,
filter,
}
}
pub async fn scan(
&self,
start: BlockNumber,
end: BlockNumber,
) -> Result<Vec<Log>, PriceCalculationError> {
let scanner = LogScanner::new(self.provider, self.config.clone());
scanner
.scan::<PriceCalculationError, _>(
self.chain,
self.filter.clone(),
start,
end,
|_, _, _| None,
)
.await
}
}