import { zeroAddress as e } from "../../constants/protocol.constants.mjs";
import { ContractType as t } from "../../types/ethereum-network.types.mjs";
import { AdminTransactionType as n } from "../../types/admin.types.mjs";
import "../../types/index.mjs";
import { transactionErrorCodes as r } from "../../error-handling/error-codes.constants.mjs";
import { getCurrentTimeInSeconds as i } from "../../functions/utils/time.utils.mjs";
import { Utxo as a } from "../utxo/Utxo.mjs";
import { isValidPrivateAddress as o } from "../../functions/utils/addresses.mjs";
import { validateAndGetChainId as s } from "../../functions/utils/token-check.utils.mjs";
import { addPaddingToUtxos as c } from "../../functions/web3/events/getShieldedBalance.mjs";
import { outputUtxoProcessing as l } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
import { constructAdminData as u } from "../../functions/pre-transaction/constructAdminData.mjs";
import { getKycAndSignatureData as d } from "../../functions/pre-transaction/getKycAndSignatureData.mjs";
import { constructZkProof as f } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
import { transactCallDirect as p } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
import { emitTxPublicData as m } from "../../API/admin-calls.mjs";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalDeposit.ts
var h = async (e, t, n, r) => {
	let i = await e.getEthereumAddressByChain(t), { patchAccessTokenMerkleTree: a, signatureData: o } = await d(e, t, n, r, i);
	return {
		signatureData: o,
		externalActionData: {
			externalActionId: 0n,
			externalAddress: i,
			externalActionMetadata: "0x00"
		},
		contractTransaction: void 0,
		contractToApprove: void 0,
		patchAccessTokenMerkleTree: a
	};
}, g = async (e, t, n, r) => {
	let a = [...await c(e, t, n, r)], o = [], s = i().toString();
	for (let t = 0; t < n.length; t += 1) {
		let { outputUtxos: n } = l(e.userKeys, a[t], r[t], s);
		o.push(n);
	}
	return {
		inputUtxosArray: a,
		outputUtxosArray: o
	};
}, _ = async (r, i, a, o = !0, c = !1) => {
	let l = s(i), d = i.map((e) => e.erc20TokenAddress), [{ externalActionData: _, contractTransaction: v, contractToApprove: y, patchAccessTokenMerkleTree: b, signatureData: x }, { inputUtxosArray: S, outputUtxosArray: C }] = await Promise.all([h(r, l, d, a), g(r, l, d, a)]), w = `swapperM${a.length.toString()}x${S[0].length}x1`, { zkCallData: T, circomData: E, dimData: D } = await f(r.merkleTreeHinkalByChain[l], r.merkleTreeAccessTokenByChain[l], S, C, r.userKeys, w, _.externalActionId, _.externalAddress, _.externalActionMetadata, r.generateProofRemotely, e, l, void 0, void 0, void 0, b, void 0, void 0, r.getContractWithFetcher(l, t.HinkalHelperContract), x), O = await p(r, l, a, i, T, E, D, y, v, o, c);
	return m(u(n.Onboarding, l, d, a, await r.getEthereumAddress())), O;
}, v = async (i, c, l, d, g = !0, _ = !1) => {
	let v = s(c), y = c.map((e) => e.erc20TokenAddress), [b, x, S] = d.split(",");
	if (!o(d)) throw Error(r.RECIPIENT_FORMAT_INCORRECT);
	let C = y.map((e) => [new a({
		amount: 0n,
		erc20TokenAddress: e,
		shieldedPrivateKey: i.userKeys.getShieldedPrivateKey()
	}), new a({
		amount: 0n,
		erc20TokenAddress: e,
		shieldedPrivateKey: i.userKeys.getShieldedPrivateKey()
	})]), w = `swapperM${l.length.toString()}x${C[0].length}x1`, T = y.map((e, t) => [new a({
		amount: l[t],
		erc20TokenAddress: e,
		randomization: BigInt(b),
		stealthAddress: x,
		encryptionKey: S
	})]), { externalActionData: E, contractTransaction: D, contractToApprove: O, patchAccessTokenMerkleTree: k } = await h(i, v, y, l), { zkCallData: A, circomData: j, dimData: M } = await f(i.merkleTreeHinkalByChain[v], i.merkleTreeAccessTokenByChain[v], C, T, i.userKeys, w, E.externalActionId, E.externalAddress, E.externalActionMetadata, i.generateProofRemotely, e, v, void 0, void 0, void 0, k, void 0, void 0, i.getContractWithFetcher(v, t.HinkalHelperContract)), N = await p(i, v, l, c, A, j, M, O, D, g, _);
	return m(u(n.PaymentLink, v, y, l, await i.getEthereumAddress())), N;
};
//#endregion
export { _ as hinkalDeposit, v as hinkalDepositForOther };
