Skip to content

devesh1011/MAS-Market

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MAS Market

🎯 Overview

MAS Market is a real-time agentic prediction market platform where specialized AI agents work together to analyze events and make intelligent predictions. The platform leverages a multi-agent architecture powered by the A2A (Agent-to-Agent) protocol, with a host orchestrator coordinating three specialized agents: a Research Agent that analyzes markets using advanced technical indicators (RSI, MACD, Bollinger Bands), real-time events data, and news sentiment; a Polymarket Agent that fetches live market datag and a Bettor Agent that handles blockchain transactions and payouts using the x402 payment protocol on Hedera testnet.

Built with LangChain, LangGraph, and Google Gemini 2.5 Flash, the platform features a Next.js frontend with real-time market grids, WebSocket price updates, and an interactive chat interface where users can research any prediction market with a single click. Users receive comprehensive AI-powered analysis with confidence scores, technical signals, and data-driven recommendations for both binary (yes/no) and continuous (price target) prediction markets. The system enables automated betting execution with non-custodial x402 payments, immutable on-chain bet recording, and automatic payout distribution when markets resolves, providing a seamless end-to-end experience for data-driven crypto predictions and automated trading.


✨ Key Features

πŸ€– Multi-Agent Intelligence

Specialized AI agents work together - Research Agent analyzes markets, Polymarket Agent executes trades, and Bettor Agent handles settlements

🎯 AI-Powered Research

Ask questions about any prediction market and get data-driven recommendations with confidence scores

πŸ’° Automated Betting

Execute trades automatically based on AI predictions without manual intervention

πŸ”— Blockchain Settlement

Secure transaction processing on Hedera testnet with transparent on-chain records

πŸ“ˆ Price Target Predictions

AI analyzes both binary (yes/no) and continuous (specific price) prediction markets

πŸ” Complete Transparency

See exactly how AI reached its conclusion with technical signals and data sources used

πŸ’¬ Interactive Chat Interface

Natural language interface to discuss markets, ask follow-ups, and refine predictions


πŸ—οΈ Architecture

mas market uses a multi-agent architecture with A2A (Agent-to-Agent) protocol for distributed intelligence:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (Next.js)                        β”‚
β”‚  - Real-time market grids with WebSocket pricing            β”‚
β”‚  - Interactive chat interface with markdown rendering        β”‚
β”‚  - One-click AI research for any market                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚
                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Host Agent (A2A Client)                         β”‚
β”‚  - LangGraph workflow orchestration                         β”‚
β”‚  - Coordinates all specialized agents                       β”‚
β”‚  - Aggregates responses and returns to frontend             β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚              β”‚                  β”‚
       β–Ό              β–Ό                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Research  β”‚  β”‚  Polymarket  β”‚  β”‚  Bettor Agent    β”‚
β”‚Agent     β”‚  β”‚  Agent       β”‚  β”‚                  β”‚
β”‚Port 8002 β”‚  β”‚  Port 8001   β”‚  β”‚  Port 8003       β”‚
β”‚          β”‚  β”‚              β”‚  β”‚                  β”‚
β”‚Tools:    β”‚  β”‚Tools:        β”‚  β”‚Tools:            β”‚
β”‚- Tavily  β”‚  β”‚- Market Data β”‚  β”‚- x402 Payment    β”‚
β”‚- CoinGeckoβ”‚ β”‚- CLOB API    β”‚  β”‚- Bet Recording   β”‚
β”‚- Technicalβ”‚ β”‚- Trading     β”‚  β”‚- Resolution Checkβ”‚
β”‚  Analysisβ”‚  β”‚              β”‚  β”‚- Payout Trigger  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Communication Flow

  1. User Request β†’ Host Agent (A2A Client)
  2. Host Agent determines which specialist agents to invoke
  3. Research Agent (port 8002) analyzes market with technical indicators
  4. Polymarket Agent (port 8001) fetches real-time market data
  5. Bettor Agent (port 8003) executes blockchain transactions
  6. Host Agent aggregates responses and returns to user

πŸ› οΈ Technology Stack

Frontend

  • Next.js 15.3.4 - React framework with App Router
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS - Utility-first CSS framework
  • Framer Motion - Animation library
  • react-markdown - Markdown rendering for AI responses

Backend / Agents

  • LangChain v1 - Agent creation and tool orchestration
  • LangGraph - State machine workflow management
  • A2A SDK - Agent-to-Agent communication protocol
  • Google Gemini 2.5 Flash - Fast LLM inference

Data Sources

  • CoinGecko API - Crypto price data (14,000+ coins)
  • Tavily Search API - News and market events
  • Polymarket API - Prediction market data
  • WebSocket (CLOB) - Real-time price updates

