PriceLevels
Entry point for Titan's pAMM price levels. Wraps a snapshot source and exposes quote helpers, mirroring the structure of PropAmmRouter.
new PriceLevels(options?: PriceLevelsOptions)Usage
import { PriceLevels, PriceLevelsWsSource } from "propamm/prices";
import { USDC, WETH } from "propamm/common/tokens";
import { parseUnits } from "propamm/common/helpers";
// one-shot HTTP snapshot (default)
const prices = new PriceLevels();
const snapshot = await prices.getPriceLevels();
// live stream
const prices = new PriceLevels({
source: new PriceLevelsWsSource({ url: "wss://eu.rpc.titanbuilder.xyz/ws/pamm_price_levels" }),
});
const snapshot = await prices.getPriceLevels();
prices.close();Methods
getPriceLevels()
getPriceLevels(): Promise<PriceLevelsSnapshot | undefined>Latest price-level snapshot from the configured source.
Returns Promise<PriceLevelsSnapshot | undefined>.
getQuote()
getQuote(tokenIn: Address, tokenOut: Address, amountIn: bigint): Promise<TitanQuote>Best quote across all pAMMs for a size (titan_getPammQuote). Served from Titan's latest snapshot over HTTP, skipping the on-chain eth_call that router.quote runs.
Returns Promise<TitanQuote>. Throws on RPC error.
getQuoteVenue()
getQuoteVenue(venue: Address, tokenIn: Address, tokenOut: Address, amountIn: bigint): Promise<TitanQuote>Quote from a specific venue for a size (titan_getPammQuoteVenue).
Returns Promise<TitanQuote>. Throws on RPC error.
close()
close(): voidTear down the snapshot source. Closes the stream socket when the source is a PriceLevelsWsSource; no-op for PriceLevelsRpcSource.
Options
source (optional)
- Type:
PriceLevelsSource - Default:
new PriceLevelsRpcSource()
Source the snapshot is pulled from. Pass a PriceLevelsWsSource for a live stream.
rpcUrl (optional)
- Type:
string - Default:
https://rpc.titanbuilder.xyz
Titan JSON-RPC endpoint used by the quote helpers. Ignored when source is a PriceLevelsRpcSource (its URL is reused). Set this when pairing a PriceLevelsWsSource with a private or regional deployment so quotes go to the same host:
const prices = new PriceLevels({
source: new PriceLevelsWsSource({ url: "wss://us.rpc.titanbuilder.xyz/ws/pamm_price_levels" }),
rpcUrl: "https://us.rpc.titanbuilder.xyz",
});