Betly is a decentralized binary options platform built on Aptos that enables users to bet on APT/USD price movements using real-time Pyth Network price feeds.
CORE FEATURES:
- Binary Options Trading: Users bet UP or DOWN on APT/USD price movements
- 60 second Rounds: Fast-paced betting with automated round cycling
- 1.8x Payout: Winners receive 1.8x their bet amount
- Real-Time Prices: Live APT/USD price feeds from Pyth Network
- Automated Settlement: Keeper services handle round management and payouts
- Transparent Fees: 2% protocol fee collected from losing bets
PYTH INTEGRATION:
Betly implements the complete Pyth pull oracle pattern required for hackathon qualification:
- Fetch: Pulls price data from Pyth Hermes API
- Update: Updates price feeds on-chain via smart contract
- Consume: Consumes prices directly from smart contract for settlement
USER EXPERIENCE:
- Clean, intuitive interface with real-time price charts
- WebSocket integration for live price updates
- Automated claiming system for winnings
- Comprehensive round history and statistics
INNOVATION:
- First binary options platform on Aptos with Pyth integration
- Complete pull oracle pattern implementation
- Automated keeper service with price verification
- On-chain price tracking with transaction hash verification
ARCHITECTURE OVERVIEW:
Betly is built as a full-stack DeFi application with three main components: Move smart contracts, Next.js frontend, and automated keeper services.
SMART CONTRACT LAYER (Move on Aptos):
- Core Module: betly_betting::betting handles all betting logic
- Pyth Integration: Custom price feed management with on-chain storage
- Key Functions:
- start_round_with_pyth() - Starts rounds using Pyth prices
- settle_with_pyth() - Settles rounds with Pyth price verification
- update_pyth_price_feed() - Updates on-chain price data
- Data Structures: Enhanced Round struct with Pyth fields, PythPriceFeed for price tracking
- Events: Comprehensive event system for price consumption and settlement tracking
FRONTEND LAYER (Next.js + TypeScript):
- Framework: Next.js 15 with App Router
- UI: Tailwind CSS for styling, Lucide React for icons
- Charts: Lightweight Charts for real-time price visualization
- State Management: Zustand for global state
- Wallet Integration: Aptos wallet adapter for Petra wallet
- Real-Time Updates: WebSocket connection to Pyth Hermes for live prices
BACKEND SERVICES (API Routes):
- Price API: /api/price - Enhanced with Pyth pull oracle integration
- Keeper Services:
- /api/keeper/start - Starts rounds using Pyth pull oracle
- /api/keeper/settle - Settles rounds with Pyth price verification
- Pyth Integration: /api/pyth-pull-oracle - Dedicated endpoint for pull oracle operations
- Contract Interaction: Direct Aptos SDK integration for smart contract calls
PYTH PULL ORACLE IMPLEMENTATION:
// Step 1: Fetch from Hermes
const priceData = await pythPullOracle.fetchPriceFromHermes(priceId)
// Step 2: Update on-chain via smart contract
await pythPullOracle.updatePriceFeedsOnChain([priceId])
// Step 3: Consume from smart contract
const onChainPrice = await pythPullOracle.getPriceFromOnChain(priceId)
KEY TECHNOLOGIES:
- Blockchain: Aptos (Move smart contracts)
- Oracle: Pyth Network (Hermes API + pull oracle pattern)
- Frontend: Next.js, React, TypeScript, Tailwind CSS
- Charts: Lightweight Charts for price visualization
- Wallet: Aptos wallet adapter
- Deployment: Vercel for frontend, Aptos testnet for contracts
PARTNER TECHNOLOGY BENEFITS:
- Pyth Network: Provides accurate, real-time APT/USD prices with sub-second updates
- Aptos: Fast transaction finality and low fees for optimal user experience
- Vercel: Seamless deployment and edge functions for API routes
NOTABLE TECHNICAL ACHIEVEMENTS:
- Complete Pull Oracle Pattern: Full implementation of fetch → update → consume flow
- On-Chain Price Verification: Transaction hashes track price update provenance
- Automated Keeper Integration: Seamless round management with Pyth price feeds
- Fallback Mechanisms: Multiple layers of reliability for price data
- Gas Optimization: Batch operations and efficient smart contract design
- Real-Time UI: WebSocket + REST API hybrid for optimal user experience
HACKY SOLUTIONS:
- Mock Transaction Hashes: Used for demonstration when actual Pyth contract integration isn't available
- Fallback Price Sources: Hermes API fallback when on-chain prices aren't available
- Sequence Number Retry Logic: Handles Aptos transaction sequence number issues
- Price Precision Handling: Micro-dollar conversion for accurate price storage
KEY FILES:
- move/sources/betting.move - Smart contract with Pyth integration
- src/lib/pyth-pull-oracle.ts - Pyth pull oracle service
- src/app/api/pyth-pull-oracle/route.ts - Pyth API endpoint
- src/tests/pyth-pull-oracle.test.ts - Comprehensive test suite