import { isSolanaLike as e, isTronLike as t } from "../../constants/chains.constants.mjs";
import { zeroAddress as n } from "../../constants/protocol.constants.mjs";
import { callLifiAPI as r } from "../../API/callLifiAPI.mjs";
import { transactionErrorCodes as i } from "../../error-handling/error-codes.constants.mjs";
import { getAmountInWei as a } from "./etherFunctions.mjs";
import { getLifiChainId as o } from "../../constants/lifi.constants.mjs";
import { toTronBase58IfHex as s } from "../utils/tron.utils.mjs";
//#region libs/shared/common/src/functions/web3/lifiAPI.ts
var c = async (c, l, u, d, f, p) => {
	try {
		let i = a(c, u), m = t(l.chainId), { lifiResponse: h } = await r({
			fromChain: o(c.chainId),
			toChain: o(l.chainId),
			fromToken: c.erc20TokenAddress,
			toToken: m ? s(l.erc20TokenAddress) : l.erc20TokenAddress,
			fromAddress: f,
			fromAmount: i.toString(),
			order: "FASTEST",
			slippage: d,
			...p && { toAddress: m ? s(p) : p }
		});
		if (e(c.chainId)) return {
			lifiDataValue: h.transactionRequest.data,
			outSwapAmountValue: BigInt(h.estimate.toAmount),
			extraNativeTokenFee: 0n
		};
		let g = BigInt(h.transactionRequest.value || "0");
		return {
			lifiDataValue: h.transactionRequest.data,
			outSwapAmountValue: BigInt(h.estimate.toAmount),
			extraNativeTokenFee: c.erc20TokenAddress === n ? g - i : g
		};
	} catch {
		throw Error(i.NO_LIFI_PRICE);
	}
};
//#endregion
export { c as getLifiPrice };
