Skip to content

Commit 81e8296

Browse files
committed
return empy results if provider is set
1 parent 9f4da6e commit 81e8296

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/api/routes/swap/swapRouter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ swapRouter.get(
124124
res,
125125
)
126126
} catch (error) {
127+
console.log("error: ", error)
127128
return handleServiceResponse(createFailureResponse(req, error), res)
128129
} finally {
129130
log("===== SWAPS END =====")

src/swapService/runner.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
93102
export 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

Comments
 (0)