The Keeper is an off-chain automation service that monitors the PIFP protocol smart contracts on Stellar/Soroban and triggers scheduled tasks automatically.
The Keeper bot:
- Monitors contract events for scheduled tasks
- Maintains a persistent task registry
- Triggers contract functions at the appropriate time
- Exposes health check and metrics endpoints
- Node.js 20+ (for local development)
- Docker and Docker Compose (for containerized deployment)
- Install dependencies:
npm install- Configure environment:
cp .env.example .env
# Edit .env with your configuration- Run the keeper:
npm startFor development with auto-reload:
npm run devThe Keeper is designed to run as a Docker container for production deployments.
npm run docker:buildOr manually:
docker build -t pifp-keeper:latest .- Configure environment:
cp .env.example .env
# Edit .env with your Stellar network configuration- Start the keeper:
docker compose up -d keeper- View logs:
docker compose logs -f keeper- Stop the keeper:
docker compose downFrom the repository root directory:
docker compose up -d keeperThis will:
- Build the keeper image
- Start the container
- Mount
./keeper/datafor persistent task storage - Load environment variables from
./keeper/.env - Expose port 3000 for health checks and metrics
- Automatically restart unless stopped manually
All configuration is done via environment variables in the .env file:
| Variable | Description | Default |
|---|---|---|
PORT |
HTTP server port | 3000 |
HOST |
HTTP server host | 0.0.0.0 |
POLL_INTERVAL_MS |
Task check interval in milliseconds | 30000 |
STELLAR_NETWORK |
Stellar network (testnet/mainnet) | testnet |
STELLAR_RPC_URL |
Soroban RPC endpoint | https://soroban-testnet.stellar.org |
CONTRACT_ADDRESS |
PIFP protocol contract address | - |
KEEPER_SECRET_KEY |
Keeper wallet secret key | - |
LOG_LEVEL |
Logging level | info |
GET /healthReturns the keeper's health status:
{
"status": "healthy",
"uptime": 123.45,
"timestamp": "2024-01-01T00:00:00.000Z"
}GET /metricsReturns operational metrics:
{
"totalTasks": 10,
"activeTasks": 3,
"completedTasks": 7,
"uptime": 123.45
}The keeper stores its task registry in ./data/tasks.json. This file is automatically created and maintained by the keeper.
When running in Docker, this directory is mounted as a volume to ensure data persists across container restarts:
volumes:
- ./keeper/data:/app/dataThe keeper consists of three main components:
- HTTP Server (
src/index.js): Exposes health check and metrics endpoints - Task Registry (
src/taskRegistry.js): Manages persistent task storage - Monitor (
src/monitor.js): Polls for tasks and triggers contract calls
- The container runs as a non-root user (
nodejs:nodejs) - Sensitive configuration is loaded from environment variables
- The
.envfile is excluded from the Docker image via.dockerignore - Health checks ensure the keeper is responsive
Deploy to any cloud provider (AWS EC2, DigitalOcean, Linode, etc.):
# SSH into your VM
ssh user@your-server
# Clone the repository
git clone <repo-url>
cd pifp-stellar
# Configure the keeper
cd keeper
cp .env.example .env
nano .env # Edit configuration
# Start with Docker Compose
cd ..
docker compose up -d keeperThe keeper can be deployed to Kubernetes, Docker Swarm, or other orchestrators:
Kubernetes Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: pifp-keeper
spec:
replicas: 1
selector:
matchLabels:
app: pifp-keeper
template:
metadata:
labels:
app: pifp-keeper
spec:
containers:
- name: keeper
image: pifp-keeper:latest
ports:
- containerPort: 3000
envFrom:
- secretRef:
name: keeper-secrets
volumeMounts:
- name: data
mountPath: /app/data
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 5
periodSeconds: 30
volumes:
- name: data
persistentVolumeClaim:
claimName: keeper-dataThe keeper exposes Prometheus-compatible metrics at /metrics. You can integrate with monitoring systems:
# Check health
curl http://localhost:3000/health
# Get metrics
curl http://localhost:3000/metricsCheck logs:
docker compose logs keeperVerify the keeper is listening:
docker compose exec keeper wget -O- http://localhost:3000/health- Check the task registry:
./keeper/data/tasks.json - Verify Stellar network connectivity
- Check keeper logs for errors
keeper/
├── src/
│ ├── index.js # Main entry point
│ ├── taskRegistry.js # Task persistence
│ └── monitor.js # Task monitoring
├── data/ # Task registry storage (gitignored)
├── Dockerfile # Multi-stage Docker build
├── .dockerignore # Docker build exclusions
├── .env.example # Environment template
├── package.json # Node.js dependencies
└── README.md # This file
To extend the keeper:
- Add new modules in
src/ - Update
src/index.jsto integrate - Add configuration to
.env.example - Update this README
MIT