require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/ethereum-network.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../types/balances.types.cjs`),r=require(`../../types/events.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/mutexes.utils.cjs`),a=require(`../../functions/utils/create-provider.cjs`),o=require(`../../functions/utils/getContractAddress.cjs`),s=require(`../../functions/web3/events/balanceChangedHandler.cjs`),c=require(`../event-service/evm/ClientBlockchainEventEmitter.cjs`),l=require(`../event-service/solana/ClientSolanaBlockchainEventEmitter.cjs`);require(`../event-service/index.cjs`);const u=require(`../snapshot/SnapshotFetcherService.cjs`),d=require(`../snapshot/solana-snapshots/ClientSolanaCommitmentsSnapshotService.cjs`),f=require(`../snapshot/solana-snapshots/ClientSolanaNullifierSnapshotService.cjs`),p=require(`../snapshot/evm-snapshots/ClientCommitmentsSnapshotService.cjs`),m=require(`../snapshot/evm-snapshots/ClientNullifierSnapshotService.cjs`);require(`../snapshot/index.cjs`);let h=require(`async-mutex`),g=require(`@solana/web3.js`);var _=new Map,v=e=>{let t=_.get(e);return t||(t=new h.Mutex,_.set(e,t)),t},y=async(h,_)=>{let y=(_??h.getSupportedChains()).map(_=>v(_).runExclusive(async()=>{h.commitmentsSnapshotServiceByChain[_]?.intervalClear(),h.nullifierSnapshotServiceByChain[_]?.intervalClear();let{maxPageSize:v,fetchRpcUrl:y,contractData:b}=t.networkRegistry[_],x;if(t.isSolanaLike(_)){let e=b.hinkalAddress;if(!y||!e)throw Error(`Fetch RPC URL or Solana program ID is not set`);x=new l.ClientSolanaBlockchainEventEmitter(_,a.createCustomSolanaConnection(y),new g.PublicKey(e),0,i.getChainBalanceFetchingMutex(_),v);let t=b.hinkalIdl;t&&x.setIdl(t);let n=new u.SnapshotFetcherService(_,e);h.commitmentsSnapshotServiceByChain[_]=new d.ClientSolanaCommitmentsSnapshotService(x,n),h.nullifierSnapshotServiceByChain[_]=new f.ClientSolanaNullifierSnapshotService(x,n)}else{let t=h.getContractWithFetcherByChainId(_,e.ContractType.HinkalContract),n=h.getContractWithFetcherByChainId(_,e.ContractType.DepositOnChainUtxos),a=i.getChainBalanceFetchingMutex(_);x=new c.ClientBlockchainEventEmitter(r.EventCategory.MainContractEvents,_,t,0,a,v,n);let s=new u.SnapshotFetcherService(_,o.getContractAddress(t));h.commitmentsSnapshotServiceByChain[_]=new p.ClientCommitmentsSnapshotService(x,s),h.nullifierSnapshotServiceByChain[_]=new m.ClientNullifierSnapshotService(x,s)}let S=h.commitmentsSnapshotServiceByChain[_],C=h.nullifierSnapshotServiceByChain[_];if(!S||!C)throw Error(`Missing snapshot service for chain ${_}`);await Promise.all([S.init(),C.init()]),await x.init(),h.merkleTreeHinkalByChain[_]=S.merkleTree,h.nullifiersByChain[_]=C.nullifiers,h.encryptedOutputsByChain[_]=S.encryptedOutputs,x.onEventsProcessed=e=>{e>0&&s.balanceChangedHandler({updateType:n.PrivateBalanceUpdateType.FreshWithoutLoader,updateTokensListBefore:!0,chainIdToUpdate:_})}}));await Promise.allSettled(y)};exports.resetMerkleTrees=y;