43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
import { tool } from 'ai';
|
|
import { z } from 'zod';
|
|
import axios from 'axios';
|
|
|
|
|
|
const BASE_URL = "https://api.rugcheck.xyz/v1";
|
|
|
|
const rugcheck = async (mint) => {
|
|
try {
|
|
const response = await axios.get(`${BASE_URL}/tokens/${mint}/report`);
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error(`Error fetching detailed report for token ${mint}:`, error.message);
|
|
throw new Error(`Failed to fetch detailed report for token ${mint}.`);
|
|
}
|
|
};
|
|
|
|
export const getRugcheckTool = (userId, chatId,responseId, dataStream) => tool({
|
|
description: `Fetches Solana token market information to decide if the token could be rugged (or has already been rugged).
|
|
This returns important token metrics like LP Locked %, what markets is it listed on, top holders, liquidity, token metadata and other data that is crucial to check if user asks for token information.`,
|
|
parameters: z.object({
|
|
mint: z.string().describe('Mint address of the token'),
|
|
}),
|
|
execute: async ({ mint }) => {
|
|
try {
|
|
console.log(`${userId} ${chatId} called rugcheck with mint: ${mint}`);
|
|
const report = await rugcheck(mint);
|
|
|
|
if (report) {
|
|
dataStream.writeMessageAnnotation({
|
|
id: responseId,
|
|
tool_type: 'tx',
|
|
content: mint.toString(),
|
|
});
|
|
}
|
|
return JSON.stringify({ report });
|
|
} catch (error) {
|
|
console.error(`Error executing rugcheck for mint ${mint}:`, error.message);
|
|
return `Failed to fetch report for mint ${mint}.`;
|
|
}
|
|
},
|
|
});
|