Skip to content

Commit

Permalink
fix: zero quote prioroty check
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Jan 23, 2025
1 parent 071f674 commit 4e6954c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/sdk-router/src/rfq/engine/priority.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Zero } from '@ethersproject/constants'

import { SupportedChainId } from '../../constants'
import { EngineID, SwapEngineQuote } from './swapEngine'

Expand Down Expand Up @@ -41,10 +43,16 @@ export const compareQuotesWithPriority = (
): SwapEngineQuote => {
const priorityA = getEnginePriority(quoteA.engineID, quoteA.chainId)
const priorityB = getEnginePriority(quoteB.engineID, quoteB.chainId)
if (priorityA === priorityB) {
return quoteA.expectedAmountOut.gt(quoteB.expectedAmountOut)
? quoteA
: quoteB
// Compare priorities only if both quotes have a non-zero amountOut.
if (
quoteA.expectedAmountOut.gt(Zero) &&
quoteB.expectedAmountOut.gt(Zero) &&
priorityA !== priorityB
) {
return priorityA > priorityB ? quoteA : quoteB
}
return priorityA > priorityB ? quoteA : quoteB
// Otherwise (same priority or at least one zero quote), compare amountOut.
return quoteA.expectedAmountOut.gte(quoteB.expectedAmountOut)
? quoteA
: quoteB
}

0 comments on commit 4e6954c

Please sign in to comment.