Skip to content

BitteProtocol/minswap-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Minswap Agent

A specialized Cardano DeFi AI agent powered by Minswap's aggregator API. This agent provides comprehensive DeFi functionality including real-time ADA pricing, wallet analysis, token discovery, swap route optimization, and transaction building across Cardano's leading DEX protocols.

🌟 Features

  • πŸ€– Complete AI Agent Setup - Pre-configured agent with OpenAPI specification for Minswap integration
  • πŸ’° Real-time ADA Pricing - Get current ADA prices in 40+ currencies with 24-hour change data
  • πŸ‘› Wallet Analysis - Comprehensive Cardano wallet balance and token analysis
  • πŸ” Token Discovery - Search and filter Cardano native tokens with verification status
  • πŸ“Š Swap Optimization - Find optimal swap routes across multiple DEX protocols:
    • MinswapV2
    • SundaeSwap
    • WingRiders
    • MuesliSwap
    • VyFinance
  • πŸ“‹ Order Management - Track pending swap orders across all supported protocols
  • πŸ”— Transaction Building - Create unsigned Cardano transactions ready for wallet signing
  • ⚑ Next.js 15 with App Router and TypeScript
  • 🎨 Modern Development Stack - Tailwind CSS, ESLint, TypeScript
  • πŸš€ One-Command Development - Integrated with make-agent for seamless development
  • πŸ“‹ Production Ready - Built-in deployment scripts and Vercel integration

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and pnpm (or npm)
  • A Bitte wallet account
  • Git

1. Clone and Setup

git clone https://github.com/BitteProtocol/minswap-agent.git
cd minswap-agent
pnpm install

2. Environment Configuration

Create a .env.local file:

# Required: Get your API key from https://key.bitte.ai
BITTE_API_KEY='your-api-key'

# Required: Your account ID (can be any identifier)
ACCOUNT_ID='your-account-id'

# Optional: For local development
NEXT_PUBLIC_HOST='localhost'
PORT=3000

3. Start Development

pnpm run dev

This command will:

  • Start your Next.js application on http://localhost:3000
  • Launch make-agent development mode
  • Prompt you to sign a message in your Bitte wallet to authenticate
  • Open your agent in the Bitte playground for testing
  • Enable hot reload for seamless development

4. Build for Production

# Build without deployment
pnpm run build

# Build and deploy to production
pnpm run build:deploy

πŸ”§ Available Tools

The Minswap agent includes comprehensive DeFi tools for Cardano ecosystem interaction:

1. ADA Price Information (/api/tools/get-ada-price)

  • Purpose: Get real-time ADA prices in 40+ currencies
  • Parameters: currency (optional, defaults to USD)
  • Features: 24-hour price change tracking
  • Use Case: Portfolio valuation and price monitoring

2. Wallet Balance Analysis (/api/tools/get-wallet-balance)

  • Purpose: Comprehensive wallet balance and token analysis
  • Parameters: address (Cardano wallet), amount_in_decimal (optional)
  • Features: ADA balance, token holdings, minimum lovelace requirements
  • Use Case: Portfolio analysis and asset management

3. Token Search & Discovery (/api/tools/search-tokens)

  • Purpose: Search and filter Cardano native tokens
  • Parameters: query, only_verified, assets, search_after
  • Features: Verification status, pricing data, project information
  • Methods: Both GET (query params) and POST (JSON body)
  • Use Case: Token research and discovery

4. Swap Route Optimization (/api/tools/get-swap-estimate)

  • Purpose: Find optimal swap routes across multiple DEXs
  • Parameters: amount, token_in, token_out, slippage, etc.
  • Features: Multi-hop routing, protocol exclusion, price impact analysis
  • Methods: Both GET (query params) and POST (JSON body)
  • Integration: Aggregates liquidity across 5 major DEX protocols

5. Pending Order Management (/api/tools/get-pending-orders)

  • Purpose: Track pending swap orders across all protocols
  • Parameters: owner_address, amount_in_decimal
  • Features: Cross-protocol order tracking, detailed order information
  • Use Case: Order monitoring and management

6. Transaction Building (/api/tools/build-swap-tx)

  • Purpose: Build unsigned Cardano transactions for swaps
  • Parameters: sender, min_amount_out, estimate, amount_in_decimal
  • Features: CBOR transaction output ready for wallet signing
  • Integration: Uses estimate data to construct valid transactions

7. User Information (/api/tools/get-user)

  • Purpose: Get user account and EVM address information
  • Context-Aware: Automatically populated by Bitte's context system
  • Use Case: User identification and multi-chain support

8. Blockchain Information (/api/tools/get-blockchains)

  • Purpose: Get supported blockchain information
  • Implementation: Returns available blockchain networks
  • Use Case: Multi-chain awareness and network selection

πŸ€– Agent Configuration

The agent is configured through AI plugin manifests at /api/ai-plugin/route.ts and /app/ai-plugin/route.ts. These endpoints return OpenAPI specifications that define:

Agent Metadata

