Skip to content

Repository files navigation

PrivatePerps: Private Perpetual DEX on Solana

A privacy perpetual futures DEX with encrypted position management and private cross-chain deposits on Solana powered by Arcium and ZEC.


  • Encrypted Position Management: All position data (size, collateral, leverage, PnL) is encrypted using Arcium's Multi-Party Computation (MPC)
  • Private Deposits: Zcash shielded transactions break the link between deposit and trading activity
  • High Performance: Sub-second finality and <$0.001 transaction fees on Solana
  • Full Trading Features: Up to 20x leverage, real-time PnL, liquidation protection

Why PrivatePerps?

Traditional DeFi exchanges expose all trading activity on-chain, making it easy for:

  • Front-runners to see large orders
  • Competitors to copy trading strategies
  • Regulators to track transactions
  • Malicious actors to target positions

PrivatePerps solves this by encrypting all position data and enabling private deposits, ensuring only you can see your trading activity.


Features

Core Trading Features

  • Perpetual Futures: Trade BTC, ETH, SOL perpetuals with up to 20x leverage
  • Long & Short Positions: Profit from both rising and falling markets
  • Real-Time PnL: Encrypted profit/loss calculations via Arcium MPC
  • Liquidation Protection: Automated margin checks and liquidation prevention
  • Funding Rates: Perpetual funding mechanism for market balance

Privacy Features

  • Encrypted Positions: Position size, collateral, and leverage are encrypted on-chain
  • Private PnL: Profit/loss calculated on encrypted data without revealing values
  • Private Deposits: Zcash shielded transactions for anonymous deposits
  • Private Withdrawals: Withdraw to new Zcash addresses for complete unlinkability

User Experience

  • Mobile Responsive: Fully responsive trading interface
  • Real-Time Charts: Professional candlestick charts with order book
  • Position Management: View and manage all positions with privacy controls
  • Bridge Integration: Seamless ZEC ↔ wZEC bridging

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PERPX ARCHITECTURE                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Frontend (Next.js/React)                                      β”‚
β”‚  β”œβ”€ Trading Interface                                           β”‚
β”‚  β”œβ”€ Position Dashboard                                         β”‚
β”‚  └─ Bridge UI                                                  β”‚
β”‚                                                                 β”‚
β”‚  Solana Programs                                                β”‚
β”‚  β”œβ”€ Perp DEX (Public Trading)                                 β”‚
β”‚  β”œβ”€ Confidential Perp (Arcium Encrypted)                        β”‚
β”‚  └─ ZEC Bridge (Cross-Chain)                                   β”‚
β”‚                                                                 β”‚
β”‚  Arcium MXE (MPC Network)                                      β”‚
β”‚  β”œβ”€ Encrypted Position Storage                                 β”‚
β”‚  β”œβ”€ Private PnL Computation                                    β”‚
β”‚  └─ Liquidation Checks                                         β”‚
β”‚                                                                 β”‚
β”‚  External Services                                              β”‚
β”‚  β”œβ”€ Pyth Oracle (Price Feeds)                                  β”‚
β”‚  β”œβ”€ Zcash Node (Bridge Relayer)                                β”‚
β”‚  └─ CoinGecko (Fallback Prices)                                β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  1. Perp DEX Program (programs/perp-dex/): Public perpetual trading program
  2. Confidential Perp Program (arcium-confidential/): Encrypted position management with Arcium
  3. ZEC Bridge Program (programs/zec-bridge/): Cross-chain bridge for Zcash deposits
  4. Frontend (frontend/): Next.js trading interface
  5. Bridge Relayer (bridge-relayer/): Service monitoring Zcash deposits

For detailed architecture, see PROJECT.md.


Quick Start

1. Clone the Repository

git clone https://github.com/e-man07/perp-dex.git
cd perp-dex

2. Install Dependencies

# Install Rust and Solana CLI (if not already installed)
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force

# Install Node.js dependencies
npm install

# Install frontend dependencies
cd frontend && npm install && cd ..

