Raindex SDK Documentation
    Preparing search index...

    Class RaindexClient

    RaindexClient provides a simplified interface for querying raindex data across multiple networks with automatic configuration management.

    This client abstracts away complex network-specific configurations by parsing YAML configuration files that define networks, tokens, raindexes, and subgraph endpoints. It enables querying raindex data either from specific chains or across all configured networks with automatic fallback mechanisms.

    The client handles:

    • YAML configuration parsing and validation
    • Network-to-subgraph URL mapping
    • Multi-network query coordination
    • Chain ID resolution to network configurations
    const result = await RaindexClient.new([yamlConfig]);
    if (result.error) {
    console.error('Failed to create client:', result.error.readableMsg);
    } else {
    const client = result.value;
    // Query orders across all networks or specific chains
    }

    // Create client with multiple YAML files for modular configuration
    const result = await RaindexClient.new([
    yamlConfig1,
    yamlConfig2,
    yamlConfig3,
    ]);
    Index

    Methods

    • Returns void

    • Returns void

    • Fetches orders that were added in a specific transaction

      Retrieves all orders created within a single blockchain transaction, useful for tracking order deployment.

      const result = await client.getAddOrdersForTransaction(1, "0x1234567890abcdef1234567890abcdef12345678");
      if (result.error) {
      console.error("Cannot fetch added orders:", result.error.readableMsg);
      return;
      }
      const orders = result.value;
      // Do something with orders

      Parameters

      • chainId: number

        Chain ID for the network

      • raindexAddress: `0x${string}`

        Raindex contract address

      • txHash: `0x${string}`

        Transaction hash

      • OptionalmaxAttempts: null | number

        Optional maximum polling attempts before timing out

      • OptionalintervalMs: null | number

        Optional polling interval in milliseconds

      Returns Promise<WasmEncodedResult<RaindexOrder[]>>

      Array of orders added in the transaction

    • Retrieves all accounts from the raindex YAML configuration

      Returns a map of account configurations where the keys are account names and the values are AccountCfg objects containing account details.

      const result = client.getAllAccounts();
      if (result.error) {
      console.error("Error getting accounts:", result.error.readableMsg);
      return;
      }
      const accounts = result.value;
      for (const [name, account] of accounts) {
      console.log(`Account name: ${name}, Address: ${account.address}`);
      }

      Returns WasmEncodedResult<Map<string, AccountCfg>>

      Returns the list of accounts from the raindex YAML configuration.

    • Retrieves all available networks with their configurations

      Returns a comprehensive map of all network configurations available in the raindex YAML. Each entry contains detailed network information including RPC endpoints and chain-specific settings.

      const result = client.getAllNetworks();
      if (result.error) {
      console.error("Error getting networks:", result.error.readableMsg);
      return;
      }
      const networks = result.value;
      for (const [key, config] of networks) {
      console.log(`Network key: ${key}, Chain ID: ${config.chainId}`);
      }

      Returns WasmEncodedResult<Map<string, NetworkCfg>>

      Returns a map of all available networks with their configurations. Keys are network names, values are NetworkCfg objects.

    • Retrieves all raindexes from the raindex YAML configuration

      Returns a map of raindex configurations where the keys are raindex names and the values are RaindexCfg objects.

      const result = client.getAllRaindexes();
      if (result.error) {
      console.error("Error getting raindexes:", result.error.readableMsg);
      return;
      }
      const raindexes = result.value;
      for (const [name, raindex] of raindexes) {
      console.log(`Raindex: ${name}, Address: ${raindex.address}, Chain: ${raindex.network.chainId}`);
      }

      Returns WasmEncodedResult<Map<string, RaindexCfg>>

      Returns the list of raindexes from the raindex YAML configuration.

    • Retrieves all tokens from the raindex YAML configuration

      Returns a map of token configurations where the keys are token names and the values are TokenCfg objects containing token details such as address, decimals, symbol, and associated network. This includes both locally defined tokens and any remotely fetched tokens that were cached during client initialization.

      const result = client.getAllTokens();
      if (result.error) {
      console.error("Error getting tokens:", result.error.readableMsg);
      return;
      }
      const tokens = result.value;
      for (const [name, token] of tokens) {
      console.log(`Token: ${name}, Address: ${token.address}, Decimals: ${token.decimals}`);
      }

      Returns WasmEncodedResult<Map<string, TokenCfg>>

      Returns a map of all available tokens with their configurations. Keys are token names, values are TokenCfg objects.

    • Fetches all unique tokens that exist in vaults.

      Retrieves all unique ERC20 tokens that have associated vaults by querying all vaults and extracting their token information, removing duplicates.

      const result = await client.getAllVaultTokens();
      if (result.error) {
      console.error("Error fetching tokens:", result.error.readableMsg);
      return;
      }
      const tokens = result.value;
      console.log(`Found ${tokens.length} unique tokens`);
      console.log(`Token ${tokens[0].name} in ${tokens[0].chainId}`);

      Parameters

      • OptionalchainIds: null | ChainIds

        Specific networks to query (optional)

      Returns Promise<WasmEncodedResult<RaindexVaultToken[]>>

      Array of raindex vault token instances

    • Returns the latest known local DB sync status snapshot.

      The live status fields are maintained by the sync scheduler as it emits status updates. When a local DB handle is available, persisted lastSyncedBlock watermark information is added per raindex.

      Returns Promise<WasmEncodedResult<LocalDbSyncSnapshot>>

      Latest local DB sync status snapshot

    • Retrieves network configuration for a specific chain ID

      Finds and returns the network configuration that matches the provided chain ID. This is useful when you need to access network-specific settings like RPC URLs.

      const result = client.getNetworkByChainId(1); // Ethereum mainnet
      if (result.error) {
      console.error("Network not found:", result.error.readableMsg);
      return;
      }
      const networkConfig = result.value;
      console.log(`Found network: ${networkConfig}`);

      Parameters

      • chainId: number

        The blockchain network ID to retrieve the configuration for

      Returns WasmEncodedResult<NetworkCfg>

      Returns the configuration for a specific network identified by its chain ID

    • Retrieves a specific order by its hash from a particular blockchain network

      Fetches complete order details including all vault information, metadata, and performance tracking capabilities for a specific order identified by its hash.

      const result = await client.getOrderByHash(
      137, // Polygon network
      "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
      );
      if (result.error) {
      console.error("Error fetching order:", result.error.readableMsg);
      return;
      }
      const order = result.value;
      // Do something with order

      Parameters

      • chainId: number

        The blockchain network ID where the order exists

      • raindexAddress: `0x${string}`

        Raindex contract address

      • orderHash: `0x${string}`

        The unique hash identifier of the order

      Returns Promise<WasmEncodedResult<RaindexOrder>>

      Complete order details with vault and metadata information

    • Executes quotes for multiple orders in a single multicall

      This function batches all order pairs into one multicall request, which is significantly more efficient than calling getQuotes on each order individually. Results are positionally aligned with the input orders: result[i] contains the quotes for orders[i].

      const orders = (await client.getOrders()).value;
      const result = await client.getOrderQuotesBatch(orders, null, null);
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }
      for (const [order, quotes] of orders.map((o, i) => [o, result.value[i]])) {
      console.log("Order", order.orderHash, "quotes:", quotes);
      }

      Parameters

      • orders: RaindexOrders

        List of orders to quote; all must share the same chain

      • OptionalblockNumber: null | bigint

        Optional specific block number for historical quotes (uses latest if None)

      • OptionalchunkSize: null | number

        Optional quote chunk size override (defaults to 16)

      Returns Promise<WasmEncodedResult<RaindexOrderQuote[][]>>

      List of quote lists, one per input order, positionally aligned

    • Queries orders with filtering and pagination across configured networks

      Retrieves a list of orders from the specified network or all configured networks, with support for filtering by owner, status, and order hash. Results are paginated for efficient data retrieval.

      const result = await client.getOrders(
      137, // Polygon network
      {
      owners: ["0x1234567890abcdef1234567890abcdef12345678"],
      active: true
      },
      1
      );
      if (result.error) {
      console.error("Error fetching orders:", result.error.readableMsg);
      return;
      }
      const { orders, totalCount } = result.value;
      // Do something with orders

      Parameters

      • OptionalchainIds: null | ChainIds

        Specific blockchain network to query (optional, queries all networks if not specified)

      • Optionalfilters: null | GetOrdersFilters

        Filtering criteria including owners, active status, and order hash (optional)

      • Optionalpage: null | number

        Page number for pagination (optional, defaults to 1)

      • OptionalpageSize: null | number

        Number of items per page (optional, defaults to 100)

      Returns Promise<WasmEncodedResult<RaindexOrdersListResult>>

      Orders list result with total count for pagination

    • Retrieves raindex configuration by contract address

      Finds and returns the raindex configuration that matches the provided contract address. This allows you to access raindex-specific settings including subgraph endpoints, network information, and other details.

      const result = client.getRaindexByAddress("0x1234567890123456789012345678901234567890");
      if (result.error) {
      console.error("Raindex not found:", result.error.readableMsg);
      return;
      }
      const raindexConfig = result.value;
      console.log(`Found raindex ${raindexConfig}`);

      Parameters

      • address: string

        The address of the raindex to retrieve the configuration for

      Returns WasmEncodedResult<RaindexCfg>

      Returns the configuration for a specific raindex identified by its address

    • Fetches orders that were removed in a specific transaction

      Retrieves all orders cancelled or removed within a single blockchain transaction. Polls either local DB or subgraph based on the query source.

      const result = await client.getRemoveOrdersForTransaction(1, "0x1234567890abcdef1234567890abcdef12345678");
      if (result.error) {
      console.error("Cannot fetch removed orders:", result.error.readableMsg);
      return;
      }
      const orders = result.value;
      // Do something with orders

      Parameters

      • chainId: number

        Chain ID for the network

      • raindexAddress: `0x${string}`

        Raindex contract address

      • txHash: `0x${string}`

        Transaction hash

      • OptionalmaxAttempts: null | number

        Optional maximum polling attempts before timing out

      • OptionalintervalMs: null | number

        Optional polling interval in milliseconds

      Returns Promise<WasmEncodedResult<RaindexOrder[]>>

      Array of orders removed in the transaction

    • Generates calldata for IRaindexV6.takeOrders4 using a mode + price-cap policy.

      This method includes preflight simulation to validate the transaction will succeed and automatically removes failing orders from the config.

      The request object contains:

      • taker: Address of the account that will execute the takeOrders transaction
      • chainId: Chain ID of the target network
      • sellToken: Token address the taker will GIVE
      • buyToken: Token address the taker will RECEIVE
      • mode: One of buyExact, buyUpTo, spendExact, or spendUpTo
      • amount: Target amount (output tokens for buy modes, input tokens for spend modes)
      • priceCap: human-readable decimal string for max sell per 1 buy

      Returns calldata plus pricing info:

      • calldata: ABI-encoded bytes for takeOrders4.
      • effectivePrice: expected blended sell per 1 buy from the simulation.
      • prices: per-leg ratios, best→worst.
      • expectedSell: simulated sell at current quotes.
      • maxSellCap: amount * priceCap for buy modes, amount for spend modes (worst-case on-chain spend cap).
      const res = await client.getTakeOrdersCalldata({
      chainId: 137,
      taker: "0xTAKER...",
      sellToken: "0xSELL...",
      buyToken: "0xBUY...",
      mode: "buyUpTo",
      amount: "10",
      priceCap: "1.2",
      });
      if (res.error) {
      console.error(res.error.readableMsg);
      } else {
      const { calldata, effectivePrice, expectedSell, maxSellCap, prices, raindex } = res.value;
      }

      Parameters

      Returns Promise<WasmEncodedResult<TakeOrdersCalldataResult>>

      Encoded takeOrders4 calldata and price information

    • Parameters

      • OptionalchainIds: null | ChainIds

        Specific blockchain networks to query (optional, queries all networks if not specified)

      • Optionalfilters: null | GetTradesFilters

        Filtering criteria including owners, order hash, token addresses, raindexes, and time range

      • Optionalpage: null | number

        Page number for pagination (optional, defaults to 1)

      • OptionalpageSize: null | number

        Number of items per page (optional, defaults to 100)

      Returns Promise<WasmEncodedResult<RaindexTradesListResult>>

      Trades list result with total count and per-pair summary

    • Parameters

      • chainIds: undefined | null | ChainIds

        Optional chain IDs to filter networks (queries all if not specified)

      • raindexAddresses: undefined | null | string[]

        Optional raindex addresses to filter results

      • owner: `0x${string}`

        Owner address

      • pagination: PaginationParams

        Optional pagination with page number and page size

      • timeFilter: TimeFilter

        Optional time filter with start/end Unix timestamps in seconds

      Returns Promise<WasmEncodedResult<RaindexTradesListResult>>

      Trades list result with total count and per-pair summary

    • Parameters

      • chainIds: undefined | null | ChainIds

        Optional chain IDs to filter networks (queries all if not specified)

      • raindexAddresses: undefined | null | string[]

        Optional raindex addresses to filter results

      • txHash: `0x${string}`

        Transaction hash

      Returns Promise<WasmEncodedResult<RaindexTradesListResult>>

      Trades list result with total count and per-pair summary

    • Fetches transaction details for a given transaction hash

      Retrieves basic transaction information including sender, block number, and timestamp. Polls either local DB or subgraph based on the query source.

      const result = await client.getTransaction(
      1,
      "0x1234567890123456789012345678901234567890",
      "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
      );
      if (result.error) {
      console.error("Transaction not found:", result.error.readableMsg);
      return;
      }
      const transaction = result.value;
      // Do something with the transaction

      Parameters

      • chainId: number

        Chain ID for the network

      • raindexAddress: `0x${string}`

        Raindex contract address

      • txHash: `0x${string}`

        Transaction hash

      • OptionalmaxAttempts: null | number

        Optional maximum polling attempts before timing out

      • OptionalintervalMs: null | number

        Optional polling interval in milliseconds

      Returns Promise<WasmEncodedResult<RaindexTransaction>>

      Transaction details

    • Retrieves a list of unique chain IDs from all configured networks

      Extracts and returns all unique blockchain network chain IDs that are available in the current raindex configuration.

      const result = client.getUniqueChainIds();
      if (result.error) {
      console.error("Error getting chain IDs:", result.error.readableMsg);
      return;
      }
      const chainIds = result.value;
      console.log("Available chains:", chainIds);

      Returns WasmEncodedResult<number[]>

      Returns a list of unique chain IDs from all available networks.

    • Fetches detailed information for a specific vault

      Retrieves complete vault information including token details, balance, etc.

      const result = await client.getVault(
      137, // Polygon network
      "0x1234567890abcdef1234567890abcdef12345678"
      );
      if (result.error) {
      console.error("Vault not found:", result.error.readableMsg);
      return;
      }
      const vault = result.value;
      // Do something with the vault

      Parameters

      • chainId: number

        Chain ID of the network the vault is on

      • raindexAddress: `0x${string}`

        Raindex contract address

      • vaultId: `0x${string}`

        Unique vault identifier

      Returns Promise<WasmEncodedResult<RaindexVault>>

      Complete vault information

    • Fetches a page of vault data from multiple networks with pagination metadata.

      const result = await client.getVaults(
      {
      owners: ["0x1234567890abcdef1234567890abcdef12345678"],
      hide_zero_balance: true
      },
      );
      if (result.error) {
      console.error("Error fetching vaults:", result.error.readableMsg);
      return;
      }
      const { items, totalItems, hasMore } = result.value;
      // Do something with the vaults

      Parameters

      • OptionalchainIds: null | ChainIds

        Specific networks to query (optional)

      • Optionalfilters: null | GetVaultsFilters

        Optional filtering options including owners and hide_zero_balance

      • Optionalpage: null | number

        Optional page number (defaults to 1)

      • OptionalpageSize: null | number

        Number of vaults per page (optional, defaults to 100)

      Returns Promise<WasmEncodedResult<RaindexVaultsListResult>>

      Vault list result with pagination metadata

    • Checks if Sentry error tracking is enabled in the YAML configuration

      Returns true if Sentry is enabled, otherwise returns false.

      const isEnabled = client.isSentryEnabled();
      if (isEnabled.error) {
      console.error("Error checking Sentry status:", isEnabled.error.readableMsg);
      return;
      }
      console.log("Is Sentry enabled?", isEnabled.value);

      Returns WasmEncodedResult<boolean>

      Returns whether Sentry is enabled in the YAML configuration.

    • Creates a RaindexClient from YAML config, optionally setting up local DB sync automatically when the YAML declares local-db-sync.

      // Subgraph-only (no local-db-sync in YAML)
      const result = await RaindexClient.new([yamlConfig]);

      // With local DB (YAML has local-db-sync)
      const result = await RaindexClient.new([yamlConfig], undefined, {
      localDb,
      statusCallback: updateStatus,
      });

      Parameters

      • raindexYamls: string[]

        List of YAML configuration strings. The YAML files must match the raindex yaml spec

      • Optionalvalidate: null | boolean
      • Optionaloptions: any

        Optional setup object with localDb and statusCallback

      Returns Promise<WasmEncodedResult<RaindexClient>>

      Initialized client instance for further operations