1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Common utilities for pool makers
use crate;
/// Check if an order range can be fulfilled based on restricted price range,
/// position tick range, and order side
///
/// This method checks if the current price (represented by restricted_range)
/// has crossed through the order range. An order range is fulfillable when:
/// - Buy order: current price has dropped through the order range
/// (restricted_range upper bound <= order upper bound)
/// - Sell order: current price has risen through the order range
/// (restricted_range lower bound >= order lower bound)
///
/// This checks if the entire order range has been crossed through by the
/// current price.
///
/// # Arguments
///
/// * `restricted_range` - The restricted price range representing current
/// market price
/// * `tick_lower` - Lower tick of the order range
/// * `tick_upper` - Upper tick of the order range
/// * `order_side` - Order side (Buy or Sell)
/// * `is_token_a_base` - Whether token A is the base currency (affects tick
/// direction)
///
/// # Returns
///
/// Returns `true` if the current price has crossed through the entire order
/// range:
/// - Buy orders: restricted_range upper bound has dropped to or below order
/// upper bound (restricted_range.tick_upper <= tick_upper)
/// - Sell orders: restricted_range lower bound has risen to or above order
/// lower bound (restricted_range.tick_lower >= tick_lower)
/// Check if an order range can be safely placed based on restricted price range
///
/// This method checks if the order range is outside the restricted price range,
/// which means it can be safely placed as a limit order without being
/// immediately filled.
///
/// An order range is placeable when:
/// - Buy order: the entire range is below the restricted range (can be placed
/// below current price)
/// - Sell order: the entire range is above the restricted range (can be placed
/// above current price)
///
/// # Arguments
///
/// * `restricted_range` - The restricted price range representing current
/// market price
/// * `tick_lower` - Lower tick of the order range
/// * `tick_upper` - Upper tick of the order range
/// * `order_side` - Order side (Buy or Sell)
/// * `is_token_a_base` - Whether token A is the base currency (affects tick
/// direction)
///
/// # Returns
///
/// Returns `true` if the order range can be safely placed:
/// - Buy orders: entire range is below restricted range (tick_upper <
/// restricted_range.tick_lower)
/// - Sell orders: entire range is above restricted range (tick_lower >=
/// restricted_range.tick_upper)