Coder Social home page Coder Social logo

solana-sdk's Introduction

Switchboard Logo

Switchboard x Solana

A collection of libraries and examples for interacting with Switchboard V2 on Solana.

Test Status Anchor Test Status

Crates.io NPM Badge

Getting Started

To get started, clone the sbv2-solana repository.

git clone https://github.com/switchboard-xyz/sbv2-solana

Then install the dependencies

cd sbv2-solana
pnpm install
pnpm build

Addresses

The following addresses can be used with the Switchboard deployment on Solana

Mainnet

Account Address
Program ID SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f
Program Authority 2NvGRFswVx3GXxURNSfjbsWY4iP1ufj8LvAKJWGXSm4D
IdlAddress Fi8vncGpNKbq62gPo56G4toCehWNy77GgqGkTaAF5Lkk
Permissioned Queue 3HBb2DQqDfuMdzWxNk1Eo9RTMkFYmuEAd32RiLKn9pAn
Permissionless Queue 5JYwqvKkqp35w8Nq3ba4z1WYUeJQ1rB36V8XvaGp6zn1

Devnet

Account Address
Program ID SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f
Program Authority 2KgowxogBrGqRcgXQEmqFvC3PGtCu66qERNJevYW8Ajh
IdlAddress Fi8vncGpNKbq62gPo56G4toCehWNy77GgqGkTaAF5Lkk
Permissioned Queue PeRMnAqNqHQYHUuCBEjhm1XPeVTh4BxjY4t4TPan1pG
Permissionless Queue uPeRMdfPmrPqgRWSrjAnAkH78RqAhe5kXoW6vBYRqFX

Clients

Lang Name Description
Rust switchboard-v2 A Rust library to interact with Switchboard V2 accounts on Solana.
Javascript @switchboard-xyz/solana.js A Typescript client to interact with Switchboard on Solana.

Examples

Lang Name Description
Rust native-feed-parser Read a Switchboard feed using Solana's native program library
Anchor anchor-feed-parser Read a Switchboard feed using Anchor
Anchor anchor-history-parser Read a data feeds history buffer and get the closest historical sample to a given timestamp
Anchor anchor-vrf-parser Read a Switchboard VRF account and make a Cross Program Invocation (CPI) to request a new randomness value
Anchor anchor-vrf-lite-parser Read a Switchboard VRF Lite account and make a Cross Program Invocation (CPI) to request a new randomness value
Anchor anchor-buffer-parser Read a Switchboard buffer relayer using Anchor
Javascript javascript-feed-walkthrough Create a private Switchboard queue and oracle and fulfill your own oracle updates

Troubleshooting

  1. File a GitHub Issue
  2. Ask a question in Discord #dev-support

solana-sdk's People

Contributors

0xripleys avatar ahermida avatar chewingglass avatar dependabot[bot] avatar gallynaut avatar harsh4786 avatar jessupjn avatar mgild avatar s1nus avatar wlaoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

solana-sdk's Issues

Cannot use AggregatorAccountData on Devnet

Using it with Anchor throws an AnchorAccountError

> Program logged: "Instruction: Initialize"
> Program logged: "AnchorError caused by account: aggregator. Error Code: AccountOwnedByWrongProgram. Error Number: 3007. Error Message: The given account is owned by a different program than expected."
> Program logged: "Left:"
> Program logged: "2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG"
> Program logged: "Right:"
> Program logged: "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"

Example transaction on explorer.

Code located here.

Executed at top level directory anchor test --provider.cluster devnet --skip-deploy --skip-build --skip-local-validator

Cannot launch feed-walkthrough project

  1. go to javascript/feed-walkthrought
  2. yarn install
  3. yarn run start

Error:
Failed to create a private feed
Error: Signature verification failed
at async main main.ts:214:22
node 19.0.0, yarn 1.22.19, ubuntu 22.10

Bad example for loading data

https://github.com/switchboard-xyz/switchboard-v2/blob/6a58d6e2f4ba0122c05aa68f3f64e294057373d3/examples/programs/anchor-feed-parser/src/lib.rs#L12-L15

https://github.com/switchboard-xyz/switchboard-v2/blob/6a58d6e2f4ba0122c05aa68f3f64e294057373d3/examples/programs/anchor-feed-parser/src/lib.rs#L32-L39

This account should really be loaded using the build in AccountLoader keyword.
pub aggregator: AccountLoader<'info, AggregatorAccountData >,
And you can use the cfg() functionality to switch the program id depending on whether it's deployed to mainnet or devnet

