sbv2-solana/javascript/switchboard-v2
mgild 96e5ba4ebc v0.0.173 2022-12-02 01:32:48 -05:00
..
src version bumps 2022-12-01 11:48:10 -05:00
tests uprev switchboard deps 2022-11-26 15:15:13 -07:00
.gitignore solana.js: docs 2022-11-28 21:07:48 -07:00
.npmignore uprev switchboard deps 2022-11-26 15:15:13 -07:00
LICENSE uprev switchboard deps 2022-11-26 15:15:13 -07:00
README.md renamed repo to sbv2-solana 2022-12-01 10:17:17 -07:00
package-lock.json version bumps 2022-12-01 11:48:10 -05:00
package.json v0.0.173 2022-12-02 01:32:48 -05:00
tsconfig.base.json moved javascript packages to npm lock files 2022-11-28 20:23:34 -07:00
tsconfig.cjs.json uprev switchboard deps 2022-11-26 15:15:13 -07:00
tsconfig.json uprev switchboard deps 2022-11-26 15:15:13 -07:00

README.md

Switchboard-v2 API module

GitHub   npm   twitter  

A library of utility functions to interact with the Switchboardv2 program

Install

npm i @switchboard-xyz/switchboard-v2

Creating Feeds

import * as anchor from "@project-serum/anchor";
import { clusterApiUrl, Connection, Keypair, PublicKey } from "@solana/web3.js";
import {
  AggregatorAccount,
  OracleQueueAccount,
  loadSwitchboardProgram,
} from "@switchboard-xyz/switchboard-v2";

const payerKeypair = Keypair.fromSecretKey(
  JSON.parse(fs.readFileSync("../keypair-path.json", "utf-8"))
);
const program = await loadSwitchboardProgram(
  "devnet",
  new Connection(clusterApiUrl("devnet")),
  payerKeypair
);
const queueAccount = new OracleQueueAccount({
  program: program,
  // devnet permissionless queue
  publicKey: new PublicKey("F8ce7MsckeZAbAGmxjJNetxYXQa9mKr9nnrC3qKubyYy"),
});

const aggregatorAccount = await AggregatorAccount.create(program, {
  name: Buffer.from("FeedName"),
  batchSize: 6,
  minRequiredJobResults: 1,
  minRequiredOracleResults: 1,
  minUpdateDelaySeconds: 30,
  queueAccount,
});

Updating Feeds

import * as anchor from "@project-serum/anchor";
import {
  AggregatorAccount,
  OracleQueueAccount,
} from "@switchboard-xyz/switchboard-v2";

const program: anchor.Program;
const queueAccount: OracleQueueAccount;

await aggregatorAccount.openRound({
  oracleQueueAccount: queueAccount,
  payoutWallet: tokenAccount,
});

Reading Feeds

import { AggregatorAccount } from "@switchboard-xyz/switchboard-v2";
import { Big } from "big.js";

const aggregatorAccount: AggregatorAccount;
const result: Big = await aggregatorAccount.getLatestValue();

console.log(result.toNumber());