import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
import { solanaNativeAddress as t, zeroAddress as n } from "../../constants/protocol.constants.mjs";
import { BPS_DENOMINATOR as r, EXTENDED_NON_NATIVE_GAS_COST_TOKEN_SYMBOL_OPTIONS as i, NON_NATIVE_GAS_COST_TOKEN_SYMBOL_OPTIONS as a } from "../../constants/fees.constants.mjs";
import { getTokenPrices as o } from "../../API/getTokenPrice.mjs";
import { caseInsensitiveEqual as s } from "./caseInsensitive.utils.mjs";
import { getAmountInToken as c, getAmountInWei as l } from "../web3/etherFunctions.mjs";
import { getERC20Token as u } from "./erc20tokenFunctions.mjs";
import { Logger as d } from "../../error-handling/logger.mjs";
//#region libs/shared/common/src/functions/utils/fees.utils.ts
var f = (r) => {
	if (!r) return i;
	let o = n;
	e(r) && (o = t);
	let s = u(o, r)?.symbol;
	return e(r) && s ? [s] : s && !a(r).includes(s) ? [s, ...a(r)] : a(r);
}, p = (e, t) => {
	let n = e * t.variableRate / r;
	return t.flatFee + n;
}, m = async (e, t, n, i) => {
	let a = u(i.feeToken, e), f;
	if (!a || s(i.feeToken, t.erc20TokenAddress) || i.variableRate === 0n) f = p(n, i);
	else {
		let s = 0n;
		try {
			let { prices: u } = await o(e, [t.erc20TokenAddress, a.erc20TokenAddress]), [d, f] = u;
			if (!d || !f) throw Error("failed to get token prices");
			s = l(a, (Number(c(t, n)) * d * Number(i.variableRate) / Number(r) / f).toFixed(a.decimals));
		} catch (e) {
			d.error("calculateModifiedFeeStructure: failed to price cross-token variable fee, charging gas fee only", e);
		}
		f = i.flatFee + s;
	}
	return {
		feeToken: i.feeToken,
		flatFee: f,
		variableRate: 0n
	};
}, h = (e, t) => {
	let n = -e;
	return t.variableRate === 0n ? n - t.flatFee : (n - t.flatFee) * r / (r + t.variableRate);
};
//#endregion
export { m as calculateModifiedFeeStructure, p as calculateTotalFee, h as calculateWithdrawalAmount, f as getGasTokenSymbols };
