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