UNPKG

kiban-agent-kit

Version:

Open-source framework connecting AI agents to Katana ecosystem protocols

66 lines (65 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchTokenByTickerTool = exports.GetTokenDataTool = void 0; const tools_1 = require("@langchain/core/tools"); const zod_1 = require("zod"); const dexscreener_1 = require("../tools/dexscreener"); /** * LangChain tool for getting token data from DexScreener */ class GetTokenDataTool extends tools_1.StructuredTool { constructor() { super(); this.name = "get_token_data"; this.description = "Get token price and market data from DexScreener using a token address"; this.schema = zod_1.z.object({ tokenAddress: zod_1.z.string().describe("The token contract address to look up"), }); this.service = new dexscreener_1.DexScreenerService(); } async _call(input) { try { const tokenData = await this.service.getTokenData(input.tokenAddress); if (!tokenData) { return "No data found for this token"; } return JSON.stringify({ name: tokenData.name, symbol: tokenData.symbol, address: tokenData.address, price_usd: tokenData.priceUsd, volume_24h: tokenData.volume24h, liquidity: tokenData.liquidity, pair_address: tokenData.pairAddress, }, null, 2); } catch (error) { return `Error fetching token data: ${error.message}`; } } } exports.GetTokenDataTool = GetTokenDataTool; /** * LangChain tool for searching tokens by ticker symbol */ class SearchTokenByTickerTool extends tools_1.StructuredTool { constructor() { super(); this.name = "search_token_by_ticker"; this.description = "Search for a token on DexScreener using its ticker symbol (e.g., 'ETH', 'USDC')"; this.schema = zod_1.z.object({ ticker: zod_1.z.string().describe("The token ticker/symbol to search for"), }); this.service = new dexscreener_1.DexScreenerService(); } async _call(input) { try { const result = await this.service.searchTokenByTicker(input.ticker); return JSON.stringify(result, null, 2); } catch (error) { return `Error searching for token: ${error.message}`; } } } exports.SearchTokenByTickerTool = SearchTokenByTickerTool;