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