Raindex SDK Documentation
    Preparing search index...

    Class RaindexOrderBuilder

    Index

    Methods

    • Returns void

    • Returns void

    • Returns Promise<WasmEncodedResult<string>>

      Combined deposit and add order multicall calldata

    • Exports the current configuration as a complete dotrain text file.

      This generates a valid dotrain file with YAML frontmatter and Rainlang code, preserving all configurations and bindings. Useful for saving or sharing orders.

      The output follows the standard dotrain format:

      builder:
        ...
      ---
      #binding1 !The binding value
      #calculate-io
      ...
      
      const result = builder.generateDotrainText();
      if (result.error) {
      console.error("Export failed:", result.error.readableMsg);
      return;
      }
      const dotrain = result.value;
      // Do something with the dotrain

      Returns WasmEncodedResult<string>

      Complete dotrain content with YAML frontmatter separator

    • Parameters

      • token_address: string

        Token contract address

      • owner: string

        Account address to check balance for

      Returns Promise<WasmEncodedResult<AccountBalance>>

      Token balance for the specified account

    • Gets information for all tokens used in the current deployment's order.

      This function automatically determines which tokens to fetch based on the deployment:

      • If select-tokens is defined, returns info for those tokens
      • Otherwise, returns info for all input/output tokens in the order

      This may trigger multiple blockchain queries if token data isn't cached in YAML. Consider caching the results in your application.

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

      Returns Promise<WasmEncodedResult<ExtendedTokenInfo[]>>

      Array of complete token information

    • Retrieves the complete builder configuration including all deployments.

      This returns the parsed builder section from the YAML, filtered to include only the current deployment. Use this to access order-level metadata.

      const result = builder.getBuilderConfig();
      if (result.error) {
      console.error("Config error:", result.error.readableMsg);
      return;
      }
      const config = result.value;
      // Do something with the config

      Returns WasmEncodedResult<OrderBuilderCfg>

      Complete builder configuration with name, description, and deployments

    • Composes the final Rainlang code with all bindings and scenarios applied.

      This method updates scenario bindings from current field values and composes the Rainlang code ready to be displayed on the UI.

      Updates the internal scenario bindings before composition.

      const result = await builder.getComposedRainlang();
      if (result.error) {
      console.error("Composition error:", result.error.readableMsg);
      return;
      }
      const rainlang = result.value;
      // Do something with the rainlang

      Returns Promise<WasmEncodedResult<string>>

      Composed Rainlang code with comments for each entrypoint

    • Gets the active deployment's configuration including fields, deposits, and tokens.

      This is the primary method for accessing deployment-specific settings that define what inputs are needed from the user. The configuration drives UI generation.

      • fields - Input fields requiring user configuration
      • deposits - Token deposits with amounts and presets
      • selectTokens - Tokens that users must choose addresses for
      • deployment - Underlying order and scenario configuration
      const result = builder.getCurrentDeployment();
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }
      const deployment = result.value;
      // Do something with the deployment

      Returns WasmEncodedResult<OrderBuilderDeploymentCfg>

      Active deployment with all configuration details

    • Gets metadata for the currently active deployment.

      Instance method that returns name and description for the deployment selected during initialization.

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

      Returns WasmEncodedResult<NameAndDescriptionCfg>

      Current deployment's metadata

    • Parameters

      • key: string

        Token key to get presets for

      Returns WasmEncodedResult<string[]>

      Array of preset deposit amounts

    • Retrieves detailed token information from YAML configuration or blockchain.

      This function first checks the YAML for cached token data (decimals, name, symbol). If any information is missing, it queries the blockchain to fetch the complete details. This hybrid approach minimizes RPC calls while ensuring accurate data.

      The RPC endpoint is determined by the deployment's order network configuration.

      // Get token info (may query blockchain)
      const result = await builder.getTokenInfo("weth");
      if (result.error) {
      console.error("Token error:", result.error.readableMsg);
      return;
      }
      const tokenInfo = result.value;
      // Do something with the tokenInfo

      Parameters

      • key: string

        Token identifier from the YAML tokens section

      Returns Promise<WasmEncodedResult<ExtendedTokenInfo>>

      Complete token details including address, decimals, name, symbol, and chain_id

    • Parameters

      • key: string

        Token key to check

      Returns WasmEncodedResult<boolean>

      Whether the token has been selected

    • Parameters

      • token: string

        Token key from the YAML configuration

      • amount: string

        Deposit amount as a decimal string

      Returns Promise<WasmEncodedResult<void>>

    • Parameters

      • field: string

        Field identifier from the YAML configuration

      • value: string

        Value to save (can be a preset value or custom input)

      Returns WasmEncodedResult<void>

    • Parameters

      • key: string

        Token key from select-tokens configuration

      • address: string

        Token contract address as hex string

      Returns Promise<WasmEncodedResult<void>>

    • Parameters

      • type: VaultType

        Vault type (input or output)

      • token: string

        Token key

      • Optionalvault_id: null | string

        Optional vault ID as hex string

      Returns WasmEncodedResult<void>

    • Parameters

      • field: string

        Field identifier from the YAML configuration

      Returns WasmEncodedResult<void>

    • Parameters

      • dotrain: string

        Complete dotrain YAML content

      • Optionalsettings: null | string[]

        Optional additional YAML settings

      Returns Promise<WasmEncodedResult<string>>

      Base64-encoded SHA256 hash of the dotrain content

    • Gets metadata for a specific deployment by key.

      Convenience method that extracts details for a single deployment without parsing all deployments.

      const result = await getDeploymentDetail(dotrainYaml, "mainnet-order");
      if (result.error) {
      console.error("Not found:", result.error.readableMsg);
      return;
      }
      const detail = result.value;
      // Do something with the detail

      Parameters

      • dotrain: string

        Complete dotrain YAML content

      • settings: undefined | null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      • key: string

        Deployment identifier to look up

      Returns WasmEncodedResult<NameAndDescriptionCfg>

      Deployment name and description

    • Gets metadata for all deployments defined in the configuration.

      This static method extracts name and description for each deployment, useful for building deployment selection interfaces with rich descriptions.

      const result = await getDeploymentDetails(dotrainYaml);
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }

      // key is the deployment key
      // value is the deployment metadata
      for (const [key, value] of result.value) {
      const {
      // name is the deployment name
      // description is the deployment description
      name,
      description,
      // short_description is the deployment short description (optional)
      short_description,
      } = value;
      }

      Parameters

      • dotrain: string

        Complete dotrain YAML content

      • Optionalsettings: null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      Returns WasmEncodedResult<Map<string, NameAndDescriptionCfg>>

      Map of deployment key to metadata

    • Lists all available builder deployment keys from a dotrain YAML file.

      This function parses the builder section of the YAML frontmatter to extract deployment keys that can be used to initialize a builder instance. Use this to build deployment selectors in your UI.

      const dotrain = `
      builder:
      deployments:
      mainnet-order:
      name: "Mainnet Trading"
      testnet-order:
      name: "Test order"
      `;

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

      Parameters

      • dotrain: string

        Complete dotrain YAML content including the builder.deployments section

      • Optionalsettings: null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      Returns Promise<WasmEncodedResult<string[]>>

      Array of deployment identifiers (keys from the deployments map)

    • Extracts order-level metadata from a dotrain configuration.

      This static method allows checking order details without creating a builder instance, useful for displaying order information before deployment selection.

      The YAML must contain:

      • builder.name - Order display name
      • builder.description - Full order description
      • builder.short-description - Brief summary (optional but recommended)
      const result = await getOrderDetails(dotrainYaml);
      if (result.error) {
      console.error("Error:", result.error.readableMsg);
      return;
      }
      const details = result.value;
      // Do something with the details

      Parameters

      • dotrain: string

        Complete dotrain YAML content

      • Optionalsettings: null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      Returns WasmEncodedResult<NameAndDescriptionCfg>

      Order name, description, and optional short description

    • Parameters

      • dotrain: string

        Complete dotrain YAML content

      • settings: undefined | null | string[]

        Optional additional YAML settings

      • serialized: string

        Serialized state string from serializeState

      • Optionalstate_update_callback: null | Function

        Optional state update callback function

      Returns Promise<WasmEncodedResult<RaindexOrderBuilder>>

      Restored builder instance

    • Creates a new builder instance for managing a specific deployment configuration.

      This is the primary initialization function that sets up the builder context for a chosen deployment. The instance tracks field values, deposits, token selections, and provides methods for generating order transactions.

      The callback function receives a serialized state string on every change, enabling auto-save functionality or state synchronization across components.

      // Basic initialization
      const result = await RaindexOrderBuilder.newWithDeployment(dotrainYaml, "mainnet-order");
      if (result.error) {
      console.error("Init failed:", result.error.readableMsg);
      return;
      }
      const builder = result.value;

      // With state persistence
      const result = await RaindexOrderBuilder.newWithDeployment(
      dotrainYaml,
      "mainnet-order",
      (serializedState) => {
      localStorage.setItem('orderState', serializedState);
      }
      );
      if (!result.error) {
      const builder = result.value;
      // Use builder instance...
      }

      Parameters

      • dotrain: string

        Complete dotrain YAML content with all configurations

      • settings: undefined | null | string[]

        Optional additional YAML configuration strings to merge with the frontmatter

      • selected_deployment: string

        Key of the deployment to activate (must exist in YAML)

      • Optionalstate_update_callback: null | Function

        Optional function called on state changes. After a state change (deposit, field value, vault id, select token, etc.), the callback is called with the new state. This is useful for auto-saving the state of the builder across sessions.

      Returns Promise<WasmEncodedResult<RaindexOrderBuilder>>

      Initialized builder instance for further operations