Skip to content

Commit

Permalink
fix: No quote for exact output (#10691)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->


<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on fixing an issue in `@pancakeswap/routing-sdk` where
there was no quote for exact output.

### Detailed summary
- Replaced `Promise.all` with `Promise.allSettled` for better error
handling
- Improved error handling for rejected trades
- Updated debug logs and removed unnecessary console logs
- Enhanced validation for finding the best route

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
chefjackson authored Sep 18, 2024
1 parent 8e267e7 commit f2818f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-cougars-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pancakeswap/routing-sdk': patch
---

Fix an issue where there's no quote for exact output
14 changes: 5 additions & 9 deletions packages/routing-sdk/src/findBestTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ export async function findBestTradeByStreams(

// Exact output doesn't support mixed route
const poolsByType = groupPoolsByType(candidatePools)
const trades = await Promise.all(
const trades = await Promise.allSettled(
poolsByType.map((pools) => getBestTrade({ tradeType, candidatePools: pools, ...rest })),
)
let bestTrade: TradeWithGraph<TradeType> | undefined
for (const trade of trades) {
if (!trade) {
for (const result of trades) {
if (result.status === 'rejected' || !result.value) {
continue
}
const { value: trade } = result
if (!bestTrade) {
bestTrade = trade
continue
Expand Down Expand Up @@ -242,7 +243,7 @@ async function getBestTrade({

// DEBUG
// console.log(
// 'BestRoute: ',
// '[DEBUG ROUTE]: ',
// path
// .map((t) => {
// const v = graph.getVertice(t)
Expand Down Expand Up @@ -375,11 +376,6 @@ async function getBestTrade({
for (const { amount, percent } of amounts) {
// eslint-disable-next-line no-await-in-loop
const route = await findBestRoute(amount)
// console.log(
// 'Route -> ',
// route?.inputAmount.currency.symbol,
// route?.outputAmount.currency.symbol,
// );
invariant(
route !== undefined,
`No valid route found for base amount ${amount.toExact()} ${amount.currency.symbol} and quote currency ${
Expand Down

0 comments on commit f2818f6

Please sign in to comment.