A TypeScript scaffold for building Solana trading bots, powered by Bun.
🔧 See also: wreckit - My companion tool for building and testing Solana bots.
- Bun-native - Fast runtime, native SQLite, ESM modules
- Solana integration - @solana/web3.js with connection pooling, wallet management, tx helpers
- SQLite persistence - bun:sqlite + Drizzle ORM for bot state and transaction history
- Async generator loops - Efficient tick-based bot architecture
- Structured logging - Pino with pretty-print support
- PM2 process management - Production-ready daemon support
- Bun >= 1.0
git clone https://github.com/mikehostetler/autofi_bot.git
cd autofi_bot
bun installCreate a .env file:
# Required for bot operations
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
SOLANA_SECRET_KEY=<base58-or-json-array>
# Optional
SOLANA_WS_URL=wss://api.mainnet-beta.solana.com
COMMITMENT=confirmed
LOG_LEVEL=info
NODE_ENV=development# Initialize the database
bun db:migrate
# Run the example bot
bun cli hello-bot
# Check status
bun cli status| Command | Description |
|---|---|
bun cli hello-bot |
Run the example bot |
bun cli status |
Show bot status and statistics |
bun cli help |
Display help information |
| Command | Description |
|---|---|
bun test |
Run tests |
bun run typecheck |
TypeScript type checking |
bun lint |
Run ESLint |
bun format |
Format code with Prettier |
bun db:migrate |
Run database migrations |
For production, use PM2 to run bots as daemons:
bun bots:start # Start bots defined in ecosystem.config.cjs
bun bots:stop # Stop all bots
bun bots:restart # Restart all bots
bun bots:logs # View logsConfigure bots in ecosystem.config.cjs:
module.exports = {
apps: [
{
name: 'HELLO_BOT',
script: 'bun',
args: ['run', 'src/index.ts', 'hello-bot'],
max_memory_restart: '124M',
out_file: './logs/hello_bot.log',
error_file: './logs/hello_bot.error.log'
}
]
}src/
├── bot/ # BaseBot class with async generator tick loop
├── cli/ # Commander.js CLI commands
├── db/ # SQLite database (bun:sqlite + Drizzle ORM)
├── solana/ # Solana client (connection, wallet, tx helpers)
└── util/ # Environment config, logging
Extend BaseBot and implement onTick:
import { BaseBot, BotContext } from './bot'
class MyBot extends BaseBot {
constructor() {
super({ name: 'MyBot', tickIntervalMs: 1000 })
}
async onTick(ctx: BotContext): Promise<void> {
const slot = await ctx.connection.getSlot()
// Your bot logic here
}
}| Table | Purpose |
|---|---|
bot_state |
Key-value store for bot configuration |
transactions |
Transaction history with status tracking |
events |
Audit log for bot events |
token_accounts |
Tracked token accounts and balances |
MIT License - Copyright (c) 2024 Mike Hostetler