Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Private Perps - TEE-Powered Perpetual DEX

A verifiable, private, and autonomous perpetual futures exchange running in Intel TDX enclaves via EigenCompute, with on-chain attestation anchored to Ethereum Sepolia.

🎯 Overview

Private Perps is a decentralized perpetual futures exchange that:

  • Executes trades privately inside TEE enclaves
  • Generates verifiable attestations for every state transition
  • Anchors state roots to Ethereum for transparency
  • Operates autonomously without centralized control
  • Provides non-custodial trading with cryptographic guarantees

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   EigenCompute TEE                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Matching  │──│   Price   │──│  Attestation   β”‚   β”‚
β”‚  β”‚  Engine   β”‚  β”‚  Oracle   β”‚  β”‚   Service      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚         β”‚             β”‚                β”‚             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚             β”‚
β”‚  β”‚ OrderBook β”‚  β”‚ REST/WS  β”‚          β”‚             β”‚
β”‚  β”‚           β”‚  β”‚   API    β”‚          β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
                                    Attestations
                                         β”‚
                                         β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚   Ethereum Sepolia   β”‚
                            β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                            β”‚  β”‚  EigenVerify   β”‚  β”‚
                            β”‚  β”‚   Contract     β”‚  β”‚
                            β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Node.js β‰₯ v18
  • Docker Desktop
  • Sepolia ETH (for contract deployment)
  • EigenX CLI access (request at eigenx.ai)

Local Development

# Clone repository
git clone https://github.com/yourusername/private-perps
cd private-perps

# Install dependencies
npm install

# Configure environment
cp .env.example .env
# Edit .env with your configuration

# Deploy smart contracts to Sepolia
npx hardhat run scripts/deploy.ts --network sepolia

# Run locally
npm run dev

Deploy to EigenCompute

# Authenticate with EigenX
eigenx auth generate --store

# Deploy to TEE
eigenx app deploy

# View deployment status
eigenx app info

πŸ“ Smart Contract Deployment

1. Configure Environment

Edit .env with your credentials:

SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
PRIVATE_KEY=your_deployment_wallet_private_key
ETHERSCAN_API_KEY=your_etherscan_api_key

2. Deploy EigenVerify Contract

# Compile contracts
npx hardhat compile

# Deploy to Sepolia
npx hardhat run scripts/deploy.ts --network sepolia

# Verify on Etherscan (automatic if API key provided)

3. Update Enclave Configuration

After deployment, update .env:

EIGEN_VERIFY_CONTRACT=0x... # Deployed contract address
ENCLAVE_SIGNER_ADDRESS=0x... # From eigenx auth whoami

πŸ”§ Configuration

Core Settings

Variable Description Default
EXCHANGE_NAME_PUBLIC Exchange name Private Perps
MAX_LEVERAGE Maximum trading leverage 20x
LIQUIDATION_PENALTY Liquidation fee percentage 2.5%
ATTESTATION_INTERVAL_SECONDS Attestation frequency 300 (5 min)

API Configuration

Variable Description Default
APP_PORT REST API port 8000
WS_PORT WebSocket port 8001
ENABLE_REST_API Enable REST endpoints true
ENABLE_WEBSOCKET Enable WebSocket server true

πŸ“‘ API Documentation

REST Endpoints

Market Data

  • GET /api/v1/orderbook/:symbol - Get order book
  • GET /api/v1/trades/:symbol - Recent trades
  • GET /api/v1/ticker/:symbol - Price ticker

Trading

  • POST /api/v1/order - Submit order
  • DELETE /api/v1/order/:orderId - Cancel order
  • GET /api/v1/orders/:userId - User orders

Positions

  • GET /api/v1/position/:userId - User position
  • GET /api/v1/positions - All positions

System

  • GET /health - Health check
  • GET /api/v1/status - Engine status
  • GET /api/v1/attestation - Attestation status

WebSocket Channels

Connect to ws://localhost:8000 and subscribe:

// Subscribe to channels
{ "type": "subscribe", "channel": "trades" }
{ "type": "subscribe", "channel": "orderbook" }
{ "type": "subscribe", "channel": "ticker" }

// Submit orders (requires auth)
{ "type": "auth", "data": { "userId": "user123" } }
{ "type": "submit_order", "data": { ... } }

πŸ” Security Model

TEE Guarantees

  • Memory Encryption: All data encrypted in Intel TDX enclave memory
  • Attestation: Cryptographic proof of code integrity
  • Isolation: Protected from host OS and hypervisor

On-Chain Verification

  • State roots anchored to Ethereum
  • Attestations verified by smart contract
  • Challenge mechanism for disputes

Non-Custodial Design

  • Users maintain control of funds
  • Enclave only manages trading logic
  • Transparent state transitions

πŸ§ͺ Testing

Run Tests

# Contract tests
npx hardhat test

# Integration tests
npm test

# Coverage report
npx hardhat coverage

Test on Sepolia

  1. Deploy contracts to Sepolia
  2. Configure .env with testnet settings
  3. Set USE_TEST_PRICES=true for mock prices
  4. Run with npm run dev

πŸ“Š Monitoring

View Logs

eigenx app logs [app-name]

Check Status

# Application status
curl http://localhost:8000/api/v1/status

# Attestation status
curl http://localhost:8000/api/v1/attestation

# Health check
curl http://localhost:8000/health

On-Chain Verification

View attestations on Etherscan:

https://sepolia.etherscan.io/address/[EIGEN_VERIFY_CONTRACT]

πŸ› οΈ Development Workflow

1. Local Development

npm run dev        # Start local server
npm run build      # Compile TypeScript
npm test          # Run tests

2. Docker Testing

docker build -t private-perps .
docker run --rm --env-file .env private-perps

3. Deploy to TEE

eigenx app deploy
eigenx app logs
eigenx app info

4. Upgrade Deployment

# Make changes to code
eigenx app upgrade

🚨 Troubleshooting

Common Issues

Attestation Failures

  • Check enclave wallet has ETH for gas
  • Verify contract address in .env
  • Ensure enclave is registered on-chain

Connection Issues

  • Verify RPC URL is correct
  • Check network connectivity
  • Ensure ports are not blocked

Build Failures

  • Platform must be linux/amd64
  • Run as root user in Docker
  • Check Node.js version β‰₯ 18

πŸ“š Additional Resources

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit changes with clear messages
  4. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file

⚠️ Disclaimer

This is experimental software running in alpha. Use at your own risk. Not audited for production use.


Built with EigenCompute | Secured by Intel TDX | Anchored on Ethereum

eigen-dex

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages