import { ExternalActionId as e } from "../../types/external-action.types.mjs";
import { isTronLike as t } from "../../constants/chains.constants.mjs";
import { HINKAL_PRIVATE_SEND_VARIABLE_RATE as n } from "../../constants/protocol.constants.mjs";
import { isValidPrivateAddress as r } from "../../functions/utils/addresses.mjs";
import { transactionErrorCodes as i } from "../../error-handling/error-codes.constants.mjs";
import { getCurrentTimeInSeconds as a } from "../../functions/utils/time.utils.mjs";
import { addressToHexFormat as o, reorderZkCallData as s } from "../../functions/utils/tron.utils.mjs";
import { validateAndGetChainId as c } from "../../functions/utils/token-check.utils.mjs";
import { addPaddingToUtxos as l } from "../../functions/web3/events/getShieldedBalance.mjs";
import { outputUtxoProcessing as u } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
import { modifyVolatileTokenAmountChanges as d } from "../../functions/pre-transaction/getVolatileTransferAmount.mjs";
import { constructAdminData as f } from "../../functions/pre-transaction/constructAdminData.mjs";
import { getFeeStructure as p } from "../../functions/pre-transaction/getFeeStructure.mjs";
import { buildCommitmentValidationData as m } from "../../functions/pre-transaction/buildCommitmentValidationData.mjs";
import "../../functions/pre-transaction/index.mjs";
import { calculateModifiedFeeStructure as h } from "../../functions/utils/fees.utils.mjs";
import { constructZkProof as g } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
import { transactCallRelayer as _ } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
import { mergeWithFeeStructure as v } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalTransfer.ts
var y = async (e, t, n, r, i, o) => {
	let s = [...await l(e, t, n, r)], c = [], d = a().toString();
	for (let t = 0; t < n.length; t += 1) {
		let { outputUtxos: n } = u(e.userKeys, s[t], r[t], d, !0, i, t === 0 ? o : 0n);
		c.push(n);
	}
	return {
		inputUtxosArray: s,
		outputUtxosArray: c
	};
}, b = async (a, l, u, b, x, S, C) => {
	let w = c(l), T = t(w);
	if (!r(b)) throw Error(i.RECIPIENT_FORMAT_INCORRECT);
	let E = o(await a.getEthereumAddressByChain(w)), D = l.map((e) => e.erc20TokenAddress), O = await d(w, l, u), k = S ?? await p(w, x, D, e.Transact, [], 5n);
	k.variableRate ||= n;
	let A = l[0];
	if (!A) throw Error("Transfer Action: No Token Found");
	let j = -O[0], M = await h(w, A, j, k);
	v(w, D, O, M);
	let [N, { inputUtxosArray: P, outputUtxosArray: F }] = await Promise.all([a.getRandomRelay(w, !0), y(a, w, D, O, b, j)]);
	if (!N) throw Error(i.RELAYER_NOT_AVAILABLE);
	let I = {
		externalActionId: 0n,
		externalAddress: N,
		externalActionMetadata: "0x00"
	}, [{ zkCallData: L, circomData: R, dimData: z }, B] = await Promise.all([g(a.merkleTreeHinkalByChain[w], P, F, a.userKeys, I.externalActionId, I.externalAddress, I.externalActionMetadata, a.generateProofRemotely, M, N, w), m(w, a.userKeys, D, P)]), V = await s(T, L, z, R);
	return await _(w, L, z, R, B, void 0, void 0, f(C, w, D, O, E), V);
};
//#endregion
export { b as hinkalTransfer };
