Skip to content

Commit 1b2efeb

Browse files
committed
Use new active index lookup functions
1 parent e6e5041 commit 1b2efeb

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

pallets/swap/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ where
10401040
/// Get fees above a tick
10411041
///
10421042
fn get_fees_above(&mut self, tick_index: TickIndex, quote: bool) -> U64F64 {
1043-
let maybe_tick_index = tick_index.find_closest_lower_active(&self.state_ops);
1043+
let maybe_tick_index = self.find_closest_lower_active_tick_index(tick_index);
10441044
let current_tick = self.get_current_tick_index();
10451045

10461046
if let Some(tick_index) = maybe_tick_index {
@@ -1072,7 +1072,7 @@ where
10721072

10731073
/// Get fees below a tick
10741074
fn get_fees_below(&mut self, tick_index: TickIndex, quote: bool) -> U64F64 {
1075-
let maybe_tick_index = tick_index.find_closest_lower_active(&self.state_ops);
1075+
let maybe_tick_index = self.find_closest_lower_active_tick_index(tick_index);
10761076
let current_tick = self.get_current_tick_index();
10771077

10781078
if let Some(tick_index) = maybe_tick_index {

pallets/swap/src/tick.rs

-48
Original file line numberDiff line numberDiff line change
@@ -373,54 +373,6 @@ impl TickIndex {
373373
}
374374
}
375375
}
376-
377-
/// Find the closest lower active tick index
378-
pub fn find_closest_lower_active<Ops, AccountIdType>(&self, ops: &Ops) -> Option<Self>
379-
where
380-
AccountIdType: Eq,
381-
Ops: SwapDataOperations<AccountIdType>,
382-
{
383-
// TODO: Implement without iteration
384-
let mut current_index = *self;
385-
loop {
386-
if current_index.get() < Self::MIN.get() {
387-
return None;
388-
}
389-
if ops.get_tick_by_index(current_index).is_some() {
390-
return Some(current_index);
391-
}
392-
393-
// Create a new index with value one less
394-
match current_index.prev() {
395-
Ok(next_index) => current_index = next_index,
396-
Err(_) => return None, // Return None if we go out of bounds
397-
}
398-
}
399-
}
400-
401-
/// Find the closest higher active tick index
402-
pub fn find_closest_higher_active<Ops, AccountIdType>(&self, ops: &Ops) -> Option<Self>
403-
where
404-
AccountIdType: Eq,
405-
Ops: SwapDataOperations<AccountIdType>,
406-
{
407-
// TODO: Implement without iteration
408-
let mut current_index = *self;
409-
loop {
410-
if current_index.get() > Self::MAX.get() {
411-
return None;
412-
}
413-
if ops.get_tick_by_index(current_index).is_some() {
414-
return Some(current_index);
415-
}
416-
417-
// Create a new index with value one more
418-
match current_index.next() {
419-
Ok(next_index) => current_index = next_index,
420-
Err(_) => return None, // Return None if we go out of bounds
421-
}
422-
}
423-
}
424376
}
425377

426378
/// A bitmap representation of a tick index position across the three-layer structure

0 commit comments

Comments
 (0)