Skip to content

aaryan-k-lab/SolPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SolPool Documentation

Integration Complete ✅

The Solana layer is now fully integrated with the backend authentication and database.

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                       FRONTEND (React + Vite)                       │
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────────────┐   │
│  │ AuthContext   │  │SolanaProvider │  │ usePoolTransactions   │   │
│  │ - login       │  │ - wallet      │  │ - joinPool()          │   │
│  │ - linkWallet  │  │ - connection  │  │ - createPool()        │   │
│  └───────┬───────┘  └───────┬───────┘  └───────────┬───────────┘   │
│          │                  │                      │               │
│          └──────────────────┴──────────────────────┘               │
│                             │                                       │
└─────────────────────────────┼───────────────────────────────────────┘
                              │
           ┌──────────────────┴──────────────────┐
           ▼                                     ▼
┌─────────────────────┐             ┌─────────────────────┐
│   SPRING BOOT API   │             │   SOLANA BLOCKCHAIN │
│                     │             │                     │
│ • Auth (JWT)        │             │ • Pool accounts     │
│ • User management   │             │ • Commitment accts  │
│ • Wallet linking    │             │ • Vault (escrow)    │
│ • Pool metadata     │             │ • Program logic     │
│ • Commitment track  │             │                     │
│                     │             │                     │
│   MongoDB ────────────────────────────► On-chain data   │
└─────────────────────┘             └─────────────────────┘

Quick Start

1. Start MongoDB

# Using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest

2. Start Backend

cd backend
./mvnw spring-boot:run

3. Start Local Solana Validator

solana-test-validator --reset

4. Deploy Solana Program

cd pooling-escrow
export ANCHOR_WALLET="$HOME/.config/solana/id.json"
anchor deploy --provider.cluster localnet
npx ts-node scripts/seed-pools.ts

5. Start Frontend

cd frontend
npm install
npm run dev

API Endpoints

Authentication

Method Endpoint Auth Description
POST /api/auth/register No Register new SMB owner
POST /api/auth/login No Login
GET /api/auth/me Yes Get current user

Wallet

Method Endpoint Auth Description
POST /api/wallet/link Yes Link Solana wallet
DELETE /api/wallet/unlink Yes Unlink wallet
GET /api/wallet/status Yes Get wallet status

Pools

Method Endpoint Auth Description
GET /api/pools No List all pools
POST /api/pools Yes Register new pool
GET /api/pools/address/{addr} No Get pool by Solana address
GET /api/pools/my-pools Yes Get user's created pools
POST /api/pools/commit Yes Record commitment
GET /api/pools/my-commitments Yes Get user's commitments

Flow: SMB Joins a Pool

1. User logs in → JWT token stored
                ↓
2. User connects Solana wallet (Phantom/Solflare)
                ↓
3. User links wallet (signs message to prove ownership)
   └─► Backend stores wallet public key
                ↓
4. User clicks "Join Pool" on a pool card
                ↓
5. Frontend checks:
   ├─ Authenticated? ✓
   ├─ Wallet connected? ✓
   └─ Wallet matches linked wallet? ✓
                ↓
6. User enters quantity in modal
                ↓
7. Frontend executes Solana transactions:
   ├─ commit(quantity) → Creates Commitment PDA
   └─ deposit(lamports) → Transfers SOL to Vault PDA
                ↓
8. Frontend records in backend:
   └─ POST /api/pools/commit
                ↓
9. Success! User sees confirmation with tx signature

Key Files

Backend (Spring Boot)

backend/src/main/java/com/blockchainBusters/SolPool/
├── auth/
│   ├── controller/AuthController.java     # Login, register, /me
│   ├── model/User.java                    # User with wallet linking
│   └── security/
│       ├── JwtFilter.java                 # JWT authentication
│       └── JwtService.java                # Token generation/validation
├── wallet/
│   ├── controller/WalletController.java   # Link/unlink wallet
│   └── service/WalletAuthService.java     # Signature verification
├── pool/
│   ├── controller/PoolController.java     # Pool CRUD + commitments
│   ├── model/Pool.java                    # Pool with cached on-chain data
│   └── service/PoolService.java           # Business logic
└── config/SecurityConfig.java             # CORS, JWT filter setup

Frontend (React)

frontend/src/
├── contexts/
│   ├── AuthContext.tsx         # Auth + wallet linking state
│   └── SolanaProvider.tsx      # Wallet adapter setup
├── hooks/
│   ├── usePools.ts             # Fetch pools from Solana
│   └── usePoolTransactions.ts  # Execute Solana transactions
├── components/
│   ├── JoinPoolModal.tsx       # Modal for joining pools
│   └── sections/ActivePoolsSection.tsx  # Pool display
└── lib/api.ts                  # Backend API client

Solana Program (Anchor)

pooling-escrow/
├── programs/pooling_escrow/src/lib.rs  # On-chain program
├── idl/pooling_escrow.json             # Program interface
└── client/poolingClient.ts             # TypeScript helpers

Security Notes

  1. Wallet Linking: Users must sign a message to prove wallet ownership before linking
  2. JWT Authentication: All sensitive endpoints require valid JWT
  3. Wallet Matching: Transactions only allowed if connected wallet matches linked wallet
  4. Signature Verification: TODO - Implement proper Ed25519 verification for production

Testing

Unit Tests

cd backend && ./mvnw test
cd frontend && npm test
cd pooling-escrow && anchor test

Manual Testing

  1. Register at /signup
  2. Login at /login
  3. Connect Phantom wallet
  4. Link wallet (signs message)
  5. Browse pools on homepage
  6. Click "Join Pool" → enter quantity → confirm transaction

About

Unlocking corporate-level buying power for SMBs atop of blockchain technology

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors