---
title: tradePriceImpact
description: Uniswap-style curve and total price impact for a trade quote.
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

```text
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

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

## Usage

```ts
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`

| Field                          | Meaning                                      |
| ------------------------------ | -------------------------------------------- |
| `curveExecutionPriceWad`       | Average price of the curve leg               |
| `effectiveExecutionPriceWad`   | Average price including fees                 |
| `spotPriceWadBefore` / `After` | Spot pin                                     |
| `spotPriceDeltaWad`            | `abs(after − before)` — ABI `priceImpactWad` |
| `spotMovePercentWad`           | Delta as a fraction of spot before           |
| `curvePriceImpactWad`          | Uniswap-style, fee exclusive                 |
| `feeImpactWad`                 | `total − curve`                              |
| `totalPriceImpactWad`          | Uniswap-style, user gross/net                |

## Parameters

### params.kind

- **Type:** `'buyExactReserveIn' \| 'buyExactAvmOut' \| 'sellExactAvmIn' \| 'sellExactReserveOut' \| 'redeemAtFloor'`

```ts
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.
