sbv2-solana/javascript/solana.js
Jackson Jessup 913f51fbc3 @switchboard-xyz/switchboard-v2 --> 0.0.139 2022-10-28 14:53:40 -04:00
..
src fix string decoding 2022-10-28 14:11:05 -04:00
tests removed monorepo structure 2022-09-28 14:37:26 -06:00
.gitignore ignore yarn bs 2022-10-28 14:16:56 -04:00
.npmignore removed monorepo structure 2022-09-28 14:37:26 -06:00
LICENSE removed monorepo structure 2022-09-28 14:37:26 -06:00
README.md removed monorepo structure 2022-09-28 14:37:26 -06:00
package.json @switchboard-xyz/switchboard-v2 --> 0.0.139 2022-10-28 14:53:40 -04:00
tsconfig.base.json removed monorepo structure 2022-09-28 14:37:26 -06:00
tsconfig.cjs.json removed monorepo structure 2022-09-28 14:37:26 -06:00
tsconfig.json removed monorepo structure 2022-09-28 14:37:26 -06:00
yarn.lock ignore yarn bs 2022-10-28 14:16:56 -04: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());