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`);require(`../../types/index.cjs`);const i=require(`../../error-handling/error-codes.constants.cjs`),a=require(`../../functions/utils/time.utils.cjs`),o=require(`../../functions/utils/addresses.cjs`),s=require(`../../functions/utils/tron.utils.cjs`),c=require(`../../functions/utils/token-check.utils.cjs`),l=require(`../../functions/web3/events/getShieldedBalance.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/utils/fees.utils.cjs`),f=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/getKycAndSignatureData.cjs`),g=require(`../../functions/pre-transaction/buildCommitmentValidationData.cjs`);require(`../../functions/pre-transaction/index.cjs`);const _=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),v=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),y=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var b=async(e,t,n,r,i,o)=>{let s=[...await l.addPaddingToUtxos(e,t,n,r)],c=[],d=a.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=u.outputUtxoProcessing(e.userKeys,s[t],r[t],d,void 0,!0,i,t===0?o:0n);c.push(n)}return{inputUtxosArray:s,outputUtxosArray:c}},x=async(a,l,u,x,S,C,w)=>{let T=c.validateAndGetChainId(l),E=e.isTronLike(T);if(!o.isValidPrivateAddress(x))throw Error(i.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let D=s.addressToHexFormat(await a.getEthereumAddressByChain(T)),O=l.map(e=>e.erc20TokenAddress),k=await f.modifyVolatileTokenAmountChanges(T,l,u),A=C??await m.getFeeStructure(T,S,O,r.ExternalActionId.Transact,[],5n);A.variableRate||=t.HINKAL_PRIVATE_SEND_VARIABLE_RATE;let j=d.calculateTotalFee(-k[0],A),M=-k[0],N={feeToken:A.feeToken,flatFee:j,variableRate:0n};if(y.mergeWithFeeStructure(T,O,k,N),!l[0])throw Error(`Transfer Action: No Token Found`);let[P,{patchAccessTokenMerkleTree:F,signatureData:I},{inputUtxosArray:L,outputUtxosArray:R}]=await Promise.all([a.getRandomRelay(T,!0),h.getKycAndSignatureData(a,T,O,k,D),b(a,T,O,k,x,M)]);if(!P)throw Error(i.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let z={externalActionId:0n,externalAddress:P,externalActionMetadata:`0x00`},B=`swapperM${k.length}x${L[0].length}x2`,[{zkCallData:V,circomData:H,dimData:U},W]=await Promise.all([_.constructZkProof(a.merkleTreeHinkalByChain[T],a.merkleTreeAccessTokenByChain[T],L,R,a.userKeys,B,z.externalActionId,z.externalAddress,z.externalActionMetadata,a.generateProofRemotely,P,T,void 0,void 0,void 0,F,void 0,N,a.getContractWithFetcher(T,n.ContractType.HinkalHelperContract),I),g.buildCommitmentValidationData(T,a.userKeys,O,L)]),G=await s.reorderZkCallData(E,V,U,H);return await v.transactCallRelayer(T,V,U,H,W,void 0,void 0,p.constructAdminData(w,T,O,k,D),G)};exports.hinkalTransfer=x;