d0fdd03357
- @switchboard-xyz/switchboardv2-cli@0.1.24 - @switchboard-xyz/sbv2-lite@0.1.4 - @switchboard-xyz/sbv2-utils@0.1.15 - @switchboard-xyz/switchboard-v2@0.0.102 - @switchboard-xyz/v2-feed-parser@0.1.3 - @switchboard-xyz/v2-feed-walkthrough@0.1.3 - @switchboard-xyz/lease-observer@0.1.4 - anchor-feed-parser@0.1.3 - anchor-vrf-parser@0.1.3 - spl-feed-parser@0.1.3 - @switchboard-xyz/eslint-config@0.1.1 - website@0.1.4 |
||
---|---|---|
.. | ||
src | ||
tests | ||
.gitignore | ||
.npmignore | ||
LICENSE | ||
README.md | ||
package.json | ||
tsconfig.cjs.json | ||
tsconfig.esm.json | ||
tsconfig.json |
README.md
Switchboard V2 Lite
A lightweight library to decode and parse aggregator accounts
Install
npm i @switchboard-xyz/sbv2-lite
Example
import SwitchboardProgram from "@switchboard-xyz/sbv2-lite";
//
const sbv2 = await SwitchboardProgram.loadDevnet();
// SOL_USD Aggregator https://switchboard.xyz/explorer
const solAggregator = new anchor.web3.PublicKey(
"GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
);
const accountInfo = await sbv2.program.provider.connection.getAccountInfo(
solAggregator
);
if (!accountInfo) {
throw new Error(`failed to fetch account info`);
}
// Get latest value if its been updated in the last 300 seconds
const latestResult = sbv2.decodeLatestAggregatorValue(accountInfo, 300);
if (latestResult === null) {
throw new Error(`failed to fetch latest result for aggregator`);
}
console.log(`latestResult: ${latestResult}`);
// latestResult: 105.673205