From 1516a1bf9bead1d6fd0599c911570aa4eb495825 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:25:49 +0200 Subject: [PATCH] handle SOR's effective price when outputAmount is 0 (#916) --- .changeset/six-pans-rhyme.md | 5 +++++ modules/sor/sorV2/sorPathService.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/six-pans-rhyme.md diff --git a/.changeset/six-pans-rhyme.md b/.changeset/six-pans-rhyme.md new file mode 100644 index 000000000..0e5f75b2f --- /dev/null +++ b/.changeset/six-pans-rhyme.md @@ -0,0 +1,5 @@ +--- +'backend': patch +--- + +handle SOR's effective price when outputAmount is 0 diff --git a/modules/sor/sorV2/sorPathService.ts b/modules/sor/sorV2/sorPathService.ts index a057d6632..a7407f9c9 100644 --- a/modules/sor/sorV2/sorPathService.ts +++ b/modules/sor/sorV2/sorPathService.ts @@ -330,7 +330,7 @@ class SorPathService implements SwapService { const returnAmount = swapKind === SwapKind.GivenIn ? outputAmount : inputAmount; const swapAmount = swapKind === SwapKind.GivenIn ? inputAmount : outputAmount; - const effectivePrice = inputAmount.divDownFixed(outputAmount.scale18); + const effectivePrice = outputAmount.amount > 0 ? inputAmount.divDownFixed(outputAmount.scale18) : Infinity; const effectivePriceReversed = outputAmount.divDownFixed(inputAmount.scale18); return { @@ -348,7 +348,13 @@ class SorPathService implements SwapService { swapAmountRaw: swapAmount.amount.toString(), returnAmount: formatUnits(returnAmount.amount, returnAmount.token.decimals), returnAmountRaw: returnAmount.amount.toString(), - effectivePrice: formatUnits(effectivePrice.amount, effectivePrice.token.decimals), + effectivePrice: + effectivePrice === Infinity + ? 'Infinity' + : formatUnits( + (effectivePrice as TokenAmount).amount, + (effectivePrice as TokenAmount).token.decimals, + ), effectivePriceReversed: formatUnits(effectivePriceReversed.amount, effectivePriceReversed.token.decimals), routes: this.mapRoutes(paths, pools), priceImpact: {