import { n as __exportAll } from "./chunk-BEJ448es.mjs";
//#region extensions/crypto/src/lib/token-decimals.ts
var token_decimals_exports = /* @__PURE__ */ __exportAll({
	isNativeEth: () => isNativeEth,
	resolveTokenDecimals: () => resolveTokenDecimals
});
/**
* Shared utility for resolving ERC-20 token decimals.
*
* Used by defi-swap (3 call sites), the plan executor balance resolver,
* safety-service, and allowance-manager.
*
* Strategy:
* 1. ETH/WETH → 18 (no RPC needed)
* 2. Well-known stablecoins (USDC, USDT) → 6
* 3. On-chain `decimals()` call via publicClient
* 4. Fallback to 18 if all else fails
*/
/** Well-known token addresses on Base (lowercase for comparison). */
const WELL_KNOWN_DECIMALS = {
	"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913": 6,
	"0xfde4c96c8593536e31f229ea8f37b2ada2699bb2": 6,
	"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": 6,
	"0xdac17f958d2ee523a2206206994597c13d831ec7": 6,
	"0x3c499c542cef5e3811e1192ce70d8cc03d5c3359": 6,
	"0x2791bca1f2de4661ed88a30c99a7a9449aa84174": 6
};
/** Sentinel addresses that represent native ETH (not an ERC-20). */
const ETH_ADDRESSES = new Set(["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "0x4200000000000000000000000000000000000006"]);
/**
* Resolve the decimal count for a token address.
*
* @param tokenAddress - The ERC-20 contract address (0x...) or ETH sentinel.
* @param publicClient - A viem PublicClient (or compatible) for on-chain reads.
*                        Pass `null` to skip on-chain resolution.
* @returns The token's decimal count (defaults to 18 if unknown).
*/
async function resolveTokenDecimals(tokenAddress, publicClient) {
	const lower = tokenAddress.toLowerCase();
	if (ETH_ADDRESSES.has(lower)) return 18;
	const known = WELL_KNOWN_DECIMALS[lower];
	if (known !== void 0) return known;
	if (publicClient) try {
		const dec = await publicClient.readContract({
			address: tokenAddress,
			abi: [{
				name: "decimals",
				type: "function",
				stateMutability: "view",
				inputs: [],
				outputs: [{
					name: "",
					type: "uint8"
				}]
			}],
			functionName: "decimals"
		});
		return Number(dec);
	} catch {}
	return 18;
}
/**
* Check if a token address represents native ETH (including WETH).
*/
function isNativeEth(tokenAddress) {
	return ETH_ADDRESSES.has(tokenAddress.toLowerCase());
}
//#endregion
export { resolveTokenDecimals as n, token_decimals_exports as r, isNativeEth as t };

//# sourceMappingURL=token-decimals-DWOm8tUx.mjs.map