sbv2-solana/libraries/ts
gallynaut a979574ab4 v0.0.130 2022-09-01 12:57:35 -06:00
..
src added aptos.js docs 2022-09-01 03:25:53 -06:00
tests added test 2022-08-10 12:23:38 -06:00
.gitignore init 2022-05-17 10:42:04 -06:00
.npmignore library build scripts cleanup 2022-05-25 15:14:48 -06:00
LICENSE cleaned up package.json, tsconfig.json, and misc build configs 2022-05-25 12:38:29 -06:00
README.md init 2022-05-17 10:42:04 -06:00
package.json v0.0.130 2022-09-01 12:57:35 -06:00
tsconfig.base.json added aptos.js docs 2022-09-01 03:25:53 -06:00
tsconfig.cjs.json chore(tooling): simplified tsconfig and esm builds 2022-06-17 23:43:26 -06:00
tsconfig.json chore(tooling): simplified tsconfig and esm builds 2022-06-17 23:43:26 -06: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());