# Install bridge relayer dependencies
cd bridge-relayer && npm install && cd ..

3. Build Programs

# Build Solana programs
anchor build

# Build Arcium confidential program
cd arcium-confidential
arcium build
cd ..

4. Start Local Development Environment

# Start Solana localnet
solana-test-validator

# In another terminal, start Arcium MXE localnet
cd arcium-confidential
arcium localnet

# In another terminal, start frontend
cd frontend
npm run dev

5. Initialize Markets

# Initialize bridge, markets, and risk parameters
npx ts-node scripts/initialize-all.ts

Visit http://localhost:3000 to start trading!


πŸ“¦ Prerequisites

Required Software

System Requirements

  • RAM: 8GB minimum, 16GB recommended
  • Disk Space: 10GB+ for Solana ledger and Zcash blockchain
  • OS: macOS, Linux, or WSL2 on Windows

πŸ”§ Installation

Step-by-Step Setup

1. Install Rust and Solana

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

# Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"

# Verify installation
solana --version
anchor --version

2. Install Arcium CLI

cargo install arcium-cli
arcium --version

3. Clone and Setup Project

git clone https://github.com/e-man07/perpX.git
cd perp-dex

# Install root dependencies
npm install

# Install frontend dependencies
cd frontend && npm install && cd ..

# Install bridge relayer dependencies
cd bridge-relayer && npm install && cd ..

4. Build Programs

# Build Solana programs
anchor build

# Build Arcium confidential program
cd arcium-confidential
arcium build
cd ..

5. Setup Solana Wallet

# Generate a new wallet (or use existing)
solana-keygen new

# Set cluster to localnet
solana config set --url localhost

# Airdrop SOL for testing
solana airdrop 10

βš™οΈ Configuration

Environment Variables

Create .env files in each directory:

Root .env

ANCHOR_PROVIDER_URL=http://localhost:8899
ANCHOR_WALLET=~/.config/solana/id.json

frontend/.env.local

NEXT_PUBLIC_SOLANA_NETWORK=localhost
NEXT_PUBLIC_RPC_URL=http://localhost:8899
NEXT_PUBLIC_USE_LOCALNET=true

bridge-relayer/.env

SOLANA_RPC_URL=http://localhost:8899
SOLANA_PRIVATE_KEY=<your-keypair-path>
ZCASH_RPC_URL=http://localhost:8232
ZCASH_RPC_USER=zcash
ZCASH_RPC_PASSWORD=<generated-password>
ZEC_VIEWING_KEY=<your-viewing-key>

Anchor Configuration

Edit Anchor.toml to configure program IDs and cluster:

[programs.localnet]
perp_dex = "6mQu42YHujNsRkUw9qD4zC6K8saQbyL28H28AuVaqQui"
zec_bridge = "3zoZWhwFvZC7mtQv44MjsrbGBS37qxdM1uQjs8CTieQK"

