Best Route

Returns Best Route via Fibrous Finance

async getBestRoute(
    amount: BigNumber,
    tokenInAddress: string,
    tokenOutAddress: string,
    options?: Partial<RouteOverrides>,
): Promise<RouteResponse> 
 type RouteOverrides = {
    reverse: boolean;
    direct: boolean;
    excludeProtocols: string[];
};
  • excludeProtocols: This is where you list the IDs of the AMMs you don't want to include. For example, if there are certain AMMs you prefer not to use due to high fees or other reasons, you simply put their unique IDs in this list. supportPairs : This function returns a list of supported AMMs, along with the AMM IDs.

RouteResponse

type RouteSuccess = {
    success: true;
    inputToken: Token;
    inputAmount: string;
    outputToken: Token;
    outputAmount: string;
    estimatedGasUsed: string;
    route: Route[];
    time: number;
};

Example usage

import { Router as FibrousRouter } from "fibrous-router-sdk";
import { BigNumber } from "@ethersproject/bignumber";
import { parseUnits } from "ethers";

const router = new FibrousRouter();

const tokenInAddress = tokens["eth"].address;
const tokenOutAddress = tokens["usdc"].address;
const tokenInDecimals = tokens["eth"].decimals;
const inputAmount = BigNumber.from(parseUnits("1", tokenInDecimals)); // for 1 Ether

const route = await fibrous.getBestRoute(
    inputAmount, // amount
    tokenInAddress, // token input
    tokenOutAddress, // token output
); 

Last updated