Abstraction around the Switchboard-On-Demand Feed account

This account is used to store the feed data and the oracle responses for a given feed.

Constructors

  • Constructs a PullFeed instance.

    Parameters

    • program: Program

      The Anchor program instance.

    • pubkey: string | PublicKey

      The public key of the pull feed account.

    Returns PullFeed

Properties

configs: {
    feedHash: Buffer;
    maxVariance: number;
    minResponses: number;
    minSampleSize: number;
    queue: PublicKey;
}
gatewayUrl: string
jobs: IOracleJob[]
lut: AddressLookupTableAccount
program: Program
pubkey: PublicKey

Methods

  • Parameters

    • params: { payer?: PublicKey }

    Returns Promise<TransactionInstruction>

  • Fetch updates for the feed.

    Parameters

    • params: {
          chain?: string;
          crossbarClient?: CrossbarClient;
          gateway?: string;
          jobs?: IOracleJob[];
          network?: "mainnet" | "mainnet-beta" | "testnet" | "devnet";
          numSignatures?: number;
          recentSlothashes?: [BN, string][];
          retries?: number;
          solanaRpcUrl?: string;
      }
    • Optionaldebug: boolean

      A boolean flag to enable or disable debug mode. Defaults to false.

    • Optionalpayer: PublicKey

    Returns Promise<
        [
            TransactionInstruction[],
            OracleResponse[],
            number,
            AddressLookupTableAccount[],
            string[],
        ],
    >

    A promise that resolves to a tuple containing:

    • The transaction instruction to fetch updates, or undefined if not applicable.
    • An array of OracleResponse objects.
    • A number representing the successful responses.
    • An array containing usable lookup tables.
  • Compiles a transaction instruction to submit oracle signatures for a given feed.

    Parameters

    • params: {
          chain?: string;
          offsets: number[];
          payer?: PublicKey;
          resps: FeedEvalResponse[];
          slot: BN;
      }

    Returns TransactionInstruction

    A promise that resolves to the transaction instruction.

  • Initializes a pull feed account.

    Parameters

    • params: {
          maxStaleness: number;
          maxVariance: number;
          minResponses: number;
          minSampleSize: number;
          name: string;
          payer?: PublicKey;
          permitWriteByAuthority?: boolean;
          queue: PublicKey;
      } & ({ feedHash: Buffer } | { jobs: IOracleJob[] })

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

  • Checks if the pull feed account has been initialized.

    Returns Promise<boolean>

    A promise that resolves to a boolean indicating if the account has been initialized.

  • Loads the feed configurations (if not already cached) for this PullFeed account from on chain.

    Parameters

    • Optionalforce: boolean

    Returns Promise<
        {
            feedHash: Buffer;
            maxVariance: number;
            minResponses: number;
            minSampleSize: number;
            queue: PublicKey;
        },
    >

    A promise that resolves to the feed configurations.

    if the feed account does not exist.

  • Loads the feed data for this PullFeed account from on chain.

    Returns Promise<PullFeedAccountData>

    A promise that resolves to the feed data.

    if the feed account does not exist.

  • Parameters

    Returns Promise<CompactResult[]>

  • Returns Promise<AddressLookupTableAccount>

  • Loads the feed data for this PullFeed account from on chain.

    Parameters

    • onlyAfter: BN

      Call will ignore data signed before this slot.

    Returns Promise<{ oracle: PublicKey; slot: BN; value: Big }>

    A promise that resolves to the observed value as it would be seen on-chain.

  • Loads the feed data for this PullFeed account from on chain.

    Returns Promise<{ oracle: PublicKey; slot: BN; value: Big }[]>

    A promise that resolves to the values currently stored in the feed.

    if the feed account does not exist.

  • Parameters

    • data: any

    Returns PublicKey

  • Set configurations for the feed.

    Parameters

    • params: {
          authority?: PublicKey;
          feedHash?: Buffer;
          jobs?: IOracleJob[];
          maxStaleness?: number;
          maxVariance?: number;
          minResponses?: number;
          minSampleSize?: number;
          name?: string;
          permitWriteByAuthority?: boolean;
      }
      • Optionalauthority?: PublicKey

        The authority of the feed.

      • OptionalfeedHash?: Buffer

        The hash of the feed as a Uint8Array or hexadecimal string. Only results signed with this hash will be accepted.

      • Optionaljobs?: IOracleJob[]
      • OptionalmaxStaleness?: number

        The maximum number of slots that can pass before a feed value is considered stale.

      • OptionalmaxVariance?: number

        The maximum variance allowed for the feed.

      • OptionalminResponses?: number

        The minimum number of responses required.

      • OptionalminSampleSize?: number

        The minimum number of samples required for setting feed value.

      • Optionalname?: string
      • OptionalpermitWriteByAuthority?: boolean

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction to set feed configs.

  • Watches for any on-chain updates to the feed data.

    Parameters

    • callback: any

      The callback to call when the feed data is updated.

    Returns Promise<number>

    A promise that resolves to a subscription ID.

  • Fetches updates for a feed, returning instructions that must be executed in order at the front of the transaction.

    Parameters

    • params: {
          chain?: string;
          crossbarClient?: CrossbarClient;
          gateway?: string;
          network?: "mainnet" | "mainnet-beta" | "testnet" | "devnet";
          numSignatures: number;
          pullFeed: PullFeed;
          recentSlothashes?: [BN, string][];
      }

      The parameters object

      • Optionalchain?: string

        Optional chain identifier (defaults to "solana")

      • OptionalcrossbarClient?: CrossbarClient

        Optional CrossbarClient instance to use

      • Optionalgateway?: string

        Optional gateway URL to use for fetching updates

      • Optionalnetwork?: "mainnet" | "mainnet-beta" | "testnet" | "devnet"

        Optional network identifier ("mainnet", "mainnet-beta", "testnet", "devnet")

      • numSignatures: number

        Number of signatures to fetch

      • pullFeed: PullFeed
      • OptionalrecentSlothashes?: [BN, string][]
    • Optionaldebug: boolean

      Enable debug logging (default: false)

    • Optionalpayer: PublicKey

      Optional transaction payer public key

    Returns Promise<
        [
            TransactionInstruction[],
            OracleResponse[],
            number,
            AddressLookupTableAccount[],
            string[],
        ],
    >

    Promise resolving to:

    • instructions: Array of instructions that must be executed in order: [0] = secp256k1 program verification instruction [1] = feed update instruction
    • oracleResponses: Array of responses from oracles
    • numSuccesses: Number of successful responses
    • luts: Array of AddressLookupTableAccount to include
    • failures: Array of errors that occurred during the fetch
  • Parameters

    • params: {
          chain?: string;
          crossbarClient?: CrossbarClient;
          gateway?: string;
          network?: "mainnet" | "mainnet-beta" | "testnet" | "devnet";
          numSignatures: number;
          pullFeed: PullFeed;
          recentSlothashes?: [BN, string][];
      }
    • Optionaldebug: boolean
    • Optionalpayer: PublicKey

    Returns Promise<
        [
            TransactionInstruction[],
            OracleResponse[],
            number,
            AddressLookupTableAccount[],
            string[],
        ],
    >

  • Fetches updates for multiple feeds at once into a SINGLE tightly packed instruction. Returns instructions that must be executed in order, with the secp256k1 verification instruction placed at the front of the transaction.

    Parameters

    • program: Program

      The Anchor program instance.

    • params: {
          chain?: string;
          crossbarClient?: CrossbarClient;
          feeds: PublicKey[];
          gateway?: string;
          network?: "mainnet" | "mainnet-beta" | "testnet" | "devnet";
          numSignatures: number;
          payer?: PublicKey;
          recentSlothashes?: [BN, string][];
      }
    • Optionaldebug: boolean

      A boolean flag to enable or disable debug mode. Defaults to false.

    Returns Promise<
        [
            TransactionInstruction[],
            AddressLookupTableAccount[],
            FetchSignaturesConsensusResponse,
        ],
    >

    A promise that resolves to a tuple containing:

    • An array of transaction instructions that must be executed in order: [0] = secp256k1 program verification instruction [1] = feed update instruction
    • An array of AddressLookupTableAccount to use.
    • The raw response data.
  • Parameters

    • program: Program

    Returns [PullFeed, Keypair]

  • Parameters

    • program: Program
    • params: {
          maxStaleness: number;
          maxVariance: number;
          minResponses: number;
          minSampleSize: number;
          name: string;
          payer?: PublicKey;
          permitWriteByAuthority?: boolean;
          queue: PublicKey;
      } & ({ feedHash: Buffer } | { jobs: IOracleJob[] })

    Returns Promise<[PullFeed, VersionedTransaction]>

  • Loads the feed data for multiple feeds at once.

    Parameters

    • program: Program

      The program instance.

    • pubkeys: PublicKey[]

      The public keys of the feeds to load.

    Returns Promise<PullFeedAccountData[]>

    A promise that resolves to an array of feed data (or null if the feed account does not exist)

  • Watches for any on-chain updates to any data feed.

    Parameters

    • program: Program

      The Anchor program instance.

    • callback: (
          event: [number, { pubkey: PublicKey; submissions: FeedSubmission[] }],
      ) => Promise<void>

      The callback to call when the feed data is updated.

    Returns Promise<number>

    A promise that resolves to a subscription ID.