import { ContractType as e } from "../../types/ethereum-network.types.mjs";
import { oneInchZeroAddress as t, zeroAddress as n } from "../../constants/protocol.constants.mjs";
import "../../types/index.mjs";
import { callOneInchAPI as r } from "../../API/callOneInchAPI.mjs";
import { transactionErrorCodes as i } from "../../error-handling/error-codes.constants.mjs";
import { getAmountInWei as a } from "./etherFunctions.mjs";
import "../../constants/index.mjs";
import { Logger as o } from "../../error-handling/logger.mjs";
import { getContractMetadata as s } from "./getContractMetadata.mjs";
import "../../error-handling/index.mjs";
//#region libs/shared/common/src/functions/web3/oneInchAPI.ts
var c = async (c, l, u, d, f = .7) => {
	try {
		let i = await r(c, {
			fromTokenAddress: l.erc20TokenAddress === n ? t : l.erc20TokenAddress,
			toTokenAddress: u.erc20TokenAddress === n ? t : u.erc20TokenAddress,
			fromAddress: n,
			destReceiver: s(e.OneInchExternalActionContract, c).address,
			amount: a(l, d),
			slippage: f,
			disableEstimate: !0,
			allowPartialFill: !1
		});
		if (!i || !i.tx) throw Error("OneInch API price fetch error");
		return {
			outSwapAmountValue: BigInt(i.toAmount),
			oneInchDataValue: i.tx.data
		};
	} catch (e) {
		throw o.log({ error: e }), Error(i.NO_ONEINCH_PRICE);
	}
};
//#endregion
export { c as getOneInchPrice };
