require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`),require(`../../types/index.cjs`);const n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`);require(`../../constants/index.cjs`);const i=require(`../crypto-keys/keys.cjs`),a=require(`../../functions/utils/time.utils.cjs`),o=require(`../../functions/utils/token-check.utils.cjs`),s=require(`../../functions/web3/events/getShieldedBalance.cjs`),c=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),l=require(`../../functions/snarkjs/common.snarkjs.cjs`),u=require(`../../functions/pre-transaction/constructAdminData.cjs`),d=require(`../../functions/pre-transaction/ensureAmountChanges.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/constructSolanaZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`);let _=require(`ethers`);var v=async(e,t,n,r)=>{let i=[...await s.addPaddingToUtxos(e,t,n,r,6)][0],o=a.getCurrentTimeInSeconds().toString(),{outputUtxos:l}=c.outputUtxoProcessing(e.userKeys,i,r[0],o);return{inputUtxos:i,outputUtxos:l}},y=async(a,s,c,y,b,x,S)=>{let C=o.validateAndGetChainId(s),w=s.map(e=>e.erc20TokenAddress),T=s[0];if(!T)throw Error(`Solana Withdraw: No Token Found`);let{originalDeployer:E}=t.networkRegistry[C].contractData;if(!E)throw Error(`missing data`);let{userKeys:D,merkleTreeHinkalByChain:O}=a,k=x??await f.getFeeStructure(C,b,w,e.ExternalActionId.Transact),A=await m.calculateModifiedFeeStructure(C,T,-c[0],k);c[0]-=A.flatFee;let[j,{inputUtxos:M,outputUtxos:N}]=await Promise.all([a.getRandomRelay(C,!0),v(a,C,w,c)]);if(!j)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);if(w.length>1)throw Error(`Solana Withdraw: Only one mint address is supported`);let P=i.UserKeys.findCorrectRandomization(r.randomBigInt(31),a.userKeys.getShieldedPrivateKey()),F={tokenNumber:w.length,nullifierAmount:M.length,outputAmount:N.length},I=l.calcEncryptedOutputs([N])[0][0],L=Array.from(_.ethers.getBytes(I));d.ensureAmountChanges([M],[N],c);let[{proofAArr:R,proofBArr:z,proofCArr:B,publicInputsArr:V},H]=await Promise.all([h.constructSolanaZkProof(a.generateProofRemotely,O[C],D,[w[0]],[M],[N],P,A.flatFee,A.variableRate,y,j,F,[L],C),p.buildCommitmentValidationData(C,D,w,[M])]),U={recipient:y,mint:w[0]===`11111111111111111111111111111111`?void 0:w[0]};return g.solanaTransactCallRelayer({chainId:C,relayAddress:j,functionName:`transact`,args:{proofAArr:R,proofBArr:z,proofCArr:B,publicInputsArr:V,encryptedOutputs:[L],relayerFee:A.flatFee.toString(),dimensions:F},accounts:U,commitmentValidationData:H,adminData:u.constructAdminData(S,C,w,c,await a.getEthereumAddress())})};exports.hinkalSolanaWithdraw=y;