const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/ethereum-network.types.cjs`),r=require(`../../types/external-action.types.cjs`),i=require(`../../types/admin.types.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/utils/caseInsensitive.utils.cjs`),s=require(`../crypto-keys/keys.cjs`),c=require(`../../functions/utils/time.utils.cjs`),l=require(`../utxo/Utxo.cjs`),u=require(`../../functions/utils/tron.utils.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs`),g=require(`../../functions/pre-transaction/getSignatureDataForTransact.cjs`),_=require(`../../functions/pre-transaction/buildCommitmentValidationData.cjs`);require(`../../functions/pre-transaction/index.cjs`);const v=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),y=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`);var b=async(b,x,S,C,w)=>{let T=d.validateAndGetChainId([x]),ee=e.isTronLike(T),E=x.erc20TokenAddress,D=u.addressToHexFormat(await b.getEthereumAddressByChain(T));if(!o.caseInsensitiveEqual(E,S.erc20TokenAddress))throw Error(`Off-chain UTXO token mismatch`);if(!S.shieldedPrivateKey)throw Error(`Claimable UTXO shieldedPrivateKey is missing`);let O=new s.UserKeys(void 0,S.shieldedPrivateKey),k=b.getRecipientInfo(),A=l.Utxo.createFrom(S,{shieldedPrivateKey:O.getShieldedPrivateKey()}),j=new l.Utxo({amount:0n,erc20TokenAddress:A.erc20TokenAddress,mintAddress:A.mintAddress,tokenId:A.tokenId,shieldedPrivateKey:O.getShieldedPrivateKey()}),M=[E],N=C??await m.getFeeStructure(T,E,[E],r.ExternalActionId.Transact);if(!o.caseInsensitiveEqual(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.HINKAL_PRIVATE_SEND_VARIABLE_RATE;if(A.amount<=N.flatFee)throw Error(a.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);let F=A.amount-N.flatFee,I=F*P/10000n,L=F-I;if(L<=0n)throw Error(a.transactionErrorCodes.RECIPIENT_AMOUNT_INVALID);let R={feeToken:N.feeToken,flatFee:N.flatFee+I,variableRate:0n},z=[-A.amount],B=await b.getRandomRelay(T,!0);if(!B)throw Error(a.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let V={externalActionId:0n,externalAddress:B??D,externalActionMetadata:`0x00`},H=[[A,j]],U=[],W=c.getCurrentTimeInSeconds().toString(),{outputUtxos:G}=f.outputUtxoProcessing(O,H[0],z[0],W,A.tokenId,!0,k,L);U.push(G);let{patchAccessTokenMerkleTree:K,kycRequired:q,hasAccessToken:J}=await h.shouldPatchAccessTokenMerkleTree(b,T,M,z,O.getAccessKey()),Y=await g.getSignatureDataForTransact(T,D,O,q,J),X=`swapperM${z.length}x${H[0].length}x2`,[{zkCallData:Z,circomData:Q,dimData:$},te]=await Promise.all([v.constructZkProof(b.merkleTreeHinkalByChain[T],b.merkleTreeAccessTokenByChain[T],H,U,O,X,V.externalActionId,V.externalAddress,V.externalActionMetadata,b.generateProofRemotely,B,T,void 0,void 0,void 0,K,void 0,R,b.getContractWithFetcher(T,n.ContractType.HinkalHelperContract),Y),_.buildCommitmentValidationData(T,O,M,H)]),ne=await u.reorderZkCallData(ee,Z,$,Q);return y.transactCallRelayer(T,Z,$,Q,te,void 0,void 0,p.constructAdminData(w??i.AdminTransactionType.ClaimUtxo,T,M,z,D),ne)};exports.hinkalClaimUtxo=b;