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