Skip to content

Commit b5e8b12

Browse files
committed
done with fargate
1 parent cfa4488 commit b5e8b12

20 files changed

+896
-289
lines changed

tooling/sparta/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
.env*
3+
dist

tooling/sparta/README.md

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
A Discord bot for managing Aztec validators, built with Node.js and deployed on AWS Elastic Beanstalk.
44

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+
513
## Prerequisites
614

715
- Node.js v18 or higher
816
- AWS CLI configured with appropriate credentials
917
- Terraform v1.0 or higher
1018
- Discord Bot Token and Application ID from [Discord Developer Portal](https://discord.com/developers/applications)
19+
- Ethereum node access (local or remote)
1120

1221
## Security Notice
1322

@@ -21,6 +30,22 @@ Always use:
2130
- `.env` files for local development (never commit these)
2231
- AWS Secrets Manager for production secrets
2332
- `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+
```
2449

2550
## Local Development
2651

@@ -64,7 +89,7 @@ npm run watch
6489

6590
## Deployment
6691

67-
The bot is deployed using Terraform to AWS Elastic Beanstalk. Follow these steps:
92+
The bot is deployed using Terraform to AWS Elastic Container Service (ECS). Follow these steps:
6893

6994
1. Navigate to the terraform directory:
7095
```bash
@@ -100,42 +125,71 @@ terraform apply
100125
## Architecture
101126

102127
- **Discord.js**: Handles bot interactions and commands
103-
- **AWS Elastic Beanstalk**: Hosts the bot in a scalable environment
128+
- **AWS ECS**: Runs the bot in containers for high availability
104129
- **AWS Secrets Manager**: Securely stores sensitive configuration
105130
- **TypeScript**: Provides type safety and better development experience
131+
- **Terraform**: Manages infrastructure as code
132+
- **Docker**: Containerizes the application
106133

107134
## Environment Variables
108135

109136
### Development
110137
- Uses `.env` file for local configuration
111138
- Supports hot reloading through `npm run watch`
139+
- Environment-specific configurations (.env.local, .env.staging)
112140

113141
### Production
114142
- Uses AWS Secrets Manager for secure configuration
115143
- Automatically loads secrets in production environment
116144
- Supports staging and production environments
117145

118-
## Commands
146+
## Available Commands
119147

148+
### User Commands
120149
- `/get-info`: Get chain information
150+
- `/validator info`: Get validator information
151+
152+
### Admin Commands
121153
- `/admin validators get`: List validators
122154
- `/admin validators remove`: Remove a validator
123155
- `/admin committee get`: Get committee information
156+
- `/admin stake manage`: Manage validator stakes
157+
158+
## Security Best Practices
159+
160+
1. **Environment Variables**
161+
- Never commit .env files
162+
- Use different env files for different environments
163+
- Rotate secrets regularly
164+
165+
2. **AWS Security**
166+
- Use IAM roles with least privilege
167+
- Enable CloudWatch logging
168+
- Use security groups to restrict access
169+
170+
3. **Discord Security**
171+
- Implement command permissions
172+
- Use ephemeral messages for sensitive info
173+
- Validate user inputs
174+
175+
4. **Ethereum Security**
176+
- Never expose private keys
177+
- Use secure RPC endpoints
178+
- Implement transaction signing safeguards
124179

125180
## Contributing
126181

127182
1. Create a feature branch
128183
2. Make your changes
129184
3. Submit a pull request
130185

131-
## Security
186+
## Monitoring and Logging
132187

133-
- All sensitive information is stored in AWS Secrets Manager
134-
- IAM roles are configured with least privilege
135-
- Environment variables are never committed to version control
136-
- SSH access is controlled via key pairs
137-
- No sensitive information in logs or error messages
188+
- AWS CloudWatch for container logs
189+
- Discord command execution logging
190+
- Error tracking and reporting
191+
- Performance monitoring
138192

139-
## License
193+
## Support
140194

141-
[Your License]
195+
For support, please open an issue in the repository or contact the maintainers.

tooling/sparta/src/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ ETHEREUM_ROLLUP_ADDRESS=your_rollup_address_here
1010
ETHEREUM_CHAIN_ID=1337
1111
ETHEREUM_VALUE=20ether
1212
ETHEREUM_ADMIN_ADDRESS=your_admin_address_here
13+
14+
MINIMUM_STAKE=100000000000000000000

tooling/sparta/src/.platform/hooks/prebuild/01_install_dependencies.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

tooling/sparta/src/admins/validators.ts renamed to tooling/sparta/src/admins/editValidators.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,28 @@ export default {
6666
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
6767
.addSubcommandGroup((group) =>
6868
group
69-
.setName("validators")
70-
.setDescription("Manage validators")
69+
.setName("get")
70+
.setDescription("Get info about validators")
7171
.addSubcommand((subcommand) =>
72-
subcommand.setName("get").setDescription("Get validators")
72+
subcommand
73+
.setName("validators")
74+
.setDescription("Get validators")
7375
)
7476
.addSubcommand((subcommand) =>
7577
subcommand
76-
.setName("remove")
77-
.setDescription("Remove a validator")
78-
.addStringOption((option) =>
79-
option
80-
.setName("address")
81-
.setDescription("The validator to remove")
82-
.setRequired(true)
83-
)
78+
.setName("committee")
79+
.setDescription("Get committee")
8480
)
8581
)
86-
.addSubcommandGroup((group) =>
87-
group
88-
.setName("committee")
89-
.setDescription("Manage the committee")
90-
.addSubcommand((subcommand) =>
91-
subcommand
92-
.setName("get")
93-
.setDescription("Get the current committee")
82+
.addSubcommand((subcommand) =>
83+
subcommand
84+
.setName("remove")
85+
.setDescription("Remove a validator")
86+
.addStringOption((option) =>
87+
option
88+
.setName("address")
89+
.setDescription("The validator to remove")
90+
.setRequired(true)
9491
)
9592
),
9693

@@ -109,7 +106,6 @@ export default {
109106
const filteredCommittee = (committee as string[]).filter(
110107
(v) => !EXCLUDED_VALIDATORS.includes(v)
111108
);
112-
113109
if (interaction.options.getSubcommand() === "committee") {
114110
await paginate(
115111
filteredCommittee,

tooling/sparta/src/admins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import validators from "./validators.js";
1+
import validators from "./editValidators.js";
22

33
export default { validators };

tooling/sparta/src/discord/index.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @fileoverview Discord bot service implementation
3+
* @description Handles Discord bot initialization, command registration, and event handling
4+
* @module sparta/discord
5+
*/
6+
7+
import {
8+
Client,
9+
GatewayIntentBits,
10+
Collection,
11+
Interaction,
12+
MessageFlags,
13+
} from "discord.js";
14+
import { deployCommands } from "../utils/deploy-commands.js";
15+
import usersCommands from "../commands/index.js";
16+
import adminsCommands from "../admins/index.js";
17+
18+
/**
19+
* Extended Discord client interface with commands collection
20+
* @interface ExtendedClient
21+
* @extends {Client}
22+
*/
23+
interface ExtendedClient extends Client {
24+
commands: Collection<string, any>;
25+
}
26+
27+
// Initialize Discord client with required intents
28+
const client = new Client({
29+
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
30+
}) as ExtendedClient;
31+
32+
// Initialize commands collection
33+
client.commands = new Collection();
34+
35+
// Register all commands from both users and admins
36+
for (const command of Object.values({ ...usersCommands, ...adminsCommands })) {
37+
client.commands.set(command.data.name, command);
38+
}
39+
40+
console.log("Starting discord service...");
41+
42+
/**
43+
* Error event handler
44+
*/
45+
client.once("error", (error) => {
46+
console.error("Error:", error);
47+
});
48+
49+
/**
50+
* Ready event handler - called when bot is initialized
51+
*/
52+
client.once("ready", async () => {
53+
console.log("Sparta bot is ready!");
54+
console.log("Bot Client ID: ", process.env.BOT_CLIENT_ID);
55+
deployCommands();
56+
});
57+
58+
/**
59+
* Interaction event handler - processes all slash commands
60+
* @param {Interaction} interaction - The interaction object from Discord
61+
*/
62+
client.on("interactionCreate", async (interaction: Interaction) => {
63+
if (!interaction.isChatInputCommand()) return;
64+
65+
const command = client.commands.get(interaction.commandName);
66+
if (!command) return;
67+
68+
try {
69+
console.log("Executing command:", command.data.name);
70+
await command.execute(interaction);
71+
} catch (error) {
72+
console.error(error);
73+
await interaction.reply({
74+
content: "There was an error executing this command!",
75+
flags: MessageFlags.Ephemeral,
76+
});
77+
}
78+
});
79+
80+
client.login(process.env.BOT_TOKEN);

0 commit comments

Comments
 (0)