|
| 1 | +# Sparta Discord Bot |
| 2 | + |
| 3 | +A Discord bot for managing Aztec validators, built with Node.js and deployed on AWS Elastic Beanstalk. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Sparta is a Discord bot designed to manage and monitor Aztec validators. It provides commands for: |
| 8 | +- Validator management (add, remove, list) |
| 9 | +- Chain information retrieval |
| 10 | +- Committee management |
| 11 | +- Stake management |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Node.js v18 or higher |
| 16 | +- AWS CLI configured with appropriate credentials |
| 17 | +- Terraform v1.0 or higher |
| 18 | +- Discord Bot Token and Application ID from [Discord Developer Portal](https://discord.com/developers/applications) |
| 19 | +- Ethereum node access (local or remote) |
| 20 | + |
| 21 | +## Security Notice |
| 22 | + |
| 23 | +⚠️ **Important**: This project uses sensitive credentials that should never be committed to version control: |
| 24 | +- Discord bot tokens |
| 25 | +- Ethereum private keys |
| 26 | +- AWS credentials |
| 27 | +- Environment variables |
| 28 | + |
| 29 | +Always use: |
| 30 | +- `.env` files for local development (never commit these) |
| 31 | +- AWS Secrets Manager for production secrets |
| 32 | +- `terraform.tfvars` for Terraform variables (never commit this) |
| 33 | +- Ensure `.gitignore` includes all sensitive files |
| 34 | +- Use environment-specific configuration files |
| 35 | + |
| 36 | +## Project Structure |
| 37 | + |
| 38 | +``` |
| 39 | +sparta/ |
| 40 | +├── src/ # Source code |
| 41 | +│ ├── commands/ # Discord bot commands |
| 42 | +│ ├── discord/ # Discord bot setup |
| 43 | +│ ├── services/ # Business logic services |
| 44 | +│ ├── utils/ # Utility functions |
| 45 | +│ └── admins/ # Admin-only commands |
| 46 | +├── terraform/ # Infrastructure as Code |
| 47 | +└── docker/ # Docker configuration |
| 48 | +``` |
| 49 | + |
| 50 | +## Local Development |
| 51 | + |
| 52 | +1. Clone the repository: |
| 53 | +```bash |
| 54 | +git clone <repository-url> |
| 55 | +cd sparta |
| 56 | +``` |
| 57 | + |
| 58 | +2. Install dependencies: |
| 59 | +```bash |
| 60 | +cd src |
| 61 | +npm install |
| 62 | +``` |
| 63 | + |
| 64 | +3. Create a `.env` file in the `src` directory using `.env.example` as a template: |
| 65 | +```bash |
| 66 | +cp .env.example .env |
| 67 | +``` |
| 68 | + |
| 69 | +4. Fill in the required environment variables in `.env`: |
| 70 | +``` |
| 71 | +# Discord Bot Configuration |
| 72 | +BOT_TOKEN=your_bot_token |
| 73 | +BOT_CLIENT_ID=your_client_id |
| 74 | +GUILD_ID=your_guild_id |
| 75 | +
|
| 76 | +# Ethereum Configuration |
| 77 | +ETHEREUM_HOST=http://localhost:8545 |
| 78 | +ETHEREUM_ROLLUP_ADDRESS=your_rollup_address |
| 79 | +ETHEREUM_CHAIN_ID=1337 |
| 80 | +MINTER_PRIVATE_KEY=your_private_key |
| 81 | +WITHDRAWER_ADDRESS=address_to_withdraw_funds_to |
| 82 | +ETHEREUM_VALUE=20ether |
| 83 | +APPROVAL_AMOUNT=some_amount |
| 84 | +``` |
| 85 | + |
| 86 | +5. Start the bot in development mode: |
| 87 | +```bash |
| 88 | +npm run watch |
| 89 | +``` |
| 90 | + |
| 91 | +## Deployment |
| 92 | + |
| 93 | +The bot is deployed using Terraform to AWS Elastic Container Service (ECS). Follow these steps: |
| 94 | + |
| 95 | +1. Navigate to the terraform directory: |
| 96 | +```bash |
| 97 | +cd terraform |
| 98 | +``` |
| 99 | + |
| 100 | +2. Create `terraform.tfvars` using the example file: |
| 101 | +```bash |
| 102 | +cp terraform.tfvars.example terraform.tfvars |
| 103 | +``` |
| 104 | + |
| 105 | +3. Fill in the required variables in `terraform.tfvars`: |
| 106 | +```hcl |
| 107 | +environment = "production" |
| 108 | +aws_region = "us-west-2" |
| 109 | +bot_token = "your_bot_token" |
| 110 | +bot_client_id = "your_client_id" |
| 111 | +guild_id = "your_guild_id" |
| 112 | +ethereum_host = "your_ethereum_host" |
| 113 | +# ... other variables |
| 114 | +``` |
| 115 | + |
| 116 | +4. Initialize Terraform: |
| 117 | +```bash |
| 118 | +terraform init |
| 119 | +``` |
| 120 | + |
| 121 | +5. Deploy: |
| 122 | +```bash |
| 123 | +terraform apply |
| 124 | +``` |
| 125 | + |
| 126 | +## Architecture |
| 127 | + |
| 128 | +- **Discord.js**: Handles bot interactions and commands |
| 129 | +- **AWS ECS**: Runs the bot in containers for high availability |
| 130 | +- **AWS Secrets Manager**: Securely stores sensitive configuration |
| 131 | +- **TypeScript**: Provides type safety and better development experience |
| 132 | +- **Terraform**: Manages infrastructure as code |
| 133 | +- **Docker**: Containerizes the application |
| 134 | + |
| 135 | +## Environment Variables |
| 136 | + |
| 137 | +### Development |
| 138 | +- Uses `.env` file for local configuration |
| 139 | +- Supports hot reloading through `npm run watch` |
| 140 | +- Environment-specific configurations (.env.local, .env.staging) |
| 141 | + |
| 142 | +### Production |
| 143 | +- Uses AWS Secrets Manager for secure configuration |
| 144 | +- Automatically loads secrets in production environment |
| 145 | +- Supports staging and production environments |
| 146 | + |
| 147 | +## Available Commands |
| 148 | + |
| 149 | +### User Commands |
| 150 | +- `/get-info`: Get chain information |
| 151 | +- `/validator info`: Get validator information |
| 152 | + |
| 153 | +### Admin Commands |
| 154 | +- `/admin validators get`: List validators |
| 155 | +- `/admin validators add`: Add a validator |
| 156 | +- `/admin validators remove`: Remove a validator |
| 157 | +- `/admin committee get`: Get committee information |
| 158 | +- `/admin stake manage`: Manage validator stakes |
| 159 | + |
| 160 | +## Security Best Practices |
| 161 | + |
| 162 | +1. **Environment Variables** |
| 163 | + - Never commit .env files |
| 164 | + - Use different env files for different environments |
| 165 | + - Rotate secrets regularly |
| 166 | + |
| 167 | +2. **AWS Security** |
| 168 | + - Use IAM roles with least privilege |
| 169 | + - Enable CloudWatch logging |
| 170 | + - Use security groups to restrict access |
| 171 | + |
| 172 | +3. **Discord Security** |
| 173 | + - Implement command permissions |
| 174 | + - Use ephemeral messages for sensitive info |
| 175 | + - Validate user inputs |
| 176 | + |
| 177 | +4. **Ethereum Security** |
| 178 | + - Never expose private keys |
| 179 | + - Use secure RPC endpoints |
| 180 | + - Implement transaction signing safeguards |
| 181 | + |
| 182 | +## Contributing |
| 183 | + |
| 184 | +1. Create a feature branch |
| 185 | +2. Make your changes |
| 186 | +3. Submit a pull request |
| 187 | + |
| 188 | +## Monitoring and Logging |
| 189 | + |
| 190 | +- AWS CloudWatch for container logs |
| 191 | +- Discord command execution logging |
| 192 | +- Error tracking and reporting |
| 193 | +- Performance monitoring |
| 194 | + |
| 195 | +## Support |
| 196 | + |
| 197 | +For support, please open an issue in the repository or contact the maintainers. |
0 commit comments