sbv2-solana/javascript/sbv2-lite
gallynaut 7feef95406
chore: pull monorepo changes (#170)
* Project import generated by Copybara.

GitOrigin-RevId: a54f824c1816bcedee95284afd276aaa37a98d80

* fix

* chore: Update pnpm lockfile

---------

Co-authored-by: Copybara <copybara@example.com>
Co-authored-by: gallynaut <gallynaut@users.noreply.github.com>
2023-11-28 10:43:30 -07:00
..
src chore: pull monorepo changes (#114) 2023-07-31 11:17:09 -05:00
tests chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
.gitignore chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
.npmignore chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
LICENSE chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
README.md chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
package.json chore: pull monorepo changes (#170) 2023-11-28 10:43:30 -07:00
tsconfig.base.json chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
tsconfig.cjs.json chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00
tsconfig.json chore: pull monorepo changes (#113) 2023-07-31 10:26:58 -05:00

README.md

Switchboard V2 Lite

A lightweight library to decode and parse aggregator accounts

npm   twitter  

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