import { chainIds as e } from "../../constants/chains.constants.mjs";
import { TokenType as t, zeroAddress as n } from "../../constants/protocol.constants.mjs";
import { caseInsensitiveEqual as r } from "./caseInsensitive.utils.mjs";
import { getERC20Registry as i } from "../../constants/token-data/ERC20Registry.mjs";
import "../../constants/token-data/index.mjs";
import { getAmountInToken as a } from "../web3/etherFunctions.mjs";
import { customTokenRegistry as o } from "../../data-structures/custom-token-registry/CustomTokenRegistry.mjs";
import { fixDecimalsAmount as s } from "./amounts.utils.mjs";
import { PopularTokenSymbols as c, chainNativeTokenSymbol as l } from "../../constants/tokens.constants.mjs";
//#region libs/shared/common/src/functions/utils/erc20tokenFunctions.ts
var u = (e) => {
	let t = i(e), n = o.getCustomTokens(e);
	return [...t, ...n];
}, d = (e, t, n) => (n ?? u(t))?.find((t) => e === void 0 ? !1 : t.erc20TokenAddress.toLowerCase() === e.toLowerCase()), f = (e, t) => {
	let n = d(e.erc20TokenAddress, t);
	return n ? {
		...e,
		name: n.name,
		symbol: n.symbol,
		logoURI: n.logoURI,
		decimals: n.decimals
	} : e;
}, p = (e, t) => u(t)?.find((t) => e === void 0 ? !1 : t.symbol.toLowerCase() === e.toLowerCase()), m = (e) => {
	let t = e.reduce((e, { amount: t, token: n, nftIds: r }) => {
		let i = n.erc20TokenAddress.toLowerCase();
		return e[i] ? e[i].amount += t : e[i] = {
			amount: t,
			token: n,
			nftIds: r
		}, e;
	}, {});
	return Object.values(t);
}, h = (e) => m(e).map(({ amount: e, token: t, nftIds: n }) => {
	if (e === 0n) return;
	let r = e > 0n ? "+" : "-", i = Number(a(t, e));
	return {
		token: t,
		amount: `${r}${s(i > 0 ? i : -i)}`,
		nftIds: n
	};
}).filter((e) => !!e), g = (e) => e.nftTokenType === t.ERC721 || e.nftTokenType === t.ERC1155 || e.nftTokenType === t.MetaplexNFT || e.nftTokenType === t.Token2022NFT || e.nftTokenType === t.CompressedNFT, _ = (t) => t.chainId === e.arcTestnet && t.erc20TokenAddress === n, v = (e, t) => {
	let n = t.toLowerCase();
	return e.symbol.toLowerCase().includes(n) || e.name.toLowerCase().includes(n) || e.erc20TokenAddress.toLowerCase().startsWith(n);
}, y = (e) => l[e.chainId] === e.symbol, b = (e) => {
	let t = e.filter(y), n = e.filter((e) => !y(e) && c.some((t) => t === e.symbol)), r = e.filter((e) => !y(e) && !c.some((t) => t === e.symbol)), i = n.sort((e, t) => e.symbol.localeCompare(t.symbol, "en-US")), a = r.sort((e, t) => e.symbol.localeCompare(t.symbol, "en-US"));
	return [
		...t,
		...i,
		...a
	];
}, x = (e, t) => e.find((e) => r(e.symbol, t));
//#endregion
export { m as aggregateTokenChanges, x as findTokenBySymbolFromTokenList, h as formatTokenChangesList, d as getERC20Token, p as getERC20TokenBySymbol, u as getErc20TokensForChain, _ as isArcNativeToken, g as isNFTToken, f as overlayTokenWithRegistryData, v as searchCompareFunction, b as sortTokens };
