Get Quote
getQuote
Fetches a quote for swapping tokens based on the provided quoteRequest
and an options
argument.
getQuote(
quoteRequest: QuoteRequest,
options?: RequestOptions
): Promise<QuoteResponse>
Request
Param | Description | Data 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.
Param | Description | Data type |
---|---|---|
srcChain (required) | Source chain for the swap | Chain |
destChain (required) | Destination chain for the swap | Chain |
srcAsset (required) | Asset to be swapped from the source chain | Asset |
destAsset (required) | Asset to be received on the destination chain | Asset |
amount (required) | Amount of the source token to be swapped, represented in the base unit of the source token | string |
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 instance | number |
affiliateBrokers (optional) | Array of objects describing the affiliate brokers that charge a commission | Array |
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.getQuote(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 interface QuoteResponse {
srcChain: Chain;
srcAsset: Asset;
destChain: Chain;
destAsset: Asset;
amount: string;
quote: QuoteDetails & {
boostQuote?: BoostedQuoteDetails // Only present if there is a boost opportunity for the requested swap amount
};
}
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",
"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" }
}
],
"estimatedDurationSeconds": 630,
"estimatedPrice": "0.05",
"estimatedBoostFeeBps": 5
}
}