const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),ee=require(`../../crypto/poseidon.cjs`),r=require(`../../types/circom-data.types.cjs`),te=require(`../../types/external-action.types.cjs`),i=require(`../web3/etherFunctions.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../data-structures/utxo/Utxo.cjs`),s=require(`./common.snarkjs.cjs`),c=require(`./generateCircomData.cjs`),l=require(`./generateZkProof.cjs`),ne=require(`../utils/fees.utils.cjs`),re=require(`../../data-structures/AccountActions/AccountActions.cjs`),u=require(`../../data-structures/Hinkal/hinkalCheckTokenRegistry.cjs`),d=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),f=require(`../private-wallet/emporium.helpers.cjs`);require(`../../crypto/index.cjs`);var p=async(p,ie,m,h,g,_,v,y,b,x,ae,oe,S=t.zeroAddress,C=e.chainIds.localhost,w=g.map(()=>!1),T=g.map(()=>0n),E,D=!1,O,k=void 0,se,A=t.defaultSignatureData,ce)=>{let j=s.calcAmountChanges(g,_),M=s.calcEncryptedOutputs(_),N=v.getShieldedPrivateKey(),P=o.Utxo.findCorrectRandomization(i.randomBigInt(31),N),F=await u.hinkalCheckTokenRegistry(se??u.createHinkalHelperFromData(C),m,s.calcAmountChanges(g,_,!0)),{inCommitmentSiblings:I,inCommitmentSiblingSides:L,accessTokenSiblings:R,accessTokenSiblingSides:z,rootHashHinkal:B,rootHashAccessToken:V,inNullifiers:H}=await d.getDataFromWorkers(C,p,ie,v,g.map(e=>e.map(e=>e.getConstructableParams())),D,F),U=s.buildOutCommitments(_),W=ce??i.randomBigInt(31),le=ee.poseidonFunction(W),G={rootHashHinkal:B,erc20TokenAddresses:m,tokenIds:h,inNullifiers:H,outTimeStamp:_.length>0?BigInt(_[0][0].timeStamp):a.getCurrentTimeInSeconds(),extraRandomization:P,amountChanges:j,outCommitments:U,rootHashAccessToken:V,calldataHash:0n,shieldedPrivateKey:N,accessTokenSiblings:R,accessTokenSiblingSides:z,outAmounts:_.map(e=>e.map(e=>e.amount)),outPublicKeys:_.map(e=>e.map(e=>e.getStealthAddress())),inAmounts:g.map(e=>e.map(e=>e.amount.toString())),inTimeStamps:g.map(e=>e.map(e=>e.timeStamp)),inRandomizations:g.map(e=>e.map(e=>e.randomization)),inCommitmentSiblings:I,inCommitmentSiblingSides:L,messageSeed:W},ue=E?re.AccountActions.getSignerAddressFromPrivateKey(C,E):void 0,K=x,q=te.ExternalActionId.Emporium,J=await f.encodeEmporiumMetadata(C,x,E,ae,le,ue),Y=_.length===0?`swapperMWMin0`:`swapperMW${y}x${b}x${_[0].length}`,X=s.calcPublicSignalCount(Y,G.erc20TokenAddresses,G.amountChanges,G.inNullifiers,G.outCommitments,h.length),Z=n.defaultHinkalLogicArgs(j.length,v);G.interactionAddress=Z.interactionAddress,G.externalApprovalAddresses=Z?.useApprovalUtxoData?.map(({externalApprovalAddresses:e})=>e),k||=ne.generateFeeStructure(T,m);let Q=s.calcAmountChanges(g,_,!0);O||=s.getSlippageValues(Q),G.calldataHash=s.createCallDataHash(X,S,K,q,J,M,T,void 0,O,w,Z,k,A);let $={outTimeStamp:a.getCurrentTimeInSeconds(),rootHashAccessToken:V,calldataHash:G.calldataHash,shieldedPrivateKey:N,accessTokenSiblings:R,accessTokenSiblingSides:z,messageSeed:W},[{zkCallData:de},fe]=await Promise.all([l.generateZkProof(C,Y,Y===`swapperMWMin0`?$:G,oe),f.getAuthorizationDataIfNeeded(C,E)]),pe=s.calcStealthAddressStructure(P,N);return{zkCallData:de,circomData:c.generateCircomData(U,H,B,V,Q,m,_,M,X,q,K,J,S,G.calldataHash,h,pe,w,r.defaultHookData,Y===`swapperMWMin0`?$.outTimeStamp:G.outTimeStamp,Z,O,k,A),dimData:{tokenNumber:g.length,nullifierAmount:g.length>0?g[0].length:0,outputAmount:_.length>0?_[0].length:0},encryptedOutputs:M,authorizationData:fe}};exports.constructEmporiumProof=p;