← Back to home

NewsQuantar

News-Driven Trading Agent: Powered by Polygon MCP & 1inch APIs

Problem Statement

BackgroundCryptocurrency markets are highly responsive to social media statements from influential figures like Vitalik Buterin or Donald Trump. For instance, on April 3, 2025, when Justin Sun criticized FUSDT, it triggered significant de-pegging. However, once the FUSDT team provided clarification, the price quickly returned to its pegged value. This volatility creates substantial arbitrage opportunities for traders who can quickly react to news and statements from media outlets and key opinion leaders (KOLs).The challenge is that a single person cannot effectively monitor all relevant news sources and KOLs across various platforms, leading to missed trading opportunities.IntroductionNewsQuantar is a sophisticated solution that leverages AI agents to monitor news and statements from media outlets and influential figures on social media and automatically execute trading decisions on the Polygon blockchain. By combining natural language processing with blockchain technology, the system can identify market-moving information and execute trades faster than human traders.Key FeaturesReal-time News and KOL Monitoring: Continuously tracks statements from media outlets and key opinion leaders on platforms like FarcasterSentiment Analysis: Uses advanced AI to determine if statements are bullish or bearish for specific tokensAutonomous Trading: Makes independent decisions to long or short tokens based on analyzed sentimentPolygon Integration: Executes all transactions on Polygon PoS for fast, low-cost trading1inch Integration: Leverages 1inch's aggregation API for optimal trading routes and reduced costs while maintaining decentralizationTechnology Stack/Core Componentspolygon-mcp with 1inch Dev Portal APIsA TypeScript implementation of the Polygon Model Context Protocol that enables:Direct blockchain interaction from AI agentsToken balance checking and transfersSmart contract deployment and interactionGas price optimization1inch swapintegration for efficient token exchangesSecure wallet management through seed phraseswebhook-sdk for FarcasterA Python SDK for Farcaster event monitoring that provides:Creation and management of Neynar webhooksReal-time event reception for Farcaster castsFiltering capabilities to focus on specific content or usersEvent deduplication to prevent duplicate trade executionSeamless integration with the trading enginechat.pyA standalone interactive CLI for blockchain operations that:Provides a conversational interface to the Polygon blockchainAllows manual querying of wallet addresses, gas prices, and token balancesSupports manual token swaps and transfers for testingServes as a development and debugging tool for the trading systemUses the Fast-Agent framework for natural language blockchain interactionquantar.pyThe core trading engine that:Connects the webhook system to the trading infrastructureAnalyzes Farcaster messages for trading signalsImplements strict trading limits and security measuresExecutes trades through the Polygon MCPSupports multiple token types with proper decimal handlingRestricts trading to authorized users onlyEnsures proper token address usage (e.g., native USDC vs USDC.e)

Solution

Architecture OverviewOur News Quantar project is built on a three-tier architecture that combines blockchain interaction capabilities with natural language processing and social media monitoring:Polygon MCP (Modified Client for Polygon): A forked and enhanced version of the official Polygon MCP that serves as our blockchain interaction layerFast-Agent Framework: The intelligence layer that processes natural language and makes trading decisionsWebhook SDK: A lightweight service that monitors Farcaster for real-time social signalsTechnical ImplementationPolygon MCP Enhancements with 1inch IntegrationWe forked the official Polygon MCP and made several critical enhancements. The Polygon MCP serves as the essential execution layer for our agent - functioning as its "hands and feet" in the blockchain world. Without this component, our intelligent agent would be unable to interact with the blockchain or execute trades, making it the foundational element that enables the entire system to function effectively.1inch Swap Integration: We implemented a comprehensive swap handler (inchSwapHandler) that connects to the 1inch API for optimal trading routes and best execution prices. The integration includes:Automatic slippage managementGas estimation with safety buffersToken approval checksUSDC/USDC.e safety mechanisms to prevent using deprecated tokensOptimized routing through 1inch's aggregation API, which significantly reduces trading costs by finding the most efficient paths across multiple DEXes while maintaining full decentralizationToken Management Tools: We added specialized handlers for:checkAllowanceHandler: Verifies if sufficient token approvals existapproveTokenHandler: Streamlines the token approval processgetTokenDecimalsHandler: Ensures accurate decimal handling across different tokensFast-Agent Framework ImplementationWe built our agent using the Fast-Agent framework, which provides a clean abstraction for LLM-powered applications. Our implementation includes:Dual-mode Operation:chat.py: A direct interface for manual blockchain interactions through natural languagequantar.py: An automated trading agent that processes Farcaster messages and executes trades based on social signalsPrompt Engineering: We carefully crafted system instructions that:Enforce trading limits (max 1 USDC per trade)Implement strict token address validationPrevent the use of deprecated tokens (USDC.e)Handle token decimal precision correctlyClaude 3.7 Sonnet Integration: We integrated with Claude's API for advanced natural language understanding, using the endpoint athttps://chat.cloudapi.vip/v1Webhook SDK for Farcaster MonitoringWe developed a lightweight but robust webhook service using FastAPI that:Provides a/webhookendpoint to receive Farcaster eventsImplements event deduplication to prevent double-processingUses an asynchronous callback system to process events without blockingLogs all activities for audit and debugging purposesSecurity and Configuration ManagementWe implemented a comprehensive security approach:Environment Variable Management: Sensitive data like API keys and seed phrases are stored in.envfiles and excluded from gitConfiguration Separation: We usefastagent.config.yamlfor non-sensitive configuration and load sensitive data from environment variablesToken Address Safety: We maintain aTOKEN_ADDRESSESdictionary with verified addresses to prevent using incorrect or deprecated tokensTrading Limits: Hard-coded maximum trade size of 1 USDC to limit risk exposureAuthorized User Restrictions: Only specified Farcaster accounts can trigger tradesHacky But Effective SolutionsUSDC.e Protection: We implemented multiple safeguards to prevent the use of USDC.e, including:Setting the USDC.e address toDO_NOT_USEin the token dictionaryAdding automatic replacement of USDC.e with native USDC in the swap handlerIncluding explicit warnings in agent instructionsAvoiding USDC.e entirely due to its persistent liquidity issues, which often lead to failed trades, higher slippage, and suboptimal execution pricesWebhook Event Deduplication: We created a simple but effective event ID generation system usingevent_type_created_atto prevent duplicate processing without needing a databaseDecimal Precision Handling: We added explicit reminders about token decimal differences in agent instructions and implemented a dedicated tool to verify token decimals before calculationsThe combination of these components creates a system that can monitor social media for trading signals, analyze them using advanced AI, and execute trades automatically with built-in safety mechanisms.

Hackathon

ETHGlobal Taipei

2025

Prizes

  • 🏆

    Use the Dev Portal APIs to streamline your dApp development2nd place

    1inch

Contributors