UNPKG

@iqai/mcp-atp

Version:

Mcp server for ATP (IQAI's Agent Tokenization Platform) access

55 lines • 2.14 kB
import dedent from "dedent"; import { env } from "../config.js"; import formatNumber from "../lib/format-number.js"; export class AgentPositionsService { walletService; constructor(walletService) { this.walletService = walletService; } async getPositions() { const walletClient = this.walletService.getWalletClient(); if (!walletClient || !walletClient.account) { throw new Error("Wallet client or account is not available. Ensure the wallet is properly initialized and configured with a private key."); } const userAddress = walletClient.account.address; try { const url = new URL(`${env.ATP_API_URL}/holdings`); url.searchParams.append("address", userAddress); const response = await fetch(url.toString(), { method: "GET", headers: { "Content-Type": "application/json", }, }); if (!response.ok) { throw new Error(`Failed to fetch agent positions: ${response.statusText}`); } return (await response.json()); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to fetch agent positions: ${error.message}`); } throw new Error("Failed to fetch agent positions due to an unknown error."); } } formatPositions(positions) { if (positions.holdings.length === 0) { return "šŸ“Š No Active Positions Found"; } const formattedPositions = positions.holdings .map((pos) => { const tokenAmount = formatNumber(Number(pos.tokenAmount)); const currentPriceInUsd = formatNumber(pos.currentPriceInUsd); return dedent ` šŸ’° ${pos.name} - Token Contract: ${pos.tokenContract} - Token Amount: ${tokenAmount} - Current Price: ${currentPriceInUsd} USD `; }) .join("\n"); return `šŸ“Š *Your Active Positions*\n\n${formattedPositions}`; } } //# sourceMappingURL=agent-positions.js.map