import { safeJsonStringify as e } from "../utils/serialize.utils.mjs";
import { isSolanaLike as t, networkRegistry as n } from "../../constants/chains.constants.mjs";
import { getSwapperAccountPublicKeyFromSalt as r } from "../pre-transaction/solana.mjs";
import { getAmountInWei as i, randomBigInt as a } from "./etherFunctions.mjs";
import { callOkxAPI as o } from "../../API/callOkxAPI.mjs";
import { PublicKey as s } from "@solana/web3.js";
//#region libs/shared/common/src/functions/web3/okxAPI.ts
var c = (e, t, n, r, i = .7) => ({
	amount: `${n}`,
	chainIndex: "501",
	fromTokenAddress: e.toString(),
	toTokenAddress: t.toString(),
	userWalletAddress: r,
	slippagePercent: `${i}`,
	directRoute: !0
}), l = async (l, u, d, f, p = .5, m, h) => {
	if (!t(l)) throw Error("OKX is only supported on Solana");
	let g = a(31), _ = i(u, f), { hinkalAddress: v, originalDeployer: y } = n[l].contractData;
	if (!y) throw Error("No original deployer configured for Solana program");
	if (h && !m) throw Error("Proxy wallet address is required");
	let b = new s(v), x = new s(y), S = h && m ? new s(m) : r(b, x, g), { okxResponse: C, status: w } = await o({ quote: c(new s(u.erc20TokenAddress), new s(d.erc20TokenAddress), _, S.toString(), p) });
	if (w !== "success") throw Error("OKX API Fetch Error");
	if (C.code !== "0") throw Error(`OKX API error: ${C.msg}`);
	return {
		outSwapAmountValue: BigInt(C.data.routerResult.toTokenAmount),
		okxDataValue: e({
			...C,
			swapperAccountSalt: g.toString()
		})
	};
};
//#endregion
export { c as createOKXQuote, l as getOKXPrice };
