Skip to content

bot #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open

bot #551

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8047afa
wip
signorecello Apr 23, 2025
df61b03
wip
signorecello Apr 24, 2025
7ee4faf
HUUGE refactor
signorecello Apr 24, 2025
b56d25e
HUUUUGE cleanup
signorecello Apr 24, 2025
dd91782
yey
signorecello Apr 24, 2025
7740280
yey
signorecello Apr 24, 2025
d5dbe79
human verification working
signorecello Apr 25, 2025
fccbb4f
gitcoin stuff done
signorecello Apr 25, 2025
78fc8d8
another one bites the dust
signorecello Apr 26, 2025
be5ba25
wip
signorecello Apr 28, 2025
c0b99f0
wip
signorecello Apr 29, 2025
d130641
wip
signorecello Apr 29, 2025
65006e2
wip
signorecello Apr 29, 2025
189f29f
wip
signorecello Apr 29, 2025
34e3643
wip
signorecello Apr 29, 2025
272220a
wip
signorecello Apr 29, 2025
1b3b491
wip
signorecello Apr 29, 2025
b74bbfe
wip
signorecello Apr 29, 2025
cff8e31
wip
signorecello Apr 29, 2025
13e06b4
wip
signorecello Apr 29, 2025
0d1023a
wip
signorecello Apr 29, 2025
bb0d1fd
wip
signorecello Apr 29, 2025
d58263a
v1
signorecello Apr 30, 2025
6739cd4
v1
signorecello Apr 30, 2025
2ec447f
v1
signorecello Apr 30, 2025
7b20e41
v1
signorecello Apr 30, 2025
42af576
v1
signorecello Apr 30, 2025
da2c6c3
v1
signorecello Apr 30, 2025
c05a949
is this it
signorecello May 1, 2025
71d8e6b
is this it
signorecello May 1, 2025
3b8c27d
some more stuff
signorecello May 1, 2025
6e61c39
some more stuff
signorecello May 1, 2025
545e60f
some more stuff
signorecello May 1, 2025
c74b4f3
error handling
signorecello May 1, 2025
39da6c4
error handling
signorecello May 1, 2025
9d0f416
error handling
signorecello May 1, 2025
be4f8ee
error handling
signorecello May 1, 2025
fcba22d
error handling
signorecello May 1, 2025
b5f1c07
error handling
signorecello May 1, 2025
001b4e3
error handling
signorecello May 1, 2025
feead9e
error handling
signorecello May 1, 2025
e7b866e
error handling
signorecello May 1, 2025
b3a4184
error handling
signorecello May 1, 2025
134776c
error handling
signorecello May 1, 2025
26d2ecf
error handling
signorecello May 1, 2025
df2704d
fixing human verification api
signorecello May 1, 2025
6146ec3
bug
signorecello May 1, 2025
7341760
typo
signorecello May 1, 2025
e14a19c
roles assignment refactor
signorecello May 3, 2025
391f994
Merge remote-tracking branch 'origin' into zkpedro/human_sparta
signorecello May 12, 2025
b8d02cb
tf workflow
signorecello May 12, 2025
59c3155
bun lock
signorecello May 12, 2025
cfd6c72
removing human from human sparta
signorecello May 12, 2025
6e29e9f
removing human from human sparta
signorecello May 12, 2025
1b75199
removing human from human sparta
signorecello May 12, 2025
aaf9156
removing human from human sparta
signorecello May 12, 2025
985e2d5
api refac
signorecello May 13, 2025
8897a35
api refac
signorecello May 13, 2025
9665bec
api refac
signorecello May 13, 2025
73e92ff
i think this is it
signorecello May 14, 2025
4faa635
adding the lambda service
signorecello May 16, 2025
5c3b387
cleanup
signorecello May 16, 2025
d1ea110
Fix API URL configuration in Swagger docs and add DiscordUsernameInde…
signorecello May 16, 2025
0537cbe
Add fallback to scan when DiscordUsernameIndex is not available
signorecello May 16, 2025
3654a75
bugfix and some tests
signorecello May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 59 additions & 22 deletions .github/workflows/sparta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ permissions:
contents: read
pull-requests: write

