Skip to content

Commit 82c452b

Browse files
authored
Merge pull request #13 from SorellaLabs/feat/l2-factory
feat: l2 factory
2 parents fefc242 + 83c0a58 commit 82c452b

5 files changed

Lines changed: 154 additions & 46 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ jobs:
134134
${{ runner.os }}-cargo-
135135
136136
- name: Run integration tests
137-
run: cargo test --features integration
137+
run: cargo test -p uni-v4
138138
env:
139139
SKIP_INTEGRATION_TESTS: false

crates/uni-v4-structure/src/fee_config.rs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub struct L2FeeConfiguration {
2424
pub protocol_tax_fee_e6: u32,
2525
pub creator_swap_fee_e6: u32,
2626
pub protocol_swap_fee_e6: u32,
27-
pub priority_fee_tax_floor: u128
27+
pub priority_fee_tax_floor: u128,
28+
pub jit_tax_enabled: bool,
29+
pub withdraw_only: bool
2830
}
2931

3032
pub trait FeeConfig:
@@ -49,6 +51,10 @@ pub trait FeeConfig:
4951
/// - L2: swap_fee (0) + protocol_fee (creator + protocol swap fees)
5052
fn fee(&self, bundle: bool) -> u32;
5153

54+
fn priority_fee_tax_floor(&self) -> u128 {
55+
0
56+
}
57+
5258
fn update_fees(&mut self, update: Self::Update);
5359

5460
/// Calculate MEV tax given a priority fee in wei.
@@ -110,21 +116,26 @@ impl FeeConfig for L2FeeConfiguration {
110116
self.swap_fee() + self.protocol_fee()
111117
}
112118

