Documentation
    Preparing search index...

    DeepBookClient class for managing DeepBook operations.

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Parameters

      • __namedParameters: {
            address: string;
            adminCap?: string;
            balanceManagers?: { [key: string]: BalanceManager };
            client: SuiJsonRpcClient;
            coins?: CoinMap;
            env: Environment;
            marginAdminCap?: string;
            marginMaintainerCap?: string;
            marginManagers?: { [key: string]: MarginManager };
            pools?: PoolMap;
        }

      Returns DeepBookClient

    Properties

    balanceManager: BalanceManagerContract
    client: SuiJsonRpcClient
    deepBookAdmin: DeepBookAdminContract
    flashLoans: FlashLoanContract
    governance: GovernanceContract
    marginAdmin: MarginAdminContract
    marginMaintainer: MarginMaintainerContract
    marginManager: MarginManagerContract
    marginPool: MarginPoolContract
    marginRegistry: MarginRegistryContract

    Methods

    • Parameters

      • poolKey: string

        Key of the pool

      • managerKey: string

        The key of the BalanceManager

      Returns Promise<
          {
              active_stake: number;
              created_proposal: boolean;
              epoch: string;
              inactive_stake: number;
              maker_volume: number;
              open_orders: { contents: string[] };
              owed_balances: { base: number; deep: number; quote: number };
              settled_balances: { base: number; deep: number; quote: number };
              taker_volume: number;
              unclaimed_rebates: { base: number; deep: number; quote: number };
              voted_proposal: null | string;
          },
      >

      A promise that resolves to an object containing the account information

      Get the account information for a given pool and balance manager

    • Parameters

      • poolKey: string

        Key of the pool

      • managerKey: string

        Key of the balance manager

      Returns Promise<string[]>

      An array of open order IDs

      Get open orders for a balance manager in a pool

    • Parameters

      • managerKey: string

        Key of the balance manager

      • coinKey: string

        Key of the coin

      Returns Promise<{ balance: number; coinType: string }>

      An object with coin type and balance

      Check the balance of a balance manager for a specific coin

    • Parameters

      • encodedOrderId: bigint

        Encoded order ID

      Returns { isBid: boolean; orderId: number; price: number }

      Object containing isBid, price, and orderId

      Decode the order ID to get bid/ask status, price, and orderId

    • Returns Promise<string[]>

      Array of allowed maintainer cap IDs

      Get all allowed maintainer cap IDs

    • Returns Promise<string[]>

      Array of allowed pause cap IDs

      Get all allowed pause cap IDs

    • Parameters

      • owner: string

        The owner address to get balance manager IDs for

      Returns Promise<string[]>

      Array of balance manager ID strings

      Get all balance manager IDs for a given owner

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<string>

      The base margin pool ID

      Get the base margin pool ID for a deepbook pool

    • Parameters

      • poolKey: string

        Key of the pool

      • quoteQuantity: number

        Quote quantity to convert

      Returns Promise<
          {
              baseOut: number;
              deepRequired: number;
              quoteOut: number;
              quoteQuantity: number;
          },
      >

      An object with quote quantity, base out, quote out, and deep required for the dry run

      Get the base quantity out for a given quote quantity

    • Parameters

      • poolKey: string

        Key of the pool

      • priceLow: number

        Lower bound of the price range

      • priceHigh: number

        Upper bound of the price range

      • isBid: boolean

        Whether to get bid or ask orders

      Returns Promise<{ prices: number[]; quantities: number[] }>

      An object with arrays of prices and quantities

      Get level 2 order book specifying range of price

    • Parameters

      • poolKey: string

        Key of the pool

      • ticks: number

        Number of ticks from mid-price

      Returns Promise<
          {
              ask_prices: number[];
              ask_quantities: number[];
              bid_prices: number[];
              bid_quantities: number[];
          },
      >

      An object with arrays of prices and quantities

      Get level 2 order book ticks from mid-price for a pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The liquidation risk ratio as a decimal (e.g., 1.125 for 112.5%)

      Get the liquidation risk ratio for a deepbook pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<{ baseAsset: string; quoteAsset: string }>

      The base and quote assets

      Calculate assets (base and quote) for a margin manager

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<string>

      The balance manager ID

      Get the balance manager ID for a margin manager

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<string>

      The borrowed base shares

      Get borrowed base shares

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<string>

      The borrowed quote shares

      Get borrowed quote shares

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<{ baseShares: string; quoteShares: string }>

      The borrowed shares

      Get borrowed shares for both base and quote assets

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<{ baseDebt: string; quoteDebt: string }>

      The base and quote debts

      Calculate debts (base and quote) for a margin manager NOTE: This function automatically determines whether to use base or quote margin pool based on hasBaseDebt. You don't need to specify the debt coin type.

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<string>

      The DeepBook pool ID

      Get the DeepBook pool ID associated with a margin manager

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<boolean>

      True if has base debt, false otherwise

      Check if margin manager has base asset debt

    • Parameters

      • owner: string

        The owner address

      Returns Promise<string[]>

      Array of margin manager IDs

      Get the margin manager IDs for a given owner address

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<null | string>

      The margin pool ID or null if no active loan

      Get the margin pool ID (if any) associated with a margin manager

    • Parameters

      • poolKey: string

        The key to identify the pool

      • marginManagerId: string

        The ID of the margin manager

      Returns Promise<string>

      The owner address

      Get the owner address of a margin manager

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The total borrow shares as a string

      Get the total borrow shares in the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      Returns Promise<string>

      The margin pool ID

      Get the margin pool ID

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      Returns Promise<number>

      The current interest rate (as a decimal)

      Get the current interest rate of the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      Returns Promise<number>

      The last update timestamp in milliseconds

      Get the last update timestamp of the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      Returns Promise<number>

      The max utilization rate (as a decimal, e.g., 0.95 for 95%)

      Get the max utilization rate of the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The minimum borrow amount as a string

      Get the minimum borrow amount for the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      Returns Promise<number>

      The protocol spread (as a decimal)

      Get the protocol spread of the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The supply cap as a string

      Get the supply cap of the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The total supply shares as a string

      Get the total supply shares in the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The total borrow amount as a string

      Get the total borrow amount in the margin pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The total supply amount as a string

      Get the total supply amount in the margin pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The minimum borrow risk ratio as a decimal (e.g., 1.25 for 125%)

      Get the minimum borrow risk ratio for a deepbook pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The minimum withdraw risk ratio as a decimal (e.g., 1.5 for 150%)

      Get the minimum withdraw risk ratio for a deepbook pool

    • Parameters

      • poolKey: string

        Key of the pool

      • orderId: string

        Order ID

      Returns Promise<
          | null
          | {
              balance_manager_id: string;
              client_order_id: string;
              epoch: string;
              expire_timestamp: string;
              fee_is_deep: boolean;
              filled_quantity: string;
              order_deep_price: { asset_is_base: boolean; deep_per_asset: string };
              order_id: string;
              quantity: string;
              status: number;
          },
      >

      A promise that resolves to an object containing the order information

      Get the order information for a specific order in a pool

    • Parameters

      • poolKey: string

        Key of the pool

      • orderId: string

        Order ID

      Returns Promise<
          | null
          | {
              balance_manager_id: string;
              client_order_id: string;
              epoch: string;
              expire_timestamp: string;
              fee_is_deep: boolean;
              filled_quantity: string;
              isBid: boolean;
              normalized_price: string;
              order_deep_price: { asset_is_base: boolean; deep_per_asset: string };
              order_id: string;
              quantity: string;
              status: number;
          },
      >

      A promise that resolves to an object containing the order information with normalized price

      Get the order information for a specific order in a pool, with normalized price

    • Parameters

      • poolKey: string

        The key identifying the pool from which to retrieve order information.

      • orderIds: string[]

        List of order IDs to retrieve information for.

      Returns Promise<
          | null
          | {
              balance_manager_id: string;
              client_order_id: string;
              epoch: string;
              expire_timestamp: string;
              fee_is_deep: boolean;
              filled_quantity: string;
              order_deep_price: { asset_is_base: boolean; deep_per_asset: string };
              order_id: string;
              quantity: string;
              status: number;
          }[],
      >

      A promise that resolves to an array of order objects, each containing details such as balance manager ID, order ID, client order ID, quantity, filled quantity, fee information, order price, epoch, status, and expiration timestamp. Returns null if the retrieval fails.

      Retrieves information for multiple specific orders in a pool.

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<
          | {
              asset_is_base: true;
              deep_per_base: number;
              deep_per_quote?: undefined;
          }
          | {
              asset_is_base: false;
              deep_per_base?: undefined;
              deep_per_quote: number;
          },
      >

      Deep price conversion

      Get the DEEP price conversion for a pool

    • Parameters

      • baseType: string

        Type of the base asset

      • quoteType: string

        Type of the quote asset

      Returns Promise<string>

      The address of the pool

      Get the pool ID by asset types

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The pool liquidation reward as a decimal (e.g., 0.05 for 5%)

      Get the pool liquidation reward for a deepbook pool

    • Parameters

      • tx: Transaction
      • coinKey: string

      Returns Promise<string>

    • Parameters

      • coinKey: string

        Key of the coin

      Returns Promise<any>

      The arrival time of the price info object

      Get the age of the price info object for a specific coin

    • Parameters

      • poolKey: string

        Key of the pool

      • baseQuantity: number

        Base quantity to convert

      • quoteQuantity: number

        Quote quantity to convert

      Returns Promise<
          {
              baseOut: number;
              baseQuantity: number;
              deepRequired: number;
              quoteOut: number;
              quoteQuantity: number;
          },
      >

      An object with base quantity, quote quantity, base out, quote out, and deep required for the dry run

      Get the output quantities for given base and quote quantities. Only one quantity can be non-zero

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<string>

      The quote margin pool ID

      Get the quote margin pool ID for a deepbook pool

    • Parameters

      • poolKey: string

        Key of the pool

      • baseQuantity: number

        Base quantity to convert

      Returns Promise<
          {
              baseOut: number;
              baseQuantity: number;
              deepRequired: number;
              quoteOut: number;
          },
      >

      An object with base quantity, base out, quote out, and deep required for the dry run

      Get the quote quantity out for a given base quantity

    • Parameters

      • poolKey: string

        Key of the pool

      • referral: string

        The referral ID to get balances for

      Returns Promise<{ base: number; deep: number; quote: number }>

      Object with base, quote, and deep balances

      Get the referral balances for a pool and referral

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The target liquidation risk ratio as a decimal (e.g., 1.25 for 125%)

      Get the target liquidation risk ratio for a deepbook pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<number>

      The user liquidation reward as a decimal (e.g., 0.05 for 5%)

      Get the user liquidation reward for a deepbook pool

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • supplierCapId: string

        The ID of the supplier cap

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The user's supply amount as a string

      Get user supply amount for a supplier cap

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • supplierCapId: string

        The ID of the supplier cap

      • decimals: number = 6

        Number of decimal places to show (default: 6)

      Returns Promise<string>

      The user's supply shares as a string

      Get user supply shares for a supplier cap

    • Parameters

      • coinKey: string

        The key to identify the margin pool

      • deepbookPoolId: string

        The ID of the deepbook pool

      Returns Promise<boolean>

      Whether the deepbook pool is allowed

      Check if a deepbook pool is allowed for borrowing from margin pool

    • Parameters

      • poolKey: string

        The key to identify the pool

      Returns Promise<boolean>

      True if the pool is enabled for margin trading

      Check if a deepbook pool is enabled for margin trading

    • Parameters

      • poolKey: string

        Key of the pool

      • balanceManagerKey: string

      Returns Promise<{ base: number; deep: number; quote: number }>

      An object with base, quote, and deep locked for the balance manager in the pool

      Get the locked balances for a pool and balance manager

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<number>

      The mid price

      Get the mid price for a pool

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<{ lotSize: number; minSize: number; tickSize: number }>

      Get the trade parameters for a given pool, including tick size, lot size, and min size.

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<{ makerFee: number; stakeRequired: number; takerFee: number }>

      Get the trade parameters for a given pool, including taker fee, maker fee, and stake required.

    • Parameters

      • referral: string

        The ID of the referral to get the owner of

      Returns Promise<string>

      The owner of the referral

      Get the owner of the referral

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<{ base: number; deep: number; quote: number }>

      An object with base, quote, and deep balances in the vault

      Get the vault balances for a pool

    • Parameters

      • poolKey: string

        Key of the pool

      Returns Promise<boolean>

      Boolean indicating if the pool is whitelisted

      Check if a pool is whitelisted