Function marketOrder

  • Executes a market order on the specified chain for trading tokens. If only amountIn is provided, spend the specified amount of input tokens. If only amountOut is provided, take the specified amount of output tokens.

    Parameters

    • __namedParameters: {
          chainId: CHAIN_IDS;
          userAddress: `0x${string}`;
          inputToken: `0x${string}`;
          outputToken: `0x${string}`;
          amountIn?: string;
          amountOut?: string;
          options?: {
              erc20PermitParam?: ERC20PermitParam;
              slippage?: number;
              roundingDownTakenBid?: boolean;
              roundingUpTakenAsk?: boolean;
              useSubgraph?: boolean;
          } & DefaultOptions & {
              gasLimit?: bigint;
              gasPriceLimit?: bigint;
          };
      }
      • chainId: CHAIN_IDS
      • userAddress: `0x${string}`
      • inputToken: `0x${string}`
      • outputToken: `0x${string}`
      • Optional amountIn?: string
      • Optional amountOut?: string
      • Optional options?: {
            erc20PermitParam?: ERC20PermitParam;
            slippage?: number;
            roundingDownTakenBid?: boolean;
            roundingUpTakenAsk?: boolean;
            useSubgraph?: boolean;
        } & DefaultOptions & {
            gasLimit?: bigint;
            gasPriceLimit?: bigint;
        }

    Returns Promise<{
        transaction: Transaction;
        result: {
            taken: CurrencyFlow & {
                events: {
                    price: string;
                    amount: string;
                }[];
            };
            spent: CurrencyFlow & {
                events: {
                    price: string;
                    amount: string;
                }[];
            };
        };
    }>

    Promise resolving to the transaction object representing the market order with the result of the order.

    Example

    import { marketOrder } from '@clober/v2-sdk'
    import { privateKeyToAccount } from 'viem/accounts'

    const transaction = await marketOrder({
    chainId: 421614,
    userAddress: '0xF8c1869Ecd4df136693C45EcE1b67f85B6bDaE69
    inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
    outputToken: '0x0000000000000000000000000000000000000000',
    amount: '100.123', // 100.123 USDC
    options: { erc20PermitParam }
    })