Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CrossChainManager

Contains method to calculate best cross chain trade.

Hierarchy

  • CrossChainManager

Index

Constructors

Properties

tradeProviders: Readonly<Record<"RUBIC" | "CELER" | "SYMBIOSIS" | "LIFI" | "DEBRIDGE" | "VIA" | "RANGO", CrossChainTradeProvider>> = ...

Methods

  • calculateTrade(fromToken: Token | { address: string; blockchain: BlockchainName }, fromAmount: string | number, toToken: Token | { address: string; blockchain: BlockchainName }, options?: Omit<SwapManagerCrossChainCalculationOptions, "providerAddress">): Promise<WrappedCrossChainTrade[]>
  • Calculates cross chain trades and sorts them by exchange courses. Wrapped trade object may contain error, but sometimes course can be calculated even with thrown error (e.g. min/max amount error).

    example
    const fromBlockchain = BLOCKCHAIN_NAME.ETHEREUM;
    // ETH
    const fromTokenAddress = '0x0000000000000000000000000000000000000000';
    const fromAmount = 1;
    const toBlockchain = BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN;
    // BUSD
    const toTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56';

    const wrappedTrades = await sdk.crossChain.calculateTrade(
    { blockchain: fromBlockchain, address: fromTokenAddress },
    fromAmount,
    { blockchain: toBlockchain, address: toTokenAddress }
    );
    const bestTrade = wrappedTrades[0];

    wrappedTrades.forEach(wrappedTrade => {
    if (wrappedTrade.trade) {
    console.log(wrappedTrade.tradeType, `to amount: ${wrappedTrade.trade.to.tokenAmount.toFormat(3)}`));
    }
    if (wrappedTrade.error) {
    console.error(wrappedTrade.tradeType, 'error: wrappedTrade.error');
    }
    });

    Parameters

    • fromToken: Token | { address: string; blockchain: BlockchainName }

      Token to sell.

    • fromAmount: string | number

      Amount to sell.

    • toToken: Token | { address: string; blockchain: BlockchainName }

      Token to get.

    • Optional options: Omit<SwapManagerCrossChainCalculationOptions, "providerAddress">

      Additional options.

    Returns Promise<WrappedCrossChainTrade[]>

    Array of sorted wrapped cross chain trades with possible errors.

  • calculateTradesReactively(fromToken: Token | { address: string; blockchain: BlockchainName }, fromAmount: string | number, toToken: Token | { address: string; blockchain: BlockchainName }, options?: Omit<SwapManagerCrossChainCalculationOptions, "providerAddress">): Observable<CrossChainProviderData>
  • Calculates cross chain trades reactively in sequence. Contains wrapped trade object which may contain error, but sometimes course can be calculated even with thrown error (e.g. min/max amount error).

    example
    const fromBlockchain = BLOCKCHAIN_NAME.ETHEREUM;
    // ETH
    const fromTokenAddress = '0x0000000000000000000000000000000000000000';
    const fromAmount = 1;
    const toBlockchain = BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN;
    // BUSD
    const toTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56';

    sdk.crossChain.calculateTrade(
    { blockchain: fromBlockchain, address: fromTokenAddress },
    fromAmount,
    { blockchain: toBlockchain, address: toTokenAddress }
    ).subscribe(tradeData => {
    console.log(tradeData.totalProviders) // 3
    console.log(tradeData.calculatedProviders) // 0 -> 1 -> ... -> totalProviders
    if (tradeData.bestTrade.trade) {
    console.log(wrappedTrade.tradeType, `to amount: ${wrappedTrade.trade.to.tokenAmount.toFormat(3)}`));
    }
    if (tradeData.bestTrade.error) {
    console.error(wrappedTrade.tradeType, 'error: wrappedTrade.error');
    }
    });

    Parameters

    • fromToken: Token | { address: string; blockchain: BlockchainName }

      Token to sell.

    • fromAmount: string | number

      Amount to sell.

    • toToken: Token | { address: string; blockchain: BlockchainName }

      Token to get.

    • Optional options: Omit<SwapManagerCrossChainCalculationOptions, "providerAddress">

      Additional options.

    Returns Observable<CrossChainProviderData>

    Observable of cross chain providers calculation data with best trade and possible errors.

Generated using TypeDoc