UNPKG

@covalenthq/goldrush-mcp-server

Version:

GoldRush MCP Server for interacting with Covalent GoldRush API

274 lines 10.5 kB
import { validQuoteValues } from "../utils/constants.js"; import { TOOL_DESCRIPTIONS, PARAM_DESCRIPTIONS, } from "../utils/generated-descriptions.js"; import { stringifyWithBigInt } from "../utils/helpers.js"; import { ChainName, } from "@covalenthq/client-sdk"; import { z } from "zod"; export function addBalanceServiceTools(server, goldRushClient) { server.tool("token_balances", TOOL_DESCRIPTIONS["token_balances"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["token_balances"]["chainName"]), walletAddress: z .string() .describe(PARAM_DESCRIPTIONS["token_balances"]["walletAddress"]), quoteCurrency: z .enum(Object.values(validQuoteValues)) .optional() .describe(PARAM_DESCRIPTIONS["token_balances"]["quoteCurrency"]), noSpam: z .boolean() .optional() .describe(PARAM_DESCRIPTIONS["token_balances"]["noSpam"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getTokenBalancesForWalletAddress(params.chainName, params.walletAddress, { quoteCurrency: params.quoteCurrency, noSpam: params.noSpam, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); server.tool("historical_token_balances", TOOL_DESCRIPTIONS["historical_token_balances"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["chainName"]), walletAddress: z .string() .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["walletAddress"]), quoteCurrency: z .enum(Object.values(validQuoteValues)) .optional() .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["quoteCurrency"]), noSpam: z .boolean() .optional() .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["noSpam"]), blockHeight: z .number() .optional() .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["blockHeight"]), date: z .string() .optional() .describe(PARAM_DESCRIPTIONS["historical_token_balances"]["date"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getHistoricalTokenBalancesForWalletAddress(params.chainName, params.walletAddress, { quoteCurrency: params.quoteCurrency, noSpam: params.noSpam, blockHeight: params.blockHeight, date: params.date, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); server.tool("historical_portfolio_value", TOOL_DESCRIPTIONS["historical_portfolio_value"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["historical_portfolio_value"]["chainName"]), walletAddress: z .string() .describe(PARAM_DESCRIPTIONS["historical_portfolio_value"]["walletAddress"]), quoteCurrency: z .enum(Object.values(validQuoteValues)) .optional() .describe(PARAM_DESCRIPTIONS["historical_portfolio_value"]["quoteCurrency"]), days: z .number() .optional() .describe(PARAM_DESCRIPTIONS["historical_portfolio_value"]["days"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getHistoricalPortfolioForWalletAddress(params.chainName, params.walletAddress, { quoteCurrency: params.quoteCurrency, days: params.days, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); server.tool("erc20_token_transfers", TOOL_DESCRIPTIONS["erc20_token_transfers"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["chainName"]), walletAddress: z .string() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["walletAddress"]), quoteCurrency: z .enum(Object.values(validQuoteValues)) .optional() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["quoteCurrency"]), contractAddress: z .string() .nullable() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["contractAddress"]), startingBlock: z .number() .optional() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["startingBlock"]), endingBlock: z .number() .optional() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["endingBlock"]), pageSize: z .number() .optional() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["pageSize"]), pageNumber: z .number() .optional() .describe(PARAM_DESCRIPTIONS["erc20_token_transfers"]["pageNumber"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getErc20TransfersForWalletAddressByPage(params.chainName, params.walletAddress, { quoteCurrency: params.quoteCurrency, contractAddress: params.contractAddress, startingBlock: params.startingBlock, endingBlock: params.endingBlock, pageSize: params.pageSize, pageNumber: params.pageNumber, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); server.tool("token_holders", TOOL_DESCRIPTIONS["token_holders"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["token_holders"]["chainName"]), tokenAddress: z .string() .describe(PARAM_DESCRIPTIONS["token_holders"]["tokenAddress"]), noSnapshot: z .boolean() .optional() .describe(PARAM_DESCRIPTIONS["token_holders"]["noSnapshot"]), blockHeight: z .union([z.string(), z.number()]) .optional() .describe(PARAM_DESCRIPTIONS["token_holders"]["blockHeight"]), date: z .string() .optional() .describe(PARAM_DESCRIPTIONS["token_holders"]["date"]), pageSize: z .number() .optional() .describe(PARAM_DESCRIPTIONS["token_holders"]["pageSize"]), pageNumber: z .number() .optional() .describe(PARAM_DESCRIPTIONS["token_holders"]["pageNumber"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getTokenHoldersV2ForTokenAddressByPage(params.chainName, params.tokenAddress, { blockHeight: params.blockHeight, date: params.date, pageSize: params.pageSize, pageNumber: params.pageNumber, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); server.tool("native_token_balance", TOOL_DESCRIPTIONS["native_token_balance"], { chainName: z .enum(Object.values(ChainName)) .describe(PARAM_DESCRIPTIONS["native_token_balance"]["chainName"]), walletAddress: z .string() .describe(PARAM_DESCRIPTIONS["native_token_balance"]["walletAddress"]), quoteCurrency: z .enum(Object.values(validQuoteValues)) .optional() .describe(PARAM_DESCRIPTIONS["native_token_balance"]["quoteCurrency"]), blockHeight: z .union([z.string(), z.number()]) .optional() .describe(PARAM_DESCRIPTIONS["native_token_balance"]["blockHeight"]), }, async (params) => { try { const response = await goldRushClient.BalanceService.getNativeTokenBalance(params.chainName, params.walletAddress, { quoteCurrency: params.quoteCurrency, blockHeight: params.blockHeight, }); return { content: [ { type: "text", text: stringifyWithBigInt(response.data), }, ], }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error}` }], isError: true, }; } }); } //# sourceMappingURL=BalanceService.js.map