require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/external-action.types.cjs`);require(`../../types/index.cjs`);const r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/web3/etherFunctions.cjs`),a=require(`../../functions/utils/time.utils.cjs`),o=require(`../utxo/Utxo.cjs`),s=require(`../../functions/utils/addresses.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/snarkjs/common.snarkjs.cjs`),f=require(`../../functions/utils/fees.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/ensureAmountChanges.cjs`),h=require(`../../functions/pre-transaction/getFeeStructure.cjs`),g=require(`../../functions/pre-transaction/buildCommitmentValidationData.cjs`);require(`../../functions/pre-transaction/index.cjs`);const _=require(`../../functions/snarkjs/constructSolanaZkProof.cjs`),v=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`);let y=require(`ethers`);var b=async(e,t,n,r,i,s)=>{let c=(await l.addPaddingToUtxos(e,t,n,r,6))[0],d=a.getCurrentTimeInSeconds().toString(),{outputUtxos:f}=u.outputUtxoProcessing(e.userKeys,c,r[0],d),[p,m,h]=i.split(`,`);return{inputUtxos:c,senderOutputUtxos:f,recipientUtxo:new o.Utxo({amount:s,erc20TokenAddress:c[0].erc20TokenAddress,mintAddress:c[0].mintAddress,timeStamp:d,randomization:BigInt(p),stealthAddress:m,encryptionKey:h})}},x=async(a,l,u,v,x,S,C)=>{if(!s.isValidPrivateAddress(v))throw Error(r.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let w=c.validateAndGetChainId(l),T=[...u],{originalDeployer:E,hinkalIdl:D}=e.networkRegistry[w].contractData;if(!E||!D)throw Error(`missing data`);let{userKeys:O,merkleTreeAccessTokenByChain:k,merkleTreeHinkalByChain:A}=a,j=l.map(e=>e.erc20TokenAddress);if(j.length>1)throw Error(`Solana Transfer: Only one mint address is supported`);let M=S??await h.getFeeStructure(w,x,j,n.ExternalActionId.Transact,[],5n);M.variableRate||=t.HINKAL_PRIVATE_SEND_VARIABLE_RATE;let N=f.calculateTotalFee(-T[0],M),P=-T[0];T[0]-=N;let[F,I,{inputUtxos:L,senderOutputUtxos:R,recipientUtxo:z}]=await Promise.all([a.getRandomRelay(w,!0),a.getEthereumAddressByChain(w),b(a,w,j,T,v,P)]);if(!F)throw Error(r.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let B=R[0],V=o.Utxo.findCorrectRandomization(i.randomBigInt(31),a.userKeys.getShieldedPrivateKey()),H={tokenNumber:j.length,nullifierAmount:L.length,outputAmount:2},U=a.getSolanaProgram(D),W=d.calcEncryptedOutputs([[B,z]])[0].map(e=>Array.from(y.ethers.getBytes(e)));m.ensureAmountChanges([L],[R],T);let[{proofAArr:G,proofBArr:K,proofCArr:q,publicInputsArr:J},Y]=await Promise.all([_.constructSolanaZkProof(a.generateProofRemotely,E,A[w],k[w],O,U,[j[0]],[L],[[B,z]],V,N,0n,t.solanaNativeAddress,F,H,W,w),g.buildCommitmentValidationData(w,O,j,[L])]),X={recipient:F,mint:j[0]===`11111111111111111111111111111111`?void 0:j[0]};return{chainId:w,relay:F,args:{proofAArr:G,proofBArr:K,proofCArr:q,publicInputsArr:J,encryptedOutputs:W,relayerFee:N.toString(),dimensions:H},accounts:X,adminData:p.constructAdminData(C,w,j,T,I),commitmentValidationData:Y,recipientUtxo:z}},S=async(e,t,n,r,i,a,o,s=!1)=>{if(s)throw Error(`onlyGasEstimate is not supported for Solana transfer`);let c=await x(e,t,n,r,i,a,o);return v.solanaTransactCallRelayer({chainId:c.chainId,relayAddress:c.relay,functionName:`transfer`,args:c.args,accounts:c.accounts,adminData:c.adminData,commitmentValidationData:c.commitmentValidationData})};exports.hinkalSolanaTransfer=S;