{
  name: "Minswap Agent",
  description: "A specialized Cardano DeFi assistant powered by Minswap's aggregator API...",
  instructions: "You are a Cardano DeFi specialist focused on Minswap integration...",
  tools: [
    { type: "get-ada-price" },
    { type: "get-wallet-balance" },
    { type: "search-tokens" },
    { type: "search-tokens-query" },
    { type: "get-swap-estimate" },
    { type: "get-swap-estimate-query" },
    { type: "get-pending-orders" },
    { type: "build-swap-tx" },
    { type: "get-user" },
    { type: "get-blockchains" },
    { type: "generate-cardano-tx" }
  ],
  categories: ["DeFi", "DAO", "Social"],
  chainIds: [1, 8453]
}

Important Configuration Notes

  1. Dual Method Support: Many endpoints support both GET (query parameters) and POST (JSON body) for AI agent flexibility
  2. Token Symbol Mapping: Automatic conversion of common symbols (MIN, DJED, SHEN, ADA) to proper token IDs
  3. Workflow Integration: Designed for estimate β†’ build-tx β†’ generate-cardano-tx workflow
  4. Error Handling: Comprehensive validation and error reporting
  5. Deployment URL: Automatically detected from Vercel or environment variables

πŸ’‘ Usage Examples

Swap Workflow

1. User: "I want to swap 10 ADA for MIN tokens"
2. Agent searches for MIN token using searchTokensQuery
3. Agent gets swap estimate using getSwapEstimateQuery
4. Agent asks user for wallet address
5. Agent builds transaction using buildSwapTx
6. Agent returns unsigned transaction CBOR for wallet signing

Price Monitoring

1. User: "What's the current ADA price in EUR?"
2. Agent calls getAdaPrice with currency=eur
3. Agent returns current price and 24h change

Portfolio Analysis

1. User provides Cardano wallet address
2. Agent calls getWalletBalance
3. Agent returns comprehensive portfolio breakdown

πŸ“ Environment Variables

Variable Required Description Example
BITTE_API_KEY βœ… Your Bitte API key from key.bitte.ai bitte_key_...
ACCOUNT_ID βœ… Your account identifier your-account-id
NEXT_PUBLIC_HOST ❌ Development host localhost
PORT ❌ Development port 3000
NEXT_PUBLIC_BASE_URL ❌ Base URL for assets https://yourdomain.com

πŸ› οΈ Development Scripts

# Development with hot reload and make-agent
pnpm run dev

# Next.js development only (without make-agent)
pnpm run dev:agent

# Production build (local)
pnpm run build

# Build and deploy to production
pnpm run build:deploy

# Linting
pnpm run lint

πŸš€ Deployment

Automatic Deployment (Recommended)

  1. Push your code to GitHub
  2. Connect your repository to Vercel
  3. Add environment variables in Vercel dashboard:
    • BITTE_API_KEY
    • ACCOUNT_ID
  4. Deploy! The build process automatically runs make-agent deploy

Manual Deployment

# Build and deploy manually
pnpm run build:deploy

πŸ”¨ Creating Custom Tools

To add your own tools to the agent:

1. Create the Tool Endpoint

// src/app/api/tools/my-tool/route.ts
import { NextResponse } from "next/server";

export async function GET(request: Request) {
  const { searchParams } = new URL(request.url);
  const param = searchParams.get("param");

  // Your tool logic here

  return NextResponse.json({ result: "success" });
}

2. Add to Agent Manifest

Update both /api/ai-plugin/route.ts and /app/ai-plugin/route.ts:

// Add to tools array
tools: [
  // ... existing tools
  { type: "my-tool" }
],

// Add to paths object
paths: {
  // ... existing paths
  "/api/tools/my-tool": {
    get: {
      summary: "My custom tool",
      description: "Description of what your tool does",
      operationId: "my-tool",
      parameters: [
        {
          name: "param",
          in: "query",
          required: true,
          schema: { type: "string" }
        }
      ],
      responses: {
        "200": {
          description: "Successful response",
          content: {
            "application/json": {
              schema: {
                type: "object",
                properties: {
                  result: { type: "string" }
                }
              }
            }
          }
        }
      }
    }
  }
}

3. Update Agent Instructions

Modify the instructions field in both agent configurations to include guidance on when and how to use your new tool.

πŸ“– Key Dependencies

🌐 Community & Support

πŸ“‹ Project Structure

minswap-agent/
β”œβ”€β”€ src/app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ ai-plugin/route.ts        # Agent manifest endpoint
β”‚   β”‚   └── tools/                    # Tool endpoints
β”‚   β”‚       β”œβ”€β”€ get-ada-price/
β”‚   β”‚       β”œβ”€β”€ get-wallet-balance/
β”‚   β”‚       β”œβ”€β”€ search-tokens/
β”‚   β”‚       β”œβ”€β”€ get-swap-estimate/
β”‚   β”‚       β”œβ”€β”€ get-pending-orders/
β”‚   β”‚       β”œβ”€β”€ build-swap-tx/
β”‚   β”‚       β”œβ”€β”€ get-user/
β”‚   β”‚       └── get-blockchains/
β”‚   β”œβ”€β”€ ai-plugin/route.ts            # Alternative agent manifest
β”‚   β”œβ”€β”€ config.ts                     # Environment configuration
β”‚   β”œβ”€β”€ layout.tsx                    # Root layout
β”‚   └── page.tsx                      # Home page
β”œβ”€β”€ public/                           # Static assets
β”œβ”€β”€ package.json                      # Dependencies and scripts
└── README.md                         # This file

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

MIT License - see LICENSE file for details.


Built with ❀️ using Bitte Protocol and Minswap

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published