Skip to content

Commit b07e0ce

Browse files
committed
fix binary search results sorting
1 parent ef2f414 commit b07e0ce

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/swapService/strategies/strategyBalmySDK.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
getAddress,
2020
isAddress,
2121
isAddressEqual,
22-
maxUint256,
2322
parseAbiParameters,
2423
parseUnits,
2524
} from "viem"
@@ -368,7 +367,12 @@ export class StrategyBalmySDK {
368367

369368
if (bestQuotes.length === 0) throw new Error("Quotes not found")
370369

371-
return bestQuotes
370+
return bestQuotes.sort((qa: SwapQuote, qb: SwapQuote) => {
371+
// sort by lowest price out/in
372+
const a = (qa.amountIn * 10n ** 18n) / qa.amountOut
373+
const b = (qb.amountIn * 10n ** 18n) / qb.amountOut
374+
return Number(a > b) || -(a < b)
375+
})
372376
}
373377

374378
// async #binarySearchOverswapQuote(swapParams: SwapParams) {

0 commit comments

Comments
 (0)