Blockchain

  • Hedera SDK - Testnet transactions
  • x402 Protocol - Non-custodial payment standard
  • HCS - Consensus service for bet recording

Development Tools

  • Node.js 18+ - JavaScript runtime
  • npm/pnpm - Package management
  • ESLint - Code linting
  • Prettier - Code formatting

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm/pnpm
  • Google API Key (for Gemini LLM)
  • Tavily API Key (for search)
  • Hedera Account (testnet for betting)
  • Git

Installation

  1. Clone the repository
git clone https://github.com/devesh1011/ethonline2025-hack.git
cd ethonline2025-hack
  1. Install dependencies
# Install root dependencies
npm install

# Install frontend dependencies
cd hedera-client-interface
npm install

# Install Research Agent dependencies
cd ../remote_agents/research_agent
npm install

# Install Polymarket Agent dependencies
cd ../polymarket_agent
npm install

# Install Bettor Agent dependencies
cd ../bettor_agent
npm install
  1. Configure environment variables

Create .env files in each agent directory:

Frontend (hedera-client-interface/.env)

NEXT_PUBLIC_POLYMARKET_WS=wss://ws-subscriptions-clob.polymarket.com/ws/market

Research Agent (remote_agents/research_agent/.env)

GOOGLE_API_KEY=your_google_api_key
TAVILY_API_KEY=your_tavily_api_key
PORT=8002

Polymarket Agent (remote_agents/polymarket_agent/.env)

GOOGLE_API_KEY=your_google_api_key
POLYMARKET_API_URL=https://gamma-api.polymarket.com
PORT=8001

Bettor Agent (remote_agents/bettor_agent/.env)

GOOGLE_API_KEY=your_google_api_key
HEDERA_NETWORK=testnet
HEDERA_OPERATOR_ID=your_hedera_account_id
HEDERA_OPERATOR_KEY=your_hedera_private_key
BETTING_CONTRACT_ID=your_contract_id
PORT=8003
  1. Start the services

Open 4 separate terminals:

Terminal 1: Research Agent

cd remote_agents/research_agent
npm start
# Runs on http://localhost:8002

Terminal 2: Polymarket Agent (optional)

cd remote_agents/polymarket_agent
npm start
# Runs on http://localhost:8001

Terminal 3: Bettor Agent (optional)

cd remote_agents/bettor_agent
npm start
# Runs on http://localhost:8003

Terminal 4: Frontend

cd hedera-client-interface
npm run dev
# Runs on http://localhost:3000
  1. Open the application
http://localhost:3000

πŸ“ Project Structure

ethonline2025-hack/
β”œβ”€β”€ hedera-client-interface/       # Next.js Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ chat/         # Chat endpoint (Host Agent)
β”‚   β”‚   β”‚   β”‚   └── polymarket/   # Market data endpoint
β”‚   β”‚   β”‚   β”œβ”€β”€ chat/             # Chat page with markets grid
β”‚   β”‚   β”‚   └── layout.tsx        # Root layout
β”‚   β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ Chat.tsx          # Chat interface with markdown
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   └── lib/                  # Utilities
β”‚   β”œβ”€β”€ public/                   # Static assets
β”‚   └── package.json
β”‚
β”œβ”€β”€ remote_agents/                # A2A Agents
β”‚   β”œβ”€β”€ research_agent/           # Market analysis agent
β”‚   β”‚   β”œβ”€β”€ agent.ts              # Agent definition with tools
β”‚   β”‚   β”œβ”€β”€ tools.ts              # CoinGecko, Tavily, Technical Analysis
β”‚   β”‚   β”œβ”€β”€ agentExecutor.ts     # A2A server implementation
β”‚   β”‚   β”œβ”€β”€ index.ts              # Entry point
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   β”œβ”€β”€ polymarket_agent/         # Trading execution agent
β”‚   β”‚   β”œβ”€β”€ agent.ts
β”‚   β”‚   β”œβ”€β”€ tools.ts              # Polymarket API integration
β”‚   β”‚   β”œβ”€β”€ agentExecutor.ts
β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   └── package.json
β”‚   β”‚
β”‚   └── bettor_agent/             # Blockchain settlement agent
β”‚       β”œβ”€β”€ agent.ts
β”‚       β”œβ”€β”€ tools.ts              # Hedera SDK, x402 protocol
β”‚       β”œβ”€β”€ instructions.ts       # Agent system prompt
β”‚       β”œβ”€β”€ agentExecutor.ts
β”‚       β”œβ”€β”€ index.ts
β”‚       └── package.json
β”‚
β”œβ”€β”€ server/                       # Host Agent (orchestrator)
β”‚   β”œβ”€β”€ initialize-agent.ts      # LangGraph workflow
β”‚   └── ...
β”‚
└── README.md

