1
1
# Sparta Discord Bot
2
2
3
- A Discord bot for managing Aztec validators, built with Node.js and deployed on AWS Elastic Beanstalk.
3
+ A Discord bot for managing Aztec validators and community roles , built with Bun/TypeScript and deployed on AWS Elastic Beanstalk.
4
4
5
5
## Overview
6
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
7
+ Sparta is a Discord bot designed to manage and monitor Aztec validators and community roles within the Discord server. It provides:
8
+
9
+ - ** Role Management** : Automatically assigns roles based on user scores from Google Sheets
10
+ - ** Validator Management** : Commands to add, remove, and check validators
11
+ - ** Chain Information** : Retrieves blockchain data like pending blocks, proven blocks, epochs, slots
12
+ - ** Discord Integration** : Full integration with Discord slash commands
12
13
13
14
## Prerequisites
14
15
15
- - Node.js v18 or higher
16
+ - [ Bun] ( https://bun.sh ) v1.0 or higher (used as runtime and package manager)
17
+ - Node.js v18 or higher (for development tools)
16
18
- AWS CLI configured with appropriate credentials
17
19
- Terraform v1.0 or higher
18
20
- Discord Bot Token and Application ID from [ Discord Developer Portal] ( https://discord.com/developers/applications )
19
21
- Ethereum node access (local or remote)
22
+ - Google Sheets API access (for role management)
20
23
21
24
## Security Notice
22
25
23
26
⚠️ ** Important** : This project uses sensitive credentials that should never be committed to version control:
24
27
- Discord bot tokens
25
28
- Ethereum private keys
26
29
- AWS credentials
30
+ - Google Sheets API credentials
27
31
- Environment variables
28
32
29
33
Always use:
@@ -37,14 +41,20 @@ Always use:
37
41
38
42
```
39
43
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
44
+ ├── src/ # Source code
45
+ │ ├── clients/ # External API clients (Discord, Ethereum, Google)
46
+ │ ├── roles/ # Role-specific Discord commands
47
+ │ │ ├── nodeOperators/ # Commands for Node Operator role
48
+ │ │ └── admins/ # Admin-only commands
49
+ │ ├── services/ # Business logic services
50
+ │ │ ├── chaininfo-service.ts # Chain information retrieval
51
+ │ │ ├── discord-service.ts # Discord role management
52
+ │ │ ├── googlesheet-service.ts # Google Sheets integration
53
+ │ │ ├── validator-service.ts # Validator management
54
+ │ │ └── index.ts # Service exports
55
+ │ └── utils/ # Utility functions
56
+ ├── terraform/ # Infrastructure as Code
57
+ └── Dockerfile # Docker configuration
48
58
```
49
59
50
60
## Local Development
@@ -55,18 +65,18 @@ git clone <repository-url>
55
65
cd sparta
56
66
```
57
67
58
- 2 . Install dependencies:
68
+ 2 . Install dependencies using Bun :
59
69
``` bash
60
70
cd src
61
- npm install
71
+ bun install
62
72
```
63
73
64
74
3 . Create a ` .env ` file in the ` src ` directory using ` .env.example ` as a template:
65
75
``` bash
66
76
cp .env.example .env
67
77
```
68
78
69
- 4 . Fill in the required environment variables in ` .env ` :
79
+ 4 . Fill in the required environment variables in ` .env ` . Required variables include :
70
80
```
71
81
# Discord Bot Configuration
72
82
BOT_TOKEN=your_bot_token
@@ -75,20 +85,47 @@ GUILD_ID=your_guild_id
75
85
76
86
# Ethereum Configuration
77
87
ETHEREUM_HOST=http://localhost:8545
78
- ETHEREUM_ROLLUP_ADDRESS=your_rollup_address
79
- ETHEREUM_CHAIN_ID=1337
80
88
MINTER_PRIVATE_KEY=your_private_key
89
+ ETHEREUM_REGISTRY_ADDRESS=your_registry_address
81
90
WITHDRAWER_ADDRESS=address_to_withdraw_funds_to
91
+ ETHEREUM_CHAIN_ID=1337
82
92
ETHEREUM_VALUE=20ether
83
- APPROVAL_AMOUNT=some_amount
93
+ MINIMUM_STAKE=100000000000000000000
94
+ APPROVAL_AMOUNT=10000000000000000000000
95
+
96
+ # Google Sheets Configuration
97
+ GOOGLE_API_KEY=your_api_key
98
+ SPREADSHEET_ID=your_spreadsheet_id
84
99
```
85
100
86
- 5 . Start the bot in development mode:
101
+ 5 . Start the bot in development mode with hot reloading :
87
102
``` bash
88
- npm run watch
103
+ bun run dev
89
104
```
90
105
91
- ## Deployment
106
+ 6 . For building a production version:
107
+ ``` bash
108
+ bun run build
109
+ ```
110
+
111
+ 7 . To start the production version:
112
+ ``` bash
113
+ bun run start
114
+ ```
115
+
116
+ ## Building with Docker
117
+
118
+ 1 . Build the Docker image:
119
+ ``` bash
120
+ docker build -t sparta-bot .
121
+ ```
122
+
123
+ 2 . Run the container:
124
+ ``` bash
125
+ docker run -d --name sparta-bot --env-file ./src/.env sparta-bot
126
+ ```
127
+
128
+ ## Deployment with Terraform
92
129
93
130
The bot is deployed using Terraform to AWS Elastic Container Service (ECS). Follow these steps:
94
131
@@ -102,16 +139,7 @@ cd terraform
102
139
cp terraform.tfvars.example terraform.tfvars
103
140
```
104
141
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
- ```
142
+ 3 . Fill in the required variables in ` terraform.tfvars ` .
115
143
116
144
4 . Initialize Terraform:
117
145
``` bash
@@ -123,40 +151,49 @@ terraform init
123
151
terraform apply
124
152
```
125
153
126
- ## Architecture
154
+ ## Bot Functionality
155
+
156
+ ### Role Management
157
+ - Monitors Google Sheets for user scores
158
+ - Assigns Discord roles based on score thresholds:
159
+ - Node Operator (base role): Default role
160
+ - Defender (middle role): Score > 5
161
+ - Sentinel (highest role): Score > 10
162
+
163
+ ### Validator Management
164
+ - Add validators to the blockchain
165
+ - Remove validators from the blockchain
166
+ - Check validator status and information
167
+
168
+ ### Chain Information
169
+ - Get pending block number
170
+ - Get proven block number
171
+ - Check current epoch and slot
172
+ - View committee members
127
173
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
174
+ ## Available Commands
175
+
176
+ ### Node Operator Commands
177
+ - ` /get-info ` : Get chain information including pending block, proven block, current epoch, current slot, and proposer
178
+ - ` /validator check ` : Check if an address is a validator
179
+ - ` /validator register ` : Register a validator address
180
+ - ` /validator help ` : Get help for validator commands
181
+
182
+ ### Admin Commands
183
+ (More details in the admin command section)
134
184
135
185
## Environment Variables
136
186
137
187
### Development
138
188
- Uses ` .env ` file for local configuration
139
- - Supports hot reloading through ` npm run watch `
189
+ - Supports hot reloading through ` bun run dev `
140
190
- Environment-specific configurations (.env.local, .env.staging)
141
191
142
192
### Production
143
193
- Uses AWS Secrets Manager for secure configuration
144
194
- Automatically loads secrets in production environment
145
195
- Supports staging and production environments
146
196
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
197
## Security Best Practices
161
198
162
199
1 . ** Environment Variables**
@@ -179,19 +216,57 @@ terraform apply
179
216
- Use secure RPC endpoints
180
217
- Implement transaction signing safeguards
181
218
182
- ## Contributing
183
-
184
- 1 . Create a feature branch
185
- 2 . Make your changes
186
- 3 . Submit a pull request
187
-
188
219
## Monitoring and Logging
189
220
190
221
- AWS CloudWatch for container logs
191
222
- Discord command execution logging
192
223
- Error tracking and reporting
193
224
- Performance monitoring
194
225
226
+ ## Logging
227
+
228
+ The application uses Pino for structured logging with the following features:
229
+
230
+ - ** Multiple log levels** : trace, debug, info, warn, error, fatal
231
+ - ** Colorful output** : Different colors for different log levels when pretty printing is enabled
232
+ - ** Timestamps** : Each log includes an ISO timestamp
233
+ - ** Request logging** : HTTP requests can be logged at the debug level
234
+ - ** Structured logging** : Logs are output in JSON format for easy parsing
235
+
236
+ ### Configuration
237
+
238
+ Logging can be configured through environment variables:
239
+
240
+ - ` LOG_LEVEL ` : Set the minimum log level (trace, debug, info, warn, error, fatal)
241
+ - ` LOG_PRETTY_PRINT ` : Enable/disable colorful, human-readable logs (true/false)
242
+
243
+ #### Example
244
+
245
+ ``` sh
246
+ # Set log level to debug and enable pretty printing
247
+ export LOG_LEVEL=debug
248
+ export LOG_PRETTY_PRINT=true
249
+ npm run dev
250
+ ```
251
+
252
+ ### Terraform Configuration
253
+
254
+ Logging can also be configured through Terraform variables:
255
+
256
+ ``` hcl
257
+ module "sparta" {
258
+ # ...
259
+ log_level = "debug"
260
+ log_pretty_print = true
261
+ }
262
+ ```
263
+
264
+ ## Contributing
265
+
266
+ 1 . Create a feature branch
267
+ 2 . Make your changes
268
+ 3 . Submit a pull request
269
+
195
270
## Support
196
271
197
272
For support, please open an issue in the repository or contact the maintainers.
0 commit comments