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

getPricing

Extract pricing metadata from list of quotes to produce usd price estimates for input and output tokens.

Example

import { getPricing, getRawQuotes } from "@spandex/core";
import { config } from "./config.js";
 
const quotes = await getRawQuotes({
  config,
  swap: {
    chainId: 8453,
    inputToken: "0x4200000000000000000000000000000000000006",
    outputToken: "0xd9AAEC86B65D86f6A7B5B1b0c42FFA531710b6CA",
    mode: "exactIn",
    inputAmount: 1_000_000_000_000_000_000n,
    slippageBps: 50,
    swapperAccount: "0x1234567890abcdef1234567890abcdef12345678",
  },
});
 
const pricing = getPricing(quotes);
 
console.log(pricing.sources);
console.log(pricing.inputToken?.usdPrice, pricing.outputToken?.usdPrice);

Params

quotes

Quote[]

Quotes to summarize. Failed quotes and quotes without pricing metadata are ignored.

Returns

PricingSummary

Aggregated pricing summary including averaged USD prices and contributing providers.