import { networkRegistry as e } from "../../constants/chains.constants.mjs";
import "../../constants/protocol.constants.mjs";
import { buildAnchorStealthAddressStructure as t, getStorageAccountPublicKey as n, getStorageVaultPublicKey as r, getTokenLimitStorageAccountPublicKey as i } from "../../functions/pre-transaction/solana.mjs";
import { transactionErrorCodes as a } from "../../error-handling/error-codes.constants.mjs";
import { formatMintAddress as o } from "../../functions/utils/solanaMint.utils.mjs";
import { constructStealthAddressStructure as s, isValidPrivateAddress as c } from "../../functions/utils/addresses.mjs";
import { validateAndGetChainId as l } from "../../functions/utils/token-check.utils.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 } from "../../functions/pre-transaction/sendV0Transaction.mjs";
import { emitTxPublicData as m } from "../../API/admin-calls.mjs";
import { BN as h } from "@coral-xyz/anchor";
import { PublicKey as g } from "@solana/web3.js";
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: a, senderPublickey: o, originalDeployer: s, storageAccount: c, storageVault: l }) => {
	let u = new h(r.toString()), d = i(e.programId, s, t), f = n === "11111111111111111111111111111111" ? null : t, p = n === "11111111111111111111111111111111" ? null : void 0;
	return e.methods.prooflessDeposit(u, a).accounts({
		mint: f,
		signer: o,
		signerAta: p,
		originalDeployer: s,
		storageAccount: c,
		storageVault: l,
		tokenLimitStorage: d,
		storageVaultAta: p,
		accessTokenOwner: null
	}).instruction();
}, b = async (i, l, d, p, m, h) => {
	let b = h ?? i.getRecipientInfo();
	if (!c(b)) throw Error(a.RECIPIENT_FORMAT_INCORRECT);
	let x = f.getAddressFromSubAccount(l, m);
	if (!x) throw Error("Public account address is not available");
	let { hinkalIdl: S, hinkalAddress: C, originalDeployer: w } = e[l].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 g(w), D = new g(C), O = new g(x), { erc20TokenAddress: k } = d, { fetchRpcUrl: A } = e[l];
	if (!A) throw Error("RPC URL not found for the specified chain ID");
	let j = u(A), { mintPublicKey: M } = o(k), N = M.toString(), P = n(D, E), F = r(D, E), I = await y({
		program: T,
		mintPublicKey: M,
		mintAddressString: N,
		tokenAmount: p,
		anchorStealthStructure: t(s(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, i, a) => {
	if (!r) throw Error("subAccount is required");
	let o = l([t]), [{ connection: s, senderPublickey: c, instructions: u }, f] = await Promise.all([b(e, o, t, n, r, i), e.getEthereumAddress()]), h = await p({
		connection: s,
		chainId: o,
		subAccount: r,
		payerPublicKey: c,
		instructions: u
	});
	return m(d(a, o, [t.erc20TokenAddress], [n], f)), h;
};
//#endregion
export { x as hinkalSolanaProxyShield };
