Skip to content

Usage

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

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

Parameters

PropTypeRequiredDescription
srcChainIdnumberYesThe chain ID of the source chain. Must match useQuote.
destChainIdnumberYesThe chain ID of the destination chain. Must match useQuote.
depositDepositYesDescribes the asset and amount being deposited on the source chain (paid by the user) - taken from quote.deposit.
expenseExpenseYesDescribes the asset, amount, and spender on the destination chain (paid by the solver) - taken from quote.expense.
callsCall[]YesAn array of contract calls to be executed on the destination chain by the solver.
validateEnabledbooleanNoDefaults to true. Enables pre-validation of the order with Omni. Use this to validate your calls. Recommended to set based on quote.isSuccess.
debugValidationbooleanNoWhether to return the debug trace in the validation result or not (default)
omniContractsQueryOptsUseQueryOptions<OmniContracts>NoReact query options for loading the Omni contracts addresses, we omit some keys here (enabled, queryKey, and queryFn) to prevent overriding some default behaviour. See useQuery docs for available options.
didFillQueryOptsUseQueryOptions<boolean>NoReact query options for loading the filled status of the order, we omit some keys here (enabled, queryKey, and queryFn) to prevent overriding some default behaviour. See useQuery docs for available options.
rejectionQueryOptsUseQueryOptions<Rejection, GetRejectionError>NoReact query options for parsing the logs of the rejection event, we omit some keys here (enabled, queryKey, and queryFn) to prevent overriding some default behaviour. See useQuery docs for available options.

Types

Deposit

Describes the deposit parameter.

type Deposit = {
  readonly token?: Address
  readonly amount: bigint
}

Expense

Describes the expense parameter.

type Expense = {
  readonly spender?: Address
  readonly token?: Address
  readonly amount: bigint
}

Order

Describes the order to placed by the user.

export type Order<abis extends OptionalAbis> = {
  readonly owner?: Address
  readonly srcChainId?: number
  readonly destChainId: number
  readonly fillDeadline?: number
  readonly calls: Calls<abis>
  readonly deposit: Deposit
  readonly expense: Expense
}

Call

Describes a contract interaction on the destination chain.

type Call = {
  target: Address;      // The contract address to call
  abi: Abi;             // The ABI of the target contract
  functionName: string; // The function to call - type inferred from the abi
  args?: unknown[];     // Arguments for the function call - type inferred from the abi
  value?: bigint;       // ETH value to send with the call (optional)
}

Return

open

() => void

status

'initializing' | 'ready' | 'opening' | 'open' | 'closed' | 'rejected' | 'error' | 'filled'

Monitor the status to provide feedback to user's throughout the lifecycle of the cross-chain transaction.

validation

The result of the pre-validation check if validateEnabled is true.

{ status: 'pending' | 'rejected' | 'accepted', rejectReason?: string, rejectDescription?: string }

error

Error | undefined

Contains error information if status is 'error'.

isReady

boolean

true when the hook is initialized and ready to attempt opening the order (status is 'ready'). Does not imply validation passed.

txMutation

UseMutationResult<...>

The raw mutation result object from wagmi for the opening transaction.

txHash

Hex | undefined

The hash of the source chain transaction used to open the order.

destTxHash

Hex | undefined

The hash of the destination chain transaction that filled the order.

waitForTx

UseWaitForTransactionReceiptReturnType

The result object from wagmi's useWaitForTransactionReceipt for the opening transaction.

rejection

{ rejectReason: string, txHash: Hex } | undefined

If an order is rejected (by the solver), this rejection will contain the reject reason and the txHash of the Reject tx - read more here.

isValidated

boolean

true if the validation check has completed (regardless of outcome).

isOpen

boolean

true if the order has been successfully opened (status === 'open').

isError

boolean

true if status is 'error'.

isTxPending

boolean

true while the source chain transaction for opening the order is being submitted (part of 'opening' status).

isTxSubmitted

boolean

true once the source chain transaction has been submitted (part of 'opening' status).

Example

See our basic deposit example here.