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 { AdminTransactionType as i } from "../../types/admin.types.mjs";
import { transactionErrorCodes as a } from "../../error-handling/error-codes.constants.mjs";
import { caseInsensitiveEqual as o } from "../../functions/utils/caseInsensitive.utils.mjs";
import { UserKeys as s } from "../crypto-keys/keys.mjs";
import { getCurrentTimeInSeconds as c } from "../../functions/utils/time.utils.mjs";
import { Utxo as l } from "../utxo/Utxo.mjs";
import { addressToHexFormat as u, reorderZkCallData as d } from "../../functions/utils/tron.utils.mjs";
import { validateAndGetChainId as f } from "../../functions/utils/token-check.utils.mjs";
import { outputUtxoProcessing as p } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
import { constructAdminData as m } from "../../functions/pre-transaction/constructAdminData.mjs";
import { getFeeStructure as h } from "../../functions/pre-transaction/getFeeStructure.mjs";
import { shouldPatchAccessTokenMerkleTree as g } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
import { getSignatureDataForTransact as _ } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
import { buildCommitmentValidationData as ee } 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";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalClaimUtxo.ts
var b = async (b, x, S, C, te) => {
	let w = f([x]), T = e(w), E = x.erc20TokenAddress, D = u(await b.getEthereumAddressByChain(w));
	if (!o(E, S.erc20TokenAddress)) throw Error("Off-chain UTXO token mismatch");
	if (!S.shieldedPrivateKey) throw Error("Claimable UTXO shieldedPrivateKey is missing");
	let O = new s(void 0, S.shieldedPrivateKey), k = b.getRecipientInfo(), A = l.createFrom(S, { shieldedPrivateKey: O.getShieldedPrivateKey() }), j = new l({
		amount: 0n,
		erc20TokenAddress: A.erc20TokenAddress,
		mintAddress: A.mintAddress,
		tokenId: A.tokenId,
		shieldedPrivateKey: O.getShieldedPrivateKey()
	}), M = [E], N = C ?? await h(w, E, [E], r.Transact);
	if (!o(N.feeToken, E)) throw Error("Claim fee token mismatch: fee must be paid from claimed UTXO token");
	let P = N.variableRate > 0n ? N.variableRate : t;
	if (A.amount <= N.flatFee) throw Error(a.INSUFFICIENT_FUNDS_TO_TRANSACT);
	let F = A.amount - N.flatFee, I = F * P / 10000n, L = F - I;
	if (L <= 0n) throw Error(a.RECIPIENT_AMOUNT_INVALID);
	let R = {
		feeToken: N.feeToken,
		flatFee: N.flatFee + I,
		variableRate: 0n
	}, z = [-A.amount], B = await b.getRandomRelay(w, !0);
	if (!B) throw Error(a.RELAYER_NOT_AVAILABLE);
	let V = {
		externalActionId: 0n,
		externalAddress: B ?? D,
		externalActionMetadata: "0x00"
	}, H = [[A, j]], U = [], W = c().toString(), { outputUtxos: G } = p(O, H[0], z[0], W, A.tokenId, !0, k, L);
	U.push(G);
	let { patchAccessTokenMerkleTree: K, kycRequired: q, hasAccessToken: J } = await g(b, w, M, z, O.getAccessKey()), Y = await _(w, D, O, q, J), X = `swapperM${z.length}x${H[0].length}x2`, [{ zkCallData: Z, circomData: Q, dimData: $ }, ne] = await Promise.all([v(b.merkleTreeHinkalByChain[w], b.merkleTreeAccessTokenByChain[w], H, U, O, X, V.externalActionId, V.externalAddress, V.externalActionMetadata, b.generateProofRemotely, B, w, void 0, void 0, void 0, K, void 0, R, b.getContractWithFetcher(w, n.HinkalHelperContract), Y), ee(w, O, M, H)]), re = await d(T, Z, $, Q);
	return y(w, Z, $, Q, ne, void 0, void 0, m(te ?? i.ClaimUtxo, w, M, z, D), re);
};
//#endregion
export { b as hinkalClaimUtxo };