113-
fn update_fees(&mut self, update: Self::Update) {
114-
let Self::Update { protocol_tax_fee_e6, protocol_swap_fee_e6, priority_fee_tax_floor } =
115-
update;
119+
fn priority_fee_tax_floor(&self) -> u128 {
120+
self.priority_fee_tax_floor
121+
}
116122

117-
if let Some(fee) = protocol_tax_fee_e6 {
123+
fn update_fees(&mut self, update: Self::Update) {
124+
if let Some(fee) = update.protocol_tax_fee_e6 {
118125
self.protocol_tax_fee_e6 = fee;
119126
}
120-
121-
if let Some(fee) = protocol_swap_fee_e6 {
127+
if let Some(fee) = update.protocol_swap_fee_e6 {
122128
self.protocol_swap_fee_e6 = fee;
123129
}
124-
125-
if let Some(floor) = priority_fee_tax_floor {
130+
if let Some(floor) = update.priority_fee_tax_floor {
126131
self.priority_fee_tax_floor = floor;
127132
}
133+
if let Some(enabled) = update.jit_tax_enabled {
134+
self.jit_tax_enabled = enabled;
135+
}
136+
if let Some(wo) = update.withdraw_only {
137+
self.withdraw_only = wo;
138+
}
128139
}
129140

130141
fn mev_tax(&self, priority_fee_wei: u128) -> u128 {
@@ -148,7 +159,9 @@ pub struct L1FeeUpdate {
148159
pub struct L2FeeUpdate {
149160
pub protocol_tax_fee_e6: Option<u32>,
150161
pub protocol_swap_fee_e6: Option<u32>,
151-
pub priority_fee_tax_floor: Option<u128>
162+
pub priority_fee_tax_floor: Option<u128>,
163+
pub jit_tax_enabled: Option<bool>,
164+
pub withdraw_only: Option<bool>
152165
}
153166

154167
#[cfg(test)]
@@ -162,7 +175,9 @@ mod tests {
162175
protocol_tax_fee_e6: 2000,
163176
creator_swap_fee_e6: 3000,
164177
protocol_swap_fee_e6: 4000,
165-
priority_fee_tax_floor: floor
178+
priority_fee_tax_floor: floor,
179+
jit_tax_enabled: false,
180+
withdraw_only: false
166181
}
167182
}
168183

@@ -210,7 +225,9 @@ mod tests {
210225
cfg.update_fees(L2FeeUpdate {
211226
protocol_tax_fee_e6: None,
212227
protocol_swap_fee_e6: None,
213-
priority_fee_tax_floor: Some(42)
228+
priority_fee_tax_floor: Some(42),
229+
jit_tax_enabled: None,
230+
withdraw_only: None
214231
});
215232
assert_eq!(cfg.priority_fee_tax_floor, 42);
216233
}
@@ -221,7 +238,9 @@ mod tests {
221238
cfg.update_fees(L2FeeUpdate {
222239
protocol_tax_fee_e6: Some(9999),
223240
protocol_swap_fee_e6: None,
224-
priority_fee_tax_floor: None
241+
priority_fee_tax_floor: None,
242+
jit_tax_enabled: None,
243+
withdraw_only: None
225244
});
226245
assert_eq!(cfg.priority_fee_tax_floor, 100);
227246
assert_eq!(cfg.protocol_tax_fee_e6, 9999);
@@ -233,10 +252,14 @@ mod tests {
233252
cfg.update_fees(L2FeeUpdate {
234253
protocol_tax_fee_e6: Some(111),
235254
protocol_swap_fee_e6: Some(222),
236-
priority_fee_tax_floor: Some(333)
255+
priority_fee_tax_floor: Some(333),
256+
jit_tax_enabled: Some(true),
257+
withdraw_only: Some(true)
237258
});
238259
assert_eq!(cfg.protocol_tax_fee_e6, 111);
239260
assert_eq!(cfg.protocol_swap_fee_e6, 222);
240261
assert_eq!(cfg.priority_fee_tax_floor, 333);
262+
assert!(cfg.jit_tax_enabled);
263+
assert!(cfg.withdraw_only);
241264
}
242265
}

crates/uni-v4-structure/src/l2/pool_updates.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub enum L2PoolUpdate {
1717
tick_spacing: i32,
1818
hook: Address,
1919
block: u64,
20-
priority_fee_tax_floor: u128
20+
priority_fee_tax_floor: u128,
21+
jit_tax_enabled: bool,
22+
withdraw_only: bool
2123
}
2224
}
2325

crates/uni-v4-upkeeper/src/l2/pool_manager_service.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use alloy_primitives::aliases::{I24, U24};
12
use alloy_provider::Provider;
23
use futures::Stream;
34
use op_alloy_network::Optimism;
45
use uni_v4_common::PoolUpdate;
56
use uni_v4_structure::{
6-
L2FeeConfiguration, PoolId, l2_structure::pool_updates::L2PoolUpdate,
7-
pool_registry::PoolRegistry, pool_updates::Slot0Update
7+
L2FeeConfiguration, PoolId, PoolKey, l2_structure::pool_updates::L2PoolUpdate,
8+
pool_updates::Slot0Update
89
};
910

1011
use crate::{
@@ -26,32 +27,41 @@ where
2627
match update {
2728
L2PoolUpdate::NewPool {
2829
pool_id,
30+
token0,
31+
token1,
32+
hook,
33+
hook_fee,
34+
tick_spacing,
2935
block,
3036
creator_tax_fee_e6,
3137
protocol_tax_fee_e6,
3238
creator_swap_fee_e6,
3339
protocol_swap_fee_e6,
3440
priority_fee_tax_floor,
41+
jit_tax_enabled,
42+
withdraw_only,
3543
..
3644
} => {
3745
if self.auto_pool_creation {
46+
let pool_key = PoolKey {
47+
currency0: *token0,
48+
currency1: *token1,
49+
fee: U24::from(*hook_fee),
50+
tickSpacing: I24::unchecked_from(*tick_spacing),
51+
hooks: *hook
52+
};
3853
let fee_cfg = L2FeeConfiguration {
3954
is_initialized: true,
4055
creator_tax_fee_e6: *creator_tax_fee_e6,
4156
protocol_tax_fee_e6: *protocol_tax_fee_e6,
4257
creator_swap_fee_e6: *creator_swap_fee_e6,
4358
protocol_swap_fee_e6: *protocol_swap_fee_e6,
44-
priority_fee_tax_floor: *priority_fee_tax_floor
59+
priority_fee_tax_floor: *priority_fee_tax_floor,
60+
jit_tax_enabled: *jit_tax_enabled,
61+
withdraw_only: *withdraw_only
4562
};
46-
// Reconstruct pool_key from the NewPool data
47-
// We need to get the pool_key from the registry
48-
if let Some(pool_key) = self.factory.registry().get(pool_id) {
49-
self.handle_new_pool(*pool_key, *block, fee_cfg);
50-
51-
tracing::info!("Pool configured: {pool_id:?}:\n{fee_cfg:?}",);
52-
} else {
53-
tracing::warn!("Pool {:?} not found in registry", pool_id);
54-
}
63+
self.handle_new_pool(pool_key, *block, fee_cfg);
64+
tracing::info!("Pool configured: {pool_id:?}:\n{fee_cfg:?}");
5565
} else {
5666
tracing::info!(
5767
"Ignoring pool configured event (auto creation disabled): {:?}",

0 commit comments

Comments
 (0)