const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../utils/erc20tokenFunctions.cjs`),o=require(`../../../data-structures/utxo/Utxo.cjs`),s=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const c=require(`../../utils/encodeTokenWithId.cjs`),l=require(`../../utils/solanaMint.utils.cjs`),u=require(`./getInputUtxoAndBalance.cjs`),d=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),f=require(`../../utils/mutexes.utils.cjs`);var p=async(t,r,i,o,s,c=!1,l,p=!1,m=!1)=>f.getChainBalanceFetchingMutex(r).runExclusive(async()=>{let{inputUtxos:f}=m?await u.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:s,passedShieldedPrivateKey:i,resetCacheBefore:c,allowRemoteDecryption:l}):await u.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:o,ethAddress:s,resetCacheBefore:c,allowRemoteDecryption:l});p&&e.isExtension&&await d.privateTokensDB.fetchAndUpdatePrivateTokens(f.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,s);let h=(e.isExtension?await d.privateTokensDB.getPrivateTokens(r,s):a.getErc20TokensForChain(r)).map(e=>({token:e,balance:f.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:f.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),g=new Map;return h.forEach(e=>{g.set(e.token.erc20TokenAddress.toLowerCase(),e)}),g}),m=async(e,n,d,f,p=6,m=d.map(()=>0),h=!1,g=!1)=>{let{userKeys:_}=e,v=_.getSpendingKeyPair().pubSpendingBJJPoint,y=[],b=[];if(d.length===0)return[];let x=await u.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:d.map((e,t)=>({erc20TokenAddress:d[t],tokenId:m[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:g,chainId:n}),S=0;for(let e=0;e<d.length;e+=1)if(h===!1){let t=x.get(c.encodeTokenWithId(n,{erc20TokenAddress:d[e],tokenId:m[e]}))??[];if(!t)throw Error(`Missing utxos for token`);S=Math.max(t.length,S),b.push(t)}else b.push([]);return S===2?b:(b.forEach((e,c)=>{if(e.length>p){let t=e.slice(0,p),o=t.reduce((e,t)=>e+t.amount,0n);if(f[c]<0n&&o<-f[c]){let e=a.getERC20Token(d[c],n),t=e.decimals===18?6:2,l=Number(i.getAmountWithPrecision(o,e,t));throw new s.ErrorWithAmount(l,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${l} ${e.symbol}, including gas fees.`)}y.push(t)}else if(e.length<=p){let r=[...e],i=p-e.length;for(;i>0;){--i;let e=t.isSolanaLike(n),a=e?d[c]:void 0,s=e?l.formatMintAddress(d[c]).compressedAddress:d[c];r.push(new o.Utxo({amount:0n,erc20TokenAddress:s,mintAddress:a,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0}))}y.push(r)}}),y)};exports.addPaddingToUtxos=m,exports.getShieldedBalance=p;