@squadswapdefi/oracle-sdk
v0.2.0
Published
TypeScript SDK for reading price feeds from the Squad Oracle Network. Chainlink-compatible, Chainlink AggregatorV3 interface under the hood.
Maintainers
Readme
@squadswapdefi/oracle-sdk
TypeScript SDK for reading price feeds from the Squad Oracle Network.
Under the hood each feed exposes the standard Chainlink AggregatorV3Interface, so if you already integrate Chainlink you can point your existing code at the per-feed adapter address and be done. This SDK is a thin convenience wrapper on top of that: multi-feed listing, pair-name lookup, staleness helpers, and typed results.
Install
npm install @squadswapdefi/oracle-sdk ethers
# or
pnpm add @squadswapdefi/oracle-sdk ethers
# or
yarn add @squadswapdefi/oracle-sdk ethersethers v6 is a peer of this SDK — installing it keeps the bundle tight.
Quick start
import { SquadOracle } from "@squadswapdefi/oracle-sdk";
const oracle = new SquadOracle(
"0xF799d1ebc55B6FD1896714b92852a49b87461fB0", // BNB Chain oracle address
"https://bsc-dataseed.binance.org"
);
// Fetch a single feed
const xmr = await oracle.getPrice("XMR/USD");
console.log(`XMR/USD: $${xmr.priceUsd} (round #${xmr.roundId})`);
// List everything the oracle exposes
const feeds = await oracle.listFeeds();
for (const f of feeds) {
console.log(f.pair, "→", f.feedId);
}
// Subscribe to updates with explicit error handling. Without `onError`,
// transient RPC failures used to be silently swallowed by an empty catch —
// supplying it lets you surface banners / retry / unsubscribe yourself.
// The polling loop never stops on error: the next interval re-attempts.
const stop = oracle.onPriceUpdate("XMR/USD", p => render(p), {
intervalMs: 5_000,
onError: e => console.warn("price poll failed:", e),
});
// Legacy signature `onPriceUpdate(pair, cb, 5000)` still works.What you get back
interface PriceData {
price: bigint; // Raw on-chain value (decimals-aware)
priceUsd: number; // Decimal-adjusted number for quick display
timestamp: number; // When the round was posted (seconds since epoch)
roundId: number; // Monotonically increasing round counter
updatedAt: number; // Same as timestamp for this oracle
isStale: boolean; // True if adapter's staleness window has expired
}Drop-in Chainlink compatibility
If you prefer the raw Chainlink interface (no SDK), point the aggregator address at the per-feed adapter and use the standard interface — works in any Solidity project:
import { AggregatorV3Interface } from
"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract MyConsumer {
AggregatorV3Interface immutable oracle;
constructor(address adapter) {
oracle = AggregatorV3Interface(adapter);
}
function latestPrice() external view returns (int256) {
(, int256 price, , uint256 updatedAt, ) = oracle.latestRoundData();
require(block.timestamp - updatedAt < 2 hours, "stale");
return price; // 8 decimals, matching Chainlink convention
}
}Per-feed adapter addresses are listed on the dashboard.
Deployed networks
| Chain | Status | Oracle | Registry |
|-------|--------|--------|----------|
| BNB Chain (56) | ✅ Active | 0xF799d1ebc55B6FD1896714b92852a49b87461fB0 | 0xbc2D232c35B876d903FEce4a6a37AB81d088e12F |
| Ethereum | 🔜 Coming soon | — | — |
Links
License
MIT
