Docs

SDK

@plumb-oracle/sdk reads feeds from TypeScript, batches them with multicall, watches them live and sponsors them. Built on viem.

Install

npm i @plumb-oracle/sdk viem

The package is ready in the repository (packages/sdk) and is being published to npm. Until then, build it with npm run build:sdk.

Create a client

import { createPlumbClient } from "@plumb-oracle/sdk";

const plumb = createPlumbClient({ chain: "mainnet" });     // Elysium, chain 99901
const custom = createPlumbClient({ rpcUrl: "https://…" }); // your own RPC
const own = createPlumbClient({ publicClient });          // reuse a viem client

Addresses come with the package. Pass deployment to point at your own deployment, for example on a fork.

Read prices

const p = await plumb.getPrice("ETH/USD", { maxAgeSec: 3600 });
// { pair, answer: 170168000000n, decimals: 8, price: 1701.68,
//   roundId, updatedAt: Date, ageSec, stale: false }

const all = await plumb.getPrices();          // every pair, one multicall
const round = await plumb.getRound("ETH/USD", p.roundId);
const pairs = await plumb.pairs();             // from the on-chain registry

getPrice throws StalePriceError when the price is older than maxAgeSec, measured against the latest block. getPrices never throws on staleness; it sets stale on each result.

Watch a price

const stop = plumb.watchPrice("HYPE/USD", (p) => {
  console.log(p.price, p.ageSec);
}, { intervalMs: 3000, onError: console.error });

// React
import { usePlumbPrice } from "@plumb-oracle/sdk/react";
const { data, error, loading } = usePlumbPrice(plumb, "HYPE/USD");
const hash = await plumb.sponsor({
  walletClient,           // viem wallet client on Elysium
  pair: "HYPE/USD",
  periods: 3,             // 3 × 30 days
  protocolName: "Your protocol",
});
const list = await plumb.sponsors("HYPE/USD");

Same median, off-chain

import { aggregate } from "@plumb-oracle/sdk/offchain";
const a = await aggregate("BTC/USD");
// a.price (median), a.quotes per venue, a.hypercore, a.spreadBps

This is the exact code the signers run, so you can check any on-chain price against the sources yourself.

Solidity helper

using PlumbPriceLib for AggregatorV3Interface;

(uint256 price18, uint256 updatedAt) = feed.read(1 hours);      // reverts if stale
(uint256 p, uint256 t, bool stale) = feed.readRelaxed(1 hours); // never reverts on age

Normalises any feed to 18 decimals and reverts with StalePrice or NonPositivePrice. A full example lives in contracts/consumer/examples/ExampleLending.sol.

Errors

ErrorWhen
StalePriceErrorThe price is older than maxAgeSec.
UnknownPairErrorThe pair is not in the registry.
NotDeployedErrorNo addresses for this chain yet.
InvalidPriceErrorThe feed answered zero or a negative number.