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