SV3 logo

tradePriceImpact

Uniswap-style curve and total price impact for a trade quote.

priceImpact = (spotOutput − actualOutput) / spotOutput

Worse is positive. Computed twice: fee-exclusive curve leg and user total (gross in / net out). Quote helpers already attach this object — you rarely call the function yourself.

The on-chain ABI field priceImpactWad is not this. It is abs(spotAfter − spotBefore), exported here as spotPriceDeltaWad.

Borrow, repay, deposit, withdraw, surrender, donate, claims, and floor raises must set priceImpact: null, not zero. Quote helpers already do that.

Import

import { tradePriceImpact } from "@repo/contract-client/math";

Usage

import { tradePriceImpact } from "@repo/contract-client/math";

const impact = tradePriceImpact({
  kind: "buyExactReserveIn",
  curveReserveInRaw: quote.curveReserveInRaw,
  grossReserveInRaw: quote.grossReserveInRaw,
  avmOut: quote.avmOut,
  spotBefore: snapshot.spotPriceWad,
  spotAfter: quote.nextSpotPriceWad,
  floorPriceWad: snapshot.floorPriceWad,
});

impact.curvePriceImpactWad;
impact.feeImpactWad;
impact.totalPriceImpactWad;
impact.spotPriceDeltaWad;

Redeem forces curve impact to 0 (spot does not move).

Return Value

TradePriceImpact

FieldMeaning
curveExecutionPriceWadAverage price of the curve leg
effectiveExecutionPriceWadAverage price including fees
spotPriceWadBefore / AfterSpot pin
spotPriceDeltaWadabs(after − before) — ABI priceImpactWad
spotMovePercentWadDelta as a fraction of spot before
curvePriceImpactWadUniswap-style, fee exclusive
feeImpactWadtotal − curve
totalPriceImpactWadUniswap-style, user gross/net

Parameters

params.kind

  • Type: 'buyExactReserveIn' \| 'buyExactAvmOut' \| 'sellExactAvmIn' \| 'sellExactReserveOut' \| 'redeemAtFloor'
tradePriceImpact({ kind: 'buyExactReserveIn', … })

params.spotBefore

  • Type: bigint

Pre-trade spot WAD. Must be > 0.

params.spotAfter

  • Type: bigint

Post-trade spot WAD.

params.floorPriceWad

  • Type: bigint

Used for redeem execution price.

Amount fields

Pass the legs that kind needs: curveReserveInRaw, grossReserveInRaw, grossReserveOutRaw, netReserveOutRaw, feesTotalRaw, avmIn, avmOut.

Error

InvalidAmountError if spot is 0 or a required amount is 0.

Tips

  • Show totalPriceImpactWad in the ticket. Show spotPriceDeltaWad only if you are matching an on-chain event field.