at the top of the lib.rs file, before the #[program] macro, for instance

#[cfg(feature = "mainnet")]
declare_id!("8ghymvPffJbkLHqYfSKdE8moRH5gSf4AQav9qtZfu77H");
#[cfg(not(feature = "mainnet"))]
declare_id!("DLANS7Qh31fFWLujEMtn5kyd87H8ZUbhwtfMurrSHYn9");

That way when the user compiles their own program, they just need to pass a feature flag and it will compile with the correct program ID. And you don't have to reimplement all the anchor checks.

Can check here for more details https://solana.stackexchange.com/questions/848/how-to-have-a-different-program-id-depending-on-the-cluster/852#852

Anchor version 0.25.0 gives error with lifetime specifier

Cargo.toml

[dependencies]
anchor-lang = "0.25.0"
switchboard-v2 = "0.1.16"

lib.rs

pub fn initialize(ctx: Context<GetResult>) -> Result<()> {
        let aggregator = &ctx.accounts.aggregator_feed;
        let val: u64 = AggregatorAccountData::new(aggregator)?
            .get_result()?
            .try_into()?;
        Ok(())
    }

AggregatorAccountData::new(aggregator) throws an error saying

lifetime may not live long enough
argument requires that `'1` must outlive `'2`

Python wrapper

Users were having trouble creating feeds from the python API. It needs to be updated to include new curator rewards params. And any new configuration functions available in the idl.

solana.rpc.core.RPCException: {'code': -32002, 'message': 'Transaction simulation failed: Error processing Instruction 0: custom program error: 0xbbf', 'data': {'accounts': None, 'err': {'InstructionError': [0, {'Custom': 3007}]}, 'logs': ['Program 2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG invoke [1]', 'Program log: Instruction: LeaseInit', 'Program log: AnchorError caused by account: funder. Error Code: AccountOwnedByWrongProgram. Error Number: 3007. Error Message: The given account is owned by a different program than expected.', 'Program log: Left:', 'Program log: 11111111111111111111111111111111', 'Program log: Right:', 'Program log: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'Program 2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG consumed 8215 of 1400000 compute units', 'Program 2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG failed: custom program error: 0xbbf'], 'unitsConsumed': 0}}

Cannot fetch price data using OracleAccount

Following the example available on test_oracle (https://github.com/switchboard-xyz/switchboard-v2/blob/main/libraries/py/tests/test_oracle.py), I tried executing the code in a Jupyter notebook but obtained the following problem:

provider = Provider(client, Wallet(Keypair()))
program = await Program.at(SBV2_DEVNET_PID, provider)
oracle = OracleAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))

# getting aggregator data
data = await oracle.load_data()
---------------------------------------------------------------------------
AccountInvalidDiscriminator               Traceback (most recent call last)
Input In [34], in <cell line: 6>()
      3 oracle = OracleAccount(AccountParams(program=program, public_key=PublicKey("88FX4tBstuwBPNhQU4EEBoPX35neSu4Le9zDSwtPRRQz")))
      5 # getting aggregator data
----> 6 data = await oracle.load_data()

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/oracle.py:89, in OracleAccount.load_data(self)
     88 async def load_data(self):
---> 89     return await OracleAccountData.fetch(self.program.provider.connection, self.public_key)

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/generated/accounts/oracle_account_data.py:66, in OracleAccountData.fetch(cls, conn, address, commitment)
     64     raise ValueError("Account does not belong to this program")
     65 bytes_data = b64decode(info["data"][0])
---> 66 return cls.decode(bytes_data)

File ~/miniconda3/envs/sol3.9/lib/python3.9/site-packages/switchboardpy/generated/accounts/oracle_account_data.py:89, in OracleAccountData.decode(cls, data)
     86 @classmethod
     87 def decode(cls, data: bytes) -> "OracleAccountData":
     88     if data[:ACCOUNT_DISCRIMINATOR_SIZE] != cls.discriminator:
---> 89         raise AccountInvalidDiscriminator(
     90             "The discriminator for this account is invalid"
     91         )
     92     dec = OracleAccountData.layout.parse(data[ACCOUNT_DISCRIMINATOR_SIZE:])
     93     return cls(
     94         name=dec.name,
     95         metadata=dec.metadata,
   (...)
    102         ebuf=dec.ebuf,
    103     )

AccountInvalidDiscriminator: The discriminator for this account is invalid

Any help very much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.