Skip to content

Pricing and oracles

Read Pyth oracle prices between tokens and in USD.

sdk.pricing.getPrice returns the Pyth rate between two tokens as a Price, in smallest units with both tokens’ decimals already folded in, so onchain math can use it as is. getUsdPrice reads one token’s USD price the same way, and getUsdPrices batches a display read across many tokens, reporting each one as fresh, stale, or unavailable.

A price update is a signed payload the oracle contract needs before it reports a value. getOraclePriceUpdate fetches one from Pyth Hermes and getOraclePriceUpdateFee says what posting it costs. Workflows that depend on a price fetch and post the update for you.

Every method is on PricingModule. What a price means for collateral is in Vaults, collateral, and risk, and staleness is covered in Prices and the oracle.

USDC per whole WETH:

const { price, exponent } = await sdk.pricing.getPrice({
inputToken: WETH,
outputToken: USDC,
});
// price * 10**exponent = USDC smallest units per 1 wei; both tokens'
// decimals are already folded in, so on-chain math uses it as-is. Rescale
// by (18 - 6) only to show USDC per whole WETH.
const usdcPerWholeWeth =
Number(price) * 10 ** (Number(exponent) + 18 - 6);

Primary APIs

Interfaces

  • Price — A price between two tokens, in smallest units of the output token per smallest unit of the input token.
  • PricingModule — Price operations: Pyth token-pair and USD prices, the signed price updates that priced transactions carry, and the fees and freshness…