Swapping
Integrations
Javascript SDK
Get Quote
Get Quote V2

Get Quote V2

getQuoteV2()

Fetches the quotes for swapping tokens based on the provided quoteRequest and an options argument. Currently quotes can be either a normal quote or a DCA one. The DCA quote will contain dcaParams which can be passed to requestDepositAddress to open a DCA swapping channel. In case of a DCA quote, boostQuote inside the DCA quote object inherits dcaParams from its parent. So to summarize, the main difference from the old version (getQuote) is that the new version returns a list of quotes (REGULAR or DCA) instead of a single one.

getQuoteV2(
  quoteRequest: QuoteRequest,
  options?: RequestOptions
): Promise<QuoteResponseV2>

Request

ParamDescriptionData type
quoteRequest(required)Object containing the quote request parameters. You can find the interface definition below.Object
options(optional)Options related to the HTTP request.Object

The quoteRequest object describes the swap for which a quote is returned.

ParamDescriptionData type
srcChain(required)Source chain for the swapChain
destChain(required)Destination chain for the swapChain
srcAsset(required)Asset to be swapped from the source chainAsset
destAsset(required)Asset to be received on the destination chainAsset
amount(required)Amount of the source token to be swapped, represented in the base unit of the source tokenstring
brokerCommissionBps(optional)Commission charged by the broker in basis points. If given, the value will be used instead of the brokerCommissionBps passed when initializing the SDK instancenumber
affiliateBrokers(optional)Array of objects describing the affiliate brokers that charge a commissionArray

Quote request example

import { Chains, Assets } from "@chainflip/sdk/swap";
 
const quoteRequest = {
  srcChain: Chains.Ethereum,
  destChain: Chains.Bitcoin,
  srcAsset: Assets.ETH,
  destAsset: Assets.BTC,
  amount: (1.5e18).toString(), // 1.5 ETH
  brokerCommissionBps: 100, // 100 basis point = 1%
  affiliateBrokers: [
    { account: "cFM8kRvLBXagj6ZXvrt7wCM4jGmHvb5842jTtXXg3mRHjrvKy", commissionBps: 50 }
  ],
};
 
console.log(await swapSDK.getQuoteV2(quoteRequest));

Response

Response type

type QuoteDetails = {
  intermediateAmount?: string;
  egressAmount: string;
  includedFees: SwapFee[];
  poolInfo: PoolInfo[];
  lowLiquidityWarning: boolean | undefined; // see below
  estimatedDurationSeconds: number; // estimated time until destination asset is received by the user
  estimatedPrice: string; // estimated price of the swap at amm level (does not include deposit/broadcast fee)
};
type BoostedQuoteDetails = QuoteDetails & {
   estimatedBoostFeeBps: number // estimated fee (in bps) that the user has to pay (from the deposit amount) to get this swap boosted
};
 
export type QuoteType = 'REGULAR' | 'DCA';
 
export interface QuoteResponseV2 {
  srcChain: Chain;
  srcAsset: Asset;
  destChain: Chain;
  destAsset: Asset;
  amount: string;
  quotes: (
    QuoteDetails & {
      boostQuote?: BoostedQuoteDetails // Only present if there is a boost opportunity for the requested swap amount
      dcaParams?: { // Only present if the quote is a DCA quote. These parameters can be passed to requestDepositAddress
        numberOfChunks: number;
        chunkIntervalBlocks: number;
      };
      type: QuoteType;
    }
  )[];
}

lowLiquidityWarning: This value is true if the difference in the chainflip swap rate (excluding fees) is lower than the global index rate of the swap by more than a certain threshold (currently set to 5%). This suggets there is not enough liquidity in the pool.

The intermediate amount is the value of the first swap leg. In this case, BTC > ETH requires both BTC/USDC and USDC/ETH pools (or legs).

Learn more about Chainflip's $USDC Denominated Pools.

Example

