import { i as jsonResult, o as readNumberParam, r as errorResult, s as readStringParam, u as Type } from "../../tool-helpers-CVAcqiCy.mjs";
import { getWalletState, requirePublicClient, requireWalletClient } from "../services/walletconnect-service.mjs";
import { getCredentialVault } from "../services/credential-vault.mjs";
import { validateLaunch } from "../services/safety-service.mjs";
//#region extensions/crypto/src/tools/clawnch-launch.ts
/**
* Clawnch Launch Tool — deploy tokens via the Clawnch launchpad
* 
* Uses the verified deploy API (two-step challenge) for safe, rate-limited launches.
* Transaction approval goes through ClawnchConnect.
*/
const ClawnchLaunchSchema = Type.Object({
	name: Type.String({ description: "Token name (e.g. \"Lobster Coin\")" }),
	symbol: Type.String({ description: "Token ticker symbol (e.g. \"LOBSTR\"). Max 10 characters." }),
	description: Type.Optional(Type.String({ description: "Token description" })),
	image: Type.Optional(Type.String({ description: "Token logo — URL to an image or base64-encoded image data" })),
	vault_percentage: Type.Optional(Type.Number({ description: "Percentage of supply to lock in vault (1-90%). Locked for 7+ days." })),
	dev_buy_eth: Type.Optional(Type.String({ description: "ETH amount for dev buy at launch (e.g. \"0.01\"). Tokens sent to your wallet." })),
	bypass_rate_limit: Type.Optional(Type.Boolean({ description: "Burn 10,000 $CLAWNCH to bypass the 1-launch-per-hour rate limit" }))
});
function createClawnchLaunchTool() {
	return {
		name: "clawnch_launch",
		label: "Clawnch Launch",
		ownerOnly: true,
		description: "Deploy a new ERC-20 token on Base via the Clawnch launchpad. Creates a Uniswap V4 pool with MEV protection and fee distribution. Requires a connected wallet and Clawnch API key. Rate limited to 1 launch per hour (bypass by burning 10K $CLAWNCH). 80% of trading fees go to you, 20% to the platform.",
		parameters: ClawnchLaunchSchema,
		execute: async (_toolCallId, args) => {
			const params = args;
			const state = getWalletState();
			if (!state.connected) return errorResult("No wallet connected. Use clawnchconnect tool to connect first.");
			const apiKey = getCredentialVault().getSecret("clawnch.launcherApiKey", "clawnch-launch");
			if (!apiKey) return errorResult("Clawnch API key required for token launches. Set CLAWNCHER_API_KEY env var. Get one at https://clawn.ch/agents");
			const name = readStringParam(params, "name", { required: true });
			const symbol = readStringParam(params, "symbol", { required: true });
			const description = readStringParam(params, "description");
			const image = readStringParam(params, "image");
			const vaultPercentageRaw = readNumberParam(params, "vault_percentage");
			const vaultPercentage = vaultPercentageRaw !== void 0 ? Math.max(1, Math.min(90, Math.round(vaultPercentageRaw))) : void 0;
			const devBuyEth = readStringParam(params, "dev_buy_eth");
			const bypassRateLimit = params.bypass_rate_limit === true;
			if (symbol.length > 10) return errorResult("Symbol must be 10 characters or less.");
			try {
				const safety = await validateLaunch({ devBuyEth: devBuyEth ? parseFloat(devBuyEth) : void 0 });
				if (!safety.safe) return errorResult(`Launch blocked by safety checks:\n` + safety.blockers.map((b) => `  ✗ ${b}`).join("\n"));
			} catch (err) {
				console.warn("[clawnch-launch] Safety pre-flight failed, proceeding without validation:", err instanceof Error ? err.message : String(err));
			}
			try {
				const { ClawnchApiDeployer } = await import("../../dist-CXAY4yCt.mjs");
				const deployer = new ClawnchApiDeployer({
					apiKey,
					wallet: requireWalletClient(),
					publicClient: requirePublicClient(),
					apiBaseUrl: process.env.CLAWNCHER_API_URL || "https://clawn.ch"
				});
				const deployOptions = {
					name,
					symbol,
					description,
					image,
					bypassRateLimit
				};
				if (vaultPercentage) deployOptions.vault = {
					percentage: vaultPercentage,
					lockupDuration: 10080 * 60,
					recipient: state.address
				};
				if (devBuyEth) deployOptions.devBuy = {
					ethAmount: devBuyEth,
					recipient: state.address
				};
				const result = await deployer.deploy(deployOptions);
				return jsonResult({
					status: "success",
					name,
					symbol,
					txHash: result.txHash,
					tokenAddress: result.tokenAddress,
					clawnchUrl: `https://clawn.ch/token/${result.tokenAddress}`,
					clawnchBurned: result.clawnchBurned ? "10,000 $CLAWNCH" : void 0,
					burnTxHash: result.burnTxHash,
					note: "Token deployed! Trading is live on Uniswap V4. MEV protection active for first 30 seconds."
				});
			} catch (err) {
				return errorResult(`Launch failed: ${err instanceof Error ? err.message : String(err)}`);
			}
		}
	};
}
//#endregion
export { createClawnchLaunchTool };

//# sourceMappingURL=clawnch-launch.mjs.map