Socket
Socket
Sign inDemoInstall

@switchboard-xyz/switchboard-v2

Package Overview
Dependencies
8
Maintainers
5
Versions
220
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @switchboard-xyz/switchboard-v2

API wrapper for intergating with the Switchboardv2 program


Version published
Weekly downloads
4.1K
increased by12.6%
Maintainers
5
Created
Weekly downloads
 

Readme

Source

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());

Keywords

FAQs

Last updated on 31 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc