Skip to main content

Quote a Trade

Use quoteMultiswapForSettlement to preview the accounting path that settlement will use, including available surplus behavior.

quoteMultiswap exposes the core reserve-only mechanism and is useful for analysis and benchmarks. It is not the preferred execution preview when surplus may affect settlement.

Build quote inputs

The quote ABI accepts packed Float values and the current state of every participating reserve asset.

type QuoteAmount = {
token: ReserveAsset;
amount: bigint; // packed Float
};

type QuoteAllocation = {
token: ReserveAsset;
allocation: bigint; // packed Float, 1.0 = 100%
minAmount: bigint; // packed Float
};

For a token amount expressed in base units:

amountFloat = bnToFloat(amount, tokenDecimals);

The reference UI represents quote allocations as 18-decimal fixed-point values before converting them to Float:

allocationFloat = bnToFloat(allocationWad); // 1e18 = 100%

Set quote-time minAmount to zero. Compute execution minimums from the returned quote.

Call the settlement quote

const result = await publicClient.readContract({
address: dispatcher,
abi: quoteAbi,
functionName: "quoteMultiswapForSettlement",
args: [pool, payQuoteAmounts, receiveQuoteAllocations],
});

The result contains:

payQuotes
receiveQuotes
feeQuotes
normalized receive allocations
priceOfUSD

Each QuoteItem exposes:

tokenAddress
reserves
surplus
rewards
treasury
valueChange
valueFlow

Convert receive output

For a receive quote, gross token amount is the absolute value of:

reserves + surplus + rewards + treasury

Convert the packed result to token base units with the asset’s decimals. The reference app uses floatToBn after applying the sign convention.

Protect the execution

For each receive asset:

minAmount = quotedAmount × (1 - slippageTolerance)

minAmount in the settlement ABI is an ordinary uint256 in token base units.

Ordering and freshness

Pay and receive legs are processed in order. Use deterministic ordering and submit against a recent quote. Requote when the pool state, target allocation, fee parameters, or block changes materially.