require(`../../../../_virtual/_rolldown/runtime.cjs`);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(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const o=require(`../../functions/utils/tron.utils.cjs`),s=require(`../../functions/web3/events/getShieldedBalance.cjs`),c=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),l=require(`../../functions/utils/fees.utils.cjs`),u=require(`../../functions/pre-transaction/constructAdminData.cjs`),d=require(`../../functions/pre-transaction/getKycAndSignatureData.cjs`),f=require(`../../functions/utils/getUtxosFromReceipt.utils.cjs`),p=require(`../../functions/utils/tx-confirmation.utils.cjs`),m=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),h=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),g=require(`../../API/admin-calls.cjs`),_=require(`../../functions/web3/functionCalls/transactCallDirectTron.cjs`),v=require(`../../API/deposit-and-withdraw-status-calls.cjs`);let y=require(`ethers`);var b=async(e,t,n,r)=>{let i=[...await s.addPaddingToUtxos(e,t,n,r)],a=[];for(let t=0;t<i.length;t+=1){let{outputUtxos:n}=c.outputUtxoProcessing(e.userKeys,i[t],r[t]);a.push(n)}return{inputUtxosArray:i,outputUtxosArray:a}},x=async(s,c,x,S,C,w,T,E=!0)=>{let D=e.isTronLike(c),O=x.erc20TokenAddress,k=o.addressToHexFormat(await s.getEthereumAddressByChain(c)),A=S.map(e=>e+l.calculateTotalFee(e,w)),j=A.reduce((e,t)=>e+t,0n),M=[O],N=[0n],P=[!0],F=y.ethers.AbiCoder.defaultAbiCoder().encode([`uint256[]`],[A]),{hinkalWrapperAddress:I,hinkalWrapperABI:L,depositOnChainUtxosExternalActionAddress:R,depositOnChainUtxosExternalActionABI:z}=e.networkRegistry[c].contractData;if(!I||!L||!R||!z)throw Error(`contract data not set in networkRegistry`);let[{patchAccessTokenMerkleTree:B,signatureData:V},{inputUtxosArray:H,outputUtxosArray:U}]=await Promise.all([d.getKycAndSignatureData(s,c,M,N,k),b(s,c,M,N)]),{zkCallData:W,circomData:G,dimData:K}=await m.constructZkProof(s.merkleTreeHinkalByChain[c],s.merkleTreeAccessTokenByChain[c],H,U,s.userKeys,`swapperM1x${H[0].length}x1`,r.ExternalActionId.DepositOnChainUtxos,R,F,s.generateProofRemotely,t.zeroAddress,c,P,void 0,void 0,B,void 0,void 0,s.getContractWithFetcher(c,n.ContractType.HinkalHelperContract),V,I),q=(await v.updateDepositAndWithdrawStatus({chainId:c,hashedEthereumAddress:T,phase:a.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,J;if(D){let e=s.getTronWeb();J=await _.transactCallDirectTron(s,c,j,x,W,G,K,e.contract(z,o.evmHexToTronBase58Address(R)),e.contract(L,o.evmHexToTronBase58Address(I)),E)}else{let e=s.getContractWithSigner(c,n.ContractType.HinkalWrapper);J=(await h.transactCallDirect(s,c,j,x,W,G,K,s.getContractWithSigner(c,n.ContractType.DepositOnChainUtxos),e,E)).hash}if(!J)throw Error(`Deposit transaction hash not found`);let Y=await p.waitForEthereumTransactionConfirmation(c,J);await v.safeUpdateDepositAndWithdrawStatus({id:q,chainId:c,hashedEthereumAddress:T,phase:a.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:J});let X=f.getOnChainUtxosFromReceipt(Y,s,c,O);if(X.length===0)throw Error(`No UTXOs found in deposit transaction. Check contract address and ABI.`);let Z=[],Q=[...X];return C.forEach((e,t)=>{let n=A[t],r=Q.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);Z.push({recipientAddress:e,utxo:r});let i=Q.indexOf(r);Q.splice(i,1)}),g.emitTxPublicData(u.constructAdminData(i.AdminTransactionType.DepositOnChainUtxos,c,M,[j],k)),{userDepositedUtxos:Z,statusId:q,depositTxHash:J}};exports.hinkalDepositOnChainUtxos=x;