import { c as stringEnum, i as jsonResult, o as readNumberParam, r as errorResult, s as readStringParam, u as Type } from "../../tool-helpers-CVAcqiCy.mjs";
import { requirePublicClient } from "../services/walletconnect-service.mjs";
//#region extensions/crypto/src/tools/watch-activity.ts
/**
* Watch Activity Tool — on-chain monitoring via ClawnchWatcher
*
* Monitors swaps, transfers, whale activity, and new token deployments
* on Base. Read-only — no wallet required.
*
* Uses ClawnchWatcher from @clawnch/clawncher-sdk.
*/
const WatchActivitySchema = Type.Object({
	action: stringEnum([
		"token_activity",
		"recent_swaps",
		"recent_transfers",
		"deployments"
	], { description: "token_activity: full activity report (swaps + transfers + stats). recent_swaps: recent swaps for a pool. recent_transfers: token transfers. deployments: recent Clawnch token deployments." }),
	token: Type.Optional(Type.String({ description: "Token contract address to monitor" })),
	pool_id: Type.Optional(Type.String({ description: "Pool ID (bytes32) for swap monitoring. Auto-derived from token if omitted." })),
	blocks: Type.Optional(Type.Number({ description: "Number of blocks to look back (default: 5000, ~3 hours on Base)" })),
	limit: Type.Optional(Type.Number({ description: "Max results to return (default: 50)" })),
	admin: Type.Optional(Type.String({ description: "Filter deployments by token admin address" }))
});
function createWatchActivityTool() {
	return {
		name: "watch_activity",
		label: "Watch Activity",
		ownerOnly: false,
		description: "Monitor on-chain activity: token swaps, transfers, whale alerts, and new deployments. Read-only — no wallet connection needed, only a public RPC client. Tracks activity on Base mainnet.",
		parameters: WatchActivitySchema,
		execute: async (_toolCallId, args) => {
			const p = args;
			const action = readStringParam(p, "action", { required: true });
			try {
				const publicClient = requirePublicClient();
				const { ClawnchWatcher } = await import("../../dist-CXAY4yCt.mjs");
				const network = process.env.CLAWNCHER_NETWORK || "mainnet";
				const watcher = new ClawnchWatcher({
					publicClient,
					network
				});
				const blocks = readNumberParam(p, "blocks") ?? 5e3;
				const fromBlock = await publicClient.getBlockNumber() - BigInt(blocks);
				switch (action) {
					case "token_activity": {
						const token = readStringParam(p, "token", { required: true });
						const poolId = readStringParam(p, "pool_id");
						if (!poolId) {
							try {
								const { ClawnchReader } = await import("../../dist-CXAY4yCt.mjs");
								const rewards = await new ClawnchReader({
									publicClient,
									network
								}).getTokenRewards(token);
								const derivedPoolId = rewards?.poolId ?? rewards?.pool_id;
								if (derivedPoolId) return jsonResult(formatActivity(await watcher.getTokenActivity(token, derivedPoolId, {
									fromBlock,
									transferLimit: 100,
									swapLimit: 100
								})));
							} catch {}
							const transfers = await watcher.getRecentTransfers(token, {
								fromBlock,
								limit: readNumberParam(p, "limit") ?? 50
							});
							return jsonResult({
								token,
								transfers: transfers.map(formatTransfer),
								transferCount: transfers.length,
								note: "No pool ID available — showing transfers only. Provide pool_id for swap data."
							});
						}
						return jsonResult(formatActivity(await watcher.getTokenActivity(token, poolId, {
							fromBlock,
							transferLimit: 100,
							swapLimit: 100
						})));
					}
					case "recent_swaps": {
						const poolId = readStringParam(p, "pool_id", { required: true });
						const swaps = await watcher.getRecentSwaps(poolId, {
							fromBlock,
							limit: readNumberParam(p, "limit") ?? 50
						});
						return jsonResult({
							poolId,
							swaps: swaps.map(formatSwap),
							count: swaps.length
						});
					}
					case "recent_transfers": {
						const token = readStringParam(p, "token", { required: true });
						const transfers = await watcher.getRecentTransfers(token, {
							fromBlock,
							limit: readNumberParam(p, "limit") ?? 50
						});
						return jsonResult({
							token,
							transfers: transfers.map(formatTransfer),
							count: transfers.length
						});
					}
					case "deployments": {
						const admin = readStringParam(p, "admin");
						const deployments = await watcher.getHistoricalDeployments({
							fromBlock,
							tokenAdmin: admin
						});
						return jsonResult({
							deployments: deployments.map((d) => ({
								tokenAddress: d.tokenAddress,
								name: d.tokenName,
								symbol: d.tokenSymbol,
								deployer: d.deployer,
								poolId: d.poolId,
								txHash: d.txHash,
								block: d.blockNumber?.toString()
							})),
							count: deployments.length
						});
					}
					default: return errorResult(`Unknown watch_activity action: ${action}`);
				}
			} catch (err) {
				return errorResult(`Watch activity error: ${err instanceof Error ? err.message : String(err)}`);
			}
		}
	};
}
function formatActivity(activity) {
	return {
		token: activity.token,
		fromBlock: activity.fromBlock?.toString(),
		toBlock: activity.toBlock?.toString(),
		stats: activity.stats ? {
			transferCount: activity.stats.transferCount,
			swapCount: activity.stats.swapCount,
			uniqueAddresses: activity.stats.uniqueAddresses,
			largestTransfer: activity.stats.largestTransfer?.toString(),
			totalVolume0: activity.stats.totalVolume0?.toString(),
			totalVolume1: activity.stats.totalVolume1?.toString()
		} : void 0,
		transfers: activity.transfers?.slice(0, 20).map(formatTransfer),
		swaps: activity.swaps?.slice(0, 20).map(formatSwap)
	};
}
function formatTransfer(t) {
	return {
		from: t.from,
		to: t.to,
		amount: t.amountFormatted ?? t.amount?.toString(),
		txHash: t.txHash,
		block: t.blockNumber?.toString()
	};
}
function formatSwap(s) {
	return {
		sender: s.sender,
		amount0: s.amount0?.toString(),
		amount1: s.amount1?.toString(),
		txHash: s.txHash,
		block: s.blockNumber?.toString()
	};
}
//#endregion
export { createWatchActivityTool };

//# sourceMappingURL=watch-activity.mjs.map