Skip to content

Commit 1ab83d6

Browse files
authored
Merge pull request #572 from SorellaLabs/jonas/feat/uniswap-v4-generics
feat(op-anstrom): uniswap v4 generic types
2 parents 5373942 + e48520c commit 1ab83d6

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/angstrom/src/components.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ where
335335
init_telemetry(signer_addr, grace_shutdown)
336336
});
337337

338-
let uniswap_pool_manager = configure_uniswap_manager::<_, DEFAULT_TICKS>(
338+
let uniswap_pool_manager = configure_uniswap_manager::<_, EthPrimitives, DEFAULT_TICKS>(
339339
querying_provider.clone(),
340340
eth_handle.subscribe_cannon_state_notifications().await,
341341
uniswap_registry,

bin/op-angstrom/src/components.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ use angstrom_types::{
3535
reth_db_wrapper::RethDbWrapper,
3636
submission::SubmissionHandler
3737
};
38-
use consensus::{AngstromValidator, ConsensusManager, ManagerNetworkDeps};
38+
use consensus::AngstromValidator;
3939
use futures::Stream;
4040
use matching_engine::{MatchingManager, manager::MatcherCommand};
4141
use order_pool::{PoolConfig, PoolManagerUpdate, order_storage::OrderStorage};
42-
use parking_lot::RwLock;
4342
use reth::{
4443
api::NodeAddOns,
4544
builder::FullNodeComponents,
@@ -296,7 +295,7 @@ where
296295
init_telemetry(signer_addr, grace_shutdown)
297296
});
298297

299-
let uniswap_pool_manager = configure_uniswap_manager::<_, DEFAULT_TICKS>(
298+
let uniswap_pool_manager = configure_uniswap_manager::<_, OpPrimitives, DEFAULT_TICKS>(
300299
querying_provider.clone(),
301300
eth_handle.subscribe_cannon_state_notifications().await,
302301
uniswap_registry,

crates/uniswap-v4/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ itertools.workspace = true
2323
malachite.workspace = true
2424
rand.workspace = true
2525
rayon = "1"
26+
reth-node-builder.workspace = true
27+
reth-primitives.workspace = true
2628
reth-provider.workspace = true
2729
serde.workspace = true
2830
telemetry-recorder.workspace = true

crates/uniswap-v4/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use angstrom_types::{
1717
};
1818
use futures::Stream;
1919
use rayon::iter::{IntoParallelIterator, ParallelIterator};
20+
use reth_node_builder::NodePrimitives;
2021
use reth_provider::{
2122
CanonStateNotifications, DatabaseProviderFactory, ReceiptProvider, StateProvider,
2223
TryIntoHistoricalStateProvider
@@ -119,16 +120,20 @@ where
119120
.collect::<Vec<_>>()
120121
}
121122

122-
pub async fn configure_uniswap_manager<BlockSync: BlockSyncConsumer, const TICKS: u16>(
123+
pub async fn configure_uniswap_manager<
124+
BlockSync: BlockSyncConsumer,
125+
N: NodePrimitives,
126+
const TICKS: u16
127+
>(
123128
provider: Arc<impl Provider + 'static>,
124-
state_notification: CanonStateNotifications,
129+
state_notification: CanonStateNotifications<N>,
125130
uniswap_pool_registry: UniswapPoolRegistry,
126131
current_block: BlockNumber,
127132
block_sync: BlockSync,
128133
pool_manager_address: Address,
129134
update_stream: Pin<Box<dyn Stream<Item = EthEvent> + Send + Sync>>
130135
) -> UniswapPoolManager<
131-
CanonicalStateAdapter<impl Provider + 'static>,
136+
CanonicalStateAdapter<impl Provider + 'static, N>,
132137
impl Provider + 'static,
133138
BlockSync,
134139
TICKS
@@ -139,8 +144,11 @@ pub async fn configure_uniswap_manager<BlockSync: BlockSyncConsumer, const TICKS
139144
pool_manager_address
140145
);
141146

142-
let notifier =
143-
Arc::new(CanonicalStateAdapter::new(state_notification, provider.clone(), current_block));
147+
let notifier = Arc::new(CanonicalStateAdapter::<_, N>::new(
148+
state_notification,
149+
provider.clone(),
150+
current_block
151+
));
144152

145153
UniswapPoolManager::new(factory, current_block, notifier, block_sync, update_stream).await
146154
}

crates/uniswap-v4/src/uniswap/pool_providers/canonical_state_adapter.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@ use alloy::{
1111
rpc::types::{Filter, FilterBlockOption}
1212
};
1313
use futures_util::StreamExt;
14+
use reth_node_builder::NodePrimitives;
15+
use reth_primitives::EthPrimitives;
1416
use reth_provider::CanonStateNotification;
1517
use tokio::sync::broadcast;
1618

1719
use super::PoolMangerBlocks;
1820
use crate::uniswap::{pool_manager::PoolManagerError, pool_providers::PoolManagerProvider};
1921

20-
pub struct CanonicalStateAdapter<P>
22+
pub struct CanonicalStateAdapter<P, N = EthPrimitives>
2123
where
22-
P: Provider + 'static
24+
P: Provider + 'static,
25+
N: NodePrimitives
2326
{
24-
canon_state_notifications: broadcast::Receiver<CanonStateNotification>,
27+
canon_state_notifications: broadcast::Receiver<CanonStateNotification<N>>,
2528
last_logs: Arc<RwLock<Vec<Log>>>,
2629
last_block_number: Arc<AtomicU64>,
2730
node_provider: Arc<P>
2831
}
2932

30-
impl<P> Clone for CanonicalStateAdapter<P>
33+
impl<P, N> Clone for CanonicalStateAdapter<P, N>
3134
where
32-
P: Provider + 'static
35+
P: Provider + 'static,
36+
N: NodePrimitives
3337
{
3438
fn clone(&self) -> Self {
3539
Self {
@@ -41,12 +45,13 @@ where
4145
}
4246
}
4347

44-
impl<P> CanonicalStateAdapter<P>
48+
impl<P, N> CanonicalStateAdapter<P, N>
4549
where
46-
P: Provider + 'static
50+
P: Provider + 'static,
51+
N: NodePrimitives
4752
{
4853
pub fn new(
49-
canon_state_notifications: broadcast::Receiver<CanonStateNotification>,
54+
canon_state_notifications: broadcast::Receiver<CanonStateNotification<N>>,
5055
node_provider: Arc<P>,
5156
block_number: u64
5257
) -> Self {
@@ -59,9 +64,10 @@ where
5964
}
6065
}
6166

62-
impl<P> PoolManagerProvider for CanonicalStateAdapter<P>
67+
impl<P, N> PoolManagerProvider for CanonicalStateAdapter<P, N>
6368
where
64-
P: Provider + 'static
69+
P: Provider + 'static,
70+
N: NodePrimitives
6571
{
6672
fn provider(&self) -> Arc<impl Provider> {
6773
self.node_provider.clone()
@@ -81,11 +87,12 @@ where
8187

8288
let logs: Vec<Log> = new
8389
.execution_outcome()
84-
.logs(block.number)
90+
.logs(block.number())
8591
.map_or_else(Vec::new, |logs| logs.cloned().collect());
8692
*last_log_write = logs;
87-
this.last_block_number.store(block.number, Ordering::SeqCst);
88-
tracing::info!(?block.number,"updated number");
93+
this.last_block_number
94+
.store(block.number(), Ordering::SeqCst);
95+
tracing::info!(number = ?block.number(), "updated number");
8996
Some(Some(PoolMangerBlocks::NewBlock(block.number())))
9097
}
9198
CanonStateNotification::Reorg { old, new } => {
@@ -122,9 +129,10 @@ where
122129
}
123130

124131
*last_log_write = logs;
125-
this.last_block_number.store(block.number, Ordering::SeqCst);
126-
tracing::info!(?block.number,"updated number");
127-
Some(Some(PoolMangerBlocks::Reorg(block.number, range)))
132+
this.last_block_number
133+
.store(block.number(), Ordering::SeqCst);
134+
tracing::info!(number = ?block.number(), "updated number");
135+
Some(Some(PoolMangerBlocks::Reorg(block.number(), range)))
128136
}
129137
};
130138
Some((block, notifications))
@@ -152,9 +160,10 @@ where
152160
}
153161
}
154162

155-
impl<P> CanonicalStateAdapter<P>
163+
impl<P, N> CanonicalStateAdapter<P, N>
156164
where
157-
P: Provider + 'static
165+
P: Provider + 'static,
166+
N: NodePrimitives
158167
{
159168
fn validate_filter(&self, filter: &Filter) -> Result<(), PoolManagerError> {
160169
let last_block = self.last_block_number.load(Ordering::SeqCst);

0 commit comments

Comments
 (0)