import type { EVMResult, IotaAggregatorResponse, IotaSimulationResult, SuiAggregatorResponse, SuiSimulationResult } from './types/chains.js'; import type { CrossbarOracleFeedFetchResponse, CrossbarSimulateProtoResponse, FeedRequest, FetchSignaturesConsensusRequest, FetchSignaturesConsensusResponse, OracleInfo, SimulateJobsRequest, SimulateJobsResponse, V2UpdateQuery, V2UpdateResponse } from './types/crossbar.js'; import { Gateway } from './gateway.js'; import type { IOracleFeed } from './protos.js'; import type { TransactionInstruction } from '@solana/web3.js'; /** * Network options for CrossbarClient operations */ export declare enum CrossbarNetwork { SolanaMainnet = "mainnet", SolanaDevnet = "devnet" } export declare class CrossbarClient { private static _instance; readonly crossbarUrl: string; readonly verbose: boolean; readonly oracleFeedCache: Map; private readonly gatewayCache; private network; /** * Create a FeedRequestV1 object * @param {string[]} jobsB64Encoded - Base64 encoded oracle jobs * @param {number} maxVariance - Maximum variance allowed for the feed, already scaled by 1e9 (1_000_000_000 = 1%) * @param {number} minResponses - Minimum number of job responses required, unscaled * @returns {FeedRequest} - A FeedRequestV1 object */ static createFeedRequestV1(jobsB64Encoded: string[], maxVariance: number, minResponses: number): FeedRequest; /** * Create a FeedRequestV2 object * @param {string} feedProtoB64 - Base64 encoded feed protobuf * @returns {FeedRequest} - A FeedRequestV2 object */ static createFeedRequestV2(feedProtoB64: string): FeedRequest; static default(verbose?: boolean): CrossbarClient; constructor(crossbarUrl: string, verbose?: boolean); /** * Set the default network for CrossbarClient operations * * This network will be used as the default for all operations that accept * a network parameter. Individual method calls can still override this by * passing their own network parameter. * * @param {CrossbarNetwork} network - The network to use (SolanaMainnet or SolanaDevnet) * * @example * ```typescript * const crossbar = CrossbarClient.default(); * crossbar.setNetwork(CrossbarNetwork.SolanaDevnet); * * // Now all operations will default to devnet * const gateway = await crossbar.fetchGateway(); // Uses devnet * const simResult = await crossbar.simulateFeed(feedId); // Uses devnet * ``` */ setNetwork(network: CrossbarNetwork): void; /** * Get the currently configured default network * * @returns {string} The current network (mainnet or devnet) */ getNetwork(): string; /** * GET /v2/fetch/:feedHash * Fetch OracleFeed data from a crossbar server using the provided feedId * @param {string} feedId - The identifier of the OracleFeed to fetch * @returns {Promise} - The data fetched from the crossbar */ fetchOracleFeed(feedId: string): Promise; /** * POST /v2/store * Store an OracleFeed on IPFS using crossbar. * @param {IOracleFeed} feed - The OracleFeed to store * @returns {Promise<{ cid: string; feedHash: string; queueHex: string }>} - The stored data information */ storeOracleFeed(feed: IOracleFeed): Promise<{ cid: string; feedId: string; }>; /** * GET /updates/solana/:network/:feedpubkeys * Fetch updates for Solana network feeds from the crossbar * @param {string} network - The Solana network to fetch updates for * @param {string[]} feedpubkeys - The public keys of the feeds to fetch updates for * @param {string} payer - The payer public key used to build the pull instructions * @param {number} [numSignatures] - The number of signatures to fetch (optional) * @returns {Promise<{ success: boolean; pullIxns: TransactionInstruction[]; responses: { oracle: string; result: number | null; errors: string }[]; lookupTables: string[] }[]>} - The decoded updates for the specified feeds */ fetchSolanaUpdates(network: string, feedpubkeys: string[], payer: string, numSignatures?: number): Promise<{ success: boolean; pullIxns: TransactionInstruction[]; responses: { oracle: string; result: number | null; errors: string; }[]; lookupTables: string[]; }[]>; /** * GET /simulate/solana/:network/:feedpubkeys * Simulate fetching Solana feed results from the crossbar * @param {string} network - The Solana network to simulate * @param {string[]} feedpubkeys - The public keys of the feeds to simulate * @returns {Promise<{ feed: string; feedHash: string; results: number[] }[]>} - The simulated feed results */ simulateSolanaFeeds(network: string, feedpubkeys: string[]): Promise<{ feed: string; feedHash: string; results: number[]; }[]>; /** * GET /updates/evm/:chainId/:aggregatorIds * Fetch updates for EVM network feeds from the crossbar * @param param0 - The chain ID and aggregator IDs to fetch updates for * @returns Promise<{ results: EVMResult[]; encoded: string[] }> - The updates for the specified feeds */ fetchEVMResults({ chainId, aggregatorIds, }: { chainId: number; aggregatorIds: string[]; }): Promise<{ results: EVMResult[]; encoded: string[]; }>; /** * GET /oracle/quote/:aggregatorIds * Fetch the quote for the given aggregator IDs * @param aggregatorIds - The aggregator IDs to fetch the quote for * @param network - The network to fetch the quote for (mainnet / testnet) * @returns {Promise} - The quote for the given aggregator IDs with timestamp and encoded data */ fetchOracleQuote(aggregatorIds: string[], network?: string): Promise; /** * GET /simulate/evm/:network/:aggregatorIds * Simulate fetching Solana feed results from the crossbar * @param {string} network - The Solana network to simulate * @param {string[]} aggregatorIds - The public keys of the feeds to simulate * @returns {Promise<{ feed: string; feedHash: string; results: number[] }[]>} - The simulated feed results */ simulateEVMFeeds(network: number, aggregatorIds: string[]): Promise<{ aggregatorId: string; feedHash: string; results: number[]; }[]>; /** * POST /randomness/evm * Fetch randomness reveal data from the crossbar * @param param0 - The parameters for the randomness request * @param param0.chainId - The EVM chain ID * @param param0.randomnessId - The randomness ID (bytes32 from the contract) * @param param0.timestamp - The roll timestamp from the randomness request * @param param0.minStalenessSeconds - The minimum staleness in seconds * @param param0.oracle - The oracle address that was assigned to the randomness request */ resolveEVMRandomness({ chainId, randomnessId, timestamp, minStalenessSeconds, oracle, }: { chainId: number; randomnessId: string; timestamp: number; minStalenessSeconds: number; oracle: string; }): Promise<{ encoded: string; response: { signature: string; recovery_id: number; value: string; }; }>; /** * GET /updates/sui/:network/:aggregatorAddresses * Fetch updates for Sui network feeds from the crossbar * @param {string} network - The Sui network to fetch updates for (mainnet / testnet) * @param {string[]} aggregatorAddresses - The addresses of the aggregators to fetch updates for * @returns {Promise<{ responses: SuiAggregatorResponse[]; failures: string[] }>} - The updates and any failures for the specified feeds */ fetchSuiUpdates(network: string, aggregatorAddresses: string[]): Promise<{ responses: SuiAggregatorResponse[]; failures: string[]; }>; /** * GET /simulate/sui/:network/:aggregatorAddresses * Simulate fetching Sui feed results from the crossbar * @param {string} network - The Sui network to simulate (mainnet / testnet) * @param {string[]} aggregatorAddresses - The feed IDs to simulate * @param {boolean} [includeReceipts] - Whether to include receipts in the response * @returns {Promise} - The simulated feed results */ simulateSuiFeeds(network: string, aggregatorAddresses: string[], includeReceipts?: boolean): Promise; /** * GET /updates/iota/:network/:aggregatorAddresses * Fetch updates for Iota network feeds from the crossbar * @param {string} network - The Iota network to fetch updates for (mainnet / testnet) * @param {string[]} aggregatorAddresses - The addresses of the aggregators to fetch updates for * @returns {Promise<{ responses: IotaAggregatorResponse[]; failures: string[] }>} - The updates and any failures for the specified feeds */ fetchIotaUpdates(network: string, aggregatorAddresses: string[]): Promise<{ responses: IotaAggregatorResponse[]; failures: string[]; }>; /** * GET /simulate/iota/:network/:aggregatorAddresses * Simulate fetching Iota feed results from the crossbar * @param {string} network - The Iota network to simulate (mainnet / testnet) * @param {string[]} aggregatorAddresses - The feed IDs to simulate * @param {boolean} [includeReceipts] - Whether to include receipts in the response * @returns {Promise} - The simulated feed results */ simulateIotaFeeds(network: string, aggregatorAddresses: string[], includeReceipts?: boolean): Promise; /** * GET /gateways * Fetch all gateways from the crossbar * @param {string} [network] - Optional network parameter (devnet/testnet/mainnet). Defaults to mainnet. * @returns {Promise} - The gateways response containing an array of Gateway urls */ fetchGateways(network?: string): Promise; /** * Fetch a Gateway instance for the specified network with caching * * This method fetches gateway URLs from the crossbar service and creates * a Gateway instance. Results are cached per network to avoid repeated * network calls. * * @param {string} [network] - Network to fetch gateway for (devnet/testnet/mainnet). * If not provided, uses the network set via setNetwork() * @returns {Promise} - A Gateway instance for the specified network * @throws {Error} If no gateways are available for the specified network * * @example * ```typescript * const crossbar = CrossbarClient.default(); * const gateway = await crossbar.fetchGateway('mainnet'); * const response = await gateway.fetchQuote(...); * ``` */ fetchGateway(network?: string): Promise; /** * GET /oracles * Fetch all oracles for a given network * @param {string} [network] - Optional network parameter (devnet/mainnet). Defaults to mainnet. * @returns {Promise} - Array of oracle information */ fetchOracles(network?: string): Promise; /** * POST /gateways/fetch_signatures_consensus * Fetch consensus signatures from oracles for a given set of feed requests * @param {FetchSignaturesConsensusRequest} request - The request parameters with camelCase fields * @param {string} [network] - Optional network parameter (devnet/mainnet). Defaults to mainnet. * @returns {Promise} - Consensus signatures and median responses in camelCase * * @example * // Using FeedRequestV1 * const feedRequestV1 = CrossbarClient.createFeedRequestV1( * ['base64EncodedJob1', 'base64EncodedJob2'], * 1_000_000_000, // maxVariance: 1%, scaled by 1e9 * 3 // minResponses * ); * * // Using FeedRequestV2 * const feedRequestV2 = CrossbarClient.createFeedRequestV2('base64EncodedProtoBuf'); * * const response = await client.fetchSignaturesConsensus({ * apiVersion: '1.0', * recentHash: 'someRecentHash', * signatureScheme: 'ed25519', * hashScheme: 'sha256', * feedRequests: [feedRequestV1, feedRequestV2], * numOracles: 3, * useTimestamp: false * }); */ fetchSignaturesConsensus(request: FetchSignaturesConsensusRequest, network?: string): Promise; /** * POST /simulate/jobs * Simulate oracle jobs execution without storing them * @param {SimulateJobsRequest} request - The simulation request containing jobs and optional parameters * @returns {Promise} - The simulation results * * @example * const response = await client.simulateJobs({ * jobs: [ * { * tasks: [ * { * httpTask: { * url: "https://api.coinbase.com/v2/prices/BTC-USD/spot" * } * }, * { * jsonParseTask: { * path: "$.data.amount" * } * } * ] * } * ], * includeReceipts: true, * variableOverrides: { * MY_VARIABLE: "custom_value" * } * }); */ simulateJobs(request: SimulateJobsRequest): Promise; /** * GET /v2/update/{feedHashes} * Fetch V2 oracle consensus updates for feed hashes with enhanced chain support * @param {string[]} feedHashes - Array of feed hashes to fetch updates for * @param {V2UpdateQuery} [options] - Optional query parameters for the request * @returns {Promise} - The V2 update response with oracle consensus data * * @example * // Basic usage with single feed hash * const response = await client.fetchV2Update( * ['0x7418dc6408f5e0eb4724dabd81922ee7b0814a43abc2b30ea7a08222cd1e23ee'] * ); * * @example * // With chain-specific options for Sui mainnet * const response = await client.fetchV2Update( * ['0x7418dc6408f5e0eb4724dabd81922ee7b0814a43abc2b30ea7a08222cd1e23ee'], * { * chain: 'sui', * network: 'mainnet', * use_timestamp: true, * num_oracles: 5 * } * ); * * @example * // Multiple feed hashes with custom gateway * const response = await client.fetchV2Update( * [ * '0x7418dc6408f5e0eb4724dabd81922ee7b0814a43abc2b30ea7a08222cd1e23ee', * '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' * ], * { * network: 'testnet', * gateway: 'https://custom-gateway.example.com', * signature_scheme: 'Secp256k1' * } * ); */ fetchV2Update(feedHashes: string[], options?: V2UpdateQuery): Promise; /** * POST /v2/simulate/proto * Simulate an OracleFeed from a protobuf object or feed hash * @param {IOracleFeed | string} feedOrHash - The OracleFeed protobuf object or feed hash to simulate * @param {boolean} [includeReceipts] - Whether to include receipts in the response * @param {Record} [variableOverrides] - Variable overrides for the simulation * @param {string} [network] - Network to use for simulation. If not provided, uses the network set via setNetwork() * @returns {Promise} - The simulation results * * @example * const feed = OracleFeed.create({ * name: "BTC/USD", * jobs: [ * { * tasks: [ * { * httpTask: { * url: "https://api.coinbase.com/v2/prices/BTC-USD/spot" * } * }, * { * jsonParseTask: { * path: "$.data.amount" * } * } * ] * } * ] * }); * * const response = await client.simulateFeed( * feed, * true, * { MY_VAR: "value" }, * "mainnet" * ); */ simulateFeed(feedOrHash: IOracleFeed | string, includeReceipts?: boolean, variableOverrides?: Record, network?: string): Promise; /** * Simulate fetching feed results from the crossbar using feed hashes * @param {string[]} feedHashes - The hashes of the feeds to simulate * @param {boolean} [includeReceipts] - Whether to include receipts in the response * @param {Record} [variableOverrides] - Request-scoped task variable overrides * @param {string} [network] - Network override for the simulations * @returns {Promise} - The simulated feed results */ simulateFeeds(feedHashes: string[], includeReceipts?: boolean, variableOverrides?: Record, network?: string): Promise; /** * Fetches the current server time from the gateway's Binance clock proxy * * This method retrieves the current server time via the gateway's Binance time * proxy endpoint. This is useful for clock synchronization and ensuring accurate * timestamps for trading operations. The gateway instance is automatically * fetched and cached based on the configured network. * * @param {string} [network] - Network to use for the gateway (devnet/testnet/mainnet). * If not provided, uses the network set via setNetwork() * @returns {Promise<{ serverTime: number }>} Server time in milliseconds since Unix epoch * @throws {Error} When gateway is unreachable or returns an error * * @example * ```typescript * const crossbar = CrossbarClient.default(); * * // Fetch server time using default network * const clock = await crossbar.fetchClock(); * console.log(`Server time: ${clock.serverTime}`); * console.log(`Server date: ${new Date(clock.serverTime)}`); * * // Calculate clock offset * const localTime = Date.now(); * const offset = clock.serverTime - localTime; * console.log(`Clock offset: ${offset}ms`); * * // Fetch from specific network * crossbar.setNetwork(CrossbarNetwork.SolanaDevnet); * const devnetClock = await crossbar.fetchClock(); * ``` */ fetchClock(network?: string): Promise<{ serverTime: number; }>; } //# sourceMappingURL=crossbar-client.d.ts.map