import { networkRegistry as e } from "../../constants/chains.constants.mjs";
import "../../constants/protocol.constants.mjs";
import { constructStealthAddressStructure as t, isValidPrivateAddress as n } from "../../functions/utils/addresses.mjs";
import { transactionErrorCodes as r } from "../../error-handling/error-codes.constants.mjs";
import { emitTxPublicData as i } from "../../API/admin-calls.mjs";
import { formatMintAddress as a } from "../../functions/utils/solanaMint.utils.mjs";
import { validateAndGetChainId as o } from "../../functions/utils/token-check.utils.mjs";
import { buildAnchorStealthAddressStructure as s, getStorageAccountPublicKey as c, getStorageVaultPublicKey as l } from "../../functions/pre-transaction/solana.mjs";
import { createCustomSolanaConnection as u } from "../../functions/utils/create-provider.mjs";
import { constructAdminData as d } from "../../functions/pre-transaction/constructAdminData.mjs";
import { AccountActions as f } from "../AccountActions/AccountActions.mjs";
import { sendProxyV0Transaction as p, serializeProxyV0Transaction as m } from "../../functions/pre-transaction/sendV0Transaction.mjs";
import { PublicKey as h } from "@solana/web3.js";
import { BN as g } from "@coral-xyz/anchor";
import { TOKEN_2022_PROGRAM_ID as _, TOKEN_PROGRAM_ID as v } from "@solana/spl-token";
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaProxyShield.ts
var y = async ({ program: e, mintPublicKey: t, mintAddressString: n, tokenAmount: r, anchorStealthStructure: i, senderPublickey: a, originalDeployer: o, storageAccount: s, storageVault: c }) => {
	let l = new g(r.toString()), u = n === "11111111111111111111111111111111" ? null : t, d = n === "11111111111111111111111111111111" ? null : void 0;
	return e.methods.prooflessDeposit(l, i).accounts({
		mint: u,
		signer: a,
		signerAta: d,
		originalDeployer: o,
		storageAccount: s,
		storageVault: c,
		storageVaultAta: d
	}).instruction();
}, b = async (i, o, d, p, m, g) => {
	let b = g ?? i.getRecipientInfo();
	if (!n(b)) throw Error(r.RECIPIENT_FORMAT_INCORRECT);
	let x = f.getAddressFromSubAccount(o, m);
	if (!x) throw Error("Public account address is not available");
	let { hinkalIdl: S, hinkalAddress: C, originalDeployer: w } = e[o].contractData;
	if (!S) throw Error("No IDL configured for Solana program on this network");
	if (!w) throw Error("missing original deployer");
	let T = i.getSolanaProgram(S), E = new h(w), D = new h(C), O = new h(x), { erc20TokenAddress: k } = d, { fetchRpcUrl: A } = e[o];
	if (!A) throw Error("RPC URL not found for the specified chain ID");
	let j = u(A), { mintPublicKey: M } = a(k), N = M.toString(), P = c(D, E), F = l(D, E), I = await y({
		program: T,
		mintPublicKey: M,
		mintAddressString: N,
		tokenAmount: p,
		anchorStealthStructure: s(t(b)),
		senderPublickey: O,
		originalDeployer: E,
		storageAccount: P,
		storageVault: F
	}), L = d.is2022Program ? _ : v;
	return {
		connection: j,
		senderAddress: x,
		senderPublickey: O,
		instructions: [I],
		storageAccount: P,
		programId: L
	};
}, x = async (e, t, n, r, a, s) => {
	if (!r) throw Error("subAccount is required");
	let c = o([t]), [{ connection: l, senderPublickey: u, instructions: f }, m] = await Promise.all([b(e, c, t, n, r, a), e.getEthereumAddress()]), h = await p({
		connection: l,
		chainId: c,
		subAccount: r,
		payerPublicKey: u,
		instructions: f
	});
	return i(d(s, c, [t.erc20TokenAddress], [n], m)), h;
}, S = async (e, t, n, r, i) => {
	let { connection: a, senderPublickey: s, instructions: c } = await b(e, o([t]), t, n, r, i);
	return m(a, s, c);
};
//#endregion
export { S as getSolanaProxyShieldSerializedTransaction, x as hinkalSolanaProxyShield };
