Automated market making on Manifest DEX using Solana Agent Kit
# 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); } } }
// 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);
interface MarketMakingLog { timestamp: number; midPrice: number; spreads: number[]; balances: { base: number; quote: number; }; activeQuotes: number; }
Was this page helpful?