Trade Previews
Structured preview helpers for estimating output, fees, price impact, and post-trade reserves before you build.
SDK
Quote first, build second
The preview surface is designed for quoting and execution workflows. It answers the questions integrations actually need: how much comes in, how much goes out, what the fee is, and how much the trade moves the market.
Curve previews use the Curve fee policy and the same checked cash-flow calculations as the amount helpers.
import { DumpsterClient } from '@dumpster-cash/dumpster-sdk';
const client = new DumpsterClient(connection);Units and price impact
Preview rates and transaction slippage use different units:
| Value | Unit | Example |
|---|---|---|
fees.*FeeBps and fees.totalFeeBps | Rate per 100,000 | 950 means 0.95% |
priceImpactBps | Basis points, per 10,000 | 100 means 1% |
Builder slippage | Percentage | 1 means 1% |
priceImpactBps measures an absolute price difference relative to the pre-trade spot price, rounded down to whole basis points. It has no direction sign.
Curve buys compare post-trade spot against pre-trade spot. Curve sells and both AMM directions compare execution against pre-trade spot. Execution includes buy fees or uses net sell proceeds. These measurements are not interchangeable estimates of reserve movement or limits on a later fill.
prices contains exact ratios in asset base units; apply mint decimals when displaying token prices. See fee helpers for fee selection and rounding.
In SDK 2.0.0 and 2.0.1, price impact remains a JavaScript number. Extreme reserve ratios can exceed its safe conversion range and make a preview throw even when the integer amount helper can quote the trade. Treat that as unavailable, not as a zero-price quote.
Curve buy preview
Start here when the user enters a GOR trade budget. Fetch the paired Curve state before calling this pure preview.
import BN from 'bn.js';
const preview = client.preview.curveBuy({
feeConfig,
bondingCurve,
amountInGor: new BN(1_000_000_000),
});Key fields:
preview.amountOutTokens-> token output after feespreview.amountInGor-> actual fee-inclusive trade cost, which can be less than the budgetpreview.amountInNetGor-> fee-exclusive principal added to the curvepreview.fees.feeAmountGor-> sum of independently rounded protocol and applicable creator feespreview.priceImpactBps-> change between post-trade and pre-trade reserve spot pricespreview.postTradeReserves-> virtual reserves after applying principal and token output
The result selects the greatest affordable token output within sale inventory. A zero/no-affordable-output budget returns zero spend, fees and output with unchanged reserves; do not build a buy instruction from it. Positive output equal to remaining inventory completes the sale.
Curve buy preview by target output
Choose this path when the target token output is known and the missing number is the required GOR input.
const preview = client.preview.curveBuyExactOut({
feeConfig,
bondingCurve,
amountOutTokens: new BN(25_000_000_000),
});Key fields:
preview.amountInGor-> total GOR input requiredpreview.amountInNetGor-> GOR that actually reaches the curve after feespreview.amountOutTokens-> exact token output being targeted
Curve sell preview
Start here when the user enters a token amount to sell.
const preview = client.preview.curveSell({
feeConfig,
bondingCurve,
amountInTokens: new BN(25_000_000_000),
});Key fields:
preview.amountOutGorGross-> output before feespreview.amountOutGorNet-> output after feespreview.fees.feeAmountGor-> estimated fee amountpreview.priceImpactBps-> net execution price difference from the pre-trade spot price
Gross output floors virtualGorReserves * amountInTokens / (virtualTokenReserves + amountInTokens). Post-trade virtual GOR reserves decrease by that gross amount, not the net estimate.
This matches the Curve sell calculation. The preview rejects completed state, invalid amounts, insufficient recorded liquidity, overflowing reserves and fee underflow. A valid zero-net sell remains a visible zero-GOR result, distinct from a thrown quote error. Other account/wallet checks can still prevent execution; choose a positive minimum if zero payout is unacceptable.
AMM buy preview
This preview answers the exact-output AMM buy question: how much quote does this output actually cost?
const preview = client.preview.swapBuy({
feeConfig,
pool,
baseReserves,
quoteReserves,
baseMintSupply,
baseAmountOut: new BN(5_000_000_000),
});Key fields:
preview.quoteAmountForSwap-> quote amount consumed by the pool before feespreview.quoteAmountInTotal-> total spend including feespreview.fees.totalFeeAmount-> total fee charged on the quote sidepreview.priceImpactBps-> fee-inclusive execution price difference from the pre-trade spot price
AMM buy preview by total quote input
This preview answers the exact-input AMM buy question: how much base output fits inside a total quote budget?
const preview = client.preview.swapBuyExactIn({
feeConfig,
pool,
baseReserves,
quoteReserves,
baseMintSupply,
quoteAmountInTotal: new BN(1_000_000_000),
});Key fields:
preview.baseAmountOut-> token output that fits inside the total quote budgetpreview.quoteAmountInTotal-> total quote input used for the previewpreview.fees.totalFeeAmount-> total fee charged on the quote sidepreview.priceImpactBps-> fee-inclusive execution price difference from the pre-trade spot price
AMM sell preview
Start here when the sell size is known up front.
const preview = client.preview.swapSell({
feeConfig,
pool,
baseReserves,
quoteReserves,
baseMintSupply,
baseAmountIn: new BN(5_000_000_000),
});Key fields:
preview.quoteAmountOutGross-> quote output before feespreview.quoteAmountOutNet-> final output after feespreview.priceImpactBps-> net execution price difference from the pre-trade spot price
When the math helpers still make sense
The raw math helpers still exist for simulations, tests, and analytics. For quoting and transaction building, the preview surface is usually better because it keeps amounts, fees, impact, and post-trade state together.
Previews still require fresh state
Use Global, FeeConfig and Curve from the same trade-state bundle. A failed refresh makes the quote unavailable even when a cache retains earlier data. Successful cached state is still a dated estimate; transaction preparation should fetch again. Quote cost excludes network fees and account deposits, and a slippage allowance is not an absolute wallet spending cap.