Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

prepareQuotes

Prepare a list of swap quote promise chains for quote fetching and secondary actions such as simulation. This is useful when custom behavior is required, such as racing quotes+simulation for multiple providers.

Example

getQuotes
import { prepareQuotes, type Quote } from "@spandex/core";
import { config } from "./config.ts";
 
// Identity fn
async function mapFn(quote: Quote): Promise<Quote> {
  return quote;
}
 
const promises = await prepareQuotes({
  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",
  },
  mapFn,
});

Params

config

Config

Aggregator configuration object created via createConfig.

swap

SwapParams

Parameters defining the swap operation. See SwapParams reference for details.

mapFn

(quote: Quote) => Promise<T>

Function that maps each fetched quote to a promise of type T. This allows for custom processing of each quote, such as simulation or other enrichment. Identity function is also valid.

Returns

Array<Promise<T>>

List of promises, each resolving to type T as defined by the mapFn.