env:
TF_LOG: DEBUG
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
terraform-sparta:
name: Terraform Sparta Bot
Expand All @@ -15,29 +20,61 @@ jobs:
run:
working-directory: tooling/sparta/terraform

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_bot_token: ${{ secrets.BOT_TOKEN }}
TF_VAR_passport_api_key: ${{ secrets.PASSPORT_API_KEY }}
TF_VAR_ethereum_host: ${{ secrets.ETHEREUM_HOST }}
TF_VAR_backend_api_key: ${{ secrets.BACKEND_API_KEY }}
TF_VAR_aws_region: "eu-west-2"
TF_VAR_environment: "production"
TF_VAR_bot_client_id: "1329079356785688616"
TF_VAR_guild_id: "1144692727120937080"
TF_VAR_passport_verified_role_id: "1364982673604345886"
TF_VAR_minimum_score: "10"
TF_VAR_passport_scorer_id: "11493"
TF_VAR_vite_reown_project_id: "d037e9da5c5c9b24cfcd94c509d88dce"
TF_VAR_staking_asset_handler_address: "0xF739D03e98e23A7B65940848aBA8921fF3bAc4b2"
TF_VAR_l1_chain_id: "11155111"
TF_VAR_local_dynamo_db: "false"
TF_VAR_dynamodb_local_endpoint: "http://localhost:8000"
TF_VAR_log_level: "info"
TF_VAR_log_pretty_print: "false"
TF_VAR_api_port: "3000"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.7

- name: Terraform Init
run: terraform init

- name: Terraform Format
run: terraform fmt -check
continue-on-error: true

- name: Terraform Validate
run: terraform validate

- name: Generate terraform.production.tfvars
run: |
cat > terraform.production.tfvars << EOF
# =============================================================================
# AWS Configuration
# =============================================================================
aws_region = "eu-west-2"
environment = "production"

# =============================================================================
# Application Secrets & Configuration
# =============================================================================

# --- Discord ---
bot_token = "${{ secrets.BOT_TOKEN }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing that is best practice to access secrets through shell variables rather than the secrets directly. When accessing secrets directly in run, there is a risk that the secrets get dumped in logs unintentionally.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen they get sanitized if printed, but I'll change it to meet best practices

bot_client_id = "1329079356785688616"
guild_id = "1144692727120937080"

# --- Ethereum ---
ethereum_host = "${{ secrets.ETHEREUM_HOST }}"
staking_asset_handler_address = "0xF739D03e98e23A7B65940848aBA8921fF3bAc4b2"
l1_chain_id = "11155111"

# --- DynamoDB ---
local_dynamo_db = false
dynamodb_local_endpoint = "http://localhost:8000"

# --- Logging ---
log_level = "debug"
log_pretty_print = false

# --- API Configuration ---
api_port = 3000
backend_api_key = "${{ secrets.BACKEND_API_KEY }}"
EOF

- name: Terraform Apply
run: terraform apply -var-file="terraform.production.tfvars" -auto-approve -input=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ proofs
debug_*.json
crs
yarn-error.log
.env*
35 changes: 33 additions & 2 deletions tooling/sparta/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
.env
.env*
# Git files
.git
.gitignore

# Node.js dependencies
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build outputs (adjust if your build output is different)
dist
build
.next

# Terraform state and plugins
terraform/.terraform
*.tfstate
*.tfstate.backup

# Environment files
.env*
!.env.example

# IDE/Editor folders
.vscode
.idea

# OS generated files
.DS_Store
Thumbs.db

# Other potential artifacts (add more as needed)
*.log
53 changes: 53 additions & 0 deletions tooling/sparta/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -------------------------------------
# Express Server Configuration
# -------------------------------------
# Port for the API server
API_PORT=3000

# -------------------------------------
# Discord Bot Configuration
# -------------------------------------
# Discord Bot Token (from Discord Developer Portal)
BOT_TOKEN=your_discord_bot_token_here
# Discord Application/Client ID (from Discord Developer Portal)
BOT_CLIENT_ID=your_discord_client_id_here
# ID of the Discord Server (Guild) where the bot operates
GUILD_ID=your_discord_guild_id_here

# -------------------------------------
# Verification Web App (Vite Frontend)
# -------------------------------------
# Base URL of the verification web app (e.g., http://localhost:5173 or your deployed URL)
# Used to generate the verification link sent to the user.
API_URL=http://localhost:3000 # for vite frontend

# -------------------------------------
# DynamoDB Configuration
# -------------------------------------
# Set to "true" to use a local DynamoDB instance (e.g., Docker container)
LOCAL_DYNAMO_DB=true
# Endpoint URL for local DynamoDB (only used if LOCAL_DYNAMO_DB is true)
DYNAMODB_LOCAL_ENDPOINT=http://localhost:8000

# --- AWS Credentials (Required if LOCAL_DYNAMO_DB=false and not using IAM roles/profiles) ---
AWS_REGION=us-east-1
# AWS_ACCESS_KEY_ID=your_aws_access_key_here
# AWS_SECRET_ACCESS_KEY=your_aws_secret_key_here

# -------------------------------------
# Logging Configuration
# -------------------------------------
# Log level: 'debug', 'info', 'warn', 'error'
LOG_LEVEL=info
# Set to "false" to disable pretty printing of logs (JSON output)
LOG_PRETTY_PRINT=true

