import { isSolanaLike as e, networkRegistry as t } from "../../constants/chains.constants.mjs";
import { ContractType as n } from "../../types/ethereum-network.types.mjs";
import { getAccessTokenMerkleAccountPublicKey as r, getMerkleAccountPublicKey as i } from "../pre-transaction/solana.mjs";
import { createCustomSolanaConnection as a } from "../utils/create-provider.mjs";
import { getContractWithFetcherByChainId as o } from "../web3/getContractMetadata.mjs";
import { fetchSolanaMerkleTreeRootHash as s } from "../web3/fetchSolanaMerkleTreeRootHash.mjs";
import { AnchorProvider as c, Program as l } from "@coral-xyz/anchor";
import { Keypair as u, PublicKey as d } from "@solana/web3.js";
//#region libs/shared/common/src/functions/snarkjs/fetchOnChainRootHashes.ts
var f = () => {
	let e = u.generate();
	return {
		publicKey: e.publicKey,
		payer: e,
		signTransaction: async (e) => e,
		signAllTransactions: async (e) => e
	};
}, p = async (e) => {
	let t = o(e, n.HinkalContract), r = o(e, n.AccessTokenContract), [i, a] = await Promise.all([t.getRootHash(), r.getRootHash()]);
	return {
		hinkalRootHash: i,
		accessTokenRootHash: a
	};
}, m = async (e) => {
	let { contractData: n, fetchRpcUrl: o } = t[e], { hinkalIdl: u, hinkalAddress: p, originalDeployer: m } = n;
	if (!u || !p || !m || !o) throw Error(`Missing Solana configuration for chain ${e}`);
	let h = new l(u, new c(a(o), f(), {
		preflightCommitment: "confirmed",
		commitment: "confirmed"
	})), g = new d(p), _ = new d(m), v = i(g, _), y = r(g, _), [b, x] = await Promise.all([s(h, v), s(h, y)]);
	return {
		hinkalRootHash: b,
		accessTokenRootHash: x
	};
}, h = async (t) => e(t) ? m(t) : p(t);
//#endregion
export { h as fetchOnChainRootHashes };