[
  {
    "intermediateAmount": "903561429", // 903.561 USDC
    "egressAmount": "851177150773322479", // 0.8511 ETH
    "includedFees": [
      { "type": "INGRESS", "chain": "Bitcoin", "asset": "BTC", "amount": "78" },
      {
        "type": "NETWORK",
        "chain": "Ethereum",
        "asset": "USDC",
        "amount": "904466"
      },
      {
        "type": "EGRESS",
        "chain": "Ethereum",
        "asset": "ETH",
        "amount": "490000"
      }
    ],
    "lowLiquidityWarning": true,
    "poolInfo": [
      {
        "baseAsset": { "chain": "Bitcoin", "asset": "BTC" },
        "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
        "fee": { "chain": "Bitcoin", "asset": "BTC", "amount": "199" }
      },
      {
        "baseAsset": { "chain": "Ethereum", "asset": "ETH" },
        "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
        "fee": { "chain": "Ethereum", "asset": "USDC", "amount": "18071" }
      }
    ],
    "estimatedDurationSeconds": 1830,
    "estimatedPrice": "0.05",
    "dcaParams": {
      "chunkIntervalBlocks": 2,
      "numberOfChunks": 1
    },
    "type": "DCA",
    "boostQuote": {
      "intermediateAmount": "903113911", // 903.113 USDC
      "egressAmount": "850759257276222562", // 0.8507592
      "includedFees": [
        { "type": "BOOST", "chain": "Bitcoin", "asset": "BTC", "amount": "5000" },
        { "type": "INGRESS", "chain": "Bitcoin", "asset": "BTC", "amount": "78" },
        {
          "type": "NETWORK",
          "chain": "Ethereum",
          "asset": "USDC",
          "amount": "904018"
        },
        {
          "type": "EGRESS",
          "chain": "Ethereum",
          "asset": "ETH",
          "amount": "490000"
        }
      ],
      "lowLiquidityWarning": true,
      "poolInfo": [
        {
          "baseAsset": { "chain": "Bitcoin", "asset": "BTC" },
          "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
          "fee": { "chain": "Bitcoin", "asset": "BTC", "amount": "199" }
        },
        {
          "baseAsset": { "chain": "Ethereum", "asset": "ETH" },
          "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
          "fee": { "chain": "Ethereum", "asset": "USDC", "amount": "18062" }
        }
      ],
      "type": "DCA",
      "estimatedDurationSeconds": 630,
      "estimatedPrice": "0.05",
      "estimatedBoostFeeBps": 5
    }
  },
  {
    "intermediateAmount": "903561429", // 903.561 USDC
    "egressAmount": "851177150773322479", // 0.8511 ETH
    "includedFees": [
      { "type": "INGRESS", "chain": "Bitcoin", "asset": "BTC", "amount": "78" },
      {
        "type": "NETWORK",
        "chain": "Ethereum",
        "asset": "USDC",
        "amount": "904466"
      },
      {
        "type": "EGRESS",
        "chain": "Ethereum",
        "asset": "ETH",
        "amount": "490000"
      }
    ],
    "lowLiquidityWarning": true,
    "poolInfo": [
      {
        "baseAsset": { "chain": "Bitcoin", "asset": "BTC" },
        "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
        "fee": { "chain": "Bitcoin", "asset": "BTC", "amount": "199" }
      },
      {
        "baseAsset": { "chain": "Ethereum", "asset": "ETH" },
        "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
        "fee": { "chain": "Ethereum", "asset": "USDC", "amount": "18071" }
      }
    ],
    "estimatedDurationSeconds": 1830,
    "estimatedPrice": "0.05",
    "type": "REGULAR",
    "boostQuote": {
      "intermediateAmount": "903113911", // 903.113 USDC
      "egressAmount": "850759257276222562", // 0.8507592
      "includedFees": [
        { "type": "BOOST", "chain": "Bitcoin", "asset": "BTC", "amount": "5000" },
        { "type": "INGRESS", "chain": "Bitcoin", "asset": "BTC", "amount": "78" },
        {
          "type": "NETWORK",
          "chain": "Ethereum",
          "asset": "USDC",
          "amount": "904018"
        },
        {
          "type": "EGRESS",
          "chain": "Ethereum",
          "asset": "ETH",
          "amount": "490000"
        }
      ],
      "lowLiquidityWarning": true,
      "poolInfo": [
        {
          "baseAsset": { "chain": "Bitcoin", "asset": "BTC" },
          "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
          "fee": { "chain": "Bitcoin", "asset": "BTC", "amount": "199" }
        },
        {
          "baseAsset": { "chain": "Ethereum", "asset": "ETH" },
          "quoteAsset": { "chain": "Ethereum", "asset": "USDC" },
          "fee": { "chain": "Ethereum", "asset": "USDC", "amount": "18062" }
        }
      ],
      "type": "REGULAR",
      "estimatedDurationSeconds": 630,
      "estimatedPrice": "0.05",
      "estimatedBoostFeeBps": 5
    }
  }
]