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