There are two types of token-swap quotes you can get from Dexible: spot and execution. Spot quotes are just the market average exchange rate between two tokens. Execution quotes will generate an execution plan and split an order into multiple rounds to minimize price impact on the market. Both of these are done through Dexible's 'exchange' property.


Dexible continues to evolve in automating DeFi interactions. In the future, it will support more than simple token swaps. As such, Dexible V2.0 is a step towards separating the types of automations that can be done on Dexible. The 'exchange' property is an instance of a TokenExchange which handles all things token-swap related, including getting quotes.

Spot Quote

To get a spot quote, you just have supply the two tokens being exchanged and a current market price is provided.

const {price} = sdk.exchange.spotRate({
    baseToken: weth,
    quoteToken: usdc,

The price above is a decimal number representing the price expressed in quoteToken units. In this case, it would be expressed in USDC.

Execution Quote

To generate an execution plan, Dexible needs to know what type of order you want to execute. There are 7 order types supported (see Algos section). In most cases, a MarketSwap type is all that's needed to get an idea of Dexible's execution plan. Here is an example that also includes some customizations for a quote using a TWAP swap. It includes DexFilters that will limit the DEXs included in Dexible's execution plan. We will discuss those more later.

const twap = new TWAPSwap({
    amountIn:  units.inBNETH(".1"),
    tokenIn: WETH[Networks.EthereumGoerli.chainId],
    tokenOut: UNI[Networks.EthereumGoerli.chainId],
    slippage: new Slippage(.5, false),
    timeWindowSeconds: 3600,
    priceRange: {
        basePrice: new Price({
            inAmount: units.inBNETH(".63"),
            inToken: WETH[Networks.EthereumGoerli.chainId],
            outAmount: units.inBNETH("1"),
            outToken: UNI[Networks.EthereumGoerli.chainId]
        upperBoundPercent: 5
    customizations: {
        dexFilters: {
            include: [GoerliDexFilter.SushiSwap]

const q = await dex.exchange.quote(twap);

Dexible will return a quote that represents a recommended execution plan based on specified details. It includes a min/max amount out, which represents before/after slippage but always AFTER fees have been deducted. Note that gas fees are estimates at the time of the quote. The value may vary if the gas market is volatile. Here is an example that uses a fixed gas price so that Dexible will only execute the swap when gas prices are at or below a specified rate:

Swap Customizations

const twap = new TWAPSwap({
    customizations: {
        dexFilters: {
            include: [GoerliDexFilter.SushiSwap]
        maxGasPriceGwei: 50,
        //can also limit the number of segments or rounds the
        //order is broken into
        //maxNumberRounds: 2

const q = await dex.exchange.quote(twap);

Here is the expected output from a quote request:

  id: 'bagaaierayqbbhep36rt45fopah6wnfdzry2767lnpjwf24ukqhj37js3fyjq',
  minAmountOut: BigNumber { _hex: '0x4b013278', _isBigNumber: true },
  maxAmountOut: BigNumber { _hex: '0x4b014359', _isBigNumber: true },
  bpsFee: BigNumber { _hex: '0x02d79883d20000', _isBigNumber: true },
  feeToken: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18,
    symbol: 'WETH',
    name: 'Wrapped ETH',
    chainId: 1
  rounds: 1,
  totalEstimatedGasFees: BigNumber { _hex: '0x2ee5547da95e5b', _isBigNumber: true 

Most of the fields are self-explanatory. Note the min/max amount out. Both of these are after the bps and estimated gas fees are applied. The feeToken represents the token used to capture fees. Rounds is the number of segments an order will be split into. The total estimated gas is an estimate of all gas fees for all rounds in the order. It's based on current gas prices or the fixed gas price you provided.

Quotes provide min/max amounts due to the slippage applied to the round. In some cases, full slippage may be realized in the market while other times, no slippage will occur. This gives a best/worst case scenario or min/max.

Last updated