πŸ€– Agent Details

1. Research Agent (Port 8002)

Purpose: Market analysis and prediction generation

Tools:

  • internet_search - Tavily API for news and events
  • get_crypto_price_data - Real-time prices from CoinGecko
  • get_crypto_historical_data - Historical trends and volatility
  • get_crypto_market_trend - Market sentiment analysis
  • calculate_technical_indicators - RSI, MACD, Bollinger Bands, Moving Averages

Input: Market question or event ID

Output:

{
  "summary": "Analysis with evidence",
  "market_type": "binary" | "continuous",
  "what_to_bet": "yes" | "no" | 2.75,
  "confidence": "high" | "medium" | "low",
  "technical_signals": ["MACD bullish", "RSI neutral"],
  "data_sources": ["CoinGecko", "Technical Indicators"]
}

2. Polymarket Agent (Port 8001)

Purpose: Fetch market data and execute trades

Tools:

  • Market data retrieval from Polymarket API
  • CLOB order book analysis
  • Trade execution interface

Input: User preferences, event data

Output: Market details, prices, trade confirmation

3. Bettor Agent (Port 8003)

Purpose: Blockchain transaction execution

Tools:

  • trigger_x402_payment - Create payment request
  • record_bet - Store bet on-chain
  • check_market_resolution - Query Polymarket for outcomes
  • get_winning_bets - Fetch winners from backend
  • trigger_payout - Execute Hedera transfer to winners

Input: Payment intent with user account, amount, market ID

Output: Transaction hash, payment URL, settlement confirmation


πŸ“‘ API Documentation

Chat Endpoint

POST /api/chat

Request:

{
  "messages": [
    {
      "role": "user",
      "content": "Research this prediction market: \"Will Bitcoin reach $100k?\""
    }
  ]
}

Response:

{
  "output": "**Analysis**: Bitcoin currently at $43,500...",
  "transactionBytes": null
}

Polymarket Endpoint

GET /api/polymarket

Response:

[
  {
    "id": "123",
    "title": "Will Bitcoin reach $100k?",
    "description": "...",
    "end_date": "2025-12-31",
    "volume": "1000000"
  }
]

Research Agent Endpoint

POST http://localhost:8002/invoke

Request:

{
  "messages": [
    {
      "role": "user",
      "content": "Analyze XRP price for October"
    }
  ]
}

πŸ’‘ Usage Examples

1. Ask for Price Prediction

User: "What price will XRP hit in October?"

AI Response:

**Analysis**: XRP currently at $2.45. Technical indicators show:
- RSI: 58 (neutral momentum)
- MACD: Bullish crossover above signal line
- Support at $2.20, resistance at $2.80
- Historical volatility suggests target range $2.50-$2.95

**Price Target**: $2.75
**Confidence**: Medium
**Technical Signals**: MACD bullish, Support at $2.20, Resistance at $2.80

2. Binary Market Analysis

User: "Will Bitcoin reach $100k by end of 2025?"

AI Response:

**Analysis**: Bitcoin at $43,500, up 56% YTD. Strong bullish momentum:
- RSI at 65 (overbought but holding)
- Price above 50-day MA ($41,200)
- Volume: $28B daily (healthy market)
- News: Institutional adoption increasing

**Recommendation**: YES
**Confidence**: High (72%)
**Reasoning**: Multiple bullish signals align with uptrend continuation

3. One-Click Market Research

  1. Browse markets on the main page
  2. Click "AI Research" button on any market
  3. Chat input auto-populates with market title
  4. AI analyzes and returns recommendation in seconds

βš™οΈ Configuration

Agent Configuration

Each agent can be configured via environment variables:

Model Settings:

  • GOOGLE_API_KEY - Gemini API key
  • Temperature (in code): 0.3-0.5 for deterministic responses

API Keys:

  • TAVILY_API_KEY - For internet search
  • POLYMARKET_API_URL - Polymarket API endpoint

Blockchain:

  • HEDERA_NETWORK - testnet or mainnet
  • HEDERA_OPERATOR_ID - Your Hedera account
  • HEDERA_OPERATOR_KEY - Private key

Frontend Configuration

WebSocket URL:

NEXT_PUBLIC_POLYMARKET_WS=wss://ws-subscriptions-clob.polymarket.com/ws/market

Environment Variables (Production)

Ensure all API keys and credentials are set in production environment:

  • Google API Key
  • Tavily API Key
  • Hedera credentials
  • Polymarket API URL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages