Skip to content

Commit 67273ce

Browse files
authored
Merge pull request #470 from AztecProtocol/zkpedro/sparta_bot
2 parents e0bc0b9 + 1b8bb02 commit 67273ce

31 files changed

+10781
-0
lines changed

LICENSE.txt

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
2+
"Business Source License" is a trademark of MariaDB Corporation Ab.
3+
4+
Parameters
5+
6+
Licensor: HashiCorp, Inc.
7+
Licensed Work: Terraform Version 1.6.0 or later. The Licensed Work is (c) 2024
8+
HashiCorp, Inc.
9+
Additional Use Grant: You may make production use of the Licensed Work, provided
10+
Your use does not include offering the Licensed Work to third
11+
parties on a hosted or embedded basis in order to compete with
12+
HashiCorp's paid version(s) of the Licensed Work. For purposes
13+
of this license:
14+
15+
A "competitive offering" is a Product that is offered to third
16+
parties on a paid basis, including through paid support
17+
arrangements, that significantly overlaps with the capabilities
18+
of HashiCorp's paid version(s) of the Licensed Work. If Your
19+
Product is not a competitive offering when You first make it
20+
generally available, it will not become a competitive offering
21+
later due to HashiCorp releasing a new version of the Licensed
22+
Work with additional capabilities. In addition, Products that
23+
are not provided on a paid basis are not competitive.
24+
25+
"Product" means software that is offered to end users to manage
26+
in their own environments or offered as a service on a hosted
27+
basis.
28+
29+
"Embedded" means including the source code or executable code
30+
from the Licensed Work in a competitive offering. "Embedded"
31+
also means packaging the competitive offering in such a way
32+
that the Licensed Work must be accessed or downloaded for the
33+
competitive offering to operate.
34+
35+
Hosting or using the Licensed Work(s) for internal purposes
36+
within an organization is not considered a competitive
37+
offering. HashiCorp considers your organization to include all
38+
of your affiliates under common control.
39+
40+
For binding interpretive guidance on using HashiCorp products
41+
under the Business Source License, please visit our FAQ.
42+
(https://www.hashicorp.com/license-faq)
43+
Change Date: Four years from the date the Licensed Work is published.
44+
Change License: MPL 2.0
45+
46+
For information about alternative licensing arrangements for the Licensed Work,
47+
please contact [email protected].
48+
49+
Notice
50+
51+
Business Source License 1.1
52+
53+
Terms
54+
55+
The Licensor hereby grants you the right to copy, modify, create derivative
56+
works, redistribute, and make non-production use of the Licensed Work. The
57+
Licensor may make an Additional Use Grant, above, permitting limited production use.
58+
59+
Effective on the Change Date, or the fourth anniversary of the first publicly
60+
available distribution of a specific version of the Licensed Work under this
61+
License, whichever comes first, the Licensor hereby grants you rights under
62+
the terms of the Change License, and the rights granted in the paragraph
63+
above terminate.
64+
65+
If your use of the Licensed Work does not comply with the requirements
66+
currently in effect as described in this License, you must purchase a
67+
commercial license from the Licensor, its affiliated entities, or authorized
68+
resellers, or you must refrain from using the Licensed Work.
69+
70+
All copies of the original and modified Licensed Work, and derivative works
71+
of the Licensed Work, are subject to this License. This License applies
72+
separately for each version of the Licensed Work and the Change Date may vary
73+
for each version of the Licensed Work released by Licensor.
74+
75+
You must conspicuously display this License on each original or modified copy
76+
of the Licensed Work. If you receive the Licensed Work in original or
77+
modified form from a third party, the terms and conditions set forth in this
78+
License apply to your use of that work.
79+
80+
Any use of the Licensed Work in violation of this License will automatically
81+
terminate your rights under this License for the current and all other
82+
versions of the Licensed Work.
83+
84+
This License does not grant you any right in any trademark or logo of
85+
Licensor or its affiliates (provided that you may use a trademark or logo of
86+
Licensor as expressly required by this License).
87+
88+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
89+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
90+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
91+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
92+
TITLE.

terraform.tfstate

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "1.10.4",
4+
"serial": 1,
5+
"lineage": "5b4500a2-d397-e510-9de0-aaeab4d564c0",
6+
"outputs": {},
7+
"resources": [],
8+
"check_results": null
9+
}

tooling/sparta/.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
.env*
3+
dist

tooling/sparta/.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Node.js
2+
node_modules/
3+
dist/
4+
*.log
5+
.env
6+
.env.*
7+
!.env.example
8+
9+
# Terraform
10+
*.tfstate
11+
*.tfstate.*
12+
.terraform/
13+
terraform.tfvars
14+
.terraform.lock.hcl
15+
*.tfvars
16+
!terraform.tfvars.example
17+
18+
# Build artifacts
19+
*.zip
20+
deployment-*.zip
21+
22+
# IDE
23+
.vscode/
24+
.idea/
25+
*.swp
26+
*.swo
27+
28+
# OS
29+
.DS_Store
30+
Thumbs.db
31+
32+
# Elastic Beanstalk Files
33+
.elasticbeanstalk/*
34+
!.elasticbeanstalk/*.cfg.yml
35+
!.elasticbeanstalk/*.global.yml
36+
37+
# Package managers
38+
bun.lockb
39+
yarn.lock
40+
package-lock.json

tooling/sparta/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM oven/bun:latest
2+
3+
ENV PATH="/root/.foundry/bin:${PATH}"
4+
5+
RUN apt update && apt install -y curl apt-utils
6+
RUN curl -fsSL https://get.docker.com | bash
7+
RUN curl -L https://foundry.paradigm.xyz | bash
8+
9+
RUN foundryup
10+
RUN cast --version
11+
12+
WORKDIR /app
13+
COPY src ./
14+
15+
RUN bun install
16+
CMD ["bun", "run", "start"]

tooling/sparta/README.md

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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.

tooling/sparta/src/.env.example

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Discord Bot Configuration
2+
BOT_TOKEN=your_bot_token_here
3+
BOT_CLIENT_ID=your_client_id_here
4+
GUILD_ID=your_guild_id_here
5+
6+
# Ethereum Configuration
7+
ETHEREUM_HOST=http://localhost:8545
8+
MINTER_PRIVATE_KEY=your_minter_private_key_here
9+
ETHEREUM_REGISTRY_ADDRESS=your_registry_address_here
10+
WITHDRAWER_ADDRESS=your_withdrawer_address_here
11+
ETHEREUM_CHAIN_ID=1337
12+
ETHEREUM_VALUE=20ether
13+
14+
MINIMUM_STAKE=100000000000000000000
15+
APPROVAL_AMOUNT=10000000000000000000000

tooling/sparta/src/admins/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import validators from "./manageValidators.js";
2+
3+
export default { validators };

0 commit comments

Comments
 (0)