createConfig
Create a configuration object to customize providers and options for all aggregation functions.
import { createConfig, fabric, kyberswap, odos, zeroX } from "@spandex/core";
export const config = createConfig({
providers: [
zeroX({ apiKey: "YOUR_0X_API_KEY" }),
fabric({ appId: "YOUR_FABRIC_APP_ID" }),
odos({}),
kyberswap({ clientId: "YOUR_KYBER_CLIENT_ID" }),
],
options: {
deadlineMs: 10000,
numRetries: 2,
initialRetryDelayMs: 200,
integratorFeeAddress: "0xFee000",
integratorSwapFeeBps: 25,
},
clients: [
baseClient,
mainnetClient
] as PublicClient[],
});Proxy configuration
Use a proxy when fetching quotes from a server (for example, to avoid browser CORS issues).
import { createConfig, proxy } from "@spandex/core";
import { createPublicClient, http, type PublicClient } from "viem";
import { base } from "viem/chains";
const client = createPublicClient({
chain: base,
transport: http("https://base.drpc.org"),
});
export const config = createConfig({
proxy: proxy({ pathOrUrl: "https://example.com/api/quotes" }),
clients: [client] as PublicClient[],
});Params
providers
Aggregator[]
List of active provider aggregators. Each provider has a factory function that returns an
Aggregator instance with its configuration. You can include multiple instances for the same
provider to test alternate configurations.
| Factory | API Key Required? | Config Docs |
|---|---|---|
zeroX | yes | View |
fabric | no | View |
kyberswap | no | View |
odos | no | View |
lifi | no | View |
relay | no | View |
Example:
import { fabric, zeroX } from "@spandex/core";
const providers = [
zeroX({
apiKey: "YOUR_0X_API_KEY",
timeoutMs: 12_000,
negotiatedFeatures: ["integratorFees"],
}),
fabric({
appId: "YOUR_FABRIC_APP_ID",
}),
];proxy
AggregatorProxy
Proxy instance used to delegate quote fetching to a server endpoint. When proxy is set, you cannot
set providers or options in the same config.
Example:
import { createConfig, proxy } from "@spandex/core";
const config = createConfig({
proxy: proxy({ pathOrUrl: "https://example.com/api/quotes" }),
});options (optional)
AggregationOptions
options.deadlineMs
number | undefined
Maximum duration for the entire aggregation process before aborting pending requests. Defaults to 15,000 ms. Set a lower value for faster responses with potentially fewer quotes.
options.numRetries
number | undefined
Number of retry attempts per provider. Defaults to 1.
options.initialRetryDelayMs
number | undefined
Initial delay before retrying failed requests (exponential backoff applied). Defaults to 100 ms.
options.integratorFeeAddress
Address | undefined
Address that should receive the integrator fee. Use this if your application collects fees on swaps from end users. Only applicable if the provider supports integrator fees. Some providers may require a custom API key tied to your integrator fee address.
options.integratorSwapFeeBps
number | undefined
Swap fee for the integrator (in basis points). Only applicable if the provider supports integrator fees.
options.integratorSurplusBps
number | undefined
Surplus share for the integrator (in basis points). Only applicable if the provider supports surplus sharing.
clients (optional)
PublicClient[] | ((chainId: number) => PublicClient | undefined)
A list of viem/wagmi clients or a lookup function to get the client for a specific chain ID. This is used to fetch on-chain data for quote simulation and validation. If not provided, getQuotes, getQuote, and simulation utilities will fail. If you wish to only get quotes without validating onchain, use getRawQuotes instead. When using SpandexProvider, the wagmi clients from the provider will be used automatically.
Returns
Config
Aggregator configuration object to be passed to aggregation functions.