import { isSolanaLike as e, networkRegistry as t } from "../../constants/chains.constants.mjs";
import { transactionErrorCodes as n } from "../../error-handling/error-codes.constants.mjs";
import { Logger as r } from "../../error-handling/logger.mjs";
import { createCustomSolanaConnection as i, createJsonRpcProvider as a } from "./create-provider.mjs";
import { TX_CONFIRMATION_TIMEOUT_EXTENDED as o } from "../../constants/tx-confirmation.constants.mjs";
import "../../constants/index.mjs";
//#region libs/shared/common/src/functions/utils/tx-confirmation.utils.ts
var s = "confirmed", c = async (e, t, r = {}) => {
	let { evmConfirmations: i = 1, evmTimeoutMs: s = o } = r, c = t.startsWith("0x") ? t : `0x${t}`, l = await a(e).waitForTransaction(c, i, s);
	if (!l || l.status !== 1) throw Error(n.TRANSACTION_NOT_CONFIRMED);
	return l;
}, l = async (e, n, r = {}) => {
	let { solanaCommitment: a = s } = r, { fetchRpcUrl: o } = t[e];
	if (!o) throw Error("RPC URL not found for the specified chain ID");
	let c = await i(o, a).confirmTransaction(n, a);
	if (c.value.err) throw Error("Transaction failed");
	return c;
}, u = async (t, n, i = {}) => {
	try {
		if (e(t)) {
			await l(t, n, i);
			return;
		}
		await c(t, n.startsWith("0x") ? n : `0x${n}`, i);
	} catch (e) {
		throw r.error("waitForTransactionConfirmation failed", {
			chainId: t,
			txHash: n,
			error: e
		}), e;
	}
};
//#endregion
export { c as waitForEthereumTransactionConfirmation, l as waitForSolanaTransactionConfirmation, u as waitForTransactionConfirmation };
