Function getExpectedInput

  • Calculates the expected input for a given output amount, based on the provided market data.

    Parameters

    • __namedParameters: {
          chainId: CHAIN_IDS;
          inputToken: `0x${string}`;
          outputToken: `0x${string}`;
          amountOut: string;
          options?: {
              limitPrice?: string;
              roundingDownTakenBid?: boolean;
              roundingUpTakenAsk?: boolean;
              useSubgraph?: boolean;
          } & DefaultOptions;
      }
      • chainId: CHAIN_IDS
      • inputToken: `0x${string}`
      • outputToken: `0x${string}`
      • amountOut: string
      • Optional options?: {
            limitPrice?: string;
            roundingDownTakenBid?: boolean;
            roundingUpTakenAsk?: boolean;
            useSubgraph?: boolean;
        } & DefaultOptions

    Returns Promise<{
        takenAmount: string;
        spentAmount: string;
        bookId: bigint;
        events: {
            price: string;
            takenAmount: string;
            spentAmount: string;
        }[];
    }>

    A Promise resolving to an object containing the taken amount, spent amount and result of the calculation.

    Example

    import { getExpectedInput } from '@clober/v2-sdk'

    const { takenAmount, spentAmount } = await getExpectedInput({
    chainId: 421614,
    inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
    outputToken: '0x0000000000000000000000000000000000000000',
    amountOut: '0.1', // take 0.1 ETH
    })