import { transactionErrorCodes as e } from "../../error-handling/error-codes.constants.mjs";
import { ethers as t } from "ethers";
//#region libs/shared/common/src/functions/web3/etherFunctions.ts
var n = (e) => t.parseEther(e), r = (e) => BigInt(t.hexlify(t.randomBytes(e))), i = (e, n) => t.formatUnits(n, e.decimals), a = (n, r) => {
	let i = 10 ** (18 - n.decimals);
	try {
		return t.parseUnits(r) / BigInt(i);
	} catch {
		throw Error(e.DECIMALS_LIMIT);
	}
}, o = (e) => {
	let [t, n] = e.toFixed(30).split("."), r = n ? n.length : 0, i = `${t}${n || ""}`;
	return [BigInt(i), r];
}, s = (e, t) => {
	try {
		return a(e, t);
	} catch {
		return BigInt(0);
	}
}, c = (n, r, i) => {
	let a = t.formatUnits(n, r.decimals), o = BigInt(10 ** (18 - i));
	try {
		let e = t.parseUnits(a) / o;
		return t.formatUnits(e, i);
	} catch {
		throw Error(e.DECIMALS_LIMIT);
	}
}, l = (e, t, n, r) => {
	let [i, a] = o(n);
	return {
		totalValueDollarsBigInt: t * i / BigInt(10 ** (e.decimals - r)) / BigInt(10 ** a),
		precision: r
	};
}, u = (e, t) => !e || !t ? "0" : c(t ?? 0n, e, e.decimals).toString() ?? "0";
//#endregion
export { l as calculateDollarValue, n as ethToWei, i as getAmountInToken, a as getAmountInWei, s as getAmountInWeiOrZero, c as getAmountWithPrecision, u as getAmountWithPrecisionOrZero, r as randomBigInt, o as toBigIntWithDecimals };
