Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Nov 19, 2024
1 parent 3a2ad8f commit dd060b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/quoting/base_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ impl BasePool {
sorted_ticks,
}
}

pub fn get_sorted_ticks(&self) -> &Vec<Tick> {
&self.sorted_ticks
}
}

impl Pool for BasePool {
Expand Down
8 changes: 8 additions & 0 deletions src/quoting/limit_order_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub struct LimitOrderPoolState {
#[derive(Default, Clone, Copy)]
pub struct LimitOrderPoolResources {
pub base_pool_resources: BasePoolResources,
// the number of orders that were pulled, i.e. the number of times we crossed active ticks
// that were the end boundary of a position
pub orders_pulled: u32,
}

impl Add for LimitOrderPoolResources {
Expand All @@ -30,6 +33,7 @@ impl Add for LimitOrderPoolResources {
fn add(self, rhs: Self) -> Self::Output {
LimitOrderPoolResources {
base_pool_resources: self.base_pool_resources + rhs.base_pool_resources,
orders_pulled: self.orders_pulled + rhs.orders_pulled,
}
}
}
Expand Down Expand Up @@ -119,6 +123,8 @@ impl Pool for LimitOrderPool {
consumed_amount: result.consumed_amount,
execution_resources: LimitOrderPoolResources {
base_pool_resources: result.execution_resources,
// todo: calculate how many orders were pulled
orders_pulled: 0,
},
fees_paid: result.fees_paid,
is_price_increasing: result.is_price_increasing,
Expand Down Expand Up @@ -192,6 +198,7 @@ mod tests {
assert_eq!(quote.state_after.max_tick_index_after_swap, Some(None));
assert_eq!(quote.consumed_amount, 641);
assert_eq!(quote.calculated_amount, 639);
assert_eq!(quote.execution_resources.orders_pulled, 0);
assert_eq!(
quote
.execution_resources
Expand Down Expand Up @@ -264,6 +271,7 @@ mod tests {
assert_eq!(quote.state_after.max_tick_index_after_swap, Some(Some(2)));
assert_eq!(quote.consumed_amount, 1000);
assert_eq!(quote.calculated_amount, 997);
assert_eq!(quote.execution_resources.orders_pulled, 1);
assert_eq!(
quote
.execution_resources
Expand Down
53 changes: 31 additions & 22 deletions src/quoting/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,52 @@ mod tests {
approximate_number_of_tick_spacings_crossed, u256_to_float_base_x128,
};
use alloc::vec;
use alloc::vec::Vec;

#[test]
fn test_find_nearest_initialized_tick_index_no_ticks() {
let sorted_ticks: Vec<Tick> = vec![];
let result = find_nearest_initialized_tick_index(&sorted_ticks, 0);
assert_eq!(result, None);
assert_eq!(find_nearest_initialized_tick_index(&vec![], 0), None);
}

#[test]
fn test_find_nearest_initialized_tick_index_one_tick_less_than() {
let sorted_ticks = vec![Tick {
index: -1,
liquidity_delta: 1,
}];
let result = find_nearest_initialized_tick_index(&sorted_ticks, 0);
assert_eq!(result, Some(0));
assert_eq!(
find_nearest_initialized_tick_index(
&vec![Tick {
index: -1,
liquidity_delta: 1,
}],
0
),
Some(0)
);
}

#[test]
fn test_find_nearest_initialized_tick_index_one_tick_equal_to() {
let sorted_ticks = vec![Tick {
index: 0,
liquidity_delta: 1,
}];
let result = find_nearest_initialized_tick_index(&sorted_ticks, 0);
assert_eq!(result, Some(0));
assert_eq!(
find_nearest_initialized_tick_index(
&vec![Tick {
index: 0,
liquidity_delta: 1,
}],
0
),
Some(0)
);
}

#[test]
fn test_find_nearest_initialized_tick_index_one_tick_greater_than() {
let sorted_ticks = vec![Tick {
index: 1,
liquidity_delta: 1,
}];
let result = find_nearest_initialized_tick_index(&sorted_ticks, 0);
assert_eq!(result, None);
assert_eq!(
find_nearest_initialized_tick_index(
&vec![Tick {
index: 1,
liquidity_delta: 1,
}],
0
),
None
);
}

#[test]
Expand Down

0 comments on commit dd060b3

Please sign in to comment.