Skip to content

useQuote

The useQuote hook is your first step in using Omni SolverNet. It fetches the real-time cost for a potential cross-chain action by calculating the relationship between:

  • Deposit: The asset and amount the user pays on the source chain to initiate the action.
  • Expense: The asset and amount the solver spends on the destination chain to execute your desired action (e.g., the amount deposited into a target vault).

Based on the mode you select, the hook calculates either:

  1. The required deposit for a fixed expense.
  2. The output expense for a fixed deposit.

This quote accounts for solver fees and current market conditions.

Usage

import { useQuote } from '@omni-network/react'

import { useQuote } from '@omni-network/react'
 
function Component() {
  const quote = useQuote({
    // ... params
  });
}

Parameters

Crucially, a quote requires fixing either the deposit amount or the expense amount. You tell the hook which one you're fixing using the mode parameter.

The hook accepts a configuration object with the following properties.

PropTypeRequiredDescription
srcChainIdnumberYesChain ID of the source chain (where the user provides the deposit).
destChainIdnumberYesChain ID of the destination chain (where the action occurs and the expense is spent).
depositQuoteAsset & { amount?: bigint }YesAasset to deposit on the source chain. Provide amount only if using mode: 'expense'.
expenseQuoteAsset & { amount?: bigint }YesAsset to spend on the destination chain. Provide amount only if using mode: 'deposit'.
mode'deposit' | 'expense'YesDefines the direction of the quote.
enabledbooleanNoDefaults to true. Set to false to disable fetching the quote.
queryOptsUseQueryOptions<Quote, QuoteError>NoReact query options, we omit some keys here (enabled, queryKey, and queryFn) to prevent overriding some default behaviour. See useQuery docs for available options.

Types

QuoteAsset

type QuoteAsset =
  | { isNative: true; token?: never } // For native ETH
  | { isNative?: false; token: Address } // For ERC20 tokens

Describes deposit and expense paramaters shape.

Quote

export type Quote = {
  deposit: { token: Address; amount: bigint }
  expense: { token: Address; amount: bigint }
}

Describes a successful quote return.

Return

useQuote returns a quote and the query object from @tanstack/react-query. Consult their documentation for all available properties.

isPending

boolean

Is true before a quote response is received.

isSuccess

boolean

Is true when the quote call succeeds.

isError

boolean

Is true when the quote call fails.

quote

{ deposit: { token: Address; amount: bigint } expense: { token: Address; amount: bigint } }

Only available when isSuccess is true.

if (res.isSuccess) res.quote.deposit

error

Only available when isError is true.

if (res.isError) res.error

Use the quote return (specifically quote.deposit.amount and quote.expense.amount) to inform the parameters for useOrder.

Examples

Quote Expense

To find out how much wstETH can be spent on Holesky for a deposit of 0.1 wstETH from Base Sepolia:

const quote = useQuote({
  srcChainId: baseSepolia.id,
  destChainId: holesky.id,
  deposit: { isNative: false, token: baseSepoliaWSTETH, amount: parseEther("0.1") },
  expense: { isNative: false, token: holeskyWSTETH }, // note - when mode: "expense" we don't supply expense.amount
  mode: "expense", // quote expense amount
  enabled: true,
})
 
if (quote.isSuccess) {
  console.log(`Depositing ${quote.deposit.amount} yields ${quote.expense.amount} on destination`);
}

Quote Deposit

To find out how much wstETH needs to be deposited on Base Sepolia to spend exactly 0.1 wstETH on Holesky:

const quote = useQuote({
  srcChainId: baseSepolia.id,
  destChainId: holesky.id,
  deposit: { isNative: false, token: baseSepoliaWSTETH }, // note - when mode: "expense" we don't supply expense.amount
  expense: { isNative: false, token: holeskyWSTETH, amount: parseEther("0.1") },
  mode: "deposit", // quote deposit amount
  enabled: true,
})
 
if (quote.isSuccess) {
  console.log(`Spending ${quote.data.expense.amount} requires depositing ${quote.data.deposit.amount} on source`);
}