diff --git a/src/agent/index.ts b/src/agent/index.ts index e982aa1..94f94d4 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -2,7 +2,7 @@ import { Connection, Keypair, PublicKey } from "@solana/web3.js"; import bs58 from "bs58"; import Decimal from "decimal.js"; import { DEFAULT_OPTIONS } from "../constants"; -import { Config } from "../types"; +import { Config, TokenCheck } from "../types"; import { deploy_collection, deploy_token, @@ -51,6 +51,8 @@ import { create_TipLink, listNFTForSale, cancelListing, + fetchTokenReportSummary, + fetchTokenDetailedReport, OrderParams, } from "../tools"; @@ -482,4 +484,12 @@ export class SolanaAgentKit { async tensorCancelListing(nftMint: PublicKey): Promise { return cancelListing(this, nftMint); } + + async fetchTokenReportSummary(mint: string): Promise { + return fetchTokenReportSummary(mint); + } + + async fetchTokenDetailedReport(mint: string): Promise { + return fetchTokenDetailedReport(mint); + } } diff --git a/src/langchain/index.ts b/src/langchain/index.ts index e2b3d7f..1632930 100644 --- a/src/langchain/index.ts +++ b/src/langchain/index.ts @@ -1919,6 +1919,67 @@ export class SolanaCancelNFTListingTool extends Tool { } } +export class SolanaFetchTokenReportSummaryTool extends Tool { + name = "solana_fetch_token_report_summary"; + description = `Fetches a summary report for a specific token from RugCheck. + Inputs: + - mint: string, the mint address of the token, e.g., "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" (required).`; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + protected async _call(input: string): Promise { + try { + const mint = input.trim(); + const report = await this.solanaKit.fetchTokenReportSummary(mint); + + return JSON.stringify({ + status: "success", + message: "Token report summary fetched successfully", + report, + }); + } catch (error: any) { + return JSON.stringify({ + status: "error", + message: error.message, + code: error.code || "FETCH_TOKEN_REPORT_SUMMARY_ERROR", + }); + } + } +} + +export class SolanaFetchTokenDetailedReportTool extends Tool { + name = "solana_fetch_token_detailed_report"; + description = `Fetches a detailed report for a specific token from RugCheck. + Inputs: + - mint: string, the mint address of the token, e.g., "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" (required).`; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + protected async _call(input: string): Promise { + try { + const mint = input.trim(); + const detailedReport = + await this.solanaKit.fetchTokenDetailedReport(mint); + + return JSON.stringify({ + status: "success", + message: "Detailed token report fetched successfully", + report: detailedReport, + }); + } catch (error: any) { + return JSON.stringify({ + status: "error", + message: error.message, + code: error.code || "FETCH_TOKEN_DETAILED_REPORT_ERROR", + }); + } + } +} + export function createSolanaTools(solanaKit: SolanaAgentKit) { return [ new SolanaBalanceTool(solanaKit), @@ -1968,5 +2029,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) { new SolanaTipLinkTool(solanaKit), new SolanaListNFTForSaleTool(solanaKit), new SolanaCancelNFTListingTool(solanaKit), + new SolanaFetchTokenReportSummaryTool(solanaKit), + new SolanaFetchTokenDetailedReportTool(solanaKit), ]; } diff --git a/src/tools/index.ts b/src/tools/index.ts index 42bdabc..f55ccf2 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -1,3 +1,5 @@ +import exp from "constants"; + export * from "./get_wallet_address"; export * from "./request_faucet_funds"; export * from "./deploy_token"; @@ -54,3 +56,4 @@ export * from "./rock_paper_scissor"; export * from "./create_tiplinks"; export * from "./tensor_trade"; +export * from "./rugcheck"; diff --git a/src/tools/rugcheck.ts b/src/tools/rugcheck.ts new file mode 100644 index 0000000..11d533d --- /dev/null +++ b/src/tools/rugcheck.ts @@ -0,0 +1,53 @@ +import { TokenCheck } from "../types"; + +const BASE_URL = "https://api.rugcheck.xyz/v1"; + +/** + * Fetches a summary report for a specific token. + * @async + * @param {string} mint - The mint address of the token. + * @returns {Promise} The token summary report. + * @throws {Error} If the API call fails. + */ +export async function fetchTokenReportSummary( + mint: string, +): Promise { + try { + const response = await fetch(`${BASE_URL}/tokens/${mint}/report/summary`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return await response.json(); + } catch (error: any) { + console.error( + `Error fetching report summary for token ${mint}:`, + error.message, + ); + throw new Error(`Failed to fetch report summary for token ${mint}.`); + } +} + +/** + * Fetches a detailed report for a specific token. + * @async + * @param {string} mint - The mint address of the token. + * @returns {Promise} The detailed token report. + * @throws {Error} If the API call fails. + */ +export async function fetchTokenDetailedReport( + mint: string, +): Promise { + try { + const response = await fetch(`${BASE_URL}/tokens/${mint}/report`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return await response.json(); + } catch (error: any) { + console.error( + `Error fetching detailed report for token ${mint}:`, + error.message, + ); + throw new Error(`Failed to fetch detailed report for token ${mint}.`); + } +} diff --git a/src/types/index.ts b/src/types/index.ts index 6d31949..1dac764 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -153,3 +153,15 @@ export interface Action { */ handler: Handler; } + +export interface TokenCheck { + tokenProgram: string; + tokenType: string; + risks: Array<{ + name: string; + level: string; + description: string; + score: number; + }>; + score: number; +}