Skip to content

AIHackatonA5/aegis-pay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

43 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Aegis Pay - The Autonomous Social Treasurer

Seoul Bowl Hackathon 2025 | Track: Autonomous Finance & FinTech

An autonomous financial agent for group expense management built with AI + Web3. Aegis Pay acts as a decentralized treasurer that automates fund collection, expense verification, and settlement using SpoonOS and Neo N3 blockchain.

🌐 Live Demo

🎯 Problem Solved

Traditional bill-splitting apps only calculate debt - they don't collect money or execute payments. Aegis Pay automates the entire flow:

  1. Platform-Independent Links: Share a vault link through any messenger (KakaoTalk, Discord, Slack, WhatsApp)
  2. Auto-Deduction: When participants accept, funds are automatically deposited to escrow smart contract
  3. AI-Powered Verification: Upload receipt β†’ GPT-4o Vision extracts total amount
  4. HITL Approval: 60-second countdown for participants to reject expenses (auto-approve on timeout)
  5. Autonomous Settlement: Agent calculates optimal payouts and executes blockchain transfers

πŸ—οΈ Architecture

3-Layer System

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Layer 1: Directives (What to do)                       β”‚
β”‚  - Natural language SOPs in directives/                 β”‚
β”‚  - Define goals, inputs, outputs for each workflow      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Layer 2: Orchestration (Decision making)               β”‚
β”‚  - SpoonOS SCDF graph-based workflows                   β”‚
β”‚  - ReAct agent pattern                                  β”‚
β”‚  - HITL interrupts for approval flows                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Layer 3: Execution (Deterministic)                     β”‚
β”‚  - Python scripts (execution/)                          β”‚
β”‚  - Neo N3 smart contracts (contracts/)                  β”‚
β”‚  - Express.js backend (backend/)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

  • Agentic Runtime: SpoonOS (SCDF framework)
  • AI: GPT-4o Vision (OCR only)
  • Blockchain: Neo N3 TestNet (smart contracts)
  • Backend: Express.js + Prisma + SQLite
  • Frontend: Next.js 14 + Tailwind CSS + shadcn/ui
  • State: MCP+ (Model Context Protocol)
  • Deployment:
    • Frontend: Vercel
    • Backend & Agent: GCP Cloud Run
    • Database: SQLite (ephemeral)
  • Infrastructure: Docker, Cloud Build

πŸš€ Quick Start

Try Live Demo First!

Before setting up locally, try the live demo:

  1. Visit: https://frontend-three-ashen-38.vercel.app
  2. Connect NeoLine Wallet (Neo N3 TestNet)
  3. Create a Vault or join an existing one
  4. Upload Receipt to test OCR
  5. Share Link via any messenger

Prerequisites for Local Development

  • Docker & Docker Compose
  • Node.js 18+
  • Python 3.10+
  • Neo N3 wallet with TestNet GAS

1. Clone & Setup

git clone <repo-url>
cd aegis-pay

# Run automated setup
chmod +x scripts/setup.sh
./scripts/setup.sh

This will:

  • Start MySQL via Docker
  • Install backend dependencies
  • Run Prisma migrations

2. Start Backend

cd backend
npm run dev

Backend API runs on http://localhost:4000

3. Deploy Smart Contract

cd contracts

# Compile contract
neo3-boa compile vault.py

# Deploy to Neo N3 TestNet (see contracts/README.md)
# Update backend/.env with contract hash

4. Set Up Agent (Optional)

cd agent  # If agent folder exists
python -m venv .venv
source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate  # Windows
pip install -r requirements.txt

python main.py  # Start agent server

5. Start Frontend

cd frontend  # If frontend folder exists
npm install
npm run dev

Frontend runs on http://localhost:3000

πŸ“ Project Structure

