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