import { ContractType as e } from "../../types/ethereum-network.types.mjs";
import { isTronLike as t } from "../../constants/chains.constants.mjs";
import { DepositAndWithdrawPhase as n } from "../../types/scheduled-transactions.types.mjs";
import "../../types/index.mjs";
import { evmHexToTronBase58Address as r } from "../../functions/utils/tron.utils.mjs";
import { getOnChainUtxosFromReceipt as i } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
import { waitForEthereumTransactionConfirmation as a } from "../../functions/utils/tx-confirmation.utils.mjs";
import { transactCallDirect as o } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
import { transactCallDirectTron as s } from "../../functions/web3/functionCalls/transactCallDirectTron.mjs";
import { safeUpdateDepositAndWithdrawStatus as c, updateDepositAndWithdrawStatus as l } from "../../API/deposit-and-withdraw-status-calls.mjs";
import { prepareDepositOnChainUtxosZkProof as u } from "./prepareDepositOnChainUtxosZkProof.mjs";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalDepositOnChainUtxos.ts
var d = async (d, f, p, m, h, g, _, v = !0) => {
	let y = t(f), b = p.erc20TokenAddress, { zkCallData: x, circomData: S, dimData: C, totalAmount: w, utxoAmounts: T, hinkalWrapperAddress: E, hinkalWrapperABI: D, depositOnChainUtxosExternalActionAddress: O, depositOnChainUtxosExternalActionABI: k } = await u(d, f, p, m, g), A = (await l({
		chainId: f,
		hashedEthereumAddress: _,
		phase: n.BEFORE_DEPOSIT
	})).id ?? void 0, j;
	if (y) {
		let e = d.getTronWeb();
		j = await s(d, f, w, p, x, S, C, e.contract(k, r(O)), e.contract(D, r(E)), v);
	} else {
		let t = d.getContractWithSigner(f, e.HinkalWrapper);
		j = (await o(d, f, w, p, x, S, C, d.getContractWithSigner(f, e.DepositOnChainUtxos), t, v)).hash;
	}
	if (!j) throw Error("Deposit transaction hash not found");
	let M = await a(f, j);
	await c({
		id: A,
		chainId: f,
		hashedEthereumAddress: _,
		phase: n.AFTER_DEPOSIT,
		depositTxHash: j
	});
	let N = i(M, d, f, b);
	if (N.length === 0) throw Error("No UTXOs found in deposit transaction. Check contract address and ABI.");
	let P = [], F = [...N];
	return h.forEach((e, t) => {
		let n = T[t], r = F.find((e) => e.amount === n);
		if (!r) throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);
		P.push({
			recipientAddress: e,
			utxo: r
		});
		let i = F.indexOf(r);
		F.splice(i, 1);
	}), {
		userDepositedUtxos: P,
		statusId: A,
		depositTxHash: j
	};
};
//#endregion
export { d as hinkalDepositOnChainUtxos };
