import { ContractType as e } from "../../../types/ethereum-network.types.mjs";
import { zeroAddress as t } from "../../../constants/protocol.constants.mjs";
import { caseInsensitiveEqual as n } from "../../utils/caseInsensitive.utils.mjs";
import { ERC20ABI as r } from "../../../externalABIs/index.mjs";
import { waitLittle as i } from "../../utils/time.utils.mjs";
//#region libs/shared/common/src/functions/web3/functionCalls/waitForErc20Approvals.ts
var a = async (r, a, o, s, c, l = 30, u = 1e3) => {
	let d = c.filter(({ tokenAddress: e, requiredAmount: r }) => r > 0n && !n(e, t));
	if (d.length === 0) return;
	let f = d.map(({ tokenAddress: t }) => r.getContractWithSigner(a, e.ERC20Contract, t));
	for (let e = 0; e < l; e += 1) {
		let e = !0;
		for (let t = 0; t < d.length; t += 1) {
			let { requiredAmount: n } = d[t], r = f[t];
			if (BigInt(await r.allowance(o, s)) < n) {
				e = !1;
				break;
			}
		}
		if (e) break;
		await i(u);
	}
}, o = async (e, a, o, s, c = 30, l = 1e3) => {
	let u = s.filter(({ tokenAddress: e, requiredAmount: r }) => r > 0n && !n(e, t) && !!e);
	if (u.length === 0) return;
	let d = await Promise.all(u.map(async ({ tokenAddress: t }) => e.contract(r, t)));
	for (let e = 0; e < c; e += 1) {
		let e = !0;
		for (let t = 0; t < u.length; t += 1) {
			let { requiredAmount: n } = u[t], r = await d[t].allowance(a, o).call({ from: a });
			if (BigInt(String(r)) < n) {
				e = !1;
				break;
			}
		}
		if (e) break;
		await i(l);
	}
};
//#endregion
export { a as waitForErc20Approvals, o as waitForTronErc20Approvals };
