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