require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/protocol.constants.cjs`),t=require(`../../types/circom-data.types.cjs`),n=require(`../../data-structures/crypto-keys/keys.cjs`),r=require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`),i=require(`../utils/external-action.utils.cjs`),a=require(`./getOriginalSender.cjs`);let o=require(`ethers`);var s=e=>e.map(e=>e.map(e=>e.amount===0n?`0`:e.getCommitment())),c=(t,n,r=!1)=>{let i=[];for(let a=0;a<t.length;a+=1){let o=0n,s=0n;for(let e=0;e<t[a].length;e+=1)o+=t[a][e].amount;for(let e=0;e<n[a].length;e+=1)s+=n[a][e].amount;s-o<0?r?i.push(s-o):i.push(e.CIRCOM_P+(s-o)):i.push(s-o)}return i},l=e=>e.map(e=>e>=0n?0n:e),u=e=>{if(e.length===0)return[];let t=[[``]];for(let n=0;n<e.length;n+=1)n>0&&t.push([``]),e[n].forEach((e,i)=>{t[n][i]=`0x${Buffer.from(r.encryptUtxo(e)).toString(`hex`)}`});return t},d=e=>{let t={...e};return t.amountChanges=e.amountChanges.map(e=>e.toString()),t.calldataHash=e.calldataHash.toString(),t.rootHashAccessToken=e.rootHashAccessToken?.toString(),t.stealthAddressStructure.extraRandomization=e.stealthAddressStructure.extraRandomization.toString(),t.stealthAddressStructure.stealthAddress=e.stealthAddressStructure.stealthAddress.toString(),t.stealthAddressStructure.H0=e.stealthAddressStructure.H0.toString(),t.stealthAddressStructure.H1=e.stealthAddressStructure.H1.toString(),t.rootHashHinkal=e.rootHashHinkal?.toString(),t.externalActionId=e.externalActionId?.toString(),t.slippageValues=e.slippageValues.map(e=>e.toString()),t.hinkalLogicArgs.inHinkalAddress=e.hinkalLogicArgs.inHinkalAddress.toString(),t.hinkalLogicArgs.executeApprovalChanges=e.hinkalLogicArgs.executeApprovalChanges.map(e=>e.toString()),t.hinkalLogicArgs.useApprovalUtxoData=e.hinkalLogicArgs.useApprovalUtxoData.map(e=>({approvalChanges:e.approvalChanges.map(e=>e.toString()),externalApprovalAddresses:e.externalApprovalAddresses,conversionInHinkalAddress:e.conversionInHinkalAddress.map(e=>e.toString())})),t.feeStructure.flatFee=e.feeStructure.flatFee.toString(),t.feeStructure.variableRate=e.feeStructure.variableRate.toString(),t},f=(n,r,s,c,l,u,d,f,p,m,h,g,_,v)=>{let y=Object.values(f||t.defaultHookData),b=v??a.getOriginalSender(s??e.zeroAddress,r),x=o.ethers.AbiCoder.defaultAbiCoder().encode([`uint16`,`address`,`address`,`uint256`,`bytes`],[n,r,s,typeof c==`bigint`?c:i.getExternalActionIdHash(c),l]),S=o.ethers.AbiCoder.defaultAbiCoder().encode([`tuple(address, address, bytes, bytes)`,`bytes[][]`,`tuple(address, uint256, uint256)`,`int256[]`,`bool[]`,`tuple(uint256, uint256,int256[],bool, tuple(int256[] approvalChanges, address[] externalApprovalAddresses, uint256[] conversionInHinkalAddress)[])`,`tuple(uint8 v, bytes32 r, bytes32 s, uint256 accessKey, uint256 nonce, address ethereumAddress)`,`address`],[y,u,[g.feeToken,g.flatFee,g.variableRate],p,m,[h.hinkalLogicAction,h.inHinkalAddress,h.executeApprovalChanges,h.doPreTxApproval,h.useApprovalUtxoData],_,b]),C=BigInt(o.ethers.keccak256(x)),w=BigInt(o.ethers.keccak256(S)),T=o.ethers.AbiCoder.defaultAbiCoder().encode([`uint256`,`uint256`],[C,w]);return BigInt(o.ethers.keccak256(T))%e.CIRCOM_P},p=e=>e.startsWith(`swapperMW`)?1:(e.startsWith(`swapperMHA`),0),m=(e,t,n,r,i,a)=>{if(e.startsWith(`swapperMWMin0`))return 4;let o=p(e);return 10+t.length+n.length+r.flat().length+i.flat().length+o+a+3*t.length},h=(e,t)=>{let{h0:r,h1:i}=n.UserKeys.getStealthAddressCompressedPoints(e,t);return{extraRandomization:e,H0:r,H1:i,stealthAddress:BigInt(n.UserKeys.getStealthAddress(e,t))}};exports.buildOutCommitments=s,exports.calcAmountChanges=c,exports.calcEncryptedOutputs=u,exports.calcPublicSignalCount=m,exports.calcStealthAddressStructure=h,exports.createCallDataHash=f,exports.getSlippageValues=l,exports.serializeCircomData=d;