[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

πŸ“– Usage

Trading on PerpX

1. Connect Wallet

  • Open the frontend at http://localhost:3000
  • Click "Connect Wallet" and select your Solana wallet (Phantom, etc.)

2. Bridge ZEC to wZEC (Optional)

  • Click "Bridge" in the navigation
  • Enter amount of ZEC to deposit
  • Generate deposit address and send ZEC
  • Wait for confirmation (or use "Dev Mode" on localnet)
  • Claim wZEC tokens

3. Open a Position

  • Select a market (BTC/USD, ETH/USD, or SOL/USD)
  • Choose Long or Short
  • Enter margin amount (in wZEC)
  • Set leverage (1x - 20x)
  • Click "Open Private Position"
  • Confirm transaction in wallet

4. Manage Positions

  • View all open positions in the "Positions" section
  • Click "Reveal" to decrypt and view position details
  • Monitor unrealized PnL and liquidation price
  • Close positions when ready

CLI Usage

Initialize Markets

# Initialize all components
npx ts-node scripts/initialize-all.ts

# Or initialize separately
npx ts-node scripts/initialize-bridge-localnet.ts
npx ts-node scripts/initialize-confidential-perp-localnet.ts
npx ts-node scripts/init-markets-localnet.ts

Deposit Liquidity

# Deposit liquidity as an LP
npx ts-node scripts/deposit-liquidity-localnet.ts

Update Prices

# Update market prices from oracle
npx ts-node scripts/update-market-prices.ts

Test Bridge Flow

# Test complete bridge flow
npx ts-node scripts/test-bridge-full-flow.ts

πŸ’» Development

Project Structure

perp-dex/
β”œβ”€β”€ programs/              # Solana programs
β”‚   β”œβ”€β”€ perp-dex/         # Public perpetual DEX
β”‚   └── zec-bridge/       # Zcash bridge
β”œβ”€β”€ arcium-confidential/  # Arcium encrypted program
β”‚   β”œβ”€β”€ programs/         # Confidential perp program
β”‚   └── encrypted-ixs/    # Encrypted instructions
β”œβ”€β”€ frontend/             # Next.js frontend
β”‚   β”œβ”€β”€ app/              # Next.js app router
β”‚   β”œβ”€β”€ components/       # React components
β”‚   └── hooks/            # React hooks
β”œβ”€β”€ bridge-relayer/       # Bridge relayer service
β”œβ”€β”€ scripts/              # Utility scripts
β”œβ”€β”€ tests/                # Integration tests
└── sdk/                  # TypeScript SDK

Development Workflow

1. Start Local Environment

# Terminal 1: Solana localnet
solana-test-validator

# Terminal 2: Arcium MXE
cd arcium-confidential && arcium localnet

# Terminal 3: Frontend
cd frontend && npm run dev

# Terminal 4: Bridge relayer (optional)
cd bridge-relayer && npm run dev

2. Make Changes

  • Edit Rust programs in programs/ or arcium-confidential/
  • Edit frontend in frontend/
  • Rebuild after Rust changes: anchor build or arcium build
  • Frontend hot-reloads automatically

3. Test Changes

# Run tests
anchor test

# Or run specific test file
anchor test tests/perp-dex.ts

Code Style

  • Rust: Follow standard Rust formatting (cargo fmt)
  • TypeScript: Use Prettier (npm run lint:fix)
  • Commit Messages: Use conventional commits

πŸ§ͺ Testing

Unit Tests

# Run all tests
anchor test

# Run specific test
anchor test tests/perp-dex.ts

Integration Tests

# Test bridge flow
npx ts-node scripts/test-bridge-full-flow.ts

# Test trading flow
npx ts-node scripts/test-perp-trade.ts

Manual Testing

  1. Start localnet: solana-test-validator
  2. Deploy programs: anchor deploy
  3. Initialize: npx ts-node scripts/initialize-all.ts
  4. Test in frontend: Open http://localhost:3000

Test Scripts

  • scripts/test-bridge-localnet.ts: Test bridge deposit/withdrawal
  • scripts/test-perp-trade.ts: Test opening/closing positions
  • scripts/quick-test-flow.sh: Quick verification script

🚒 Deployment

Deploy to Devnet

1. Configure Devnet

# Set cluster to devnet
solana config set --url devnet

# Airdrop SOL
solana airdrop 2

2. Deploy Programs

# Deploy Solana programs
anchor deploy

# Deploy Arcium program
cd arcium-confidential
arcium deploy
cd ..

3. Initialize on Devnet

# Update Anchor.toml to use devnet program IDs
# Then initialize
npx ts-node scripts/initialize-bridge.ts
npx ts-node scripts/initialize-confidential-perp.ts
npx ts-node scripts/init-markets-localnet.ts

4. Deploy Frontend

cd frontend

# Update .env.local with devnet RPC
NEXT_PUBLIC_SOLANA_NETWORK=devnet
NEXT_PUBLIC_RPC_URL=https://api.devnet.solana.com

# Build and deploy
npm run build
# Deploy to Vercel, Netlify, etc.

About

A private perp dex on Solana powered by Arcium and ZEC .

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages