Skip to content

Commit

Permalink
fix: lookup of smart router quotes (#920)
Browse files Browse the repository at this point in the history
* fix: lookup of smart router quotes

* fix: failing tests

* fix: add types
  • Loading branch information
creed-victor authored May 22, 2024
1 parent 865976c commit a53308e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-avocados-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sovryn/sdk': patch
---

fix: smart router lookup
26 changes: 18 additions & 8 deletions packages/sdk/src/swaps/smart-router/smart-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,24 @@ export class SmartRouter {
destination,
);

const quotes = await Promise.all(
routes.map(async route => {
const quote = await route.quote(entry, destination, amount).catch();
if (!quote) {
return { route, quote: BigNumber.from(0) };
}
return { route, quote };
}),
const quotes = await Promise.allSettled(
routes.map(route =>
route
.quote(entry, destination, amount)
.then(quote => ({ route, quote })),
),
).then(results =>
results
.filter(result => result.status === 'fulfilled')
.map(
result =>
(
result as PromiseFulfilledResult<{
route: SwapRoute;
quote: BigNumber;
}>
).value,
),
);

const sortedQuotes = quotes.sort((a, b) =>
Expand Down

0 comments on commit a53308e

Please sign in to comment.