aegis-pay/
β”œβ”€β”€ backend/              # Express.js API + Prisma
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ server.js    # Entry point
β”‚   β”‚   β”œβ”€β”€ routes/      # API routes
β”‚   β”‚   β”œβ”€β”€ services/    # Business logic
β”‚   β”‚   └── lib/         # Utilities
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   └── schema.prisma
β”‚   └── package.json
β”‚
β”œβ”€β”€ contracts/            # Neo N3 smart contracts
β”‚   β”œβ”€β”€ vault.py         # Main escrow contract
β”‚   └── README.md
β”‚
β”œβ”€β”€ directives/           # Agent SOPs (Layer 1)
β”‚   β”œβ”€β”€ vault_creation.md
β”‚   β”œβ”€β”€ ocr_receipt.md
β”‚   β”œβ”€β”€ hitl_approval.md
β”‚   └── settlement.md
β”‚
β”œβ”€β”€ execution/            # Deterministic scripts (Layer 3)
β”‚   β”œβ”€β”€ ocr_extract.py
β”‚   β”œβ”€β”€ calculate_split.py
β”‚   β”œβ”€β”€ neo_deploy.py
β”‚   └── neo_transfer.py
β”‚
β”œβ”€β”€ src/                  # Frontend components
β”‚   β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ lib/
β”‚   └── styles/
β”‚
β”œβ”€β”€ docs/                 # Documentation
β”‚   β”œβ”€β”€ PRD.md
β”‚   β”œβ”€β”€ ARCHITECTURE.md
β”‚   β”œβ”€β”€ SMART_CONTRACT.md
β”‚   └── SPOONOS_WORKFLOW.md
β”‚
β”œβ”€β”€ scripts/
β”‚   └── setup.sh         # Quick setup script
β”‚
β”œβ”€β”€ docker-compose.yml   # MySQL container
β”œβ”€β”€ CLAUDE.md            # Agent instructions
└── README.md            # This file

πŸ”§ Development Workflow

Backend Development

cd backend

# Development with hot reload
npm run dev

# Database management
npm run prisma:studio    # Visual DB editor
npm run prisma:migrate   # Create new migration

# Testing
curl http://localhost:4000/health

Smart Contract Development

cd contracts

# Compile
neo3-boa compile vault.py

# Deploy to TestNet
# See contracts/README.md for deployment options

# Test
python test_vault.py

Frontend Development

cd frontend

# Development server
npm run dev

# Build for production
npm run build

# Type checking
npm run type-check

🌐 API Endpoints

Health Check

GET /health

Vaults

POST   /api/vaults              # Create vault
GET    /api/vaults/:id          # Get vault details
POST   /api/vaults/:id/join     # Join vault
POST   /api/vaults/:id/expenses # Upload expense receipt
POST   /api/vaults/:id/close    # Close vault and settle

πŸ§ͺ Testing

Backend

cd backend
curl -X POST http://localhost:4000/api/vaults \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Vault",
    "target_participants": 3,
    "amount_per_person": 10,
    "created_by": "NQtest123..."
  }'

Smart Contract

cd contracts
python test_vault.py

# Or use neo-express
neoxp contract invoke <hash> create_vault [params...]

πŸ“Š Database Schema

See backend/prisma/schema.prisma for full schema. Key models:

  • Vault: Main vault entity
  • Participant: Users who joined vault
  • Expense: Receipt uploads with OCR data
  • Transaction: Blockchain transaction records

πŸ” Environment Variables

Backend (backend/.env)

# Local Development
DATABASE_URL="mysql://root:password@localhost:3306/aegis_pay"
NEO_NETWORK="TestNet"
NEO_RPC_URL="https://testnet1.neo.coz.io:443"
NEO_CONTRACT_HASH="0x8f616d5ead7dbd85ccea2f61c2fff36bea53ba6b"
NEO_WALLET_WIF="YOUR_WIF_KEY"
NEO_WALLET_PASSWORD="YOUR_PASSWORD"
AGENT_URL="http://localhost:8000"
FRONTEND_URL="http://localhost:3000"

