@getclave/lifi-sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
41 lines (40 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertQuoteToRoute = void 0;
const SDKError_1 = require("../errors/SDKError");
const errors_1 = require("../errors/errors");
/**
* Converts a quote to Route
* @param quote - Step returned from the quote endpoint.
* @param txHash
* @param chainId
* @returns - The route to be executed.
* @throws {BaseError} Throws a ValidationError if the step has missing values.
*/
const convertQuoteToRoute = (quote) => {
if (!quote.estimate.fromAmountUSD) {
throw new SDKError_1.SDKError(new errors_1.ValidationError("Missing 'fromAmountUSD' in step estimate."));
}
if (!quote.estimate.toAmountUSD) {
throw new SDKError_1.SDKError(new errors_1.ValidationError("Missing 'toAmountUSD' in step estimate."));
}
const route = {
id: quote.id,
fromChainId: quote.action.fromToken.chainId,
fromToken: quote.action.fromToken,
fromAmount: quote.action.fromAmount,
fromAmountUSD: quote.estimate.fromAmountUSD,
fromAddress: quote.action.fromAddress,
toChainId: quote.action.toToken.chainId,
toToken: quote.action.toToken,
toAmount: quote.estimate.toAmount,
toAmountMin: quote.estimate.toAmountMin,
toAmountUSD: quote.estimate.toAmountUSD,
toAddress: quote.action.toAddress || quote.action.fromAddress,
gasCostUSD: quote.estimate.gasCosts?.[0].amountUSD,
steps: [quote],
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
};
return route;
};
exports.convertQuoteToRoute = convertQuoteToRoute;