Skip to content

Commit

Permalink
fix: jupiter more accurate price impact (#8566)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeOMakinG authored Jan 14, 2025
1 parent c414093 commit c239295
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const getTradeQuote = async (
affiliateBps,
receiveAddress,
slippageTolerancePercentageDecimal,
priceImpactPercentageDecimal: priceResponse.priceImpactPct,
steps: [
{
accountNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const getTradeRate = async (
receiveAddress,
potentialAffiliateBps: affiliateBps,
affiliateBps,
priceImpactPercentageDecimal: priceResponse.priceImpactPct,
slippageTolerancePercentageDecimal,
steps: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ type TradeQuoteBase = {
potentialAffiliateBps: string // even if the swapper does not support affiliateBps, we need to zero-them out or view-layer will be borked
affiliateBps: string // even if the swapper does not support affiliateBps, we need to zero-them out or view-layer will be borked
isStreaming?: boolean
priceImpactPercentageDecimal?: string
slippageTolerancePercentageDecimal: string | undefined // undefined if slippage limit is not provided or specified by the swapper
isLongtail?: boolean
quoteOrRate: 'quote' | 'rate'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const usePriceImpact = (tradeQuote: TradeQuote | TradeRate | undefined) =
const priceImpactPercentage = useMemo(() => {
if (!tradeQuote || !buyAsset || !buyAssetUsdRate || !sellAmountBeforeFeesUsd) return

if (tradeQuote.priceImpactPercentageDecimal) {
return bnOrZero(tradeQuote.priceImpactPercentageDecimal).times(100).abs()
}

// price impact calculation must use buyAmountBeforeFees because it relates to the liquidity in
// the pool rather than a rate of input versus output

Expand Down

0 comments on commit c239295

Please sign in to comment.