Deep Mind AI
  • Introduction
  • Examples
    • Getting Started with NextJS
    • Telegram Agent
    • Persistent Agent with PostgreSQL
    • AI Guided Market Making Agent
    • Discord Agent Integration
  • Guides
    • Add your own tool
    • Setup locally
    • Test it out
  • Features
    • Transfer Tokens
    • Stake SOL
    • Deploy SPL Token
    • Check Token Balances
    • Token Data Retrieval
    • Deploy NFT Collection
    • Mint NFT
    • Tensor NFT Marketplace
    • Jupiter Exchange Swaps
    • Solana Name Service (SNS)
    • Launch Token on Pump.fun
Powered by GitBook
On this page
  • Core Features
  • ​Quick Start
  • ​Example Configuration
  • ​Implementation Details
  • ​Trading Parameters
  • ​Risk Management
  • ​Example Usage
  • ​Common Issues
  • ​Performance Optimization
  • ​Monitoring
  • ​Development Tips
  • ​Resources
  • ​Support
  1. Examples

AI Guided Market Making Agent

Automated market making on Manifest DEX using Solana Agent Kit

PreviousPersistent Agent with PostgreSQLNextDiscord Agent Integration

Last updated 3 months ago

Build an intelligent market making bot for Manifest DEX using Solana Agent Kit. This implementation provides automated quote management with randomization to prevent front-running.

Core Features

  1. Automated Market Making

    • Two-sided quoting

    • Configurable parameters

    • Automatic quote refreshing

    • Random pricing model

  2. Trading Strategy

    • Configurable depth

    • Multiple quote levels

    • Balance management

    • Risk controls

Quick Start

1. Setup

# Clone repository
npm install -g degit
degit sendaifun/solana-agent-kit/tree/main/examples/market-making-agent market-maker
cd market-maker

# Install dependencies
pnpm install

# Configure environment
cp .env.example .env.local
interface MarketMakerConfig {
  marketId: string;          // Manifest market ID
  baseToken: string;         // Base token symbol
  quoteToken: string;        // Quote token symbol
  quoteParams: {
    number: number;          // Quotes per side
    minDepth: number;        // Min price distance
    maxDepth: number;        // Max price distance
  };
  allowance: {
    base: number;           // Base token allowance
    quote: number;          // Quote token allowance
  };
  intervalSeconds: number;   // Update interval
}
{
  "marketId": "2Uj8277fkaVBtTU6Wp2GPRbQC86SkSdgQ2mp1Q5N2LHc",
  "baseToken": "SEND",
  "quoteToken": "USDC",
  "quoteParams": {
    "number": 4,
    "minDepth": 0.1,
    "maxDepth": 2
  },
  "allowance": {
    "base": 2,
    "quote": 3
  },
  "intervalSeconds": 20
}
function generateQuotes(midPrice: number, params: QuoteParams): Quote[] {
  const quotes = [];
  for (let i = 0; i < params.number; i++) {
    // Add randomization to prevent front-running
    const randomFactor = 1 + (Math.random() - 0.5) * 0.01;
    const depth = params.minDepth + 
      (params.maxDepth - params.minDepth) * (i / params.number);
    
    quotes.push({
      price: midPrice * (1 + depth) * randomFactor,
      size: calculateSize(depth)
    });
  }
  return quotes;
}
async function startMarketMaking(config: MarketMakerConfig) {
  while (true) {
    try {
      // 1. Get current market state
      const marketState = await getMarketState(config.marketId);
      
      // 2. Generate quotes
      const quotes = generateQuotes(marketState.midPrice, config.quoteParams);
      
      // 3. Place orders
      await placeOrders(quotes);
      
      // 4. Wait for interval
      await sleep(config.intervalSeconds * 1000);
    } catch (error) {
      console.error('Market making error:', error);
    }
  }
}
  • Minimum: Distance from mid price for closest quote

  • Maximum: Distance from mid price for furthest quote

  • Number: Quotes to place on each side

  • Base Allowance: Maximum base token usage

  • Quote Allowance: Maximum quote token usage

  • Size Distribution: How size scales with depth

  1. Balance Monitoring

    • Track token usage

    • Enforce allowance limits

    • Monitor exposure

    • Balance reallocation

  2. Quote Management

    • Price sanity checks

    • Size limits

    • Spread controls

    • Update frequency

  3. Error Handling

    • Transaction failures

    • Network issues

    • Market conditions

    • Balance issues

// Initialize configuration
const config = {
  marketId: "your-market-id",
  baseToken: "SEND",
  quoteToken: "USDC",
  quoteParams: {
    number: 4,
    minDepth: 0.1,
    maxDepth: 2
  },
  allowance: {
    base: 2,
    quote: 3
  },
  intervalSeconds: 20
};

// Start market making
await startMarketMaking(config);
  1. Market Conditions

    • Insufficient liquidity

    • High volatility

    • Wide spreads

    • Price impact

  2. Technical Issues

    • Network latency

    • Transaction failures

    • API limits

    • Balance sync

  3. Configuration

    • Parameter tuning

    • Quote spacing

    • Size allocation

    • Update frequency

  1. Quote Management

    • Batch updates

    • Cancel strategies

    • Order tracking

    • State management

  2. Network Optimization

    • RPC endpoint selection

    • Retry strategies

    • Confirmation levels

    • Transaction priority

  3. Resource Usage

    • Memory management

    • CPU utilization

    • Network bandwidth

    • Storage efficiency

  • Quote placement success rate

  • Fill rates per level

  • Token utilization

  • P&L tracking

interface MarketMakingLog {
  timestamp: number;
  midPrice: number;
  spreads: number[];
  balances: {
    base: number;
    quote: number;
  };
  activeQuotes: number;
}
  1. Testing

    • Use devnet first

    • Test with small sizes

    • Monitor closely

    • Log everything

  2. Deployment

    • Secure key management

    • Environment setup

    • Monitoring setup

    • Backup systems

  3. Maintenance

    • Regular updates

    • Parameter tuning

    • Performance analysis

    • Risk assessment

For support and questions:

  • GitHub issues

  • Documentation

  • Community channels

  • Development team

2. Configuration Parameters

Example Configuration

Implementation Details

Quote Generation

Market Making Loop

Trading Parameters

Quote Depth

Size Parameters

Risk Management

Example Usage

Start Market Making

Common Issues

Performance Optimization

Monitoring

Metrics to Track

Logging

Development Tips

Resources

Support

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Manifest DEX Documentation
Solana Agent Kit GitHub
Market Making Strategies
Risk Management Guide
​