diff --git a/crates/artemis-core/src/collectors/block_collector.rs b/crates/artemis-core/src/collectors/block_collector.rs index 5b71642..e94968a 100644 --- a/crates/artemis-core/src/collectors/block_collector.rs +++ b/crates/artemis-core/src/collectors/block_collector.rs @@ -4,13 +4,13 @@ use async_trait::async_trait; use ethers::{ prelude::Middleware, providers::PubsubClient, - types::{H256, U64}, + types::{Block, TxHash}, }; use std::sync::Arc; use tokio_stream::StreamExt; /// A collector that listens for new blocks, and generates a stream of -/// [events](NewBlock) which contain the block number and hash. +/// [events](NewBlock) which contain the entire block pub struct BlockCollector { provider: Arc, } @@ -18,8 +18,7 @@ pub struct BlockCollector { /// A new block event, containing the block number and hash. #[derive(Debug, Clone)] pub struct NewBlock { - pub hash: H256, - pub number: U64, + pub block: Block, } impl BlockCollector { @@ -39,10 +38,7 @@ where { async fn get_event_stream(&self) -> Result> { let stream = self.provider.subscribe_blocks().await?; - let stream = stream.filter_map(|block| match block.hash { - Some(hash) => block.number.map(|number| NewBlock { hash, number }), - None => None, - }); + let stream = stream.filter_map(|block| Some(NewBlock { block })); Ok(Box::pin(stream)) } } diff --git a/crates/artemis-core/tests/main.rs b/crates/artemis-core/tests/main.rs index 52fbe47..bb55ffe 100644 --- a/crates/artemis-core/tests/main.rs +++ b/crates/artemis-core/tests/main.rs @@ -35,7 +35,7 @@ async fn test_block_collector_sends_blocks() { .await .unwrap() .unwrap(); - assert_eq!(block_a.hash, block_b.hash.unwrap()); + assert_eq!(block_a.block.hash.unwrap(), block_b.hash.unwrap()); } /// Test that mempool collector correctly emits blocks. diff --git a/crates/strategies/opensea-sudo-arb/src/strategy.rs b/crates/strategies/opensea-sudo-arb/src/strategy.rs index c8939fb..ae7b19a 100644 --- a/crates/strategies/opensea-sudo-arb/src/strategy.rs +++ b/crates/strategies/opensea-sudo-arb/src/strategy.rs @@ -156,14 +156,20 @@ impl OpenseaSudoArb { /// Process new block events, updating the internal state. async fn process_new_block_event(&mut self, event: NewBlock) -> Result<()> { - info!("processing new block {}", event.number); + info!("processing new block {}", event.block.number.unwrap()); // Find new pools tthat were created in the last block. let new_pools = self - .get_new_pools(event.number.as_u64(), event.number.as_u64()) + .get_new_pools( + event.block.number.unwrap().as_u64(), + event.block.number.unwrap().as_u64(), + ) .await?; // Find existing pools that were touched in the last block. let touched_pools = self - .get_touched_pools(event.number.as_u64(), event.number.as_u64()) + .get_touched_pools( + event.block.number.unwrap().as_u64(), + event.block.number.unwrap().as_u64(), + ) .await?; // Get quotes for all new and touched pools and update state. let quotes = self