@accret/bridge-sdk
Version:
56 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getQuote = getQuote;
const ethers_1 = require("ethers");
const index_1 = require("../../constants/index");
async function getQuote(params) {
const srcChainId = params.srcChain;
const dstChainId = params.dstChain;
const amountInAtomicUnits = (0, ethers_1.parseUnits)(params.srcChainTokenInAmount, params.srcTokenDecimals);
if (srcChainId === dstChainId) {
const queryParams = new URLSearchParams({
chainId: srcChainId,
tokenIn: params.srcChainTokenIn,
tokenInAmount: amountInAtomicUnits.toString(),
slippage: params.slippage?.toString() || "auto",
tokenOut: params.dstChainTokenOut,
affiliateFeeRecipient: params.affiliateFeeRecipient,
affiliateFeePercent: params.affiliateFeePercent
? params.affiliateFeePercent.toString()
: "0",
});
const response = await fetch(`${index_1.DEBRIDGE_API}/chain/estimation?${queryParams}`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to get quote: ${response.statusText}. ${errorText}`);
}
const result = (await response.json());
return result;
}
else {
const queryParams = new URLSearchParams({
srcChainId: srcChainId,
srcChainTokenIn: params.srcChainTokenIn,
dstChainId: dstChainId,
srcChainTokenInAmount: amountInAtomicUnits.toString(),
dstChainTokenOut: params.dstChainTokenOut,
slippage: params.slippage?.toString() || "auto",
affiliateFeePercent: params.affiliateFeePercent
? params.affiliateFeePercent.toString()
: "0",
prependOperatingExpenses: "false",
affiliateFeeRecipient: params.affiliateFeeRecipient ||
"0x39845CA4AC1D64a9065327Aa641BB656c36c66fd",
skipSolanaRecipientValidation: "false",
srcChainPriorityLevel: "normal",
});
const response = await fetch(`${index_1.DEBRIDGE_API}/dln/order/create-tx?${queryParams}`);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to create order: ${response.statusText}. ${errorText}`);
}
const result = (await response.json());
return result;
}
}
//# sourceMappingURL=getQuote.js.map