Prophyt Smart Contracts
Documentation for Prophyt Move smart contracts on the Sui blockchain.
Contract Overview
Prophyt contracts are written in Move and deployed on Sui. The protocol consists of multiple modules that work together to provide prediction markets with integrated yield farming.
Core Modules
Prediction Market
The main module for market lifecycle management.
Module: prophyt::prediction_market
Key Functions:
MOVE// Create a new market public fun create_market<CoinType>( state: &mut PredictionMarketState<CoinType>, question: String, description: String, duration: u64, clock: &Clock, ctx: &mut TxContext, ) // Place a bet public fun place_bet<CoinType>( state: &mut PredictionMarketState<CoinType>, registry: &mut ProtocolRegistry<CoinType>, suilend_state: &mut SuilendState<CoinType>, haedal_state: &mut HaedalState<CoinType>, volo_state: &mut VoloState<CoinType>, market_id: u64, position: bool, bet_coin: Coin<CoinType>, bet_proof_blob_address: address, image_url: String, image_blob_id: String, clock: &Clock, ctx: &mut TxContext, ) // Resolve market (standard) public fun resolve_market<CoinType>( state: &mut PredictionMarketState<CoinType>, _owner_cap: &OwnerCap, registry: &ProtocolRegistry<CoinType>, suilend_state: &SuilendState<CoinType>, haedal_state: &HaedalState<CoinType>, volo_state: &VoloState<CoinType>, market_id: u64, outcome: bool, clock: &Clock, ctx: &mut TxContext, ) // Resolve market with Nautilus verification public fun resolve_market_with_nautilus<CoinType>( state: &mut PredictionMarketState<CoinType>, nautilus_registry: &NautilusRegistry, registry: &ProtocolRegistry<CoinType>, suilend_state: &SuilendState<CoinType>, haedal_state: &HaedalState<CoinType>, volo_state: &VoloState<CoinType>, market_id: u64, outcome: bool, source_data: String, source_data_hash: vector<u8>, resolution_timestamp: u64, media_hash: vector<u8>, signature: vector<u8>, enclave_public_key: vector<u8>, clock: &Clock, ctx: &mut TxContext, ) // Claim winnings public fun claim_winnings<CoinType>( state: &mut PredictionMarketState<CoinType>, registry: &ProtocolRegistry<CoinType>, suilend_state: &mut SuilendState<CoinType>, haedal_state: &mut HaedalState<CoinType>, volo_state: &mut VoloState<CoinType>, market_id: u64, bet_index: u64, winning_proof_blob_address: address, image_url: String, image_blob_id: String, clock: &Clock, ctx: &mut TxContext, )
State Structure:
MOVEpublic struct PredictionMarketState<phantom CoinType> has key { id: UID, markets: Table<u64, Market>, market_bets: Table<u64, vector<Bet>>, user_bets: Table<address, vector<u64>>, next_market_id: u64, next_bet_id: u64, protocol_fee_percentage: u64, transaction_fee_percentage: u64, fee_recipient: address, total_protocol_fees: u64, total_transaction_fees: u64, pausable_cap: PausableCap, }
Protocol Selector
Manages DeFi protocol integration and automatic selection.
Module: prophyt::protocol_selector
Key Functions:
MOVE// Initialize protocol registry public fun initialize<CoinType>( min_apy_threshold: u64, max_risk_tolerance: u8, ctx: &mut TxContext, ) // Register a protocol public fun register_protocol<CoinType>( registry: &mut ProtocolRegistry<CoinType>, protocol_type: u8, protocol_address: address, state_id: ID, risk_level: u8, ctx: &mut TxContext, ) // Automatic deposit to best protocol public fun auto_deposit<CoinType>( registry: &mut ProtocolRegistry<CoinType>, suilend_state: &mut SuilendState<CoinType>, haedal_state: &mut HaedalState<CoinType>, volo_state: &mut VoloState<CoinType>, deposit_coin: Coin<CoinType>, ctx: &mut TxContext, ): bool // Automatic withdrawal from protocols public fun auto_withdraw<CoinType>( registry: &ProtocolRegistry<CoinType>, suilend_state: &mut SuilendState<CoinType>, haedal_state: &mut HaedalState<CoinType>, volo_state: &mut VoloState<CoinType>, amount: u64, ctx: &mut TxContext, ): Coin<CoinType>
Protocol Selection Algorithm:
The protocol selector uses a weighted scoring system:
- APY: 60% weight
- TVL: 20% weight
- Risk: 20% weight
Protocols must meet minimum APY threshold and maximum risk tolerance.
Prophyt Agent
Automated rebalancing for yield optimization.
Module: prophyt::prophyt_agent
Key Functions:
MOVE// Analyze rebalancing opportunity public fun analyze_rebalance_opportunity<CoinType>( config: &AgentConfig, registry: &protocol_selector::ProtocolRegistry<CoinType>, ctx: &mut TxContext, ): (bool, RebalanceProposal) // Execute rebalancing public fun execute_rebalance<CoinType>( config: &mut AgentConfig, proposal: RebalanceProposal, registry: &mut protocol_selector::ProtocolRegistry<CoinType>, suilend_state: &mut suilend_adapter::SuilendState<CoinType>, haedal_state: &mut haedal_adapter::HaedalState<CoinType>, volo_state: &mut volo_adapter::VoloState<CoinType>, ctx: &mut TxContext, )
Nautilus Oracle
Trust oracle for provable market resolution.
Module: prophyt::nautilus_oracle
Key Functions:
MOVE// Register enclave public fun register_enclave( registry: &mut NautilusRegistry, public_key: vector<u8>, pcrs: vector<vector<u8>>, name: String, ctx: &mut TxContext, ) // Verify resolution signature public fun verify_resolution_signature( registry: &NautilusRegistry, resolution: &MarketResolution, signature: vector<u8>, public_key: vector<u8>, clock: &Clock, ): (bool, address)
Protocol Adapters
Suilend Adapter
Module: prophyt::suilend_adapter
- Deposit and withdrawal operations
- User balance tracking
- APY and exchange rate management
Haedal Adapter
Module: prophyt::haedal_adapter
- Whitelist functionality
- Staking operations
- Validator management
Volo Adapter
Module: prophyt::volo_adapter
- Share-based accounting
- Multiple yield strategies
- Performance fee mechanism
Fee Structure
Protocol Fees
- Maximum: 20% of generated yield (2000 basis points)
- Deducted at market resolution
- Configurable by owner
Transaction Fees
- Maximum: 10% of bet amount (1000 basis points)
- Deducted at bet placement
- Configurable by owner
Constants
Protocol Identifiers:
- Suilend: 1
- Haedal: 2
- Volo: 3
Risk Levels:
- Low: 1
- Medium: 5
- High: 10
Scoring Weights:
- APY: 60
- TVL: 20
- Risk: 20
Events
Market Events
MOVEpublic struct MarketCreated has copy, drop { market_id: u64, question: String, end_time: u64, creator: address, } public struct MarketResolved has copy, drop { market_id: u64, outcome: bool, total_yield_earned: u64, }
Betting Events
MOVEpublic struct BetPlaced has copy, drop { bet_id: u64, market_id: u64, user: address, position: bool, amount: u64, nft_id: address, } public struct WinningsClaimed has copy, drop { bet_id: u64, user: address, winning_amount: u64, yield_share: u64, nft_id: address, }
Error Codes
Common error codes:
E_MARKET_NOT_FOUND: Market does not existE_MARKET_ENDED: Market has already endedE_MARKET_NOT_ENDED: Market has not ended yetE_MARKET_ALREADY_RESOLVED: Market already resolvedE_INVALID_AMOUNT: Invalid bet amountE_BET_NOT_FOUND: Bet does not existE_BET_ALREADY_CLAIMED: Bet already claimedE_NOT_BET_OWNER: Not the bet ownerE_INVALID_SIGNATURE: Invalid Nautilus signature
Security Features
- Owner-only functions for critical operations
- Pausable contracts for emergency stops
- Input validation on all functions
- Time-based logic enforcement
- Signature verification for Nautilus resolutions
Contract Deployment
Contracts are deployed on Sui using the standard deployment process:
BASHsui client publish --gas-budget 100000000
After deployment, initialize each component:
- Initialize prediction market state
- Initialize protocol registry
- Initialize protocol adapters
- Initialize Prophyt agent
- Initialize Nautilus registry
- Register protocols
- Register Nautilus enclaves
Testing
Contracts include comprehensive test suites:
- Unit tests for individual components
- Integration tests for cross-contract interactions
- Test fixtures for consistent testing environments
Run tests with:
BASHsui move test
