Queue account management for Switchboard On-Demand

The Queue class is the primary interface for interacting with oracle operators in the Switchboard network. It manages:

  • Oracle operator authorization and verification
  • Bundle fetching and signature verification
  • Address lookup table management
  • Gateway interactions for data retrieval
  • Oracle Management: Track and verify authorized oracle signers
  • Bundle Operations: Fetch signed data bundles from oracle operators
  • LUT Optimization: Automatic address lookup table management
  • Network Detection: Automatic mainnet/devnet queue selection
// Load the default queue for your network
const queue = await Queue.loadDefault(program);

// Fetch a bundle for specific feeds
const [sigVerifyIx, bundle] = await queue.fetchUpdateBundleIx(
gateway,
crossbar,
['0x1234...', '0x5678...'] // Feed hashes
);

Queue

Constructors

Properties

program: Program

The Anchor program instance.

pubkey: PublicKey

The public key of the queue account.

DEFAULT_DEVNET_KEY: PublicKey = ...
DEFAULT_MAINNET_KEY: PublicKey = ...

Methods

  • Adds a new MR enclave to the queue. This will allow the queue to accept signatures from the given MR enclave.

    Parameters

    • params: { mrEnclave: Uint8Array }

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

    if the request fails.

    if the MR enclave is already added.

    if the MR enclave is invalid.

    if the MR enclave is not a valid length.

  • Fetches most recently added and verified Oracle Key.

    Returns Promise<PublicKey>

    A promise that resolves to an oracle public key.

    if the request fails.

  • Fetches a gateway interface for interacting with oracle nodes.

    Parameters

    • OptionalgatewayUrl: string

      Optional URL of a specific gateway to use. If not provided, a random gateway will be selected from the queue's available gateways.

    Returns Promise<Gateway>

    Gateway - A Gateway instance for making oracle requests

    If no gateways are available on the queue when selecting randomly

  • Fetches a gateway URL from the Crossbar network

    The gateway is the interface to oracle operators. This method automatically detects your network and returns an appropriate gateway for fetching oracle data.

    Parameters

    • crossbar: CrossbarClient

      Crossbar client instance

    Returns Promise<Gateway>

    Gateway instance for oracle communication

    const crossbar = CrossbarClient.default();
    const gateway = await queue.fetchGatewayFromCrossbar(crossbar);
  • Loads the queue data from on chain and returns the listed oracle keys.

    Returns Promise<PublicKey[]>

    A promise that resolves to an array of oracle public keys.

  • Fetches signatures from a random gateway on the queue.

    REST API endpoint: /api/v1/fetch_signatures

    Parameters

    • params: {
          gateway?: string;
          jobs: IOracleJob[];
          maxVariance?: number;
          minResponses?: number;
          numSignatures?: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<{ failures: string[]; responses: FeedEvalResponse[] }>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Fetches oracle bundle and creates verification instruction

    This is the primary method for fetching oracle data in the bundle approach. It retrieves signed price data from oracle operators and creates the instruction to verify signatures on-chain.

    Parameters

    • gateway: Gateway

      Gateway instance for oracle communication

    • crossbar: CrossbarClient

      Crossbar client for data routing

    • feedHashes: string[]

      Array of feed hashes to fetch (hex strings)

    • numSignatures: number = 1

      Number of oracle signatures required (default: 1)

    Returns Promise<[TransactionInstruction, Buffer<ArrayBufferLike>]>

    Tuple of [signature verification instruction, bundle data]

    // Fetch prices for BTC and ETH
    const [sigVerifyIx, bundle] = await queue.fetchUpdateBundleIx(
    gateway,
    crossbar,
    ['0x1234...', '0x5678...'], // Feed hashes
    3 // Require 3 oracle signatures
    );

    // Use in your transaction
    const tx = await asV0Tx({
    connection,
    ixs: [sigVerifyIx, yourProgramIx],
    signers: [payer],
    });
  • Add an Oracle to a queue and set permissions

    Parameters

    • params: {
          maxQuoteVerificationAge: number;
          mrEnclave: Buffer;
          oracle: PublicKey;
          secp256k1Signer: Buffer;
          slot: number;
      }

    Returns Promise<TransactionInstruction>

  • Removes all MR enclaves from the queue.

    Returns Promise<TransactionInstruction[]>

    A promise that resolves to an array of transaction instructions.

    if the request fails.

  • Removes an MR enclave from the queue. This will prevent the queue from accepting signatures from the given MR enclave.

    Parameters

    • params: { mrEnclave: Uint8Array }

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

    if the request fails.

    if the MR enclave is not present.

  • Sets the queue configurations.

    Parameters

    • params: { authority?: PublicKey; nodeTimeout?: number; reward?: number }
      • Optionalauthority?: PublicKey

        The new authority for the queue.

      • OptionalnodeTimeout?: number

        The new node timeout for the queue.

      • Optionalreward?: number

        The new reward for the queue.

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

  • Sets the oracle permission on the queue.

    Parameters

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction

  • Parameters

    • params: { enable: boolean; vault: PublicKey }

    Returns Promise<TransactionInstruction>

  • Creates a new queue account

    Parameters

    • program: Program

      Anchor program instance

    • params: {
          allowAuthorityOverrideAfter?: number;
          lutSlot?: number;
          maxQuoteVerificationAge?: number;
          nodeTimeout?: number;
          requireAuthorityHeartbeatPermission?: boolean;
          requireUsagePermission?: boolean;
          reward?: number;
      }

      Queue configuration parameters

    Returns Promise<[Queue, Keypair, TransactionInstruction]>

    Tuple of [Queue instance, keypair, creation instruction]

  • Creates a new instance of the Queue account with a PDA for SVM (non-solana) chains.

    Parameters

    • program: Program

      The anchor program instance.

    • params: {
          allowAuthorityOverrideAfter?: number;
          lutSlot?: number;
          maxQuoteVerificationAge?: number;
          nodeTimeout?: number;
          requireAuthorityHeartbeatPermission?: boolean;
          requireUsagePermission?: boolean;
          reward?: number;
          sourceQueueKey: PublicKey;
      }

      The initialization parameters for the queue.

    Returns Promise<[Queue, TransactionInstruction]>

  • Parameters

    • program: Program
    • params: {
          gateway?: string;
          jobs: IOracleJob[];
          maxVariance?: number;
          minResponses?: number;
          numSignatures?: number;
          queue: PublicKey;
          recentHash?: string;
      }

    Returns Promise<Buffer<ArrayBufferLike>>

    Deprecated. Use @switchboard-xyz/common#FeedHash.compute instead.

  • Fetches signatures from a random gateway on the queue.

    REST API endpoint: /api/v1/fetch_signatures

    Parameters

    • program: Program
    • params: {
          gateway?: string;
          jobs: IOracleJob[];
          maxVariance?: number;
          minResponses?: number;
          numSignatures?: number;
          queue: PublicKey;
          recentHash?: string;
      }

    Returns Promise<{ failures: string[]; responses: FeedEvalResponse[] }>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Loads the default queue for the current network

    Automatically detects whether you're on mainnet or devnet and loads the appropriate default queue. This is the recommended way to get started with Switchboard On-Demand.

    Parameters

    • program: Program

      Anchor program instance

    Returns Promise<Queue>

    The default queue for your network

    const queue = await Queue.loadDefault(program);
    console.log('Using queue:', queue.pubkey.toBase58());
  • Get the PDA for the queue (SVM chains that are not solana)

    Parameters

    • program: Program

      Anchor program

    • pubkey: PublicKey

      Queue pubkey

    Returns PublicKey

    Queue PDA Pubkey