import { chainIds as e } from "../../constants/chains.constants.mjs";
import { httpClient as t } from "../../data-structures/http/HttpClient.mjs";
import "../../data-structures/http/index.mjs";
import { ERC20ABI as n } from "../../externalABIs/index.mjs";
import { createJsonRpcProvider as r } from "../utils/create-provider.mjs";
import "../utils/index.mjs";
import { ethers as i } from "ethers";
//#region libs/shared/common/src/functions/web3/getTokenHolder.ts
var a = {
	[e.base]: "base",
	[e.optimism]: "optimism",
	[e.arbMainnet]: "arbitrum",
	[e.polygon]: "polygon",
	[e.ethMainnet]: "eth"
}, o = async (e, o) => {
	let s = `https://${a[e]}.blockscout.com/api?module=token&action=getTokenHolders&contractaddress=${o}&page=0&offset=10`, { result: c } = await t.get(s), l = r(e), u = new i.Contract(o, n, l);
	for (let { address: e } of c) {
		let t = await u.balanceOf(e);
		if (BigInt(t) !== 0n) return e;
	}
}, s = async (e, n) => {
	let r = `https://api.routescan.io/v2/network/mainnet/evm/${e}/etherscan/api?module=token&action=tokenholderlist&contractaddress=${n}&page=1&offset=10&apikey=YourApiKeyToken`, { result: i } = await t.get(r);
	return i.at(0)?.TokenHolderAddress;
}, c = async (e, t) => {
	try {
		if (!(e in a)) throw Error("Chain is not supported by blockscout");
		let n = await o(e, t);
		if (!n || !i.isAddress(n)) throw Error("Token holder not found in blockscout");
		return n;
	} catch {
		return await s(e, t);
	}
};
//#endregion
export { c as getTokenHolder };
