getQuotes
Fetches quotes from all configured providers and simulates the quote transactions to validate the swap operation and the final token output amount.
Example
import { getQuotes } from "@spandex/core";
import { config } from "./config.js";
const quotes = await getQuotes({
config,
swap: {
chainId: 8453,
inputToken: "0x4200000000000000000000000000000000000006", // WETH
outputToken: "0xd9AAEC86B65D86f6A7B5B1b0c42FFA531710b6CA", // USDbC
mode: "exactIn",
inputAmount: 1_000_000_000_000_000_000n, // 1 WETH
slippageBps: 50, // Tolerance
swapperAccount: "0x1234567890abcdef1234567890abcdef12345678",
}
});
for (const quote of quotes) {
if (quote.success && quote.simulation.success) {
console.log(
`${quote.provider} yields ${quote.simulation.outputAmount}`
);
}
}
fabric yields 995000000n
odos yields 994500000n
Params
config
Config
Aggregator configuration object created via createConfig.
swap
SwapParams
Parameters defining the swap operation. See SwapParams reference for details.
client
PublicClient | undefined
Optional custom PublicClient to use for onchain simulations. If not provided, the configured clients in the config will be used.
Returns
Promise<SimulatedQuote[]>
List of simulated quotes from all providers. Each quote includes the provider name, raw quote data, and the simulated output amount after onchain validation. Quotes that fail simulation are denoted by success=false and include an error message. Simulation may also fail, due to a revert, etc. See SimulatedQuote for details.