An example implementation of a solver bot using the iLayer network, supporting multiple EVM chains and ERC20 tokens.
See the iLayer documentation for more details.
- Prerequisites
- Quick Start
- Database Setup
- Production Deployment
- Configuration
- Available Scripts
- Troubleshooting
- Node.js 20 or higher
- npm or yarn
- PostgreSQL 14 or higher (if running locally)
- Docker 20.10 or higher
- Docker Compose 2.0 or higher
-
Clone the repository
git clone <repository-url> cd bot-2
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Set up PostgreSQL (if not using Docker)
Install PostgreSQL:
# macOS brew install postgresql@16 brew services start postgresql@16 # Ubuntu/Debian sudo apt-get install postgresql-16 sudo systemctl start postgresql
Create database and user:
psql postgres -c "CREATE USER ilayer_admin WITH PASSWORD 'ilayer_password' CREATEDB;" psql postgres -c "CREATE DATABASE ilayer_db OWNER ilayer_admin;"
-
Start the bot
npm run start:dev
The bot will automatically:
- Generate Prisma client
- Run database migrations
- Start the application in watch mode
The API will be available at
http://localhost:8080
-
Start all services
docker compose up
This will start:
- PostgreSQL database with automatic initialization
- Soketi WebSocket server
- The database will be accessible at
localhost:5432
-
Run the bot locally (connected to Docker database)
# In a separate terminal npm run start:dev
The database setup is fully automated when using npm run start:dev or npm run start:prod:
- Prisma client is generated
- Pending migrations are applied
- Application starts
If you need to manually manage the database:
# Generate Prisma client
npm run prisma:generate
# Apply migrations (development - interactive)
npm run prisma:migrate:dev
# Apply migrations (production - no prompts)
npm run prisma:migrate:deploy
# Open Prisma Studio (database GUI)
npm run prisma:studio
# Reset database (WARNING: deletes all data)
npm run prisma:resetCreating a new migration:
npx prisma migrate dev --name your_migration_nameThe migration will be automatically applied the next time you run npm run start:dev.
-
Prepare environment
# Create production environment file cp .env .env.prod # Edit .env.prod with production values
-
Deploy
docker compose -f docker-compose.prod.yml up -d --build
This will:
- Build the optimized production image
- Start PostgreSQL with health checks
- Start Soketi with health checks
- Wait for services to be healthy
- Run database migrations automatically
- Start the bot application
-
Verify deployment
# Check service health docker compose -f docker-compose.prod.yml ps # View logs docker compose -f docker-compose.prod.yml logs -f bot # Check API curl http://localhost:8080/api
-
Build production image
docker build -t ilayer-bot:latest . -
Run with database connection
docker run -d \ --name ilayer-bot \ -p 8080:8080 \ -e DATABASE_URL="postgresql://user:password@host:5432/dbname" \ --env-file .env.prod \ ilayer-bot:latestThe entrypoint script will automatically run migrations before starting the app.
Key environment variables in .env:
# Application
PORT=8080
# Database
DATABASE_USER=ilayer_admin
DATABASE_PASSWORD=ilayer_password
DATABASE_NAME=ilayer_db
DATABASE_URL=postgresql://ilayer_admin:ilayer_password@localhost:5432/ilayer_db
# Blockchain RPC URLs
RPC_URL_ARBITRUM=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
RPC_URL_BASE=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY
RPC_URL_BSC=https://bsc-dataseed.binance.org
RPC_URL_POLYGON=https://polygon-rpc.com
# Private Keys (one per chain)
PRIVATE_KEY_ARBITRUM=your_private_key
PRIVATE_KEY_BASE=your_private_key
PRIVATE_KEY_BSC=your_private_key
PRIVATE_KEY_POLYGON=your_private_key
# Soketi Configuration
SOKETI_APP_ID=ilayer
SOKETI_APP_KEY=app-key
SOKETI_APP_SECRET=app-secret
SOKETI_HOST=localhost
SOKETI_PORT=6001
# Solver Configuration
SOLVER_ID=solver-bot-1
SOLVER_LISTEN_CHAINS=arbitrum,base
SOLVER_NUMERAIRE=USDC
SOLVER_MARGIN_BPS=10For a complete list of configuration options, see DATABASE_SETUP_PLAN.md.
npm run start:dev- Start in development mode with auto-reload (includes DB setup)npm run start:debug- Start in debug modenpm run dev- Alias for start:dev
npm run build- Build for productionnpm run start:prod- Start in production mode (includes DB migrations)
npm run prisma:generate- Generate Prisma clientnpm run prisma:migrate:dev- Create and apply migration (dev)npm run prisma:migrate:deploy- Apply migrations (production)npm run prisma:studio- Open Prisma Studio GUInpm run prisma:reset- Reset database (WARNING: deletes all data)npm run db:setup- Generate client + deploy migrationsnpm run db:setup:dev- Generate client + run dev migrations
npm run lint- Run ESLintnpm run format- Format code with Prettiernpm test- Run testsnpm run test:watch- Run tests in watch modenpm run test:cov- Run tests with coverage
npm run smoke:soketi- Test Soketi WebSocket connection
Problem: P1010: User was denied access on the database
Solution:
-
Verify PostgreSQL is running:
# macOS brew services list | grep postgresql # Linux sudo systemctl status postgresql
-
Check database credentials:
psql -U ilayer_admin -d ilayer_db -c "SELECT 1;" -
Verify DATABASE_URL in
.envmatches your setup
Problem: Error: P1001: Can't reach database server
Solution:
- If using Docker: Ensure database service is running (
docker compose ps) - If local: Check PostgreSQL is running on port 5432
- Verify firewall settings
Problem: Migrations fail with "relation already exists"
Solution:
# Mark existing migrations as applied
npx prisma migrate resolve --applied <migration_name>
# Or reset and reapply (WARNING: deletes data)
npm run prisma:resetProblem: Prisma client out of sync
Solution:
npm run prisma:generateProblem: docker compose up fails with port conflicts
Solution:
# Stop conflicting services
docker compose down
# Or change ports in docker-compose.ymlProblem: Docker containers keep restarting
Solution:
# Check logs
docker compose logs -f bot
# Common causes:
# - Database not ready (wait for health check)
# - Migration failure (check DATABASE_URL)
# - Missing environment variablesProblem: Hot reload not working
Solution:
- Ensure you're using
npm run start:devnotnpm start - Check file watcher limits (Linux):
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf sudo sysctl -p
Problem: "Module not found" errors after updating
Solution:
# Clean install
rm -rf node_modules package-lock.json
npm install
npm run prisma:generate- Check the database setup plan for detailed architecture
- Review Prisma logs:
DEBUG="prisma:*" npm run start:dev - Check application logs in
docker compose logs - Open an issue on GitHub
The bot uses:
- NestJS: Backend framework
- Prisma: Type-safe database ORM
- PostgreSQL: Primary database
- Soketi: WebSocket server for RFQ
- Viem/Ethers: Blockchain interaction
- Docker: Containerization
For detailed architecture and setup process, see DATABASE_SETUP_PLAN.md.
MIT