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.
import { DumpsterClient } from '@dumpster-cash/dumpster-sdk';
const client = new DumpsterClient(connection);Curve buy preview
Start here when the user enters a GOR spend amount.
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.fees.feeAmountGor-> fee amount charged on the tradepreview.priceImpactBps-> how far the execution moves from the pre-trade spot pricepreview.postTradeReserves-> the next virtual reserve state if the trade lands
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-> fee amount charged on the trade
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 side
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-> market movement implied by that spend
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-> execution movement vs 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
The preview helpers are only as good as the state you feed into them. Fetch fresh curve or pool reserves before building the final transaction.