import "../../constants/protocol.constants.mjs";
import { transactionErrorCodes as e } from "../../error-handling/error-codes.constants.mjs";
import { getCurrentTimeInSeconds as t } from "../../functions/utils/time.utils.mjs";
import { validateAndGetChainId as n } from "../../functions/utils/token-check.utils.mjs";
import { addPaddingToUtxos as r } from "../../functions/web3/events/getShieldedBalance.mjs";
import { outputUtxoProcessing as i } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
import { constructAdminData as a } from "../../functions/pre-transaction/constructAdminData.mjs";
import { getFeeStructure as o } from "../../functions/pre-transaction/getFeeStructure.mjs";
import { buildCommitmentValidationData as s } from "../../functions/pre-transaction/buildCommitmentValidationData.mjs";
import "../../functions/pre-transaction/index.mjs";
import { constructZkProof as c } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
import { transactCallRelayer as l } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
import { getExternalSwapAddress as u } from "../../functions/pre-transaction/getExternalSwapAddress.mjs";
import { mergeWithFeeStructure as d } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSwap.ts
var f = async (e, n, a, o) => {
	let s = [...await r(e, n, a, o)], c = [], l = t().toString();
	for (let t = 0; t < a.length; t += 1) {
		let { outputUtxos: n } = i(e.userKeys, s[t], o[t], l);
		c.push(n);
	}
	return {
		inputUtxosArray: s,
		outputUtxosArray: c
	};
}, p = async (t, r, i, p, m, h, g, _) => {
	let v = n(r), y = r.map((e) => e.erc20TokenAddress), b = await t.getEthereumAddressByChain(v), x = g ?? await o(v, h, y, p, void 0, 35n);
	d(v, y, i, x);
	let S = {
		externalActionId: p,
		externalAddress: u(v, p),
		externalActionMetadata: m
	}, [C, { inputUtxosArray: w, outputUtxosArray: T }] = await Promise.all([t.getRandomRelay(v, !0), f(t, v, y, i)]);
	if (!C) throw Error(e.RELAYER_NOT_AVAILABLE);
	let E = [
		!1,
		!0,
		!1
	].slice(0, i.length), [{ zkCallData: D, circomData: O, dimData: k }, A] = await Promise.all([c(t.merkleTreeHinkalByChain[v], w, T, t.userKeys, S.externalActionId, S.externalAddress, S.externalActionMetadata, t.generateProofRemotely, x, C, v, E), s(v, t.userKeys, y, w)]);
	return await l(v, D, k, O, A, void 0, void 0, a(_, v, y, i, b, r));
};
//#endregion
export { p as hinkalSwap };
