Skip to content

ross2121/MPC_INDEXER

Repository files navigation

MCP Indexer

A comprehensive Solana blockchain indexing and MPC (Multi-Party Computation) service built with Rust. This project provides account indexing, user management, and threshold signature scheme (TSS) capabilities for Solana transactions.

Project Structure

This is a Rust workspace containing multiple crates:

  • backend: REST API server for user management and Solana operations
  • indexer: Yellowstone gRPC client for indexing Solana account data
  • mpc1: Multi-party computation service for threshold signature schemes
  • store: Shared library with database types and utilities

Features

Backend API

  • User authentication (sign up, sign in)
  • JWT-based authentication middleware
  • Solana wallet operations:
    • SOL balance checking
    • Token balance checking
    • SOL transfers
    • Token swaps
    • Transaction quotes

Indexer Service

  • Real-time Solana account indexing via Yellowstone gRPC
  • Balance tracking for SOL and SPL tokens
  • Account state monitoring
  • PostgreSQL database integration

MPC Service

  • Threshold signature scheme (TSS) implementation
  • Multi-party key generation
  • Aggregated transaction signing
  • Support for SOL transfers and token swaps
  • Secure key management

Prerequisites

  • Rust (latest stable version)
  • PostgreSQL 16+
  • Docker and Docker Compose (for local database setup)
  • Solana CLI tools (optional, for development)

Getting Started

1. Clone the Repository

git clone <repository-url>
cd MCP_INDEXER

2. Set Up Database

Start the PostgreSQL database using Docker Compose:

docker compose up -d

This will:

  • Start a PostgreSQL 16 container on port 5435
  • Create the database mpc5
  • Run initialization scripts from init/

3. Environment Variables

Create a .env file in the project root with the following variables:

# Database
DATABASE_URL=postgresql://mympcuser:mympc@localhost:5435/mpc5

# gRPC Endpoint (for indexer)
GRPC_ENDPOINT=https://solana-rpc.parafi.tech:10443
X_TOKEN=your_token_here  # Optional, for authenticated endpoints

# Backend Configuration
PORT=8085

4. Build the Project

cargo build --release

5. Run Services

Backend API Server

cd backend
cargo run

The backend will start on http://127.0.0.1:8085

Indexer Service

cd indexer
cargo run

MPC Service

cd mpc1
cargo run

The MPC service will start on http://127.0.0.1:8080

API Endpoints

Backend API (Port 8085)

Authentication

  • POST /sign_up - Register a new user
  • POST /sign_in - Sign in and get JWT token
  • GET /get_user - Get user information

Solana Operations

  • GET /sol_balance - Get SOL balance for a wallet
  • GET /token_balance - Get token balance for a wallet
  • POST /quote - Get swap quote
  • POST /swap - Execute token swap
  • POST /transfer - Transfer SOL or tokens

MPC Service (Port 8080)

Key Management

  • POST /generate - Generate a new keypair for a user
  • GET /getuser - Get user keypair information
  • POST /aggregate-keys - Aggregate multiple public keys

TSS Operations

  • POST /agg-send-step1 - First step of TSS signing
  • POST /agg-send-step2 - Second step of TSS signing
  • POST /agg-send-step2-swap - Second step for swap transactions
  • POST /aggregate-signatures-broadcast - Aggregate signatures and broadcast transaction
  • POST /aggregate-signatures-broadcast-swap - Aggregate signatures and broadcast swap transaction

Database Schema

The project uses PostgreSQL with the following main tables:

  • users: User accounts with authentication and wallet information
  • Account and balance tracking tables (managed by the indexer)

See init/init.sql for the initial schema.

Development

Running Tests

cargo test

Code Formatting

cargo fmt

Linting

cargo clippy

Architecture

graph TB
    Frontend[Frontend]
    Backend[Backend<br/>POST /signup<br/>POST /signin<br/>GET /user<br/>POST /quote<br/>POST /swap<br/>POST /send<br/>GET /balance/sol<br/>GET /balance/tokens]
    Postgres[(Postgres)]
    Indexer[Indexer]
    MPC1[MPC 1]
    MPC2[MPC 2]
    MPC3[MPC 3]
    DB1[(DB)]
    DB2[(DB)]
    DB3[(DB)]
    SolanaRPC[Solana RPC]
    
    Frontend -->|HTTP Requests| Backend
    Backend -->|Database Operations| Postgres
    Backend -->|TSS Operations| MPC1
    Backend -->|TSS Operations| MPC2
    Backend -->|TSS Operations| MPC3
    Backend -->|Blockchain Operations| SolanaRPC
    Indexer -->|Write Indexed Data| Postgres
    MPC1 -->|Key Storage| DB1
    MPC2 -->|Key Storage| DB2
    MPC3 -->|Key Storage| DB3
    
    style Frontend fill:#1e1e1e,stroke:#fff,stroke-width:2px,color:#fff
    style Backend fill:#8b0000,stroke:#fff,stroke-width:2px,color:#fff
    style Postgres fill:#336791,stroke:#fff,stroke-width:2px,color:#fff
    style Indexer fill:#0066cc,stroke:#fff,stroke-width:2px,color:#fff
    style MPC1 fill:#008000,stroke:#fff,stroke-width:2px,color:#fff
    style MPC2 fill:#008000,stroke:#fff,stroke-width:2px,color:#fff
    style MPC3 fill:#008000,stroke:#fff,stroke-width:2px,color:#fff
    style SolanaRPC fill:#ff8c00,stroke:#fff,stroke-width:2px,color:#fff
    style DB1 fill:#336791,stroke:#fff,stroke-width:2px,color:#fff
    style DB2 fill:#336791,stroke:#fff,stroke-width:2px,color:#fff
    style DB3 fill:#336791,stroke:#fff,stroke-width:2px,color:#fff
Loading

Component Overview

  • Frontend: User interface that communicates with the Backend API
  • Backend: REST API server handling authentication, user management, and Solana operations
  • Postgres: Central database storing user data and indexed account information
  • Indexer: Yellowstone gRPC service that monitors Solana blockchain and indexes account data
  • MPC Services (MPC 1, 2, 3): Multi-party computation services for threshold signature schemes, each with its own database for key management
  • Solana RPC: Solana blockchain RPC endpoint for on-chain operations (queries, transactions)

Security Considerations

  • JWT tokens for API authentication
  • Password hashing with Argon2
  • Secure key management in MPC service
  • Database connection pooling
  • Environment variable configuration for sensitive data

Dependencies

Key dependencies:

  • actix-web: Web framework for backend API
  • sqlx: Async PostgreSQL driver
  • yellowstone-grpc: Solana gRPC client
  • solana-sdk: Solana blockchain SDK
  • multi-party-eddsa: Threshold signature implementation
  • tokio: Async runtime

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages