@@ -19,110 +19,152 @@ fn new_sim_value_too_low(original_sim: U256, new_sim: U256) -> bool {
19
19
new_sim * U256 :: from ( 100 ) < ( original_sim * U256 :: from ( MIN_SIM_RESULT_PERCENTAGE ) )
20
20
}
21
21
22
- // @TODO: Make macro!
23
-
24
- ///////////////////////////////
25
- /// MevGasPrice
26
- ///////////////////////////////
27
-
28
- #[ derive( Debug , Clone ) ]
29
- pub struct OrderMevGasPricePriority {
30
- order : Arc < SimulatedOrder > ,
22
+ macro_rules! create_order_priority {
23
+ ( $order_priority: ident( $cmp: ident $( , $next_cmp: ident ) * ) <$new_sim_value_too_low_func: ident>) => {
24
+ #[ derive( Debug , Clone ) ]
25
+ pub struct $order_priority {
26
+ order: Arc <SimulatedOrder >,
27
+ }
28
+
29
+ impl OrderPriority for $order_priority {
30
+ fn new( order: Arc <SimulatedOrder >) -> Self {
31
+ Self { order }
32
+ }
33
+
34
+ fn simulation_too_low(
35
+ original_sim_value: & SimValue ,
36
+ new_sim_value: & SimValue ,
37
+ ) -> bool {
38
+ $new_sim_value_too_low_func(
39
+ original_sim_value,
40
+ new_sim_value,
41
+ )
42
+ }
43
+ }
44
+
45
+ impl PartialEq for $order_priority {
46
+ fn eq( & self , other: & Self ) -> bool {
47
+ $cmp:: eq( & self . order, & other. order)
48
+ }
49
+ }
50
+
51
+ impl Eq for $order_priority { }
52
+
53
+ impl PartialOrd for $order_priority {
54
+ fn partial_cmp( & self , other: & Self ) -> Option <std:: cmp:: Ordering > {
55
+ Some ( self . cmp( other) )
56
+ }
57
+ }
58
+
59
+ impl Ord for $order_priority {
60
+ fn cmp( & self , other: & Self ) -> std:: cmp:: Ordering {
61
+ $cmp:: cmp( & self . order, & other. order)
62
+ $( . then_with( || $next_cmp:: cmp( & self . order, & other. order) ) ) *
63
+ }
64
+ }
65
+ } ;
31
66
}
32
67
33
- impl OrderPriority for OrderMevGasPricePriority {
34
- fn new ( order : Arc < SimulatedOrder > ) -> Self {
35
- Self { order }
68
+ /// MevGasPrice
69
+ struct OrderMevGasPricePriorityCmp { }
70
+ impl OrderMevGasPricePriorityCmp {
71
+ #[ inline]
72
+ fn eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
73
+ a. sim_value . mev_gas_price == b. sim_value . mev_gas_price
36
74
}
37
75
38
- fn simulation_too_low ( original_sim_value : & SimValue , new_sim_value : & SimValue ) -> bool {
39
- new_sim_value_too_low (
40
- original_sim_value. mev_gas_price ,
41
- new_sim_value. mev_gas_price ,
42
- )
76
+ #[ inline]
77
+ fn cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
78
+ a. sim_value . mev_gas_price . cmp ( & b. sim_value . mev_gas_price )
43
79
}
44
80
}
45
-
46
- #[ inline]
47
- fn mev_gas_price_eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
48
- a. sim_value . mev_gas_price == b. sim_value . mev_gas_price
49
- }
50
-
51
81
#[ inline]
52
- fn mev_gas_price_cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
53
- a. sim_value . mev_gas_price . cmp ( & b. sim_value . mev_gas_price )
54
- }
55
-
56
- impl PartialEq for OrderMevGasPricePriority {
57
- fn eq ( & self , other : & Self ) -> bool {
58
- mev_gas_price_eq ( & self . order , & other. order )
59
- }
60
- }
61
-
62
- impl Eq for OrderMevGasPricePriority { }
63
-
64
- impl PartialOrd for OrderMevGasPricePriority {
65
- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
66
- Some ( self . cmp ( other) )
67
- }
82
+ fn simulation_too_low_gas_price ( original_sim_value : & SimValue , new_sim_value : & SimValue ) -> bool {
83
+ new_sim_value_too_low (
84
+ original_sim_value. mev_gas_price ,
85
+ new_sim_value. mev_gas_price ,
86
+ )
68
87
}
69
88
70
- impl Ord for OrderMevGasPricePriority {
71
- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
72
- mev_gas_price_cmp ( & self . order , & other. order )
73
- }
74
- }
75
-
76
- ///////////////////////////////
77
89
/// MaxProfit
78
- ///////////////////////////////
79
-
80
- #[ derive( Debug , Clone ) ]
81
- pub struct OrderMaxProfitPriority {
82
- order : Arc < SimulatedOrder > ,
83
- }
84
-
85
- impl OrderPriority for OrderMaxProfitPriority {
86
- fn new ( order : Arc < SimulatedOrder > ) -> Self {
87
- Self { order }
90
+ struct OrderMaxProfitPriorityCmp { }
91
+ impl OrderMaxProfitPriorityCmp {
92
+ #[ inline]
93
+ fn eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
94
+ a. sim_value . coinbase_profit == b. sim_value . coinbase_profit
88
95
}
89
96
90
- fn simulation_too_low ( original_sim_value : & SimValue , new_sim_value : & SimValue ) -> bool {
91
- new_sim_value_too_low (
92
- original_sim_value . coinbase_profit ,
93
- new_sim_value . coinbase_profit ,
94
- )
97
+ # [ inline ]
98
+ fn cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
99
+ a . sim_value
100
+ . coinbase_profit
101
+ . cmp ( & b . sim_value . coinbase_profit )
95
102
}
96
103
}
97
-
98
104
#[ inline]
99
- fn max_profit_eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
100
- a. sim_value . coinbase_profit == b. sim_value . coinbase_profit
101
- }
102
-
103
- #[ inline]
104
- fn max_profit_cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
105
- a. sim_value
106
- . coinbase_profit
107
- . cmp ( & b. sim_value . coinbase_profit )
108
- }
105
+ fn simulation_too_low_profit ( original_sim_value : & SimValue , new_sim_value : & SimValue ) -> bool {
106
+ new_sim_value_too_low (
107
+ original_sim_value. coinbase_profit ,
108
+ new_sim_value. coinbase_profit ,
109
+ )
110
+ }
111
+
112
+ /// OrderType
113
+ /// Prioritizes Bundles over Mempool
114
+ struct OrderTypeCmp { }
115
+ impl OrderTypeCmp {
116
+ #[ inline]
117
+ fn eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
118
+ a. order . is_tx ( ) == b. order . is_tx ( )
119
+ }
109
120
110
- impl PartialEq for OrderMaxProfitPriority {
111
- fn eq ( & self , other : & Self ) -> bool {
112
- max_profit_eq ( & self . order , & other. order )
121
+ #[ inline]
122
+ fn cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
123
+ let a_is_tx = a. order . is_tx ( ) ;
124
+ let b_is_tx = b. order . is_tx ( ) ;
125
+ if a_is_tx == b_is_tx {
126
+ Ordering :: Equal
127
+ } else if a_is_tx {
128
+ //*a_is_tx && !b_is_tx
129
+ Ordering :: Less
130
+ } else {
131
+ //*!a_is_tx && b_is_tx
132
+ Ordering :: Greater
133
+ }
113
134
}
114
135
}
115
136
116
- impl Eq for OrderMaxProfitPriority { }
137
+ /// Prioritizes orders with 3 or more txs
138
+ struct OrderLengthThreeCmp { }
139
+ impl OrderLengthThreeCmp {
140
+ #[ inline]
141
+ fn is_long ( a : & SimulatedOrder ) -> bool {
142
+ a. order . list_txs_len ( ) >= 3
143
+ }
117
144
118
- impl PartialOrd for OrderMaxProfitPriority {
119
- fn partial_cmp ( & self , other : & Self ) -> Option < std :: cmp :: Ordering > {
120
- Some ( self . cmp ( other ) )
145
+ # [ inline ]
146
+ fn eq ( a : & SimulatedOrder , b : & SimulatedOrder ) -> bool {
147
+ Self :: is_long ( a ) == Self :: is_long ( b )
121
148
}
122
- }
123
149
124
- impl Ord for OrderMaxProfitPriority {
125
- fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
126
- max_profit_cmp ( & self . order , & other. order )
150
+ #[ inline]
151
+ fn cmp ( a : & SimulatedOrder , b : & SimulatedOrder ) -> Ordering {
152
+ let a_is_long = Self :: is_long ( a) ;
153
+ let b_is_long = Self :: is_long ( b) ;
154
+ if a_is_long == b_is_long {
155
+ Ordering :: Equal
156
+ } else if a_is_long {
157
+ //*a_is_long && !b_is_long
158
+ Ordering :: Greater
159
+ } else {
160
+ //*!a_is_long && b_is_long
161
+ Ordering :: Less
162
+ }
127
163
}
128
164
}
165
+
166
+ create_order_priority ! ( OrderMevGasPricePriority ( OrderMevGasPricePriorityCmp ) <simulation_too_low_gas_price>) ;
167
+ create_order_priority ! ( OrderMaxProfitPriority ( OrderMaxProfitPriorityCmp ) <simulation_too_low_profit>) ;
168
+ create_order_priority ! ( OrderTypePriority ( OrderTypeCmp , OrderMaxProfitPriorityCmp ) <simulation_too_low_profit>) ;
169
+ create_order_priority ! ( OrderLengthThreeMaxProfitPriority ( OrderLengthThreeCmp , OrderMaxProfitPriorityCmp ) <simulation_too_low_profit>) ;
170
+ create_order_priority ! ( OrderLengthThreeMevGasPricePriority ( OrderLengthThreeCmp , OrderMevGasPricePriorityCmp ) <simulation_too_low_profit>) ;
0 commit comments