@@ -170,21 +170,21 @@ impl Inner {
170170 . route ( native_price_request, self . max_hops )
171171 . await
172172 {
173- Ok ( Some ( route) ) => {
173+ Some ( route) if !route . is_empty ( ) => {
174174 // how many units of buy_token are bought for one unit of sell_token
175175 // (buy_amount / sell_amount).
176176 let price = self . native_token_price_estimation_amount . to_f64_lossy ( )
177- / route. input ( ) . amount . to_f64_lossy ( ) ;
177+ / route
178+ . input ( )
179+ . expect ( "route is not empty" )
180+ . amount
181+ . to_f64_lossy ( ) ;
178182 let Some ( price) = to_normalized_price ( price) else {
179183 continue ;
180184 } ;
181185
182186 auction:: Price ( eth:: Ether ( price) )
183187 }
184- Ok ( None ) => {
185- tracing:: info!( "Solving for sell=buy, price is 1" ) ;
186- auction:: Price ( eth:: Ether ( U256 :: one ( ) ) )
187- }
188188 _ => {
189189 // This is to allow quotes to be generated for tokens for which the sell
190190 // token price is not available, so we default to fee=0
@@ -196,48 +196,40 @@ impl Inner {
196196
197197 let compute_solution = async |request : Request | -> Option < Solution > {
198198 let wrappers = request. wrappers . clone ( ) ;
199- let route = boundary_solver. route ( request, self . max_hops ) . await . ok ( ) ?;
199+ let route = boundary_solver. route ( request, self . max_hops ) . await ?;
200200 let interactions;
201201 let gas;
202202 let ( input, mut output) ;
203203
204- match route {
205- Some ( route) => {
206- interactions = route
207- . segments
208- . iter ( )
209- . map ( |segment| {
210- solution:: Interaction :: Liquidity ( Box :: new (
211- solution:: LiquidityInteraction {
212- liquidity : segment. liquidity . clone ( ) ,
213- input : segment. input ,
214- output : segment. output ,
215- // TODO does the baseline solver know about this
216- // optimization?
217- internalize : false ,
218- } ,
219- ) )
220- } )
221- . collect ( ) ;
222- gas = route. gas ( ) + self . solution_gas_offset ;
223- input = route. input ( ) ;
224- output = route. output ( ) ;
225- }
226- None => {
227- interactions = Vec :: default ( ) ;
228- gas = eth:: Gas ( U256 :: zero ( ) ) + self . solution_gas_offset ;
229-
230- ( input, output) = match order. side {
231- order:: Side :: Sell => ( order. buy , order. sell ) ,
232- order:: Side :: Buy => ( order. sell , order. buy ) ,
233- } ;
234- let sell = order. sell ;
235- let buy = order. buy ;
236- tracing:: info!(
237- "Computing solution for sell=buy. input: {input:?} output: \
238- {output:?}, sell: {sell:?}, buy: {buy:?}"
239- ) ;
240- }
204+ if !route. is_empty ( ) {
205+ interactions = route
206+ . segments
207+ . iter ( )
208+ . map ( |segment| {
209+ solution:: Interaction :: Liquidity ( Box :: new (
210+ solution:: LiquidityInteraction {
211+ liquidity : segment. liquidity . clone ( ) ,
212+ input : segment. input ,
213+ output : segment. output ,
214+ // TODO does the baseline solver know about this
215+ // optimization?
216+ internalize : false ,
217+ } ,
218+ ) )
219+ } )
220+ . collect ( ) ;
221+ gas = route. gas ( ) + self . solution_gas_offset ;
222+ input = route. input ( ) . expect ( "route is not empty" ) ;
223+ output = route. output ( ) . expect ( "route is not empty" ) ;
224+ } else {
225+ interactions = Vec :: default ( ) ;
226+ gas = eth:: Gas ( U256 :: zero ( ) ) + self . solution_gas_offset ;
227+
228+ ( input, output) = match order. side {
229+ order:: Side :: Sell => ( order. sell , order. buy ) ,
230+ order:: Side :: Buy => ( order. buy , order. sell ) ,
231+ } ;
232+ output. amount = input. amount ;
241233 }
242234
243235 // The baseline solver generates a path with swapping
@@ -386,22 +378,20 @@ pub struct Segment<'a> {
386378}
387379
388380impl < ' a > Route < ' a > {
389- pub fn new ( segments : Vec < Segment < ' a > > ) -> Option < Self > {
390- if segments. is_empty ( ) {
391- return None ;
392- }
393- Some ( Self { segments } )
381+ pub fn new ( segments : Vec < Segment < ' a > > ) -> Self {
382+ Self { segments }
383+ }
384+
385+ fn input ( & self ) -> Option < eth:: Asset > {
386+ self . segments . first ( ) . map ( |segment| segment. input )
394387 }
395388
396- fn input ( & self ) -> eth:: Asset {
397- self . segments [ 0 ] . input
389+ fn output ( & self ) -> Option < eth:: Asset > {
390+ self . segments . last ( ) . map ( |segment| segment . output )
398391 }
399392
400- fn output ( & self ) -> eth:: Asset {
401- self . segments
402- . last ( )
403- . expect ( "route has at least one segment by construction" )
404- . output
393+ fn is_empty ( & self ) -> bool {
394+ self . segments . is_empty ( )
405395 }
406396
407397 fn gas ( & self ) -> eth:: Gas {
0 commit comments