require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`);require(`../../constants/protocol.constants.cjs`);const t=require(`../../functions/pre-transaction/solana.cjs`),n=require(`./hinkalCheckSolanaTokenRegistry.cjs`),r=require(`../../types/admin.types.cjs`),i=require(`../../error-handling/error-codes.constants.cjs`),a=require(`../../functions/web3/etherFunctions.cjs`),o=require(`../utxo/Utxo.cjs`),s=require(`../../functions/utils/solanaMint.utils.cjs`),c=require(`../../functions/utils/addresses.cjs`),l=require(`../../API/API.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/snarkjs/common.snarkjs.cjs`),f=require(`../../functions/pre-transaction/constructAdminData.cjs`),p=require(`../../error-handling/retrySolanaError.cjs`),m=require(`../../API/admin-calls.cjs`);require(`../../API/index.cjs`);const h=require(`../../functions/web3/signAndSendSerializedTransaction.cjs`);let g=require(`@coral-xyz/anchor`),_=require(`@solana/web3.js`);var v=async(r,i,a,o,c)=>{if(a.length===0)throw Error(`amounts must not be empty`);if(a.length!==o.length)throw Error(`amounts and stealthAddressStructures length mismatch`);if(a.some(e=>e<=0n))throw Error(`all amounts must be positive`);let d=u.validateAndGetChainId([i]),v=i.erc20TokenAddress,{hinkalIdl:y,hinkalAddress:b,originalDeployer:x}=e.networkRegistry[d].contractData;if(!y)throw Error(`No IDL configured for Solana program on this network`);if(!x)throw Error(`missing original deployer`);let S=f.constructAdminData(c,d,Array(a.length).fill(v),a,await r.getEthereumAddress()),C=r.getSolanaProgram(y),w=r.getSolanaPublicKey(),T=new _.PublicKey(x),E=new _.PublicKey(b),{mintPublicKey:D}=s.formatMintAddress(v),O=D.toString(),k=t.getStorageAccountPublicKey(E,T),A=t.getStorageVaultPublicKey(E,T),j=t.getMerkleAccountPublicKey(E,T),M=o.map(e=>t.buildAnchorStealthAddressStructure(e)),N=a.reduce((e,t)=>e+t,0n),P=await n.hinkalCheckSolanaTokenRegistry(C,new _.PublicKey(T),[v],[N]),F=a.map(e=>e.toString()),I=t.getTokenLimitStorageAccountPublicKey(C.programId,T,D),L=O===`11111111111111111111111111111111`?null:D,R=O===`11111111111111111111111111111111`?null:void 0;for(let e=0;e<10;e+=1){let t=e===9;try{if(P){let{serializedTransaction:e,blockhash:t,lastValidBlockHeight:n}=await l.API.generateMultiPaymentDepositLimitless({amounts:F,payer:w.toBase58(),ethereumAddress:await r.getEthereumAddressByChain(d),mint:v,stealthAddressStructures:M,chainId:d,createBlockedUtxos:!1}),i=await h.signAndSendSerializedTransaction(C.provider,e,t,n);return await m.emitTxPublicData(S),i}let e=await C.methods.multiPaymentDeposit(F.map(e=>new g.BN(e)),M,!1).accounts({mint:L,signer:w,signerAta:R,originalDeployer:T,storageAccount:k,storageVault:A,merkleAccount:j,tokenLimitStorage:I,storageVaultAta:R,accessTokenOwner:null}).rpc();return await m.emitTxPublicData(S),e}catch(e){if(p.shouldRetryForSolanaError(e)&&!t)continue;throw e}}return``},y=async(e,t,n)=>{let i=e.userKeys.getShieldedPrivateKey(),s=d.calcStealthAddressStructure(o.Utxo.findCorrectRandomization(a.randomBigInt(31),i),i);return v(e,n,[t],[s],r.AdminTransactionType.ProoflessDeposit)},b=async(e,t,n,a)=>{if(!c.isValidPrivateAddress(a))throw Error(i.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let o=c.constructStealthAddressStructure(a);return v(e,n,[t],[o],r.AdminTransactionType.PaymentLink)};exports.hinkalSolanaDeposit=y,exports.hinkalSolanaDepositForOther=b,exports.submitSolanaProoflessDeposit=v;