Raindex SDK Documentation
    Preparing search index...

    Class RaindexOrder

    A single order representation within a given raindex.

    RaindexOrder represents a trading order on a specific blockchain with its associated input and output vaults, metadata, and performance tracking capabilities. Each order is deployed on a specific raindex contract and can be queried for volume and performance metrics over time.

    The order contains both the raw order data (bytes and hash) and structured access to its vaults, which define what tokens can be traded and their current balances.

    Index

    Properties

    active: boolean
    chainId: number
    dotrainSource: undefined | string
    id: `0x${string}`
    inputsList: RaindexVaultsList
    inputsOutputsList: RaindexVaultsList
    meta: undefined | `0x${string}`
    oracleUrl: undefined | string

    Returns the signed context oracle URL if this order has oracle metadata.

    orderBuilderState: undefined | string
    orderBytes: `0x${string}`
    orderHash: `0x${string}`
    outputsList: RaindexVaultsList
    owner: `0x${string}`
    parsedMeta: ParsedMeta[]
    raindex: `0x${string}`
    rainlang: undefined | string
    timestampAdded: bigint
    timestampRemoved: undefined | bigint
    tradesCount: number
    transaction: undefined | RaindexTransaction
    vaultsList: RaindexVaultsList

    Methods

    • Returns void

    • Converts the order from RaindexOrder to an SgOrder type

      const sgOrder = await order.convertToSgOrder();
      // Do something with sgOrder

      Returns WasmEncodedResult<SgOrder>

      Order as SgOrder type

    • Returns void

    • Executes quotes directly from complete order objects without additional data fetching

      This function performs quote calculations using complete order data structures that typically come from previous subgraph queries. It generates quotes for all possible input/output token pairs within each order, providing comprehensive trading information without requiring additional network calls for order data.

      const result = await getOrderQuote();
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }
      const quoteResponses = result.value;
      // Do something with the quoteResponses

      Parameters

      • 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 batch quote responses with trading pair information

    • Generates ABI-encoded calldata for the removeOrder2() function on the raindex contract

      Takes an existing order from the subgraph and creates the transaction calldata needed to remove it from the raindex. The order must be active and owned by the caller.

      // Generate calldata for removing an order
      const result = await order.getRemoveCalldata();
      if (result.error) {
      console.error('Failed:', result.error.readableMsg);
      } else {
      const calldata = result.value;
      // Do something with the calldata
      }

      Returns WasmEncodedResult<`0x${string}`>

      ABI-encoded calldata ready for blockchain submission

    • Generates calldata for IRaindexV6.takeOrders4 targeting this specific order.

      Unlike getTakeOrdersCalldata on RaindexClient which discovers orders from the subgraph, this method generates calldata for taking this single known order that the user has already selected. The method fetches a fresh quote at execution time using the provided pair indices.

      This method includes preflight simulation to validate the transaction will succeed.

      Parameters:

      • inputIndex: Index of the input token in the order's validInputs array
      • outputIndex: Index of the output token in the order's validOutputs array
      • taker: Address of the account that will execute the takeOrders transaction
      • 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 (single entry for this order).
      • expectedSell: simulated sell at current quotes.
      • maxSellCap: worst-case on-chain spend cap.
      const res = await order.getTakeCalldata(
      0, // inputIndex
      0, // outputIndex
      "0xTAKER...",
      "buyUpTo",
      "10",
      "1.2",
      );
      if (res.error) {
      console.error(res.error.readableMsg);
      } else {
      const { calldata, effectivePrice, expectedSell, maxSellCap, prices, raindex } = res.value;
      }

      Parameters

      • inputIndex: number

        Index of the input token in the order's validInputs array

      • outputIndex: number

        Index of the output token in the order's validOutputs array

      • taker: string

        Address of the taker account

      • mode: TakeOrdersMode

        Take orders mode: buyExact, buyUpTo, spendExact, or spendUpTo

      • amount: string

        Target amount as decimal string

      • priceCap: string

        Maximum price cap as decimal string

      Returns Promise<WasmEncodedResult<TakeOrdersCalldataResult>>

      Encoded takeOrders4 calldata and price information for this order

    • Fetches detailed information for a specific trade

      Retrieves complete information about a single trade including vault changes and transaction details.

      const result = await order.getTradeDetail("0x1234567890abcdef1234567890abcdef12345678");
      if (result.error) {
      console.error("Trade not found:", result.error.readableMsg);
      return;
      }
      const trade = result.value;

      Parameters

      • tradeId: `0x${string}`

        Unique trade identifier

      Returns Promise<WasmEncodedResult<RaindexTrade>>

      Complete trade information

    • Fetches trade history with optional time filtering

      Retrieves a chronological list of trades executed by an order within an optional time range, along with the total count and optional per-pair summary.

      const result = await order.getTradesList();
      if (result.error) {
      console.error("Cannot fetch trades:", result.error.readableMsg);
      return;
      }
      const { trades, totalCount, summary } = result.value;

      Parameters

      • OptionalstartTimestamp: null | bigint

        Optional start time filter (Unix timestamp in seconds)

      • OptionalendTimestamp: null | bigint

        Optional end time filter (Unix timestamp in seconds)

      • Optionalpage: null | number

        Optional page number (defaults to 1)

      Returns Promise<WasmEncodedResult<RaindexTradesListResult>>

      Trades list result with total count and optional per-pair summary

    • Parameters

      • OptionalstartTimestamp: null | bigint

        Unix timestamp for the start of the query period (optional)

      • OptionalendTimestamp: null | bigint

        Unix timestamp for the end of the query period (optional)

      Returns Promise<WasmEncodedResult<RaindexVaultVolume[]>>

      Volume data for each vault over the specified period