Agent (agent/.env)

OPENAI_API_KEY="sk-proj-..."
OPENAI_MODEL="gpt-4o-2024-08-06"
SPOONOS_API_KEY="sk-or-v1-..."
BACKEND_URL="http://localhost:4000"
NEO_RPC_URL="https://testnet1.neo.coz.io:443"
NEO_WALLET_WIF="YOUR_WIF_KEY"
NEO_WALLET_PASSWORD="YOUR_PASSWORD"
NEO_CONTRACT_HASH="0x8f616d5ead7dbd85ccea2f61c2fff36bea53ba6b"
NEO_NETWORK="TestNet"
AGENT_HOST="0.0.0.0"
AGENT_PORT="8000"
HITL_APPROVAL_TIMEOUT="60"
POLLING_INTERVAL="5"

Frontend (frontend/.env.local)

NEXT_PUBLIC_API_URL="http://localhost:4000"
NEXT_PUBLIC_AGENT_URL="http://localhost:8000"
NEXT_PUBLIC_AGENT_WS_URL="ws://localhost:8000/ws"
NEXT_PUBLIC_NEO_NETWORK="TestNet"
NEXT_PUBLIC_NEO_RPC_URL="https://testnet1.neo.coz.io:443"
NEXT_PUBLIC_VAULT_CONTRACT_HASH="0x8f616d5ead7dbd85ccea2f61c2fff36bea53ba6b"

Production (Cloud Run & Vercel)

All services are deployed with production environment variables configured in:

  • Backend: Cloud Run environment variables
  • Agent: Cloud Run environment variables
  • Frontend: Vercel environment variables

🎯 MVP Scope (48-hour Hackathon)

Must Have βœ…

  • Backend API with SQLite (deployed on Cloud Run)
  • Neo N3 smart contract (deployed on TestNet)
  • Frontend vault creation UI (deployed on Vercel)
  • Shareable link generation
  • Receipt OCR with GPT-4o Vision
  • Auto-deduction on vault join
  • SpoonOS agent integration (deployed on Cloud Run)
  • HITL approval flow
  • Automated settlement

Nice to Have

  • SpoonOS agent integration
  • WebSocket real-time updates
  • Email notifications
  • Receipt search with BeVec

Out of Scope

  • Mobile app
  • Multi-vault management
  • Mainnet deployment
  • Advanced analytics

πŸš€ Deployment

All services are deployed and running:

Frontend (Vercel)

Backend (GCP Cloud Run)

Agent (GCP Cloud Run)

Smart Contract (Neo N3 TestNet)

πŸ“š Documentation

🚨 Troubleshooting

MySQL Connection Issues

# Check if container is running
docker ps

# View logs
docker logs aegis-pay-mysql

# Restart
docker-compose restart mysql

Prisma Issues

# Regenerate client
cd backend
npm run prisma:generate

# Reset database (⚠️ deletes all data)
npx prisma migrate reset

Contract Deployment

# Check TestNet GAS balance
# Get more from: https://neowish.ngd.network/

# Verify RPC endpoint
curl https://testnet1.neo.org:20331

🎨 Design Principles

  1. MVP First: Ship working demo, polish later
  2. 3-Layer Separation: Directives β†’ Orchestration β†’ Execution
  3. Self-Annealing: When errors occur, fix + document + strengthen system
  4. Platform Independence: Work across any messenger via links
  5. HITL by Default: Human approval required, auto-timeout as fallback

🀝 Contributing

This is a hackathon project. Contributions welcome after Seoul Bowl 2025!

πŸ“„ License

MIT

πŸ‘₯ Team

Aegis Pay Team - Seoul Bowl Hackathon 2025


Built with: SpoonOS | Neo N3 | GPT-4o | Next.js | Express.js

Hackathon Deadline: December 21, 2025, 23:59 KST

About

Aegis Pay - Autonomous Financial Agent for Group Expense Management

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •