Prophyt Architecture

This document provides a comprehensive overview of the Prophyt protocol architecture, components, and how they interact.

System Overview

Prophyt consists of three main layers:

  1. Smart Contracts: Move contracts on Sui blockchain
  2. Indexer: Event processing and REST API
  3. Nautilus Server: Trust oracle for market resolution

Smart Contract Architecture

Core Components

Prediction Market (prediction_market.move)

The primary module for market lifecycle management.

Key Functions:

  • create_market(): Create new prediction markets
  • place_bet(): Place bets with automatic yield deposit
  • resolve_market(): Standard market resolution
  • resolve_market_with_nautilus(): Nautilus-verified resolution
  • claim_winnings(): Claim rewards and yield

State Management:

  • Markets stored in Table<u64, Market>
  • Bets tracked per market and per user
  • Fee tracking and recipient management
  • Pausable functionality for emergency stops

Protocol Selector (protocol_selector.move)

Manages integration with multiple DeFi yield protocols.

Protocol Selection Algorithm:

  • Weighted scoring: APY (60%), TVL (20%), Risk (20%)
  • Minimum APY threshold enforcement
  • Maximum risk tolerance filtering
  • Automatic fallback to alternative protocols

Supported Protocols:

  1. Suilend (ID: 1): Lending protocol
  2. Haedal (ID: 2): Liquid staking with whitelist
  3. Volo (ID: 3): Yield farming with share-based accounting

Prophyt Agent (prophyt_agent.move)

Automated rebalancing system for yield optimization.

Features:

  • Monitors APY differences between protocols
  • Generates rebalancing proposals
  • Executes fund transfers automatically
  • Configurable thresholds and intervals

Nautilus Oracle (nautilus_oracle.move)

Trust oracle system for provable market resolution.

Enclave Registration:

  • Public key and PCR (Platform Configuration Register) storage
  • Enclave activation/deactivation
  • Signature verification using Ed25519

Resolution Verification:

  • Ed25519 signature verification
  • Timestamp validation (1 hour max age)
  • Source data and media hash validation

Protocol Adapters

Each DeFi protocol has a dedicated adapter:

  • Suilend Adapter: Balance tracking, deposit/withdraw operations
  • Haedal Adapter: Whitelist management, staking operations
  • Volo Adapter: Share-based accounting, strategy management

Supporting Components

  • Access Control: Owner capabilities and pausability
  • Constants: Protocol-wide configuration values
  • Walrus Proof NFTs: Commemorative NFT minting

Indexer Architecture

Event Processing

The indexer monitors Sui blockchain events in real-time:

Event Types:

  • MarketCreated: New market creation
  • BetPlaced: User bet placement
  • MarketResolved: Market resolution
  • WinningsClaimed: User claim events
  • BetProofNFTMinted: Bet proof NFT minting
  • WinningProofNFTMinted: Winning proof NFT minting

Processing Flow:

  1. Poll Sui events with cursor-based tracking
  2. Filter Prophyt-specific contract events
  3. Process events through handlers
  4. Store in PostgreSQL database
  5. Update market statistics and user portfolios

REST API

Express.js server providing comprehensive API:

Endpoints:

  • /api/markets: Market listing and details
  • /api/bets: Bet tracking and user portfolios
  • /api/users: User analytics and statistics
  • /api/oracle: Price feeds and market data
  • /api/charts: Analytics and chart data
  • /api/nautilus: Nautilus integration endpoints

Background Services

Price Updater:

  • Fetches SUI/USD price from CoinGecko
  • Caches prices with configurable duration
  • Updates database periodically

Market Resolution Scheduler:

  • Checks for expired markets every 60 seconds
  • Automatically triggers Nautilus resolution
  • Submits resolutions to blockchain

Image Generation

Dynamic NFT portfolio image creation:

  • Canvas-based rendering
  • Custom fonts and branding
  • Bet proof and winning proof templates
  • Walrus storage integration

Nautilus Server Architecture

Enclave-Based Resolution

The Nautilus server runs in an AWS Nitro Enclave to provide:

Key Management:

  • Ed25519 signing keys generated in enclave
  • Keys stored securely in database
  • Public keys registered on-chain

Resolution Process:

  1. Receive market resolution request
  2. Verify market has ended
  3. Query external data sources
  4. Compute source data hash
  5. Verify media provenance (if provided)
  6. Serialize resolution data
  7. Sign with Ed25519 private key
  8. Return signed resolution

API Endpoints:

  • POST /resolve: Request market resolution
  • GET /health: Health check
  • GET /markets/pending: Get pending markets

Data Flow

Market Lifecycle

SHELL
1. User creates market → Contract emits MarketCreated event 2. Indexer processes event → Stores market in database 3. Users place bets → Funds auto-deposited to yield protocol 4. Indexer tracks bets → Updates market statistics 5. Market expires → Resolution scheduler triggers 6. Nautilus resolves → Returns signed resolution 7. Indexer submits → On-chain resolution via contract 8. Winners claim → Funds auto-withdrawn from protocols

Yield Optimization Flow

SHELL
1. Bet placed → Protocol selector chooses optimal protocol 2. Funds deposited → Automatic deposit to selected protocol 3. Agent monitors → Tracks APY differences 4. Rebalancing triggered → When threshold exceeded 5. Funds moved → From lower-yield to higher-yield protocol 6. Claim initiated → Automatic withdrawal across protocols

Security Architecture

On-Chain Security

  • Access Controls: Owner-only functions for critical operations
  • Pausable Contracts: Emergency stop functionality
  • Input Validation: Comprehensive error checking
  • Time-Based Logic: Proper market lifecycle enforcement
  • Signature Verification: Ed25519 for Nautilus resolutions

Off-Chain Security

  • Enclave Isolation: Nautilus keys never leave enclave
  • Database Security: Parameterized queries, connection security
  • API Security: Input validation, error handling
  • Image Validation: Content verification before upload

Integration Points

Frontend Integration

  • REST API for all data needs
  • Real-time market and bet data
  • User portfolio and statistics
  • Chart and analytics data

External Services

  • CoinGecko: Price feeds
  • Adjacent API: Market data seeding
  • Walrus Network: Decentralized storage
  • Sui Network: Blockchain interaction

Performance Considerations

  • Event Processing: 1-second polling with cursor tracking
  • Concurrent Operations: Rate limiting (1000 concurrent)
  • Database: Connection pooling and query optimization
  • Caching: Price data caching with configurable duration

Future Enhancements

  • WebSocket support for real-time updates
  • Advanced analytics and machine learning
  • Enhanced NFT generation templates
  • Additional DeFi protocol integrations
  • Multi-asset market support
Previous
Introduction