From 13ffb874f8a1206d9d20faaaa80af61849466632 Mon Sep 17 00:00:00 2001 From: Daniel Traynor <7traynor@gmail.com> Date: Wed, 8 Apr 2026 10:29:17 -0400 Subject: [PATCH 1/2] Add logout button to dashboard layout, include credentials in fetch requests, and update environment variable handling in Docker Compose --- .env.example | 10 +++ .github/workflows/ci.yml | 27 ++++++- .gitleaks.toml | 16 ++++ CONTRIBUTING.md | 2 + README.md | 10 +-- dashboard/next.config.js | 4 +- dashboard/src/app/(dashboard)/layout.tsx | 14 +++- dashboard/src/app/api/auth/login/route.ts | 48 +++++++++++ dashboard/src/app/api/auth/logout/route.ts | 16 ++++ dashboard/src/app/layout.tsx | 3 +- dashboard/src/app/login/page.tsx | 70 ++++++++++++++++ dashboard/src/components/LogoutButton.tsx | 40 ++++++++++ .../src/components/system/ControlsPanel.tsx | 5 +- .../lib/__tests__/dashboard-session.test.ts | 22 ++++++ dashboard/src/lib/branding.ts | 7 ++ dashboard/src/lib/dashboard-fetch.ts | 8 ++ dashboard/src/lib/dashboard-session.ts | 79 +++++++++++++++++++ dashboard/src/middleware.ts | 52 ++++++++++++ docker-compose.yml | 34 ++++---- docs/DEPLOY_RUNBOOK.md | 3 + execution/src/index.ts | 8 +- first-run-setup.sh | 13 +-- .../monitoring/docker-compose.monitoring.yml | 2 +- 23 files changed, 455 insertions(+), 38 deletions(-) create mode 100644 .gitleaks.toml create mode 100644 dashboard/src/app/api/auth/login/route.ts create mode 100644 dashboard/src/app/api/auth/logout/route.ts create mode 100644 dashboard/src/app/login/page.tsx create mode 100644 dashboard/src/components/LogoutButton.tsx create mode 100644 dashboard/src/lib/__tests__/dashboard-session.test.ts create mode 100644 dashboard/src/lib/branding.ts create mode 100644 dashboard/src/lib/dashboard-fetch.ts create mode 100644 dashboard/src/lib/dashboard-session.ts create mode 100644 dashboard/src/middleware.ts diff --git a/.env.example b/.env.example index ae7564d..6038424 100644 --- a/.env.example +++ b/.env.example @@ -67,6 +67,16 @@ IMAGE_TAG=latest # ================================ GRAFANA_ADMIN_PASSWORD= +# ================================ +# Dashboard (Next.js UI) +# ================================ +# Optional label in the sidebar / login (default: Trading Terminal) +# NEXT_PUBLIC_APP_NAME= +# Required for production: min 16 characters. Signs the session cookie only (not sent to Polymarket). +DASHBOARD_API_SECRET= +# Local dev only: set to "true" to skip dashboard login (never use in production) +# DASHBOARD_INSECURE_DEV_BYPASS=true + # ================================ # Trading Parameters # ================================ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed10d02..f441430 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,16 @@ on: branches: [main] jobs: + gitleaks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: gitleaks/gitleaks-action@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build-rust: runs-on: ubuntu-latest strategy: @@ -48,9 +58,24 @@ jobs: run: npm run build working-directory: ${{ matrix.service }} + build-dashboard: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + cache-dependency-path: dashboard/package-lock.json + - name: Install and build + env: + DASHBOARD_API_SECRET: ci_placeholder_secret_min_len_16 + run: npm ci && npm run build + working-directory: dashboard + build-docker: runs-on: ubuntu-latest - needs: [build-rust, build-typescript] + needs: [build-rust, build-typescript, build-dashboard] steps: - uses: actions/checkout@v4 - name: Build all images diff --git a/.gitleaks.toml b/.gitleaks.toml new file mode 100644 index 0000000..984cebc --- /dev/null +++ b/.gitleaks.toml @@ -0,0 +1,16 @@ +# Gitleaks: extend defaults; allowlist known false positives from generic-api-key. +# Re-run after edits: gitleaks git . -c .gitleaks.toml -v + +title = "algorithmic-trading-polymarket" + +[extend] +useDefault = true + +[allowlist] +description = "Hardhat/Anvil test key #0; Redis kill-switch key names (not API secrets)" +regexes = [ + '''0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80''', + '''^BTC_5M_TRADING_ENABLED$''', + '''^BTC_5M_LATENCY_TRADING_ENABLED$''', + '''^BTC_5M_MOMENTUM_TRADING_ENABLED$''', +] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1d7492..7b34031 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,8 @@ Thanks for your interest in contributing to the Polymarket trading platform. +The codebase is meant as a **neutral, structured deployment**: every environment brings its own wallets, RPC URLs, and API keys via `.env` — nothing in the tree should assume a specific operator. + ## Getting Started 1. Fork the repo and clone it locally diff --git a/README.md b/README.md index bb9480d..20bd3ed 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Polymarket Trading Platform -A 12-service automated trading system for [Polymarket](https://polymarket.com) prediction markets, running multiple strategies simultaneously — from sub-second arbitrage scanning to Bayesian sports modeling. Built with Rust and TypeScript, orchestrated via Docker Compose, with a real-time Bloomberg terminal-style dashboard. +**Deployment template** — this repo ships **no** accounts, wallets, or API secrets. Fork or clone it, copy [`.env.example`](.env.example) to `.env`, and fill in **your** Polygon RPC, Gnosis Safe, Polymarket CLOB credentials, dashboard password, and optional GCP settings. Behavior is strategy-agnostic: the same layout runs paper or live depending on your env flags. -This started as a box spread arbitrage bot and grew into a multi-strategy platform handling live capital on Polygon L2. +A 12-service automated trading system for [Polymarket](https://polymarket.com) prediction markets, running multiple strategies simultaneously — from sub-second arbitrage scanning to Bayesian sports modeling. Built with Rust and TypeScript, orchestrated via Docker Compose, with a real-time terminal-style dashboard. ## Architecture @@ -122,12 +122,12 @@ Key features: ### Setup ```bash -git clone https://github.com/dantraynor/algorithmic-trading-polymarket.git -cd algorithmic-trading-polymarket +git clone https://github.com//.git +cd # Configure credentials cp .env.example .env -# Edit .env: PRIVATE_KEY, GNOSIS_SAFE_ADDRESS, POLYGON_RPC_URL +# Edit .env: PRIVATE_KEY, GNOSIS_SAFE_ADDRESS, POLYGON_RPC_URL, DASHBOARD_API_SECRET (min 16 chars) # Derive CLOB API keys (must run from the server that will trade) cd scripts && npm install && PRIVATE_KEY=0x... node derive-keys.js diff --git a/dashboard/next.config.js b/dashboard/next.config.js index 4c72b7d..122a141 100644 --- a/dashboard/next.config.js +++ b/dashboard/next.config.js @@ -1,7 +1,9 @@ /** @type {import('next').NextConfig} */ const nextConfig = { output: 'standalone', - serverExternalPackages: ['better-sqlite3'], + experimental: { + serverComponentsExternalPackages: ['better-sqlite3'], + }, }; module.exports = nextConfig; diff --git a/dashboard/src/app/(dashboard)/layout.tsx b/dashboard/src/app/(dashboard)/layout.tsx index 2ce9f18..b399293 100644 --- a/dashboard/src/app/(dashboard)/layout.tsx +++ b/dashboard/src/app/(dashboard)/layout.tsx @@ -1,3 +1,5 @@ +import { LogoutButton } from '@/components/LogoutButton'; +import { getAppDisplayName } from '@/lib/branding'; import Link from 'next/link'; const NAV_ITEMS = [ @@ -28,14 +30,18 @@ function SidebarHealthPlaceholder() { } export default function DashboardLayout({ children }: { children: React.ReactNode }) { + const appName = getAppDisplayName(); return (
{/* Left sidebar */}