import { c as stringEnum, i as jsonResult, r as errorResult, s as readStringParam, u as Type } from "../../tool-helpers-CVAcqiCy.mjs";
import { getWalletState, requirePublicClient, requireWalletClient } from "../services/walletconnect-service.mjs";
import { validateClaim } from "../services/safety-service.mjs";
//#region extensions/crypto/src/tools/clawnch-fees.ts
/**
* Clawnch Fees Tool — check and claim LP trading fees
* 
* Clawnch-launched tokens earn 1% LP fees on every swap.
* 80% goes to the deployer, 20% to the platform.
*/
const CLAWNCH_API_URL = process.env.CLAWNCHER_API_URL || "https://clawn.ch";
const ClawnchFeesSchema = Type.Object({
	action: stringEnum([
		"check",
		"claim",
		"claim_all"
	], { description: "check: see unclaimed fees. claim: claim fees for a specific token. claim_all: claim all available fees." }),
	token: Type.Optional(Type.String({ description: "Token contract address (required for \"claim\" action)" }))
});
function createClawnchFeesTool() {
	return {
		name: "clawnch_fees",
		label: "Clawnch Fees",
		ownerOnly: true,
		description: "Check and claim trading fee revenue from Clawnch-launched tokens. Every swap pays 1% LP fees — 80% goes to you as the deployer. Fees accumulate in WETH and can be claimed anytime.",
		parameters: ClawnchFeesSchema,
		execute: async (_toolCallId, args) => {
			const params = args;
			const action = readStringParam(params, "action", { required: true });
			const state = getWalletState();
			if (!state.connected) return errorResult("No wallet connected. Use clawnchconnect tool to connect first.");
			switch (action) {
				case "check": return handleCheck(state.address);
				case "claim": return handleClaim(params, state.address);
				case "claim_all": return handleClaimAll(state.address);
				default: return errorResult(`Unknown action: ${action}`);
			}
		}
	};
}
async function handleCheck(address) {
	try {
		const { ClawnchClient } = await import("../../dist-CXAY4yCt.mjs");
		const fees = await new ClawnchClient({ baseUrl: CLAWNCH_API_URL }).getAvailableFees(address);
		return jsonResult({
			address,
			...fees,
			note: fees.tokens?.length ? "Use action \"claim\" with a token address to claim fees, or \"claim_all\" to claim everything." : "No unclaimed fees found. Deploy tokens to start earning."
		});
	} catch (err) {
		return errorResult(`Fee check failed: ${err instanceof Error ? err.message : String(err)}`);
	}
}
async function handleClaim(params, address) {
	const token = readStringParam(params, "token", { required: true });
	try {
		const safety = await validateClaim();
		if (!safety.safe) return errorResult(`Claim blocked:\n` + safety.blockers.map((b) => `  ✗ ${b}`).join("\n"));
	} catch {}
	try {
		const { ClawncherClaimer } = await import("../../dist-CXAY4yCt.mjs");
		const result = await new ClawncherClaimer({
			wallet: requireWalletClient(),
			publicClient: requirePublicClient(),
			network: process.env.CLAWNCHER_NETWORK || "mainnet"
		}).claimAll(token, address);
		return jsonResult({
			status: "success",
			token,
			collectTx: result.collectRewards?.txHash,
			claimWethTx: result.claimFeesWeth?.txHash,
			claimTokenTx: result.claimFeesToken?.txHash
		});
	} catch (err) {
		return errorResult(`Fee claim failed: ${err instanceof Error ? err.message : String(err)}`);
	}
}
async function handleClaimAll(address) {
	try {
		const { ClawnchClient, ClawncherClaimer } = await import("../../dist-CXAY4yCt.mjs");
		const claimableTokens = (await new ClawnchClient({ baseUrl: CLAWNCH_API_URL }).getAvailableFees(address)).tokens?.filter((t) => parseFloat(t.wethFees || "0") > 0 || parseFloat(t.tokenFees || "0") > 0) ?? [];
		if (claimableTokens.length === 0) return jsonResult({
			status: "nothing_to_claim",
			address,
			message: "No unclaimed fees found."
		});
		const claimer = new ClawncherClaimer({
			wallet: requireWalletClient(),
			publicClient: requirePublicClient(),
			network: process.env.CLAWNCHER_NETWORK || "mainnet"
		});
		const tokens = claimableTokens.map((t) => t.address);
		const batchResult = await claimer.claimBatch(tokens, address);
		const results = batchResult.results.map((r) => ({
			token: r.token,
			status: r.success ? "claimed" : "failed",
			collectTx: r.collectRewards?.txHash,
			claimWethTx: r.claimFeesWeth?.txHash,
			claimTokenTx: r.claimFeesToken?.txHash,
			error: r.error?.message
		}));
		return jsonResult({
			status: "complete",
			tokensProcessed: batchResult.results.length,
			successCount: batchResult.successCount,
			failureCount: batchResult.failureCount,
			results
		});
	} catch (err) {
		return errorResult(`Claim all failed: ${err instanceof Error ? err.message : String(err)}`);
	}
}
//#endregion
export { createClawnchFeesTool };

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