# -------------------------------------
# Ethereum Configuration (Used by Moderator/NodeOperator commands)
# -------------------------------------
# RPC URL for the Ethereum network (e.g., Sepolia)
ETHEREUM_HOST=your_ethereum_rpc_url_here
# Chain ID for the Ethereum network (e.g., 11155111 for Sepolia)
L1_CHAIN_ID=11155111
# Staking asset handler contract address
STAKING_ASSET_HANDLER_ADDRESS=your_staking_asset_handler_address_here
61 changes: 61 additions & 0 deletions tooling/sparta/.github/workflows/terraform-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Terraform Deploy

on:
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
terraform:
name: Terraform
runs-on: ubuntu-latest

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_bot_token: ${{ secrets.BOT_TOKEN }}
TF_VAR_ethereum_host: ${{ secrets.ETHEREUM_HOST }}
TF_VAR_backend_api_key: ${{ secrets.BACKEND_API_KEY }}
TF_VAR_aws_region: "eu-west-2"
TF_VAR_environment: "production"
TF_VAR_bot_client_id: "1329079356785688616"
TF_VAR_guild_id: "1144692727120937080"
TF_VAR_staking_asset_handler_address: "0xF739D03e98e23A7B65940848aBA8921fF3bAc4b2"
TF_VAR_l1_chain_id: "11155111"
TF_VAR_local_dynamo_db: "false"
TF_VAR_dynamodb_local_endpoint: "http://localhost:8000"
TF_VAR_log_level: "info"
TF_VAR_log_pretty_print: "false"
TF_VAR_api_port: "3000"

defaults:
run:
working-directory: tooling/sparta/terraform

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.7

- name: Terraform Init
id: init
run: terraform init

- name: Terraform Format
id: fmt
run: terraform fmt -check
continue-on-error: true

- name: Terraform Validate
id: validate
run: terraform validate

- name: Terraform Apply
run: |
terraform apply -auto-approve
2 changes: 2 additions & 0 deletions tooling/sparta/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ Thumbs.db
bun.lockb
yarn.lock
package-lock.json
.cursor/
out.txt
55 changes: 38 additions & 17 deletions tooling/sparta/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sparta Discord Bot Dockerfile
# This Dockerfile builds the Sparta Discord bot for deployment
# Sparta API & Frontend Dockerfile
# This Dockerfile builds the Sparta API (Express) and Frontend (Vite) for deployment

# Start with the official Bun image
FROM oven/bun:latest
Expand All @@ -10,30 +10,51 @@ ENV PATH="/root/.foundry/bin:${PATH}"
# Install required dependencies
# - curl: For downloading tools
# - apt-utils: For better apt functionality
RUN apt update && apt install -y curl apt-utils
RUN apt update && apt install -y curl apt-utils git

# Install Docker within the container for potential nested container operations
RUN curl -fsSL https://get.docker.com | bash
# Install Docker within the container (If needed for runtime operations, otherwise remove)
# RUN curl -fsSL https://get.docker.com | bash

# Install Foundry toolkit for Ethereum development (cast, anvil, forge)
# Install Foundry toolkit for Ethereum development (If needed for runtime operations, otherwise remove)
RUN curl -L https://foundry.paradigm.xyz | bash
RUN foundryup

# Verify Foundry installation by checking cast version
RUN cast --version
# RUN cast --version # Optional: remove if not needed for runtime verification

# Set the working directory
WORKDIR /app

# Copy package files first to leverage Docker layer caching
# This way, dependencies are only re-installed when package files change
COPY src/package.json src/bun.lockb ./
RUN bun install
# Copy the root package.json and lockfile
COPY package.json bun.lock ./

# Then copy the rest of the source code
# This step is separate to avoid reinstalling dependencies when only code changes
COPY src ./
# Copy package.json files from workspaces to ensure dependencies are captured
# Create the packages directory first
RUN mkdir packages
COPY packages/express/package.json ./packages/express/
COPY packages/utils/package.json ./packages/utils/
COPY packages/discord/package.json ./packages/discord/
COPY packages/ethereum/package.json ./packages/ethereum/
COPY packages/scheduler/package.json ./packages/scheduler/
# Add other packages if they exist and are needed

# Start the bot
# Uses the production start command from package.json
CMD ["bun", "run", "start"]
# Install all dependencies for the monorepo using the lockfile
RUN bun install --frozen-lockfile

# Copy the entire monorepo source code
# This includes Express, Vite, Utils, etc.
COPY . .

# Declare the build argument for the Vite frontend URL
ARG API_URL

ENV API_URL=$API_URL

# Expose the port the Express server will listen on
# Make sure this matches the PORT environment variable passed in Terraform (var.api_port)
EXPOSE 3000

# Start ONLY the Express API server using its own start script
# Assumes a "start" script exists in packages/express/package.json (or the relevant API package)
# This avoids running the root build/swagger scripts at runtime.
CMD ["bun", "--filter=@sparta/api", "--filter=@sparta/discord", "run", "start"]
Loading