@@ -63,22 +63,31 @@ export async function runPipeline(
6363 StatusCodes . NOT_FOUND ,
6464 "Pipeline empty or result not found" ,
6565 )
66- if ( ! finalResult . quotes || finalResult . quotes . length === 0 ) {
66+
67+ // empty results when provider is set is a valid response
68+ if (
69+ ! finalResult . quotes ||
70+ ( finalResult . quotes . length === 0 && ! swapParams . provider )
71+ ) {
6772 throw new ApiError (
6873 StatusCodes . NOT_FOUND ,
6974 "Swap quote not found" ,
7075 allResults ,
7176 )
7277 }
7378
74- console . log ( {
75- name : "Best quote" ,
76- amountIn : finalResult . quotes [ 0 ] . amountIn ,
77- amountInMax : finalResult . quotes [ 0 ] . amountInMax ,
78- amountOut : finalResult . quotes [ 0 ] . amountOut ,
79- amountOutMin : finalResult . quotes [ 0 ] . amountOutMin ,
80- route : finalResult . quotes [ 0 ] . route ,
81- } )
79+ if ( finalResult . quotes . length ) {
80+ console . log ( {
81+ name : "Best quote" ,
82+ amountIn : finalResult . quotes [ 0 ] . amountIn ,
83+ amountInMax : finalResult . quotes [ 0 ] . amountInMax ,
84+ amountOut : finalResult . quotes [ 0 ] . amountOut ,
85+ amountOutMin : finalResult . quotes [ 0 ] . amountOutMin ,
86+ route : finalResult . quotes [ 0 ] . route ,
87+ } )
88+ } else {
89+ console . log ( "Empty results []" )
90+ }
8291 // console.log(
8392 // finalResult.quotes
8493 // .map((q) => q.route.map((r) => r.providerName).join(" "))
@@ -93,13 +102,14 @@ export async function runPipeline(
93102export async function findSwaps ( swapParams : SwapParams ) {
94103 // GLOBAL CHECKS
95104 let quotes = await runPipeline ( swapParams )
105+ const origQuoteLenght = quotes . length
96106
97107 // make sure verify item includes at least a function selector
98108 quotes = quotes . filter (
99109 ( q ) => isHex ( q . verify . verifierData ) && q . verify . verifierData . length >= 10 ,
100110 )
101111
102- if ( quotes . length === 0 )
112+ if ( origQuoteLenght > 0 && quotes . length === 0 )
103113 throw new ApiError ( StatusCodes . INTERNAL_SERVER_ERROR , "Invalid quotes" )
104114
105115 for ( const quote of quotes ) {
0 commit comments