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