Dialed in with Switchboard: 5–23–22

Switchboard V2 SDK is Here!

github.com/switchboard-xyz/switchboard-v2

The Switchboard V2 SDK is here and includes the necessary tools to help you integrate Switchboard into your on-or-off chain applications. The SDK includes libraries for Typescript/Javascript, Python, and Rust, as well as example programs demonstrating how to read and interact with Switchboard V2. Below is the current overview of the Github repo structure:

Current Switchboard V2 SDK Layout

Setup

Clone the repository

git clone https://github.com/switchboard-xyz/switchboard-v2.git && cd switchboard-v2

Then, install and link the dependencies

yarn installyarn workspaces run buildyarn workspace @switchboard-xyz/switchboardv2-cli linkanchor build && node ./scripts/setup-example-programs.js

Finally, test the example programs

anchor test

Quick Links

Localnet Integration

The SDK supports copying a Switchboard devnet environment to your localnet environment for integration testing. This is useful if you want to see how your program will react to Switchboard data feed updates.

First, change the cluster to localnet in Anchor.toml.

Next, create a Switchboard devnet queue and oracle.

sbv2 localnet:env --keypair ../payer-keypair.json -o .switchboard

This command will output:

  • start-local-validator.sh: starts a local Solana validator with the Switchboard program, IDL, and our devnet environment pre-loaded
  • start-oracle.sh: start a Switchboard oracle and start heartbeating on the localnet queue
  • docker-compose.yml: docker file with the Switchboard oracle environment
  • switchboard.env: contains your Switchboard accounts

In three separate shells, run the following commands in this order:

  • .switchboard/start-local-validator.sh
  • .switchboard/start-oracle.sh
  • anchor test --skip-local-validator

The anchor tests are configured to first fetch the account info for the Switchboard DAO controlled devnet permissionless queue. If the account info is not found, it assumes a localnet connection and looks for the switchboard.env with your Switchboard environment specific public keys. If a .switchboard directory or switchboard.env file is not found in the root project directory, it will look 2 levels higher until giving up.

Uniswap & SushiSwap Task Types

Switchboard has added the UniswapExchangeRateTask and SushiSwapExchangeRateTask to resolve the swap price of assets on Uniswap and SushiSwap. These new task types will allow Solana protocols to offer DeFi products using data sourced from Ethereum.

xStepPriceTask

Switchboard also ported over the xStepPriceTask from Switchboard V1 to Switchboard V2. The following is an example of how to use the new task type:

SplTokenParseTask & SplStakePoolTask

Switchboard has added the SplTokenParseTask and SplStakePoolTask to resolve on-chain data in your Switchboard feeds. This will allow developers to build data feeds using live on-chain data. The following is an example of how to fetch the total token supply of the MonkeeDao stake pool:

Publisher

The publisher got a facelift

… more details soon™!

publish.switchboard.xyz

Conclusion

The Switchboard V2 SDK is here to help developers integrate Switchboard into their applications. We welcome any PRs or feedback from the community!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store